回退功能开发中

This commit is contained in:
wanglin 2021-07-12 07:56:38 +08:00
parent f38b92a2e2
commit 395e802b6b
15 changed files with 189 additions and 21 deletions

View File

@ -24,14 +24,14 @@ export default {
"data": { "data": {
"text": "根节点" "text": "根节点"
}, },
"children": [ "childrens": [
{ {
"data": { "data": {
"text": "二级节点1" "text": "二级节点1"
} }
} }
], ],
"childrens": [ "children": [
{ {
"data": { "data": {
"text": "二级节点1", "text": "二级节点1",

View File

@ -29,6 +29,9 @@ class Command {
this.commands[name].forEach((fn) => { this.commands[name].forEach((fn) => {
fn(...args) fn(...args)
}) })
if (name === 'BACK' || name === 'FORWARD') {
return ;
}
this.addHistory() this.addHistory()
} }
} }
@ -58,6 +61,18 @@ class Command {
this.mindMap.emit('data_change', data) this.mindMap.emit('data_change', data)
} }
/**
* @Author: 王林
* @Date: 2021-07-11 22:34:53
* @Desc: 回退
*/
back(step = 1) {
if (this.activeHistoryIndex - step >= 0) {
this.activeHistoryIndex -= step
return simpleDeepClone(this.history[this.activeHistoryIndex]);
}
}
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2021-05-04 15:02:58 * @Date: 2021-05-04 15:02:58

View File

@ -89,6 +89,18 @@ class Node {
this.getSize() this.getSize()
} }
/**
* @Author: 王林
* @Date: 2021-07-12 07:40:47
* @Desc: 更新主题配置
*/
updateThemeConfig() {
// 主题配置
this.themeConfig = this.mindMap.themeConfig
// 样式实例
this.style.updateThemeConfig(this.themeConfig)
}
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2021-07-05 23:11:39 * @Date: 2021-07-05 23:11:39
@ -471,6 +483,7 @@ class Node {
let { paddingY } = this.getPaddingVale() let { paddingY } = this.getPaddingVale()
// 创建组 // 创建组
this.group = new G() this.group = new G()
this.draw.add(this.group)
this.update(false) this.update(false)
// 节点矩形 // 节点矩形
this.style.rect(this.group.rect(width, height)) this.style.rect(this.group.rect(width, height))
@ -574,7 +587,6 @@ class Node {
this.removeAllNode() this.removeAllNode()
this.createNodeData() this.createNodeData()
this.layout() this.layout()
this.draw.add(this.group)
} }
/** /**
@ -584,13 +596,13 @@ class Node {
*/ */
update(animate = true) { update(animate = true) {
if (!this.group) { if (!this.group) {
return; return
} }
// 需要移除展开收缩按钮 // 需要移除展开收缩按钮
if (this._expandBtn && this.nodeData.children.length <= 0) { if (this._expandBtn && this.nodeData.children.length <= 0) {
this.removeExpandBtn() this.removeExpandBtn()
} else if (!this._expandBtn && this.nodeData.children.length > 0) {// 需要添加展开收缩按钮 } else if (!this._expandBtn && this.nodeData.children.length > 0) {// 需要添加展开收缩按钮
this.renderExpandBtn() this.renderExpandBtn()
} }
let t = this.group.transform() let t = this.group.transform()
@ -619,9 +631,21 @@ class Node {
} }
// 子节点 // 子节点
if (this.children && this.children.length && this.nodeData.data.expand !== false) { if (this.children && this.children.length && this.nodeData.data.expand !== false) {
this.children.forEach((child) => { let index = 0
child.render() let loop = () => {
}) if (index >= this.children.length) {
return
}
this.children[index].render()
setTimeout(() => {
index++
loop()
}, 0)
}
loop()
// this.children.forEach((child) => {
// child.render()
// })
} }
} }
@ -637,9 +661,21 @@ class Node {
this.removeLine() this.removeLine()
// 子节点 // 子节点
if (this.children && this.children.length) { if (this.children && this.children.length) {
this.children.forEach((child) => { let index = 0
child.remove() let loop = () => {
}) if (index >= this.children.length) {
return
}
this.children[index].remove()
setTimeout(() => {
index++
loop()
}, 0)
}
loop()
// this.children.forEach((child) => {
// child.remove()
// })
} }
} }

