From c0de917641bd8ed08a5a4f1fda9c774770d879ec Mon Sep 17 00:00:00 2001 From: streakingman Date: Sun, 2 Oct 2022 21:50:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=93=E5=AD=98=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 55 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 7abf58f..4184a2c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -225,26 +225,45 @@ const App: FC = () => { useEffect(() => { if (customThemeIdFromPath) { // 自定义主题 - Bmob.Query('config') - .get(customThemeIdFromPath) - .then((res) => { - // @ts-ignore - const { content } = res; - try { - const customTheme = JSON.parse(content); - if (!customTheme.pure) { - setPureMode(false); - setThemes([...themes, customTheme]); - } - setCurTheme(customTheme); - } catch (e) { - console.log(e); + const storageTheme = localStorage.getItem(customThemeIdFromPath); + if (storageTheme) { + // 节省请求 + try { + const customTheme = JSON.parse(storageTheme); + if (!customTheme.pure) { + setPureMode(false); + setThemes([...themes, customTheme]); } - }) - .catch((e) => { - setCurTheme({ ...curTheme, title: CUSTOM_THEME_FAIL_TIP }); + setCurTheme(customTheme); + } catch (e) { console.log(e); - }); + } + } else { + Bmob.Query('config') + .get(customThemeIdFromPath) + .then((res) => { + // @ts-ignore + const { content } = res; + localStorage.setItem(customThemeIdFromPath, content); + try { + const customTheme = JSON.parse(content); + if (!customTheme.pure) { + setPureMode(false); + setThemes([...themes, customTheme]); + } + setCurTheme(customTheme); + } catch (e) { + console.log(e); + } + }) + .catch((e) => { + setCurTheme({ + ...curTheme, + title: CUSTOM_THEME_FAIL_TIP, + }); + console.log(e); + }); + } } else if (themeFromPath) { // 内置主题 setCurTheme(