-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathindex.vue
More file actions
488 lines (451 loc) · 20.5 KB
/
index.vue
File metadata and controls
488 lines (451 loc) · 20.5 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
<template>
<div v-loading="loading">
<LayoutContent :title="$t('setting.panel')" :divider="true">
<template #main>
<el-form :model="form" :label-position="mobile ? 'top' : 'left'" label-width="150px">
<el-row>
<el-col :span="1"><br /></el-col>
<el-col :xs="24" :sm="20" :md="15" :lg="12" :xl="12">
<el-form-item :label="$t('setting.user')" prop="userName">
<el-input disabled v-model="form.userName">
<template #append>
<el-button @click="onChangeUserName()" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
</el-form-item>
<el-form-item :label="$t('setting.passwd')" prop="password">
<el-input type="password" disabled v-model="form.password">
<template #append>
<el-button icon="Setting" @click="onChangePassword">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
</el-form-item>
<el-form-item :label="$t('setting.theme')" prop="theme">
<div class="flex justify-between items-center gap-6">
<el-radio-group @change="onSave('Theme', form.theme)" v-model="form.theme">
<el-radio-button value="light">
<span>{{ $t('setting.light') }}</span>
</el-radio-button>
<el-radio-button value="dark">
<span>{{ $t('setting.dark') }}</span>
</el-radio-button>
<el-radio-button value="auto">
<span>{{ $t('setting.auto') }}</span>
</el-radio-button>
</el-radio-group>
<el-button
v-if="isProductPro"
@click="onChangeThemeColor"
icon="Setting"
class="!h-[34px]"
>
<span>{{ $t('container.custom') }}</span>
</el-button>
</div>
</el-form-item>
<el-form-item :label="$t('setting.menuTabs')" prop="menuTabs">
<el-radio-group @change="onSave('MenuTabs', form.menuTabs)" v-model="form.menuTabs">
<el-radio-button value="enable">
<span>{{ $t('commons.button.enable') }}</span>
</el-radio-button>
<el-radio-button value="disable">
<span>{{ $t('commons.button.disable') }}</span>
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item :label="$t('setting.title')" prop="panelName">
<el-input disabled v-model="form.panelName">
<template #append>
<el-button icon="Setting" @click="onChangeTitle">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
</el-form-item>
<el-form-item :label="$t('setting.language')" prop="language">
<el-radio-group
style="width: 100%"
@change="onSave('Language', form.language)"
v-model="form.language"
>
<el-radio value="zh">中文(简体)</el-radio>
<el-radio value="tw">中文(繁體)</el-radio>
<el-radio value="en">English</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item :label="$t('setting.sessionTimeout')" prop="sessionTimeout">
<el-input disabled v-model.number="form.sessionTimeout">
<template #append>
<el-button @click="onChangeTimeout" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
<span class="input-help">
{{ $t('setting.sessionTimeoutHelper', [form.sessionTimeout]) }}
</span>
</el-form-item>
<el-form-item :label="$t('setting.defaultNetwork')">
<el-input disabled v-model="form.defaultNetworkVal">
<template #append>
<el-button v-show="!show" @click="onChangeNetwork" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
</el-form-item>
<el-form-item :label="$t('setting.systemIP')" prop="systemIP">
<el-input disabled v-if="form.systemIP" v-model="form.systemIP">
<template #append>
<el-button @click="onChangeSystemIP" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
<el-input disabled v-if="!form.systemIP" v-model="unset">
<template #append>
<el-button @click="onChangeSystemIP" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
</el-form-item>
<el-form-item v-if="!globalStore.isIntl" :label="$t('setting.proxy')" prop="proxyShow">
<el-input disabled v-model="form.proxyShow">
<template #append>
<el-button @click="onChangeProxy" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
</el-form-item>
<el-form-item :label="$t('setting.apiInterface')" prop="apiInterface">
<el-switch
@change="onChangeApiInterfaceStatus"
v-model="form.apiInterfaceStatus"
active-value="enable"
inactive-value="disable"
/>
<span class="input-help">{{ $t('setting.apiInterfaceHelper') }}</span>
<div v-if="form.apiInterfaceStatus === 'enable'">
<div>
<el-button link type="primary" @click="onChangeApiInterfaceStatus">
{{ $t('commons.button.view') }}
</el-button>
</div>
</div>
</el-form-item>
<el-form-item :label="$t('setting.developerMode')" prop="developerMode">
<el-radio-group
@change="onSave('DeveloperMode', form.developerMode)"
v-model="form.developerMode"
>
<el-radio-button value="enable">
<span>{{ $t('commons.button.enable') }}</span>
</el-radio-button>
<el-radio-button value="disable">
<span>{{ $t('commons.button.disable') }}</span>
</el-radio-button>
</el-radio-group>
<span class="input-help">{{ $t('setting.developerModeHelper') }}</span>
</el-form-item>
<el-form-item v-if="!globalStore.isIntl" :label="$t('setting.advancedMenuHide')">
<el-input disabled v-model="form.proHideMenus">
<template #append>
<el-button v-show="!show" @click="onChangeHideMenus" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
</template>
</LayoutContent>
<Password ref="passwordRef" />
<UserName ref="userNameRef" />
<PanelName ref="panelNameRef" @search="search()" />
<SystemIP ref="systemIPRef" @search="search()" />
<Proxy ref="proxyRef" @search="search()" />
<ApiInterface ref="apiInterfaceRef" @search="search()" />
<Timeout ref="timeoutRef" @search="search()" />
<Network ref="networkRef" @search="search()" />
<HideMenu ref="hideMenuRef" @search="search()" />
<ThemeColor ref="themeColorRef" />
</div>
</template>
<script lang="ts" setup>
import { ref, reactive, onMounted, computed } from 'vue';
import { ElForm, ElMessageBox } from 'element-plus';
import { getSettingInfo, updateSetting, getSystemAvailable, updateApiConfig } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
import { useI18n } from 'vue-i18n';
import { useTheme } from '@/hooks/use-theme';
import { MsgSuccess } from '@/utils/message';
import Password from '@/views/setting/panel/password/index.vue';
import UserName from '@/views/setting/panel/username/index.vue';
import Timeout from '@/views/setting/panel/timeout/index.vue';
import PanelName from '@/views/setting/panel/name/index.vue';
import SystemIP from '@/views/setting/panel/systemip/index.vue';
import Proxy from '@/views/setting/panel/proxy/index.vue';
import Network from '@/views/setting/panel/default-network/index.vue';
import HideMenu from '@/views/setting/panel/hidemenu/index.vue';
import ThemeColor from '@/views/setting/panel/theme-color/index.vue';
import ApiInterface from '@/views/setting/panel/api-interface/index.vue';
import { storeToRefs } from 'pinia';
import { getXpackSetting, updateXpackSettingByKey } from '@/utils/xpack';
import { setPrimaryColor } from '@/utils/theme';
const loading = ref(false);
const i18n = useI18n();
const globalStore = GlobalStore();
const { isProductPro } = storeToRefs(globalStore);
const { switchTheme } = useTheme();
const mobile = computed(() => {
return globalStore.isMobile();
});
interface ThemeColor {
light: string;
dark: string;
}
const form = reactive({
userName: '',
password: '',
email: '',
sessionTimeout: 0,
localTime: '',
timeZone: '',
ntpSite: '',
panelName: '',
systemIP: '',
theme: '',
themeColor: {} as ThemeColor,
menuTabs: '',
language: '',
complexityVerification: '',
defaultNetwork: '',
defaultNetworkVal: '',
developerMode: '',
proxyShow: '',
proxyUrl: '',
proxyType: '',
proxyPort: '',
proxyUser: '',
proxyPasswd: '',
proxyPasswdKeep: '',
proxyDocker: '',
apiInterfaceStatus: 'disable',
apiKey: '',
ipWhiteList: '',
proHideMenus: ref(i18n.t('setting.unSetting')),
hideMenuList: '',
});
const show = ref();
const userNameRef = ref();
const passwordRef = ref();
const panelNameRef = ref();
const systemIPRef = ref();
const proxyRef = ref();
const timeoutRef = ref();
const networkRef = ref();
const hideMenuRef = ref();
const themeColorRef = ref();
const apiInterfaceRef = ref();
const unset = ref(i18n.t('setting.unSetting'));
interface Node {
id: string;
title: string;
path?: string;
label: string;
isCheck: boolean;
children?: Node[];
}
const search = async () => {
const res = await getSettingInfo();
form.userName = res.data.userName;
form.password = '******';
form.sessionTimeout = Number(res.data.sessionTimeout);
form.localTime = res.data.localTime;
form.timeZone = res.data.timeZone;
form.ntpSite = res.data.ntpSite;
form.panelName = res.data.panelName;
form.systemIP = res.data.systemIP;
form.menuTabs = res.data.menuTabs;
form.language = res.data.language;
form.complexityVerification = res.data.complexityVerification;
form.defaultNetwork = res.data.defaultNetwork;
form.defaultNetworkVal = res.data.defaultNetwork === 'all' ? i18n.t('commons.table.all') : res.data.defaultNetwork;
form.proHideMenus = res.data.xpackHideMenu;
form.hideMenuList = res.data.xpackHideMenu;
form.developerMode = res.data.developerMode;
form.proxyUrl = res.data.proxyUrl;
form.proxyType = res.data.proxyType;
form.proxyPort = res.data.proxyPort;
form.proxyShow = form.proxyUrl ? form.proxyUrl + ':' + form.proxyPort : unset.value;
form.proxyUser = res.data.proxyUser;
form.proxyPasswd = res.data.proxyPasswd;
form.proxyPasswdKeep = res.data.proxyPasswdKeep;
form.apiInterfaceStatus = res.data.apiInterfaceStatus;
form.apiKey = res.data.apiKey;
form.ipWhiteList = res.data.ipWhiteList;
const json: Node = JSON.parse(res.data.xpackHideMenu);
const checkedTitles = getCheckedTitles(json);
form.proHideMenus = checkedTitles.toString();
if (isProductPro.value) {
const xpackRes = await getXpackSetting();
if (xpackRes) {
form.theme = xpackRes.data.theme || globalStore.themeConfig.theme || 'light';
form.themeColor = JSON.parse(xpackRes.data.themeColor);
globalStore.themeConfig.themeColor = xpackRes.data.themeColor;
globalStore.themeConfig.theme = form.theme;
form.proxyDocker = xpackRes.data.proxyDocker;
}
} else {
form.theme = globalStore.themeConfig.theme || res.data.theme || 'light';
}
};
function extractTitles(node: Node, result: string[]): void {
if (!node.isCheck && !node.children) {
result.push(i18n.t(node.title));
}
if (node.children) {
for (const childNode of node.children) {
extractTitles(childNode, result);
}
}
}
function getCheckedTitles(json: Node): string[] {
let result: string[] = [];
extractTitles(json, result);
if (result.length === 0) {
result.push(i18n.t('setting.unSetting'));
}
if (result.length === json.children.length) {
result = [];
result.push(i18n.t('setting.hideALL'));
}
return result;
}
const onChangePassword = () => {
passwordRef.value.acceptParams({ complexityVerification: form.complexityVerification });
};
const onChangeUserName = () => {
userNameRef.value.acceptParams({ userName: form.userName });
};
const onChangeTitle = () => {
panelNameRef.value.acceptParams({ panelName: form.panelName });
};
const onChangeTimeout = () => {
timeoutRef.value.acceptParams({ sessionTimeout: form.sessionTimeout });
};
const onChangeSystemIP = () => {
systemIPRef.value.acceptParams({ systemIP: form.systemIP });
};
const onChangeProxy = () => {
proxyRef.value.acceptParams({
url: form.proxyUrl,
type: form.proxyType,
port: form.proxyPort,
user: form.proxyUser,
passwd: form.proxyPasswd,
passwdKeep: form.proxyPasswdKeep,
proxyDocker: form.proxyDocker,
});
};
const onChangeApiInterfaceStatus = async () => {
if (form.apiInterfaceStatus === 'enable') {
apiInterfaceRef.value.acceptParams({
apiInterfaceStatus: form.apiInterfaceStatus,
apiKey: form.apiKey,
ipWhiteList: form.ipWhiteList,
});
return;
}
ElMessageBox.confirm(i18n.t('setting.apiInterfaceClose'), i18n.t('setting.apiInterface'), {
confirmButtonText: i18n.t('commons.button.confirm'),
cancelButtonText: i18n.t('commons.button.cancel'),
})
.then(async () => {
loading.value = true;
form.apiInterfaceStatus = 'disable';
let param = {
apiKey: form.apiKey,
ipWhiteList: form.ipWhiteList,
apiInterfaceStatus: form.apiInterfaceStatus,
};
await updateApiConfig(param)
.then(() => {
loading.value = false;
search();
MsgSuccess(i18n.t('commons.msg.operationSuccess'));
})
.catch(() => {
loading.value = false;
});
})
.catch(() => {
form.apiInterfaceStatus = 'enable';
});
};
const onChangeNetwork = () => {
networkRef.value.acceptParams({ defaultNetwork: form.defaultNetwork });
};
const onChangeHideMenus = () => {
hideMenuRef.value.acceptParams({ menuList: form.hideMenuList });
};
const onChangeThemeColor = () => {
const themeColor: ThemeColor = JSON.parse(globalStore.themeConfig.themeColor);
themeColorRef.value.acceptParams({ themeColor: themeColor, theme: globalStore.themeConfig.theme });
};
const onSave = async (key: string, val: any) => {
loading.value = true;
if (key === 'Language') {
i18n.locale.value = val;
globalStore.updateLanguage(val);
}
if (key === 'Theme') {
globalStore.themeConfig.theme = val;
switchTheme();
if (globalStore.isProductPro) {
await updateXpackSettingByKey('Theme', val);
let color: string;
const themeColor: ThemeColor = JSON.parse(globalStore.themeConfig.themeColor);
if (val === 'auto') {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
color = prefersDark.matches ? themeColor.dark : themeColor.light;
} else {
color = val === 'dark' ? themeColor.dark : themeColor.light;
}
globalStore.themeConfig.primary = color;
setPrimaryColor(color);
}
}
if (key === 'MenuTabs') {
globalStore.setOpenMenuTabs(val === 'enable');
}
let param = {
key: key,
value: val + '',
};
await updateSetting(param)
.then(async () => {
if (param.key === 'Language') {
location.reload();
}
loading.value = false;
MsgSuccess(i18n.t('commons.msg.operationSuccess'));
await search();
})
.catch(() => {
loading.value = false;
});
};
onMounted(() => {
search();
getSystemAvailable();
});
</script>