From ad8cf74bbaf91c2e90507640010a0f283ec4aa17 Mon Sep 17 00:00:00 2001 From: wangqi01 <13693607080@163.com> Date: Tue, 12 Nov 2024 16:02:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=89=8D=E5=90=8E=EF=BC=8C=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=BA=86=E9=83=A8=E5=88=86=E5=AD=97=E4=BD=93=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E7=9A=84=E8=8A=82=E7=82=B9=EF=BC=8C=E5=85=B6=E6=9C=AA=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E5=AD=97=E4=BD=93=E6=A0=B7=E5=BC=8F=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=93=8D=E5=BA=94=E6=96=B0=E4=B8=BB=E9=A2=98=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/node/Style.js | 16 ++++++++++++++-- .../src/core/render/node/nodeCreateContents.js | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/simple-mind-map/src/core/render/node/Style.js b/simple-mind-map/src/core/render/node/Style.js index 68a38fc6..4443f034 100644 --- a/simple-mind-map/src/core/render/node/Style.js +++ b/simple-mind-map/src/core/render/node/Style.js @@ -192,14 +192,15 @@ class Style { } // 生成内联样式 - createStyleText() { + createStyleText(customStyle) { const styles = { color: this.merge('color'), fontFamily: this.merge('fontFamily'), fontSize: this.merge('fontSize'), fontWeight: this.merge('fontWeight'), fontStyle: this.merge('fontStyle'), - textDecoration: this.merge('textDecoration') + textDecoration: this.merge('textDecoration'), + ...customStyle } return ` color: ${styles.color}; @@ -354,6 +355,17 @@ class Style { return res } + // 获取自定义的样式 + getCustomStyle() { + let customStyle = {} + Object.keys(this.ctx.getData()).forEach(item => { + if (checkIsNodeStyleDataKey(item)) { + customStyle[item] = this.ctx.getData(item) + } + }) + return customStyle + } + // hover和激活节点 hoverNode(node) { const hoverRectColor = diff --git a/simple-mind-map/src/core/render/node/nodeCreateContents.js b/simple-mind-map/src/core/render/node/nodeCreateContents.js index e21686cf..9ecc8a0a 100644 --- a/simple-mind-map/src/core/render/node/nodeCreateContents.js +++ b/simple-mind-map/src/core/render/node/nodeCreateContents.js @@ -139,16 +139,18 @@ function createRichTextNode(specifyText) { recoverText = true } if ([CONSTANTS.CHANGE_THEME].includes(this.mindMap.renderer.renderSource)) { - // 如果自定义过样式则不允许覆盖 - if (!this.hasCustomStyle()) { + // // 如果自定义过样式则不允许覆盖 + // if (!this.hasCustomStyle() ) { recoverText = true - } + // } } if (recoverText && !isUndef(text)) { // 判断节点内容是否是富文本 let isRichText = checkIsRichText(text) + // 获取自定义样式 + let customStyle = this.getCustomStyle() // 样式字符串 - let style = this.style.createStyleText() + let style = this.style.createStyleText(customStyle) if (isRichText) { // 如果是富文本那么线移除内联样式 text = removeHtmlStyle(text) @@ -159,6 +161,14 @@ function createRichTextNode(specifyText) { if (text === _text) { text = addHtmlStyle(text, 'strong', style) } + // 给strong添加样式没有成功,则尝试给s标签添加样式 + if (text === _text) { + text = addHtmlStyle(text, 's', style) + } + // 给s添加样式没有成功,则尝试给em标签添加样式 + if (text === _text) { + text = addHtmlStyle(text, 'em', style) + } } else { // 非富文本 text = `

${text}

`