代码拉取完成,页面将自动刷新
同步操作将从 likeadmin/likeadmin(Java版)- MIT协议-免费任意商用 - 管理后台_小程序_手机H5_PC端_uni-app 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import colors from 'css-color-function'
const lightConfig = {
'dark-2': 'shade(20%)',
'light-3': 'tint(30%)',
'light-5': 'tint(50%)',
'light-7': 'tint(70%)',
'light-8': 'tint(80%)',
'light-9': 'tint(90%)'
}
const darkConfig = {
'light-3': 'shade(20%)',
'light-5': 'shade(30%)',
'light-7': 'shade(50%)',
'light-8': 'shade(60%)',
'light-9': 'shade(70%)',
'dark-2': 'tint(20%)'
}
const themeId = 'theme-vars'
/**
* @author Jason
* @description 用于生成elementui主题的行为变量
* 可选值有primary、success、warning、danger、error、info
*/
export const generateVars = (color: string, type = 'primary', isDark = false) => {
const colos = {
[`--el-color-${type}`]: color
}
const config: Record<string, string> = isDark ? darkConfig : lightConfig
for (const key in config) {
colos[`--el-color-${type}-${key}`] = `color(${color} ${config[key]})`
}
return colos
}
/**
* @author Jason
* @description 用于设置css变量
* @param key css变量key 如 --color-primary
* @param value css变量值 如 #f40
* @param dom dom元素
*/
export const setCssVar = (key: string, value: string, dom = document.documentElement) => {
dom.style.setProperty(key, value)
}
/**
* @author Jason
* @description 设置主题
*/
export const setTheme = (options: Record<string, string>, isDark = false) => {
const varsMap: Record<string, string> = Object.keys(options).reduce((prev, key) => {
return Object.assign(prev, generateVars(options[key], key, isDark))
}, {})
let theme = Object.keys(varsMap).reduce((prev, key) => {
const color = colors.convert(varsMap[key])
return `${prev}${key}:${color};`
}, '')
theme = `:root{${theme}}`
let style = document.getElementById(themeId)
if (style) {
style.innerHTML = theme
return
}
style = document.createElement('style')
style.setAttribute('type', 'text/css')
style.setAttribute('id', themeId)
style.innerHTML = theme
document.head.append(style)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。