View File

@ -74,6 +74,9 @@ class Render {
* @Desc: 注册命令 * @Desc: 注册命令
*/ */
registerCommands() { registerCommands() {
// 回退
this.back = this.back.bind(this)
this.mindMap.command.add('BACK', this.back)
// 插入同级节点 // 插入同级节点
this.insertNode = this.insertNode.bind(this) this.insertNode = this.insertNode.bind(this)
this.mindMap.command.add('INSERT_NODE', this.insertNode) this.mindMap.command.add('INSERT_NODE', this.insertNode)
@ -154,8 +157,11 @@ class Render {
* @Desc: 渲染 * @Desc: 渲染
*/ */
render() { render() {
let s = Date.now()
this.root = this.layout.doLayout() this.root = this.layout.doLayout()
console.log(Date.now() - s)
this.root.render() this.root.render()
console.log(Date.now() - s)
} }
/** /**
@ -214,6 +220,19 @@ class Render {
}) : 0 }) : 0
} }
/**
* @Author: 王林
* @Date: 2021-07-11 22:34:12
* @Desc: 回退
*/
back(step) {
let data = this.mindMap.command.back(step)
if (data) {
this.renderTree = data
this.mindMap.reRender()
}
}
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2021-05-04 13:19:54 * @Date: 2021-05-04 13:19:54
@ -295,6 +314,7 @@ class Render {
i-- i--
} }
} }
this.mindMap.emit('node_active', null, [])
this.mindMap.render() this.mindMap.render()
} }
@ -329,7 +349,9 @@ class Render {
this.setNodeData(node, { this.setNodeData(node, {
isActive: active isActive: active
}) })
let s = Date.now()
node.renderNode() node.renderNode()
console.log(Date.now() - s)
} }
/** /**

View File

@ -31,6 +31,15 @@ class Style {
this.themeConfig = themeConfig this.themeConfig = themeConfig
} }
/**
* @Author: 王林
* @Date: 2021-07-12 07:40:14
* @Desc: 更新主题配置
*/
updateThemeConfig(themeConfig) {
this.themeConfig = themeConfig
}
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2021-04-11 12:02:55 * @Date: 2021-04-11 12:02:55

View File

