1、布局大小存储改为本地存储2、多语言默认语言改为配置文件

This commit is contained in:
不做码农 2023-05-23 11:44:38 +08:00
parent 1de85b2521
commit ad054f6699
3 changed files with 44 additions and 35 deletions

View File

@ -31,7 +31,8 @@ export const constantRoutes = [
{ {
path: '/redirect/:path(.*)', path: '/redirect/:path(.*)',
component: () => import('@/views/redirect/index.vue') component: () => import('@/views/redirect/index.vue')
}] }
]
}, },
{ {
path: '/login', path: '/login',
@ -49,7 +50,7 @@ export const constantRoutes = [
hidden: true hidden: true
}, },
{ {
path: "/:pathMatch(.*)*", path: '/:pathMatch(.*)*',
component: () => import('@/views/error/404'), component: () => import('@/views/error/404'),
hidden: true hidden: true
}, },
@ -68,7 +69,8 @@ export const constantRoutes = [
component: () => import('@/views/index'), component: () => import('@/views/index'),
name: 'Index', name: 'Index',
meta: { title: '首页', icon: 'dashboard', affix: true, titleKey: 'menu.home' } meta: { title: '首页', icon: 'dashboard', affix: true, titleKey: 'menu.home' }
}] }
]
}, },
{ {
path: '/user', path: '/user',
@ -81,7 +83,8 @@ export const constantRoutes = [
component: () => import('@/views/system/user/profile/index'), component: () => import('@/views/system/user/profile/index'),
name: 'Profile', name: 'Profile',
meta: { title: '个人中心', icon: 'user', titleKey: 'menu.personalCenter' } meta: { title: '个人中心', icon: 'user', titleKey: 'menu.personalCenter' }
}] }
]
}, },
// 不用可删掉 // 不用可删掉
{ {
@ -92,16 +95,17 @@ export const constantRoutes = [
children: [ children: [
{ {
path: 'icon', path: 'icon',
component: () => import('@/views/components/icons/index'), // component: () => import('@/views/components/icons/index'),
component: () => import('@/views/business/GenDemo'),
name: 'icon', name: 'icon',
meta: { title: '图标icon', icon: 'icon1', noCache: 'fasle', titleKey: 'menu.icon' } meta: { title: '图标icon', icon: 'icon1', noCache: 'fasle', titleKey: 'menu.icon' }
}] }
}, ]
]; }
]
const router = createRouter({ const router = createRouter({
history: createWebHistory( history: createWebHistory(import.meta.env.VITE_APP_ROUTER_PREFIX),
import.meta.env.VITE_APP_ROUTER_PREFIX),
routes: constantRoutes, routes: constantRoutes,
scrollBehavior(to, from, savedPosition) { scrollBehavior(to, from, savedPosition) {
if (savedPosition) { if (savedPosition) {
@ -109,7 +113,7 @@ const router = createRouter({
} else { } else {
return { top: 0 } return { top: 0 }
} }
}, }
}); })
export default router; export default router

View File

@ -75,5 +75,9 @@ export default {
/** /**
* 默认大小 * 默认大小
*/ */
defaultSize: 'default' defaultSize: 'default',
/**
* 默认语言
*/
defaultLang: 'zh-cn'
} }

View File

@ -1,4 +1,5 @@
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import cache from '@/plugins/cache'
import defaultSettings from '@/settings' import defaultSettings from '@/settings'
const useAppStore = defineStore('app', { const useAppStore = defineStore('app', {
state: () => ({ state: () => ({
@ -8,8 +9,8 @@ const useAppStore = defineStore('app', {
hide: false hide: false
}, },
device: 'desktop', device: 'desktop',
size: Cookies.get('size') || defaultSettings.defaultSize, size: cache.local.get('size') || defaultSettings.defaultSize,
lang: Cookies.get('lang') || 'zh-cn' lang: cache.cookie.get('lang') || defaultSettings.defaultLang
}), }),
actions: { actions: {
toggleSideBar() { toggleSideBar() {
@ -32,14 +33,14 @@ const useAppStore = defineStore('app', {
}, },
setSize(size) { setSize(size) {
this.size = size this.size = size
Cookies.set('size', size) cache.local.set('size', size)
}, },
toggleSideBarHide(status) { toggleSideBarHide(status) {
this.sidebar.hide = status this.sidebar.hide = status
}, },
setLang(lang) { setLang(lang) {
this.lang = lang this.lang = lang
Cookies.set('lang', lang) cache.cookie.set('lang', lang)
} }
} }
}) })