update 修改非时效性数据存入Local中
This commit is contained in:
		| @ -4,7 +4,6 @@ import { createI18n } from 'vue-i18n'; | |||||||
| // 本地语言包 | // 本地语言包 | ||||||
| import enUSLocale from './en_US'; | import enUSLocale from './en_US'; | ||||||
| import zhCNLocale from './zh_CN'; | import zhCNLocale from './zh_CN'; | ||||||
| import Cookies from 'js-cookie'; |  | ||||||
|  |  | ||||||
| const messages = { | const messages = { | ||||||
|   zh_CN: { |   zh_CN: { | ||||||
| @ -16,22 +15,13 @@ const messages = { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 获取当前系统使用语言字符串 |  * 获取当前语言 | ||||||
|  * @returns zh-cn|en ... |  * @returns zh-cn|en ... | ||||||
|  */ |  */ | ||||||
| export const getLanguage = () => { | export const getLanguage = () => { | ||||||
|   // 本地缓存获取 |   const language = useStorage('language', 'zh_CN'); | ||||||
|   let language = Cookies.get('language'); |   if (language.value) { | ||||||
|   if (language) { |     return language.value; | ||||||
|     return language; |  | ||||||
|   } |  | ||||||
|   // 浏览器使用语言 |  | ||||||
|   language = navigator.language.toLowerCase(); |  | ||||||
|   const locales = Object.keys(messages); |  | ||||||
|   for (const locale of locales) { |  | ||||||
|     if (language.indexOf(locale) > -1) { |  | ||||||
|       return locale; |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
|   return 'zh_CN'; |   return 'zh_CN'; | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -1,46 +1,42 @@ | |||||||
| import Cookies from 'js-cookie'; |  | ||||||
| import zhCN from 'element-plus/es/locale/lang/zh-cn'; | import zhCN from 'element-plus/es/locale/lang/zh-cn'; | ||||||
| import enUS from 'element-plus/es/locale/lang/en'; | import enUS from 'element-plus/es/locale/lang/en'; | ||||||
|  |  | ||||||
| export const useAppStore = defineStore('app', () => { | export const useAppStore = defineStore('app', () => { | ||||||
|   const sidebarStatus = Cookies.get('sidebarStatus'); |   const sidebarStatus = useStorage('sidebarStatus', '1'); | ||||||
|   const sidebar = reactive({ |   const sidebar = reactive({ | ||||||
|     opened: sidebarStatus ? !!+sidebarStatus : true, |     opened: sidebarStatus.value ? !!+sidebarStatus.value : true, | ||||||
|     withoutAnimation: false, |     withoutAnimation: false, | ||||||
|     hide: false |     hide: false | ||||||
|   }); |   }); | ||||||
|   const device = ref<string>('desktop'); |   const device = ref<string>('desktop'); | ||||||
|   const size = ref(Cookies.get('size') || 'default'); |   const size = useStorage('size', 'default'); | ||||||
|  |  | ||||||
|   // 语言 |   // 语言 | ||||||
|   const language = ref(Cookies.get('language')); |   const language = useStorage('language', 'zh_CN'); | ||||||
|   const languageObj: any = { |   const languageObj: any = { | ||||||
|     en_US: enUS, |     en_US: enUS, | ||||||
|     zh_CN: zhCN |     zh_CN: zhCN | ||||||
|   }; |   }; | ||||||
|   const locale = computed(() => { |   const locale = computed(() => { | ||||||
|     if (!language.value) { |  | ||||||
|       return zhCN; |  | ||||||
|     } |  | ||||||
|     return languageObj[language.value]; |     return languageObj[language.value]; | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|   const toggleSideBar = (withoutAnimation?: boolean) => { |   const toggleSideBar = (withoutAnimation: boolean) => { | ||||||
|     if (sidebar.hide) { |     if (sidebar.hide) { | ||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     sidebar.opened = !sidebar.opened; |     sidebar.opened = !sidebar.opened; | ||||||
|     sidebar.withoutAnimation = withoutAnimation as boolean; |     sidebar.withoutAnimation = withoutAnimation; | ||||||
|     if (sidebar.opened) { |     if (sidebar.opened) { | ||||||
|       Cookies.set('sidebarStatus', '1'); |       sidebarStatus.value = '1'; | ||||||
|     } else { |     } else { | ||||||
|       Cookies.set('sidebarStatus', '0'); |       sidebarStatus.value = '0'; | ||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   const closeSideBar = ({ withoutAnimation }: any): void => { |   const closeSideBar = ({ withoutAnimation }: any): void => { | ||||||
|     Cookies.set('sidebarStatus', '0'); |     sidebarStatus.value = '0'; | ||||||
|     sidebar.opened = false; |     sidebar.opened = false; | ||||||
|     sidebar.withoutAnimation = withoutAnimation; |     sidebar.withoutAnimation = withoutAnimation; | ||||||
|   }; |   }; | ||||||
| @ -49,7 +45,6 @@ export const useAppStore = defineStore('app', () => { | |||||||
|   }; |   }; | ||||||
|   const setSize = (s: string): void => { |   const setSize = (s: string): void => { | ||||||
|     size.value = s; |     size.value = s; | ||||||
|     Cookies.set('size', s); |  | ||||||
|   }; |   }; | ||||||
|   const toggleSideBarHide = (status: boolean): void => { |   const toggleSideBarHide = (status: boolean): void => { | ||||||
|     sidebar.hide = status; |     sidebar.hide = status; | ||||||
| @ -57,7 +52,6 @@ export const useAppStore = defineStore('app', () => { | |||||||
|  |  | ||||||
|   const changeLanguage = (val: string): void => { |   const changeLanguage = (val: string): void => { | ||||||
|     language.value = val; |     language.value = val; | ||||||
|     Cookies.set('language', val); |  | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   return { |   return { | ||||||
|  | |||||||
| @ -1,9 +1,9 @@ | |||||||
| import Cookies from 'js-cookie'; |  | ||||||
|  |  | ||||||
| const TokenKey = 'Admin-Token'; | const TokenKey = 'Admin-Token'; | ||||||
|  |  | ||||||
| export const getToken = () => Cookies.get(TokenKey); | const tokenStorage = useStorage<null | string>(TokenKey, null); | ||||||
|  |  | ||||||
| export const setToken = (token: string) => Cookies.set(TokenKey, token); | export const getToken = () => tokenStorage.value; | ||||||
|  |  | ||||||
| export const removeToken = () => Cookies.remove(TokenKey); | export const setToken = (token: string) => (tokenStorage.value = token); | ||||||
|  |  | ||||||
|  | export const removeToken = () => (tokenStorage.value = null); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 LiuHao
					LiuHao