@ -16,8 +16,6 @@ class Base {
this.renderer = renderer this.renderer = renderer
// 控制实例 // 控制实例
this.mindMap = renderer.mindMap this.mindMap = renderer.mindMap
// 渲染树
this.renderTree = renderer.renderTree
// 绘图对象 // 绘图对象
this.draw = this.mindMap.draw this.draw = this.mindMap.draw
// 根节点 // 根节点

View File

@ -42,7 +42,7 @@ class LogicalStructure extends Base {
* @Desc: 遍历数据计算节点的leftwidthheight * @Desc: 遍历数据计算节点的leftwidthheight
*/ */
computedBaseValue() { computedBaseValue() {
walk(this.renderTree, null, (cur, parent, isRoot, layerIndex) => { walk(this.renderer.renderTree, null, (cur, parent, isRoot, layerIndex) => {
let newNode = this.createNode(cur, parent, isRoot, layerIndex) let newNode = this.createNode(cur, parent, isRoot, layerIndex)
// 根节点定位在画布中心位置 // 根节点定位在画布中心位置
if (isRoot) { if (isRoot) {

View File

@ -54,6 +54,18 @@
<div class="content unicode" style="display: block;"> <div class="content unicode" style="display: block;">
<ul class="icon_lists dib-box"> <ul class="icon_lists dib-box">
<li class="dib">
<span class="icon iconfont">&#xe603;</span>
<div class="name">撤回</div>
<div class="code-name">&amp;#xe603;</div>
</li>
<li class="dib">
<span class="icon iconfont">&#xe600;</span>
<div class="name">前进</div>
<div class="code-name">&amp;#xe600;</div>
</li>
<li class="dib"> <li class="dib">
<span class="icon iconfont">&#xe60e;</span> <span class="icon iconfont">&#xe60e;</span>
<div class="name">恢复默认</div> <div class="name">恢复默认</div>
@ -222,9 +234,9 @@
<pre><code class="language-css" <pre><code class="language-css"
>@font-face { >@font-face {
font-family: 'iconfont'; font-family: 'iconfont';
src: url('iconfont.woff2?t=1626000433132') format('woff2'), src: url('iconfont.woff2?t=1626013782202') format('woff2'),
url('iconfont.woff?t=1626000433132') format('woff'), url('iconfont.woff?t=1626013782202') format('woff'),
url('iconfont.ttf?t=1626000433132') format('truetype'); url('iconfont.ttf?t=1626013782202') format('truetype');
} }
</code></pre> </code></pre>
<h3 id="-iconfont-">第二步:定义使用 iconfont 的样式</h3> <h3 id="-iconfont-">第二步:定义使用 iconfont 的样式</h3>
@ -250,6 +262,24 @@
<div class="content font-class"> <div class="content font-class">
<ul class="icon_lists dib-box"> <ul class="icon_lists dib-box">
<li class="dib">
<span class="icon iconfont iconwithdraw"></span>
<div class="name">
撤回
</div>
<div class="code-name">.iconwithdraw
</div>
</li>
<li class="dib">
<span class="icon iconfont iconqianjin"></span>
<div class="name">
前进
</div>
<div class="code-name">.iconqianjin
</div>
</li>
<li class="dib"> <li class="dib">
<span class="icon iconfont iconhuifumoren"></span> <span class="icon iconfont iconhuifumoren"></span>
<div class="name"> <div class="name">
@ -502,6 +532,22 @@
<div class="content symbol"> <div class="content symbol">
<ul class="icon_lists dib-box"> <ul class="icon_lists dib-box">
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#iconwithdraw"></use>
</svg>
<div class="name">撤回</div>
<div class="code-name">#iconwithdraw</div>
</li>
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#iconqianjin"></use>
</svg>
<div class="name">前进</div>
<div class="code-name">#iconqianjin</div>
</li>
<li class="dib"> <li class="dib">
<svg class="icon svg-icon" aria-hidden="true"> <svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#iconhuifumoren"></use> <use xlink:href="#iconhuifumoren"></use>

View File

@ -1,8 +1,8 @@
@font-face { @font-face {
font-family: "iconfont"; /* Project id 2479351 */ font-family: "iconfont"; /* Project id 2479351 */
src: url('iconfont.woff2?t=1626000433132') format('woff2'), src: url('iconfont.woff2?t=1626013782202') format('woff2'),
url('iconfont.woff?t=1626000433132') format('woff'), url('iconfont.woff?t=1626013782202') format('woff'),
url('iconfont.ttf?t=1626000433132') format('truetype'); url('iconfont.ttf?t=1626013782202') format('truetype');
} }
.iconfont { .iconfont {
@ -13,6 +13,14 @@
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
.iconwithdraw:before {
content: "\e603";
}
.iconqianjin:before {
content: "\e600";
}
.iconhuifumoren:before { .iconhuifumoren:before {
content: "\e60e"; content: "\e60e";
} }

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,20 @@
"css_prefix_text": "icon", "css_prefix_text": "icon",
"description": "思维导图", "description": "思维导图",
"glyphs": [ "glyphs": [
{
"icon_id": "1368553",
"name": "撤回",
"font_class": "withdraw",
"unicode": "e603",
"unicode_decimal": 58883
},
{
"icon_id": "15006636",
"name": "前进",
"font_class": "qianjin",
"unicode": "e600",
"unicode_decimal": 58880
},
{ {
"icon_id": "19980541", "icon_id": "19980541",
"name": "恢复默认", "name": "恢复默认",

View File

@ -3,6 +3,26 @@
<div class="toolbar"> <div class="toolbar">
<!-- 节点操作 --> <!-- 节点操作 -->
<div class="toolbarBlock"> <div class="toolbarBlock">
<div
class="toolbarBtn"
:class="{
disabled: false,
}"
@click="$bus.$emit('execCommand', 'BACK')"
>
<span class="icon iconfont iconwithdraw"></span>
<span class="text">回退</span>
</div>
<div
class="toolbarBtn"
:class="{
disabled: false,
}"
@click="$bus.$emit('execCommand', 'FORWARD')"
>
<span class="icon iconfont iconqianjin"></span>
<span class="text">前进</span>
</div>
<div <div
class="toolbarBtn" class="toolbarBtn"
:class="{ :class="{