/** 顶栏站内信摘要共享状态;切换账号同步清空,旧账号或较早刷新结果不得覆盖新状态。 */ import { watch } from "vue"; import { useState } from "#app"; import { useApi } from "~/lib/auth.js"; import { useAuth } from "~/lib/auth.js"; function i() { let i = useState(`mail-unread-count`, () => 0), a = useState(`mail-recent`, () => []), o = useState(`mail-types`, () => []), s = useState(`mail-session`, () => null), c = useState(`mail-request-id`, () => 0), l = useAuth(), u = useApi(); watch( () => l.token, (e) => { s.value !== e && ((s.value = e), (c.value += 1), (i.value = 0), (a.value = []), (o.value = [])); }, { immediate: !0, flush: `sync`, }, ); // 接口现有摘要位于 credit_limit 字段;失败保留本会话既有摘要,不中断页面主流程。 async function d() { if (!l.token) return; let e = l.token, t = ++c.value; 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 {} } return { count: i, recent: a, types: o, refresh: d, }; } export { i as t };