diff --git a/apps/antd-view/package.json b/apps/antd-view/package.json index 9e58fb5e..a2c26848 100644 --- a/apps/antd-view/package.json +++ b/apps/antd-view/package.json @@ -35,6 +35,7 @@ "@vben/styles": "workspace:*", "@vben/types": "workspace:*", "@vben/utils": "workspace:*", + "@vueuse/core": "^10.9.0", "ant-design-vue": "^4.2.1", "axios": "^1.7.1", "dayjs": "^1.11.11", diff --git a/apps/antd-view/src/router/guard/index.ts b/apps/antd-view/src/router/guard/index.ts index 77112418..3c05d11e 100644 --- a/apps/antd-view/src/router/guard/index.ts +++ b/apps/antd-view/src/router/guard/index.ts @@ -1,7 +1,9 @@ import type { Router } from 'vue-router'; +import { $t } from '@vben/locales'; import { preference } from '@vben/preference'; import { startProgress, stopProgress } from '@vben/utils'; +import { useTitle } from '@vueuse/core'; import { configAccessGuard } from './access'; @@ -26,6 +28,12 @@ function configCommonGuard(router: Router) { if (preference.pageProgress) { stopProgress(); } + + // 动态修改标题 + if (preference.dynamicTitle) { + const { title } = to.meta; + useTitle(`${$t(title)} - ${preference.appName}`); + } }); } diff --git a/apps/antd-view/vite.config.mts b/apps/antd-view/vite.config.mts index c0632051..783296bb 100644 --- a/apps/antd-view/vite.config.mts +++ b/apps/antd-view/vite.config.mts @@ -18,7 +18,7 @@ export default defineConfig({ { name: 'vue-demi' }, ], }, - visualizer: true, + visualizer: false, }, vite: { server: { diff --git a/packages/@vben-core/shared/design-tokens/src/dark/index.scss b/packages/@vben-core/shared/design-tokens/src/dark/index.scss index b5e8eca2..958afe0f 100644 --- a/packages/@vben-core/shared/design-tokens/src/dark/index.scss +++ b/packages/@vben-core/shared/design-tokens/src/dark/index.scss @@ -1,4 +1,4 @@ -.dark { +:root.dark { /* 基础背景颜色颜色 */ /* --color-background: 240 6% 18%; */ diff --git a/packages/@vben-core/shared/typings/src/preference.ts b/packages/@vben-core/shared/typings/src/preference.ts index 95a63b4c..bc821cc2 100644 --- a/packages/@vben-core/shared/typings/src/preference.ts +++ b/packages/@vben-core/shared/typings/src/preference.ts @@ -55,6 +55,8 @@ interface Preference { copyright: string; /** 应用默认头像 */ defaultAvatar: string; + /** 开启动态标题 */ + dynamicTitle: boolean; /** 页脚是否固定 */ footerFixed: boolean; /** 页脚是否可见 */ diff --git a/packages/@vben-core/shared/typings/src/tools.ts b/packages/@vben-core/shared/typings/src/tools.ts index 904c7136..faae162d 100644 --- a/packages/@vben-core/shared/typings/src/tools.ts +++ b/packages/@vben-core/shared/typings/src/tools.ts @@ -1,7 +1,7 @@ import { type ComputedRef, type MaybeRef } from 'vue'; /** - * 深度部分类型 + * 深层递归所有属性为可选 */ type DeepPartial = T extends object ? { @@ -9,6 +9,13 @@ type DeepPartial = T extends object } : T; +/** + * 深层递归所有属性为只读 + */ +type DeepReadonly = { + readonly [P in keyof T]: T[P] extends object ? DeepReadonly : T[P]; +}; + /** * 任意类型的异步函数 */ @@ -78,6 +85,7 @@ export { type AnyNormalFunction, type AnyPromiseFunction, type DeepPartial, + type DeepReadonly, type IntervalHandle, type MaybeComputedRef, type MaybeReadonlyRef, diff --git a/packages/@vben-core/uikit/shadcn-ui/src/components/logo/logo.vue b/packages/@vben-core/uikit/shadcn-ui/src/components/logo/logo.vue index af23b48f..70675a14 100644 --- a/packages/@vben-core/uikit/shadcn-ui/src/components/logo/logo.vue +++ b/packages/@vben-core/uikit/shadcn-ui/src/components/logo/logo.vue @@ -69,6 +69,7 @@ const logoClass = computed(() => { /> {{ text }} + diff --git a/packages/business/common-ui/package.json b/packages/business/common-ui/package.json index 9ffd4a6e..fc49bc8e 100644 --- a/packages/business/common-ui/package.json +++ b/packages/business/common-ui/package.json @@ -42,6 +42,9 @@ } } }, + "peerDependencies": { + "@vben-core/design": "workspace:*" + }, "dependencies": { "@vben-core/design": "workspace:*", "@vben-core/iconify": "workspace:*", diff --git a/packages/business/common-ui/src/preference/blocks/general/general.vue b/packages/business/common-ui/src/preference/blocks/general/general.vue index 7334bfdc..7721bd31 100644 --- a/packages/business/common-ui/src/preference/blocks/general/general.vue +++ b/packages/business/common-ui/src/preference/blocks/general/general.vue @@ -5,12 +5,14 @@ import { $t } from '@vben/locales'; import { staticPreference } from '@vben/preference'; import SelectItem from '../select-item.vue'; +import SwitchItem from '../switch-item.vue'; defineOptions({ name: 'PreferenceGeneralConfig', }); const locale = defineModel('locale'); +const dynamicTitle = defineModel('dynamicTitle'); const localeItems: SelectListItem[] = staticPreference.supportLanguages.map( (item) => ({ @@ -24,4 +26,7 @@ const localeItems: SelectListItem[] = staticPreference.supportLanguages.map( {{ $t('preference.language') }} + + {{ $t('preference.dynamic-title') }} + diff --git a/packages/business/common-ui/src/preference/preference-widget.vue b/packages/business/common-ui/src/preference/preference-widget.vue index 5a06dde2..ef944acb 100644 --- a/packages/business/common-ui/src/preference/preference-widget.vue +++ b/packages/business/common-ui/src/preference/preference-widget.vue @@ -46,6 +46,7 @@ function updateLocale(value: string) { :footer-fixed="preference.footerFixed" :header-mode="preference.headerMode" :theme="preference.theme" + :dynamic-title="preference.dynamicTitle" :breadcrumb-hide-only-one="preference.breadcrumbHideOnlyOne" :page-transition="preference.pageTransition" :page-progress="preference.pageProgress" @@ -55,6 +56,7 @@ function updateLocale(value: string) { :side-collapse-show-title="preference.sideCollapseShowTitle" :page-transition-enable="preference.pageTransitionEnable" @update:navigation-style="(value) => handleUpdate('navigationStyle', value)" + @update:dynamic-title="(value) => handleUpdate('dynamicTitle', value)" @update:tabs-icon="(value) => handleUpdate('tabsIcon', value)" @update:side-collapse="(value) => handleUpdate('sideCollapse', value)" @update:locale="updateLocale" diff --git a/packages/business/common-ui/src/preference/preference.vue b/packages/business/common-ui/src/preference/preference.vue index e750c2d1..9a4e348e 100644 --- a/packages/business/common-ui/src/preference/preference.vue +++ b/packages/business/common-ui/src/preference/preference.vue @@ -40,6 +40,7 @@ withDefaults(defineProps<{ colorPrimaryPresets: string[] }>(), { const theme = defineModel('theme'); const locale = defineModel('locale'); +const dynamicTitle = defineModel('dynamicTitle'); const semiDarkMenu = defineModel('semiDarkMenu'); const breadcrumbVisible = defineModel('breadcrumbVisible'); const breadcrumbIcon = defineModel('breadcrumbIcon'); @@ -210,7 +211,10 @@ function handleReset() {