Commit e2333642c43f05055a199e0355044e11e3756782

Authored by vben
1 parent bdce8453

style: some format adjustments

src/layouts/Logo.vue
... ... @@ -23,12 +23,14 @@
23 23 },
24 24 },
25 25 setup(props) {
  26 + const showRef = ref<boolean>(!!props.showTitle);
26 27 const { globSetting } = useSetting();
27 28 const go = useGo();
  29 +
28 30 function handleGoHome() {
29 31 go(PageEnum.BASE_HOME);
30 32 }
31   - const showRef = ref<boolean>(!!props.showTitle);
  33 +
32 34 watch(
33 35 () => props.showTitle,
34 36 (show: boolean) => {
... ... @@ -41,6 +43,7 @@
41 43 }
42 44 }
43 45 );
  46 +
44 47 return {
45 48 handleGoHome,
46 49 globSetting,
... ... @@ -55,7 +58,6 @@
55 58  
56 59 .app-logo {
57 60 display: flex;
58   - // justify-content: center;
59 61 align-items: center;
60 62 cursor: pointer;
61 63  
... ...
src/layouts/iframe/useFrameKeepAlive.ts
  1 +import type { AppRouteRecordRaw } from '/@/router/types';
  2 +
1 3 import { computed, toRaw, unref } from 'vue';
  4 +import { useRouter } from 'vue-router';
  5 +import router from '/@/router';
2 6  
3 7 import { tabStore } from '/@/store/modules/tab';
4 8 import { appStore } from '/@/store/modules/app';
5 9  
6   -import { AppRouteRecordRaw } from '/@/router/types';
7   -import { useRouter } from 'vue-router';
8   -import router from '/@/router';
9 10 import { unique } from '/@/utils';
10 11  
11 12 export function useFrameKeepAlive() {
... ...
src/layouts/page/index.tsx
1 1 import { computed, defineComponent, unref, Transition, KeepAlive, toRaw } from 'vue';
  2 +import { RouterView, RouteLocation } from 'vue-router';
2 3  
3   -import { appStore } from '/@/store/modules/app';
  4 +import FrameLayout from '/@/layouts/iframe/index.vue';
4 5  
5 6 import { useTransition } from './useTransition';
  7 +import { useSetting } from '/@/hooks/core/useSetting';
6 8  
7   -import { RouterView, RouteLocation } from 'vue-router';
8 9 import { tabStore } from '/@/store/modules/tab';
9   -import FrameLayout from '/@/layouts/iframe/index.vue';
  10 +import { appStore } from '/@/store/modules/app';
10 11  
11   -import { useSetting } from '/@/hooks/core/useSetting';
12   -// import { useRouter } from 'vue-router';
13 12 export default defineComponent({
14 13 name: 'PageLayout',
15 14 setup() {
16   - // const { currentRoute } = useRouter();
17 15 const getProjectConfigRef = computed(() => {
18 16 return appStore.getProjectConfig;
19 17 });
... ...
src/router/constant.ts
... ... @@ -22,6 +22,7 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
22 22 hideBreadcrumb: true,
23 23 },
24 24 };
  25 +
25 26 export const REDIRECT_ROUTE: AppRouteRecordRaw = {
26 27 path: '/redirect/:path(.*)*',
27 28 name: 'Redirect',
... ... @@ -31,16 +32,3 @@ export const REDIRECT_ROUTE: AppRouteRecordRaw = {
31 32 hideBreadcrumb: true,
32 33 },
33 34 };
34   -
35   -// Whole site 404
36   -// export const FULL_PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
37   -// path: '/:path(.*)*',
38   -// name: 'FullErrorPage',
39   -// component: EXCEPTION_COMPONENT,
40   -// props: {
41   -// full: true,
42   -// },
43   -// meta: {
44   -// title: 'FullErrorPage',
45   -// },
46   -// };
... ...
src/router/guard/index.ts
1 1 import type { Router } from 'vue-router';
2 2  
3 3 import { Modal, notification } from 'ant-design-vue';
4   -import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel';
  4 +
5 5 import { createProgressGuard } from './progressGuard';
6 6 import { createPermissionGuard } from './permissionGuard';
7 7 import { createPageLoadingGuard } from './pageLoadingGuard';
  8 +
8 9 import { useSetting } from '/@/hooks/core/useSetting';
  10 +
9 11 import { getIsOpenTab, setCurrentTo } from '/@/utils/helper/routeHelper';
10 12 import { setTitle } from '/@/utils/browser';
  13 +import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel';
11 14  
12 15 const { projectSetting, globSetting } = useSetting();
13 16 export function createGuard(router: Router) {
... ... @@ -36,10 +39,7 @@ export function createGuard(router: Router) {
36 39  
37 40 router.afterEach((to) => {
38 41 // change html title
39   -
40   - setTimeout(() => {
41   - setTitle(to.meta.title, globSetting.title);
42   - }, 0);
  42 + setTitle(to.meta.title, globSetting.title);
43 43 });
44 44  
45 45 openNProgress && createProgressGuard(router);
... ...
src/router/guard/permissionGuard.ts
... ... @@ -2,12 +2,11 @@ import type { Router, RouteRecordRaw } from &#39;vue-router&#39;;
2 2  
3 3 import { userStore } from '/@/store/modules/user';
4 4 import { permissionStore } from '/@/store/modules/permission';
  5 +
5 6 import { PageEnum } from '/@/enums/pageEnum';
6 7 import { getToken } from '/@/utils/auth';
7   -import {
8   - // FULL_PAGE_NOT_FOUND_ROUTE,
9   - PAGE_NOT_FOUND_ROUTE,
10   -} from '/@/router/constant';
  8 +
  9 +import { PAGE_NOT_FOUND_ROUTE } from '/@/router/constant';
11 10 import { RootRoute } from '../routes/index';
12 11  
13 12 const LOGIN_PATH = PageEnum.BASE_LOGIN;
... ... @@ -60,6 +59,7 @@ export function createPermissionGuard(router: Router) {
60 59 permissionStore.commitDynamicAddedRouteState(true);
61 60 next(nextData);
62 61 });
  62 +
63 63 router.afterEach((to) => {
64 64 // Just enter the login page and clear the authentication information
65 65 if (to.path === LOGIN_PATH) {
... ...
src/router/guard/progressGuard.ts
... ... @@ -11,6 +11,7 @@ export function createProgressGuard(router: Router) {
11 11 !to.meta.inTab && NProgress.start();
12 12 return true;
13 13 });
  14 +
14 15 router.afterEach(async (to) => {
15 16 !to.meta.inTab && NProgress.done();
16 17 return true;
... ...
src/router/index.ts
... ... @@ -2,6 +2,7 @@ import type { RouteRecordRaw } from &#39;vue-router&#39;;
2 2 import type { App } from 'vue';
3 3  
4 4 import { createRouter, createWebHashHistory } from 'vue-router';
  5 +
5 6 import { scrollWaiter } from '../utils/scrollWaiter';
6 7  
7 8 import { createGuard } from './guard/';
... ... @@ -24,6 +25,7 @@ const router = createRouter({
24 25 }
25 26 },
26 27 });
  28 +
27 29 // reset router
28 30 export function resetRouter() {
29 31 const resetWhiteNameList = [
... ... @@ -45,21 +47,4 @@ export function setupRouter(app: App&lt;Element&gt;) {
45 47 createGuard(router);
46 48 }
47 49  
48   -// // hmr
49   -// if (import.meta.hot) {
50   -// let removeRoutes: (() => void)[] = [];
51   -
52   -// for (let route of routes) {
53   -// removeRoutes.push(router.addRoute(route as RouteRecordRaw));
54   -// }
55   -
56   -// import.meta.hot?.acceptDeps('./routes.ts', ({ routes }) => {
57   -// for (let removeRoute of removeRoutes) removeRoute();
58   -// removeRoutes = [];
59   -// for (let route of routes) {
60   -// removeRoutes.push(router.addRoute(route));
61   -// }
62   -// router.replace('');
63   -// });
64   -// }
65 50 export default router;
... ...
src/router/menus/index.ts
... ... @@ -9,33 +9,7 @@ import { PermissionModeEnum } from &#39;/@/enums/appEnum&#39;;
9 9 import { pathToRegexp } from 'path-to-regexp';
10 10 import modules from 'globby!/@/router/menus/modules/**/*.@(ts)';
11 11  
12   -// ===========================
13   -// ==========module import====
14   -// ===========================
15   -// import dashboard from './modules/dashboard';
16   -
17   -// import exceptionDemo from './modules/demo/exception';
18   -// import iframeDemo from './modules/demo/iframe';
19   -// import compDemo from './modules/demo/comp';
20   -// import permissionDemo from './modules/demo/permission';
21   -// import featDemo from './modules/demo/feat';
22   -// import chartsDemo from './modules/demo/charts';
23   -// import tableDemo from './modules/demo/table';
24   -// import formDemo from './modules/demo/form';
25   -// import treeDemo from './modules/demo/tree';
26   -
27   -const menuModules: MenuModule[] = [
28   - // dashboard,
29   - // featDemo,
30   - // exceptionDemo,
31   - // iframeDemo,
32   - // compDemo,
33   - // permissionDemo,
34   - // chartsDemo,
35   - // tableDemo,
36   - // formDemo,
37   - // treeDemo,
38   -];
  12 +const menuModules: MenuModule[] = [];
39 13  
40 14 Object.keys(modules).forEach((key) => {
41 15 menuModules.push(modules[key]);
... ...
src/router/routes/index.ts
... ... @@ -4,30 +4,7 @@ import { DEFAULT_LAYOUT_COMPONENT, PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from &#39;
4 4 import { genRouteModule } from '/@/utils/helper/routeHelper';
5 5 import modules from 'globby!/@/router/routes/modules/**/*.@(ts)';
6 6  
7   -// import dashboard from './modules/dashboard';
8   -// demo
9   -// import exceptionDemo from './modules/demo/exception';
10   -// import iframeDemo from './modules/demo/iframe';
11   -// import compDemo from './modules/demo/comp';
12   -// import permissionDemo from './modules/demo/permission';
13   -// import featDemo from './modules/demo/feat';
14   -// import chartsDemo from './modules/demo/charts';
15   -// import tableDemo from './modules/demo/table';
16   -// import formDemo from './modules/demo/form';
17   -// import treeDemo from './modules/demo/tree';
18   -
19   -const routeModuleList: AppRouteModule[] = [
20   - // exceptionDemo,
21   - // dashboard,
22   - // iframeDemo,
23   - // compDemo,
24   - // featDemo,
25   - // permissionDemo,
26   - // chartsDemo,
27   - // tableDemo,
28   - // formDemo,
29   - // treeDemo,
30   -];
  7 +const routeModuleList: AppRouteModule[] = [];
31 8  
32 9 Object.keys(modules).forEach((key) => {
33 10 routeModuleList.push(modules[key]);
... ... @@ -38,6 +15,7 @@ export const asyncRoutes = [
38 15 PAGE_NOT_FOUND_ROUTE,
39 16 ...genRouteModule(routeModuleList),
40 17 ];
  18 +
41 19 // 主框架根路由
42 20 export const RootRoute: AppRouteRecordRaw = {
43 21 path: '/',
... ...
src/setup/error-handle/index.ts
... ... @@ -66,25 +66,23 @@ export function scriptErrorHandler(
66 66 if (event === 'Script error.' && !source) {
67 67 return false;
68 68 }
69   - setTimeout(function () {
70   - const errorInfo: Partial<ErrorInfo> = {};
71   - colno = colno || (window.event && (window.event as any).errorCharacter) || 0;
72   - errorInfo.message = event as string;
73   - if (error && error.stack) {
74   - errorInfo.stack = error.stack;
75   - } else {
76   - errorInfo.stack = '';
77   - }
78   - const name = source ? source.substr(source.lastIndexOf('/') + 1) : 'script';
79   - errorStore.commitErrorInfoState({
80   - type: ErrorTypeEnum.SCRIPT,
81   - name: name,
82   - file: source as string,
83   - detail: 'lineno' + lineno,
84   - url: window.location.href,
85   - ...(errorInfo as Pick<ErrorInfo, 'message' | 'stack'>),
86   - });
87   - }, 0);
  69 + const errorInfo: Partial<ErrorInfo> = {};
  70 + colno = colno || (window.event && (window.event as any).errorCharacter) || 0;
  71 + errorInfo.message = event as string;
  72 + if (error && error.stack) {
  73 + errorInfo.stack = error.stack;
  74 + } else {
  75 + errorInfo.stack = '';
  76 + }
  77 + const name = source ? source.substr(source.lastIndexOf('/') + 1) : 'script';
  78 + errorStore.commitErrorInfoState({
  79 + type: ErrorTypeEnum.SCRIPT,
  80 + name: name,
  81 + file: source as string,
  82 + detail: 'lineno' + lineno,
  83 + url: window.location.href,
  84 + ...(errorInfo as Pick<ErrorInfo, 'message' | 'stack'>),
  85 + });
88 86 return true;
89 87 }
90 88  
... ...
src/store/index.ts
... ... @@ -15,7 +15,9 @@ const store = createStore({
15 15 strict: isDev,
16 16 // plugins,
17 17 });
  18 +
18 19 export function setupStore(app: App<Element>) {
19 20 app.use(store);
20 21 }
  22 +
21 23 export default store;
... ...
src/store/modules/app.ts
1   -import store from '/@/store';
2   -import { hotModuleUnregisterModule } from '/@/utils/helper/vuexHelper';
  1 +import type { ProjectConfig } from '/@/types/config';
  2 +
3 3 import { VuexModule, getModule, Module, Mutation, Action } from 'vuex-module-decorators';
  4 +import store from '/@/store';
4 5  
5 6 import { PROJ_CFG_KEY, LOCK_INFO_KEY } from '/@/enums/cacheEnum';
6   -import { ProjectConfig } from '/@/types/config';
7 7  
8   -// import { userStore } from './user';
  8 +import { hotModuleUnregisterModule } from '/@/utils/helper/vuexHelper';
9 9 import { setLocal, getLocal, removeLocal } from '/@/utils/helper/persistent';
10 10 import { deepMerge } from '/@/utils';
  11 +
11 12 import { userStore } from './user';
12 13  
13 14 export interface LockInfo {
... ... @@ -20,12 +21,16 @@ const NAME = &#39;app&#39;;
20 21 hotModuleUnregisterModule(NAME);
21 22 @Module({ dynamic: true, namespaced: true, store, name: NAME })
22 23 class App extends VuexModule {
  24 + // Page loading status
23 25 private pageLoadingState = false;
24 26  
  27 + // project config
25 28 private projectConfigState: ProjectConfig | null = getLocal(PROJ_CFG_KEY);
26 29  
  30 + // lock info
27 31 private lockInfoState: LockInfo | null = getLocal(LOCK_INFO_KEY);
28 32  
  33 + // set main overflow hidden
29 34 private lockMainScrollState = false;
30 35  
31 36 get getPageLoading() {
... ... @@ -87,7 +92,7 @@ class App extends VuexModule {
87 92 }
88 93  
89 94 // /**
90   - // * @description: 解锁
  95 + // * @description: unlock page
91 96 // */
92 97 @Action
93 98 public async unLockAction({ password, valid = true }: { password: string; valid?: boolean }) {
... ...
src/store/modules/error.ts
... ... @@ -25,7 +25,10 @@ const NAME = &#39;error&#39;;
25 25 hotModuleUnregisterModule(NAME);
26 26 @Module({ dynamic: true, namespaced: true, store, name: NAME })
27 27 class Error extends VuexModule implements ErrorState {
  28 + // error log list
28 29 errorInfoState: ErrorInfo[] = [];
  30 +
  31 + // error log count
29 32 errorListCountState = 0;
30 33  
31 34 get getErrorInfoState() {
... ...
src/store/modules/permission.ts
... ... @@ -26,16 +26,16 @@ const NAME = &#39;permission&#39;;
26 26 hotModuleUnregisterModule(NAME);
27 27 @Module({ dynamic: true, namespaced: true, store, name: NAME })
28 28 class Permission extends VuexModule {
29   - // private routesState: AppRouteRecordRaw[] = [];
30   -
31   - // 权限编码列表
  29 + // Permission code list
32 30 private permCodeListState: string[] = [];
33 31  
34 32 // Whether the route has been dynamically added
35 33 private isDynamicAddedRouteState = false;
36 34  
  35 + // To trigger a menu update
37 36 private lastBuildMenuTimeState = 0;
38 37  
  38 + // Backstage menu list
39 39 private backMenuListState: Menu[] = [];
40 40  
41 41 get getPermCodeListState() {
... ... @@ -50,10 +50,6 @@ class Permission extends VuexModule {
50 50 return this.lastBuildMenuTimeState;
51 51 }
52 52  
53   - // get getRoutesState() {
54   - // return this.routesState;
55   - // }
56   -
57 53 get getIsDynamicAddedRouteState() {
58 54 return this.isDynamicAddedRouteState;
59 55 }
... ... @@ -73,11 +69,6 @@ class Permission extends VuexModule {
73 69 this.lastBuildMenuTimeState = new Date().getTime();
74 70 }
75 71  
76   - // @Mutation
77   - // commitRoutesState(routes: AppRouteRecordRaw[]): void {
78   - // this.routesState = routes;
79   - // }
80   -
81 72 @Mutation
82 73 commitDynamicAddedRouteState(added: boolean): void {
83 74 this.isDynamicAddedRouteState = added;
... ...
src/store/modules/tab.ts
... ... @@ -34,18 +34,15 @@ const getOpenKeepAliveRef = computed(() =&gt; appStore.getProjectConfig.openKeepAli
34 34  
35 35 @Module({ namespaced: true, name: NAME, dynamic: true, store })
36 36 class Tab extends VuexModule {
37   - // tab列表
  37 + // tab list
38 38 tabsState: TabItem[] = [];
39   - // 缓存列表
  39 + // tab cache list
40 40 keepAliveTabsState: CacheName[] = [];
41 41  
42 42 currentContextMenuIndexState = -1;
43 43  
44 44 currentContextMenuState: TabItem | null = null;
45 45  
46   - /**
47   - * @description: 获取tabs
48   - */
49 46 get getTabsState() {
50 47 return this.tabsState;
51 48 }
... ... @@ -58,9 +55,6 @@ class Tab extends VuexModule {
58 55 return this.currentContextMenuState;
59 56 }
60 57  
61   - /**
62   - * @description: 获取缓存的tab列表
63   - */
64 58 get getKeepAliveTabsState() {
65 59 return this.keepAliveTabsState;
66 60 }
... ...
src/store/modules/user.ts
... ... @@ -58,7 +58,6 @@ class User extends VuexModule {
58 58 this.userInfoState = null;
59 59 this.tokenState = '';
60 60 this.roleListState = [];
61   - // permissionStore.commitReset();
62 61 }
63 62  
64 63 @Mutation
... ... @@ -136,7 +135,6 @@ class User extends VuexModule {
136 135 resetRouter();
137 136 clearSession();
138 137 clearLocal();
139   - // router.addRoute(FULL_PAGE_NOT_FOUND_ROUTE as RouteRecordRaw);
140 138 permissionStore.commitResetState();
141 139 tabStore.commitResetState();
142 140 this.resetState();
... ...
src/types/config.d.ts
... ... @@ -70,7 +70,6 @@ export interface ProjectConfig {
70 70 headerSetting: HeaderSetting;
71 71 // 菜单类型
72 72 // menuType: MenuTypeEnum;
73   -
74 73 menuSetting: MenuSetting;
75 74  
76 75 messageSetting: MessageSetting;
... ... @@ -88,15 +87,12 @@ export interface ProjectConfig {
88 87 showBreadCrumbIcon: boolean;
89 88 // 使用error-handler-plugin
90 89 useErrorHandle: boolean;
91   -
92 90 // 开启页面切换动画
93 91 openRouterTransition: boolean;
94 92 // 路由切换动画
95 93 routerTransition: RouterTransitionEnum;
96   -
97 94 // 是否开启登录安全校验
98 95 openLoginVerify: boolean;
99   -
100 96 // 是否监听网络变化
101 97 listenNetWork: boolean;
102 98 // 是否开启页面切换loading
... ... @@ -116,23 +112,17 @@ export interface ProjectConfig {
116 112 export interface GlobConfig {
117 113 // 网站标题
118 114 title: string;
119   -
120 115 // 项目路径
121 116 apiUrl: string;
122   -
123 117 urlPrefix?: string;
124   -
125 118 shortName: string;
126 119 }
127 120 export interface GlobEnvConfig {
128 121 // 网站标题
129 122 VITE_GLOB_APP_TITLE: string;
130   -
131 123 // 项目路径
132 124 VITE_GLOB_API_URL: string;
133   -
134 125 VITE_GLOB_API_URL_PREFIX?: string;
135   -
136 126 VITE_GLOB_APP_SHORT_NAME: string;
137 127 }
138 128  
... ...
src/types/global.d.ts
... ... @@ -9,6 +9,7 @@ declare interface IObj&lt;T = any&gt; {
9 9 }
10 10  
11 11 declare function parseInt(s: string | number, radix?: number): number;
  12 +
12 13 declare function parseFloat(string: string | number): number;
13 14  
14 15 declare type Dictionary<T> = Record<string, T>;
... ... @@ -26,6 +27,7 @@ declare type CustomizedHTMLElement&lt;T&gt; = HTMLElement &amp; T;
26 27 declare type Indexable<T = any> = {
27 28 [key: string]: T;
28 29 };
  30 +
29 31 declare type Hash<T> = Indexable<T>;
30 32  
31 33 declare type DeepPartial<T> = {
... ...
src/types/module.d.ts
1 1 declare module 'ant-design-vue/es/locale/zh_CN';
  2 +
2 3 declare module 'globby!/@/router/routes/modules/**/*.@(ts)';
  4 +
3 5 declare module 'globby!/@/router/menus/modules/**/*.@(ts)';
  6 +
4 7 declare const React: string;
... ...
src/types/shim-tsx.d.ts
1   -// 文件: `shim-tsx.d.ts`
2   -import Vue, { VNode } from 'vue';
3   -import type { ComponentRenderProxy } from '@vue/composition-api';
  1 +import type { ComponentRenderProxy, VNode } from 'vue';
4 2  
5 3 declare module '*.tsx' {
6 4 import { defineComponent } from 'vue';
7 5 const component: ReturnType<defineComponent>;
8   - // import { ComponentOptions } from 'vue';
9   - // const component: ReturnType<ComponentOptions>;
10 6 export default component;
11 7 }
12 8  
... ...