From c14ebc2343a978a8f31499982c71d4260ecabf98 Mon Sep 17 00:00:00 2001 From: chenxin Date: Thu, 5 Sep 2024 16:02:24 +0800 Subject: [PATCH] refactor: organize file dir --- .env | 6 +-- locales/en_US.json | 10 ++--- locales/zh_CN.json | 10 ++--- package.json | 36 +++++++-------- src/components/common/IconSelect.vue | 24 +++++----- src/router/routes.static.ts | 44 +++++++++---------- src/store/router/helper.ts | 6 +-- src/utils/storage.ts | 9 ++-- src/views/{ => demo}/about/index.vue | 0 src/views/{ => demo}/documents/vite/index.vue | 0 src/views/{ => demo}/documents/vue/index.vue | 0 src/views/{ => demo}/list/cardList/index.vue | 0 .../list/commonList/components/TableModal.vue | 0 .../{ => demo}/list/commonList/index.vue | 0 .../multi/multi2}/detail/index.vue | 0 .../test2 => demo/multi/multi2}/index.vue | 2 +- .../multi/multi3/multi4}/index.vue | 0 .../{ => demo}/permission/justSuper/index.vue | 0 .../permission/permission/index.vue | 0 src/views/{ => demo}/userCenter/index.vue | 0 .../setting/account/components/TableModal.vue | 2 +- .../setting/menu/components/TableModal.vue | 2 +- 22 files changed, 74 insertions(+), 77 deletions(-) rename src/views/{ => demo}/about/index.vue (100%) rename src/views/{ => demo}/documents/vite/index.vue (100%) rename src/views/{ => demo}/documents/vue/index.vue (100%) rename src/views/{ => demo}/list/cardList/index.vue (100%) rename src/views/{ => demo}/list/commonList/components/TableModal.vue (100%) rename src/views/{ => demo}/list/commonList/index.vue (100%) rename src/views/{test/test2 => demo/multi/multi2}/detail/index.vue (100%) rename src/views/{test/test2 => demo/multi/multi2}/index.vue (80%) rename src/views/{test/test3/test4 => demo/multi/multi3/multi4}/index.vue (100%) rename src/views/{ => demo}/permission/justSuper/index.vue (100%) rename src/views/{ => demo}/permission/permission/index.vue (100%) rename src/views/{ => demo}/userCenter/index.vue (100%) diff --git a/.env b/.env index b6e81eb..a185209 100644 --- a/.env +++ b/.env @@ -8,13 +8,13 @@ VITE_APP_NAME = Nova - Admin VITE_ROUTE_MODE = web # 路由加载模式 static | dynamic -VITE_ROUTE_LOAD_MODE = dynamic +VITE_ROUTE_LOAD_MODE = static # 设置登陆后跳转地址 VITE_HOME_PATH = /dashboard/workbench # 本地存储前缀 -VITE_STORAGE_PREFIX= +VITE_STORAGE_PREFIX = # 版权信息 VITE_COPYRIGHT_INFO = Copyright © 2024 chansee97 @@ -22,5 +22,5 @@ VITE_COPYRIGHT_INFO = Copyright © 2024 chansee97 # 自动刷新token VITE_AUTO_REFRESH_TOKEN = Y -# 默认多语言 +# 默认多语言 enUS | zhCN VITE_DEFAULT_LANG = enUS diff --git a/locales/en_US.json b/locales/en_US.json index a747ad5..ccd0df8 100644 --- a/locales/en_US.json +++ b/locales/en_US.json @@ -95,11 +95,11 @@ "fetch": "Request example", "list": "List", "monitor": "Monitoring", - "test": "Multi-level menu", - "test2": "Multi-level menu subpage", - "test2Detail": "Details page of multi-level menu", - "test3": "multi-level menu", - "test4": "Multi-level menu 3-1", + "multi": "Multi-level menu", + "multi2": "Multi-level menu subpage", + "multi2Detail": "Details page of multi-level menu", + "multi3": "multi-level menu", + "multi4": "Multi-level menu 3-1", "workbench": "Workbench", "QRCode": "QR code", "about": "About", diff --git a/locales/zh_CN.json b/locales/zh_CN.json index 1da4bd3..b693bd6 100644 --- a/locales/zh_CN.json +++ b/locales/zh_CN.json @@ -118,11 +118,11 @@ "dashboard": "仪表盘", "workbench": "工作台", "monitor": "监控页", - "test": "多级菜单演示", - "test2": "多级菜单子页", - "test2Detail": "多级菜单的详情页", - "test3": "多级菜单", - "test4": "多级菜单3-1", + "multi": "多级菜单演示", + "multi2": "多级菜单子页", + "multi2Detail": "多级菜单的详情页", + "multi3": "多级菜单", + "multi4": "多级菜单3-1", "list": "列表页", "commonList": "常用列表", "cardList": "卡片列表", diff --git a/package.json b/package.json index 6a4ed2e..2433fa2 100644 --- a/package.json +++ b/package.json @@ -50,41 +50,41 @@ "sizecheck": "npx vite-bundle-visualizer" }, "dependencies": { - "@vueuse/core": "^10.11.1", - "alova": "^3.0.8", + "@vueuse/core": "^11.0.3", + "alova": "^3.0.16", "colord": "^2.9.3", "echarts": "^5.5.1", "md-editor-v3": "^4.15.2", - "pinia": "^2.2.1", - "pinia-plugin-persistedstate": "^3.2.1", + "pinia": "^2.2.2", + "pinia-plugin-persistedstate": "^4.0.0", "quill": "^2.0.2", "radash": "^12.1.0", - "vue": "^3.4.37", - "vue-i18n": "^9.13.1", + "vue": "^3.5.1", + "vue-i18n": "^9.14.0", "vue-router": "^4.4.3" }, "devDependencies": { - "@antfu/eslint-config": "^2.25.1", - "@iconify-json/icon-park-outline": "^1.1.16", + "@antfu/eslint-config": "^3.2.0", + "@iconify-json/icon-park-outline": "^1.2.0", "@iconify/vue": "^4.1.2", - "@types/node": "^22.3.0", - "@vitejs/plugin-vue": "^5.1.2", - "@vitejs/plugin-vue-jsx": "^4.0.0", - "eslint": "^9.9.0", + "@types/node": "^22.5.4", + "@vitejs/plugin-vue": "^5.1.3", + "@vitejs/plugin-vue-jsx": "^4.0.1", + "eslint": "^9.9.1", "lint-staged": "^15.2.9", "naive-ui": "^2.39.0", - "sass": "^1.77.8", + "sass": "^1.78.0", "simple-git-hooks": "^2.11.1", "typescript": "^5.5.4", - "unocss": "^0.62.1", + "unocss": "^0.62.3", "unplugin-auto-import": "^0.18.2", - "unplugin-icons": "^0.19.2", + "unplugin-icons": "^0.19.3", "unplugin-vue-components": "^0.27.4", - "vite": "^5.4.0", + "vite": "^5.4.3", "vite-bundle-visualizer": "^1.2.1", "vite-plugin-compression": "^0.5.1", - "vite-plugin-vue-devtools": "7.3.8", - "vue-tsc": "^2.0.29" + "vite-plugin-vue-devtools": "7.3.9", + "vue-tsc": "^2.1.6" }, "simple-git-hooks": { "pre-commit": "pnpm lint-staged" diff --git a/src/components/common/IconSelect.vue b/src/components/common/IconSelect.vue index a98a07d..543e972 100644 --- a/src/components/common/IconSelect.vue +++ b/src/components/common/IconSelect.vue @@ -39,6 +39,16 @@ async function fetchIconAllList(nameList: string[]) { return i }) } +// 获取svg文件名 +function getSvgName(path: string) { + const regex = /\/([^/]+)\.svg$/ + const match = path.match(regex) + if (match) { + const fileName = match[1] + return fileName + } + return path +} // 获取所有本地图标 function generateLocalIconList() { @@ -48,15 +58,6 @@ function generateLocalIconList() { eager: true, }) - function getSvgName(path: string) { - const regex = /\/([^/]+)\.svg$/ - const match = path.match(regex) - if (match) { - const fileName = match[1] - return fileName - } - return path - } return mapEntries(localSvgList, (key, value) => { return [getSvgName(key), value] }) @@ -103,9 +104,8 @@ const icons = computed(() => { // 符合搜索条件的图标列表 const visibleIcons = computed(() => { - return icons.value - ?.filter(i => i.includes(searchValue.value)) - ?.slice((currentPage.value - 1) * 200, (currentPage.value) * 200) + return icons.value?.filter(i => i + .includes(searchValue.value))?.slice((currentPage.value - 1) * 200, (currentPage.value) * 200) }) const showModal = ref(false) diff --git a/src/router/routes.static.ts b/src/router/routes.static.ts index 8c8c17a..73a382c 100644 --- a/src/router/routes.static.ts +++ b/src/router/routes.static.ts @@ -34,8 +34,8 @@ export const staticRoutes: AppRoute.RowRoute[] = [ pid: 1, }, { - name: 'test', - path: '/test', + name: 'multi', + path: '/multi', title: '多级菜单演示', requiresAuth: true, icon: 'icon-park-outline:list', @@ -45,32 +45,32 @@ export const staticRoutes: AppRoute.RowRoute[] = [ pid: null, }, { - name: 'test2', - path: '/test/test2', + name: 'multi2', + path: '/multi/multi2', title: '多级菜单子页', requiresAuth: true, icon: 'icon-park-outline:list', menuType: 'page', - componentPath: '/test/test2/index.vue', + componentPath: '/demo/multi/multi2/index.vue', id: 6, pid: 4, }, { - name: 'test2Detail', - path: '/test/test2/detail', + name: 'multi2Detail', + path: '/multi/multi2/detail', title: '多级菜单的详情页', requiresAuth: true, icon: 'icon-park-outline:list', hide: true, - activeMenu: '/test/test2', + activeMenu: '/multi/multi2', menuType: 'page', - componentPath: '/test/test2/detail/index.vue', + componentPath: '/demo/multi/multi2/detail/index.vue', id: 7, pid: 4, }, { - name: 'test3', - path: '/test/test3', + name: 'multi3', + path: '/multi/multi3', title: '多级菜单', requiresAuth: true, icon: 'icon-park-outline:list', @@ -80,12 +80,12 @@ export const staticRoutes: AppRoute.RowRoute[] = [ pid: 4, }, { - name: 'test4', - path: '/test/test3/test4', + name: 'multi4', + path: '/multi/multi3/multi4', title: '多级菜单3-1', requiresAuth: true, icon: 'icon-park-outline:list', - componentPath: '/test/test3/test4/index.vue', + componentPath: '/demo/multi/multi3/multi4/index.vue', id: 9, pid: 8, }, @@ -106,7 +106,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [ title: '常用列表', requiresAuth: true, icon: 'icon-park-outline:list-view', - componentPath: '/list/commonList/index.vue', + componentPath: '/demo/list/commonList/index.vue', id: 11, pid: 10, }, @@ -116,7 +116,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [ title: '卡片列表', requiresAuth: true, icon: 'icon-park-outline:view-grid-list', - componentPath: '/list/cardList/index.vue', + componentPath: '/demo/list/cardList/index.vue', id: 12, pid: 10, }, @@ -240,7 +240,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [ title: 'Vue', requiresAuth: true, icon: 'logos:vue', - componentPath: '/documents/vue/index.vue', + componentPath: '/demo/documents/vue/index.vue', id: 25, pid: 24, }, @@ -250,7 +250,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [ title: 'Vite', requiresAuth: true, icon: 'logos:vitejs', - componentPath: '/documents/vite/index.vue', + componentPath: '/demo/documents/vite/index.vue', id: 26, pid: 24, }, @@ -282,7 +282,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [ title: '权限示例', requiresAuth: true, icon: 'icon-park-outline:right-user', - componentPath: '/permission/permission/index.vue', + componentPath: '/demo/permission/permission/index.vue', id: 29, pid: 28, }, @@ -295,7 +295,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [ 'super', ], icon: 'icon-park-outline:wrong-user', - componentPath: '/permission/justSuper/index.vue', + componentPath: '/demo/permission/justSuper/index.vue', id: 30, pid: 28, }, @@ -390,7 +390,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [ title: '个人中心', requiresAuth: true, icon: 'carbon:user-avatar-filled-alt', - componentPath: '/userCenter/index.vue', + componentPath: '/demo/userCenter/index.vue', id: 39, pid: null, }, @@ -400,7 +400,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [ title: '关于', requiresAuth: true, icon: 'icon-park-outline:info', - componentPath: '/about/index.vue', + componentPath: '/demo/about/index.vue', id: 40, pid: null, }, diff --git a/src/store/router/helper.ts b/src/store/router/helper.ts index e76d3ea..4179e1a 100644 --- a/src/store/router/helper.ts +++ b/src/store/router/helper.ts @@ -104,8 +104,9 @@ export function createMenus(userRoutes: AppRoute.RowRoute[]) { // render the returned routing table as a sidebar function transformAuthRoutesToMenus(userRoutes: AppRoute.Route[]) { const { hasPermission } = usePermission() - // Filter out side menus without permission - return userRoutes.filter(i => hasPermission(i.meta.roles)) + return userRoutes + // Filter out side menus without permission + .filter(i => hasPermission(i.meta.roles)) // Sort the menu according to the order size .sort((a, b) => { if (a.meta && a.meta.order && b.meta && b.meta.order) @@ -116,7 +117,6 @@ function transformAuthRoutesToMenus(userRoutes: AppRoute.Route[]) { return 1 else return 0 }) - // Convert to side menu data structure .map((item) => { const target: MenuOption = { diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 281fb51..4c79ff5 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -39,9 +39,8 @@ function createLocalStorage() { window.localStorage.removeItem(`${STORAGE_PREFIX}${String(key)}`) } - function clear() { - window.localStorage.clear() - } + const clear = window.localStorage.clear + return { set, get, @@ -73,9 +72,7 @@ function createSessionStorage() { function remove(key: keyof T) { window.sessionStorage.removeItem(`${STORAGE_PREFIX}${String(key)}`) } - function clear() { - window.sessionStorage.clear() - } + const clear = window.sessionStorage.clear return { set, diff --git a/src/views/about/index.vue b/src/views/demo/about/index.vue similarity index 100% rename from src/views/about/index.vue rename to src/views/demo/about/index.vue diff --git a/src/views/documents/vite/index.vue b/src/views/demo/documents/vite/index.vue similarity index 100% rename from src/views/documents/vite/index.vue rename to src/views/demo/documents/vite/index.vue diff --git a/src/views/documents/vue/index.vue b/src/views/demo/documents/vue/index.vue similarity index 100% rename from src/views/documents/vue/index.vue rename to src/views/demo/documents/vue/index.vue diff --git a/src/views/list/cardList/index.vue b/src/views/demo/list/cardList/index.vue similarity index 100% rename from src/views/list/cardList/index.vue rename to src/views/demo/list/cardList/index.vue diff --git a/src/views/list/commonList/components/TableModal.vue b/src/views/demo/list/commonList/components/TableModal.vue similarity index 100% rename from src/views/list/commonList/components/TableModal.vue rename to src/views/demo/list/commonList/components/TableModal.vue diff --git a/src/views/list/commonList/index.vue b/src/views/demo/list/commonList/index.vue similarity index 100% rename from src/views/list/commonList/index.vue rename to src/views/demo/list/commonList/index.vue diff --git a/src/views/test/test2/detail/index.vue b/src/views/demo/multi/multi2/detail/index.vue similarity index 100% rename from src/views/test/test2/detail/index.vue rename to src/views/demo/multi/multi2/detail/index.vue diff --git a/src/views/test/test2/index.vue b/src/views/demo/multi/multi2/index.vue similarity index 80% rename from src/views/test/test2/index.vue rename to src/views/demo/multi/multi2/index.vue index 19d575a..cef8316 100644 --- a/src/views/test/test2/index.vue +++ b/src/views/demo/multi/multi2/index.vue @@ -5,7 +5,7 @@ const router = useRouter()