From 2462f110efdab77679a74e1bf0140c4c7e98621d Mon Sep 17 00:00:00 2001 From: lyt-Top <1105290566@qq.com> Date: Sun, 20 Jun 2021 11:46:51 +0800 Subject: [PATCH] =?UTF-8?q?'admin-21.06.19:=E4=BF=AE=E5=A4=8D=E8=AF=B8?= =?UTF-8?q?=E5=A4=9A=E9=97=AE=E9=A2=98=EF=BC=8C=E5=85=B7=E4=BD=93=E6=9F=A5?= =?UTF-8?q?=E7=9C=8BCHANGELOG.md=E6=96=87=E4=BB=B61.04=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=A5=E5=BF=97'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + package.json | 2 +- src/App.vue | 6 +++--- src/store/index.ts | 41 +++++++++++++++-------------------------- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0c42ae..f0d2212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - 🌟 更新 依赖更新最新版本("vite": "^2.3.7")热更新无问题 - 🎉 新增 深克隆工具,方便开发,感谢@kangert(#6) +- 🎯 优化 vuex 模块自动导入。感谢@kangert(#4),感谢群友@web 小学生-第五君 - 🎯 优化 类型定义提高编码体验,修复不能将类型“string | undefined”分配给类型“string”的问题。感谢@kangert(#5) - 🎯 优化 `layout` 文件夹移动到与 `views` 文件夹同级(改动较大,`/@/views/layout` 变成 `/@/layout`) - 🎯 优化 页面有 `console.log` 时 `eslint` 不生效问题 diff --git a/package.json b/package.json index a96ad91..ccd2cb1 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "sass": "^1.35.1", "sass-loader": "^12.1.0", "typescript": "^4.3.4", - "vite": "^2.3.7", + "vite": "^2.3.8", "vue-eslint-parser": "^7.6.0" }, "browserslist": [ diff --git a/src/App.vue b/src/App.vue index 731a9d3..4d8822d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -60,9 +60,9 @@ export default defineComponent({ () => route.path, () => { nextTick(() => { - // let webTitle = ''; - // route.path === '/login' ? (webTitle = route.meta.title) : (webTitle = t(route.meta.title)); - // document.title = `${webTitle} - ${getThemeConfig.value.globalTitle}` || getThemeConfig.value.globalTitle; + let webTitle = ''; + route.path === '/login' ? (webTitle = route.meta.title) : (webTitle = t(route.meta.title)); + document.title = `${webTitle} - ${getThemeConfig.value.globalTitle}` || getThemeConfig.value.globalTitle; }); } ); diff --git a/src/store/index.ts b/src/store/index.ts index 179d883..bb1d741 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,37 +1,26 @@ import { InjectionKey } from 'vue'; import { createStore, useStore as baseUseStore, Store } from 'vuex'; import { RootStateTypes } from '/@/store/interface/index'; -import themeConfig from '/@/store/modules/themeConfig.ts'; -import routesList from '/@/store/modules/routesList.ts'; -import keepAliveNames from '/@/store/modules/keepAliveNames.ts'; -import tagsViewRoutes from '/@/store/modules/tagsViewRoutes.ts'; -import userInfos from '/@/store/modules/userInfos.ts'; -import requestOldRoutes from '/@/store/modules/requestOldRoutes.ts'; -// const modulesFiles: Record = import.meta.glob('./modules/*.ts'); +// Vite supports importing multiple modules from the file system using the special import.meta.glob function +// see https://cn.vitejs.dev/guide/features.html#glob-import +const modulesFiles = import.meta.globEager('./modules/*.ts'); +const pathList: string[] = []; -// npm run build -// https://github.com/vitejs/vite/issues/3035 -// Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1") -// let modules: ModuleTree = {}; -// for (const path in modulesFiles) { -// const moduleName: string = path.replace(/(.*\/)*([^.]+).*/gi, '$2'); -// let module: ModuleTree = await modulesFiles[path](); -// modules = { ...modules, [moduleName]: module.default }; -// } +for (const path in modulesFiles) { + pathList.push(path); +} + +const modules = pathList.reduce((modules: { [x: string]: any }, modulePath: string) => { + const moduleName = modulePath.replace(/^\.\/modules\/(.*)\.\w+$/, '$1'); + const value = modulesFiles[modulePath]; + modules[moduleName] = value.default; + return modules; +}, {}); export const key: InjectionKey> = Symbol(); -export const store = createStore({ - modules: { - themeConfig, - routesList, - keepAliveNames, - tagsViewRoutes, - userInfos, - requestOldRoutes, - }, -}); +export const store = createStore({ modules }); export function useStore() { return baseUseStore(key);