提交 | 用户 | 时间
|
820397
|
1 |
import { defineStore } from 'pinia' |
H |
2 |
import { store } from '../index' |
9259c2
|
3 |
import { humpToUnderline, setCssVar } from '@/utils' |
820397
|
4 |
import { ElMessage } from 'element-plus' |
H |
5 |
import { CACHE_KEY, useCache } from '@/hooks/web/useCache' |
|
6 |
import { ElementPlusSize } from '@/types/elementPlus' |
|
7 |
import { LayoutType } from '@/types/layout' |
|
8 |
import { ThemeTypes } from '@/types/theme' |
|
9 |
|
|
10 |
const { wsCache } = useCache() |
|
11 |
|
|
12 |
interface AppState { |
|
13 |
breadcrumb: boolean |
|
14 |
breadcrumbIcon: boolean |
|
15 |
collapse: boolean |
|
16 |
uniqueOpened: boolean |
|
17 |
hamburger: boolean |
|
18 |
screenfull: boolean |
|
19 |
search: boolean |
|
20 |
size: boolean |
|
21 |
locale: boolean |
|
22 |
message: boolean |
|
23 |
tagsView: boolean |
9259c2
|
24 |
tagsViewImmerse: boolean |
820397
|
25 |
tagsViewIcon: boolean |
H |
26 |
logo: boolean |
|
27 |
fixedHeader: boolean |
|
28 |
greyMode: boolean |
|
29 |
pageLoading: boolean |
|
30 |
layout: LayoutType |
|
31 |
title: string |
|
32 |
userInfo: string |
|
33 |
isDark: boolean |
|
34 |
currentSize: ElementPlusSize |
|
35 |
sizeMap: ElementPlusSize[] |
|
36 |
mobile: boolean |
|
37 |
footer: boolean |
|
38 |
theme: ThemeTypes |
|
39 |
fixedMenu: boolean |
|
40 |
} |
|
41 |
|
|
42 |
export const useAppStore = defineStore('app', { |
|
43 |
state: (): AppState => { |
|
44 |
return { |
|
45 |
userInfo: 'userInfo', // 登录信息存储字段-建议每个项目换一个字段,避免与其他项目冲突 |
|
46 |
sizeMap: ['default', 'large', 'small'], |
|
47 |
mobile: false, // 是否是移动端 |
|
48 |
title: import.meta.env.VITE_APP_TITLE, // 标题 |
|
49 |
pageLoading: false, // 路由跳转loading |
|
50 |
|
|
51 |
breadcrumb: true, // 面包屑 |
|
52 |
breadcrumbIcon: true, // 面包屑图标 |
|
53 |
collapse: false, // 折叠菜单 |
|
54 |
uniqueOpened: true, // 是否只保持一个子菜单的展开 |
|
55 |
hamburger: true, // 折叠图标 |
|
56 |
screenfull: true, // 全屏图标 |
|
57 |
search: true, // 搜索图标 |
|
58 |
size: true, // 尺寸图标 |
|
59 |
locale: true, // 多语言图标 |
|
60 |
message: true, // 消息图标 |
|
61 |
tagsView: true, // 标签页 |
9259c2
|
62 |
tagsViewImmerse: false, // 标签页沉浸 |
820397
|
63 |
tagsViewIcon: true, // 是否显示标签图标 |
H |
64 |
logo: true, // logo |
|
65 |
fixedHeader: true, // 固定toolheader |
|
66 |
footer: true, // 显示页脚 |
|
67 |
greyMode: false, // 是否开始灰色模式,用于特殊悼念日 |
|
68 |
fixedMenu: wsCache.get('fixedMenu') || false, // 是否固定菜单 |
|
69 |
|
|
70 |
layout: wsCache.get(CACHE_KEY.LAYOUT) || 'classic', // layout布局 |
|
71 |
isDark: wsCache.get(CACHE_KEY.IS_DARK) || false, // 是否是暗黑模式 |
|
72 |
currentSize: wsCache.get('default') || 'default', // 组件尺寸 |
|
73 |
theme: wsCache.get(CACHE_KEY.THEME) || { |
|
74 |
// 主题色 |
|
75 |
elColorPrimary: '#409eff', |
|
76 |
// 左侧菜单边框颜色 |
|
77 |
leftMenuBorderColor: 'inherit', |
|
78 |
// 左侧菜单背景颜色 |
|
79 |
leftMenuBgColor: '#001529', |
|
80 |
// 左侧菜单浅色背景颜色 |
|
81 |
leftMenuBgLightColor: '#0f2438', |
|
82 |
// 左侧菜单选中背景颜色 |
|
83 |
leftMenuBgActiveColor: 'var(--el-color-primary)', |
|
84 |
// 左侧菜单收起选中背景颜色 |
|
85 |
leftMenuCollapseBgActiveColor: 'var(--el-color-primary)', |
|
86 |
// 左侧菜单字体颜色 |
|
87 |
leftMenuTextColor: '#bfcbd9', |
|
88 |
// 左侧菜单选中字体颜色 |
|
89 |
leftMenuTextActiveColor: '#fff', |
|
90 |
// logo字体颜色 |
|
91 |
logoTitleTextColor: '#fff', |
|
92 |
// logo边框颜色 |
|
93 |
logoBorderColor: 'inherit', |
|
94 |
// 头部背景颜色 |
|
95 |
topHeaderBgColor: '#fff', |
|
96 |
// 头部字体颜色 |
|
97 |
topHeaderTextColor: 'inherit', |
|
98 |
// 头部悬停颜色 |
|
99 |
topHeaderHoverColor: '#f6f6f6', |
|
100 |
// 头部边框颜色 |
|
101 |
topToolBorderColor: '#eee' |
|
102 |
} |
|
103 |
} |
|
104 |
}, |
|
105 |
getters: { |
|
106 |
getBreadcrumb(): boolean { |
|
107 |
return this.breadcrumb |
|
108 |
}, |
|
109 |
getBreadcrumbIcon(): boolean { |
|
110 |
return this.breadcrumbIcon |
|
111 |
}, |
|
112 |
getCollapse(): boolean { |
|
113 |
return this.collapse |
|
114 |
}, |
|
115 |
getUniqueOpened(): boolean { |
|
116 |
return this.uniqueOpened |
|
117 |
}, |
|
118 |
getHamburger(): boolean { |
|
119 |
return this.hamburger |
|
120 |
}, |
|
121 |
getScreenfull(): boolean { |
|
122 |
return this.screenfull |
|
123 |
}, |
|
124 |
getSize(): boolean { |
|
125 |
return this.size |
|
126 |
}, |
|
127 |
getLocale(): boolean { |
|
128 |
return this.locale |
|
129 |
}, |
|
130 |
getMessage(): boolean { |
|
131 |
return this.message |
|
132 |
}, |
|
133 |
getTagsView(): boolean { |
|
134 |
return this.tagsView |
9259c2
|
135 |
}, |
H |
136 |
getTagsViewImmerse(): boolean { |
|
137 |
return this.tagsViewImmerse |
820397
|
138 |
}, |
H |
139 |
getTagsViewIcon(): boolean { |
|
140 |
return this.tagsViewIcon |
|
141 |
}, |
|
142 |
getLogo(): boolean { |
|
143 |
return this.logo |
|
144 |
}, |
|
145 |
getFixedHeader(): boolean { |
|
146 |
return this.fixedHeader |
|
147 |
}, |
|
148 |
getGreyMode(): boolean { |
|
149 |
return this.greyMode |
|
150 |
}, |
|
151 |
getFixedMenu(): boolean { |
|
152 |
return this.fixedMenu |
|
153 |
}, |
|
154 |
getPageLoading(): boolean { |
|
155 |
return this.pageLoading |
|
156 |
}, |
|
157 |
getLayout(): LayoutType { |
|
158 |
return this.layout |
|
159 |
}, |
|
160 |
getTitle(): string { |
|
161 |
return this.title |
|
162 |
}, |
|
163 |
getUserInfo(): string { |
|
164 |
return this.userInfo |
|
165 |
}, |
|
166 |
getIsDark(): boolean { |
|
167 |
return this.isDark |
|
168 |
}, |
|
169 |
getCurrentSize(): ElementPlusSize { |
|
170 |
return this.currentSize |
|
171 |
}, |
|
172 |
getSizeMap(): ElementPlusSize[] { |
|
173 |
return this.sizeMap |
|
174 |
}, |
|
175 |
getMobile(): boolean { |
|
176 |
return this.mobile |
|
177 |
}, |
|
178 |
getTheme(): ThemeTypes { |
|
179 |
return this.theme |
|
180 |
}, |
|
181 |
getFooter(): boolean { |
|
182 |
return this.footer |
|
183 |
} |
|
184 |
}, |
|
185 |
actions: { |
|
186 |
setBreadcrumb(breadcrumb: boolean) { |
|
187 |
this.breadcrumb = breadcrumb |
|
188 |
}, |
|
189 |
setBreadcrumbIcon(breadcrumbIcon: boolean) { |
|
190 |
this.breadcrumbIcon = breadcrumbIcon |
|
191 |
}, |
|
192 |
setCollapse(collapse: boolean) { |
|
193 |
this.collapse = collapse |
|
194 |
}, |
|
195 |
setUniqueOpened(uniqueOpened: boolean) { |
|
196 |
this.uniqueOpened = uniqueOpened |
|
197 |
}, |
|
198 |
setHamburger(hamburger: boolean) { |
|
199 |
this.hamburger = hamburger |
|
200 |
}, |
|
201 |
setScreenfull(screenfull: boolean) { |
|
202 |
this.screenfull = screenfull |
|
203 |
}, |
|
204 |
setSize(size: boolean) { |
|
205 |
this.size = size |
|
206 |
}, |
|
207 |
setLocale(locale: boolean) { |
|
208 |
this.locale = locale |
|
209 |
}, |
|
210 |
setMessage(message: boolean) { |
|
211 |
this.message = message |
|
212 |
}, |
|
213 |
setTagsView(tagsView: boolean) { |
|
214 |
this.tagsView = tagsView |
|
215 |
}, |
9259c2
|
216 |
setTagsViewImmerse(tagsViewImmerse: boolean) { |
H |
217 |
this.tagsViewImmerse = tagsViewImmerse |
|
218 |
}, |
820397
|
219 |
setTagsViewIcon(tagsViewIcon: boolean) { |
H |
220 |
this.tagsViewIcon = tagsViewIcon |
|
221 |
}, |
|
222 |
setLogo(logo: boolean) { |
|
223 |
this.logo = logo |
|
224 |
}, |
|
225 |
setFixedHeader(fixedHeader: boolean) { |
|
226 |
this.fixedHeader = fixedHeader |
|
227 |
}, |
|
228 |
setGreyMode(greyMode: boolean) { |
|
229 |
this.greyMode = greyMode |
|
230 |
}, |
|
231 |
setFixedMenu(fixedMenu: boolean) { |
|
232 |
wsCache.set('fixedMenu', fixedMenu) |
|
233 |
this.fixedMenu = fixedMenu |
|
234 |
}, |
|
235 |
setPageLoading(pageLoading: boolean) { |
|
236 |
this.pageLoading = pageLoading |
|
237 |
}, |
|
238 |
setLayout(layout: LayoutType) { |
|
239 |
if (this.mobile && layout !== 'classic') { |
|
240 |
ElMessage.warning('移动端模式下不支持切换其他布局') |
|
241 |
return |
|
242 |
} |
|
243 |
this.layout = layout |
|
244 |
wsCache.set(CACHE_KEY.LAYOUT, this.layout) |
|
245 |
}, |
|
246 |
setTitle(title: string) { |
|
247 |
this.title = title |
|
248 |
}, |
|
249 |
setIsDark(isDark: boolean) { |
|
250 |
this.isDark = isDark |
|
251 |
if (this.isDark) { |
|
252 |
document.documentElement.classList.add('dark') |
|
253 |
document.documentElement.classList.remove('light') |
|
254 |
} else { |
|
255 |
document.documentElement.classList.add('light') |
|
256 |
document.documentElement.classList.remove('dark') |
|
257 |
} |
|
258 |
wsCache.set(CACHE_KEY.IS_DARK, this.isDark) |
|
259 |
}, |
|
260 |
setCurrentSize(currentSize: ElementPlusSize) { |
|
261 |
this.currentSize = currentSize |
|
262 |
wsCache.set('currentSize', this.currentSize) |
|
263 |
}, |
|
264 |
setMobile(mobile: boolean) { |
|
265 |
this.mobile = mobile |
|
266 |
}, |
|
267 |
setTheme(theme: ThemeTypes) { |
|
268 |
this.theme = Object.assign(this.theme, theme) |
|
269 |
wsCache.set(CACHE_KEY.THEME, this.theme) |
|
270 |
}, |
|
271 |
setCssVarTheme() { |
|
272 |
for (const key in this.theme) { |
|
273 |
setCssVar(`--${humpToUnderline(key)}`, this.theme[key]) |
|
274 |
} |
|
275 |
}, |
|
276 |
setFooter(footer: boolean) { |
|
277 |
this.footer = footer |
|
278 |
} |
|
279 |
}, |
|
280 |
persist: false |
|
281 |
}) |
|
282 |
|
|
283 |
export const useAppStoreWithOut = () => { |
|
284 |
return useAppStore(store) |
|
285 |
} |