wangyanshen
2023-01-11 4638422d5a6b8146ec0f8ddd1bf17160330a2049
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<template>
  <div style="width: 100%;height: 100%;">
    <config-grid v-show="type === 'grid'" />
    <config-node v-show="type === 'node'" :id="id" />
    <config-edge v-show="type === 'edge'" :id="id" />
  </div>
</template>
 
<script>
import ConfigGrid from './ConfigGrid/index.vue'
import ConfigNode from './ConfigNode/index.vue'
import ConfigEdge from './ConfigEdge/index.vue'
import FlowGraph from '../../graph'
import './index.css'
export default {
  data() {
    return {
      type: 'grid',
      id: '',
    }
  },
  components:{
    ConfigGrid,
    ConfigNode,
    ConfigEdge
  },
  created() {
    this.boundEvent()
  },
  methods: {
    // 待优化
    boundEvent() {
      const { graph } = FlowGraph
      graph.on('blank:click', () => {
        this.type = "grid"
      })
      graph.on('cell:mousedown', ({ cell }) => {
        this.type = cell.isNode() ? "node" : "edge"
        this.id = cell.id
        if(this.type == "node") {
          let nodeType = cell['attrs']['image'] && cell['attrs']['image']['xlink:href'] ? 'image' : 'text'
          this.$store.commit('flow/updatenodeType', nodeType)
        }
      })
    }
  }
}
</script>