Files
lgp-wx-plus/mixins/theme.js
年糕崽崽 516f077568 初始化
缺陷:主题配色需要优化整体的同风格
2026-08-14 23:17:19 +08:00

51 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { getActiveVars, loadAndApplyTheme } from '@/utils/theme'
/**
* 页面主题 mixin把后端 css_vars 绑到页面可读的计算属性
* 小程序无法动态改全局 scss必须在页面 :style 里消费这些值
*/
export default {
data() {
return {
themeVars: getActiveVars(),
}
},
computed: {
/** 页面根节点背景/文字 */
themePageStyle() {
const v = this.themeVars || {}
return {
backgroundColor: v['--color-bg'] || '#F7F8FA',
color: v['--color-text'] || '#1a1a1a',
}
},
themePrimary() {
return (this.themeVars && this.themeVars['--color-primary']) || '#B08D57'
},
themeSurface() {
return (this.themeVars && this.themeVars['--color-surface']) || '#ffffff'
},
themeText() {
return (this.themeVars && this.themeVars['--color-text']) || '#1a1a1a'
},
themeTextSoft() {
return (this.themeVars && this.themeVars['--color-text-soft']) || '#666666'
},
themeBorder() {
return (this.themeVars && this.themeVars['--color-border']) || '#eeeeee'
},
themeRadius() {
return (this.themeVars && this.themeVars['--radius-md']) || '16rpx'
},
},
async onShow() {
// 每次进页刷新:后台改默认模板后无需杀掉小程序
try {
const theme = await loadAndApplyTheme()
this.themeVars = (theme && theme.css_vars) || getActiveVars()
} catch (e) {
this.themeVars = getActiveVars()
}
},
}