diff --git a/src/permission.ts b/src/permission.ts index 0ebd780a..10963534 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -95,8 +95,20 @@ const homePublicAccessWhiteList = [ '/erp/stock/overview' ] +const homePublicAccessParamPaths = ['/', '/index'] + let homePublicAccessEnabled: boolean | undefined +const isEnabledQueryValue = (value: unknown) => { + const rawValue = Array.isArray(value) ? value[0] : value + return ['1', 'true', 'yes', 'on'].includes(String(rawValue ?? '').toLowerCase()) +} + +const hasHomePublicAccessParam = (query: Recordable = {}) => + isEnabledQueryValue(query.public) || + isEnabledQueryValue(query.homePublic) || + isEnabledQueryValue(query.noLogin) + const isHomePublicAccessEnabled = async () => { if (homePublicAccessEnabled !== undefined) return homePublicAccessEnabled try { @@ -107,8 +119,9 @@ const isHomePublicAccessEnabled = async () => { return homePublicAccessEnabled } -const isPublicHomePath = async (path: string) => { +const isPublicHomePath = async (path: string, query: Recordable = {}) => { if (homePublicAccessWhiteList.indexOf(path) === -1) return false + if (homePublicAccessParamPaths.indexOf(path) !== -1 && !hasHomePublicAccessParam(query)) return false return await isHomePublicAccessEnabled() } @@ -161,7 +174,7 @@ router.beforeEach(async (to, from, next) => { } } } else { - if (whiteList.indexOf(to.path) !== -1 || (await isPublicHomePath(to.path))) { + if (whiteList.indexOf(to.path) !== -1 || (await isPublicHomePath(to.path, to.query))) { next() } else { next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts index 797f6e43..fda8f604 100644 --- a/src/router/modules/remaining.ts +++ b/src/router/modules/remaining.ts @@ -53,7 +53,7 @@ const remainingRouter: AppRouteRecordRaw[] = [ { path: '/', component: Layout, - redirect: '/index', + redirect: (to) => ({ path: '/index', query: to.query }), name: 'Root', meta: {}, children: [ diff --git a/src/views/iot/runoverview/index.vue b/src/views/iot/runoverview/index.vue index ab4ec980..718d1906 100644 --- a/src/views/iot/runoverview/index.vue +++ b/src/views/iot/runoverview/index.vue @@ -2,7 +2,7 @@