diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index fb874fbf..83fa8116 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -30,7 +30,8 @@ import { createSmmFormatData, checkSmmFormatData, checkIsNodeStyleDataKey, - removeRichTextStyes + removeRichTextStyes, + formatGetNodeGeneralization } from '../../utils' import { shapeList } from './node/Shape' import { lineStyleProps } from '../../themes/default' @@ -992,18 +993,13 @@ class Render { const _hasCustomStyles = this._handleRemoveCustomStyles(node.data) if (_hasCustomStyles) hasCustomStyles = true // 不要忘记概要节点 - let generalization = node.data.generalization - if (generalization) { - generalization = Array.isArray(generalization) - ? generalization - : [generalization] - if (generalization.length > 0) { - generalization.forEach(generalizationData => { - const _hasCustomStyles = - this._handleRemoveCustomStyles(generalizationData) - if (_hasCustomStyles) hasCustomStyles = true - }) - } + const generalizationList = formatGetNodeGeneralization(node.data) + if (generalizationList.length > 0) { + generalizationList.forEach(generalizationData => { + const _hasCustomStyles = + this._handleRemoveCustomStyles(generalizationData) + if (_hasCustomStyles) hasCustomStyles = true + }) } }) } @@ -1840,14 +1836,24 @@ class Render { return } let parentsList = [] + let isGeneralization = false const cache = {} bfsWalk(this.renderTree, (node, parent) => { if (node.data.uid === uid) { parentsList = parent ? [...cache[parent.data.uid], parent] : [] return 'stop' - } else { - cache[node.data.uid] = parent ? [...cache[parent.data.uid], parent] : [] } + const generalizationList = formatGetNodeGeneralization(node.data) + generalizationList.forEach(item => { + if (item.uid === uid) { + parentsList = parent ? [...cache[parent.data.uid], parent] : [] + isGeneralization = true + } + }) + if (isGeneralization) { + return 'stop' + } + cache[node.data.uid] = parent ? [...cache[parent.data.uid], parent] : [] }) let needRender = false parentsList.forEach(node => { @@ -1856,6 +1862,18 @@ class Render { node.data.expand = true } }) + // 如果是展开到概要节点,那么父节点下的所有节点都需要开 + if (isGeneralization) { + const lastNode = parentsList[parentsList.length - 1] + if (lastNode) { + walk(lastNode, null, node => { + if (!node.data.expand) { + needRender = true + node.data.expand = true + } + }) + } + } if (needRender) { this.mindMap.render(callback) } else { @@ -1871,6 +1889,17 @@ class Render { res = node return true } + // 概要节点 + let isGeneralization = false + ;(node._generalizationList || []).forEach(item => { + if (item.generalizationNode.getData('uid') === uid) { + res = item.generalizationNode + isGeneralization = true + } + }) + if (isGeneralization) { + return true + } }) return res } diff --git a/simple-mind-map/src/plugins/Demonstrate.js b/simple-mind-map/src/plugins/Demonstrate.js index 68159a45..044678e9 100644 --- a/simple-mind-map/src/plugins/Demonstrate.js +++ b/simple-mind-map/src/plugins/Demonstrate.js @@ -3,7 +3,8 @@ import { getNodeTreeBoundingRect, fullscrrenEvent, fullScreen, - exitFullScreen + exitFullScreen, + formatGetNodeGeneralization } from '../utils/index' import { keyMap } from '../core/command/keyMap' @@ -215,7 +216,11 @@ class Demonstrate { // 如果该节点实例不存在,那么先展开到该节点 if (!node) { this.mindMap.renderer.expandToNodeUid(uid, () => { - this.jump(index) + const node = this.mindMap.renderer.findNodeByUid(uid) + // 展开后还是没找到,那么就别进入了,否则会死循环 + if (node) { + this.jump(index) + } }) return } @@ -284,6 +289,19 @@ class Demonstrate { type: 'node', node }) + // 添加概要步骤 + const generalizationList = formatGetNodeGeneralization(node.data) + generalizationList.forEach(item => { + // 没有uid的直接过滤掉,否则会死循环 + if (item.uid) { + this.stepList.push({ + type: 'node', + node: { + data: item + } + }) + } + }) if (node.children.length > 1) { this.stepList.push({ type: 'children', diff --git a/simple-mind-map/src/plugins/RichText.js b/simple-mind-map/src/plugins/RichText.js index 3e84f7c3..aee60138 100644 --- a/simple-mind-map/src/plugins/RichText.js +++ b/simple-mind-map/src/plugins/RichText.js @@ -8,7 +8,8 @@ import { getVisibleColorFromTheme, isUndef, checkSmmFormatData, - removeHtmlNodeByClass + removeHtmlNodeByClass, + formatGetNodeGeneralization } from '../utils' import { CONSTANTS } from '../constants/constant' @@ -651,13 +652,9 @@ class RichText { node.data.text = getTextFromHtml(node.data.text) } // 概要 - let generalization = - node.data && node.data.generalization ? node.data.generalization : [] - generalization = Array.isArray(generalization) - ? generalization - : [generalization] - if (generalization.length > 0) { - generalization.forEach(item => { + if (node.data) { + const generalizationList = formatGetNodeGeneralization(node.data) + generalizationList.forEach(item => { item.richText = false item.text = getTextFromHtml(item.text) }) @@ -682,13 +679,9 @@ class RichText { root.data.resetRichText = true } // 概要 - let generalization = - root.data && root.data.generalization ? root.data.generalization : [] - generalization = Array.isArray(generalization) - ? generalization - : [generalization] - if (generalization.length > 0) { - generalization.forEach(item => { + if (root.data) { + const generalizationList = formatGetNodeGeneralization(root.data) + generalizationList.forEach(item => { item.richText = true item.resetRichText = true }) diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index a47a60a0..b192b932 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -157,16 +157,10 @@ export const copyRenderTree = (tree, root, removeActiveState = false) => { tree.data = simpleDeepClone(root.data) if (removeActiveState) { tree.data.isActive = false - const generalization = tree.data.generalization - if (generalization) { - if (Array.isArray(generalization)) { - generalization.forEach(item => { - item.isActive = false - }) - } else { - generalization.isActive = false - } - } + const generalizationList = formatGetNodeGeneralization(tree.data) + generalizationList.forEach(item => { + item.isActive = false + }) } tree.children = [] if (root.children && root.children.length > 0) { @@ -1472,3 +1466,13 @@ export const createForeignObjectNode = ({ el, width, height }) => { foreignObject.add(el) return foreignObject } + +// 格式化获取节点的概要数据 +export const formatGetNodeGeneralization = data => { + const generalization = data.generalization + if (generalization) { + return Array.isArray(generalization) ? generalization : [generalization] + } else { + return [] + } +} diff --git a/simple-mind-map/src/utils/xmind.js b/simple-mind-map/src/utils/xmind.js index 43948d02..4d0c1316 100644 --- a/simple-mind-map/src/utils/xmind.js +++ b/simple-mind-map/src/utils/xmind.js @@ -5,6 +5,7 @@ import { getTextFromHtml, createUid } from './index' +import { formatGetNodeGeneralization } from '../utils/index' // 解析出新xmind的概要文本 export const getSummaryText = (node, topicId) => { @@ -182,19 +183,9 @@ export const getXmindContentXmlData = () => { return ` Warning 警告 Attention Warnung 경고 This file can not be opened normally, please do not modify and save, otherwise the contents will be permanently lost! You can try using XMind 8 Update 3 or later version to open 该文件无法正常打开,请勿修改并保存,否则文件内容将会永久性丢失! 你可以尝试使用 XMind 8 Update 3 或更新版本打开 該文件無法正常打開,請勿修改並保存,否則文件內容將會永久性丟失! 你可以嘗試使用 XMind 8 Update 3 或更新版本打開 この文書は正常に開かないので、修正して保存しないようにしてください。そうでないと、書類の内容が永久に失われます。! XMind 8 Update 3 や更新版を使って開くこともできます Datei kann nicht richtig geöffnet werden. Bitte ändern Sie diese Datei nicht und speichern Sie sie, sonst wird die Datei endgültig gelöscht werden. Bitte versuchen Sie, diese Datei mit XMind 8 Update 3 oder später zu öffnen. Ce fichier ne peut pas ouvert normalement, veuillez le rédiger et sauvegarder, sinon le fichier sera perdu en permanence. Vous pouvez essayer d'ouvrir avec XMind 8 Update 3 ou avec une version plus récente. 파일을 정상적으로 열 수 없으며, 수정 및 저장하지 마십시오. 그렇지 않으면 파일의 내용이 영구적으로 손실됩니다! XMind 8 Update 3 또는 이후 버전을 사용하여 -1 Sheet 1 ` } -// 获取节点的概要列表 -const formatGetGeneralization = data => { - const generalization = data.generalization - return Array.isArray(generalization) - ? generalization - : generalization - ? [generalization] - : [] -} - // 获取节点自身的概要,非子节点区间 const getSelfGeneralization = data => { - const list = formatGetGeneralization(data) + const list = formatGetNodeGeneralization(data) return list.filter(item => { return !item.range || item.range.length <= 0 }) @@ -202,7 +193,7 @@ const getSelfGeneralization = data => { // 获取节点区间概要 const getRangeGeneralization = data => { - const list = formatGetGeneralization(data) + const list = formatGetNodeGeneralization(data) return list.filter(item => { return item.range && item.range.length > 0 }) diff --git a/web/src/pages/Edit/components/Edit.vue b/web/src/pages/Edit/components/Edit.vue index 02635a8f..1e4e0fdf 100644 --- a/web/src/pages/Edit/components/Edit.vue +++ b/web/src/pages/Edit/components/Edit.vue @@ -789,7 +789,7 @@ export default { if (this.mindMap.cooperate && this.$route.query.userName) { this.mindMap.cooperate.setProvider(null, { roomName: 'demo-room', - signalingList: ['ws://10.16.83.118:4444'] + signalingList: ['ws://localhost:4444'] }) this.mindMap.cooperate.setUserInfo({ id: Math.random(),