Commit bfebd780 authored by 崔佳豪's avatar 崔佳豪

fix: 站点切换支持改变主题

parent 82fa49ff
Pipeline #54946 passed with stages
......@@ -376,7 +376,22 @@ class Login {
self.globalConfig.shortcutIcon = mainConf.shortcutIcon;
if (mainConf && mainConf.hasOwnProperty('topMenu'))
self.globalConfig.topMenu = mainConf.topMenu;
if (mainConf && mainConf.navTheme) self.globalConfig.navTheme = mainConf.navTheme; // 云平台统一navTheme
if (mainConf && mainConf.navTheme && self.globalConfig.CloudStyle !== '否') self.globalConfig.navTheme = mainConf.navTheme; // 云平台统一navTheme
// 云平台切换站点 应用站点自己主题配置
if (config.CloudStyle === '否') {
self.globalConfig.variableTheme = {
primaryColor: config.primaryColor,
navTheme: config.navTheme,
headerPrimaryColor: config.headerPrimaryColor,
}
} else {
self.globalConfig.variableTheme = {
primaryColor: mainConf.primaryColor,
navTheme: mainConf.navTheme,
headerPrimaryColor: mainConf.headerPrimaryColor,
}
}
// if (mainConf.productType)
// self.globalConfig.productType = mainConf.productType;
self.updateConfig && self.updateConfig(self.globalConfig);
......
......@@ -230,46 +230,33 @@ export const AppInitState = () => {
) return false
return true
}
/**
* @param {Object} theme
* primaryColor:
* navTheme: "dark" or "light"
* headerPrimaryColor:
*/
window.share && window.share.event && window.share.event.on('update:theme', function(theme) {
if(!theme || !hasThemeChanged(window.globalConfig.variableTheme, theme)) return;
const preVariableTheme = window.globalConfig.variableTheme ?? {};
const {
primaryColor: prePrimaryColor,
navTheme: preNavTheme,
headerPrimaryColor: preHeaderPrimaryColor,
} = preVariableTheme;
const { primaryColor, navTheme, headerPrimaryColor } = theme;
if (primaryColor && primaryColor !== prePrimaryColor) {
ConfigProvider.config({
prefixCls: customPrefixCls,
theme: {
primaryColor,
}
});
}
if (navTheme && navTheme !== preNavTheme) {
// do nothing
}
if (headerPrimaryColor && headerPrimaryColor !== preHeaderPrimaryColor) {
registerTheme(customPrefixCls, {
'header-bg-color': headerPrimaryColor,
});
store.subscribe((function() {
let preVariableTheme = store.getState().toJS().global?.globalConfig?.variableTheme;
return function() {
// if (!preVariableTheme)
const variableTheme = store.getState().toJS().global?.globalConfig?.variableTheme;
if(!hasThemeChanged(preVariableTheme, variableTheme)) return false
const {
primaryColor: prePrimaryColor,
navTheme: preNavTheme,
headerPrimaryColor: preHeaderPrimaryColor,
} = (preVariableTheme || {});
const { primaryColor, headerPrimaryColor } = variableTheme;
if (primaryColor && primaryColor !== prePrimaryColor) {
ConfigProvider.config({
prefixCls: customPrefixCls,
theme: {
primaryColor,
}
});
}
if (headerPrimaryColor && headerPrimaryColor !== preHeaderPrimaryColor) {
registerTheme(customPrefixCls, {
'header-bg-color': headerPrimaryColor,
});
}
}
// updage global config
const variableTheme = Object.assign({}, preVariableTheme, theme);
store.dispatch(actionCreators.getConfig(Object.assign({}, window.globalConfig, {
variableTheme: variableTheme,
})));
})
})())
};
initLocale();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment