修复:将页面异步副作用绑定到当前归属
This commit is contained in:
1 parent
b3a66d97c8
commit
eca3aa8fe5
6 files changed
+623
-90
No files matched your search
@@ -10,6 +10,7 @@ definePageMeta({
|
||||
});
|
||||
import { toDisplayString } from "vue";
|
||||
import { onMounted } from "vue";
|
||||
import { onScopeDispose } from "vue";
|
||||
import { normalizeClass } from "vue";
|
||||
import { createBlock } from "vue";
|
||||
import { ref } from "vue";
|
||||
@@ -27,7 +28,7 @@ import { createVNode } from "vue";
|
||||
import { openBlock } from "vue";
|
||||
import { withModifiers } from "vue";
|
||||
import { useRoute } from "#app";
|
||||
import { useApi } from "~/lib/auth.js";
|
||||
import { useApi, useAuth } from "~/lib/auth.js";
|
||||
import dialog from "openvue/dialog";
|
||||
import button from "openvue/button";
|
||||
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
|
||||
@@ -111,6 +112,12 @@ var ge = {
|
||||
defineComponent({
|
||||
__name: `index`,
|
||||
setup(p) {
|
||||
const session = useAuth().prepareLogin();
|
||||
let disposed = false;
|
||||
const isCurrent = () => !disposed && session.isCurrent();
|
||||
onScopeDispose(() => {
|
||||
disposed = true;
|
||||
});
|
||||
composables_t({
|
||||
key: (e) => e.fullPath,
|
||||
});
|
||||
@@ -185,37 +192,39 @@ var ge = {
|
||||
}
|
||||
// 将指定 ID 标为已读,完成后清除选择并刷新列表与全局未读计数。
|
||||
async function ze(e) {
|
||||
if (!(!e.length || B.value || G.value)) {
|
||||
if (isCurrent() && !(!e.length || B.value || G.value)) {
|
||||
((B.value = !0), (U.value = ``));
|
||||
try {
|
||||
(await y.put(`/client_care/mail/read`, {
|
||||
await y.put(`/client_care/mail/read`, {
|
||||
id: e,
|
||||
}),
|
||||
(z.value = []),
|
||||
await R(),
|
||||
await D());
|
||||
});
|
||||
if (!isCurrent()) return;
|
||||
z.value = [];
|
||||
await refreshMessages();
|
||||
} catch (e) {
|
||||
U.value = e instanceof Error ? e.message : `操作失败`;
|
||||
if (isCurrent())
|
||||
U.value = e instanceof Error ? e.message : `操作失败`;
|
||||
} finally {
|
||||
B.value = !1;
|
||||
if (isCurrent()) B.value = !1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 使用 all 标记请求服务端全部已读,不局限于当前可见页。
|
||||
async function Be() {
|
||||
if (!(B.value || G.value)) {
|
||||
if (isCurrent() && !(B.value || G.value)) {
|
||||
((B.value = !0), (U.value = ``));
|
||||
try {
|
||||
(await y.put(`/client_care/mail/read`, {
|
||||
await y.put(`/client_care/mail/read`, {
|
||||
all: 1,
|
||||
}),
|
||||
(z.value = []),
|
||||
await R(),
|
||||
await D());
|
||||
});
|
||||
if (!isCurrent()) return;
|
||||
z.value = [];
|
||||
await refreshMessages();
|
||||
} catch (e) {
|
||||
U.value = e instanceof Error ? e.message : `操作失败`;
|
||||
if (isCurrent())
|
||||
U.value = e instanceof Error ? e.message : `操作失败`;
|
||||
} finally {
|
||||
B.value = !1;
|
||||
if (isCurrent()) B.value = !1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,24 +240,30 @@ var ge = {
|
||||
}
|
||||
// 仅提交选中消息的 ID;成功后同步列表与未读计数。
|
||||
async function He() {
|
||||
if (!z.value.length || G.value || B.value) return;
|
||||
if (!isCurrent() || !z.value.length || G.value || B.value) return;
|
||||
let e = z.value.map((e) => e.id);
|
||||
((G.value = !0), (U.value = ``));
|
||||
try {
|
||||
(await y.del(`/client_care/mail`, {
|
||||
await y.del(`/client_care/mail`, {
|
||||
id: e,
|
||||
}),
|
||||
(W.value = !1),
|
||||
(z.value = []),
|
||||
await R(),
|
||||
await D());
|
||||
});
|
||||
if (!isCurrent()) return;
|
||||
W.value = !1;
|
||||
z.value = [];
|
||||
await refreshMessages();
|
||||
} catch (e) {
|
||||
if (!isCurrent()) return;
|
||||
((W.value = !1),
|
||||
(U.value = e instanceof Error ? e.message : `删除失败`));
|
||||
} finally {
|
||||
G.value = !1;
|
||||
if (isCurrent()) G.value = !1;
|
||||
}
|
||||
}
|
||||
async function refreshMessages() {
|
||||
if (!isCurrent()) return;
|
||||
await R();
|
||||
if (isCurrent()) await D();
|
||||
}
|
||||
let K = ref(!1),
|
||||
q = ref(null),
|
||||
J = ref(!1),
|
||||
@@ -257,7 +272,9 @@ var ge = {
|
||||
Z = 0;
|
||||
// 详情打开时清除旧正文并递增请求序号;加载成功后尝试标读,标读失败不覆盖已加载的正文。
|
||||
async function Q(e) {
|
||||
if (!isCurrent()) return;
|
||||
let t = ++Z;
|
||||
const ownsDetail = () => isCurrent() && t === Z;
|
||||
((X.value = e),
|
||||
(K.value = !0),
|
||||
(J.value = !0),
|
||||
@@ -265,7 +282,7 @@ var ge = {
|
||||
(q.value = null));
|
||||
try {
|
||||
let n = await y.get(`/client_care/mail/${e}`);
|
||||
if (t !== Z) return;
|
||||
if (!ownsDetail()) return;
|
||||
if (!n?.mail?.id) {
|
||||
Y.value = `消息不存在或已删除`;
|
||||
return;
|
||||
@@ -274,23 +291,25 @@ var ge = {
|
||||
let r = M.value.find((t) => t.id === e);
|
||||
if (!r || r.read === 0)
|
||||
try {
|
||||
(await y.put(`/client_care/mail/read`, {
|
||||
await y.put(`/client_care/mail/read`, {
|
||||
id: [e],
|
||||
}),
|
||||
r && (r.read = 1),
|
||||
await D());
|
||||
});
|
||||
if (!ownsDetail()) return;
|
||||
if (r) r.read = 1;
|
||||
await D();
|
||||
} catch {}
|
||||
} catch (e) {
|
||||
t === Z && (Y.value = e instanceof Error ? e.message : `加载失败`);
|
||||
ownsDetail() &&
|
||||
(Y.value = e instanceof Error ? e.message : `加载失败`);
|
||||
} finally {
|
||||
t === Z && (J.value = !1);
|
||||
ownsDetail() && (J.value = !1);
|
||||
}
|
||||
}
|
||||
return (
|
||||
onMounted(async () => {
|
||||
await D();
|
||||
let e = Number(T.query.id);
|
||||
e && Q(e);
|
||||
isCurrent() && e && Q(e);
|
||||
}),
|
||||
// 批量操作基于当前选择集,详情正文经公共清理后展示;详情 ID 与加载代次防止快速切换串信。
|
||||
(t, i) => {
|
||||
|
||||
Reference in new issue
Block a user