146 lines
4.4 KiB
Vue
Raw Normal View History

2025-04-22 10:22:33 +08:00
<template>
<view class="wh-full">
2025-05-13 15:39:44 +08:00
<BasicLoading
2025-10-29 10:30:04 +08:00
:isShow="isShow"
bgColor="#fff"
isShowTitle
textColor="#000"
title="启动中..."
:type="1"
2025-05-13 15:39:44 +08:00
/>
2025-04-22 10:22:33 +08:00
</view>
</template>
<script lang="ts" setup>
2025-10-29 10:30:04 +08:00
import {onLoad} from "@dcloudio/uni-app";
import {useDataStore} from "@/store/modules/data";
2026-02-23 17:29:36 +08:00
import {useMenuStore} from "@/store/modules/menu";
2025-10-29 10:30:04 +08:00
import {useUserStore} from "@/store/modules/user";
2025-11-02 20:34:32 +08:00
import {checkOpenId} from "@/api/system/login";
2026-02-23 17:29:36 +08:00
import {getMobileMenuApi} from "@/api/system/menu";
import {getPermissionChangeTimeApi} from "@/api/system/config";
2025-10-29 10:30:04 +08:00
2025-11-02 20:34:32 +08:00
const dataStore = useDataStore();
2026-02-23 17:29:36 +08:00
const menuStore = useMenuStore();
const { setGlobal, getFile } = dataStore;
2025-11-02 20:34:32 +08:00
const userStore = useUserStore();
const { afterLoginAction } = userStore;
2025-05-13 15:39:44 +08:00
const isShow = ref(true);
2025-09-30 21:53:10 +08:00
function goByqd(data: any) {
if (data && data.qdId) {
2025-09-23 18:15:14 +08:00
// 有签到参数,重定向到签到确认页面
2025-09-30 21:53:10 +08:00
let confirmUrl = `/pages/view/routine/qd/confirm?qdId=${data.qdId}`;
if (data.rqgqtime) {
confirmUrl += `&rqgqtime=${data.rqgqtime}`;
2025-09-23 18:15:14 +08:00
}
2025-09-30 21:53:10 +08:00
if (data.timestampqd) {
confirmUrl += `&timestampqd=${data.timestampqd}`;
2025-09-23 18:15:14 +08:00
}
2025-09-30 21:53:10 +08:00
2025-09-23 18:15:14 +08:00
console.log('重定向到签到确认页面:', confirmUrl);
uni.reLaunch({
url: confirmUrl
});
return;
}
2025-09-30 21:53:10 +08:00
}
function goByJs(js: any) {
2025-08-02 11:15:22 +08:00
if (js.confirmStatus == "A") {
// 跳转到自助服务首页
uni.reLaunch({
2025-08-02 11:15:22 +08:00
url: "/pages/base/service/index",
});
} else {
2026-02-23 17:29:36 +08:00
dataStore.setFile({
2025-08-02 11:15:22 +08:00
...js,
2026-02-23 17:29:36 +08:00
...dataStore.getFile,
2025-08-02 11:15:22 +08:00
});
setTimeout(() => {
uni.reLaunch({
url: "/pages/view/hr/teacherProfile/index",
});
}, 1500);
}
2025-05-13 15:39:44 +08:00
}
2025-08-02 11:15:22 +08:00
2025-05-13 15:39:44 +08:00
onLoad(async (data: any) => {
2025-09-23 18:15:14 +08:00
console.log('launchPage onLoad - 接收到的参数:', data);
2025-05-13 15:39:44 +08:00
if (data && data.openId) {
2025-10-22 15:01:22 +08:00
// ⭐ 先保存参数到 global确保后续页面可以获取
setGlobal({
openId: data.openId,
menu: data.menu,
type: data.type || 2, // 默认为教师端
profilePhoto: data.profilePhoto,
qdId: data.qdId,
rqgqtime: data.rqgqtime,
timestampqd: data.timestampqd
});
2025-10-29 10:30:04 +08:00
console.log('已保存参数到 global:', {openId: data.openId, type: data.type});
2025-08-02 11:15:22 +08:00
try {
const res = await checkOpenId({
openId: data.openId,
appCode: "JS",
});
2025-10-29 10:30:04 +08:00
if (res.resultCode == 1 && res.result) {
2025-08-02 11:15:22 +08:00
// 执行登录操作
afterLoginAction(res.result);
2025-10-29 10:30:04 +08:00
2026-02-23 17:29:36 +08:00
// 判断是否需要拉取菜单:时间戳不一致或本地无菜单则重新请求
let needFetchMenu = true;
try {
const timeRes = await getPermissionChangeTimeApi();
console.log('[launchPage] getPermissionChangeTime 原始返回:', JSON.stringify(timeRes));
const serverChangeTime = String((timeRes as any)?.result ?? '');
const localChangeTime = userStore.getChangeTime || '';
const localMenu = menuStore.getMobileMenu || [];
needFetchMenu = serverChangeTime !== localChangeTime || !localMenu?.length;
console.log('[launchPage] serverChangeTime:', serverChangeTime, 'localChangeTime:', localChangeTime, 'localMenuLength:', localMenu?.length ?? 0, 'needFetchMenu:', needFetchMenu);
if (serverChangeTime) userStore.setChangeTime(serverChangeTime);
} catch (e) {
console.warn('[launchPage] getPermissionChangeTime 失败:', e);
needFetchMenu = true;
}
2025-10-29 10:30:04 +08:00
2026-02-23 17:29:36 +08:00
if (needFetchMenu) {
console.log('[launchPage] 调用 find-mobile-menu');
await getMobileMenuApi()
.then((r) => {
if (r?.result && Array.isArray(r.result) && r.result.length > 0) {
menuStore.setMobileMenu(r.result);
}
})
.catch(() => {});
} else {
console.log('[launchPage] 跳过 find-mobile-menu使用本地缓存');
2025-05-13 15:39:44 +08:00
}
2026-02-23 17:29:36 +08:00
2025-10-29 10:30:04 +08:00
if (data && data.qdId) {
goByqd(data);
} else {
goByJs(res.result.js);
}
2025-08-02 11:15:22 +08:00
} else {
uni.reLaunch({
url: "/pages/system/login/login",
});
2025-08-02 11:15:22 +08:00
}
} catch (err) {
2025-09-23 18:15:14 +08:00
console.error('launchPage onLoad - checkOpenId失败:', err);
2025-08-02 11:15:22 +08:00
uni.reLaunch({
url: "/pages/system/login/login"
});
2025-08-02 11:15:22 +08:00
}
2025-06-20 09:51:43 +08:00
} else {
2025-09-23 18:15:14 +08:00
console.log('launchPage onLoad - 没有openId参数跳转到登录页面');
2025-08-02 11:15:22 +08:00
uni.reLaunch({
url: "/pages/system/login/login"
});
2025-04-22 10:22:33 +08:00
}
2025-05-13 15:39:44 +08:00
});
2025-04-22 10:22:33 +08:00
</script>