fix(样式): 修复生产环境产物样式不生效的问题
This commit is contained in:
@@ -5,6 +5,7 @@ Vue.use(Vuex)
|
||||
import Http from '../common/js/http.js'
|
||||
import { themeConfig } from '../common/js/config-external.js'
|
||||
import configExternal from '../common/js/config-external.js'
|
||||
import util from '../common/js/util.js'
|
||||
|
||||
const store = new Vuex.Store({
|
||||
state: {
|
||||
@@ -14,6 +15,7 @@ const store = new Vuex.Store({
|
||||
tabBarList: '',
|
||||
siteState: 1,
|
||||
themeStyle: '',
|
||||
themeColor: '',
|
||||
addonIsExist: {
|
||||
bundling: 0,
|
||||
coupon: 0,
|
||||
@@ -236,6 +238,10 @@ const store = new Vuex.Store({
|
||||
// 设置AI未读消息数量
|
||||
setAiUnreadCount(state, value) {
|
||||
state.aiUnreadCount = value;
|
||||
},
|
||||
// 设置主题颜色
|
||||
setThemeColor(state, value) {
|
||||
state.themeColor = value;
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
@@ -253,6 +259,7 @@ const store = new Vuex.Store({
|
||||
var data = res.data;
|
||||
if (data) {
|
||||
this.commit('setThemeStyle', configExternal.loadThemeSync(data.style_theme?.name));
|
||||
this.dispatch('themeColorSet');
|
||||
|
||||
// 底部导航
|
||||
this.commit('setTabBarList', data.diy_bottom_nav);
|
||||
@@ -401,6 +408,34 @@ const store = new Vuex.Store({
|
||||
|
||||
this.commit('setCartIds', ids);
|
||||
|
||||
},
|
||||
// 生成主题颜色CSS变量
|
||||
themeColorSet() {
|
||||
console.log('样式颜色设置...');
|
||||
let theme = this.state.themeStyle;
|
||||
if (!theme?.main_color || !theme?.aux_color) return;
|
||||
try {
|
||||
let themeColor = `--base-color:${theme.main_color};--base-help-color:${theme.aux_color};`;
|
||||
if (this.state.tabBarHeight != '56px') themeColor += `--tab-bar-height:${this.state.tabBarHeight};`
|
||||
Object.keys(theme).forEach(key => {
|
||||
let data = theme[key];
|
||||
if (typeof (data) == "object") {
|
||||
Object.keys(data).forEach(k => {
|
||||
themeColor += '--' + k.replace(/_/g, "-") + ':' + data[k] + ';';
|
||||
});
|
||||
} else if (typeof (key) == "string" && key) {
|
||||
themeColor += '--' + key.replace(/_/g, "-") + ':' + data + ';';
|
||||
}
|
||||
});
|
||||
for (let i = 9; i >= 5; i--) {
|
||||
let color = util.colourBlend(theme.main_color, '#ffffff', (i / 10));
|
||||
themeColor += `--base-color-light-${i}:${color};`;
|
||||
}
|
||||
this.commit('setThemeColor', themeColor);
|
||||
} catch (e) {
|
||||
console.error('设置主题颜色失败', e);
|
||||
}
|
||||
console.log('themeColor => ', this.state.themeColor);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user