zhxy-jsd/src/utils/xkTfPageUtils.ts
2025-09-26 10:17:14 +08:00

80 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { xxtsFindByIdApi, xxtsSaveApi } from "@/api/base/xxtsApi";
import { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data";
const { loginByOpenId } = useUserStore();
const { getData, setXxts, setData, getXxts } = useDataStore();
export const XkTfPageUtils = {
// 初始化校验
async init(data?: any) {
setXxts({});
let ret = {
success: true,
dbFlag: false,
xkTfId: getData.id,
};
if (!data || !data.from || data.from != "db") {
return ret;
}
// 从待办过来的,需要从后端获取数据
ret.dbFlag = true;
// 检查登录状态
const isLoggedIn = await loginByOpenId(data.openId);
if (!isLoggedIn) {
console.log("用户未登录,跳过处理");
ret.success = false;
return ret;
}
let url = "/pages/base/message/index";
try {
// 优先从后端根据url中的id去查询Xxts
const xxtsRes = await xxtsFindByIdApi({ id: data.id });
if (xxtsRes && xxtsRes.result) {
const xxts = xxtsRes.result;
setXxts(xxts);
ret.xkTfId = xxts.xxzbId;
// 检查待办状态
if (xxts.dbZt === "B") {
setData({ id: xxts.xxzbId });
url = "/pages/view/routine/xk/tf/detail";
uni.reLaunch({ url });
ret.success = false;
} else {
ret.success = true;
}
} else {
uni.showToast({
title: "获取消息推送数据失败",
icon: "error",
});
uni.reLaunch({ url });
ret.success = false;
}
return ret;
} catch (error) {
console.error("获取待办信息失败", error);
// 如果获取Xxts失败回退到原来的逻辑
const xxtsData = getXxts;
if (xxtsData && xxtsData.dbZt === "B") {
setData({ id: data.id });
uni.reLaunch({ url });
ret.success = false;
return ret;
}
}
},
// 检查待办状态是否需要更新
async updateXxts() {
// 如果没有查询过消息推送,表示不是从待办进入的,不自动更新,
if (!getXxts || !getXxts.id) {
return false;
}
// 更新待办状态
await xxtsSaveApi({
id: getXxts.id,
dbZt: "B",
});
return true;
},
}