2025-11-02 20:34:32 +08:00

157 lines
4.2 KiB
Vue
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.

<template>
<view class="wh-full">
<BasicLoading
:isShow="isShow"
bgColor="#fff"
isShowTitle
textColor="#000"
title="启动中..."
:type="1"
/>
</view>
</template>
<script lang="ts" setup>
import {onLoad} from "@dcloudio/uni-app";
import {useDataStore} from "@/store/modules/data";
import {useUserStore} from "@/store/modules/user";
import {checkOpenId} from "@/api/system/login";
const dataStore = useDataStore();
const { setGlobal, getGlobal, setFile, getFile, refreshMessageBadge } = dataStore;
const userStore = useUserStore();
const { afterLoginAction } = userStore;
const isShow = ref(true);
/**
* 强制刷新权限
*/
async function forceRefreshPermission(changeTime?: string): Promise<void> {
try {
// 重新获取用户权限
const userStore = useUserStore();
const currentUser = userStore.getUser;
if (currentUser && currentUser.id) {
// 重新调用权限获取接口
const {authenticationApi} = await import('@/api/system/login');
const result = await authenticationApi({userId: currentUser.id});
if (result && result.result) {
// 直接设置权限并刷新缓存不调用setAuth避免重复操作
userStore.auth = result.result;
// 手动刷新缓存,传递权限变更时间
const {refreshPermissionCache} = await import('@/utils/permission');
refreshPermissionCache(result.result, changeTime);
}
}
} catch (error) {
console.error('强制刷新权限失败:', error);
}
}
function goByqd(data: any) {
if (data && data.qdId) {
// 有签到参数,重定向到签到确认页面
let confirmUrl = `/pages/view/routine/qd/confirm?qdId=${data.qdId}`;
if (data.rqgqtime) {
confirmUrl += `&rqgqtime=${data.rqgqtime}`;
}
if (data.timestampqd) {
confirmUrl += `&timestampqd=${data.timestampqd}`;
}
console.log('重定向到签到确认页面:', confirmUrl);
uni.reLaunch({
url: confirmUrl
});
return;
}
}
function goByJs(js: any) {
if (js.confirmStatus == "A") {
// 跳转到自助服务首页
uni.reLaunch({
url: "/pages/base/service/index",
});
} else {
setFile({
...js,
...getFile,
});
setTimeout(() => {
uni.reLaunch({
url: "/pages/view/hr/teacherProfile/index",
});
}, 1500);
}
}
onLoad(async (data: any) => {
console.log('launchPage onLoad - 接收到的参数:', data);
if (data && data.openId) {
// ⭐ 先保存参数到 global确保后续页面可以获取
setGlobal({
openId: data.openId,
menu: data.menu,
type: data.type || 2, // 默认为教师端
profilePhoto: data.profilePhoto,
qdId: data.qdId,
rqgqtime: data.rqgqtime,
timestampqd: data.timestampqd
});
console.log('已保存参数到 global:', {openId: data.openId, type: data.type});
try {
const res = await checkOpenId({
openId: data.openId,
appCode: "JS",
});
if (res.resultCode == 1 && res.result) {
// 执行登录操作
afterLoginAction(res.result);
// 刷新教师待办角标
await refreshMessageBadge(res.result?.js?.id);
// 如果有changeTime参数更新权限缓存
if (data.changeTime) {
const {refreshPermissionCache} = await import('@/utils/permission');
const userStore = useUserStore();
const currentPermissions = userStore.getAuth;
if (currentPermissions && currentPermissions.length > 0) {
refreshPermissionCache(currentPermissions, data.changeTime);
}
}
if (data && data.qdId) {
goByqd(data);
} else {
goByJs(res.result.js);
}
} else {
uni.reLaunch({
url: "/pages/system/login/login",
});
}
} catch (err) {
console.error('launchPage onLoad - checkOpenId失败:', err);
uni.reLaunch({
url: "/pages/system/login/login"
});
}
} else {
console.log('launchPage onLoad - 没有openId参数跳转到登录页面');
uni.reLaunch({
url: "/pages/system/login/login"
});
}
});
</script>