Skip to content

Commit 99bc817

Browse files
authored
feat: Save custom theme color scheme (#7690)
1 parent cf2a137 commit 99bc817

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

frontend/src/views/setting/panel/index.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ const mobile = computed(() => {
252252
interface ThemeColor {
253253
light: string;
254254
dark: string;
255+
themePredefineColors: {
256+
light: string[];
257+
dark: string[];
258+
};
255259
}
256260
257261
const form = reactive({
@@ -366,8 +370,10 @@ const search = async () => {
366370
const xpackRes = await getXpackSetting();
367371
if (xpackRes) {
368372
form.theme = xpackRes.data.theme || globalStore.themeConfig.theme || 'light';
369-
form.themeColor = JSON.parse(xpackRes.data.themeColor);
370-
globalStore.themeConfig.themeColor = xpackRes.data.themeColor;
373+
form.themeColor = JSON.parse(xpackRes.data.themeColor || '{"light":"#005eeb","dark":"#F0BE96"}');
374+
globalStore.themeConfig.themeColor = xpackRes.data.themeColor
375+
? xpackRes.data.themeColor
376+
: '{"light":"#005eeb","dark":"#F0BE96"}';
371377
globalStore.themeConfig.theme = form.theme;
372378
form.proxyDocker = xpackRes.data.proxyDocker;
373379
}

frontend/src/views/setting/panel/theme-color/index.vue

+21-7
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,24 @@ const drawerVisible = ref();
9494
const loading = ref();
9595
9696
interface DialogProps {
97-
themeColor: { light: string; dark: string };
97+
themeColor: {
98+
light: string;
99+
dark: string;
100+
themePredefineColors: {
101+
light: string[];
102+
dark: string[];
103+
};
104+
};
98105
theme: '';
99106
}
100107
101108
interface ThemeColor {
102109
light: string;
103110
dark: string;
111+
themePredefineColors: {
112+
light: string[];
113+
dark: string[];
114+
};
104115
}
105116
106117
const form = reactive({
@@ -124,6 +135,7 @@ const lightPredefineColors = ref([
124135
'#ff4500',
125136
'#ff8c00',
126137
'#ffd700',
138+
'#333539',
127139
]);
128140
const darkPredefineColors = ref([
129141
'#238636',
@@ -135,6 +147,7 @@ const darkPredefineColors = ref([
135147
'#ff4500',
136148
'#ff8c00',
137149
'#ffd700',
150+
'#333539',
138151
]);
139152
140153
const defaultDarkColors = [
@@ -191,9 +204,13 @@ const acceptParams = (params: DialogProps): void => {
191204
form.theme = params.theme;
192205
form.dark = form.themeColor.dark;
193206
form.light = form.themeColor.light;
207+
if (form.themeColor.themePredefineColors) {
208+
localStorage.setItem(STORAGE_KEY, JSON.stringify(form.themeColor.themePredefineColors));
209+
}
194210
initThemeColors();
195211
lightPredefineColors.value = themeColors.value['light'];
196212
darkPredefineColors.value = themeColors.value['dark'];
213+
lightColors = defaultLightColors;
197214
lightPredefineColors.value.slice(0, 2).forEach((color) => {
198215
const exists = lightColors.some((item) => item.color === color);
199216
if (!exists) {
@@ -203,6 +220,7 @@ const acceptParams = (params: DialogProps): void => {
203220
});
204221
}
205222
});
223+
darkColors = defaultDarkColors;
206224
darkPredefineColors.value.slice(0, 2).forEach((color) => {
207225
const exists = darkColors.some((item) => item.color === color);
208226
if (!exists) {
@@ -259,7 +277,7 @@ const onSave = async (formEl: FormInstance | undefined) => {
259277
}).then(async () => {
260278
await formEl.validate(async (valid) => {
261279
if (!valid) return;
262-
form.themeColor = { light: form.light, dark: form.dark };
280+
form.themeColor = { light: form.light, dark: form.dark, themePredefineColors: themeColors.value };
263281
if (globalStore.isProductPro) {
264282
await updateXpackSettingByKey('ThemeColor', JSON.stringify(form.themeColor));
265283
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
@@ -288,12 +306,8 @@ const onReSet = async () => {
288306
cancelButtonText: i18n.global.t('commons.button.cancel'),
289307
type: 'info',
290308
}).then(async () => {
291-
form.themeColor = { light: '#005eeb', dark: '#F0BE96' };
309+
form.themeColor = { light: '#005eeb', dark: '#F0BE96', themePredefineColors: themeColors.value };
292310
if (globalStore.isProductPro) {
293-
localStorage.setItem(STORAGE_KEY, JSON.stringify(defaultColors));
294-
themeColors.value = { ...defaultColors };
295-
darkColors = [...defaultDarkColors];
296-
lightColors = [...defaultLightColors];
297311
await updateXpackSettingByKey('ThemeColor', JSON.stringify(form.themeColor));
298312
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
299313
loading.value = false;

0 commit comments

Comments
 (0)