From 4677b11dfb88fd4c2dfafda06001e4dc804ecd9b Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Mon, 22 Nov 2021 19:59:21 +0800 Subject: [PATCH] =?UTF-8?q?'=E7=8A=B6=E6=80=81=E6=95=B0=E6=8D=AE=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BF=9D=E5=AD=98=E6=BF=80=E6=B4=BB=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E3=80=81=E8=A7=86=E5=9B=BE=E7=8A=B6=E6=80=81=EF=BC=88=E6=8B=96?= =?UTF-8?q?=E5=8A=A8=E4=BD=8D=E7=BD=AE=E3=80=81=E7=BC=A9=E6=94=BE=E5=80=BC?= =?UTF-8?q?=EF=BC=89'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 63 +++++---- simple-mind-map/src/View.js | 54 ++++++-- simple-mind-map/src/utils/index.js | 2 +- web/src/api/index.js | 2 +- web/src/pages/Edit/components/Edit.vue | 174 +++++++++++++++++-------- 5 files changed, 206 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index e9eccd1c..314429a0 100644 --- a/README.md +++ b/README.md @@ -112,29 +112,30 @@ const mindMap = new MindMap({ 监听事件,事件列表: -| 事件名称 | 描述 | 回调参数 | -| --------------------- | ------------------------------------------ | ------------------------------------------------------------ | -| data_change | 渲染树数据变化,可以监听该方法获取最新数据 | data(当前渲染树数据) | -| back_forward | 前进或回退 | activeHistoryIndex(当前在历史数据数组里的索引)、length(当前历史数据数组的长度) | -| draw_click | *画布的单击事件* | e(事件对象) | -| svg_mousedown | svg画布的鼠标按下事件 | e(事件对象) | -| mousedown | el元素的鼠标按下事件 | e(事件对象)、this(Event事件类实例) | -| mousemove | el元素的鼠标移动事件 | e(事件对象)、this(Event事件类实例) | -| drag | 如果是按住左键拖动的话会触发拖动事件 | e(事件对象)、this(Event事件类实例) | -| mouseup | el元素的鼠标松开事件 | e(事件对象)、this(Event事件类实例) | -| mousewheel | 鼠标滚动事件 | e(事件对象)、dir(向上up还是向下down滚动)、this(Event事件类实例) | -| contextmenu | svg画布的鼠标右键菜单事件 | e(事件对象) | -| node_click | 节点的单击事件 | this(节点实例)、e(事件对象) | -| node_mousedown | 节点的鼠标按下事件 | this(节点实例)、e(事件对象) | -| node_mouseup | 节点的鼠标松开事件 | this(节点实例)、e(事件对象) | -| node_dblclick | 节点的双击事件 | this(节点实例)、e(事件对象) | -| node_contextmenu | 节点的右键菜单事件 | e(事件对象)、this(节点实例) | -| before_node_active | 节点激活前事件 | this(节点实例)、activeNodeList(当前激活的所有节点列表) | -| node_active | 节点激活事件 | this(节点实例)、activeNodeList(当前激活的所有节点列表) | -| expand_btn_click | 节点展开或收缩事件 | this(节点实例) | -| before_show_text_edit | 节点文本编辑框即将打开事件 | | -| hide_text_edit | 节点文本编辑框关闭事件 | textEditNode(文本编辑框DOM节点)、activeNodeList(当前激活的所有节点列表) | -| scale | 放大缩小事件 | scale(缩放比例) | +| 事件名称 | 描述 | 回调参数 | +| --------------------------- | ------------------------------------------ | ------------------------------------------------------------ | +| data_change | 渲染树数据变化,可以监听该方法获取最新数据 | data(当前渲染树数据) | +| view_data_change(v0.1.1+) | 视图变化数据,比如拖动或缩放时会触发 | data(当前视图状态数据) | +| back_forward | 前进或回退 | activeHistoryIndex(当前在历史数据数组里的索引)、length(当前历史数据数组的长度) | +| draw_click | *画布的单击事件* | e(事件对象) | +| svg_mousedown | svg画布的鼠标按下事件 | e(事件对象) | +| mousedown | el元素的鼠标按下事件 | e(事件对象)、this(Event事件类实例) | +| mousemove | el元素的鼠标移动事件 | e(事件对象)、this(Event事件类实例) | +| drag | 如果是按住左键拖动的话会触发拖动事件 | e(事件对象)、this(Event事件类实例) | +| mouseup | el元素的鼠标松开事件 | e(事件对象)、this(Event事件类实例) | +| mousewheel | 鼠标滚动事件 | e(事件对象)、dir(向上up还是向下down滚动)、this(Event事件类实例) | +| contextmenu | svg画布的鼠标右键菜单事件 | e(事件对象) | +| node_click | 节点的单击事件 | this(节点实例)、e(事件对象) | +| node_mousedown | 节点的鼠标按下事件 | this(节点实例)、e(事件对象) | +| node_mouseup | 节点的鼠标松开事件 | this(节点实例)、e(事件对象) | +| node_dblclick | 节点的双击事件 | this(节点实例)、e(事件对象) | +| node_contextmenu | 节点的右键菜单事件 | e(事件对象)、this(节点实例) | +| before_node_active | 节点激活前事件 | this(节点实例)、activeNodeList(当前激活的所有节点列表) | +| node_active | 节点激活事件 | this(节点实例)、activeNodeList(当前激活的所有节点列表) | +| expand_btn_click | 节点展开或收缩事件 | this(节点实例) | +| before_show_text_edit | 节点文本编辑框即将打开事件 | | +| hide_text_edit | 节点文本编辑框关闭事件 | textEditNode(文本编辑框DOM节点)、activeNodeList(当前激活的所有节点列表) | +| scale | 放大缩小事件 | scale(缩放比例) | @@ -402,6 +403,22 @@ mindMap.keyCommand.addShortcut('Control+Enter', () => {}) +#### getTransformData() + +v0.1.1+ + +获取当前变换数据,可用于回显 + + + +#### setTransformData(data) + +v0.1.1+ + +动态设置变换数据,可以通过getTransformData方法获取变换数据 + + + ## doExport实例 `doExport`实例负责导出,可通过`mindMap.doExport`获取到该实例 diff --git a/simple-mind-map/src/View.js b/simple-mind-map/src/View.js index 7e1661e9..0abc166c 100644 --- a/simple-mind-map/src/View.js +++ b/simple-mind-map/src/View.js @@ -19,6 +19,7 @@ class View { this.sy = 0 this.x = 0 this.y = 0 + this.setTransformData(this.mindMap.opt.viewData) this.bind() } @@ -63,6 +64,42 @@ class View { }) } + /** + * javascript comment + * @Author: 王林25 + * @Date: 2021-11-22 18:30:24 + * @Desc: 获取当前变换状态数据 + */ + getTransformData() { + return { + transform: this.mindMap.draw.transform(), + state: { + scale: this.scale, + x: this.x, + y: this.y, + sx: this.sx, + sy: this.sy + } + } + } + + /** + * javascript comment + * @Author: 王林25 + * @Date: 2021-11-22 19:54:17 + * @Desc: 动态设置变换状态数据 + */ + setTransformData(viewData) { + if (viewData) { + Object.keys(viewData.state).forEach((prop) => { + this[prop] = viewData.state[prop] + }) + this.mindMap.draw.transform({ + ...viewData.transform + }) + } + } + /** * javascript comment * @Author: 王林25 @@ -96,6 +133,7 @@ class View { origin: 'left center', translate: [this.x, this.y], }) + this.mindMap.emit('view_data_change', this.getTransformData()) } /** @@ -104,22 +142,18 @@ class View { * @Desc: 恢复 */ reset() { - let t = this.mindMap.draw.transform() + // let t = this.mindMap.draw.transform() this.scale = 1 this.x = 0 this.y = 0 - this.mindMap.draw.transform({ - scale: this.scale, - origin: 'left center', - translate: [this.x, this.y], - }) + this.transform() } /** - * @Author: 王林 - * @Date: 2021-07-04 17:10:34 - * @Desc: 缩小 - */ + * @Author: 王林 + * @Date: 2021-07-04 17:10:34 + * @Desc: 缩小 + */ narrow() { if (this.scale - this.mindMap.opt.scaleRatio > 0.1) { this.scale -= this.mindMap.opt.scaleRatio diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index a0cc9ef5..68b1cef7 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -143,7 +143,7 @@ export const copyRenderTree = (tree, root) => { */ export const copyNodeTree = (tree, root) => { tree.data = simpleDeepClone(root.nodeData.data) - tree.data.isActive = false + // tree.data.isActive = false tree.children = [] if (root.children && root.children.length > 0) { root.children.forEach((item, index) => { diff --git a/web/src/api/index.js b/web/src/api/index.js index 70415711..33b52155 100644 --- a/web/src/api/index.js +++ b/web/src/api/index.js @@ -10,7 +10,7 @@ const SIMPLE_MIND_MAP_DATA = 'SIMPLE_MIND_MAP_DATA' */ const copyMindMapTreeData = (tree, root) => { tree.data = simpleDeepClone(root.data) - tree.data.isActive = false + // tree.data.isActive = false tree.children = [] if (root.children && root.children.length > 0) { root.children.forEach((item, index) => { diff --git a/web/src/pages/Edit/components/Edit.vue b/web/src/pages/Edit/components/Edit.vue index 547f58f9..29437ea5 100644 --- a/web/src/pages/Edit/components/Edit.vue +++ b/web/src/pages/Edit/components/Edit.vue @@ -14,17 +14,17 @@