This commit is contained in:
@@ -7,11 +7,11 @@
|
|||||||
<view class="device-info flex-col-g16">
|
<view class="device-info flex-col-g16">
|
||||||
<view class="info-row flex-row-sb">
|
<view class="info-row flex-row-sb">
|
||||||
<view class="info-label">
|
<view class="info-label">
|
||||||
<view class="subtitle">当前卡: {{ deviceInfo.currentIccid }}</view>
|
<view class="subtitle">当前卡号 {{ deviceInfo.currentIccid }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="info-values flex-row-g20" @tap="$emit('authentication')">
|
<view class="info-values flex-row-g20" @tap="$emit('authentication')">
|
||||||
<view class="tag-apple" :class="isRealName ? 'tag-success' : 'tag-warning'">
|
<view class="tag-apple" :class="isRealName ? 'tag-success' : 'tag-warning'">
|
||||||
{{ isRealName ? "已实名" : "未实名" }}
|
{{ isRealName ? '已实名' : '未实名' }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -40,7 +40,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
const props = defineProps({
|
import { getNetworkLevelByMetrics } from '@/utils/networkSignal.js';
|
||||||
|
|
||||||
|
defineProps({
|
||||||
deviceInfo: { type: Object, default: () => ({}) },
|
deviceInfo: { type: Object, default: () => ({}) },
|
||||||
isRealName: { type: Boolean, default: false },
|
isRealName: { type: Boolean, default: false },
|
||||||
isDevice: { type: Boolean, default: true },
|
isDevice: { type: Boolean, default: true },
|
||||||
@@ -49,34 +51,8 @@
|
|||||||
|
|
||||||
defineEmits(['authentication']);
|
defineEmits(['authentication']);
|
||||||
|
|
||||||
const normalizeSignalScore = (value, min, max) => {
|
const getSignalText = (deviceInfo) =>
|
||||||
if (value === null || value === undefined || value === '' || value === '-') return null;
|
getNetworkLevelByMetrics(deviceInfo?.rsrp, deviceInfo?.rsrq, deviceInfo?.sinr);
|
||||||
|
|
||||||
const numericValue = Number(value);
|
|
||||||
if (!Number.isFinite(numericValue)) return null;
|
|
||||||
if (numericValue <= min) return 0;
|
|
||||||
if (numericValue >= max) return 100;
|
|
||||||
|
|
||||||
return ((numericValue - min) / (max - min)) * 100;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getSignalText = (deviceInfo) => {
|
|
||||||
const signalScores = [
|
|
||||||
{ score: normalizeSignalScore(deviceInfo?.rsrp, -120, -80), weight: 0.5 },
|
|
||||||
{ score: normalizeSignalScore(deviceInfo?.rsrq, -20, -10), weight: 0.25 },
|
|
||||||
{ score: normalizeSignalScore(deviceInfo?.rssi, -100, -65), weight: 0.25 }
|
|
||||||
].filter(item => item.score !== null);
|
|
||||||
|
|
||||||
if (!signalScores.length) return '-';
|
|
||||||
|
|
||||||
const totalWeight = signalScores.reduce((sum, item) => sum + item.weight, 0);
|
|
||||||
const weightedScore =
|
|
||||||
signalScores.reduce((sum, item) => sum + item.score * item.weight, 0) / totalWeight;
|
|
||||||
|
|
||||||
if (weightedScore >= 67) return '强';
|
|
||||||
if (weightedScore >= 34) return '中';
|
|
||||||
return '弱';
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
@@ -84,15 +60,29 @@
|
|||||||
.info-row {
|
.info-row {
|
||||||
padding: var(--space-sm) 0;
|
padding: var(--space-sm) 0;
|
||||||
border-bottom: 1rpx solid var(--gray-200);
|
border-bottom: 1rpx solid var(--gray-200);
|
||||||
&:last-child { border-bottom: none; }
|
|
||||||
.info-label { min-width: 200rpx; }
|
&:last-child {
|
||||||
.info-values { flex: 1; justify-content: flex-end; }
|
border-bottom: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.info-label {
|
||||||
|
min-width: 200rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-values {
|
||||||
|
flex: 1;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.device-metrics {
|
.device-metrics {
|
||||||
background: var(--gray-100);
|
background: var(--gray-100);
|
||||||
border-radius: var(--radius-small);
|
border-radius: var(--radius-small);
|
||||||
padding: 20rpx;
|
padding: 20rpx;
|
||||||
.metric-item { flex: 1; }
|
|
||||||
|
.metric-item {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -158,6 +158,7 @@
|
|||||||
rssi: '-',
|
rssi: '-',
|
||||||
rsrp: '-',
|
rsrp: '-',
|
||||||
rsrq: '-',
|
rsrq: '-',
|
||||||
|
sinr: '-',
|
||||||
onlineStatus: '0',
|
onlineStatus: '0',
|
||||||
connCnt: 0,
|
connCnt: 0,
|
||||||
run_time: 0,
|
run_time: 0,
|
||||||
@@ -270,6 +271,7 @@
|
|||||||
deviceInfo.rssi = rt.rssi ?? '-';
|
deviceInfo.rssi = rt.rssi ?? '-';
|
||||||
deviceInfo.rsrp = rt.rsrp ?? '-';
|
deviceInfo.rsrp = rt.rsrp ?? '-';
|
||||||
deviceInfo.rsrq = rt.rsrq ?? '-';
|
deviceInfo.rsrq = rt.rsrq ?? '-';
|
||||||
|
deviceInfo.sinr = rt.sinr ?? '-';
|
||||||
} else {
|
} else {
|
||||||
// 没有实时信息时设置默认值
|
// 没有实时信息时设置默认值
|
||||||
deviceInfo.onlineStatus = '0';
|
deviceInfo.onlineStatus = '0';
|
||||||
@@ -283,6 +285,7 @@
|
|||||||
deviceInfo.rssi = '-';
|
deviceInfo.rssi = '-';
|
||||||
deviceInfo.rsrp = '-';
|
deviceInfo.rsrp = '-';
|
||||||
deviceInfo.rsrq = '-';
|
deviceInfo.rsrq = '-';
|
||||||
|
deviceInfo.sinr = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 到期时间由 TrafficCard 组件获取套餐信息时一并返回
|
// 到期时间由 TrafficCard 组件获取套餐信息时一并返回
|
||||||
|
|||||||
39
utils/networkSignal.js
Normal file
39
utils/networkSignal.js
Normal file
@@ -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));
|
||||||
Reference in New Issue
Block a user