fix: req:bug
This commit is contained in:
@@ -335,19 +335,24 @@
|
||||
ref="bindCardFormRef"
|
||||
:model="bindCardForm"
|
||||
:rules="bindCardRules"
|
||||
label-width="100px"
|
||||
label-width="80"
|
||||
>
|
||||
<ElRow :gutter="20">
|
||||
<ElCol :span="10">
|
||||
<ElFormItem label="IoT卡" prop="iot_card_id">
|
||||
<ElSelect
|
||||
v-model="bindCardForm.iot_card_id"
|
||||
placeholder="请选择或搜索IoT卡(支持ICCID搜索)"
|
||||
:placeholder="
|
||||
iotCardList.length === 0 && !iotCardSearchLoading
|
||||
? '当前没有未绑定设备的卡'
|
||||
: '请选择或搜索IoT卡(支持ICCID搜索)'
|
||||
"
|
||||
filterable
|
||||
remote
|
||||
reserve-keyword
|
||||
:remote-method="searchIotCards"
|
||||
:loading="iotCardSearchLoading"
|
||||
:disabled="iotCardList.length === 0 && !iotCardSearchLoading"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
@@ -376,7 +381,7 @@
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
<ElCol :span="4">
|
||||
<ElCol :span="3">
|
||||
<ElButton
|
||||
type="primary"
|
||||
@click="handleConfirmBindCard"
|
||||
@@ -438,76 +443,14 @@
|
||||
</ElDialog>
|
||||
|
||||
<!-- 切换SIM卡对话框 -->
|
||||
<ElDialog v-model="switchCardDialogVisible" title="切换SIM卡" width="600px">
|
||||
<div v-if="loadingDeviceCards" style="padding: 40px; text-align: center">
|
||||
<ElIcon class="is-loading" :size="40"><Loading /></ElIcon>
|
||||
<div style="margin-top: 16px">加载设备绑定的卡列表中...</div>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<ElAlert
|
||||
v-if="deviceBindingCards.length === 0"
|
||||
title="该设备暂无绑定的SIM卡"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
style="margin-bottom: 20px"
|
||||
>
|
||||
<template #default>
|
||||
<div>当前设备没有绑定任何SIM卡,无法进行切换操作。</div>
|
||||
<div>请先为设备绑定SIM卡后再进行切换。</div>
|
||||
</template>
|
||||
</ElAlert>
|
||||
|
||||
<ElForm
|
||||
v-if="deviceBindingCards.length > 0"
|
||||
ref="switchCardFormRef"
|
||||
:model="switchCardForm"
|
||||
:rules="switchCardRules"
|
||||
label-width="120px"
|
||||
>
|
||||
<ElFormItem label="设备号">
|
||||
<span style="font-weight: bold; color: #409eff">{{ currentOperatingImei }}</span>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="目标ICCID" prop="target_iccid">
|
||||
<ElSelect
|
||||
v-model="switchCardForm.target_iccid"
|
||||
placeholder="请选择要切换到的目标ICCID"
|
||||
style="width: 100%"
|
||||
clearable
|
||||
>
|
||||
<ElOption
|
||||
v-for="card in deviceBindingCards"
|
||||
:key="card.iccid"
|
||||
:label="`${card.iccid} - 插槽${card.slot_position} - ${card.carrier_name}${card.is_current ? ' (当前)' : ''}`"
|
||||
:value="card.iccid"
|
||||
>
|
||||
<div style="display: flex; align-items: center; justify-content: space-between">
|
||||
<span>{{ card.iccid }}</span>
|
||||
<ElTag size="small" style="margin-left: 10px"
|
||||
>插槽{{ card.slot_position }}</ElTag
|
||||
>
|
||||
</div>
|
||||
</ElOption>
|
||||
</ElSelect>
|
||||
<div style="margin-top: 8px; font-size: 12px; color: #909399">
|
||||
当前设备共绑定 {{ deviceBindingCards.length }} 张SIM卡
|
||||
</div>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<ElButton @click="switchCardDialogVisible = false">取消</ElButton>
|
||||
<ElButton
|
||||
v-if="deviceBindingCards.length > 0"
|
||||
type="primary"
|
||||
@click="handleConfirmSwitchCard"
|
||||
:loading="switchCardLoading"
|
||||
>
|
||||
确认切换
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
<SwitchCardDialog
|
||||
v-model="switchCardDialogVisible"
|
||||
:device-info="currentOperatingImei"
|
||||
:cards="deviceBindingCards"
|
||||
:loading="loadingDeviceCards"
|
||||
:confirm-loading="switchCardLoading"
|
||||
@confirm="handleConfirmSwitchCard"
|
||||
/>
|
||||
|
||||
<!-- 设置WiFi对话框 -->
|
||||
<ElDialog v-model="setWiFiDialogVisible" title="设置WiFi" width="500px">
|
||||
@@ -566,7 +509,9 @@
|
||||
label-width="120px"
|
||||
>
|
||||
<ElFormItem label="设备标识">
|
||||
<span style="font-weight: bold; color: #409eff">{{ currentOperatingDeviceIdentifier }}</span>
|
||||
<span style="font-weight: bold; color: #409eff">{{
|
||||
currentOperatingDeviceIdentifier
|
||||
}}</span>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="当前模式">
|
||||
<ElTag :type="currentDeviceSwitchMode === 0 ? 'success' : 'warning'">
|
||||
@@ -621,6 +566,7 @@
|
||||
import { ElMessage, ElMessageBox, ElTag, ElIcon, ElRadioGroup, ElRadio } from 'element-plus'
|
||||
import { Loading } from '@element-plus/icons-vue'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import SwitchCardDialog from '@/components/device/SwitchCardDialog.vue'
|
||||
import type {
|
||||
Device,
|
||||
DeviceStatus,
|
||||
@@ -708,6 +654,7 @@
|
||||
const bindCardFormRef = ref<FormInstance>()
|
||||
const iotCardList = ref<any[]>([])
|
||||
const iotCardSearchLoading = ref(false)
|
||||
const iotCardHasSearched = ref(false) // 标记是否已执行过搜索
|
||||
const bindCardForm = reactive({
|
||||
iot_card_id: undefined as number | undefined,
|
||||
slot_position: 1
|
||||
@@ -724,13 +671,6 @@
|
||||
|
||||
const switchCardDialogVisible = ref(false)
|
||||
const switchCardLoading = ref(false)
|
||||
const switchCardFormRef = ref<FormInstance>()
|
||||
const switchCardForm = reactive({
|
||||
target_iccid: ''
|
||||
})
|
||||
const switchCardRules = reactive<FormRules>({
|
||||
target_iccid: [{ required: true, message: '请选择目标ICCID', trigger: 'change' }]
|
||||
})
|
||||
const deviceBindingCards = ref<any[]>([]) // 设备绑定的卡列表
|
||||
const loadingDeviceCards = ref(false) // 加载设备绑定卡列表的状态
|
||||
|
||||
@@ -868,7 +808,7 @@
|
||||
{ label: '已绑定卡数', prop: 'bound_card_count' },
|
||||
{ label: '状态', prop: 'status' },
|
||||
{ label: '在线状态', prop: 'online_status' },
|
||||
{ label: '固件版本', prop: 'software_version' },
|
||||
|
||||
{ label: '切卡模式', prop: 'switch_mode' },
|
||||
{ label: '最后在线时间', prop: 'last_online_time' },
|
||||
{ label: '最后同步时间', prop: 'last_gateway_sync_at' },
|
||||
@@ -917,8 +857,8 @@
|
||||
// 重置绑定卡表单
|
||||
bindCardForm.iot_card_id = undefined
|
||||
bindCardForm.slot_position = 1
|
||||
// 加载设备卡列表和默认IoT卡列表
|
||||
await Promise.all([loadDeviceCards(device.virtual_no), loadDefaultIotCards()])
|
||||
// 只加载设备卡列表
|
||||
await loadDeviceCards(device.virtual_no)
|
||||
}
|
||||
|
||||
// 加载设备绑定的卡列表
|
||||
@@ -927,15 +867,9 @@
|
||||
try {
|
||||
const res = await DeviceService.getDeviceCards(virtualNo)
|
||||
if (res.code === 0 && res.data) {
|
||||
deviceCards.value = res.data.bindings || []
|
||||
console.log('设备绑定的卡列表:', deviceCards.value)
|
||||
|
||||
// 🔧 临时调试:强制第一张卡显示为当前卡(方便测试UI效果)
|
||||
// 测试完成后请删除此代码
|
||||
if (deviceCards.value.length > 0) {
|
||||
deviceCards.value[0].is_current = true
|
||||
console.log('🧪 测试模式:已将第一张卡标记为当前卡')
|
||||
}
|
||||
deviceCards.value = (res.data.bindings || []).sort(
|
||||
(a, b) => a.slot_position - b.slot_position
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备绑定的卡列表失败:', error)
|
||||
@@ -950,7 +884,8 @@
|
||||
try {
|
||||
const res = await CardService.getStandaloneIotCards({
|
||||
page: 1,
|
||||
page_size: 20
|
||||
page_size: 20,
|
||||
is_standalone: true
|
||||
})
|
||||
if (res.code === 0 && res.data?.items) {
|
||||
iotCardList.value = res.data.items
|
||||
@@ -969,11 +904,13 @@
|
||||
return
|
||||
}
|
||||
iotCardSearchLoading.value = true
|
||||
iotCardHasSearched.value = true
|
||||
try {
|
||||
const res = await CardService.getStandaloneIotCards({
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
iccid: query
|
||||
iccid: query,
|
||||
is_standalone: true
|
||||
})
|
||||
if (res.code === 0 && res.data?.items) {
|
||||
iotCardList.value = res.data.items
|
||||
@@ -1182,13 +1119,6 @@
|
||||
return h(ElTag, { type: status.type }, () => status.text)
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: 'software_version',
|
||||
label: '固件版本',
|
||||
width: 120,
|
||||
showOverflowTooltip: true,
|
||||
formatter: (row: Device) => row.software_version || '-'
|
||||
},
|
||||
{
|
||||
prop: 'switch_mode',
|
||||
label: '切卡模式',
|
||||
@@ -1201,6 +1131,20 @@
|
||||
return modeMap[row.switch_mode || ''] || '-'
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: 'realname_policy',
|
||||
label: '实名认证策略',
|
||||
width: 150,
|
||||
formatter: (row: Device) => {
|
||||
const policy = row.realname_policy || ''
|
||||
const policyMap: Record<string, string> = {
|
||||
none: '无需实名',
|
||||
before_order: '先实名后充值/购买',
|
||||
after_order: '先充值/购买后实名'
|
||||
}
|
||||
return policyMap[policy] || (policy ? policy : '未知')
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: 'last_online_time',
|
||||
label: '最后在线时间',
|
||||
@@ -1229,13 +1173,17 @@
|
||||
}
|
||||
])
|
||||
|
||||
let isFirstActivation = true
|
||||
onMounted(() => {
|
||||
getTableData()
|
||||
})
|
||||
|
||||
// 当页面被 keep-alive 激活时自动刷新数据
|
||||
onActivated(() => {
|
||||
getTableData()
|
||||
if (!isFirstActivation) {
|
||||
getTableData()
|
||||
}
|
||||
isFirstActivation = false
|
||||
})
|
||||
|
||||
// 获取设备列表
|
||||
@@ -1758,7 +1706,6 @@
|
||||
// 显示切换SIM卡对话框
|
||||
const showSwitchCardDialog = async (imei: string) => {
|
||||
currentOperatingImei.value = imei
|
||||
switchCardForm.target_iccid = ''
|
||||
deviceBindingCards.value = []
|
||||
switchCardDialogVisible.value = true
|
||||
|
||||
@@ -1775,14 +1722,6 @@
|
||||
const res = await DeviceService.getDeviceCards(device.virtual_no)
|
||||
if (res.code === 0 && res.data) {
|
||||
deviceBindingCards.value = res.data.bindings || []
|
||||
|
||||
// 🔧 临时调试:强制第一张卡显示为当前卡(方便测试UI效果)
|
||||
// 测试完成后请删除此代码
|
||||
if (deviceBindingCards.value.length > 0) {
|
||||
deviceBindingCards.value[0].is_current = true
|
||||
console.log('🧪 切换SIM卡测试模式:已将第一张卡标记为当前卡')
|
||||
}
|
||||
|
||||
if (deviceBindingCards.value.length === 0) {
|
||||
ElMessage.warning('该设备暂无绑定的SIM卡')
|
||||
}
|
||||
@@ -1795,29 +1734,20 @@
|
||||
}
|
||||
|
||||
// 确认切换SIM卡
|
||||
const handleConfirmSwitchCard = async () => {
|
||||
if (!switchCardFormRef.value) return
|
||||
|
||||
await switchCardFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
switchCardLoading.value = true
|
||||
try {
|
||||
const res = await DeviceService.switchCard(currentOperatingImei.value, {
|
||||
target_iccid: switchCardForm.target_iccid
|
||||
})
|
||||
if (res.code === 0) {
|
||||
ElMessage.success('切换SIM卡指令已发送')
|
||||
switchCardDialogVisible.value = false
|
||||
} else {
|
||||
ElMessage.error(res.msg || '切换失败')
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('切换SIM卡失败:', error)
|
||||
} finally {
|
||||
switchCardLoading.value = false
|
||||
}
|
||||
const handleConfirmSwitchCard = async (data: { target_iccid: string }) => {
|
||||
try {
|
||||
const res = await DeviceService.switchCard(currentOperatingImei.value, {
|
||||
target_iccid: data.target_iccid
|
||||
})
|
||||
if (res.code === 0) {
|
||||
ElMessage.success('切换SIM卡指令已发送')
|
||||
switchCardDialogVisible.value = false
|
||||
} else {
|
||||
ElMessage.error(res.msg || '切换失败')
|
||||
}
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('切换SIM卡失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 显示设置WiFi对话框
|
||||
|
||||
Reference in New Issue
Block a user