修复:区分通知加载失败与空列表
This commit is contained in:
1 parent
3d6d4deabb
commit
9b8124a4ea
3 files changed
+109
-5
No files matched your search
+21
-1
@@ -244,6 +244,7 @@ const userItems = computed(() => [
|
||||
const {
|
||||
count: unreadCount,
|
||||
recent: recentMessages,
|
||||
status: mailboxStatus,
|
||||
refresh: refreshMailbox,
|
||||
} = useMailbox();
|
||||
const mailboxOpen = ref(false);
|
||||
@@ -672,7 +673,26 @@ useHead(() => ({
|
||||
:draggable="false"
|
||||
>
|
||||
<div class="mail-pop">
|
||||
<div v-if="recentMessages.length" class="mail-pop-list">
|
||||
<div
|
||||
v-if="mailboxStatus === 'loading' || mailboxStatus === 'idle'"
|
||||
class="mail-pop-empty"
|
||||
role="status"
|
||||
>
|
||||
正在加载通知…
|
||||
</div>
|
||||
<div
|
||||
v-else-if="mailboxStatus === 'error'"
|
||||
class="mail-pop-empty"
|
||||
role="alert"
|
||||
>
|
||||
<Icon name="lucide:triangle-alert" aria-hidden="true" />
|
||||
<strong>通知暂时不可用</strong>
|
||||
<span>加载失败,请重试</span>
|
||||
<button type="button" class="mail-pop-foot" @click="refreshMailbox">
|
||||
重新加载通知
|
||||
</button>
|
||||
</div>
|
||||
<div v-else-if="recentMessages.length" class="mail-pop-list">
|
||||
<button
|
||||
v-for="message in recentMessages"
|
||||
:key="message.id"
|
||||
|
||||
+11
-4
@@ -7,6 +7,7 @@ function i() {
|
||||
let i = useState(`mail-unread-count`, () => 0),
|
||||
a = useState(`mail-recent`, () => []),
|
||||
o = useState(`mail-types`, () => []),
|
||||
status = useState(`mail-status`, () => `idle`),
|
||||
s = useState(`mail-session`, () => null),
|
||||
c = useState(`mail-request-id`, () => 0),
|
||||
l = useAuth(),
|
||||
@@ -19,31 +20,37 @@ function i() {
|
||||
(c.value += 1),
|
||||
(i.value = 0),
|
||||
(a.value = []),
|
||||
(o.value = []));
|
||||
(o.value = []),
|
||||
(status.value = `idle`));
|
||||
},
|
||||
{
|
||||
immediate: !0,
|
||||
flush: `sync`,
|
||||
},
|
||||
);
|
||||
// 接口现有摘要位于 credit_limit 字段;失败保留本会话既有摘要,不中断页面主流程。
|
||||
// 失败可保留本会话摘要,但必须显式标为不可用;只有成功的空结果才是暂无通知。
|
||||
async function d() {
|
||||
if (!l.token) return;
|
||||
let e = l.token,
|
||||
t = ++c.value;
|
||||
status.value = `loading`;
|
||||
try {
|
||||
let n = await u.get(`/client_care/mail`);
|
||||
if (e !== l.token || t !== c.value) return;
|
||||
let r = n?.credit_limit;
|
||||
((i.value = Number(r?.count ?? 0)),
|
||||
(a.value = r?.list ?? []),
|
||||
(o.value = r?.type ?? []));
|
||||
} catch {}
|
||||
(o.value = r?.type ?? []),
|
||||
(status.value = `success`));
|
||||
} catch {
|
||||
if (e === l.token && t === c.value) status.value = `error`;
|
||||
}
|
||||
}
|
||||
return {
|
||||
count: i,
|
||||
recent: a,
|
||||
types: o,
|
||||
status,
|
||||
refresh: d,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user