From 956d47f9dabe3c38227aeb2f1e3e8dc460877bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=98=AD?= <81747598+lan-yonghui@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:06:19 +0800 Subject: [PATCH] refactor: Demo server, prohibit operation (#7433) --- frontend/src/api/index.ts | 2 +- frontend/src/views/setting/panel/index.vue | 74 +++++++++++----------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 57e5393e6..e52fc4e42 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -130,7 +130,7 @@ class RequestHttp { response.status, response.data && response.data['message'] ? response.data['message'] : '', ); - return; + return Promise.reject(error); default: globalStore.isLogin = false; globalStore.errStatus = 'code-' + response.status; diff --git a/frontend/src/views/setting/panel/index.vue b/frontend/src/views/setting/panel/index.vue index 2d7d8b601..15264a9f5 100644 --- a/frontend/src/views/setting/panel/index.vue +++ b/frontend/src/views/setting/panel/index.vue @@ -438,48 +438,50 @@ const onChangeThemeColor = () => { themeColorRef.value.acceptParams({ themeColor: themeColor, theme: globalStore.themeConfig.theme }); }; +const handleThemeChange = async (val: string) => { + 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); + } +}; + 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; - }); + try { + await updateSetting(param); + if (key === 'Language') { + i18n.locale.value = val; + globalStore.updateLanguage(val); + location.reload(); + } + + if (key === 'Theme') { + await handleThemeChange(val); + } + if (key === 'MenuTabs') { + globalStore.setOpenMenuTabs(val === 'enable'); + } + MsgSuccess(i18n.t('commons.msg.operationSuccess')); + await search(); + } catch (error) { + } finally { + loading.value = false; + } }; onMounted(() => {