This commit is contained in:
TimSpan 2025-07-07 10:04:29 +08:00
parent e2579fcb99
commit ede170795f
2 changed files with 16 additions and 18 deletions

View File

@ -26,12 +26,10 @@
<script setup lang="ts"> <script setup lang="ts">
import IcBaselineKeyboardArrowDown from "@/components/icon/src/icons/IcBaselineKeyboardArrowDown.vue"; import IcBaselineKeyboardArrowDown from "@/components/icon/src/icons/IcBaselineKeyboardArrowDown.vue";
import CarbonSubtractAlt from "@/components/icon/src/icons/CarbonSubtractAlt.vue"; import CarbonSubtractAlt from "@/components/icon/src/icons/CarbonSubtractAlt.vue";
import CodiconCloseAll from "@/components/icon/src/icons/CodiconCloseAll.vue"; import CodiconCloseAll from "@/components/icon/src/icons/CodiconCloseAll.vue";
import IconamoonSynchronize from "@/components/icon/src/icons/IconamoonSynchronize.vue"; import IconamoonSynchronize from "@/components/icon/src/icons/IconamoonSynchronize.vue";
import MaterialSymbolsCancelOutline from "@/components/icon/src/icons/MaterialSymbolsCancelOutline.vue"; import MaterialSymbolsCancelOutline from "@/components/icon/src/icons/MaterialSymbolsCancelOutline.vue";
import { INDEX_ROUTER } from "@/config/constant"; import { INDEX_ROUTER } from "@/config/constant";
import { type TabsMenuProps, useTabsStore } from "@/stores/tabsStore"; import { type TabsMenuProps, useTabsStore } from "@/stores/tabsStore";
import { message } from "@/utils"; import { message } from "@/utils";
@ -39,12 +37,10 @@
import { computed, inject, watch } from "vue"; import { computed, inject, watch } from "vue";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { TabsPro } from "@/components"; import { TabsPro } from "@/components";
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const tabStore = useTabsStore(); const tabStore = useTabsStore();
const { tabList } = storeToRefs(useTabsStore()); const { tabList } = storeToRefs(useTabsStore());
const ts = computed(() => const ts = computed(() =>
tabList.value.map((e) => ({ tabList.value.map((e) => ({
value: e.path, value: e.path,
@ -53,9 +49,7 @@
closable: e.closable, closable: e.closable,
})) }))
); );
const refreshCurrentPage = inject<Function>("refreshCurrentPage"); const refreshCurrentPage = inject<Function>("refreshCurrentPage");
//退/ //退/
watch( watch(
() => route.fullPath, () => route.fullPath,

View File

@ -1,4 +1,4 @@
import { darkTheme, type GlobalTheme } from "naive-ui"; import { darkTheme, lightTheme, type GlobalTheme } from "naive-ui";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
export const useSettingsStore = defineStore( export const useSettingsStore = defineStore(
@ -6,19 +6,23 @@ export const useSettingsStore = defineStore(
() => { () => {
const isDark = ref(false); const isDark = ref(false);
watch(isDark, (newVal) => { watch(
isDark,
(newVal) => {
// 控制根元素 class // 控制根元素 class
if (newVal) { if (newVal) {
document.documentElement.classList.add('dark'); document.documentElement.classList.add("dark");
document.documentElement.setAttribute('data-theme', 'dark'); document.documentElement.setAttribute("data-theme", "dark");
} else { } else {
document.documentElement.classList.remove('dark'); document.documentElement.classList.remove("dark");
document.documentElement.setAttribute('data-theme', 'light'); document.documentElement.setAttribute("data-theme", "light");
} }
}, { immediate: true }); // 立即执行一次初始化 },
{ immediate: true }
); // 立即执行一次初始化
const theme = computed<GlobalTheme | null>(() => const theme = computed<GlobalTheme | null>(() =>
isDark.value ? darkTheme : null isDark.value ? darkTheme : lightTheme
); );
function toggleTheme() { function toggleTheme() {