From ad054f6699a978757a8b0b74dac2c9051e0c8c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Tue, 23 May 2023 11:44:38 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=201=E3=80=81=E5=B8=83=E5=B1=80=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E5=AD=98=E5=82=A8=E6=94=B9=E4=B8=BA=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=AD=98=E5=82=A82=E3=80=81=E5=A4=9A=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E8=AF=AD=E8=A8=80=E6=94=B9=E4=B8=BA=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 64 +++++++++++++++++++++------------------- src/settings.js | 6 +++- src/store/modules/app.js | 9 +++--- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 7858671..5e6f01c 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -28,10 +28,11 @@ export const constantRoutes = [ component: Layout, hidden: true, children: [ - { - path: '/redirect/:path(.*)', - component: () => import('@/views/redirect/index.vue') - }] + { + path: '/redirect/:path(.*)', + component: () => import('@/views/redirect/index.vue') + } + ] }, { path: '/login', @@ -49,7 +50,7 @@ export const constantRoutes = [ hidden: true }, { - path: "/:pathMatch(.*)*", + path: '/:pathMatch(.*)*', component: () => import('@/views/error/404'), hidden: true }, @@ -63,12 +64,13 @@ export const constantRoutes = [ component: Layout, redirect: '/index', children: [ - { - path: '/index', - component: () => import('@/views/index'), - name: 'Index', - meta: { title: '首页', icon: 'dashboard', affix: true, titleKey: 'menu.home' } - }] + { + path: '/index', + component: () => import('@/views/index'), + name: 'Index', + meta: { title: '首页', icon: 'dashboard', affix: true, titleKey: 'menu.home' } + } + ] }, { path: '/user', @@ -76,12 +78,13 @@ export const constantRoutes = [ hidden: true, redirect: 'noredirect', children: [ - { - path: 'profile', - component: () => import('@/views/system/user/profile/index'), - name: 'Profile', - meta: { title: '个人中心', icon: 'user', titleKey: 'menu.personalCenter' } - }] + { + path: 'profile', + component: () => import('@/views/system/user/profile/index'), + name: 'Profile', + meta: { title: '个人中心', icon: 'user', titleKey: 'menu.personalCenter' } + } + ] }, // 不用可删掉 { @@ -90,18 +93,19 @@ export const constantRoutes = [ hidden: false, meta: { title: '组件示例', icon: 'icon', noCache: 'fasle' }, children: [ - { - path: 'icon', - component: () => import('@/views/components/icons/index'), - name: 'icon', - meta: { title: '图标icon', icon: 'icon1', noCache: 'fasle', titleKey: 'menu.icon' } - }] - }, -]; + { + path: 'icon', + // component: () => import('@/views/components/icons/index'), + component: () => import('@/views/business/GenDemo'), + name: 'icon', + meta: { title: '图标icon', icon: 'icon1', noCache: 'fasle', titleKey: 'menu.icon' } + } + ] + } +] const router = createRouter({ - history: createWebHistory( - import.meta.env.VITE_APP_ROUTER_PREFIX), + history: createWebHistory(import.meta.env.VITE_APP_ROUTER_PREFIX), routes: constantRoutes, scrollBehavior(to, from, savedPosition) { if (savedPosition) { @@ -109,7 +113,7 @@ const router = createRouter({ } else { return { top: 0 } } - }, -}); + } +}) -export default router; \ No newline at end of file +export default router diff --git a/src/settings.js b/src/settings.js index 913b2ad..c3b9050 100644 --- a/src/settings.js +++ b/src/settings.js @@ -75,5 +75,9 @@ export default { /** * 默认大小 */ - defaultSize: 'default' + defaultSize: 'default', + /** + * 默认语言 + */ + defaultLang: 'zh-cn' } diff --git a/src/store/modules/app.js b/src/store/modules/app.js index 84d2ae4..48b2456 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -1,4 +1,5 @@ import Cookies from 'js-cookie' +import cache from '@/plugins/cache' import defaultSettings from '@/settings' const useAppStore = defineStore('app', { state: () => ({ @@ -8,8 +9,8 @@ const useAppStore = defineStore('app', { hide: false }, device: 'desktop', - size: Cookies.get('size') || defaultSettings.defaultSize, - lang: Cookies.get('lang') || 'zh-cn' + size: cache.local.get('size') || defaultSettings.defaultSize, + lang: cache.cookie.get('lang') || defaultSettings.defaultLang }), actions: { toggleSideBar() { @@ -32,14 +33,14 @@ const useAppStore = defineStore('app', { }, setSize(size) { this.size = size - Cookies.set('size', size) + cache.local.set('size', size) }, toggleSideBarHide(status) { this.sidebar.hide = status }, setLang(lang) { this.lang = lang - Cookies.set('lang', lang) + cache.cookie.set('lang', lang) } } })