MaxKB/ui/src/stores/modules/theme.ts
wangdan-fit2cloud 65a65de03e
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run
feat: theme
2025-06-21 03:55:48 +08:00

41 lines
1.2 KiB
TypeScript

import { defineStore } from 'pinia'
import { cloneDeep } from 'lodash'
import { useElementPlusTheme } from 'use-element-plus-theme'
import ThemeApi from '@/api/system-settings/theme'
import type {Ref} from "vue";
export interface themeStateTypes {
themeInfo: any
}
const defalueColor = '#3370FF'
const useThemeStore = defineStore('theme', {
state: (): themeStateTypes => ({
themeInfo: null,
}),
actions: {
isDefaultTheme() {
return !this.themeInfo?.theme || this.themeInfo?.theme === defalueColor
},
setTheme(data?: any) {
const { changeTheme } = useElementPlusTheme(this.themeInfo?.theme || defalueColor)
changeTheme(defalueColor)
changeTheme(data?.['theme'])
this.themeInfo = cloneDeep(data)
},
async theme(loading?: Ref<boolean>) {
return await ThemeApi.getThemeInfo(loading).then((ok) => {
this.setTheme(ok.data)
// window.document.title = this.themeInfo['title'] || 'MaxKB'
// const link = document.querySelector('link[rel="icon"]') as any
// if (link) {
// link['href'] = this.themeInfo['icon'] || '/favicon.ico'
// }
})
},
},
})
export default useThemeStore