* feat: 权限验证功能 * chore: v2.10.0 * feat: 500 服务异常页面 * feat: 只有结束才会滚动到底部 * chore: 修改 CHANGELOG * chore: 不存在时输出默认报错
26 lines
622 B
TypeScript
26 lines
622 B
TypeScript
import type { Router } from 'vue-router'
|
|
import { useAuthStoreWithout } from '@/store/modules/auth'
|
|
|
|
export function setupPageGuard(router: Router) {
|
|
router.beforeEach(async (from, to, next) => {
|
|
const authStore = useAuthStoreWithout()
|
|
if (!authStore.session) {
|
|
try {
|
|
const data = await authStore.getSession()
|
|
if (String(data.auth) === 'false' && authStore.token)
|
|
authStore.removeToken()
|
|
next()
|
|
}
|
|
catch (error) {
|
|
if (from.path !== '/500')
|
|
next({ name: '500' })
|
|
else
|
|
next()
|
|
}
|
|
}
|
|
else {
|
|
next()
|
|
}
|
|
})
|
|
}
|