app.js
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import Cookies from 'js-cookie'
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import en from 'element-plus/es/locale/lang/en';
import ru from 'element-plus/es/locale/lang/ru';
import router from '@/router'
const useAppStore = defineStore(
'app',
{
state: () => ({
definition: [
{ label: '中文', value: 'zh_CN', correspondence: zhCn},
{ label: '英文', value: 'en_US', correspondence: en},
{ label: '俄文', value: 'ru_RU', correspondence: ru},
],
sidebar: {
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
withoutAnimation: false,
hide: false,
status: true
},
device: 'desktop',
size: Cookies.get('size') || 'default',
language: 'zh_CN',
locale: zhCn,
}),
actions: {
toggleSideBar(withoutAnimation, opened = true) {
if (this.sidebar.hide) {
return false;
}
// this.sidebar.opened = !this.sidebar.opened
this.sidebar.opened = opened
this.sidebar.withoutAnimation = withoutAnimation
if (this.sidebar.opened) {
Cookies.set('sidebarStatus', 1)
} else {
Cookies.set('sidebarStatus', 0)
}
},
closeSideBar({ withoutAnimation }) {
Cookies.set('sidebarStatus', 0)
this.sidebar.opened = false
this.sidebar.withoutAnimation = withoutAnimation
},
toggleDevice(device) {
this.device = device
},
setSize(size) {
this.size = size;
Cookies.set('size', size)
},
toggleSideBarHide(status) {
this.sidebar.hide = status
},
// 设置侧边栏是否需要显示
toggleSidebarStatus(status){
this.sidebar.status = status
},
// 国际化改变
changeLanguage(state) {
this.language = state
// location.reload()
const { path, query } = router.currentRoute.value;
router.replace({
path: '/redirect' + path,
query: query
})
console.log(router);
// this.locale = this.changeLocal()
},
changeLocal() {
return this.definition.find(i => i.value == this.language)?.correspondence || zhCn
}
}
})
export default useAppStore