This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
|
||||
<!-- 操作按钮组 -->
|
||||
<div v-if="hasCardInfo" class="operation-button-group">
|
||||
<ElButton @click="handleRefresh" type="primary" :icon="Refresh"> 刷新 </ElButton>
|
||||
<ElButton @click="handleRefresh" type="primary" :icon="Refresh" :disabled="refreshDisabled"> 刷新 </ElButton>
|
||||
</div>
|
||||
</div>
|
||||
</ElCard>
|
||||
@@ -54,10 +54,12 @@
|
||||
// Props
|
||||
interface Props {
|
||||
hasCardInfo?: boolean
|
||||
refreshDisabled?: boolean
|
||||
}
|
||||
|
||||
withDefaults(defineProps<Props>(), {
|
||||
hasCardInfo: false
|
||||
hasCardInfo: false,
|
||||
refreshDisabled: false
|
||||
})
|
||||
|
||||
// Emits
|
||||
|
||||
@@ -53,6 +53,9 @@
|
||||
<ElDescriptionsItem label="本月已用流量">{{
|
||||
formatDataSize(cardInfo?.current_month_usage_mb || 0)
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="运营商周期月内已用流量">{{
|
||||
formatDataSize(cardInfo?.last_gateway_reading_mb || 0)
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="实名时间">{{
|
||||
cardInfo?.real_name_at ? formatDateTime(cardInfo.real_name_at) : '-'
|
||||
}}</ElDescriptionsItem>
|
||||
@@ -480,6 +483,7 @@
|
||||
real_name_status?: number
|
||||
network_status?: number
|
||||
current_month_usage_mb?: number
|
||||
last_gateway_reading_mb?: number
|
||||
device_type?: string
|
||||
device_name?: string
|
||||
device_model?: string
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
<div class="card-header">
|
||||
<span>套餐列表</span>
|
||||
<div class="card-header-right">
|
||||
<ElButton type="primary" @click="handleShowRecharge">套餐充值</ElButton>
|
||||
<ElButton type="primary" :disabled="props.boundDeviceId" @click="handleShowRecharge"
|
||||
>套餐充值</ElButton
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -276,6 +276,9 @@ export function useAssetInfo() {
|
||||
if (data.current_month_usage_mb !== undefined) {
|
||||
cardInfo.value.current_month_usage_mb = data.current_month_usage_mb
|
||||
}
|
||||
if (data.last_gateway_reading_mb !== undefined) {
|
||||
cardInfo.value.last_gateway_reading_mb = data.last_gateway_reading_mb
|
||||
}
|
||||
} else if (assetType === 'device') {
|
||||
// 设备的实时状态
|
||||
if (data.device_protect_status !== undefined) {
|
||||
@@ -353,8 +356,9 @@ export function useAssetInfo() {
|
||||
* 刷新资产数据(调用refresh接口后重新加载)
|
||||
* @param identifier - 资产标识符
|
||||
* @param assetType - 资产类型(card/device)
|
||||
* @returns true if refresh was successful, false if rate limited (429)
|
||||
*/
|
||||
const refreshAsset = async (identifier: string, assetType: string) => {
|
||||
const refreshAsset = async (identifier: string, assetType: string): Promise<boolean> => {
|
||||
try {
|
||||
await AssetService.refreshAsset(identifier)
|
||||
ElMessage.success('刷新成功')
|
||||
@@ -363,8 +367,15 @@ export function useAssetInfo() {
|
||||
if (identifier) {
|
||||
await loadRealtimeStatus(identifier, assetType)
|
||||
}
|
||||
return true
|
||||
} catch (error: any) {
|
||||
console.log(error)
|
||||
// Check if it's a 429 rate limit error
|
||||
if (error?.response?.status === 429) {
|
||||
ElMessage.warning('操作过于频繁,请30秒后再试')
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<AssetSearchCard
|
||||
ref="assetSearchCardRef"
|
||||
:has-card-info="!!cardInfo"
|
||||
:refresh-disabled="refreshDisabled"
|
||||
@search="handleSearch"
|
||||
@refresh="handleRefresh"
|
||||
/>
|
||||
@@ -266,6 +267,9 @@
|
||||
await updatePollingStatus(val)
|
||||
})
|
||||
|
||||
// ========== 刷新按钮状态 ==========
|
||||
const refreshDisabled = ref(false)
|
||||
|
||||
// ========== 事件处理 ==========
|
||||
|
||||
/**
|
||||
@@ -301,7 +305,14 @@
|
||||
*/
|
||||
const handleRefresh = async () => {
|
||||
if (!cardInfo.value) return
|
||||
await refreshAsset(cardInfo.value.identifier, cardInfo.value.asset_type)
|
||||
const success = await refreshAsset(cardInfo.value.identifier, cardInfo.value.asset_type)
|
||||
if (!success) {
|
||||
// 如果刷新失败(429错误),禁用刷新按钮30秒
|
||||
refreshDisabled.value = true
|
||||
setTimeout(() => {
|
||||
refreshDisabled.value = false
|
||||
}, 30000)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user