From f7aa93f5b0e40394ba813675f97f730c99999e32 Mon Sep 17 00:00:00 2001 From: vben Date: Sat, 21 Nov 2020 22:47:10 +0800 Subject: [PATCH] chore: miscellaneous modifications --- package.json | 2 +- src/hooks/core/useSetting.ts | 4 +++- src/router/index.ts | 6 +----- src/router/types.d.ts | 1 + src/store/modules/app.ts | 9 ++++----- src/store/modules/error.ts | 1 - src/store/modules/menu.ts | 1 - src/store/modules/permission.ts | 1 - src/store/modules/tab.ts | 3 ++- src/store/modules/user.ts | 1 - src/types/config.d.ts | 2 ++ src/types/global.d.ts | 6 ++++++ src/types/shim-tsx.d.ts | 10 +--------- src/utils/file/{stream.ts => base64.ts} | 0 src/utils/file/download.ts | 2 +- src/utils/helper/persistent.ts | 12 ++++++------ src/utils/helper/treeHelper.ts | 1 + yarn.lock | 8 ++++---- 18 files changed, 33 insertions(+), 37 deletions(-) rename src/utils/file/{stream.ts => base64.ts} (100%) diff --git a/package.json b/package.json index 2063cf1a..0ed980cc 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "lint-staged": "^10.5.1", "portfinder": "^1.0.28", "postcss-import": "^12.0.1", - "prettier": "^2.1.2", + "prettier": "^2.2.0", "rimraf": "^3.0.2", "rollup-plugin-visualizer": "^4.1.2", "stylelint": "^13.8.0", diff --git a/src/hooks/core/useSetting.ts b/src/hooks/core/useSetting.ts index 741f19a1..3020ac6e 100644 --- a/src/hooks/core/useSetting.ts +++ b/src/hooks/core/useSetting.ts @@ -20,7 +20,9 @@ const { } = ENV; if (!reg.test(VITE_GLOB_APP_SHORT_NAME)) { - warn(`VITE_GLOB_APP_SHORT_NAME 变量只能是字符/下划线,请在环境变量中修改并重新运行。`); + warn( + `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.` + ); } export const useSetting = (): SettingWrap => { diff --git a/src/router/index.ts b/src/router/index.ts index 851f398a..2e9d90b8 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -18,11 +18,7 @@ const router = createRouter({ // reset router export function resetRouter() { - const resetWhiteNameList = [ - 'Login', - 'Root', - // 'FullErrorPage' - ]; + const resetWhiteNameList = ['Login', 'Root']; router.getRoutes().forEach((route) => { const { name } = route; if (name && !resetWhiteNameList.includes(name as string)) { diff --git a/src/router/types.d.ts b/src/router/types.d.ts index 3c7025a4..cea77722 100644 --- a/src/router/types.d.ts +++ b/src/router/types.d.ts @@ -69,6 +69,7 @@ export interface Menu { tag?: MenuTag; } + export interface MenuModule { orderNo?: number; menu: Menu; diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index f4c50a85..7d840616 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -81,7 +81,7 @@ class App extends VuexModule { public async setPageLoadingAction(loading: boolean): Promise { if (loading) { clearTimeout(timeId); - // 防止闪动 + // Prevent flicker timeId = setTimeout(() => { this.commitPageLoadingState(loading); }, 100); @@ -91,9 +91,9 @@ class App extends VuexModule { } } - // /** - // * @description: unlock page - // */ + /** + * @description: unlock page + */ @Action public async unLockAction({ password, valid = true }: { password: string; valid?: boolean }) { if (!valid) { @@ -125,5 +125,4 @@ class App extends VuexModule { return res; } } -export { App }; export const appStore = getModule(App); diff --git a/src/store/modules/error.ts b/src/store/modules/error.ts index ffc3149b..ad00185a 100644 --- a/src/store/modules/error.ts +++ b/src/store/modules/error.ts @@ -78,5 +78,4 @@ class Error extends VuexModule implements ErrorState { this.commitErrorInfoState(errInfo as ErrorInfo); } } -export { Error }; export const errorStore = getModule(Error); diff --git a/src/store/modules/menu.ts b/src/store/modules/menu.ts index 4586f73d..5d3f01bd 100644 --- a/src/store/modules/menu.ts +++ b/src/store/modules/menu.ts @@ -64,5 +64,4 @@ class Menu extends VuexModule { } } -export { Menu }; export const menuStore = getModule(Menu); diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index 544b3fb9..03d4cc10 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -128,5 +128,4 @@ class Permission extends VuexModule { return routes; } } -export { Permission }; export const permissionStore = getModule(Permission); diff --git a/src/store/modules/tab.ts b/src/store/modules/tab.ts index ad2e1ad8..3f28403d 100644 --- a/src/store/modules/tab.ts +++ b/src/store/modules/tab.ts @@ -15,6 +15,7 @@ import { PAGE_NOT_FOUND_ROUTE, REDIRECT_ROUTE } from '/@/router/constant'; import { getCurrentTo } from '/@/utils/helper/routeHelper'; type CacheName = string | symbol | null | undefined; + /** * @description: vuex Tab模块 */ @@ -29,6 +30,7 @@ export interface TabItem { } const NAME = 'tab'; + hotModuleUnregisterModule(NAME); const getOpenKeepAliveRef = computed(() => appStore.getProjectConfig.openKeepAlive); @@ -252,5 +254,4 @@ class Tab extends VuexModule { this.closeMultipleTab({ pathList, nameList }); } } -export { Tab }; export const tabStore = getModule(Tab); diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 4f7e7f7a..94d5a5cc 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -154,5 +154,4 @@ class User extends VuexModule { }); } } -export { User }; export const userStore = getModule(User); diff --git a/src/types/config.d.ts b/src/types/config.d.ts index e1339a91..24f060f7 100644 --- a/src/types/config.d.ts +++ b/src/types/config.d.ts @@ -138,9 +138,11 @@ export type SetProjectSettingFn = ( key: T, value: ProjectConfig[T] ) => void; + interface GlobWrap { globSetting: Readonly; } + interface ProjectSettingWrap { projectSetting: Readonly; } diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 4d45ac2f..60440076 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -37,6 +37,12 @@ declare type DeepPartial = { [P in keyof T]?: DeepPartial; }; +// type DeepPartial = T extends Function +// ? T +// : T extends object +// ? { [K in keyof T]?: DeepPartial } +// : T; + declare type LabelValueOptions = { label: string; value: any; diff --git a/src/types/shim-tsx.d.ts b/src/types/shim-tsx.d.ts index d9f0595c..188f5886 100644 --- a/src/types/shim-tsx.d.ts +++ b/src/types/shim-tsx.d.ts @@ -13,21 +13,13 @@ declare global { // tslint:disable no-empty-interface type ElementClass = ComponentRenderProxy; interface ElementAttributesProperty { - $props: any; // 定义要使用的属性名称 + $props: any; } interface IntrinsicElements { [elem: string]: any; } interface IntrinsicAttributes { - // ['v-if']?: unknown; - // ['v-else-if']?: unknown; - // ['v-else']?: unknown; - // need - // ['v-show']?: unknown; [elem: string]: any; - // ['v-html']?: unknown; - // ['v-text']?: unknown; - // ['v-model']?: unknown; } } } diff --git a/src/utils/file/stream.ts b/src/utils/file/base64.ts similarity index 100% rename from src/utils/file/stream.ts rename to src/utils/file/base64.ts diff --git a/src/utils/file/download.ts b/src/utils/file/download.ts index fded7167..87c870c8 100644 --- a/src/utils/file/download.ts +++ b/src/utils/file/download.ts @@ -1,4 +1,4 @@ -import { dataURLtoBlob, urlToBase64 } from './stream'; +import { dataURLtoBlob, urlToBase64 } from './base64'; /** * Download online pictures diff --git a/src/utils/helper/persistent.ts b/src/utils/helper/persistent.ts index f9399401..79ccbcef 100644 --- a/src/utils/helper/persistent.ts +++ b/src/utils/helper/persistent.ts @@ -7,8 +7,8 @@ const ls = createStorage(localStorage); const ss = createStorage(); interface CacheStore { - local?: any; - session?: any; + local: Record; + session: Record; } /** @@ -25,14 +25,14 @@ function initCache() { cacheStore.local = ls.get(BASE_LOCAL_CACHE_KEY) || {}; cacheStore.session = ss.get(BASE_SESSION_CACHE_KEY) || {}; } + initCache(); export function setLocal(key: string, value: any, immediate = false) { cacheStore.local[BASE_LOCAL_CACHE_KEY] = cacheStore.local[BASE_LOCAL_CACHE_KEY] || {}; cacheStore.local[BASE_LOCAL_CACHE_KEY][key] = value; if (immediate) { - const localCache = cacheStore.local; - ls.set(BASE_LOCAL_CACHE_KEY, localCache); + ls.set(BASE_LOCAL_CACHE_KEY, cacheStore.local); } } @@ -43,6 +43,7 @@ export function getLocal(key: string): T | null { return null; } } + export function removeLocal(key: string) { if (cacheStore.local[BASE_LOCAL_CACHE_KEY]) { Reflect.deleteProperty(cacheStore.local[BASE_LOCAL_CACHE_KEY], key); @@ -91,8 +92,6 @@ export function clearAll() { const localCache = cacheStore.local; const sessionCache = cacheStore.session; - // const ss = createStorage(); - ls.set(BASE_LOCAL_CACHE_KEY, localCache); ss.set(BASE_SESSION_CACHE_KEY, sessionCache); }); @@ -114,6 +113,7 @@ export function clearAll() { } } } + if (isIeFn() && (document as any).attachEvent) { (document as any).attachEvent('onstorage', storageChange); } else { diff --git a/src/utils/helper/treeHelper.ts b/src/utils/helper/treeHelper.ts index a1f96b9e..15b2c099 100644 --- a/src/utils/helper/treeHelper.ts +++ b/src/utils/helper/treeHelper.ts @@ -158,6 +158,7 @@ export function forEach( export function treeMap(treeData: any[], opt: { children?: string; conversion: Fn }) { return treeData.map((item) => treeMapEach(item, opt)); } + /** * @description: 提取tree指定结构 */ diff --git a/yarn.lock b/yarn.lock index 8b29ccb5..bf78c8f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6343,10 +6343,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@^2.1.2: - version "2.1.2" - resolved "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5" - integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg== +prettier@^2.2.0: + version "2.2.0" + resolved "https://registry.npmjs.org/prettier/-/prettier-2.2.0.tgz#8a03c7777883b29b37fb2c4348c66a78e980418b" + integrity sha512-yYerpkvseM4iKD/BXLYUkQV5aKt4tQPqaGW6EsZjzyu0r7sVZZNPJW4Y8MyKmicp6t42XUPcBVA+H6sB3gqndw== pretty-bytes@^5.3.0: version "5.4.1" -- GitLab