feat: add theme-aware logo support via optional sourceDark configuration (#6866)

* Initial plan

* Initial exploration and setup

Co-authored-by: aonoa <32682251+aonoa@users.noreply.github.com>

* Add support for separate light and dark theme logos

Co-authored-by: aonoa <32682251+aonoa@users.noreply.github.com>

* Update documentation with dark theme logo configuration

Co-authored-by: aonoa <32682251+aonoa@users.noreply.github.com>

* feat: Add theme-aware logo support for authentication/login page

Co-authored-by: aonoa <32682251+aonoa@users.noreply.github.com>

* revert: .npmrc

Signed-off-by: aonoa <1991849113@qq.com>

---------

Signed-off-by: aonoa <1991849113@qq.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: aonoa <32682251+aonoa@users.noreply.github.com>
Co-authored-by: Li Kui <90845831+likui628@users.noreply.github.com>
Co-authored-by: aonoa <1991849113@qq.com>
This commit is contained in:
Copilot
2025-11-03 13:07:36 +08:00
committed by GitHub
parent f8a7a0a9a2
commit c7c39047de
12 changed files with 76 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
<script setup lang="ts">
import type { ToolbarType } from './types';
import { computed } from 'vue';
import { preferences, usePreferences } from '@vben/preferences';
import { Copyright } from '../basic/copyright';
@@ -11,6 +13,7 @@ import Toolbar from './toolbar.vue';
interface Props {
appName?: string;
logo?: string;
logoDark?: string;
pageTitle?: string;
pageDescription?: string;
sloganImage?: string;
@@ -20,10 +23,11 @@ interface Props {
clickLogo?: () => void;
}
withDefaults(defineProps<Props>(), {
const props = withDefaults(defineProps<Props>(), {
appName: '',
copyright: true,
logo: '',
logoDark: '',
pageDescription: '',
pageTitle: '',
sloganImage: '',
@@ -34,6 +38,18 @@ withDefaults(defineProps<Props>(), {
const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
usePreferences();
/**
* @zh_CN 根据主题选择合适的 logo 图标
*/
const logoSrc = computed(() => {
// 如果是暗色主题且提供了 logoDark则使用暗色主题的 logo
if (isDark.value && props.logoDark) {
return props.logoDark;
}
// 否则使用默认的 logo
return props.logo;
});
</script>
<template>
@@ -65,14 +81,21 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
<slot name="logo">
<!-- 头部 Logo 和应用名称 -->
<div
v-if="logo || appName"
v-if="logoSrc || appName"
class="absolute left-0 top-0 z-10 flex flex-1"
@click="clickLogo"
>
<div
class="text-foreground lg:text-foreground ml-4 mt-4 flex flex-1 items-center sm:left-6 sm:top-6"
>
<img v-if="logo" :alt="appName" :src="logo" class="mr-2" width="42" />
<img
v-if="logoSrc"
:key="logoSrc"
:alt="appName"
:src="logoSrc"
class="mr-2"
width="42"
/>
<p v-if="appName" class="m-0 text-xl font-medium">
{{ appName }}
</p>