This commit is contained in:
@@ -9,6 +9,22 @@
|
||||
</ElTag>
|
||||
</div>
|
||||
<div class="card-header-right">
|
||||
<ElButton
|
||||
v-if="
|
||||
cardInfo?.asset_type === 'card' &&
|
||||
cardInfo.asset_id > 0 &&
|
||||
hasAuth('iot_info:polling_state')
|
||||
"
|
||||
link
|
||||
type="primary"
|
||||
@click="
|
||||
emit('showPollingState', {
|
||||
cardId: cardInfo.asset_id,
|
||||
iccid: cardInfo.iccid || cardInfo.identifier
|
||||
})
|
||||
"
|
||||
>轮询状态</ElButton
|
||||
>
|
||||
<ElButton
|
||||
v-if="
|
||||
cardInfo?.asset_type === 'card' &&
|
||||
@@ -501,6 +517,18 @@
|
||||
</div>
|
||||
|
||||
<div class="binding-card-actions">
|
||||
<ElButton
|
||||
v-if="
|
||||
bindingCard.card_id != null &&
|
||||
bindingCard.card_id > 0 &&
|
||||
hasAuth('device_info:polling_state')
|
||||
"
|
||||
type="primary"
|
||||
@click="
|
||||
emit('showPollingState', { cardId: bindingCard.card_id!, iccid: bindingCard.iccid })
|
||||
"
|
||||
>轮询状态</ElButton
|
||||
>
|
||||
<ElButton
|
||||
v-if="bindingCard.card_id != null && hasAuth('device_info:stop_resume_records')"
|
||||
type="primary"
|
||||
@@ -938,6 +966,7 @@
|
||||
// Emits
|
||||
interface Emits {
|
||||
(e: 'showStopResumeRecords', payload: { cardId: number; iccid: string }): void
|
||||
(e: 'showPollingState', payload: { cardId: number; iccid: string }): void
|
||||
(e: 'update:pollingEnabled', value: boolean): void
|
||||
(e: 'enableCard'): void
|
||||
(e: 'disableCard'): void
|
||||
|
||||
@@ -249,7 +249,6 @@ export function useAssetInfo() {
|
||||
max_sim_slots: data.max_sim_slots || 0,
|
||||
bound_card_count: data.bound_card_count || 0,
|
||||
cards: (data.cards || []).map((card) => ({ ...card })),
|
||||
device_protect_status: data.device_protect_status,
|
||||
online_status: data.online_status,
|
||||
last_online_time: data.last_online_time,
|
||||
software_version: data.software_version,
|
||||
@@ -436,6 +435,8 @@ export function useAssetInfo() {
|
||||
) {
|
||||
return
|
||||
}
|
||||
if (typeof data.enable_polling === 'boolean')
|
||||
cardInfo.value.enable_polling = data.enable_polling
|
||||
// 更新实时状态数据
|
||||
if (assetType === 'card') {
|
||||
// 卡的实时状态
|
||||
@@ -472,9 +473,6 @@ export function useAssetInfo() {
|
||||
}
|
||||
} else if (assetType === 'device') {
|
||||
// 设备的实时状态
|
||||
if (data.device_protect_status !== undefined) {
|
||||
cardInfo.value.device_protect_status = data.device_protect_status
|
||||
}
|
||||
if (data.cards && data.cards.length > 0) {
|
||||
// 实时 cards 可能缺少部分卡或静态字段,不能替换详情里的完整绑定列表。
|
||||
cardInfo.value.cards = mergeAssetBoundCards(cardInfo.value.cards || [], data.cards)
|
||||
|
||||
@@ -2,6 +2,8 @@ import { ref } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { AssetService, DeviceService } from '@/api/modules'
|
||||
import { PollingSchedulerService } from '@/api/modules/pollingScheduler'
|
||||
import { gatewayData, gatewayError } from '@/utils/business/gateway'
|
||||
import { formatRemainingTime, FrontendRateLimitError } from '@/utils/business/apiRateLimit'
|
||||
|
||||
/**
|
||||
@@ -248,6 +250,7 @@ export function useAssetOperations(cardInfo: Ref<any>, refreshAssetFn?: () => Pr
|
||||
* Update polling status
|
||||
*/
|
||||
const updatePollingStatus = async (enabled: boolean) => {
|
||||
if (pollingLoading.value) return false
|
||||
if (!cardInfo.value) {
|
||||
ElMessage.warning('无法更新轮询状态:缺少资产信息')
|
||||
return false
|
||||
@@ -257,7 +260,12 @@ export function useAssetOperations(cardInfo: Ref<any>, refreshAssetFn?: () => Pr
|
||||
pollingLoading.value = true
|
||||
const identifier =
|
||||
cardInfo.value.asset_type === 'card' ? cardInfo.value.iccid : cardInfo.value.virtual_no
|
||||
|
||||
const target = cardInfo.value
|
||||
const impact = gatewayData(await PollingSchedulerService.getImpact())
|
||||
const lines = impact[enabled ? 'enable' : 'disable']
|
||||
if (!Array.isArray(lines) || !lines.length) throw new Error('未获取到有效操作影响说明')
|
||||
await ElMessageBox.confirm(lines.join('\n'), '确认轮询开关影响', { type: 'warning' })
|
||||
if (cardInfo.value !== target) return false
|
||||
const response = await AssetService.updatePollingStatus(identifier, {
|
||||
enable_polling: enabled
|
||||
})
|
||||
@@ -265,17 +273,17 @@ export function useAssetOperations(cardInfo: Ref<any>, refreshAssetFn?: () => Pr
|
||||
if (response.code === 0) {
|
||||
ElMessage.success(enabled ? '已开启自动轮询' : '已关闭自动轮询')
|
||||
// Update local state
|
||||
if (cardInfo.value) {
|
||||
if (cardInfo.value === target) {
|
||||
cardInfo.value.enable_polling = enabled
|
||||
}
|
||||
if (refreshAssetFn && cardInfo.value === target) await refreshAssetFn()
|
||||
return true
|
||||
} else {
|
||||
ElMessage.error(response.msg || '更新轮询状态失败')
|
||||
return false
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('更新轮询状态失败:', error)
|
||||
console.log(error?.message || '更新轮询状态失败')
|
||||
if (error !== 'cancel' && error !== 'close') ElMessage.error(gatewayError(error))
|
||||
return false
|
||||
} finally {
|
||||
pollingLoading.value = false
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
@show-realname-policy="showRealnamePolicyDialog"
|
||||
@show-speed-limit="speedLimitDialogVisible = true"
|
||||
@show-stop-resume-records="showStopResumeRecords"
|
||||
@show-polling-state="showPollingState"
|
||||
@show-update-realname-status="showUpdateRealnameStatusDialog"
|
||||
@enable-binding-card="handleEnableBindingCard"
|
||||
@disable-binding-card="handleDisableBindingCard"
|
||||
@@ -187,6 +188,13 @@
|
||||
@confirm="handleSpeedTierConfirm"
|
||||
/>
|
||||
</div>
|
||||
<PollingStateDialog
|
||||
v-if="pollingStateTarget"
|
||||
:key="pollingStateTarget.cardId"
|
||||
:card-id="pollingStateTarget.cardId"
|
||||
:permission="pollingStatePermission"
|
||||
@close="pollingStateTarget = null"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -199,6 +207,8 @@
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { GATEWAY_PERMISSIONS } from '@/config/constants/gateway'
|
||||
import StopResumeRecords from '@/components/business/gateway/StopResumeRecords.vue'
|
||||
import PollingStateDialog from '@/components/business/polling/PollingStateDialog.vue'
|
||||
import { SCHEDULER_PERMISSIONS } from '@/config/constants/pollingScheduler'
|
||||
import {
|
||||
formatRemainingTime,
|
||||
FrontendRateLimitError,
|
||||
@@ -302,6 +312,29 @@
|
||||
const dailyRecordsDialogVisible = ref(false)
|
||||
const orderHistoryDialogVisible = ref(false)
|
||||
const stopResumeVisible = ref(false)
|
||||
const pollingStateTarget = ref<{ cardId: number; iccid: string } | null>(null)
|
||||
const pollingStatePermission = computed(() =>
|
||||
cardInfo.value?.asset_type === 'card'
|
||||
? SCHEDULER_PERMISSIONS.cardState
|
||||
: SCHEDULER_PERMISSIONS.deviceCardState
|
||||
)
|
||||
function showPollingState(target: { cardId: number; iccid: string }) {
|
||||
if (
|
||||
!hasAuth(pollingStatePermission.value) ||
|
||||
!Number.isInteger(target.cardId) ||
|
||||
target.cardId <= 0
|
||||
)
|
||||
return
|
||||
const asset = cardInfo.value
|
||||
const belongs =
|
||||
asset?.asset_type === 'card'
|
||||
? asset.asset_id === target.cardId
|
||||
: asset?.cards?.some(
|
||||
(card: { card_id: number; iccid: string }) =>
|
||||
card.card_id === target.cardId && card.iccid === target.iccid
|
||||
)
|
||||
if (belongs) pollingStateTarget.value = { ...target }
|
||||
}
|
||||
const stopResumeTarget = ref<{ cardId: number; iccid: string } | null>(null)
|
||||
const stopResumePermission = computed(() =>
|
||||
cardInfo.value?.asset_type === 'card'
|
||||
@@ -333,6 +366,7 @@
|
||||
() => {
|
||||
stopResumeVisible.value = false
|
||||
stopResumeTarget.value = null
|
||||
pollingStateTarget.value = null
|
||||
}
|
||||
)
|
||||
const realnamePolicyDialogVisible = ref(false)
|
||||
@@ -381,9 +415,25 @@
|
||||
// ========== 轮询状态 ==========
|
||||
const pollingEnabled = ref(false)
|
||||
let pollingInitializing = false
|
||||
// 订单/有效期/刷新可能由后端恢复轮询,仅同步真实状态,不能触发新的开关写请求。
|
||||
watch(
|
||||
() => [cardInfo.value, cardInfo.value?.enable_polling],
|
||||
async () => {
|
||||
pollingInitializing = true
|
||||
pollingEnabled.value = cardInfo.value?.enable_polling ?? false
|
||||
await nextTick()
|
||||
pollingInitializing = false
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
watch(pollingEnabled, async (val) => {
|
||||
if (pollingInitializing) return
|
||||
await updatePollingStatus(val)
|
||||
if (!(await updatePollingStatus(val))) {
|
||||
pollingInitializing = true
|
||||
pollingEnabled.value = cardInfo.value?.enable_polling ?? false
|
||||
await nextTick()
|
||||
pollingInitializing = false
|
||||
}
|
||||
})
|
||||
|
||||
// ========== 刷新按钮状态 ==========
|
||||
|
||||
Reference in New Issue
Block a user