fix(router): 修复授权后首次访问跳过周期检查的问题
添加调试信息并优化路由守卫逻辑 当从授权页面返回时跳过周期检查 确保表单检查逻辑在跳过周期检查时正常执行
Showing
3 changed files
with
58 additions
and
3 deletions
| ... | @@ -148,6 +148,8 @@ onMounted(async () => { | ... | @@ -148,6 +148,8 @@ onMounted(async () => { |
| 148 | if (!import.meta.env.DEV && open_auth && form_setting.wxzq_scope && record_openid) { | 148 | if (!import.meta.env.DEV && open_auth && form_setting.wxzq_scope && record_openid) { |
| 149 | // 预览模式不开启 | 149 | // 预览模式不开启 |
| 150 | if (no_preview_model) { | 150 | if (no_preview_model) { |
| 151 | + // 设置标识,让路由守卫跳过首次周期检查 | ||
| 152 | + sessionStorage.setItem('skip_cycle_check_for_auth', 'true'); | ||
| 151 | $router.replace({ | 153 | $router.replace({ |
| 152 | path: '/auth', | 154 | path: '/auth', |
| 153 | query: { | 155 | query: { | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Date: 2022-05-26 13:57:28 | 2 | * @Date: 2022-05-26 13:57:28 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-09 10:29:55 | 4 | + * @LastEditTime: 2025-09-10 10:26:45 |
| 5 | * @FilePath: /data-table/src/router.js | 5 | * @FilePath: /data-table/src/router.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -119,15 +119,56 @@ router.beforeEach((to, from, next) => { | ... | @@ -119,15 +119,56 @@ router.beforeEach((to, from, next) => { |
| 119 | return; | 119 | return; |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | + // 检查是否从授权页面返回,如果是首次访问且可能需要授权,则跳过周期检查 | ||
| 123 | + const isFromAuth = from.path === '/auth'; | ||
| 124 | + const skipCycleCheck = sessionStorage.getItem('skip_cycle_check_for_auth'); | ||
| 125 | + | ||
| 126 | + // 如果不是从授权页面返回,且设置了跳过标识,则先清除标识并跳过周期检查 | ||
| 127 | + if (!isFromAuth && skipCycleCheck === 'true') { | ||
| 128 | + sessionStorage.removeItem('skip_cycle_check_for_auth'); | ||
| 129 | + // 直接执行表单检查逻辑,跳过周期检查 | ||
| 130 | + if (to.query.page_type === 'add' || to.query.page_type === undefined) { | ||
| 131 | + const existingCookie = Cookies.get(to.query.code); | ||
| 132 | + if (existingCookie && to.query.force_back !== '1') { | ||
| 133 | + showConfirmDialog({ | ||
| 134 | + title: '温馨提示', | ||
| 135 | + message: '您还未完成的表单,是否继续?', | ||
| 136 | + confirmButtonColor: styleColor.baseColor, | ||
| 137 | + cancelButtonText: '删除', | ||
| 138 | + closeOnPopstate: false, | ||
| 139 | + }) | ||
| 140 | + .then(() => { | ||
| 141 | + next(); | ||
| 142 | + }) | ||
| 143 | + .catch(() => { | ||
| 144 | + Cookies.remove(to.query.code); | ||
| 145 | + next(); | ||
| 146 | + }); | ||
| 147 | + } else { | ||
| 148 | + next(); | ||
| 149 | + } | ||
| 150 | + } else { | ||
| 151 | + next(); | ||
| 152 | + } | ||
| 153 | + return; | ||
| 154 | + } | ||
| 155 | + | ||
| 122 | // 异步检查周期选择 | 156 | // 异步检查周期选择 |
| 123 | checkCycleSelection(to).then(needsCycleSelection => { | 157 | checkCycleSelection(to).then(needsCycleSelection => { |
| 124 | if (needsCycleSelection) { | 158 | if (needsCycleSelection) { |
| 125 | // 保存目标路由到sessionStorage | 159 | // 保存目标路由到sessionStorage |
| 126 | - sessionStorage.setItem('cycle_target_route', JSON.stringify({ | 160 | + const targetRoute = { |
| 127 | path: to.path, | 161 | path: to.path, |
| 128 | query: to.query, | 162 | query: to.query, |
| 129 | params: to.params | 163 | params: to.params |
| 130 | - })); | 164 | + }; |
| 165 | + | ||
| 166 | + // 调试信息:检查保存的路由对象 | ||
| 167 | + console.log('保存到sessionStorage的目标路由:', targetRoute); | ||
| 168 | + console.log('目标路由查询参数:', targetRoute.query); | ||
| 169 | + console.log('目标路由code参数:', targetRoute.query.code); | ||
| 170 | + | ||
| 171 | + sessionStorage.setItem('cycle_target_route', JSON.stringify(targetRoute)); | ||
| 131 | // 直接跳转,不使用next | 172 | // 直接跳转,不使用next |
| 132 | router.push({ | 173 | router.push({ |
| 133 | path: '/cycle-selection', | 174 | path: '/cycle-selection', | ... | ... |
| ... | @@ -150,6 +150,12 @@ const getCycleList = async (form_code) => { | ... | @@ -150,6 +150,12 @@ const getCycleList = async (form_code) => { |
| 150 | if (targetRoute) { | 150 | if (targetRoute) { |
| 151 | sessionStorage.removeItem('cycle_target_route'); | 151 | sessionStorage.removeItem('cycle_target_route'); |
| 152 | const route = JSON.parse(targetRoute); | 152 | const route = JSON.parse(targetRoute); |
| 153 | + | ||
| 154 | + // 调试信息:检查不需要周期选择时的路由对象 | ||
| 155 | + console.log('不需要周期选择时的路由对象:', route); | ||
| 156 | + console.log('不需要周期选择时的查询参数:', route.query); | ||
| 157 | + console.log('不需要周期选择时的code参数:', route.query.code); | ||
| 158 | + | ||
| 153 | // 检查是否需要显示未完成表单弹框 | 159 | // 检查是否需要显示未完成表单弹框 |
| 154 | checkUnfinishedForm(route); | 160 | checkUnfinishedForm(route); |
| 155 | } else { | 161 | } else { |
| ... | @@ -176,6 +182,12 @@ const confirmCycleSelection = () => { | ... | @@ -176,6 +182,12 @@ const confirmCycleSelection = () => { |
| 176 | x_cycle: selectedCycle.value, | 182 | x_cycle: selectedCycle.value, |
| 177 | cycle_selected: '1' | 183 | cycle_selected: '1' |
| 178 | }; | 184 | }; |
| 185 | + | ||
| 186 | + // 调试信息:检查route对象内容 | ||
| 187 | + console.log('周期选择后的路由对象:', route); | ||
| 188 | + console.log('查询参数:', route.query); | ||
| 189 | + console.log('code参数:', route.query.code); | ||
| 190 | + | ||
| 179 | // 清除临时存储 | 191 | // 清除临时存储 |
| 180 | sessionStorage.removeItem('cycle_target_route'); | 192 | sessionStorage.removeItem('cycle_target_route'); |
| 181 | 193 | ... | ... |
-
Please register or login to post a comment