feat: 支持body和背景样式

This commit is contained in:
wuyue.xht 2020-05-12 21:12:55 +08:00
parent b774428a0f
commit 661d98dfbb

View File

@ -74,17 +74,35 @@ designer.addPropsReducer(upgradePropsReducer, TransformStage.Init);
// 设计器组件样式处理 // 设计器组件样式处理
function stylePropsReducer(props: any, node: any) { function stylePropsReducer(props: any, node: any) {
if (props && typeof props === 'object' && props.__style__) { if (props && typeof props === 'object' && props.__style__) {
const cssId = '_style_pesudo_' + node.id.replace(/\$/g, '_');
const cssClass = '_css_pesudo_' + node.id.replace(/\$/g, '_');
const styleProp = props.__style__;
appendStyleNode(props, styleProp, cssClass, cssId);
}
if (props && typeof props === 'object' && props.pageStyle) {
const cssId = '_style_pesudo_engine-document';
const cssClass = 'engine-document';
const styleProp = props.pageStyle;
appendStyleNode(props, styleProp, cssClass, cssId);
}
if (props && typeof props === 'object' && props.containerStyle) {
const cssId = '_style_pesudo_' + node.id;
const cssClass = '_css_pesudo_' + node.id.replace(/\$/g, '_');
const styleProp = props.containerStyle;
appendStyleNode(props, styleProp, cssClass, cssId);
}
return props;
}
function appendStyleNode(props: any, styleProp: any, cssClass: string, cssId: string) {
const doc = designer.currentDocument?.simulator?.contentDocument; const doc = designer.currentDocument?.simulator?.contentDocument;
if (!doc) { if (!doc) {
return; return;
} }
const cssId = '_style_pesudo_' + node.id.replace(/\$/g, '_');
const cssClass = '_css_pesudo_' + node.id.replace(/\$/g, '_');
const dom = doc.getElementById(cssId); const dom = doc.getElementById(cssId);
if (dom) { if (dom) {
dom.parentNode?.removeChild(dom); dom.parentNode?.removeChild(dom);
} }
let styleProp = props.__style__;
if (typeof styleProp === 'object') { if (typeof styleProp === 'object') {
styleProp = toCss(styleProp); styleProp = toCss(styleProp);
} }
@ -97,8 +115,6 @@ function stylePropsReducer(props: any, node: any) {
s.appendChild(doc.createTextNode(styleProp.replace(/:root/g, '.' + cssClass))); s.appendChild(doc.createTextNode(styleProp.replace(/:root/g, '.' + cssClass)));
} }
}
return props;
} }
designer.addPropsReducer(stylePropsReducer, TransformStage.Render); designer.addPropsReducer(stylePropsReducer, TransformStage.Render);