Browse Source

chore: exception

master
wangxiang 2 years ago
parent
commit
25175b6bd6
No known key found for this signature in database
GPG Key ID: 1BA7946AB6B232E4
  1. 4
      src/router/routes/basic.ts
  2. 10
      src/store/modules/app.ts

4
src/router/routes/basic.ts

@ -8,6 +8,7 @@
import type { AppRouteRecordRaw } from '/@/router/types'; import type { AppRouteRecordRaw } from '/@/router/types';
import { REDIRECT_NAME, LAYOUT, EXCEPTION_COMPONENT, PAGE_NOT_FOUND_NAME } from '/@/router/constant'; import { REDIRECT_NAME, LAYOUT, EXCEPTION_COMPONENT, PAGE_NOT_FOUND_NAME } from '/@/router/constant';
import { useAppStoreWithOut } from '/@/store/modules/app';
export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = { export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
path: '/:path(.*)*', path: '/:path(.*)*',
@ -23,6 +24,9 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
path: '/:path(.*)*', path: '/:path(.*)*',
name: PAGE_NOT_FOUND_NAME, name: PAGE_NOT_FOUND_NAME,
component: EXCEPTION_COMPONENT, component: EXCEPTION_COMPONENT,
props: () => ({
status: useAppStoreWithOut().getPageException
}),
meta: { meta: {
title: 'ErrorPage', title: 'ErrorPage',
hideBreadcrumb: true, hideBreadcrumb: true,

10
src/store/modules/app.ts

@ -21,6 +21,7 @@ import { Persistent } from '/@/utils/cache/persistent';
import { darkMode } from '/@/settings/designSetting'; import { darkMode } from '/@/settings/designSetting';
import { resetRouter } from '/@/router'; import { resetRouter } from '/@/router';
import { deepMerge } from '/@/utils'; import { deepMerge } from '/@/utils';
import { ExceptionEnum } from '/@/enums/exceptionEnum';
interface AppState { interface AppState {
// 主题颜色 // 主题颜色
@ -31,6 +32,8 @@ interface AppState {
projectConfig: ProjectConfig | null; projectConfig: ProjectConfig | null;
// 当窗口收缩时,记住一些状态,在窗口恢复时恢复这些状态 // 当窗口收缩时,记住一些状态,在窗口恢复时恢复这些状态
beforeMiniInfo: BeforeMiniState; beforeMiniInfo: BeforeMiniState;
// 页面异常状态
pageException: ExceptionEnum;
} }
let timeId: TimeoutHandle; let timeId: TimeoutHandle;
@ -41,11 +44,15 @@ export const useAppStore = defineStore({
pageLoading: false, pageLoading: false,
projectConfig: Persistent.getLocal(PROJ_CFG_KEY), projectConfig: Persistent.getLocal(PROJ_CFG_KEY),
beforeMiniInfo: {}, beforeMiniInfo: {},
pageException: ExceptionEnum.PAGE_NOT_FOUND,
}), }),
getters: { getters: {
getPageLoading(): boolean { getPageLoading(): boolean {
return this.pageLoading; return this.pageLoading;
}, },
getPageException(): ExceptionEnum {
return this.pageException;
},
getDarkMode(): 'light' | 'dark' | string { getDarkMode(): 'light' | 'dark' | string {
return this.darkMode || darkMode; return this.darkMode || darkMode;
}, },
@ -72,6 +79,9 @@ export const useAppStore = defineStore({
setPageLoading(loading: boolean): void { setPageLoading(loading: boolean): void {
this.pageLoading = loading; this.pageLoading = loading;
}, },
setPageException(exception: ExceptionEnum): void {
this.pageException = exception;
},
setDarkMode(mode: ThemeEnum): void { setDarkMode(mode: ThemeEnum): void {
this.darkMode = mode; this.darkMode = mode;
localStorage.setItem(APP_DARK_MODE_KEY, mode); localStorage.setItem(APP_DARK_MODE_KEY, mode);

Loading…
Cancel
Save