fix: 修改index数据来源
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 44s

This commit is contained in:
sexygoat
2026-04-14 10:50:48 +08:00
parent 1a407924de
commit 5fa2b6dacf
4 changed files with 108 additions and 56 deletions

View File

@@ -47,6 +47,8 @@
identifier: { type: String, default: '' }
});
const emit = defineEmits(['packageLoaded']);
const userStore = useUserStore();
// 流量数据
@@ -117,11 +119,15 @@
totalMB.value = activePackage.data_limit_mb || 0;
remainMB.value = totalMB.value - usedMB.value;
}
// 将套餐信息(包括到期时间)传递给父组件
emit('packageLoaded', activePackage);
} else {
// 没有生效中的套餐
usedMB.value = 0;
totalMB.value = 0;
remainMB.value = 0;
emit('packageLoaded', null);
}
} catch (e) {
console.error('加载套餐流量数据失败', e);

View File

@@ -32,7 +32,7 @@
<script setup>
import { ref, reactive, onMounted } from 'vue';
import { assetApi, realnameApi } from '@/api/index.js';
import { deviceApi, realnameApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
const userStore = useUserStore();
@@ -55,11 +55,11 @@
const loadCards = async () => {
try {
const data = await assetApi.getInfo(userStore.state.identifier);
const data = await deviceApi.getCards(userStore.state.identifier);
if (data.cards && data.cards.length > 0) {
list.splice(0, list.length, ...data.cards.map(card => ({
iccid: card.iccid,
category: card.carrier_name.includes('电信') ? '124' : card.carrier_name.includes('联通') ? '125' : '126',
category: getCarrierCategory(card.carrier_name),
isRealName: card.real_name_status === 1
})));
}
@@ -68,6 +68,14 @@
}
};
const getCarrierCategory = (carrierName) => {
if (!carrierName) return '126';
if (carrierName.includes('电信')) return '124';
if (carrierName.includes('联通')) return '125';
if (carrierName.includes('移动')) return '126';
return '126';
};
const toReal = async (card) => {
currentCard.value = card;
currentModalIccid.value = card.iccid;

View File

@@ -8,7 +8,7 @@
<VoiceCard v-if="!userInfo.isDevice" :voiceStats="voiceStats" :dateRangeText="dateRangeText"
@openDatePicker="openDateRangePicker" />
<TrafficCard :identifier="currentCardNo" />
<TrafficCard :identifier="currentCardNo" @packageLoaded="handlePackageLoaded" />
<WhitelistCard v-if="!userInfo.isDevice" :whitelistData="whitelistData" @refresh="refreshWhitelist"
@add="showAddWhitelistDialog" @showSms="showSmsCodeDialog" />
@@ -120,8 +120,13 @@
import WifiCard from '@/components/WifiCard.vue';
import FunctionCard from '@/components/FunctionCard.vue';
import FloatingButton from '@/components/FloatingButton.vue';
import { assetApi, deviceApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
import {
assetApi,
deviceApi
} from '@/api/index.js';
import {
useUserStore
} from '@/store/index.js';
const userStore = useUserStore();
@@ -137,26 +142,26 @@
});
let deviceInfo = reactive({
battery: 100,
battery: 0,
connect: 0,
status: 1,
expireDate: '',
currentIccid: '',
category: '',
phone: '',
expireDate: '-',
currentIccid: '-',
category: '-',
phone: '-',
flowSize: 0,
totalBytesCnt: 0,
ssidName: '',
ssidPwd: '',
rssi: '',
ssidName: '-',
ssidPwd: '-',
rssi: '-',
onlineStatus: '0',
connCnt: 0,
run_time: 0,
last_online_time: '',
lan_ip: '',
kf_url: '',
last_online_time: '-',
lan_ip: '-',
kf_url: '-',
mchList: [],
imei: '',
imei: '-',
max_clients: 1
});
@@ -206,9 +211,9 @@
// 基本信息
userInfo.isDevice = data.asset_type === 'device';
currentCardNo.value = data.identifier;
deviceInfo.status = data.status;
deviceInfo.imei = data.imei || '';
currentCardNo.value = data.identifier || '-';
deviceInfo.status = data.status || 1;
deviceInfo.imei = data.imei || '-';
isRealName.value = data.real_name_status === 1;
realNameStatus.value = data.real_name_status === 1 ? '已实名' : '未实名';
boundPhone.value = data.bound_phone || '';
@@ -220,32 +225,45 @@
if (data.cards && data.cards.length > 0) {
// 找到当前卡
const currentCard = data.cards.find(card => card.is_current) || data.cards[0];
deviceInfo.currentIccid = currentCard.iccid;
deviceInfo.currentIccid = currentCard.iccid || '-';
// 卡列表
deviceInfo.mchList = data.cards.map(card => ({
iccidMark: card.iccid,
iccidMark: card.iccid || '-',
category: card.slot_position,
is_current: card.is_current
}));
} else {
deviceInfo.currentIccid = '-';
deviceInfo.mchList = [];
}
// 设备实时信息
if (data.device_realtime) {
const rt = data.device_realtime;
deviceInfo.onlineStatus = rt.online_status === 1 ? '1' : '0';
deviceInfo.battery = rt.battery_level || 100;
deviceInfo.ssidName = rt.ssid || '';
deviceInfo.ssidPwd = rt.wifi_password || '';
deviceInfo.lan_ip = rt.lan_ip || '';
deviceInfo.connCnt = rt.client_number || 0;
deviceInfo.max_clients = rt.max_clients || 1;
deviceInfo.battery = rt.battery_level ?? 0;
deviceInfo.ssidName = rt.ssid || '-';
deviceInfo.ssidPwd = rt.wifi_password || '-';
deviceInfo.lan_ip = rt.lan_ip || '-';
deviceInfo.connCnt = rt.client_number ?? 0;
deviceInfo.max_clients = rt.max_clients ?? 1;
deviceInfo.run_time = rt.run_time || 0;
deviceInfo.rssi = calculateSignalStrength(rt.rsrp, rt.rsrq, rt.rssi);
} else {
// 没有实时信息时设置默认值
deviceInfo.onlineStatus = '0';
deviceInfo.battery = 0;
deviceInfo.ssidName = '-';
deviceInfo.ssidPwd = '-';
deviceInfo.lan_ip = '-';
deviceInfo.connCnt = 0;
deviceInfo.max_clients = 1;
deviceInfo.run_time = 0;
deviceInfo.rssi = '-';
}
// 获取到期时间(从套餐历史中获取)
await loadExpireDate(identifier);
// 到期时间由 TrafficCard 组件获取套餐信息时一并返回
} catch (e) {
console.error('加载资产信息失败', e);
}
@@ -255,29 +273,24 @@
// 计算信号强度
const calculateSignalStrength = (rsrp, rsrq, rssi) => {
// 简单的信号强度计算逻辑
if (!rsrp && !rsrq && !rssi) return '';
if (!rsrp && !rsrq && !rssi) return '-';
const rsrpNum = parseInt(rsrp);
if (isNaN(rsrpNum)) return '-';
const rsrpNum = parseInt(rsrp) || 0;
if (rsrpNum >= -80) return '强';
if (rsrpNum >= -95) return '中';
return '弱';
};
// 获取到期时间(从生效中的套餐获取
const loadExpireDate = async (identifier) => {
try {
const historyData = await assetApi.getPackageHistory(identifier, 1, 10, { status: 1 });
if (historyData.items && historyData.items.length > 0) {
// 找到生效中的套餐
const activePackage = historyData.items.find(item => item.status === 1);
if (activePackage && activePackage.expires_at) {
// 格式化日期
const date = new Date(activePackage.expires_at);
deviceInfo.expireDate = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
}
}
} catch (e) {
console.error('获取到期时间失败', e);
// 处理套餐加载完成事件(从 TrafficCard 组件传递过来
const handlePackageLoaded = (activePackage) => {
if (activePackage && activePackage.expires_at) {
// 格式化到期时间
const date = new Date(activePackage.expires_at);
deviceInfo.expireDate = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
} else {
deviceInfo.expireDate = '-';
}
};
@@ -297,7 +310,10 @@
);
deviceInfo.ssidName = wifi_info.ssid;
deviceInfo.ssidPwd = wifi_info.pwd;
uni.showToast({ title: '修改成功', icon: 'success' });
uni.showToast({
title: '修改成功',
icon: 'success'
});
} catch (e) {
console.error('修改WiFi失败', e);
}
@@ -308,6 +324,7 @@
title: '正在跳转客服',
icon: 'none'
});
const enterBack = () => uni.showToast({
title: '正在跳转后台',
icon: 'none'
@@ -316,7 +333,10 @@
const YesRestart = async () => {
try {
await deviceApi.reboot(userStore.state.identifier);
uni.showToast({ title: '重启指令已发送', icon: 'success' });
uni.showToast({
title: '重启指令已发送',
icon: 'success'
});
} catch (e) {
console.error('重启设备失败', e);
}
@@ -336,7 +356,10 @@
const YesRecover = async () => {
try {
await deviceApi.factoryReset(userStore.state.identifier);
uni.showToast({ title: '恢复出厂设置指令已发送', icon: 'success' });
uni.showToast({
title: '恢复出厂设置指令已发送',
icon: 'success'
});
} catch (e) {
console.error('恢复出厂设置失败', e);
}
@@ -474,7 +497,10 @@
};
const onSync = () => {
uni.showToast({ title: '同步成功', icon: 'success' });
uni.showToast({
title: '同步成功',
icon: 'success'
});
};
const enterDetail = (name) => {

View File

@@ -35,7 +35,7 @@
<script setup>
import { reactive, ref, onMounted } from 'vue';
import { deviceApi, assetApi } from '@/api/index.js';
import { deviceApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
const userStore = useUserStore();
@@ -56,11 +56,15 @@
const loadCards = async () => {
try {
const data = await assetApi.getInfo(userStore.state.identifier);
const data = await deviceApi.getCards(userStore.state.identifier);
if (data.cards && data.cards.length > 0) {
mchList.splice(0, mchList.length, ...data.cards.map(card => ({
...card,
category: card.carrier_name.includes('电信') ? '124' : card.carrier_name.includes('联通') ? '125' : '126'
iccid: card.iccid,
carrier_name: card.carrier_name,
is_current: card.is_active,
real_name_status: card.real_name_status,
slot_position: card.slot_position,
category: getCarrierCategory(card.carrier_name)
})));
}
} catch (e) {
@@ -68,6 +72,14 @@
}
};
const getCarrierCategory = (carrierName) => {
if (!carrierName) return '126';
if (carrierName.includes('电信')) return '124';
if (carrierName.includes('联通')) return '125';
if (carrierName.includes('移动')) return '126';
return '126';
};
const switchOperator = async (item) => {
switching.value = true;
try {