罗广辉
2026-06-18 44dd9c4eb8a2489c63a5eb53fd4254bbb3510e95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * @Author       : yuan
 * @Date         : 2025-09-28 09:31:16
 * @LastEditors  : yuan
 * @LastEditTime : 2025-09-28 09:48:36
 * @FilePath     : \src\hooks\use-theme\index.js
 * @Description  : 
 * Copyright 2025 OBKoro1, All Rights Reserved. 
 * 2025-09-28 09:31:16
 */
import { computed } from "vue"
import { useAppStore } from "@/store"
 
/**
 * 主题Hook
 */
export default function useTheme () {
  const appStore = useAppStore()
 
  // 当前主题模式
  const theme = computed(() => appStore.getTheme)
 
  // 是否为深色主题
  const isDark = computed(() => appStore.getTheme === "dark")
 
  /**
   * 设置主题
   */
  const setTheme = mode => {
    appStore.setTheme(mode)
  }
 
  /**
   * 切换主题
   */
  const toggleTheme = () => {
    const newTheme = theme.value === "light" ? "dark" : "light"
    appStore.setTheme(newTheme)
  }
 
  return {
    theme,
    isDark,
    setTheme,
    toggleTheme
  }
}