Commit b7ce74abd61fbb2a47344d9dc89994531e66b6f0

Authored by Vben
1 parent 371af18d

refactor: refactor the project to solve the hot update problem caused by circula…

…r dependencies close #301
.vscode/settings.json
... ... @@ -138,6 +138,7 @@
138 138 "vetur.format.defaultFormatter.ts": "prettier-tslint",
139 139 "vetur.format.defaultFormatter.js": "prettier",
140 140 "vetur.languageFeatures.codeActions": false,
  141 + "vetur.validation.script": false,
141 142 "vetur.format.defaultFormatterOptions": {
142 143 "js-beautify-html": {
143 144 "wrap_attributes": "force-expand-multiline"
... ... @@ -188,6 +189,11 @@
188 189 "editor.codeActionsOnSave": {
189 190 "source.fixAll.eslint": true
190 191 },
  192 + "[vue]": {
  193 + "editor.codeActionsOnSave": {
  194 + "source.fixAll.eslint": false
  195 + }
  196 + },
191 197 "i18n-ally.localesPaths": ["src/locales/lang"],
192 198 "i18n-ally.keystyle": "nested",
193 199 "i18n-ally.sortKeys": true,
... ...
CHANGELOG.zh_CN.md
  1 +## Wip
  2 +
  3 +### ✨ Refactor
  4 +
  5 +- 重构项目以解决循环依赖项导致的热更新问题
  6 +
1 7 ## 2.0.3 (2021-03-07)
2 8  
3 9 ### ✨ Features
... ...
package.json
... ... @@ -53,7 +53,7 @@
53 53 "devDependencies": {
54 54 "@commitlint/cli": "^12.0.1",
55 55 "@commitlint/config-conventional": "^12.0.1",
56   - "@iconify/json": "^1.1.312",
  56 + "@iconify/json": "^1.1.313",
57 57 "@ls-lint/ls-lint": "^1.9.2",
58 58 "@purge-icons/generated": "^0.7.0",
59 59 "@types/crypto-js": "^4.0.1",
... ... @@ -119,7 +119,7 @@
119 119 "resolutions": {
120 120 "//": "Used to install imagemin dependencies, because imagemin may not be installed in China.If it is abroad, you can delete it",
121 121 "bin-wrapper": "npm:bin-wrapper-china",
122   - "esbuild": "0.8.56",
  122 + "esbuild": "0.8.57",
123 123 "rollup": "2.40.0"
124 124 },
125 125 "repository": {
... ...
src/api/sys/user.ts
... ... @@ -5,6 +5,7 @@ import {
5 5 GetUserInfoByUserIdParams,
6 6 GetUserInfoByUserIdModel,
7 7 } from './model/userModel';
  8 +
8 9 import { ErrorMessageMode } from '/@/utils/http/axios/types';
9 10  
10 11 enum Api {
... ...
src/components/Table/src/types/table.ts
... ... @@ -5,10 +5,12 @@ import type {
5 5 ColumnProps,
6 6 TableRowSelection as ITableRowSelection,
7 7 } from 'ant-design-vue/lib/table/interface';
  8 +
8 9 import { ComponentType } from './componentType';
9 10 import { VueNode } from '/@/utils/propTypes';
10   -// import { ColumnProps } from './column';
  11 +
11 12 export declare type SortOrder = 'ascend' | 'descend';
  13 +
12 14 export interface TableCurrentDataSource<T = Recordable> {
13 15 currentDataSource: T[];
14 16 }
... ...
src/directives/permission.ts
... ... @@ -5,12 +5,13 @@
5 5 */
6 6 import type { App, Directive, DirectiveBinding } from 'vue';
7 7  
8   -import { appStore } from '/@/store/modules/app';
  8 +import projectSetting from '/@/settings/projectSetting';
9 9 import { usePermission } from '/@/hooks/web/usePermission';
10 10 import { PermissionModeEnum } from '/@/enums/appEnum';
11   -const { hasPermission } = usePermission();
12 11  
13 12 function isAuth(el: Element, binding: any) {
  13 + const { hasPermission } = usePermission();
  14 +
14 15 const value = binding.value;
15 16 if (!value) return;
16 17 if (!hasPermission(value)) {
... ... @@ -19,7 +20,7 @@ function isAuth(el: Element, binding: any) {
19 20 }
20 21  
21 22 function isBackMode() {
22   - return appStore.getProjectConfig.permissionMode === PermissionModeEnum.BACK;
  23 + return projectSetting.permissionMode === PermissionModeEnum.BACK;
23 24 }
24 25  
25 26 const mounted = (el: Element, binding: DirectiveBinding<any>) => {
... ...
src/hooks/web/usePermission.ts
... ... @@ -9,6 +9,7 @@ import { useTabs } from &#39;./useTabs&#39;;
9 9 import router, { resetRouter } from '/@/router';
10 10 // import { RootRoute } from '/@/router/routes';
11 11  
  12 +import projectSetting from '/@/settings/projectSetting';
12 13 import { PermissionModeEnum } from '/@/enums/appEnum';
13 14 import { RoleEnum } from '/@/enums/roleEnum';
14 15  
... ... @@ -24,7 +25,7 @@ export function usePermission() {
24 25 async function togglePermissionMode() {
25 26 appStore.commitProjectConfigState({
26 27 permissionMode:
27   - appStore.getProjectConfig.permissionMode === PermissionModeEnum.BACK
  28 + projectSetting.permissionMode === PermissionModeEnum.BACK
28 29 ? PermissionModeEnum.ROLE
29 30 : PermissionModeEnum.BACK,
30 31 });
... ... @@ -51,7 +52,7 @@ export function usePermission() {
51 52 * Determine whether there is permission
52 53 */
53 54 function hasPermission(value?: RoleEnum | RoleEnum[] | string | string[], def = true): boolean {
54   - const permMode = appStore.getProjectConfig.permissionMode;
  55 + const permMode = projectSetting.permissionMode;
55 56 if (PermissionModeEnum.ROLE === permMode) {
56 57 // Visible by default
57 58 if (!value) {
... ... @@ -81,7 +82,7 @@ export function usePermission() {
81 82 * @param roles
82 83 */
83 84 async function changeRole(roles: RoleEnum | RoleEnum[]): Promise<void> {
84   - if (appStore.getProjectConfig.permissionMode !== PermissionModeEnum.ROLE) {
  85 + if (projectSetting.permissionMode !== PermissionModeEnum.ROLE) {
85 86 throw new Error(
86 87 'Please switch PermissionModeEnum to ROLE mode in the configuration to operate!'
87 88 );
... ...
src/layouts/default/setting/components/SettingFooter.vue
... ... @@ -19,17 +19,23 @@
19 19 <script lang="ts">
20 20 import { defineComponent, unref } from 'vue';
21 21  
22   - import { useDesign } from '/@/hooks/web/useDesign';
23   - import { useI18n } from '/@/hooks/web/useI18n';
24 22 import { CopyOutlined, RedoOutlined } from '@ant-design/icons-vue';
  23 +
25 24 import { appStore } from '/@/store/modules/app';
26   - import defaultSetting from '/@/settings/projectSetting';
  25 + import { permissionStore } from '/@/store/modules/permission';
  26 + import { tabStore } from '/@/store/modules/tab';
  27 + import { userStore } from '/@/store/modules/user';
  28 +
  29 + import { useDesign } from '/@/hooks/web/useDesign';
  30 + import { useI18n } from '/@/hooks/web/useI18n';
27 31 import { useMessage } from '/@/hooks/web/useMessage';
28 32 import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
29 33 import { useRootSetting } from '/@/hooks/setting/useRootSetting';
  34 +
30 35 import { updateColorWeak } from '/@/logics/theme/updateColorWeak';
31 36 import { updateGrayMode } from '/@/logics/theme/updateGrayMode';
32 37  
  38 + import defaultSetting from '/@/settings/projectSetting';
33 39 export default defineComponent({
34 40 name: 'SettingFooter',
35 41 components: { CopyOutlined, RedoOutlined },
... ... @@ -63,6 +69,9 @@
63 69 function handleClearAndRedo() {
64 70 localStorage.clear();
65 71 appStore.resumeAllState();
  72 + permissionStore.commitResetState();
  73 + tabStore.commitResetState();
  74 + userStore.commitResetState();
66 75 location.reload();
67 76 }
68 77 return {
... ...
src/layouts/page/useCache.ts
... ... @@ -3,17 +3,21 @@ import type { RouteLocation } from &#39;vue-router&#39;;
3 3 import { computed, ref, unref } from 'vue';
4 4 import { useRootSetting } from '/@/hooks/setting/useRootSetting';
5 5 import { tryTsxEmit } from '/@/utils/helper/vueHelper';
6   -import { tabStore, PAGE_LAYOUT_KEY } from '/@/store/modules/tab';
7 6  
8 7 import { useRouter } from 'vue-router';
  8 +import { useStore } from 'vuex';
9 9  
10 10 const ParentLayoutName = 'ParentLayout';
11 11  
  12 +const PAGE_LAYOUT_KEY = '__PAGE_LAYOUT__';
  13 +
12 14 export function getKey(component: FunctionalComponent & { type: Indexable }, route: RouteLocation) {
13 15 return !!component?.type.parentView ? {} : { key: route.fullPath };
14 16 }
15 17  
16 18 export function useCache(isPage: boolean) {
  19 + const { getters } = useStore();
  20 +
17 21 const name = ref('');
18 22 const { currentRoute } = useRouter();
19 23  
... ... @@ -38,7 +42,7 @@ export function useCache(isPage: boolean) {
38 42 if (!unref(getOpenKeepAlive)) {
39 43 return [];
40 44 }
41   - const cached = tabStore.getCachedMapState;
  45 + const cached = getters['app-tab/getCachedMapState'];
42 46  
43 47 if (isPage) {
44 48 // page Layout
... ...
src/main.ts
... ... @@ -17,9 +17,11 @@ import { setupStore } from &#39;/@/store&#39;;
17 17 import { setupErrorHandle } from '/@/logics/error-handle';
18 18 import { setupGlobDirectives } from '/@/directives';
19 19 import { setupI18n } from '/@/locales/setupI18n';
20   -
21 20 import { registerGlobComp } from '/@/components/registerGlobComp';
22 21  
  22 +// router-guard
  23 +import '/@/router/guard';
  24 +
23 25 // Register icon Sprite
24 26 import 'vite-plugin-svg-icons/register';
25 27  
... ... @@ -32,6 +34,7 @@ import { isDevMode } from &#39;/@/utils/env&#39;;
32 34  
33 35 // Multilingual configuration
34 36 await setupI18n(app);
  37 +
35 38 // Configure routing
36 39 setupRouter(app);
37 40  
... ...
src/router/guard/index.ts
1   -import { Router } from 'vue-router';
  1 +import router from '/@/router';
2 2  
3 3 import { createProgressGuard } from './progressGuard';
4 4 import { createPermissionGuard } from './permissionGuard';
... ... @@ -10,14 +10,12 @@ import { createHttpGuard } from &#39;./httpGuard&#39;;
10 10 import { createPageGuard } from './pageGuard';
11 11 import { createStateGuard } from './stateGuard';
12 12  
13   -export function createGuard(router: Router) {
14   - createPageGuard(router);
15   - createPageLoadingGuard(router);
16   - createHttpGuard(router);
17   - createScrollGuard(router);
18   - createMessageGuard(router);
19   - createTitleGuard(router);
20   - createProgressGuard(router);
21   - createPermissionGuard(router);
22   - createStateGuard(router);
23   -}
  13 +createPageGuard(router);
  14 +createPageLoadingGuard(router);
  15 +createHttpGuard(router);
  16 +createScrollGuard(router);
  17 +createMessageGuard(router);
  18 +createTitleGuard(router);
  19 +createProgressGuard(router);
  20 +createPermissionGuard(router);
  21 +createStateGuard(router);
... ...
src/router/guard/stateGuard.ts
1 1 import type { Router } from 'vue-router';
2 2 import { appStore } from '/@/store/modules/app';
  3 +import { tabStore } from '/@/store/modules/tab';
  4 +import { userStore } from '/@/store/modules/user';
  5 +import { permissionStore } from '/@/store/modules/permission';
3 6 import { PageEnum } from '/@/enums/pageEnum';
4 7 import { removeTabChangeListener } from '/@/logics/mitt/tabChange';
5 8  
... ... @@ -8,6 +11,9 @@ export function createStateGuard(router: Router) {
8 11 // Just enter the login page and clear the authentication information
9 12 if (to.path === PageEnum.BASE_LOGIN) {
10 13 appStore.resumeAllState();
  14 + permissionStore.commitResetState();
  15 + tabStore.commitResetState();
  16 + userStore.commitResetState();
11 17 removeTabChangeListener();
12 18 }
13 19 });
... ...
src/router/index.ts
... ... @@ -3,7 +3,6 @@ import type { App } from &#39;vue&#39;;
3 3  
4 4 import { createRouter, createWebHashHistory } from 'vue-router';
5 5  
6   -import { createGuard } from './guard';
7 6 import { basicRoutes, LoginRoute } from './routes';
8 7 import { REDIRECT_NAME } from './constant';
9 8  
... ... @@ -30,7 +29,6 @@ export function resetRouter() {
30 29 // config router
31 30 export function setupRouter(app: App<Element>) {
32 31 app.use(router);
33   - createGuard(router);
34 32 }
35 33  
36 34 export default router;
... ...
src/store/modules/app.ts
... ... @@ -10,10 +10,6 @@ import { Persistent } from &#39;/@/utils/cache/persistent&#39;;
10 10 import { deepMerge } from '/@/utils';
11 11  
12 12 import { resetRouter } from '/@/router';
13   -import { permissionStore } from './permission';
14   -import { tabStore } from './tab';
15   -
16   -import { userStore } from './user';
17 13  
18 14 export interface LockInfo {
19 15 pwd: string | undefined;
... ... @@ -66,10 +62,6 @@ export default class App extends VuexModule {
66 62 async resumeAllState() {
67 63 resetRouter();
68 64 Persistent.clearAll();
69   -
70   - permissionStore.commitResetState();
71   - tabStore.commitResetState();
72   - userStore.commitResetState();
73 65 }
74 66  
75 67 @Action
... ...
src/store/modules/lock.ts
  1 +import type { LockInfo } from '/@/store/types';
  2 +
1 3 import { VuexModule, getModule, Module, Mutation, Action } from 'vuex-module-decorators';
2 4 import store from '/@/store';
3 5  
... ... @@ -8,11 +10,6 @@ import { Persistent } from &#39;/@/utils/cache/persistent&#39;;
8 10  
9 11 import { userStore } from './user';
10 12  
11   -export interface LockInfo {
12   - pwd: string | undefined;
13   - isLock: boolean;
14   -}
15   -
16 13 const NAME = 'app-lock';
17 14 hotModuleUnregisterModule(NAME);
18 15 @Module({ dynamic: true, namespaced: true, store, name: NAME })
... ...
src/store/modules/tab.ts
1   -import { toRaw } from 'vue';
  1 +import type { RouteLocationNormalized, RouteLocationRaw } from 'vue-router';
2 2  
3   -import { unref } from 'vue';
  3 +import { toRaw, unref } from 'vue';
4 4 import { Action, Module, Mutation, VuexModule, getModule } from 'vuex-module-decorators';
5 5 import { hotModuleUnregisterModule } from '/@/utils/helper/vuexHelper';
6 6  
... ... @@ -9,8 +9,8 @@ import { PageEnum } from &#39;/@/enums/pageEnum&#39;;
9 9 import store from '/@/store';
10 10 import router from '/@/router';
11 11 import { PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '/@/router/constant';
12   -import { RouteLocationNormalized, RouteLocationRaw } from 'vue-router';
13 12 import { getRoute } from '/@/router/helper/routeHelper';
  13 +
14 14 import { useGo, useRedo } from '/@/hooks/web/usePage';
15 15 import { cloneDeep } from 'lodash-es';
16 16  
... ...
src/store/modules/user.ts
... ... @@ -3,6 +3,7 @@ import type {
3 3 GetUserInfoByUserIdModel,
4 4 GetUserInfoByUserIdParams,
5 5 } from '/@/api/sys/model/userModel';
  6 +import type { UserInfo } from '/@/store/types';
6 7  
7 8 import store from '/@/store/index';
8 9 import { VuexModule, Module, getModule, Mutation, Action } from 'vuex-module-decorators';
... ... @@ -10,7 +11,7 @@ import { hotModuleUnregisterModule } from &#39;/@/utils/helper/vuexHelper&#39;;
10 11  
11 12 import { PageEnum } from '/@/enums/pageEnum';
12 13 import { RoleEnum } from '/@/enums/roleEnum';
13   -import { CacheTypeEnum, ROLES_KEY, TOKEN_KEY, USER_INFO_KEY } from '/@/enums/cacheEnum';
  14 +import { ROLES_KEY, TOKEN_KEY, USER_INFO_KEY } from '/@/enums/cacheEnum';
14 15  
15 16 import { useMessage } from '/@/hooks/web/useMessage';
16 17  
... ... @@ -18,29 +19,13 @@ import router from &#39;/@/router&#39;;
18 19  
19 20 import { loginApi, getUserInfoById } from '/@/api/sys/user';
20 21  
21   -import { Persistent, BasicKeys } from '/@/utils/cache/persistent';
22 22 import { useI18n } from '/@/hooks/web/useI18n';
23 23 import { ErrorMessageMode } from '/@/utils/http/axios/types';
24   -import projectSetting from '/@/settings/projectSetting';
25   -
26   -export type UserInfo = Omit<GetUserInfoByUserIdModel, 'roles'>;
27   -
28   -const { permissionCacheType } = projectSetting;
29   -const isLocal = permissionCacheType === CacheTypeEnum.LOCAL;
  24 +import { getAuthCache, setAuthCache } from '/@/utils/auth/index';
30 25  
31 26 const NAME = 'app-user';
32 27 hotModuleUnregisterModule(NAME);
33 28  
34   -function getCache<T>(key: BasicKeys) {
35   - const fn = isLocal ? Persistent.getLocal : Persistent.getSession;
36   - return fn(key) as T;
37   -}
38   -
39   -function setCache(key: BasicKeys, value) {
40   - const fn = isLocal ? Persistent.setLocal : Persistent.setSession;
41   - return fn(key, value);
42   -}
43   -
44 29 @Module({ namespaced: true, name: NAME, dynamic: true, store })
45 30 class User extends VuexModule {
46 31 // user info
... ... @@ -53,15 +38,15 @@ class User extends VuexModule {
53 38 private roleListState: RoleEnum[] = [];
54 39  
55 40 get getUserInfoState(): UserInfo {
56   - return this.userInfoState || getCache<UserInfo>(USER_INFO_KEY) || {};
  41 + return this.userInfoState || getAuthCache<UserInfo>(USER_INFO_KEY) || {};
57 42 }
58 43  
59 44 get getTokenState(): string {
60   - return this.tokenState || getCache<string>(TOKEN_KEY);
  45 + return this.tokenState || getAuthCache<string>(TOKEN_KEY);
61 46 }
62 47  
63 48 get getRoleListState(): RoleEnum[] {
64   - return this.roleListState.length > 0 ? this.roleListState : getCache<RoleEnum[]>(ROLES_KEY);
  49 + return this.roleListState.length > 0 ? this.roleListState : getAuthCache<RoleEnum[]>(ROLES_KEY);
65 50 }
66 51  
67 52 @Mutation
... ... @@ -74,19 +59,19 @@ class User extends VuexModule {
74 59 @Mutation
75 60 commitUserInfoState(info: UserInfo): void {
76 61 this.userInfoState = info;
77   - setCache(USER_INFO_KEY, info);
  62 + setAuthCache(USER_INFO_KEY, info);
78 63 }
79 64  
80 65 @Mutation
81 66 commitRoleListState(roleList: RoleEnum[]): void {
82 67 this.roleListState = roleList;
83   - setCache(ROLES_KEY, roleList);
  68 + setAuthCache(ROLES_KEY, roleList);
84 69 }
85 70  
86 71 @Mutation
87 72 commitTokenState(info: string): void {
88 73 this.tokenState = info;
89   - setCache(TOKEN_KEY, info);
  74 + setAuthCache(TOKEN_KEY, info);
90 75 }
91 76  
92 77 /**
... ...
src/store/types.ts 0 → 100644
  1 +export interface LockInfo {
  2 + pwd: string | undefined;
  3 + isLock: boolean;
  4 +}
  5 +
  6 +export interface UserInfo {
  7 + // 用户id
  8 + userId: string | number;
  9 + // 用户名
  10 + username: string;
  11 + // 真实名字
  12 + realName: string;
  13 + // 介绍
  14 + desc?: string;
  15 +}
... ...
src/utils/auth/index.ts 0 → 100644
  1 +import { Persistent, BasicKeys } from '/@/utils/cache/persistent';
  2 +import { CacheTypeEnum } from '/@/enums/cacheEnum';
  3 +import projectSetting from '/@/settings/projectSetting';
  4 +import { TOKEN_KEY } from '/@/enums/cacheEnum';
  5 +
  6 +const { permissionCacheType } = projectSetting;
  7 +const isLocal = permissionCacheType === CacheTypeEnum.LOCAL;
  8 +
  9 +export function getToken() {
  10 + return getAuthCache(TOKEN_KEY);
  11 +}
  12 +
  13 +export function getAuthCache<T>(key: BasicKeys) {
  14 + const fn = isLocal ? Persistent.getLocal : Persistent.getSession;
  15 + return fn(key) as T;
  16 +}
  17 +
  18 +export function setAuthCache(key: BasicKeys, value) {
  19 + const fn = isLocal ? Persistent.setLocal : Persistent.setSession;
  20 + return fn(key, value);
  21 +}
... ...
src/utils/cache/persistent.ts
1   -import type { UserInfo } from '/@/store/modules/user';
2   -import type { LockInfo } from '/@/store/modules/lock';
  1 +import type { LockInfo, UserInfo } from '/@/store/types';
  2 +
3 3 import { ProjectConfig } from '/#/config';
4 4  
5 5 import { createLocalStorage, createSessionStorage } from '/@/utils/cache';
... ...
src/utils/env.ts
1 1 import type { GlobEnvConfig } from '/#/config';
2 2  
3   -import { useGlobSetting } from '/@/hooks/setting';
  3 +import { warn } from '/@/utils/log';
4 4 import pkg from '../../package.json';
5 5 import { getConfigFileName } from '../../build/getConfigFileName';
6 6  
7 7 export function getCommonStoragePrefix() {
8   - const globSetting = useGlobSetting();
9   - return `${globSetting.shortName}__${getEnv()}`.toUpperCase();
  8 + const { VITE_GLOB_APP_SHORT_NAME } = getAppEnvConfig();
  9 + return `${VITE_GLOB_APP_SHORT_NAME}__${getEnv()}`.toUpperCase();
10 10 }
11 11  
12 12 // Generate cache key according to version
... ... @@ -21,7 +21,27 @@ export function getAppEnvConfig() {
21 21 ? // Get the global configuration (the configuration will be extracted independently when packaging)
22 22 ((import.meta.env as unknown) as GlobEnvConfig)
23 23 : window[ENV_NAME as any]) as unknown) as GlobEnvConfig;
24   - return ENV;
  24 +
  25 + const {
  26 + VITE_GLOB_APP_TITLE,
  27 + VITE_GLOB_API_URL,
  28 + VITE_GLOB_APP_SHORT_NAME,
  29 + VITE_GLOB_API_URL_PREFIX,
  30 + VITE_GLOB_UPLOAD_URL,
  31 + } = ENV;
  32 +
  33 + if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) {
  34 + warn(
  35 + `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`
  36 + );
  37 + }
  38 + return {
  39 + VITE_GLOB_APP_TITLE,
  40 + VITE_GLOB_API_URL,
  41 + VITE_GLOB_APP_SHORT_NAME,
  42 + VITE_GLOB_API_URL_PREFIX,
  43 + VITE_GLOB_UPLOAD_URL,
  44 + };
25 45 }
26 46  
27 47 /**
... ...
src/utils/http/axios/axiosTransform.ts
... ... @@ -4,6 +4,12 @@
4 4 import type { AxiosRequestConfig, AxiosResponse } from 'axios';
5 5 import type { RequestOptions, Result } from './types';
6 6  
  7 +export interface CreateAxiosOptions extends AxiosRequestConfig {
  8 + prefixUrl?: string;
  9 + transform?: AxiosTransform;
  10 + requestOptions?: RequestOptions;
  11 +}
  12 +
7 13 export abstract class AxiosTransform {
8 14 /**
9 15 * @description: Process configuration before request
... ...
src/utils/http/axios/checkStatus.ts
1 1 import { useMessage } from '/@/hooks/web/useMessage';
2   -import { userStore } from '/@/store/modules/user';
3 2 import { useI18n } from '/@/hooks/web/useI18n';
  3 +import router from '/@/router';
  4 +import { PageEnum } from '/@/enums/pageEnum';
  5 +
4 6 const { createMessage } = useMessage();
5 7  
6 8 const error = createMessage.error!;
... ... @@ -15,7 +17,7 @@ export function checkStatus(status: number, msg: string): void {
15 17 // Return to the current page after successful login. This step needs to be operated on the login page.
16 18 case 401:
17 19 error(t('sys.api.errMsg401'));
18   - userStore.logout(true);
  20 + router.push(PageEnum.BASE_LOGIN);
19 21 break;
20 22 case 403:
21 23 error(t('sys.api.errMsg403'));
... ...
src/utils/http/axios/index.ts
... ... @@ -2,10 +2,10 @@
2 2 // The axios configuration can be changed according to the project, just change the file, other files can be left unchanged
3 3  
4 4 import type { AxiosResponse } from 'axios';
5   -import type { CreateAxiosOptions, RequestOptions, Result } from './types';
6   -import { VAxios } from './Axios';
7   -import { AxiosTransform } from './axiosTransform';
  5 +import type { RequestOptions, Result } from './types';
  6 +import type { AxiosTransform, CreateAxiosOptions } from './axiosTransform';
8 7  
  8 +import { VAxios } from './Axios';
9 9 import { checkStatus } from './checkStatus';
10 10  
11 11 import { useGlobSetting } from '/@/hooks/setting';
... ... @@ -14,12 +14,12 @@ import { useMessage } from &#39;/@/hooks/web/useMessage&#39;;
14 14 import { RequestEnum, ResultEnum, ContentTypeEnum } from '/@/enums/httpEnum';
15 15  
16 16 import { isString } from '/@/utils/is';
  17 +import { getToken } from '/@/utils/auth';
17 18 import { setObjToUrlParams, deepMerge } from '/@/utils';
18 19 import { errorStore } from '/@/store/modules/error';
19 20 import { errorResult } from './const';
20 21 import { useI18n } from '/@/hooks/web/useI18n';
21 22 import { createNow, formatRequestDate } from './helper';
22   -import { userStore } from '/@/store/modules/user';
23 23  
24 24 const globSetting = useGlobSetting();
25 25 const prefix = globSetting.urlPrefix;
... ... @@ -137,7 +137,7 @@ const transform: AxiosTransform = {
137 137 */
138 138 requestInterceptors: (config) => {
139 139 // 请求之前处理config
140   - const token = userStore.getTokenState;
  140 + const token = getToken();
141 141 if (token) {
142 142 // jwt token
143 143 config.headers.Authorization = token;
... ...
src/utils/http/axios/types.ts
1   -import type { AxiosRequestConfig } from 'axios';
2   -import type { AxiosTransform } from './axiosTransform';
3 1 export type ErrorMessageMode = 'none' | 'modal' | 'message' | undefined;
4 2  
5 3 export interface RequestOptions {
... ... @@ -20,12 +18,6 @@ export interface RequestOptions {
20 18 ignoreCancelToken?: boolean;
21 19 }
22 20  
23   -export interface CreateAxiosOptions extends AxiosRequestConfig {
24   - prefixUrl?: string;
25   - transform?: AxiosTransform;
26   - requestOptions?: RequestOptions;
27   -}
28   -
29 21 export interface Result<T = any> {
30 22 code: number;
31 23 type: 'success' | 'error' | 'warning';
... ...
src/views/demo/system/account/index.vue
... ... @@ -3,7 +3,7 @@
3 3 <DeptTree class="w-1/4 xl:w-1/5" @select="handleSelect" />
4 4 <BasicTable @register="registerTable" class="w-3/4 xl:w-4/5">
5 5 <template #toolbar>
6   - <a-button type="primary" @click="handleCreate"> 新增账号 </a-button>
  6 + <a-button type="primary" @click="handleCreate">新增账号</a-button>
7 7 </template>
8 8 <template #action="{ record }">
9 9 <TableAction
... ...
src/views/sys/login/RegisterForm.vue
... ... @@ -47,7 +47,7 @@
47 47 class="enter-x"
48 48 size="large"
49 49 block
50   - @click="handleReset"
  50 + @click="handleRegister"
51 51 :loading="loading"
52 52 >
53 53 {{ t('sys.login.registerButton') }}
... ... @@ -103,7 +103,7 @@
103 103  
104 104 const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER);
105 105  
106   - async function handleReset() {
  106 + async function handleRegister() {
107 107 const data = await validForm();
108 108 if (!data) return;
109 109 console.log(data);
... ... @@ -114,7 +114,7 @@
114 114 formRef,
115 115 formData,
116 116 getFormRules,
117   - handleReset,
  117 + handleRegister,
118 118 loading,
119 119 handleBackLogin,
120 120 getShow,
... ...
yarn.lock
... ... @@ -1117,10 +1117,10 @@
1117 1117 dependencies:
1118 1118 cross-fetch "^3.0.6"
1119 1119  
1120   -"@iconify/json@^1.1.312":
1121   - version "1.1.312"
1122   - resolved "https://registry.npmjs.org/@iconify/json/-/json-1.1.312.tgz#d8e92f31acfb326dcbfa4daea2d4ba885423c186"
1123   - integrity sha512-bYgaMaNB17MkLL1UgRRD6fv9Vp80kny7KA4SVMxonBEsVtZ+53dCK0R7RccrC45X1mspG8MejUaEw/AaEmWHZQ==
  1120 +"@iconify/json@^1.1.313":
  1121 + version "1.1.313"
  1122 + resolved "https://registry.npmjs.org/@iconify/json/-/json-1.1.313.tgz#c225be3c5ce3280a2c34e753a65dc257b85b6652"
  1123 + integrity sha512-gv00rSX4apKE0i/fUjXp5+sBb8LHzzdJqrXkBNVby7Nl7yzRqeQ/EyY+7ixtSpEu3f1P/co/vrgdbZN6wlw6DA==
1124 1124  
1125 1125 "@intlify/core-base@9.0.0":
1126 1126 version "9.0.0"
... ... @@ -1312,14 +1312,14 @@
1312 1312 resolved "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
1313 1313 integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==
1314 1314  
1315   -"@types/fs-extra@^9.0.8":
  1315 +"@types/fs-extra@^9.0.6", "@types/fs-extra@^9.0.8":
1316 1316 version "9.0.8"
1317 1317 resolved "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.8.tgz#32c3c07ddf8caa5020f84b5f65a48470519f78ba"
1318 1318 integrity sha512-bnlTVTwq03Na7DpWxFJ1dvnORob+Otb8xHyUqUWhqvz/Ksg8+JXPlR52oeMSZ37YEOa5PyccbgUNutiQdi13TA==
1319 1319 dependencies:
1320 1320 "@types/node" "*"
1321 1321  
1322   -"@types/glob@^7.1.1":
  1322 +"@types/glob@^7.1.1", "@types/glob@^7.1.3":
1323 1323 version "7.1.3"
1324 1324 resolved "https://registry.npmjs.org/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"
1325 1325 integrity sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==
... ... @@ -1515,6 +1515,13 @@
1515 1515 resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.0.tgz#dd3e6699ba3237f0348cd085e4698780204842f9"
1516 1516 integrity sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==
1517 1517  
  1518 +"@types/yargs@^15.0.12":
  1519 + version "15.0.13"
  1520 + resolved "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.13.tgz#34f7fec8b389d7f3c1fd08026a5763e072d3c6dc"
  1521 + integrity sha512-kQ5JNTrbDv3Rp5X2n/iUu37IJBDU2gsZ5R/g1/KHOOEc5IKfUFjXT6DENPGduh08I/pamwtEq4oul7gUqKTQDQ==
  1522 + dependencies:
  1523 + "@types/yargs-parser" "*"
  1524 +
1518 1525 "@types/yargs@^16.0.0":
1519 1526 version "16.0.0"
1520 1527 resolved "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.0.tgz#0e033b23452da5d61b6c44747612cb80ac528751"
... ... @@ -2219,6 +2226,15 @@ bl@^1.0.0:
2219 2226 readable-stream "^2.3.5"
2220 2227 safe-buffer "^5.1.1"
2221 2228  
  2229 +bl@^4.0.3:
  2230 + version "4.1.0"
  2231 + resolved "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a"
  2232 + integrity sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==
  2233 + dependencies:
  2234 + buffer "^5.5.0"
  2235 + inherits "^2.0.4"
  2236 + readable-stream "^3.4.0"
  2237 +
2222 2238 bluebird@^3.5.0, bluebird@^3.7.2:
2223 2239 version "3.7.2"
2224 2240 resolved "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
... ... @@ -2310,7 +2326,7 @@ buffer-from@^1.0.0, buffer-from@^1.1.1:
2310 2326 resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
2311 2327 integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
2312 2328  
2313   -buffer@^5.2.1, buffer@^5.4.3:
  2329 +buffer@^5.2.1, buffer@^5.4.3, buffer@^5.5.0:
2314 2330 version "5.7.1"
2315 2331 resolved "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
2316 2332 integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
... ... @@ -2582,6 +2598,11 @@ cli-cursor@^3.1.0:
2582 2598 dependencies:
2583 2599 restore-cursor "^3.1.0"
2584 2600  
  2601 +cli-spinners@^2.5.0:
  2602 + version "2.5.0"
  2603 + resolved "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.5.0.tgz#12763e47251bf951cb75c201dfa58ff1bcb2d047"
  2604 + integrity sha512-PC+AmIuK04E6aeSs/pUccSujsTzBhu4HzC2dL+CfJB/Jcc2qTRbEwZQDfIUpt2Xl8BodYBEq8w4fc0kU2I9DjQ==
  2605 +
2585 2606 cli-truncate@^2.1.0:
2586 2607 version "2.1.0"
2587 2608 resolved "https://registry.npmjs.org/cli-truncate/-/cli-truncate-2.1.0.tgz#c39e28bf05edcde5be3b98992a22deed5a2b93c7"
... ... @@ -2632,6 +2653,11 @@ clone-response@1.0.2:
2632 2653 dependencies:
2633 2654 mimic-response "^1.0.0"
2634 2655  
  2656 +clone@^1.0.2:
  2657 + version "1.0.4"
  2658 + resolved "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e"
  2659 + integrity sha1-2jCcwmPfFZlMaIypAheco8fNfH4=
  2660 +
2635 2661 clone@^2.1.1:
2636 2662 version "2.1.2"
2637 2663 resolved "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
... ... @@ -3342,6 +3368,13 @@ deepmerge@^4.2.2:
3342 3368 resolved "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
3343 3369 integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
3344 3370  
  3371 +defaults@^1.0.3:
  3372 + version "1.0.3"
  3373 + resolved "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
  3374 + integrity sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=
  3375 + dependencies:
  3376 + clone "^1.0.2"
  3377 +
3345 3378 define-properties@^1.1.3:
3346 3379 version "1.1.3"
3347 3380 resolved "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"
... ... @@ -3533,6 +3566,22 @@ download@^7.1.0:
3533 3566 p-event "^2.1.0"
3534 3567 pify "^3.0.0"
3535 3568  
  3569 +dpdm@^3.6.0:
  3570 + version "3.6.0"
  3571 + resolved "https://registry.npmjs.org/dpdm/-/dpdm-3.6.0.tgz#d8612e9899725287f8ad5b705cb081a5158d2f2f"
  3572 + integrity sha512-+DRT3o/5mIbjKENtKUEDX0qOk0xIBDllDITtvHRH+5Yppz2aJAHQkozj3oiIPLWWfup8CuuBl3xWvk5yD5oaOg==
  3573 + dependencies:
  3574 + "@types/fs-extra" "^9.0.6"
  3575 + "@types/glob" "^7.1.3"
  3576 + "@types/yargs" "^15.0.12"
  3577 + chalk "^4.1.0"
  3578 + fs-extra "^9.0.1"
  3579 + glob "^7.1.6"
  3580 + ora "^5.2.0"
  3581 + tslib "^2.1.0"
  3582 + typescript "^4.1.3"
  3583 + yargs "^16.2.0"
  3584 +
3536 3585 duplexer3@^0.1.4:
3537 3586 version "0.1.4"
3538 3587 resolved "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
... ... @@ -3704,10 +3753,10 @@ esbuild-register@^2.2.0:
3704 3753 dependencies:
3705 3754 jsonc-parser "^3.0.0"
3706 3755  
3707   -esbuild@0.8.56, esbuild@^0.8.52, esbuild@^0.8.54, esbuild@^0.8.56:
3708   - version "0.8.56"
3709   - resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.8.56.tgz#9c7c3d6e614db7367afa348adb0ab287c296735e"
3710   - integrity sha512-PTMdAWK3JI2MNW811znGssGP5GR44tQPr++VQ1rPP0n8Z1cTKbCPD3S/kXPLr3ZZDIwAaVm08fuFym6Rp8l/0A==
  3756 +esbuild@0.8.57, esbuild@^0.8.52, esbuild@^0.8.54, esbuild@^0.8.56:
  3757 + version "0.8.57"
  3758 + resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.8.57.tgz#a42d02bc2b57c70bcd0ef897fe244766bb6dd926"
  3759 + integrity sha512-j02SFrUwFTRUqiY0Kjplwjm1psuzO1d6AjaXKuOR9hrY0HuPsT6sV42B6myW34h1q4CRy+Y3g4RU/cGJeI/nNA==
3711 3760  
3712 3761 escalade@^3.1.1:
3713 3762 version "3.1.1"
... ... @@ -5045,7 +5094,7 @@ inflight@^1.0.4:
5045 5094 once "^1.3.0"
5046 5095 wrappy "1"
5047 5096  
5048   -inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.3:
  5097 +inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3:
5049 5098 version "2.0.4"
5050 5099 resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
5051 5100 integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
... ... @@ -5279,6 +5328,11 @@ is-hexadecimal@^1.0.0:
5279 5328 resolved "https://registry.npmjs.org/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7"
5280 5329 integrity sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==
5281 5330  
  5331 +is-interactive@^1.0.0:
  5332 + version "1.0.0"
  5333 + resolved "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz#cea6e6ae5c870a7b0a0004070b7b587e0252912e"
  5334 + integrity sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==
  5335 +
5282 5336 is-jpg@^2.0.0:
5283 5337 version "2.0.0"
5284 5338 resolved "https://registry.npmjs.org/is-jpg/-/is-jpg-2.0.0.tgz#2e1997fa6e9166eaac0242daae443403e4ef1d97"
... ... @@ -6596,6 +6650,20 @@ optipng-bin@^7.0.0:
6596 6650 bin-wrapper "^4.0.0"
6597 6651 logalot "^2.0.0"
6598 6652  
  6653 +ora@^5.2.0:
  6654 + version "5.3.0"
  6655 + resolved "https://registry.npmjs.org/ora/-/ora-5.3.0.tgz#fb832899d3a1372fe71c8b2c534bbfe74961bb6f"
  6656 + integrity sha512-zAKMgGXUim0Jyd6CXK9lraBnD3H5yPGBPPOkC23a2BG6hsm4Zu6OQSjQuEtV0BHDf4aKHcUFvJiGRrFuW3MG8g==
  6657 + dependencies:
  6658 + bl "^4.0.3"
  6659 + chalk "^4.1.0"
  6660 + cli-cursor "^3.1.0"
  6661 + cli-spinners "^2.5.0"
  6662 + is-interactive "^1.0.0"
  6663 + log-symbols "^4.0.0"
  6664 + strip-ansi "^6.0.0"
  6665 + wcwidth "^1.0.1"
  6666 +
6599 6667 os-filter-obj@^2.0.0:
6600 6668 version "2.0.0"
6601 6669 resolved "https://registry.npmjs.org/os-filter-obj/-/os-filter-obj-2.0.0.tgz#1c0b62d5f3a2442749a2d139e6dddee6e81d8d16"
... ... @@ -7370,7 +7438,7 @@ read-pkg@^5.2.0:
7370 7438 parse-json "^5.0.0"
7371 7439 type-fest "^0.6.0"
7372 7440  
7373   -readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.1.1:
  7441 +readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.1.1, readable-stream@^3.4.0:
7374 7442 version "3.6.0"
7375 7443 resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
7376 7444 integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
... ... @@ -8762,7 +8830,7 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0:
8762 8830 resolved "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
8763 8831 integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
8764 8832  
8765   -tslib@^2.0.3:
  8833 +tslib@^2.0.3, tslib@^2.1.0:
8766 8834 version "2.1.0"
8767 8835 resolved "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
8768 8836 integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
... ... @@ -8820,7 +8888,7 @@ typedarray-to-buffer@^3.1.5:
8820 8888 dependencies:
8821 8889 is-typedarray "^1.0.0"
8822 8890  
8823   -typescript@4.2.3:
  8891 +typescript@4.2.3, typescript@^4.1.3:
8824 8892 version "4.2.3"
8825 8893 resolved "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3"
8826 8894 integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==
... ... @@ -9282,6 +9350,13 @@ warning@^4.0.0:
9282 9350 dependencies:
9283 9351 loose-envify "^1.0.0"
9284 9352  
  9353 +wcwidth@^1.0.1:
  9354 + version "1.0.1"
  9355 + resolved "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"
  9356 + integrity sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=
  9357 + dependencies:
  9358 + defaults "^1.0.3"
  9359 +
9285 9360 webidl-conversions@^4.0.2:
9286 9361 version "4.0.2"
9287 9362 resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
... ...