From 468607c8e855bf903692145cf108b19fa529f512 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 17 Apr 2024 14:38:40 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E7=AB=99=E7=82=B9=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 1 + src/@core/components/StatIcon.vue | 18 +++++++++++++++ src/api/types.ts | 27 ++++++++++++++++++++++ src/components/cards/SiteCard.vue | 37 ++++++++++++++++++++++++++++--- yarn.lock | 7 ++++++ 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 src/@core/components/StatIcon.vue diff --git a/components.d.ts b/components.d.ts index 8f4e3f15..842ae72d 100644 --- a/components.d.ts +++ b/components.d.ts @@ -13,6 +13,7 @@ declare module 'vue' { MoreBtn: typeof import('./src/@core/components/MoreBtn.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] + StatIcon: typeof import('./src/@core/components/StatIcon.vue')['default'] ThemeSwitcher: typeof import('./src/@core/components/ThemeSwitcher.vue')['default'] } } diff --git a/src/@core/components/StatIcon.vue b/src/@core/components/StatIcon.vue new file mode 100644 index 00000000..e5c82df3 --- /dev/null +++ b/src/@core/components/StatIcon.vue @@ -0,0 +1,18 @@ + + + diff --git a/src/api/types.ts b/src/api/types.ts index 32ab43f6..1d0efbe1 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -505,6 +505,33 @@ export interface Site { is_active: boolean } +// 站点使用统计 +export interface SiteStatistic { + + // 站点主域名Key + domain?: string + + // 成功次数 + success?: number + + // 失败次数 + fail?: number + + // 平均耗时 + seconds?: number + + // 最后一次访问状态 0-成功 1-失败 + lst_state?: number + + // 最后访问时间 + lst_mod_date?: string + + // 耗时记录 JSON + note?: string + + +} + // 正在下载 export interface DownloadingInfo { diff --git a/src/components/cards/SiteCard.vue b/src/components/cards/SiteCard.vue index 2b97b415..8fd8528a 100644 --- a/src/components/cards/SiteCard.vue +++ b/src/components/cards/SiteCard.vue @@ -5,7 +5,7 @@ import SiteAddEditForm from '../form/SiteAddEditForm.vue' import SiteTorrentTable from '../table/SiteTorrentTable.vue' import { requiredValidator } from '@/@validators' import api from '@/api' -import type { Site } from '@/api/types' +import type { Site, SiteStatistic } from '@/api/types' import ExistIcon from '@core/components/ExistIcon.vue' // 输入参数 @@ -58,6 +58,9 @@ const userPwForm = ref({ code: '', }) +// 站点使用统计 +const siteStats = ref({}) + // 查询站点图标 async function getSiteIcon() { try { @@ -82,6 +85,18 @@ async function testSite() { testButtonText.value = '测试' testButtonDisable.value = false + + getSiteStats() + } + catch (error) { + console.error(error) + } +} + +// 查询站点使用统计 +async function getSiteStats() { + try { + siteStats.value = (await api.get(`site/statistic/${cardProps.site?.domain}`)) } catch (error) { console.error(error) @@ -140,9 +155,24 @@ function openSitePage() { window.open(cardProps.site?.url, '_blank') } +// 根据站点状态显示不同的状态图标 +const statColor = computed(() => { + if (siteStats.value?.lst_state == 1){ + return 'error' + } + else if (siteStats.value?.lst_state == 0){ + if (!siteStats.value?.seconds) + return 'secondary' + if (siteStats.value?.seconds >= 10) + return 'warning' + return 'success' + } +}) + // 装载时查询站点图标 onMounted(() => { getSiteIcon() + getSiteStats() }) @@ -163,16 +193,17 @@ onMounted(() => { + {{ cardProps.site?.name }} - {{ cardProps.site?.url }} + {{ cardProps.site?.url }} - +