hookehuyr

fix(router): 修复授权后首次访问跳过周期检查的问题

添加调试信息并优化路由守卫逻辑
当从授权页面返回时跳过周期检查
确保表单检查逻辑在跳过周期检查时正常执行
......@@ -148,6 +148,8 @@ onMounted(async () => {
if (!import.meta.env.DEV && open_auth && form_setting.wxzq_scope && record_openid) {
// 预览模式不开启
if (no_preview_model) {
// 设置标识,让路由守卫跳过首次周期检查
sessionStorage.setItem('skip_cycle_check_for_auth', 'true');
$router.replace({
path: '/auth',
query: {
......
/*
* @Date: 2022-05-26 13:57:28
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-09 10:29:55
* @LastEditTime: 2025-09-10 10:26:45
* @FilePath: /data-table/src/router.js
* @Description: 文件描述
*/
......@@ -119,15 +119,56 @@ router.beforeEach((to, from, next) => {
return;
}
// 检查是否从授权页面返回,如果是首次访问且可能需要授权,则跳过周期检查
const isFromAuth = from.path === '/auth';
const skipCycleCheck = sessionStorage.getItem('skip_cycle_check_for_auth');
// 如果不是从授权页面返回,且设置了跳过标识,则先清除标识并跳过周期检查
if (!isFromAuth && skipCycleCheck === 'true') {
sessionStorage.removeItem('skip_cycle_check_for_auth');
// 直接执行表单检查逻辑,跳过周期检查
if (to.query.page_type === 'add' || to.query.page_type === undefined) {
const existingCookie = Cookies.get(to.query.code);
if (existingCookie && to.query.force_back !== '1') {
showConfirmDialog({
title: '温馨提示',
message: '您还未完成的表单,是否继续?',
confirmButtonColor: styleColor.baseColor,
cancelButtonText: '删除',
closeOnPopstate: false,
})
.then(() => {
next();
})
.catch(() => {
Cookies.remove(to.query.code);
next();
});
} else {
next();
}
} else {
next();
}
return;
}
// 异步检查周期选择
checkCycleSelection(to).then(needsCycleSelection => {
if (needsCycleSelection) {
// 保存目标路由到sessionStorage
sessionStorage.setItem('cycle_target_route', JSON.stringify({
const targetRoute = {
path: to.path,
query: to.query,
params: to.params
}));
};
// 调试信息:检查保存的路由对象
console.log('保存到sessionStorage的目标路由:', targetRoute);
console.log('目标路由查询参数:', targetRoute.query);
console.log('目标路由code参数:', targetRoute.query.code);
sessionStorage.setItem('cycle_target_route', JSON.stringify(targetRoute));
// 直接跳转,不使用next
router.push({
path: '/cycle-selection',
......
......@@ -150,6 +150,12 @@ const getCycleList = async (form_code) => {
if (targetRoute) {
sessionStorage.removeItem('cycle_target_route');
const route = JSON.parse(targetRoute);
// 调试信息:检查不需要周期选择时的路由对象
console.log('不需要周期选择时的路由对象:', route);
console.log('不需要周期选择时的查询参数:', route.query);
console.log('不需要周期选择时的code参数:', route.query.code);
// 检查是否需要显示未完成表单弹框
checkUnfinishedForm(route);
} else {
......@@ -176,6 +182,12 @@ const confirmCycleSelection = () => {
x_cycle: selectedCycle.value,
cycle_selected: '1'
};
// 调试信息:检查route对象内容
console.log('周期选择后的路由对象:', route);
console.log('查询参数:', route.query);
console.log('code参数:', route.query.code);
// 清除临时存储
sessionStorage.removeItem('cycle_target_route');
......