-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathglobal.ts
More file actions
111 lines (107 loc) · 3.31 KB
/
global.ts
File metadata and controls
111 lines (107 loc) · 3.31 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { defineStore } from 'pinia';
import piniaPersistConfig from '@/config/pinia-persist';
import { GlobalState, ThemeConfigProp } from '../interface';
import { DeviceType } from '@/enums/app';
import i18n from '@/lang';
const GlobalStore = defineStore({
id: 'GlobalState',
state: (): GlobalState => ({
isLoading: false,
loadingText: '',
isLogin: false,
entrance: '',
language: '',
themeConfig: {
panelName: '',
primary: '#005eeb',
theme: 'auto',
footer: true,
themeColor: '',
title: '',
logo: '',
logoWithText: '',
favicon: '',
},
openMenuTabs: false,
isFullScreen: false,
isOnRestart: false,
agreeLicense: false,
hasNewVersion: false,
ignoreCaptcha: true,
device: DeviceType.Desktop,
lastFilePath: '',
currentDB: '',
currentRedisDB: '',
showEntranceWarn: true,
defaultNetwork: 'all',
isProductPro: false,
isIntl: false,
isTrial: false,
productProExpires: 0,
licenseVerify: '',
errStatus: '',
}),
getters: {
isDarkTheme: (state) =>
state.themeConfig.theme === 'dark' ||
(state.themeConfig.theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches),
isDarkGoldTheme: (state) => state.themeConfig.primary === '#F0BE96' && state.isProductPro,
docsUrl: (state) => (state.isIntl ? 'https://docs.1panel.pro' : 'https://1panel.cn/docs/v1'),
},
actions: {
setOpenMenuTabs(openMenuTabs: boolean) {
this.openMenuTabs = openMenuTabs;
},
setScreenFull() {
this.isFullScreen = !this.isFullScreen;
},
setLogStatus(login: boolean) {
this.isLogin = login;
},
setGlobalLoading(loading: boolean) {
this.isLoading = loading;
},
setLoadingText(text: string) {
this.loadingText = i18n.global.t('commons.loadingText.' + text);
},
setCsrfToken(token: string) {
this.csrfToken = token;
},
updateLanguage(language: any) {
if (language === 'pt-BR') {
language = 'pt-br';
}
this.language = language;
localStorage.setItem('lang', language);
},
setThemeConfig(themeConfig: ThemeConfigProp) {
this.themeConfig = themeConfig;
},
setAgreeLicense(agree: boolean) {
this.agreeLicense = agree;
},
toggleDevice(value: DeviceType) {
this.device = value;
},
isMobile() {
return this.device === DeviceType.Mobile;
},
setLastFilePath(path: string) {
this.lastFilePath = path;
},
setCurrentDB(name: string) {
this.currentDB = name;
},
setCurrentRedisDB(name: string) {
this.currentRedisDB = name;
},
setShowEntranceWarn(show: boolean) {
this.showEntranceWarn = show;
},
setDefaultNetwork(net: string) {
this.defaultNetwork = net;
},
},
persist: piniaPersistConfig('GlobalState'),
});
export default GlobalStore;