49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
export function buildQuotaQuery(query) {
|
|
return {
|
|
pageIndex: Math.max(1, Number(query.pageIndex) || 1),
|
|
pageSize: Math.min(100, Math.max(1, Number(query.pageSize) || 10)),
|
|
keyword: String(query.keyword || '').trim(),
|
|
status: String(query.status || '').trim()
|
|
}
|
|
}
|
|
|
|
export function quotaGate(summary = {}) {
|
|
if (summary.readStatus !== 'readable') {
|
|
return {
|
|
type: 'error',
|
|
title: '配额配置不可读取',
|
|
detail: '为避免超配额,新增和启用请求已关闭;已有设备、视频流与查询不受影响。请检查配置来源后重试。',
|
|
writable: false
|
|
}
|
|
}
|
|
if ((Number(summary.remaining) || 0) <= 0) {
|
|
return {
|
|
type: 'warning',
|
|
title: '当前配额已满',
|
|
detail: '新增和启用请求将被拒绝;已有设备、视频流与查询继续正常运行。',
|
|
writable: false
|
|
}
|
|
}
|
|
return {
|
|
type: 'success',
|
|
title: '安全闸正常',
|
|
detail: '新增和启用设备可继续;系统会在写入时再次原子校验剩余配额。',
|
|
writable: true
|
|
}
|
|
}
|
|
|
|
export function usagePercent(summary = {}) {
|
|
const limit = Number(summary.limit) || 0
|
|
const used = Number(summary.used) || 0
|
|
if (limit <= 0) return 0
|
|
return Math.min(100, Math.max(0, Math.round((used / limit) * 100)))
|
|
}
|
|
|
|
export function deviceStatusLabel(status) {
|
|
return ({ active: '已接入', pending: '待接入', disabled: '已停用' })[status] || status || '未知'
|
|
}
|
|
|
|
export function tierValidationLabel(value) {
|
|
return value === 'verified' ? '已验证' : '未验证'
|
|
}
|