|
|
|
|
@ -8,6 +8,7 @@ import { usePageLoading } from '@/hooks/web/usePageLoading'
|
|
|
|
|
import { useDictStoreWithOut } from '@/store/modules/dict'
|
|
|
|
|
import { useUserStoreWithOut } from '@/store/modules/user'
|
|
|
|
|
import { usePermissionStoreWithOut } from '@/store/modules/permission'
|
|
|
|
|
import { HomeApi } from '@/api/home/info'
|
|
|
|
|
|
|
|
|
|
const { start, done } = useNProgress()
|
|
|
|
|
|
|
|
|
|
@ -79,12 +80,32 @@ const whiteList = [
|
|
|
|
|
'/auth-redirect',
|
|
|
|
|
'/bind',
|
|
|
|
|
'/register',
|
|
|
|
|
'/oauthLogin/gitee',
|
|
|
|
|
'/oauthLogin/gitee'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const homePublicAccessWhiteList = [
|
|
|
|
|
'/iot/report/dashboardPage/Dashboard8',
|
|
|
|
|
'/iot/report/dashboardPage/Dashboard1',
|
|
|
|
|
'/iot/report/dashboardPage/Dashboard3'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
let homePublicAccessEnabled: boolean | undefined
|
|
|
|
|
|
|
|
|
|
const isHomePublicAccessEnabled = async () => {
|
|
|
|
|
if (homePublicAccessEnabled !== undefined) return homePublicAccessEnabled
|
|
|
|
|
try {
|
|
|
|
|
homePublicAccessEnabled = await HomeApi.isPublicAccessEnabled()
|
|
|
|
|
} catch {
|
|
|
|
|
homePublicAccessEnabled = false
|
|
|
|
|
}
|
|
|
|
|
return homePublicAccessEnabled
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isPublicHomePath = async (path: string) => {
|
|
|
|
|
if (homePublicAccessWhiteList.indexOf(path) === -1) return false
|
|
|
|
|
return await isHomePublicAccessEnabled()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 路由加载前
|
|
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
|
|
|
start()
|
|
|
|
|
@ -134,7 +155,7 @@ router.beforeEach(async (to, from, next) => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (whiteList.indexOf(to.path) !== -1) {
|
|
|
|
|
if (whiteList.indexOf(to.path) !== -1 || (await isPublicHomePath(to.path))) {
|
|
|
|
|
next()
|
|
|
|
|
} else {
|
|
|
|
|
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
|
|
|
|
|