|
@@ -43,9 +43,9 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
- this.baseNode = baseNode
|
|
|
+ this.baseNode = baseNode //默认节点样式
|
|
|
return {
|
|
|
- graph:null,
|
|
|
+ graph:null,//画布对象
|
|
|
/* contextMenu:[{
|
|
|
label: '编辑',
|
|
|
key: 'edit',
|
|
@@ -56,11 +56,12 @@ export default {
|
|
|
key: 'del',
|
|
|
icon: 'el-icon-delete'
|
|
|
}], *///右键菜单
|
|
|
- isSelectEdge:false,
|
|
|
- isSelectNode:false,
|
|
|
- currentCell:null,
|
|
|
- canRedo:false,
|
|
|
- canUndo:false,
|
|
|
+ isSelectEdge:false,//是否选择了边
|
|
|
+ isSelectNode:false,//是否选择了节点
|
|
|
+ currentCell:null,//当前选中的元素
|
|
|
+ canRedo:false,//是否能前进
|
|
|
+ canUndo:false,//是否能后退
|
|
|
+ cleanSelect:false,//是否清除选区
|
|
|
};
|
|
|
},
|
|
|
watch:{
|
|
@@ -69,12 +70,12 @@ export default {
|
|
|
this.currentCell = null
|
|
|
}
|
|
|
},
|
|
|
- FrameworkContent(newVal){
|
|
|
+ FrameworkContent(newVal){//当框架内容发生改变时,画布内容也发生改变
|
|
|
newVal.length&&this.gragh&&this.graph.fromJSON(JSON.parse(newVal))
|
|
|
}
|
|
|
},
|
|
|
computed:{
|
|
|
- contextMenu(){
|
|
|
+ contextMenu(){//右键菜单,根据权限配置
|
|
|
const editOption = {label: '编辑',key: 'edit',icon: 'el-icon-edit'}
|
|
|
const deleteOption = {label: '删除',key: 'del',icon: 'el-icon-delete'}
|
|
|
let MenuArr = []
|
|
@@ -86,9 +87,11 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ //初始化画布
|
|
|
init(){
|
|
|
//如果需要在内部调用vue实例,则初始化时就将this传入
|
|
|
this.graph = new myGraph('frameContainer',this)
|
|
|
+ //如果有内容,初始化画布内容
|
|
|
this.FrameworkContent.length&&this.graph.fromJSON(JSON.parse(this.FrameworkContent))
|
|
|
//如果有内容,将画布内容居中
|
|
|
this.FrameworkContent.length&&this.graph.scrollToContent({ animation: { duration: 600 }})
|
|
@@ -97,9 +100,11 @@ export default {
|
|
|
//如果是编辑页,加载完成后清除历史数据
|
|
|
!window.location.pathname.startsWith('/chartframe')&&this.graph.cleanHistory()
|
|
|
},
|
|
|
+ //销毁画布
|
|
|
dispose(){
|
|
|
this.graph&&this.graph.dispose()
|
|
|
},
|
|
|
+ //添加/编辑节点
|
|
|
editNode(node){
|
|
|
//获取视口范围
|
|
|
const position = this.graph.getContentArea()
|
|
@@ -126,6 +131,7 @@ export default {
|
|
|
}})
|
|
|
}
|
|
|
},
|
|
|
+ //点击右键菜单事件
|
|
|
handleContext(key){
|
|
|
const select_cell = this.graph.getSelectedCells()
|
|
|
if(!select_cell.length) return
|
|
@@ -134,10 +140,10 @@ export default {
|
|
|
const {id} = select_cell[0]
|
|
|
const node = this.graph.getNodes().find(item=>item.id===id)
|
|
|
this.$emit('editNode',{
|
|
|
- nodeId:node.id,
|
|
|
- nodeName:node.label,
|
|
|
- nodeLink:node.data.nodeLink
|
|
|
- })
|
|
|
+ nodeId:node.id,
|
|
|
+ nodeName:node.label,
|
|
|
+ nodeLink:node.data.nodeLink
|
|
|
+ })
|
|
|
}
|
|
|
if(key==='del'){
|
|
|
this.graph.removeCells(select_cell)
|
|
@@ -151,6 +157,7 @@ export default {
|
|
|
dom.style.left = '-9999px';
|
|
|
dom.style.top = '-9999px';
|
|
|
},
|
|
|
+ //获取画布内容的svg数据
|
|
|
getContentPic(){
|
|
|
const { cells } = this.graph.toJSON();
|
|
|
let svgData = ''
|
|
@@ -180,6 +187,7 @@ export default {
|
|
|
})
|
|
|
return svgData
|
|
|
},
|
|
|
+ //获取画布节点并转换成对应格式
|
|
|
getContentNodes(){
|
|
|
return this.graph.getNodes().map(node=>{
|
|
|
return {
|