mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-01-30 18:56:23 +08:00
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import type { GlobalThemeOverrides } from 'naive-ui'
|
|
import { computed, watch } from 'vue'
|
|
import { darkTheme, useOsTheme } from 'naive-ui'
|
|
import { useAppStore } from '@/store'
|
|
|
|
export function useTheme() {
|
|
const appStore = useAppStore()
|
|
|
|
const OsTheme = useOsTheme()
|
|
|
|
const isDark = computed(() => {
|
|
if (appStore.theme === 'auto')
|
|
return OsTheme.value === 'dark'
|
|
else
|
|
return appStore.theme === 'dark'
|
|
})
|
|
|
|
const theme = computed(() => {
|
|
return isDark.value ? darkTheme : undefined
|
|
})
|
|
|
|
const themeOverrides = computed<GlobalThemeOverrides>(() => {
|
|
if (isDark.value) {
|
|
return {
|
|
common: {},
|
|
}
|
|
}
|
|
return {
|
|
common: {
|
|
primaryColor: '#EC5E42',
|
|
primaryColorHover: '#CF523A',
|
|
primaryColorPressed: '#963C2A',
|
|
},
|
|
}
|
|
})
|
|
|
|
watch(
|
|
() => isDark.value,
|
|
(dark) => {
|
|
if (dark)
|
|
document.documentElement.classList.add('dark')
|
|
else
|
|
document.documentElement.classList.remove('dark')
|
|
},
|
|
{ immediate: true },
|
|
)
|
|
|
|
return { theme, themeOverrides }
|
|
}
|