zhxy-jzd/src/utils/pageUtil.ts

168 lines
4.3 KiB
TypeScript
Raw Normal View History

import { checkXsXkApi, checkXkTfApi } from "@/api/base/xkApi";
2025-09-13 20:37:43 +08:00
import { checkXsJcApi } from "@/api/base/jcApi";
2025-09-02 15:45:06 +08:00
import { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data";
const userStore = useUserStore();
const dataStore = useDataStore();
2025-09-03 19:46:26 +08:00
// TODO: 记住测试的时候才默认使用第一个
const devFlag = false;
2025-09-02 15:45:06 +08:00
/**
*
*/
export const PageUtils = {
/**
*
* @param lxId JC: 就餐816059832: 俱乐部962488654: 兴趣课
* @param action jf: 缴费tf: 退费
2025-09-02 15:45:06 +08:00
*/
async toHome(lxId: string, action: string) {
2025-09-02 15:45:06 +08:00
// 没有类型,则跳转首页
if (!lxId) {
uni.reLaunch({
url: "/pages/base/home/index",
});
return;
}
// 判断当前学生列表如果大于1则跳转学生选择页面
const xsList = userStore.getUser.xsList;
if (devFlag) {
userStore.setCurXs(xsList[0]);
} else {
2025-09-03 15:02:20 +08:00
if (xsList && xsList.length > 1
&& (dataStore.getGlobal && dataStore.getGlobal.from == 'launch')) {
2025-09-02 15:45:06 +08:00
uni.reLaunch({
url: "/pages/base/home/xsXz",
});
return;
}
}
2025-09-22 19:36:41 +08:00
try {
// 判断业务逻辑,并跳转界面
await this.checkLogicPage(lxId, action);
} catch (error) {
console.error("逻辑校验失败:", error);
uni.reLaunch({
url: "/pages/base/home/xsXz",
});
}
2025-09-02 15:45:06 +08:00
},
/**
*
*/
async checkLogicPage(lxId: string, action: string) {
2025-09-02 15:45:06 +08:00
switch (lxId) {
// 就餐逻辑单独处理
case "JC": {
2025-09-13 20:37:43 +08:00
2025-09-02 15:45:06 +08:00
} break;
// 默认当作 选课的选课类型IDxkLxId处理
default: {
if (action === "jf") {
await this.checkQkLogic(lxId);
} else if (action === "tf") {
await this.checkXkTfLogic(lxId);
}
2025-09-02 15:45:06 +08:00
}
}
},
/**
*
* @param xklxId
*/
async checkQkLogic(xklxId: string) {
const res: any = await checkXsXkApi({
xsId: userStore.getCurXs.id,
njmcId: userStore.getCurXs.njmcId,
xklxId: xklxId,
});
console.log('checkQkLogic', res);
if (res.resultCode != 1) {
uni.showToast({
title: res.message,
icon: 'none'
});
uni.reLaunch({
url: "/pages/base/home/xsXz",
});
return;
}
const result = res.result || {};
// 记录到缓存数据中
dataStore.setQk(result);
// 状态判断
switch (result.xsXkStatus) {
2025-09-03 19:46:26 +08:00
case 'WFB': { // KQK可抢课
uni.reLaunch({
url: "/pages/base/xk/qk/wks?xklxId=" + xklxId,
});
} break;
2025-09-02 15:45:06 +08:00
case 'KQK': { // KQK可抢课
uni.reLaunch({
2025-09-02 21:55:01 +08:00
url: "/pages/base/gzs/index?lxId=" + xklxId,
2025-09-02 15:45:06 +08:00
});
} break;
case 'QKZ': { // QKZ抢课中
2025-09-02 20:57:37 +08:00
uni.reLaunch({
url: "/pages/base/xk/qk/index?xklxId=" + xklxId,
});
2025-09-02 15:45:06 +08:00
} break;
case 'YQK': { // YQK已选课
2025-09-02 20:57:37 +08:00
uni.reLaunch({
url: "/pages/base/xk/pay/index?xklxId=" + xklxId,
});
2025-09-02 15:45:06 +08:00
} break;
case 'DZF': { // DZF待支付
2025-09-02 20:57:37 +08:00
uni.reLaunch({
url: "/pages/base/xk/pay/index?xklxId=" + xklxId,
});
2025-09-02 15:45:06 +08:00
} break;
case 'YZF': { // YZF已支付
uni.reLaunch({
url: "/pages/base/xk/pay/success?xklxId=" + xklxId,
});
} break;
}
},
// 判断退费页面切换逻辑
async checkXkTfLogic(xklxId: string) {
const res = await checkXkTfApi({
xsId: userStore.getCurXs.id,
njmcId: userStore.getCurXs.njmcId,
xklxId: xklxId,
});
console.log('checkXkTfLogic', res);
if (res.resultCode != 1) {
uni.showToast({
title: res.message,
icon: 'none',
duration: 2000,
});
uni.reLaunch({
url: "/pages/base/home/index",
});
return;
}
const result = res.result || {};
// 记录到缓存数据中
dataStore.setTf(result);
// 状态判断
switch (result.status) {
case 'KTF': { // KTF可退费
uni.reLaunch({
url: "/pages/base/gzs/tf?lxId=" + xklxId,
});
} break;
case 'TFZ': { // TFZ退费中
uni.reLaunch({
url: "/pages/base/xk/tf/detail?xklxId=" + xklxId,
});
} break;
}
},
2025-09-02 15:45:06 +08:00
}