49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
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`,
|
|
},
|
|
);
|
|
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 };
|