From 1702f429b484170d4e31f194b68e434d990e5ca3 Mon Sep 17 00:00:00 2001 From: bietiaop <1527109126@qq.com> Date: Sun, 9 Feb 2025 00:17:49 +0800 Subject: [PATCH] fix --- napcat.webui/src/main.tsx | 6 ++---- napcat.webui/src/pages/dashboard/config/login.tsx | 4 ++-- .../src/pages/dashboard/config/onebot.tsx | 4 ++-- napcat.webui/src/pages/dashboard/config/theme.tsx | 7 +++++-- napcat.webui/src/utils/theme.ts | 15 +++++++++++++++ 5 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 napcat.webui/src/utils/theme.ts diff --git a/napcat.webui/src/main.tsx b/napcat.webui/src/main.tsx index ed4dfb93..0b9c4f9c 100644 --- a/napcat.webui/src/main.tsx +++ b/napcat.webui/src/main.tsx @@ -8,6 +8,7 @@ import '@/styles/globals.css' import key from './const/key' import WebUIManager from './controllers/webui_manager' +import { loadTheme } from './utils/theme' WebUIManager.checkWebUiLogined() @@ -22,10 +23,7 @@ if (theme && !theme.startsWith('"')) { localStorage.setItem(key.theme, JSON.stringify(theme)) } -const themeStyle = document.createElement('link') -themeStyle.rel = 'stylesheet' -themeStyle.href = '/files/theme.css' -document.head.appendChild(themeStyle) +loadTheme() ReactDOM.createRoot(document.getElementById('root')!).render( // diff --git a/napcat.webui/src/pages/dashboard/config/login.tsx b/napcat.webui/src/pages/dashboard/config/login.tsx index 8138408c..0dc8e4a0 100644 --- a/napcat.webui/src/pages/dashboard/config/login.tsx +++ b/napcat.webui/src/pages/dashboard/config/login.tsx @@ -33,9 +33,9 @@ const LoginConfigCard = () => { setOnebotValue('quickLoginQQ', quickLoginData ?? '') } - const onSubmit = handleOnebotSubmit((data) => { + const onSubmit = handleOnebotSubmit(async (data) => { try { - QQManager.setQuickLoginQQ(data.quickLoginQQ) + await QQManager.setQuickLoginQQ(data.quickLoginQQ) toast.success('保存成功') } catch (error) { const msg = (error as Error).message diff --git a/napcat.webui/src/pages/dashboard/config/onebot.tsx b/napcat.webui/src/pages/dashboard/config/onebot.tsx index 1155db0e..8311b617 100644 --- a/napcat.webui/src/pages/dashboard/config/onebot.tsx +++ b/napcat.webui/src/pages/dashboard/config/onebot.tsx @@ -30,9 +30,9 @@ const OneBotConfigCard = () => { setOnebotValue('parseMultMsg', config.parseMultMsg) } - const onSubmit = handleOnebotSubmit((data) => { + const onSubmit = handleOnebotSubmit(async (data) => { try { - saveConfigWithoutNetwork(data) + await saveConfigWithoutNetwork(data) toast.success('保存成功') } catch (error) { const msg = (error as Error).message diff --git a/napcat.webui/src/pages/dashboard/config/theme.tsx b/napcat.webui/src/pages/dashboard/config/theme.tsx index 3116fa78..2806f8b2 100644 --- a/napcat.webui/src/pages/dashboard/config/theme.tsx +++ b/napcat.webui/src/pages/dashboard/config/theme.tsx @@ -7,6 +7,8 @@ import ColorPicker from '@/components/ColorPicker' import SaveButtons from '@/components/button/save_buttons' import PageLoading from '@/components/page_loading' +import { loadTheme } from '@/utils/theme' + import WebUIManager from '@/controllers/webui_manager' const ThemeConfigCard = () => { @@ -33,10 +35,11 @@ const ThemeConfigCard = () => { if (data) setOnebotValue('theme', data) } - const onSubmit = handleOnebotSubmit((data) => { + const onSubmit = handleOnebotSubmit(async (data) => { try { - WebUIManager.setThemeConfig(data.theme) + await WebUIManager.setThemeConfig(data.theme) toast.success('保存成功') + loadTheme() } catch (error) { const msg = (error as Error).message toast.error(`保存失败: ${msg}`) diff --git a/napcat.webui/src/utils/theme.ts b/napcat.webui/src/utils/theme.ts new file mode 100644 index 00000000..dafe4516 --- /dev/null +++ b/napcat.webui/src/utils/theme.ts @@ -0,0 +1,15 @@ +import { request } from './request' + +const style = document.createElement('style') +document.head.appendChild(style) + +export function loadTheme() { + request('/files/theme.css?_t=' + Date.now()) + .then((res) => res.data) + .then((css) => { + style.innerHTML = css + }) + .catch(() => { + console.error('Failed to load theme.css') + }) +}