|
@@ -4,7 +4,7 @@ const version = require('element-ui/package.json').version // element-ui version
|
|
|
const ORIGINAL_THEME = '#409EFF' // default color
|
|
|
|
|
|
let chalk = ''
|
|
|
-let theme = ''
|
|
|
+// let theme = ''
|
|
|
|
|
|
// themeList: [{
|
|
|
// selected: true,
|
|
@@ -48,58 +48,73 @@ let theme = ''
|
|
|
// style: 'background-color: #722ed1'
|
|
|
// }],
|
|
|
|
|
|
-export const setTheme = async (val, isLoading) => { // 是否显示加载样式
|
|
|
- const oldVal = ORIGINAL_THEME
|
|
|
- if (typeof val !== 'string') return
|
|
|
- const themeCluster = getThemeCluster(val.replace('#', ''))
|
|
|
- const originalCluster = getThemeCluster(oldVal.replace('#', ''))
|
|
|
|
|
|
- if(isLoading) {
|
|
|
- showFullScreenLoading()
|
|
|
- }
|
|
|
+// 设置主题色
|
|
|
+export const setTheme = async (params) => { // 是否显示加载样式
|
|
|
+ const { themeColor, theme, isLoading } = params
|
|
|
+ if(themeColor) {
|
|
|
+ const oldVal = ORIGINAL_THEME
|
|
|
+ if (typeof themeColor !== 'string') return
|
|
|
+ const themeCluster = getThemeCluster(themeColor.replace('#', ''))
|
|
|
+ const originalCluster = getThemeCluster(oldVal.replace('#', ''))
|
|
|
|
|
|
- const getHandler = (variable, id) => {
|
|
|
- return () => {
|
|
|
- const originalCluster = getThemeCluster(ORIGINAL_THEME.replace('#', ''))
|
|
|
- const newStyle = updateStyle(chalk, originalCluster, themeCluster)
|
|
|
+ if(isLoading) {
|
|
|
+ showFullScreenLoading()
|
|
|
+ }
|
|
|
|
|
|
- let styleTag = document.getElementById(id)
|
|
|
- if (!styleTag) {
|
|
|
- styleTag = document.createElement('style')
|
|
|
- styleTag.setAttribute('id', id)
|
|
|
- document.head.appendChild(styleTag)
|
|
|
+ const getHandler = (variable, id) => {
|
|
|
+ return () => {
|
|
|
+ const originalCluster = getThemeCluster(ORIGINAL_THEME.replace('#', ''))
|
|
|
+ const newStyle = updateStyle(chalk, originalCluster, themeCluster)
|
|
|
+
|
|
|
+ let styleTag = document.getElementById(id)
|
|
|
+ if (!styleTag) {
|
|
|
+ styleTag = document.createElement('style')
|
|
|
+ styleTag.setAttribute('id', id)
|
|
|
+ document.head.appendChild(styleTag)
|
|
|
+ }
|
|
|
+ styleTag.innerText = newStyle
|
|
|
}
|
|
|
- styleTag.innerText = newStyle
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (!chalk) {
|
|
|
- const url = `https://unpkg.com/element-ui@${version}/lib/theme-chalk/index.css`
|
|
|
- await getCSSString(url, 'chalk')
|
|
|
- }
|
|
|
+ if (!chalk) {
|
|
|
+ const url = `https://unpkg.com/element-ui@${version}/lib/theme-chalk/index.css`
|
|
|
+ await getCSSString(url, 'chalk')
|
|
|
+ }
|
|
|
|
|
|
- const chalkHandler = getHandler('chalk', 'chalk-style')
|
|
|
+ const chalkHandler = getHandler('chalk', 'chalk-style')
|
|
|
|
|
|
- chalkHandler()
|
|
|
+ chalkHandler()
|
|
|
|
|
|
- const styles = [].slice.call(document.querySelectorAll('style'))
|
|
|
- .filter(style => {
|
|
|
- const text = style.innerText
|
|
|
- return new RegExp(oldVal, 'i').test(text) && !/Chalk Variables/.test(text)
|
|
|
+ const styles = [].slice.call(document.querySelectorAll('style'))
|
|
|
+ .filter(style => {
|
|
|
+ const text = style.innerText
|
|
|
+ return new RegExp(oldVal, 'i').test(text) && !/Chalk Variables/.test(text)
|
|
|
+ })
|
|
|
+ styles.forEach(style => {
|
|
|
+ const { innerText } = style
|
|
|
+ if (typeof innerText !== 'string') return
|
|
|
+ style.innerText = updateStyle(innerText, originalCluster, themeCluster)
|
|
|
})
|
|
|
- styles.forEach(style => {
|
|
|
- const { innerText } = style
|
|
|
- if (typeof innerText !== 'string') return
|
|
|
- style.innerText = updateStyle(innerText, originalCluster, themeCluster)
|
|
|
- })
|
|
|
|
|
|
- const element = document.getElementById('app')
|
|
|
- element.style.setProperty('--color-primary', val)
|
|
|
+ // 修改其它不是组件里面的颜色
|
|
|
+ const element = document.getElementById('app')
|
|
|
+ element.style.setProperty('--color-primary', themeColor)
|
|
|
+ }
|
|
|
+ // 修改主题
|
|
|
+ if(theme) {
|
|
|
+ document.querySelector("#app").className = theme
|
|
|
+ }
|
|
|
|
|
|
// 修改存的主题色
|
|
|
let tenantConfig = sessionStorage.getItem('tenantConfig')
|
|
|
tenantConfig = tenantConfig ? JSON.parse(tenantConfig) : {}
|
|
|
- tenantConfig.themeColor = val
|
|
|
+ if(themeColor) {
|
|
|
+ tenantConfig.themeColor = themeColor
|
|
|
+ }
|
|
|
+ if(theme) {
|
|
|
+ tenantConfig.theme = theme
|
|
|
+ }
|
|
|
sessionStorage.setItem('tenantConfig', JSON.stringify(tenantConfig))
|
|
|
|
|
|
if(isLoading) {
|