diff --git a/components/DeviceStatusCard.vue b/components/DeviceStatusCard.vue index 18f7083..07fd8ee 100644 --- a/components/DeviceStatusCard.vue +++ b/components/DeviceStatusCard.vue @@ -7,11 +7,11 @@ - 当前卡: {{ deviceInfo.currentIccid }} + 当前卡号 {{ deviceInfo.currentIccid }} - {{ isRealName ? "已实名" : "未实名" }} + {{ isRealName ? '已实名' : '未实名' }} @@ -40,7 +40,9 @@ diff --git a/pages/index/index.vue b/pages/index/index.vue index 14eece9..f0dee05 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -158,6 +158,7 @@ rssi: '-', rsrp: '-', rsrq: '-', + sinr: '-', onlineStatus: '0', connCnt: 0, run_time: 0, @@ -270,6 +271,7 @@ deviceInfo.rssi = rt.rssi ?? '-'; deviceInfo.rsrp = rt.rsrp ?? '-'; deviceInfo.rsrq = rt.rsrq ?? '-'; + deviceInfo.sinr = rt.sinr ?? '-'; } else { // 没有实时信息时设置默认值 deviceInfo.onlineStatus = '0'; @@ -283,6 +285,7 @@ deviceInfo.rssi = '-'; deviceInfo.rsrp = '-'; deviceInfo.rsrq = '-'; + deviceInfo.sinr = '-'; } // 到期时间由 TrafficCard 组件获取套餐信息时一并返回 diff --git a/utils/networkSignal.js b/utils/networkSignal.js new file mode 100644 index 0000000..97fbf0e --- /dev/null +++ b/utils/networkSignal.js @@ -0,0 +1,39 @@ +const isEmptyValue = (value) => value === null || value === undefined || value === '' || value === '-'; + +const toFiniteNumber = (value) => { + if (isEmptyValue(value)) return null; + + const numericValue = Number(value); + return Number.isFinite(numericValue) ? numericValue : null; +}; + +const clampScore = (value) => Math.min(Math.max(value, 0), 100); + +export const getNetworkScore = (rsrp, rsrq, sinr) => { + const rsrpValue = toFiniteNumber(rsrp); + const rsrqValue = toFiniteNumber(rsrq); + const sinrValue = toFiniteNumber(sinr); + + const metrics = [ + { score: rsrpValue === null ? null : clampScore((rsrpValue + 120) * 2), weight: 0.5 }, + { score: sinrValue === null ? null : clampScore(sinrValue * 5), weight: 0.3 }, + { score: rsrqValue === null ? null : clampScore((rsrqValue + 20) * 5), weight: 0.2 } + ].filter(item => item.score !== null); + + if (!metrics.length) return null; + + const totalWeight = metrics.reduce((sum, item) => sum + item.weight, 0); + return metrics.reduce((sum, item) => sum + item.score * item.weight, 0) / totalWeight; +}; + +export const getNetworkLevel = (score) => { + if (score === null || score === undefined || !Number.isFinite(score)) return '-'; + if (score >= 85) return '极好'; + if (score >= 70) return '良好'; + if (score >= 50) return '一般'; + if (score >= 30) return '较差'; + return '很差'; +}; + +export const getNetworkLevelByMetrics = (rsrp, rsrq, sinr) => + getNetworkLevel(getNetworkScore(rsrp, rsrq, sinr));