fix:修改错误提示
This commit is contained in:
@@ -5,7 +5,7 @@ import { useAppStore } from '@/store/modules/app';
|
|||||||
import type { ECOption } from '@/hooks/common/echarts';
|
import type { ECOption } from '@/hooks/common/echarts';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useAuthStore } from '@/store/modules/auth';
|
import { useAuthStore } from '@/store/modules/auth';
|
||||||
|
import { clientAuth } from '@/service/ue/client';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
@@ -257,94 +257,122 @@ const updateGaugeData = (opts: ECOption, data: GaugeDisplayData, progressRatio?:
|
|||||||
// 添加峰值速率的 ref
|
// 添加峰值速率的 ref
|
||||||
const peakTrafficRate = ref(0);
|
const peakTrafficRate = ref(0);
|
||||||
|
|
||||||
|
// 添加检查是否可以上网的函数
|
||||||
|
function checkAndTriggerAuth(dashboardData: any) {
|
||||||
|
// 检查是否有余额
|
||||||
|
const hasBalance = dashboardData.balance > 0;
|
||||||
|
// 检查是否不限制流量
|
||||||
|
const noTrafficLimit = !dashboardData.trafficEnable;
|
||||||
|
// 检查是否有剩余流量
|
||||||
|
const hasRemainingTraffic = dashboardData.trafficEnable &&
|
||||||
|
(dashboardData.traffic - dashboardData.trafficUsed) > 0;
|
||||||
|
|
||||||
|
// 如果满足任一条件,静默触发上网
|
||||||
|
if (hasBalance || noTrafficLimit || hasRemainingTraffic) {
|
||||||
|
clientAuth().catch(err => {
|
||||||
|
console.warn('Auto auth failed:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 修改 mockDataUpdate 函数,在获取数据后添加检查
|
// 修改 mockDataUpdate 函数,在获取数据后添加检查
|
||||||
async function mockDataUpdate() {
|
async function mockDataUpdate() {
|
||||||
try {
|
try {
|
||||||
const response = await authStore.getDashboardData();
|
const response = await authStore.getDashboardData();
|
||||||
if (response) {
|
// 检查响应是否有效
|
||||||
// 更新余额和设备数据
|
if (response && typeof response === 'object') {
|
||||||
const numBalance = Number(response.balance);
|
// 检查必要的字段是否存在
|
||||||
baseData.value[0] = {
|
if (response.balance !== undefined) {
|
||||||
...baseData.value[0],
|
// 更新余额和设备数据
|
||||||
value: numBalance, // 使用转换后的数字
|
const numBalance = Number(response.balance);
|
||||||
max: Math.max(numBalance, 100),
|
baseData.value[0] = {
|
||||||
displayValue: formatBalance(response.balance),
|
...baseData.value[0],
|
||||||
unit: '元',
|
value: numBalance,
|
||||||
subTitle: t('page.headerbanner.deviceCount') + `: ${response.clientNum}台`
|
max: Math.max(numBalance, 100),
|
||||||
};
|
displayValue: formatBalance(response.balance),
|
||||||
|
unit: '元',
|
||||||
// 先计算剩余流量(字节单位)
|
subTitle: t('page.headerbanner.deviceCount') + `: ${response.clientNum || 0}台`
|
||||||
const totalTraffic = response.traffic; // 总流量(字节)
|
|
||||||
const usedTraffic = response.trafficUsed; // 已用流量(字节)
|
|
||||||
|
|
||||||
// 计算剩余流量,确保不会出现负数
|
|
||||||
const remainingTraffic = Math.max(0, totalTraffic - usedTraffic); // 剩余流量(字节)
|
|
||||||
|
|
||||||
// 计算进度比例,确保在 0-1 之间
|
|
||||||
const progressRatio = Math.min(1, Math.max(0, remainingTraffic / totalTraffic));
|
|
||||||
|
|
||||||
// 格式化流量显示
|
|
||||||
const formattedTotal = formatTraffic(totalTraffic);
|
|
||||||
const formattedUsed = formatTraffic(usedTraffic);
|
|
||||||
const formattedRemaining = formatTraffic(remainingTraffic);
|
|
||||||
|
|
||||||
// 更新流量数据显示
|
|
||||||
baseData.value[1] = {
|
|
||||||
...baseData.value[1],
|
|
||||||
value: remainingTraffic,
|
|
||||||
max: totalTraffic,
|
|
||||||
displayValue: `${formattedRemaining.value}${formattedRemaining.unit}`,
|
|
||||||
unit: '',
|
|
||||||
description: `${t('page.headerbanner.monthflowr')} (${formattedTotal.value}${formattedTotal.unit})`,
|
|
||||||
subTitle: t('page.headerbanner.Used') + `: ${formattedUsed.value}${formattedUsed.unit}`
|
|
||||||
};
|
|
||||||
|
|
||||||
// 获取当前速率
|
|
||||||
const currentActivity = Number(response.activity ?? 0);
|
|
||||||
|
|
||||||
// 更新峰值速率
|
|
||||||
if (currentActivity > peakTrafficRate.value) {
|
|
||||||
peakTrafficRate.value = currentActivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 格式化当前速度和峰值速度
|
|
||||||
const currentSpeed = formatSpeed(currentActivity);
|
|
||||||
const peakSpeed = formatSpeed(peakTrafficRate.value);
|
|
||||||
|
|
||||||
// 设置速率的最大值
|
|
||||||
const minMax = 1024; // 1KB/s 作为最小最大值
|
|
||||||
const dynamicMax = Math.max(
|
|
||||||
currentSpeed.value * 1.5,
|
|
||||||
peakSpeed.value,
|
|
||||||
minMax
|
|
||||||
);
|
|
||||||
|
|
||||||
// 更新速率数据
|
|
||||||
baseData.value[2] = {
|
|
||||||
...baseData.value[2],
|
|
||||||
value: currentSpeed.value,
|
|
||||||
unit: currentSpeed.unit,
|
|
||||||
max: dynamicMax,
|
|
||||||
subTitle: t('page.headerbanner.maxspeed') + `: ${peakSpeed.value}${peakSpeed.unit}`
|
|
||||||
};
|
|
||||||
|
|
||||||
// 统一更新所有图表
|
|
||||||
updateGauge1(opts => updateGaugeData(opts, baseData.value[0]));
|
|
||||||
updateGauge2(opts => {
|
|
||||||
const newOpts = updateGaugeData(opts, baseData.value[1], progressRatio);
|
|
||||||
// 添加动画配置
|
|
||||||
return {
|
|
||||||
...newOpts,
|
|
||||||
animation: true,
|
|
||||||
animationDuration: 1000,
|
|
||||||
animationEasing: 'cubicInOut'
|
|
||||||
};
|
};
|
||||||
});
|
|
||||||
updateGauge3(opts => updateGaugeData(opts, baseData.value[2]));
|
// 处理流量数据,使用默认值处理可能的空值
|
||||||
|
const totalTraffic = response.traffic || 0;
|
||||||
|
const usedTraffic = response.trafficUsed || 0;
|
||||||
|
const remainingTraffic = Math.max(0, totalTraffic - usedTraffic);
|
||||||
|
const progressRatio = totalTraffic ? Math.min(1, Math.max(0, remainingTraffic / totalTraffic)) : 0;
|
||||||
|
|
||||||
|
// 格式化流量显示
|
||||||
|
const formattedTotal = formatTraffic(totalTraffic);
|
||||||
|
const formattedUsed = formatTraffic(usedTraffic);
|
||||||
|
const formattedRemaining = formatTraffic(remainingTraffic);
|
||||||
|
|
||||||
|
// 更新流量数据显示
|
||||||
|
baseData.value[1] = {
|
||||||
|
...baseData.value[1],
|
||||||
|
value: remainingTraffic,
|
||||||
|
max: totalTraffic,
|
||||||
|
displayValue: `${formattedRemaining.value}${formattedRemaining.unit}`,
|
||||||
|
unit: '',
|
||||||
|
description: `${t('page.headerbanner.monthflowr')} (${formattedTotal.value}${formattedTotal.unit})`,
|
||||||
|
subTitle: t('page.headerbanner.Used') + `: ${formattedUsed.value}${formattedUsed.unit}`
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取当前速率
|
||||||
|
const currentActivity = Number(response.activity ?? 0);
|
||||||
|
|
||||||
|
// 更新峰值速率
|
||||||
|
if (currentActivity > peakTrafficRate.value) {
|
||||||
|
peakTrafficRate.value = currentActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化当前速度和峰值速度
|
||||||
|
const currentSpeed = formatSpeed(currentActivity);
|
||||||
|
const peakSpeed = formatSpeed(peakTrafficRate.value);
|
||||||
|
|
||||||
|
// 设置速率的最大值
|
||||||
|
const minMax = 1024; // 1KB/s 作为最小最大值
|
||||||
|
const dynamicMax = Math.max(
|
||||||
|
currentSpeed.value * 1.5,
|
||||||
|
peakSpeed.value,
|
||||||
|
minMax
|
||||||
|
);
|
||||||
|
|
||||||
|
// 更新速率数据
|
||||||
|
baseData.value[2] = {
|
||||||
|
...baseData.value[2],
|
||||||
|
value: currentSpeed.value,
|
||||||
|
unit: currentSpeed.unit,
|
||||||
|
max: dynamicMax,
|
||||||
|
subTitle: t('page.headerbanner.maxspeed') + `: ${peakSpeed.value}${peakSpeed.unit}`
|
||||||
|
};
|
||||||
|
|
||||||
|
// 静默执行自动上网检查
|
||||||
|
try {
|
||||||
|
await checkAndTriggerAuth(response);
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Auto auth check failed:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新图表
|
||||||
|
updateGauge1(opts => updateGaugeData(opts, baseData.value[0]));
|
||||||
|
updateGauge2(opts => {
|
||||||
|
const newOpts = updateGaugeData(opts, baseData.value[1], progressRatio);
|
||||||
|
return {
|
||||||
|
...newOpts,
|
||||||
|
animation: true,
|
||||||
|
animationDuration: 1000,
|
||||||
|
animationEasing: 'cubicInOut'
|
||||||
|
};
|
||||||
|
});
|
||||||
|
updateGauge3(opts => updateGaugeData(opts, baseData.value[2]));
|
||||||
|
} else {
|
||||||
|
console.warn('Invalid dashboard data structure:', response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch dashboard data:', error);
|
// 只记录真正的错误
|
||||||
|
if (error instanceof Error) {
|
||||||
|
console.warn('Dashboard data update failed:', error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user