feat:站点状态显示

This commit is contained in:
jxxghp
2024-04-17 14:38:40 +08:00
parent 5bd9283177
commit 468607c8e8
5 changed files with 87 additions and 3 deletions

1
components.d.ts vendored
View File

@@ -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']
}
}

View File

@@ -0,0 +1,18 @@
<script lang="ts" setup>
interface Props {
color?: string
message?: string
}
const props = defineProps<Props>()
</script>
<template>
<div class="absolute top-2 right-2 flex items-center justify-between p-2 shadow">
<VBadge :color="props.color" bordered>
<template #badge>
<VIcon icon="mdi-pulse"></VIcon>
</template>
</VBadge>
</div>
</template>

View File

@@ -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 {

View File

@@ -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<SiteStatistic>({})
// 查询站点图标
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()
})
</script>
@@ -163,16 +193,17 @@ onMounted(() => {
<VImg :src="siteIcon" />
</VAvatar>
</template>
<VCardItem>
<VCardTitle class="font-bold">
<span @click.stop="openSitePage">{{ cardProps.site?.name }}</span>
</VCardTitle>
<VCardSubtitle>
{{ cardProps.site?.url }}
<span @click.stop="openSitePage">{{ cardProps.site?.url }}</span>
</VCardSubtitle>
</VCardItem>
<ExistIcon v-if="cardProps.site?.is_active" />
<StatIcon v-if="cardProps.site?.is_active" :color="statColor" />
<VCardText class="py-2">
<VTooltip

View File

@@ -3057,6 +3057,11 @@ data-view-byte-offset@^1.0.0:
es-errors "^1.3.0"
is-data-view "^1.0.1"
dayjs@^1.11.10:
version "1.11.10"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.10.tgz#68acea85317a6e164457d6d6947564029a6a16a0"
integrity sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==
de-indent@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"
@@ -6482,6 +6487,7 @@ stop-iteration-iterator@^1.0.0:
internal-slot "^1.0.4"
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.3:
name string-width-cjs
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -6555,6 +6561,7 @@ stringify-object@^3.3.0:
is-regexp "^1.0.0"
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
name strip-ansi-cjs
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==