工作流部分数据重构
This commit is contained in:
parent
c3268b5511
commit
5a6a4f6db3
|
|
@ -52,16 +52,11 @@ export default {
|
|||
if (!(node && node.id)) {
|
||||
return []
|
||||
}
|
||||
console.log(node.name, "node.name", node.id, "node.id")
|
||||
if (this.isPrimaryNode(node)) {
|
||||
|
||||
//普通业务节点
|
||||
console.log("node name", node.name, "id", node.id, "parentId", node.parentId)
|
||||
let childDoms = this.getDomTree(h, node.id)
|
||||
this.decodeAppendDom(h, node, childDoms)
|
||||
return [h('div', {'class': {'primary-node': true}}, childDoms)];
|
||||
|
||||
|
||||
} else if (this.isBranchNode(node)) {
|
||||
let index = 0;
|
||||
//遍历分支节点,包含并行及条件节点
|
||||
|
|
@ -97,52 +92,6 @@ export default {
|
|||
}
|
||||
return []
|
||||
},
|
||||
|
||||
|
||||
getDomTreeOld(h, node) {
|
||||
this.toMapping(node);
|
||||
if (this.isPrimaryNode(node)) {
|
||||
//普通业务节点
|
||||
let childDoms = this.getDomTreeOld(h, node.children)
|
||||
this.decodeAppendDom(h, node, childDoms)
|
||||
return [h('div', {'class': {'primary-node': true}}, childDoms)];
|
||||
} else if (this.isBranchNode(node)) {
|
||||
let index = 0;
|
||||
//遍历分支节点,包含并行及条件节点
|
||||
let branchItems = node.branchs.map(branchNode => {
|
||||
//处理每个分支内子节点
|
||||
this.toMapping(branchNode);
|
||||
let childDoms = this.getDomTreeOld(h, branchNode.children)
|
||||
this.decodeAppendDom(h, branchNode, childDoms, {level: index + 1, size: node.branchs.length})
|
||||
//插入4条横线,遮挡掉条件节点左右半边线条
|
||||
this.insertCoverLine(h, index, childDoms, node.branchs)
|
||||
//遍历子分支尾部分支
|
||||
index++;
|
||||
return h('div', {'class': {'branch-node-item': true}}, childDoms);
|
||||
})
|
||||
//插入添加分支/条件的按钮
|
||||
branchItems.unshift(h('div', {'class': {'add-branch-btn': true}}, [
|
||||
h('el-button', {
|
||||
'class': {'add-branch-btn-el': true},
|
||||
props: {size: 'small', round: true},
|
||||
on: {click: () => this.addBranchNode(node)},
|
||||
domProps: {innerHTML: `添加${this.isConditionNode(node) ? '条件' : '分支'}`},
|
||||
}, [])
|
||||
]));
|
||||
let bchDom = [h('div', {'class': {'branch-node': true}}, branchItems)]
|
||||
//继续遍历分支后的节点
|
||||
let afterChildDoms = this.getDomTreeOld(h, node.children)
|
||||
return [h('div', {}, [bchDom, afterChildDoms])]
|
||||
} else if (this.isEmptyNode(node)) {
|
||||
//空节点,存在于分支尾部
|
||||
let childDoms = this.getDomTreeOld(h, node.children)
|
||||
this.decodeAppendDom(h, node, childDoms)
|
||||
return [h('div', {'class': {'empty-node': true}}, childDoms)];
|
||||
} else {
|
||||
//遍历到了末端,无子节点
|
||||
return [];
|
||||
}
|
||||
},
|
||||
//解码渲染的时候插入dom到同级
|
||||
decodeAppendDom(h, node, dom, props = {}) {
|
||||
props.config = node
|
||||
|
|
@ -171,7 +120,6 @@ export default {
|
|||
//id映射到map,用来向上遍历
|
||||
toMapping(node) {
|
||||
if (node && node.id) {
|
||||
//console.log("node=> " + node.id + " name:" + node.name + " type:" + node.type)
|
||||
let newNode = {
|
||||
...node
|
||||
}
|
||||
|
|
@ -205,7 +153,7 @@ export default {
|
|||
parentNode.branchs.splice(parentNode.branchs.indexOf(node), 0, branchNode)
|
||||
this.$forceUpdate()
|
||||
},
|
||||
//移动节点
|
||||
//移动分支节点
|
||||
branchMove(node, offset) {
|
||||
let parentNode = this.nodeMap.get(node.parentId)
|
||||
let index = parentNode.branchs.indexOf(node)
|
||||
|
|
@ -250,15 +198,12 @@ export default {
|
|||
//处理节点插入逻辑
|
||||
insertNode(type, parentNode) {
|
||||
this.$refs['_root'].click()
|
||||
//缓存一下后面的节点
|
||||
console.log(parentNode)
|
||||
//插入新节点
|
||||
let id = this.getRandomId();
|
||||
this.updateParentId(id, parentNode.id)
|
||||
let children = {
|
||||
id: id,
|
||||
parentId: parentNode.id,
|
||||
// props: {},
|
||||
type: type,
|
||||
}
|
||||
switch (type) {
|
||||
|
|
@ -417,12 +362,6 @@ export default {
|
|||
this.dom.push(emptyNode)
|
||||
},
|
||||
|
||||
getBranchEndNode(conditionNode) {
|
||||
if (!conditionNode.children || !conditionNode.children.id) {
|
||||
return conditionNode;
|
||||
}
|
||||
return this.getBranchEndNode(conditionNode.children);
|
||||
},
|
||||
addBranchNode(node) {
|
||||
if (node.branchs.length < 8) {
|
||||
node.branchs.push({
|
||||
|
|
@ -438,7 +377,6 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
|
||||
//删除当前节点
|
||||
delNode(node) {
|
||||
//获取该节点的父节点
|
||||
|
|
@ -494,7 +432,7 @@ export default {
|
|||
//更改分支上第一个节点的父id
|
||||
this.updateParentId(parentNode.parentId,sunNode.parentId)
|
||||
//找到最后一个节点
|
||||
let lastNode = this.getLastNode(sunNode.id)
|
||||
let lastNode = this.getLastBranchNode(sunNode.id)
|
||||
let emptyNode = this.parentMap.get(parentNode.id)
|
||||
//更新空节点下的第一个节点的id为当前分支最后一个节点
|
||||
this.updateParentId(lastNode.id,emptyNode.id)
|
||||
|
|
@ -511,10 +449,10 @@ export default {
|
|||
}
|
||||
},
|
||||
//获取最后一个节点
|
||||
getLastNode(id){
|
||||
getLastBranchNode(id){
|
||||
let node = this.parentMap.get(id)
|
||||
if (node){
|
||||
return this.getLastNode(node.id)
|
||||
return this.getLastBranchNode(node.id)
|
||||
}else {
|
||||
return this.nodeMap.get(id)
|
||||
}
|
||||
|
|
@ -582,23 +520,6 @@ export default {
|
|||
}
|
||||
})
|
||||
},
|
||||
validateOld(err, node) {
|
||||
if (this.isPrimaryNode(node)) {
|
||||
this.validateNode(err, node)
|
||||
this.validate(err, node.children)
|
||||
} else if (this.isBranchNode(node)) {
|
||||
//校验每个分支
|
||||
node.branchs.map(branchNode => {
|
||||
//校验条件节点
|
||||
this.validateNode(err, branchNode)
|
||||
//校验条件节点后面的节点
|
||||
this.validate(err, branchNode.children)
|
||||
})
|
||||
this.validate(err, node.children)
|
||||
} else if (this.isEmptyNode(node)) {
|
||||
this.validate(err, node.children)
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue