From 417659c2c0ab1d2ac9196f246c5a7d5e7b732cd5 Mon Sep 17 00:00:00 2001 From: terwer Date: Mon, 22 Apr 2024 11:02:33 +0800 Subject: [PATCH] feat: adapt savor theme --- components/{default => }/setting/Basic.vue | 15 +++++++++++++++ components/{default => }/setting/ChangeLocal.vue | 0 components/{default => }/setting/Preference.vue | 0 composables/useStaticThemeMode.ts | 9 +++++---- locales/en_US.ts | 1 + locales/zh_CN.ts | 1 + pages/setting.vue | 6 +++--- 7 files changed, 25 insertions(+), 7 deletions(-) rename components/{default => }/setting/Basic.vue (91%) rename components/{default => }/setting/ChangeLocal.vue (100%) rename components/{default => }/setting/Preference.vue (100%) diff --git a/components/default/setting/Basic.vue b/components/setting/Basic.vue similarity index 91% rename from components/default/setting/Basic.vue rename to components/setting/Basic.vue index 198db44c..c8f3500e 100644 --- a/components/default/setting/Basic.vue +++ b/components/setting/Basic.vue @@ -53,6 +53,10 @@ const formData = reactive({ value: "Zhihu", label: "Zhihu", }, + { + value: "Savor", + label: "写未", + }, ], dark: [ { @@ -63,10 +67,20 @@ const formData = reactive({ value: "Zhihu", label: "Zhihu", }, + { + value: "Savor", + label: "写未", + }, ], }, lightTheme: setting?.theme?.lightTheme ?? "Zhihu", darkTheme: setting?.theme?.darkTheme ?? "Zhihu", + versionMap: { + midlight: "3.0.10", + daylight: "3.0.10", + Zhihu: "0.1.1", + Savor: "3.9.2", + } as any, }) // methods @@ -77,6 +91,7 @@ const onSubmit = async () => { setting.theme ||= {} setting.theme.lightTheme = formData.lightTheme setting.theme.darkTheme = formData.darkTheme + setting.theme.themeVersion = formData.versionMap[toRaw(setting.theme.lightTheme)] ?? "0.1.1" await updateSetting(setting) ElMessage.success(t("main.opt.success")) } catch (e) { diff --git a/components/default/setting/ChangeLocal.vue b/components/setting/ChangeLocal.vue similarity index 100% rename from components/default/setting/ChangeLocal.vue rename to components/setting/ChangeLocal.vue diff --git a/components/default/setting/Preference.vue b/components/setting/Preference.vue similarity index 100% rename from components/default/setting/Preference.vue rename to components/setting/Preference.vue diff --git a/composables/useStaticThemeMode.ts b/composables/useStaticThemeMode.ts index ce0b74a0..af701504 100644 --- a/composables/useStaticThemeMode.ts +++ b/composables/useStaticThemeMode.ts @@ -26,6 +26,7 @@ import { BrowserUtil } from "zhi-device" import { createAppLogger } from "~/common/appLogger" import { CONSTANTS } from "~/utils/constants" +import { useRoute } from "vue-router" // 创建日志记录器 const logger = createAppLogger("use-theme-mode") @@ -37,7 +38,7 @@ export const useStaticThemeMode = async () => { // 获取颜色模式和运行时配置 const color = useColorMode() // const env = useRuntimeConfig() - + const { query } = useRoute() const appBase = process.env.APP_BASE // computes @@ -64,9 +65,9 @@ export const useStaticThemeMode = async () => { const siyuanV = CONSTANTS.SIYUAN_VERSION const hljsV = CONSTANTS.HLJS_VERSION - const siyuanLightTheme = "Zhihu" as string - const siyuanDarkTheme = "Zhihu" as string - const siyuanThemeV = "0.1.1" + const siyuanLightTheme = (query.lightTheme ?? "Zhihu") as string + const siyuanDarkTheme = (query.darkTheme ?? "Zhihu") as string + const siyuanThemeV = (query.themeVersion ?? "0.1.1") as string const detectedMode = color.preference const isDarkMode = detectedMode === "dark" useHead({ diff --git a/locales/en_US.ts b/locales/en_US.ts index 265f3e1e..7de3cf11 100644 --- a/locales/en_US.ts +++ b/locales/en_US.ts @@ -72,6 +72,7 @@ export default { "siyuan.theme": "Theme", "siyuan.theme.light": "Light theme", "siyuan.theme.dark": "Dark theme", + "siyuan.theme.version": "Theme version", "siyuan.theme.select": "Select theme", "share.to.web": "Share to web", "share.to.web.before.tip": "Publish and share link to everyone", diff --git a/locales/zh_CN.ts b/locales/zh_CN.ts index 32636812..aa3ea5ed 100644 --- a/locales/zh_CN.ts +++ b/locales/zh_CN.ts @@ -32,6 +32,7 @@ export default { "theme.mode.choose": "切换模式", "theme.mode.dark": "暗黑模式", "theme.mode.light": "浅色模式", + "siyuan.theme.version": "主题版本", "setting.conf.export": "导出配置", "setting.conf.import": "导入配置", "setting.conf.clear": "清空配置", diff --git a/pages/setting.vue b/pages/setting.vue index 767262e5..28448803 100644 --- a/pages/setting.vue +++ b/pages/setting.vue @@ -38,13 +38,13 @@ definePageMeta({
- + - + - +