diff --git a/src/views/home/modules/header-banner.vue b/src/views/home/modules/header-banner.vue index 6327c18..234024e 100644 --- a/src/views/home/modules/header-banner.vue +++ b/src/views/home/modules/header-banner.vue @@ -5,7 +5,7 @@ import { useAppStore } from '@/store/modules/app'; import type { ECOption } from '@/hooks/common/echarts'; import { useI18n } from 'vue-i18n'; import { useAuthStore } from '@/store/modules/auth'; - +import { clientAuth } from '@/service/ue/client' const { t } = useI18n(); const authStore = useAuthStore(); defineOptions({ @@ -230,8 +230,29 @@ const updateGaugeData = (opts: ECOption, data: GaugeDisplayData) => { // 添加峰值速率的 ref const peakTrafficRate = ref(0); +//增加模拟上网 +function checkAndTriggerAuth(dashboardData: any) { + // 检查是否有余额 + const hasBalance = dashboardData.balance > 0; -// 修改 mockDataUpdate 函数 + // 检查是否不限制流量 + const noTrafficLimit = !dashboardData.trafficEnable; + + // 检查是否有剩余流量 + const hasRemainingTraffic = dashboardData.trafficEnable && + (dashboardData.traffic - dashboardData.trafficUsed) > 0; + + // 如果满足任一条件,触发上网 + if (hasBalance || noTrafficLimit || hasRemainingTraffic) { + clientAuth().then((res) => { + console.log('Auto auth triggered:', res); + }).catch(err => { + console.error('Auto auth failed:', err); + }); + } +} + +// mockDataUpdate 函数 async function mockDataUpdate() { try { const response = await authStore.getDashboardData(); @@ -268,7 +289,8 @@ async function mockDataUpdate() { description: `${t('page.headerbanner.monthflowr')} (${formattedTotal.value}${formattedTotal.unit})`, // 显示总流量 subTitle: t('page.headerbanner.Used') + `: ${formattedUsed.value}${formattedUsed.unit}` // 显示已用流量 }; - + // 在数据处理完成后,添加自动上网检查 + checkAndTriggerAuth(response); // 更新仪表盘的进度比例 updateGauge2(opts => { if (opts.series && Array.isArray(opts.series)) {