useTheme.hook.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { computed, toRefs } from 'vue'
  2. import { darkTheme, GlobalThemeOverrides } from 'naive-ui'
  3. import { useDesignStore } from '@/store/modules/designStore/designStore'
  4. import { borderRadius } from '@/settings/designSetting'
  5. import { toLight } from '@/utils'
  6. /**
  7. * * 设置全局主题
  8. */
  9. export const useThemeOverridesHook = () => {
  10. const designStore = useDesignStore()
  11. const { getAppTheme } = toRefs(designStore)
  12. const darkTheme = computed(
  13. (): GlobalThemeOverrides => {
  14. // 通用
  15. const commonObj = {
  16. common: {
  17. primaryColor: getAppTheme.value,
  18. primaryColorHover: toLight(getAppTheme.value, 6),
  19. primaryColorPressed: toLight(getAppTheme.value, 6),
  20. primaryColorSuppl: getAppTheme.value,
  21. borderRadius
  22. }
  23. }
  24. // 亮色主题
  25. const lightObject = {
  26. common: {
  27. ...commonObj.common
  28. }
  29. }
  30. // 暗色主题
  31. const dartObject = {
  32. common: {
  33. ...commonObj.common
  34. },
  35. LoadingBar: {
  36. colorLoading: getAppTheme.value
  37. }
  38. }
  39. return designStore.getDarkTheme ? dartObject : lightObject
  40. }
  41. )
  42. return darkTheme
  43. }
  44. // 返回暗黑主题
  45. export const useDarkThemeHook = () => {
  46. const designStore = useDesignStore()
  47. return computed(() => (designStore.getDarkTheme ? darkTheme : undefined))
  48. }