|
@@ -643,6 +643,10 @@ const { line} = configOpt;
|
|
|
canUndo:false,
|
|
|
canRedo:false,
|
|
|
mindmapDataUse:[],
|
|
|
+ mindmapAssistData:{
|
|
|
+ mindmapDataRecoverUse:[],//用于恢复撤销和重做时被删除的思维导图数据
|
|
|
+ mindmapDataRecoverPtr:-1, //当前索引
|
|
|
+ },
|
|
|
sandSaveParams:{
|
|
|
Name:'',
|
|
|
SandboxClassifyId:'',
|
|
@@ -878,43 +882,41 @@ const { line} = configOpt;
|
|
|
},
|
|
|
// 初始化画布
|
|
|
init() {
|
|
|
- const graph = new myGraph('sand-chart-container',this.mindmapDataUse);
|
|
|
+ const graph = new myGraph('sand-chart-container',this.mindmapDataUse,this.mindmapAssistData);
|
|
|
graph.history.on('change', (args) => {
|
|
|
// console.log(args,'change-history');
|
|
|
this.canUndo = graph.canUndo()
|
|
|
this.canRedo = graph.canRedo()
|
|
|
// console.log(this.canUndo,this.canRedo);
|
|
|
})
|
|
|
- // graph.history.on('undo', (args) => {
|
|
|
- // // console.log(args,'undo-history');
|
|
|
- // for (let i = 0; i < args.cmds.length; i++) {
|
|
|
- // const element = args.cmds[i];
|
|
|
- // if(element.data.props.shape.indexOf('mindmap')!=-1 && element.data.node){
|
|
|
- // console.log(element,'element.data.props');
|
|
|
- // if(element.event== 'cell:added'){
|
|
|
-
|
|
|
- // //撤销是添加,意味着要从数据源删除
|
|
|
- // let ids = element.data.props.id.split('-').map(id => +id)
|
|
|
- // let start=ids[0]-1,end=ids[ids.length-1]-1;
|
|
|
- // let operationMindmap = this.mindmapDataUse[start].mindmapData
|
|
|
- // ids.map((item,index)=>{
|
|
|
- // if(index==0 || index==(ids.length-1)) return
|
|
|
- // console.log(operationMindmap,index,'operationMindmap');
|
|
|
- // operationMindmap=operationMindmap.children[(item-1)]
|
|
|
- // })
|
|
|
- // operationMindmap.children.splice(end,1)
|
|
|
- // console.log(operationMindmap,ids);
|
|
|
- // }
|
|
|
- // console.log(element,i);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // console.log(this.mindmapDataUse);
|
|
|
- // })
|
|
|
- // graph.history.on('redo', (args) => {
|
|
|
- // console.log(args,'redo-history');
|
|
|
-
|
|
|
- // // console.log(this.canUndo,this.canRedo);
|
|
|
- // })
|
|
|
+ graph.history.on('undo', (args) => {
|
|
|
+ console.log(args,'undo-history');
|
|
|
+ // let ids=[]
|
|
|
+ let mindmapNodes=args.cmds.filter(it => it.data.props && it.data.props.shape.indexOf('mindmap')!=-1 && it.data.node)
|
|
|
+ if(!(mindmapNodes && mindmapNodes.length>0)) return
|
|
|
+ // console.log(mindmapNodes,'mindmapNodes');
|
|
|
+ let mindmapUndoType=mindmapNodes[0].event
|
|
|
+ if(mindmapUndoType=="cell:added"){
|
|
|
+ this.mindmapRecoverRemove(mindmapNodes)
|
|
|
+ }else if(mindmapUndoType=="cell:removed"){
|
|
|
+ this.mindmapRecoverAdd()
|
|
|
+ }
|
|
|
+ console.log(this.mindmapDataUse);
|
|
|
+ })
|
|
|
+ graph.history.on('redo', (args) => {
|
|
|
+ console.log(args,'redo-history');
|
|
|
+ // let ids=[]
|
|
|
+ let mindmapNodes=args.cmds.filter(it => it.data.props && it.data.props.shape.indexOf('mindmap')!=-1 && it.data.node)
|
|
|
+ if(!(mindmapNodes && mindmapNodes.length>0)) return
|
|
|
+ // console.log(mindmapNodes,'mindmapNodes');
|
|
|
+ let mindmapUndoType=mindmapNodes[0].event
|
|
|
+ if(mindmapUndoType=="cell:added"){
|
|
|
+ this.mindmapRecoverAdd()
|
|
|
+ }else if(mindmapUndoType=="cell:removed"){
|
|
|
+ this.mindmapRecoverRemove(mindmapNodes)
|
|
|
+ }
|
|
|
+ console.log(this.mindmapDataUse,'mindmapDataUse');
|
|
|
+ })
|
|
|
graph.on('node:mouseenter', ({ node, e }) => {
|
|
|
console.log(node);
|
|
|
let data = node.data
|
|
@@ -1044,7 +1046,8 @@ const { line} = configOpt;
|
|
|
}
|
|
|
},
|
|
|
generateMindmapData(position,addType){
|
|
|
- let beId=this.mindmapDataUse.length+1+''
|
|
|
+ let beId=this.mindmapDataUse.length>0?
|
|
|
+ parseInt(this.mindmapDataUse[this.mindmapDataUse.length-1].mindmapData.id)+1+'':'1'
|
|
|
let mindmapData={
|
|
|
id: beId,
|
|
|
type: 'topic',
|
|
@@ -1821,7 +1824,71 @@ const { line} = configOpt;
|
|
|
this.$nextTick(()=>{
|
|
|
this.popoverVisible=true
|
|
|
})
|
|
|
- },200)
|
|
|
+ },200) ,
|
|
|
+ mindmapRecoverRemove(mindmapNodes){
|
|
|
+ let shouldOperations=[]
|
|
|
+ this.mindmapDataUse.map((item,index)=>{
|
|
|
+ let levelIds = mindmapNodes.filter(mindMap => mindMap.data.id.startsWith(item.mindmapData.id)).map(mindMap => mindMap.data.id)
|
|
|
+ console.log(levelIds,'levelIds');
|
|
|
+ if(!(levelIds && levelIds.length>0)) return
|
|
|
+ // console.log(levelIds,'levelIds');
|
|
|
+ let mindMapIds=[...levelIds]
|
|
|
+ for (let i = 0; i < levelIds.length; i++) {
|
|
|
+ const element = levelIds[i]
|
|
|
+ mindMapIds=mindMapIds.filter( id => id.indexOf(element) !=0 || id==element)
|
|
|
+ }
|
|
|
+ console.log(mindMapIds,'mindMapIds');
|
|
|
+ shouldOperations.push(mindMapIds)
|
|
|
+ })
|
|
|
+ // 重做删除时 恢复数据指针回退
|
|
|
+ // if(
|
|
|
+ // this.mindmapAssistData.mindmapDataRecoverPtr==(this.mindmapAssistData.mindmapDataRecoverUse.length-1)){
|
|
|
+ // // this.mindmapAssistData.mindmapDataRecoverPtr--
|
|
|
+ this.mindmapAssistData.mindmapDataRecoverUse.push(JSON.stringify(this.mindmapDataUse))
|
|
|
+ // }
|
|
|
+ this.mindmapAssistData.mindmapDataRecoverPtr++
|
|
|
+ console.log(this.mindmapAssistData.mindmapDataRecoverUse[this.mindmapAssistData.mindmapDataRecoverPtr],
|
|
|
+ this.mindmapDataUse,this.mindmapAssistData.mindmapDataRecoverPtr,this.mindmapAssistData.mindmapDataRecoverUse.length,
|
|
|
+ 'this.mindmapAssistData.mindmapDataRecoverPtr');
|
|
|
+ console.log(shouldOperations,'shouldOperations');
|
|
|
+ shouldOperations.map(it =>{
|
|
|
+ it.map(it1 =>{
|
|
|
+ this.deleteMindmapData(it1,this.mindmapDataUse)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ mindmapRecoverAdd(){
|
|
|
+ // 重做添加时 恢复数据指针前进
|
|
|
+ this.mindmapDataUse=JSON.parse(this.mindmapAssistData.mindmapDataRecoverUse[this.mindmapAssistData.mindmapDataRecoverPtr])
|
|
|
+ this.mindmapAssistData.mindmapDataRecoverUse.pop()
|
|
|
+ this.mindmapAssistData.mindmapDataRecoverPtr--
|
|
|
+ console.log(this.mindmapAssistData.mindmapDataRecoverUse[this.mindmapAssistData.mindmapDataRecoverPtr],
|
|
|
+ this.mindmapDataUse,this.mindmapAssistData.mindmapDataRecoverPtr,this.mindmapAssistData.mindmapDataRecoverUse.length,
|
|
|
+ 'this.mindmapAssistData.mindmapDataRecoverPtr');
|
|
|
+ },
|
|
|
+ deleteMindmapData(id,data){
|
|
|
+ console.log(id,data,'id,data');
|
|
|
+ // return
|
|
|
+ let ids = id.split('-')
|
|
|
+ let mindmapDataIndex = data.findIndex(mindmap => mindmap.mindmapData.id == ids[0])
|
|
|
+ if(ids.length==1){
|
|
|
+ data.splice(mindmapDataIndex,1)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let mindmapData = data[mindmapDataIndex].mindmapData
|
|
|
+ let findId = ids[0]
|
|
|
+ for (let i = 1; i < ids.length-1; i++) {
|
|
|
+ const element = ids[i];
|
|
|
+ findId = findId+'-'+element
|
|
|
+ mindmapData=mindmapData.children.find(it => it.id==findId)
|
|
|
+ }
|
|
|
+ let endId = ids[ids.length-1]
|
|
|
+ console.log(mindmapData.children,'mindmapData.children');
|
|
|
+ let endIndex = mindmapData.children.findIndex(it => it.id == findId+'-'+endId)
|
|
|
+ mindmapData.children.splice(endIndex,1)
|
|
|
+ // console.log(data);
|
|
|
+ }
|
|
|
},
|
|
|
}
|
|
|
</script>
|