fix(pl): 区分用证详情权限失败与网络异常以保留完整账目保护。
This commit is contained in:
1 parent
fb45466c0c
commit
6eba9c1aae
2 files changed
+36
-5
No files matched your search
@@ -350,3 +350,28 @@ test('plan expansion loads on demand, preserves total during refresh and ignores
|
||||
assert.deepEqual(Object.keys(s.details), [])
|
||||
h.stop()
|
||||
})
|
||||
|
||||
for (const status of [403, 404, 500, undefined])
|
||||
test(`plan expansion reports ${status || 'network'} failure without showing partial usage`, async () => {
|
||||
const h = pageHarness('quota', { mobile: false }),
|
||||
s = h.state
|
||||
const pending = s.loadDetail('plan')
|
||||
h.gets[0].reject(status ? { response: { status } } : new Error('network'))
|
||||
await pending
|
||||
assert.equal(
|
||||
s.details.plan.error,
|
||||
[403, 404].includes(status as number)
|
||||
? '计划或证件不可读取,无法展示完整用证详情'
|
||||
: '段次用证加载失败,请重试'
|
||||
)
|
||||
assert.equal(s.details.plan.data, undefined)
|
||||
assert.equal(s.details.plan.loading, false)
|
||||
if (status === 500) {
|
||||
const retry = s.loadDetail('plan')
|
||||
h.gets[1].resolve({ planId: 'plan', sourceOptions: [], usages: [] })
|
||||
await retry
|
||||
assert.equal(s.details.plan.error, undefined)
|
||||
assert.equal(s.details.plan.data.planId, 'plan')
|
||||
}
|
||||
h.stop()
|
||||
})
|
||||
@@ -78,7 +78,7 @@
|
||||
>
|
||||
<el-alert
|
||||
v-if="details[row.id]?.error"
|
||||
title="段次用证加载失败"
|
||||
:title="details[row.id]?.error"
|
||||
type="error"
|
||||
:closable="false"
|
||||
><el-button @click="loadDetail(row.id)"
|
||||
@@ -221,7 +221,7 @@
|
||||
rows = ref<(Plan & { quotaStatus: string })[]>([])
|
||||
const dialog = ref<InstanceType<typeof PlPlanQuotaDialog>>()
|
||||
const expandedIds = ref<string[]>([])
|
||||
const details = reactive<Record<string, { loading: boolean; data?: PlanQuota; error?: boolean }>>(
|
||||
const details = reactive<Record<string, { loading: boolean; data?: PlanQuota; error?: string }>>(
|
||||
{}
|
||||
)
|
||||
function clearDetails() {
|
||||
@@ -230,15 +230,21 @@
|
||||
}
|
||||
async function loadDetail(id: string) {
|
||||
const current = epoch
|
||||
const state = reactive<{ loading: boolean; data?: PlanQuota; error?: boolean }>({
|
||||
const state = reactive<{ loading: boolean; data?: PlanQuota; error?: string }>({
|
||||
loading: true
|
||||
})
|
||||
details[id] = state
|
||||
try {
|
||||
const value = await planQuotaApi.get(id)
|
||||
if (current === epoch && details[id] === state) state.data = value
|
||||
} catch {
|
||||
if (current === epoch && details[id] === state) state.error = true
|
||||
} catch (error) {
|
||||
if (current === epoch && details[id] === state) {
|
||||
const status = (error as { response?: { status?: number } })?.response?.status
|
||||
state.error =
|
||||
status === 403 || status === 404
|
||||
? '计划或证件不可读取,无法展示完整用证详情'
|
||||
: '段次用证加载失败,请重试'
|
||||
}
|
||||
} finally {
|
||||
if (current === epoch && details[id] === state) state.loading = false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user