refactor: create custom a-statistic component

This commit is contained in:
Shishkevich D. 2025-03-17 10:45:17 +00:00
parent a83d2cc6a5
commit 01e260cab4
3 changed files with 72 additions and 32 deletions

View file

@ -0,0 +1,55 @@
{{define "component/customStatistic"}}
<template>
<a-statistic :title="title" :value="value">
<template #prefix>
<slot name="prefix"></slot>
</template>
<template #suffix>
<slot name="suffix"></slot>
</template>
</a-statistic>
</template>
{{end}}
{{define "component/aCustomStatistic"}}
<style>
.dark .ant-statistic-title,
.dark .ant-statistic-content {
color: var(--dark-color-text-primary) !important
}
.dark .ant-statistic-title {
user-select: none;
opacity: 0.55;
}
.ant-statistic-title {
margin-bottom: 0 !important;
}
.ant-statistic-content-prefix {
margin-right: 6px !important;
}
.ant-statistic-content-prefix,
.ant-statistic-content-value {
font-size: 1.05rem;
}
</style>
<script>
Vue.component('a-custom-statistic', {
props: {
'title': {
type: String,
required: false,
},
'value': {
type: String,
required: false
}
},
template: `{{template "component/customStatistic"}}`,
});
</script>
{{end}}

View file

@ -22,14 +22,6 @@
<script> <script>
Vue.component('a-setting-list-item', { Vue.component('a-setting-list-item', {
props: { props: {
'title': {
type: String,
required: true,
},
'description': {
type: String,
required: false,
},
'paddings': { 'paddings': {
type: String, type: String,
required: false, required: false,

View file

@ -27,8 +27,6 @@
.dark .ant-backup-list-item svg, .dark .ant-backup-list-item svg,
.dark .ant-card-actions>li>*, .dark .ant-card-actions>li>*,
.dark .ant-badge-status-text, .dark .ant-badge-status-text,
.dark .ant-statistic-title,
.dark .ant-statistic-content,
.dark .ant-card-extra { .dark .ant-card-extra {
color: var(--dark-color-text-primary) !important; color: var(--dark-color-text-primary) !important;
} }
@ -44,12 +42,6 @@
.ant-card-actions { .ant-card-actions {
background: transparent !important; background: transparent !important;
} }
.ant-statistic-content-prefix {
font-size: 20px;
}
.ant-statistic-content-value {
font-size: 18px;
}
.ip-hidden { .ip-hidden {
filter: blur(10px); filter: blur(10px);
} }
@ -223,18 +215,18 @@
</template> </template>
<a-row :class="showIp ? 'ip-visible' : 'ip-hidden'"> <a-row :class="showIp ? 'ip-visible' : 'ip-hidden'">
<a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }"> <a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }">
<a-statistic title="IPv4" :value="status.publicIP.ipv4"> <a-custom-statistic title="IPv4" :value="status.publicIP.ipv4">
<template #prefix> <template #prefix>
<a-icon type="global" /> <a-icon type="global" />
</template> </template>
</a-statistic> </a-custom-statistic>
</a-col> </a-col>
<a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }"> <a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }">
<a-statistic title="IPv6" :value="status.publicIP.ipv6"> <a-custom-statistic title="IPv6" :value="status.publicIP.ipv6">
<template #prefix> <template #prefix>
<a-icon type="global" /> <a-icon type="global" />
</template> </template>
</a-statistic> </a-custom-statistic>
</a-col> </a-col>
</a-row> </a-row>
</a-card> </a-card>
@ -243,18 +235,18 @@
<a-card title='{{ i18n "pages.index.connectionCount" }}' hoverable> <a-card title='{{ i18n "pages.index.connectionCount" }}' hoverable>
<a-row> <a-row>
<a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }"> <a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }">
<a-statistic title="TCP" :value="status.tcpCount"> <a-custom-statistic title="TCP" :value="status.tcpCount">
<template #prefix> <template #prefix>
<a-icon type="swap" /> <a-icon type="swap" />
</template> </template>
</a-statistic> </a-custom-statistic>
</a-col> </a-col>
<a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }"> <a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }">
<a-statistic title="UDP" :value="status.udpCount"> <a-custom-statistic title="UDP" :value="status.udpCount">
<template #prefix> <template #prefix>
<a-icon type="swap" /> <a-icon type="swap" />
</template> </template>
</a-statistic> </a-custom-statistic>
</a-col> </a-col>
</a-row> </a-row>
</a-card> </a-card>
@ -263,24 +255,24 @@
<a-card title='{{ i18n "pages.index.overallSpeed" }}' hoverable> <a-card title='{{ i18n "pages.index.overallSpeed" }}' hoverable>
<a-row> <a-row>
<a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }"> <a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }">
<a-statistic title='{{ i18n "pages.index.upload" }}' :value="SizeFormatter.sizeFormat(status.netIO.up)"> <a-custom-statistic title='{{ i18n "pages.index.upload" }}' :value="SizeFormatter.sizeFormat(status.netIO.up)">
<template #prefix> <template #prefix>
<a-icon type="arrow-up" /> <a-icon type="arrow-up" />
</template> </template>
<template #suffix> <template #suffix>
/s /s
</template> </template>
</a-statistic> </a-custom-statistic>
</a-col> </a-col>
<a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }"> <a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }">
<a-statistic title='{{ i18n "pages.index.download" }}' :value="SizeFormatter.sizeFormat(status.netIO.down)"> <a-custom-statistic title='{{ i18n "pages.index.download" }}' :value="SizeFormatter.sizeFormat(status.netIO.down)">
<template #prefix> <template #prefix>
<a-icon type="arrow-down" /> <a-icon type="arrow-down" />
</template> </template>
<template #suffix> <template #suffix>
/s /s
</template> </template>
</a-statistic> </a-custom-statistic>
</a-col> </a-col>
</a-row> </a-row>
</a-card> </a-card>
@ -289,18 +281,18 @@
<a-card title='{{ i18n "pages.index.totalData" }}' hoverable> <a-card title='{{ i18n "pages.index.totalData" }}' hoverable>
<a-row> <a-row>
<a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }"> <a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }">
<a-statistic title='{{ i18n "pages.index.sent" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.sent)"> <a-custom-statistic title='{{ i18n "pages.index.sent" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.sent)">
<template #prefix> <template #prefix>
<a-icon type="cloud-upload" /> <a-icon type="cloud-upload" />
</template> </template>
</a-statistic> </a-custom-statistic>
</a-col> </a-col>
<a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }"> <a-col :lg="12" :sm="24" :style="{ marginTop: isMobile ? '10px' : 0 }">
<a-statistic title='{{ i18n "pages.index.received" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.recv)"> <a-custom-statistic title='{{ i18n "pages.index.received" }}' :value="SizeFormatter.sizeFormat(status.netTraffic.recv)">
<template #prefix> <template #prefix>
<a-icon type="cloud-download" /> <a-icon type="cloud-download" />
</template> </template>
</a-statistic> </a-custom-statistic>
</a-col> </a-col>
</a-row> </a-row>
</a-card> </a-card>
@ -398,6 +390,7 @@
</a-layout> </a-layout>
{{template "js" .}} {{template "js" .}}
{{template "component/aThemeSwitch" .}} {{template "component/aThemeSwitch" .}}
{{template "component/aCustomStatistic" .}}
{{template "textModal"}} {{template "textModal"}}
<script> <script>
const State = { const State = {