Browse Source

fix: quiet pool 404 toast and localize purchase status

Allow skipErrorToast for expected missing pool and map inactive to 失效.
main
xiaosi 3 weeks ago
parent
commit
b0e212f25b
  1. 4
      src/utils/http.js
  2. 8
      src/views/TrafficOpsView/TrafficOpsView.vue

4
src/utils/http.js

@ -25,7 +25,9 @@ request.interceptors.response.use(
if (res && res.code === 200) {
return res.data
}
if (!response.config.skipErrorToast) {
useUiStore().toast(res?.msg || '请求失败')
}
return Promise.reject(new Error(res?.msg || '请求失败'))
},
(error) => {
@ -40,7 +42,9 @@ request.interceptors.response.use(
useUiStore().toast(data?.msg || '无权限访问')
} else {
const message = data?.msg || error.message || '网络错误'
if (!error.config?.skipErrorToast) {
useUiStore().toast(message)
}
const err = new Error(message)
err.status = status
err.response = error.response

8
src/views/TrafficOpsView/TrafficOpsView.vue

@ -86,8 +86,8 @@
</div>
<div>
<span>池状态</span>
<strong>{{ pool.status === 'active' ? '有效' : (pool.status || '—') }}</strong>
<small>{{ pool.status || '—' }}</small>
<strong>{{ pool.status === 'active' ? '有效' : (pool.status === 'inactive' ? '失效' : (pool.status || '—')) }}</strong>
<small>{{ pool.status === 'active' ? '有效' : (pool.status === 'inactive' ? '失效' : (pool.status || '—')) }}</small>
</div>
</div>
@ -518,7 +518,7 @@ const purchaseColumns = [
async function loadPool() {
poolMissing.value = false
try {
pool.value = await request.get(urls.ADMIN_TRAFFIC_POOL)
pool.value = await request.get(urls.ADMIN_TRAFFIC_POOL, { skipErrorToast: true })
} catch (e) {
if (e.status === 404 || /资源不存在|not found/i.test(e.message || '')) {
pool.value = null
@ -543,7 +543,7 @@ async function loadPurchases() {
totalText: bytesToGbText(p.totalBytes),
costText: `¥${Number(p.totalCost || 0).toFixed(2)}`,
expiresAt: fmtTime(p.expiresAt),
statusName: p.status === 'active' ? '有效' : (p.status || '—'),
statusName: p.status === 'active' ? '有效' : (p.status === 'inactive' ? '失效' : (p.status || '—')),
remark: p.remark || '',
createdAt: fmtTime(p.createdAt),
raw: p

Loading…
Cancel
Save