From 628a6b72a2fa15182e7824db74a21af26bc357ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Wed, 25 Dec 2024 18:28:00 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E5=AF=8C=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=A2=9E=E5=8A=A0=E5=AF=B9=E8=80=81=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E6=95=B0=E6=8D=AE=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/RichText.js | 16 +++++++++++---- simple-mind-map/src/utils/index.js | 26 +++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/simple-mind-map/src/plugins/RichText.js b/simple-mind-map/src/plugins/RichText.js index fbf263f8..435b9e0e 100644 --- a/simple-mind-map/src/plugins/RichText.js +++ b/simple-mind-map/src/plugins/RichText.js @@ -9,7 +9,8 @@ import { formatGetNodeGeneralization, nodeRichTextToTextWithWrap, getNodeRichTextStyles, - htmlEscape + htmlEscape, + compareVersion } from '../utils' import { CONSTANTS, richTextSupportStyleList } from '../constants/constant' import MindMapNode from '../core/render/node/MindMapNode' @@ -762,22 +763,29 @@ class RichText { } handleDataToRichText(data) { + const oldIsRichText = data.richText data.richText = true data.resetRichText = true - data.text = htmlEscape(data.text) + // 如果原本就是富文本,那么不能转换 + if (!oldIsRichText) { + data.text = htmlEscape(data.text) + } } // 处理导入数据 handleSetData(data) { + // 短期处理,为了兼容老数据,长期会去除 + const isOldRichTextVersion = + !data.smmVersion || compareVersion(data.smmVersion, '0.13.0') === '<' const walk = root => { - if (root.data && !root.data.richText) { + if (root.data && (!root.data.richText || isOldRichTextVersion)) { this.handleDataToRichText(root.data) } // 概要 if (root.data) { const generalizationList = formatGetNodeGeneralization(root.data) generalizationList.forEach(item => { - if (!item.richText) { + if (!item.richText || isOldRichTextVersion) { this.handleDataToRichText(item) } }) diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index b96cc128..33d817af 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -175,7 +175,7 @@ export const copyRenderTree = (tree, root, removeActiveState = false) => { }) } // data、children外的其他字段 - Object.keys(root).forEach((key) => { + Object.keys(root).forEach(key => { if (!['data', 'children'].includes(key) && !/^_/.test(key)) { tree[key] = root[key] } @@ -216,7 +216,7 @@ export const copyNodeTree = ( }) } // data、children外的其他字段 - Object.keys(root).forEach((key) => { + Object.keys(root).forEach(key => { if (!['data', 'children'].includes(key) && !/^_/.test(key)) { tree[key] = root[key] } @@ -1673,3 +1673,25 @@ export const getNodeRichTextStyles = node => { }) return res } + +// 判断两个版本号的关系 +/* +a > b 返回 > +a < b 返回 < +a = b 返回 = +*/ +export const compareVersion = (a, b) => { + const aArr = String(a).split('.') + const bArr = String(b).split('.') + const max = Math.max(aArr.length, bArr.length) + for (let i = 0; i < max; i++) { + const ai = aArr[i] || 0 + const bi = bArr[i] || 0 + if (ai > bi) { + return '>' + } else if (ai < bi) { + return '<' + } + } + return '=' +}