diff --git a/locales/zh-chs.yml b/locales/zh-chs.yml index f84c756..17b6e6d 100644 --- a/locales/zh-chs.yml +++ b/locales/zh-chs.yml @@ -107,7 +107,7 @@ layout: warningColor: 警告色 errorColor: 错误色 infoColor: 信息色 - headerTheme: 顶栏主题 + headerDark: 顶栏深色 sidebarDark: 侧边栏深色 menuDrag: 侧边菜单拖拽 diff --git a/src/auto-imports.d.ts b/src/auto-imports.d.ts index 8322aba..abd178d 100644 --- a/src/auto-imports.d.ts +++ b/src/auto-imports.d.ts @@ -26,6 +26,7 @@ declare global { const createApp: typeof import('vue')['createApp'] const createEventHook: typeof import('@vueuse/core')['createEventHook'] const createGlobalState: typeof import('@vueuse/core')['createGlobalState'] + const createGridLayoutListen: typeof import('./composables/web/theme')['createGridLayoutListen'] const createInjectionState: typeof import('@vueuse/core')['createInjectionState'] const createMediaPrefersColorSchemeListen: typeof import('./composables/web/theme')['createMediaPrefersColorSchemeListen'] const createReactiveFn: typeof import('@vueuse/core')['createReactiveFn'] @@ -382,6 +383,7 @@ declare module 'vue' { readonly createApp: UnwrapRef readonly createEventHook: UnwrapRef readonly createGlobalState: UnwrapRef + readonly createGridLayoutListen: UnwrapRef readonly createInjectionState: UnwrapRef readonly createMediaPrefersColorSchemeListen: UnwrapRef readonly createReactiveFn: UnwrapRef @@ -721,6 +723,7 @@ declare module '@vue/runtime-core' { readonly createApp: UnwrapRef readonly createEventHook: UnwrapRef readonly createGlobalState: UnwrapRef + readonly createGridLayoutListen: UnwrapRef readonly createInjectionState: UnwrapRef readonly createMediaPrefersColorSchemeListen: UnwrapRef readonly createReactiveFn: UnwrapRef diff --git a/src/composables/setting/header-setting.ts b/src/composables/setting/header-setting.ts index a9b420c..fd130a7 100644 --- a/src/composables/setting/header-setting.ts +++ b/src/composables/setting/header-setting.ts @@ -18,7 +18,6 @@ export function useHeaderSetting() { const getHeaderTheme = computed(() => appConfig.header.value.theme) const getShowHeader = computed(() => appConfig.header.value.show) const getFixed = computed(() => appConfig.header.value.fixed) - const getHeaderBgColor = computed(() => appConfig.header.value.bgColor) const getShowSearch = computed(() => appConfig.header.value.showSearch) const getUseLockPage = computed(() => false) const getShowFullScreen = computed(() => appConfig.header.value.showFullScreen) @@ -80,7 +79,6 @@ export function useHeaderSetting() { getShowFullHeaderRef, getShowInsetHeaderRef, getUnFixedAndFull, - getHeaderBgColor, getShowLocalePicker, } } diff --git a/src/composables/web/theme.ts b/src/composables/web/theme.ts index 2bf5adc..1780da2 100644 --- a/src/composables/web/theme.ts +++ b/src/composables/web/theme.ts @@ -1,25 +1,25 @@ import { storeToRefs } from 'pinia' import { ThemeEnum } from '~/constants' import type { MaybeElementRef } from '~/utils' -import { darken, generateColors, lighten, pickTextColorBasedOnBgColor, setCssVar, toggleClass } from '~/utils' +import { generateColors, setCssVar, toggleClass } from '~/utils' const HEADER_HEIGHT = '--header-height' -const HEADER_BG_COLOR_VAR = '--header-background-color' -const HEADER_TEXT_COLOR_VAR = '--header-text-color' -const HEADER_ACTION_HOVER_BG_COLOR_VAR = '--header-action-hover-bg-color' +// const HEADER_BG_COLOR_VAR = '--header-background-color' +// const HEADER_TEXT_COLOR_VAR = '--header-text-color' +// const HEADER_ACTION_HOVER_BG_COLOR_VAR = '--header-action-hover-bg-color' const ASIDE_WIDTH = '--aside-width' -const ASIDE_DARK_BG_COLOR = '--aside-background-color' -const ASIDE_TEXT_COLOR_VAR = '--aside-text-color' +// const ASIDE_DARK_BG_COLOR = '--aside-background-color' +// const ASIDE_TEXT_COLOR_VAR = '--aside-text-color' -const TRIGGER_BG_COLOR_VAR = '--trigger-background-color' +// const TRIGGER_BG_COLOR_VAR = '--trigger-background-color' const TAB_BAR_HEIGHT = '--tab-bar-height' const FOOTER_HEIGHT = '--footer-height' -const LIGHT_TEXT_COLOR = 'rgba(0,0,0,.85)' -const DARK_TEXT_COLOR = '#fff' +// const LIGHT_TEXT_COLOR = 'rgba(0,0,0,.85)' +// const DARK_TEXT_COLOR = '#fff' export function createMediaPrefersColorSchemeListen() { const { setAppConfig } = useAppConfig() @@ -107,81 +107,65 @@ export function createGridLayoutListen(el: MaybeElementRef | null) { export function createThemeColorListen() { const { - sidebar, - header, grayMode, colorWeak, - setAppConfig, } = useAppConfig() - const headerBgColor = useCssVar(HEADER_BG_COLOR_VAR, null, { - initialValue: `${unref(header).bgColor}px`, - }) - - const headerTextColor = useCssVar( - HEADER_TEXT_COLOR_VAR, - null, - { - initialValue: LIGHT_TEXT_COLOR, - }, - ) - const headerActionHoverBgColor = useCssVar( - HEADER_ACTION_HOVER_BG_COLOR_VAR, - null, - ) - - const sidebarBgColor = useCssVar( - ASIDE_DARK_BG_COLOR, - null, - { - initialValue: `${unref(sidebar).bgColor}px`, - }, - ) - - const asideTextColor = useCssVar( - ASIDE_TEXT_COLOR_VAR, - null, - { - initialValue: LIGHT_TEXT_COLOR, - }, - ) - const triggerBackgroundColor = useCssVar( - TRIGGER_BG_COLOR_VAR, - null, - ) + // const headerTextColor = useCssVar( + // HEADER_TEXT_COLOR_VAR, + // null, + // { + // initialValue: LIGHT_TEXT_COLOR, + // }, + // ) + // const headerActionHoverBgColor = useCssVar( + // HEADER_ACTION_HOVER_BG_COLOR_VAR, + // null, + // ) + + // const asideTextColor = useCssVar( + // ASIDE_TEXT_COLOR_VAR, + // null, + // { + // initialValue: LIGHT_TEXT_COLOR, + // }, + // ) + // const triggerBackgroundColor = useCssVar( + // TRIGGER_BG_COLOR_VAR, + // null, + // ) watchEffect(() => { - headerBgColor.value = unref(header).bgColor - headerTextColor.value = pickTextColorBasedOnBgColor( - unref(header).bgColor, - LIGHT_TEXT_COLOR, - DARK_TEXT_COLOR, - ) - - if (['#fff', '#ffffff'].includes(unref(header).bgColor.toLowerCase())) { - headerActionHoverBgColor.value = darken(unref(header).bgColor, 6) - setAppConfig({ header: { theme: ThemeEnum.LIGHT } }) - } - else { - headerActionHoverBgColor.value = lighten(unref(header).bgColor, 6) - setAppConfig({ header: { theme: ThemeEnum.DARK } }) - } + // headerTextColor.value = pickTextColorBasedOnBgColor( + // unref(header).bgColor, + // LIGHT_TEXT_COLOR, + // DARK_TEXT_COLOR, + // ) - sidebarBgColor.value = unref(sidebar).bgColor - asideTextColor.value = pickTextColorBasedOnBgColor( - unref(sidebar).bgColor, - LIGHT_TEXT_COLOR, - DARK_TEXT_COLOR, - ) + // if (['#fff', '#ffffff'].includes(unref(header).bgColor.toLowerCase())) { + // headerActionHoverBgColor.value = darken(unref(header).bgColor, 6) + // setAppConfig({ header: { theme: ThemeEnum.LIGHT } }) + // } + // else { + // headerActionHoverBgColor.value = lighten(unref(header).bgColor, 6) + // setAppConfig({ header: { theme: ThemeEnum.DARK } }) + // } + + // sidebarBgColor.value = unref(sidebar).bgColor + // asideTextColor.value = pickTextColorBasedOnBgColor( + // unref(sidebar).bgColor, + // LIGHT_TEXT_COLOR, + // DARK_TEXT_COLOR, + // ) - if (['#fff', '#ffffff'].includes(unref(sidebar).bgColor.toLowerCase())) { - triggerBackgroundColor.value = darken(unref(sidebar).bgColor, 6) - setAppConfig({ sidebar: { theme: ThemeEnum.LIGHT } }) - } - else { - triggerBackgroundColor.value = lighten(unref(sidebar).bgColor, 6) - setAppConfig({ sidebar: { theme: ThemeEnum.DARK } }) - } + // if (['#fff', '#ffffff'].includes(unref(sidebar).bgColor.toLowerCase())) { + // triggerBackgroundColor.value = darken(unref(sidebar).bgColor, 6) + // setAppConfig({ sidebar: { theme: ThemeEnum.LIGHT } }) + // } + // else { + // triggerBackgroundColor.value = lighten(unref(sidebar).bgColor, 6) + // setAppConfig({ sidebar: { theme: ThemeEnum.DARK } }) + // } toggleGrayMode(unref(grayMode)) toggleColorWeak(unref(colorWeak)) diff --git a/src/constants/design.ts b/src/constants/design.ts index f4b94d0..a5fb22e 100644 --- a/src/constants/design.ts +++ b/src/constants/design.ts @@ -1,3 +1,4 @@ +// primary preset color export const APP_PRESET_COLOR_LIST: string[] = [ '#0960bd', '#0084f4', @@ -10,49 +11,6 @@ export const APP_PRESET_COLOR_LIST: string[] = [ '#ff9800', ] -// header preset color -export const HEADER_PRESET_BG_COLOR_LIST: string[] = [ - '#ffffff', - '#151515', - '#009688', - '#5172DC', - '#018ffb', - '#409eff', - '#e74c3c', - '#24292e', - '#394664', - '#001529', - '#383f45', -] - -// sider preset color -export const SIDE_BAR_BG_COLOR_LIST: string[] = [ - '#001529', - '#212121', - '#273352', - '#ffffff', - '#191b24', - '#191a23', - '#304156', - '#001628', - '#28333E', - '#344058', - '#383f45', -] - -export enum ThemeChangeEnum { - THEME_CHANGE, - - THEME_PRIMARY_COLOR_CHANGE, - THEME_INFO_COLOR_CHANGE, - THEME_SUCCESS_COLOR_CHANGE, - THEME_WARNING_COLOR_CHANGE, - THEME_ERROR_COLOR_CHANGE, - - THEME_HEADER_BG_COLOR_CHANGE, - THEME_SIDEBAR_BG_COLOR_CHANGE, -} - // 设置事件Enum export enum HandlerSettingEnum { CHANGE_LAYOUT, @@ -101,3 +59,16 @@ export enum HandlerSettingEnum { OPEN_PAGE_LOADING, OPEN_ROUTE_TRANSITION, } + +export enum ThemeChangeEnum { + THEME_CHANGE, + + THEME_PRIMARY_COLOR_CHANGE, + THEME_INFO_COLOR_CHANGE, + THEME_SUCCESS_COLOR_CHANGE, + THEME_WARNING_COLOR_CHANGE, + THEME_ERROR_COLOR_CHANGE, + + THEME_HEADER_BG_COLOR_CHANGE, + THEME_SIDEBAR_BG_COLOR_CHANGE, +} diff --git a/src/layouts/nlayout/components/header.vue b/src/layouts/nlayout/components/header.vue index 94cf2e8..9452574 100644 --- a/src/layouts/nlayout/components/header.vue +++ b/src/layouts/nlayout/components/header.vue @@ -14,6 +14,8 @@ const { menu, } = useAppConfig() +const { isHeaderDark } = useAppTheme() + const { getShowHeader, getShowFullScreen, @@ -62,57 +64,59 @@ const { isFullscreen } = useFullscreen()