From 6dcbc0604dda8f33d93b525a572bd76dd718fd78 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Wed, 18 Oct 2023 11:19:55 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=8D=8F?= =?UTF-8?q?=E5=90=8C=E6=8F=92=E4=BB=B6=E5=BD=93=E5=88=9B=E5=BB=BA=E6=96=B0?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=97=B6=E6=96=B0=E8=8A=82=E7=82=B9=E6=9C=AA?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=88=9B=E5=BB=BA=E4=BA=BA=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/Cooperate.js | 35 +++++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/simple-mind-map/src/plugins/Cooperate.js b/simple-mind-map/src/plugins/Cooperate.js index 6e33d6a7..ea3eb2f5 100644 --- a/simple-mind-map/src/plugins/Cooperate.js +++ b/simple-mind-map/src/plugins/Cooperate.js @@ -16,6 +16,7 @@ class Cooperate { // 感知数据 this.awareness = null this.currentAwarenessData = [] + this.waitNodeUidMap = {} // 该列表中的uid对应的节点还未渲染完毕 // 当前的平级对象类型的思维导图数据 this.currentData = null // 用户信息 @@ -79,6 +80,10 @@ class Cooperate { this.onNodeActive = this.onNodeActive.bind(this) this.mindMap.on('node_active', this.onNodeActive) + // 监听思维导图渲染完毕事件 + this.onNodeTreeRenderEnd = this.onNodeTreeRenderEnd.bind(this) + this.mindMap.on('node_tree_render_end', this.onNodeTreeRenderEnd) + // 监听设置思维导图数据事件 this.initData = this.initData.bind(this) this.mindMap.on('set_data', this.initData) @@ -91,6 +96,7 @@ class Cooperate { } this.mindMap.off('data_change', this.onDataChange) this.mindMap.off('node_active', this.onNodeActive) + this.mindMap.off('node_tree_render_end', this.onNodeTreeRenderEnd) this.mindMap.off('set_data', this.initData) this.ydoc.destroy() } @@ -153,6 +159,17 @@ class Cooperate { } } + // 节点树渲染完毕事件 + onNodeTreeRenderEnd() { + Object.keys(this.waitNodeUidMap).forEach(uid => { + const node = this.mindMap.renderer.findNodeByUid(uid) + if (node) { + node.addUser(this.waitNodeUidMap[uid]) + } + }) + this.waitNodeUidMap = {} + } + // 设置用户信息 /** * { @@ -183,23 +200,27 @@ class Cooperate { const nodeIdList = data.nodeIdList nodeIdList.forEach(uid => { const node = this.mindMap.renderer.findNodeByUid(uid) - if (node) { - callback(node, userInfo) - } + callback(uid, node, userInfo) }) }) } // 清除之前的数据 - walk(this.currentAwarenessData, (node, userInfo) => { - node.removeUser(userInfo) + walk(this.currentAwarenessData, (uid, node, userInfo) => { + if (node) { + node.removeUser(userInfo) + } }) // 设置当前数据 const data = Array.from(this.awareness.getStates().values()) this.currentAwarenessData = data - walk(data, (node, userInfo) => { + walk(data, (uid, node, userInfo) => { // 不显示自己 if (userInfo.id === this.userInfo.id) return - node.addUser(userInfo) + if (node) { + node.addUser(userInfo) + } else { + this.waitNodeUidMap[uid] = userInfo + } }) }