diff --git a/src/api/home/info/index.ts b/src/api/home/info/index.ts index 676feb35..4c849cf4 100644 --- a/src/api/home/info/index.ts +++ b/src/api/home/info/index.ts @@ -26,6 +26,11 @@ export interface WeatherVO { // 生产计划 API export const HomeApi = { + // 是否允许免登录访问首页 + isPublicAccessEnabled: async () => { + return await request.get({ url: `/home/info/public-access-enabled` }) + }, + // 查询天气 getWeatherInfo: async () => { diff --git a/src/permission.ts b/src/permission.ts index ddfe4b8f..894c235e 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -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}`) // 否则全部重定向到登录页 diff --git a/src/views/mes/energyOverview/index.vue b/src/views/mes/energyOverview/index.vue index 389f32ed..62f7540e 100644 --- a/src/views/mes/energyOverview/index.vue +++ b/src/views/mes/energyOverview/index.vue @@ -332,7 +332,7 @@ const disabledFutureSeconds = ( const defaultTimeRange = getTodayTimeRange() const defaultPickerEndTime = new Date() -const datePickerDefaultTime = [ +const datePickerDefaultTime: [Date, Date] = [ new Date(2000, 0, 1, 0, 0, 0), new Date( 2000, @@ -515,8 +515,8 @@ const regionPieOptions = ref({ ] }) -const trendChartDisplayOptions = computed(() => trendChartOptions.value) -const regionPieDisplayOptions = computed(() => regionPieOptions.value) +const trendChartDisplayOptions = computed(() => trendChartOptions.value as EChartsOption) +const regionPieDisplayOptions = computed(() => regionPieOptions.value as EChartsOption) const metricThemeMap: Record = { total: { icon: 'ep:lightning', theme: 'blue' },