Commit ad6b51e0 by lijiabin

fix: 修复 nas 服务异常导致系统白屏的问题

登录时 await 了 nas 的分片鉴权接口 nas 挂掉时异常会抛到路由守卫
导致首次导航失败 isReady reject app.mount 不执行 整屏白屏

- 分片 token 改为不 await 放后台获取 失败只打日志 不阻断登录
- 守卫里的登录加 try/catch 失败给提示而不是静默中断导航
- isReady 加 catch 兜底 保证任何情况下都能把应用挂载出来

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
parent 534f21d2
......@@ -41,6 +41,13 @@ app.directive('parse-comment', vParseComment)
// 全局组件挂载
app.component('SvgIcon', SvgIcon)
router.isReady().then(() => {
app.mount('#app')
})
// 首次导航的守卫一旦抛错 isReady 会 reject 页面就永远挂不上去(整屏白屏)
// 所以这里兜底 无论首次导航成功与否都要把应用挂载出来
router
.isReady()
.catch((error) => {
console.error('首次路由导航失败 仍然挂载应用', error)
})
.then(() => {
app.mount('#app')
})
......@@ -4,6 +4,7 @@ import { saveScrollPosition } from './scrollStorage'
import { parseCode } from '@/utils/wxUtil'
import { useUserStore } from '@/stores'
import { finishPageProgress, startPageProgress } from '@/components/common/Progress/usePageProgress'
import { push } from 'notivue'
// 白名单
const WHITE_LIST: string[] = ['/aa']
......@@ -30,10 +31,17 @@ export function registerRouterGuards(router: Router) {
if (code) {
// 如果有token 就不需要重新获取用户信息
// if (!userStore.token || !userStore.refreshToken) {
await userStore.getUserInfoByCode({
code,
isCodeLogin: 0,
})
try {
await userStore.getUserInfoByCode({
code,
isCodeLogin: 0,
})
} catch (error) {
// 守卫里抛错会直接中断导航 页面白屏 什么提示都没有
// 这里兜住 给个提示再照常进页面 后续接口 401 会走重新登录的逻辑
console.error('企微 code 登录失败', error)
push.error('登录失败,请刷新页面重试')
}
// }
return {
path: to.path,
......
......@@ -45,8 +45,15 @@ export const useUserStore = defineStore('user', () => {
setUserInfoAndToken(data)
// 同时获取关于分片的token
const token = await getChunkApiAuthToken(data.account)
setChunkApiAuthToken(token)
// 这个 token 走的是 nas 那边的接口 跟登录、跟首页展示都没有依赖关系
// 所以不 await 直接放后台跑 让首页尽快出来 nas 慢或者挂了也不会拖住登录
// 这里的 catch 不能省 不然 nas 挂掉时会变成未处理的 promise rejection
// 万一没拿到 等真正要分片上传的时候会再补一次(见 ensureChunkApiAuthToken)
getChunkApiAuthToken(data.account)
.then(setChunkApiAuthToken)
.catch((error) => {
console.error('获取分片上传 token 失败 不影响登录', error)
})
}
const getNewToken = async () => {
const { data } = await refreshTokenApi(refreshToken.value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment