diff --git a/CHANGELOG.md b/CHANGELOG.md index 815b249493e821d14094a6234c32238fe7b5b217..7534851dc9cbed17b88bfff6966b656a6460b30a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ ## [Unreleased] +### Added + +- 自定义主题组件识别颜色主题插件,支持插件主题切换 + ## [0.7.41-alpha.31] - 2025-10-11 ### Added diff --git a/src/common/custom-theme/custom-theme.controller.ts b/src/common/custom-theme/custom-theme.controller.ts index de9acd18269212fd3192111db773ade313755be3..b289092a866cb8cbedb96c78838ea913526206be 100644 --- a/src/common/custom-theme/custom-theme.controller.ts +++ b/src/common/custom-theme/custom-theme.controller.ts @@ -1,5 +1,6 @@ import { clone } from 'ramda'; import { reactive } from 'vue'; +import { useNamespace } from '@ibiz-template/vue3-util'; import { predefineThemeVars } from './custom-theme-model'; /** @@ -100,6 +101,42 @@ export class CustomThemeController { this.model.forEach((item: IData) => { this.initModelMapping(item); }); + const pluginTheme = ibiz.util.theme.pluginTheme; + pluginTheme.forEach(item => { + const ns = useNamespace('custom-theme'); + const color = this.getRootCssVar( + ns.cssVarName('color-primary'), + item.themeTag!, + ); + this.predefineType.push({ + codeName: item.themeTag, + label: item.themeTag, + color, + isCustom: true, + }); + }); + } + + /** + * @description 获取根节点样式变量 + * @protected + * @param {string} name + * @param {string} themeTag + * @returns {*} {(string | number)} + * @memberof CustomThemeController + */ + protected getRootCssVar(name: string, themeTag: string): string | number { + const root = document.documentElement; + if (root.classList.contains(themeTag)) { + return this.getCssVar(name); + } + const className = root.className; + // 先改变根节点样式名获取变量后再还原 + root.className = themeTag; + const color = this.getCssVar(name); + // 还原 + root.className = className; + return color; } /** diff --git a/src/common/custom-theme/custom-theme.tsx b/src/common/custom-theme/custom-theme.tsx index adcd889be68381f17ab873fea28fc78dbe31f5ac..9e1c30dd64a88469d0d403ab4183cbe6edafafc0 100644 --- a/src/common/custom-theme/custom-theme.tsx +++ b/src/common/custom-theme/custom-theme.tsx @@ -255,6 +255,13 @@ export const CustomTheme = defineComponent({ vue.$forceUpdate(); }; + const getVarLabel = (item: IData) => { + if (item.labelLang) { + return ibiz.i18n.t(`control.common.customTheme.${item.labelLang}`); + } + return item.label; + }; + // 预置颜色 const predefineColors = ref([ 'rgb(241, 4, 4)', @@ -332,9 +339,7 @@ export const CustomTheme = defineComponent({ } return (
-
- {ibiz.i18n.t(`control.common.customTheme.${item.labelLang}`)} -
+
{getVarLabel(item)}
{item.vars.map((data: IData) => { let content = renderColorPicker(data); @@ -351,9 +356,7 @@ export const CustomTheme = defineComponent({ ), )} > - {ibiz.i18n.t( - `control.common.customTheme.${data.labelLang}`, - )} + {getVarLabel(item)} {content}
@@ -431,11 +434,7 @@ export const CustomTheme = defineComponent({ return ( { handleThemeChange(item.codeName); }} @@ -476,12 +475,7 @@ export const CustomTheme = defineComponent({ {c.model.map((item: IData, index: number) => { return ( - + {renderItem(item)} );