feat(theme): implement dynamic theme color change

- Add functionality to change the main theme color dynamically
- Update CSS to use a custom property for the main theme color
- Modify JavaScript to set the main theme color based on user preference Adjust form select styles to match the new theme color
This commit is contained in:
wolfcode
2025-04-21 18:03:39 +08:00
parent 9a0ff912b5
commit 253379f0c6
3 changed files with 37 additions and 1 deletions

View File

@@ -4,6 +4,10 @@
@import url("../css/themes/index.css");
@import url("../css/iconfont.css");
:root {
--ea8-theme-main-color: #16b777;
}
html,
body {
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
@@ -304,9 +308,17 @@ table样式
}
.layui-form-select dl {
border: 1px #16b777 solid;
border: 1px var(--ea8-theme-main-color) solid;
border-top: none;
z-index: 99999;
padding: 0;
border-radius: 0;
}
.layui-form-select dl dd.layui-this {
background-color: var(--ea8-theme-main-color);
border-top: none;
color: #ffffff;
}
.form-search .layui-form-select dl {
@@ -517,4 +529,8 @@ table样式
.wangEditor_div {
z-index: 99999;
border: 1px solid var(--w-e-textarea-slight-border-color);
}
.layui-input:focus, .layui-textarea:focus {
border-color: var(--ea8-theme-main-color) !important;
}

View File

@@ -8,6 +8,7 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect", "lazyload"], function
iframe.contentWindow.onInitElemStyle();
}
});
miniTheme.changeThemeMainColor();
};
window.onInitElemStyle();

View File

@@ -295,6 +295,24 @@ define(["jquery"], function ($) {
}
miniTheme.buildBodyElemStyle(elemStyleName);
},
changeThemeMainColor() {
let bgcolorId = localStorage.getItem('layuiminiBgColorId');
if (bgcolorId === null || bgcolorId === undefined || bgcolorId === '') return false;
let bgcolorData = miniTheme.config(bgcolorId);
let mainColor = bgcolorData.headerRightBg
if (bgcolorId == 0) mainColor = '#16b777';
const bgColor = window.getComputedStyle(document.documentElement).getPropertyValue('--ea8-theme-main-color');
document.documentElement.style.setProperty('--ea8-theme-main-color', mainColor);
const iframes = document.getElementsByTagName('iframe');
if (iframes.length === 0) return false;
$.each(iframes, (i, iframe) => {
if (iframe === '' || iframe === undefined) return false;
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
iframeDocument.documentElement.style.setProperty('--ea8-theme-main-color', mainColor);
})
},
/**
* 构建主题样式
* @param bgcolorId
@@ -555,6 +573,7 @@ define(["jquery"], function ($) {
bgColorDefault: bgcolorId,
listen: false,
});
miniTheme.changeThemeMainColor()
});
$('body').on('click', '[data-select-style]', function () {
var elemStyleName = $(this).attr('data-select-style');