tanghaolin
2023-01-11 50ad0a40d942624f7fcdfa8af3bc67d656a747a3
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<template>
  <div class="flow">
    <div class="content">
      <!--左侧工具栏-->
      <div id="stencil" />
      <div class="panel">
        <!--流程图工具栏-->
        <div class="toolbar">
          <tool-bar v-if="isReady" />
        </div>
        <!--流程图画板-->
        <div id="container" />
      </div>
      <!--右侧工具栏-->
      <div class="config">
        <config-panel v-if="isReady" />
      </div>
    </div>
  </div>
</template>
<script>
import "./index.css";
import FlowGraph from "./graph";
import ToolBar from "./components/ToolBar/index.vue";
import ConfigPanel from "./components/ConfigPanel/index.vue";
import { $, getImg, getContainerSize } from "@/utils/util";
// import './shape'
import { customPorts, basicPorts } from "./graph/ports";
import graphData from "./graph/data/data";
export default {
  name:'x6_edit',
  data() {
    return {
      isReady: false,
      destroyFn: null,
    };
  },
  components: { ToolBar, ConfigPanel },
  mounted() {
    this.destroyFn = this.initGraph();
  },
  destroyed() {
    // 移除监听、销毁画布、资源回收
    this.destroyFn();
  },
  methods: {
    initGraph() {
      const graph = FlowGraph.init(
        $("#container"),
        $("#container").getBoundingClientRect().width,
        $("#container").getBoundingClientRect().height
      );
      this.isReady = true;
      graph.fromJSON(graphData);
      setTimeout(() => {
            graph.zoomToFit()
        }, 500);
      let option = {
        stencilGraphWidth: 260,
        collapsable: true,
        groups: [
          {
            name: "basic",
            title: "基础节点",
            graphHeight: 370,
          },
          {
            name: "custom-image",
            title: "系统设计图",
            graphHeight: 600,
          },
        ],
      };
      const stencil = FlowGraph.initStencil(option);
      this.initShape(graph, stencil);
      // const resizeFn = () => {
      //   const { width, height } = getContainerSize($('.panel'))
      //   graph.resize(width, height - 38)
      // }
      // resizeFn()
      // window.addEventListener('resize', resizeFn)
      return () => {
        // window.removeEventListener('resize', resizeFn)
        graph.dispose();
      };
    },
    initShape(graph, stencil) {
      // 基础节点
      const r1 = graph.createNode({
        shape: "flow-chart-rect1",
        attrs: {
          body: {
            rx: 24,
            ry: 24,
          },
          text: {
            text: "起始节点",
          },
        },
      });
 
      const r2 = graph.createNode({
        shape: "flow-chart-rect",
        attrs: {
          text: {
            text: "流程节点",
          },
        },
      });
      const r3 = graph.createNode({
        shape: "flow-chart-rect",
        width: 52,
        height: 52,
        angle: 45,
        attrs: {
          "edit-text": {
            style: {
              transform: "rotate(-45deg)",
            },
          },
          text: {
            text: "判断节点",
            transform: "rotate(-45deg)",
          },
        },
        ports: {
          groups: {
            top: {
              position: {
                name: "top",
                args: {
                  dx: -26,
                },
              },
            },
            right: {
              position: {
                name: "right",
                args: {
                  dy: -26,
                },
              },
            },
            bottom: {
              position: {
                name: "bottom",
                args: {
                  dx: 26,
                },
              },
            },
            left: {
              position: {
                name: "left",
                args: {
                  dy: 26,
                },
              },
            },
          },
        },
      });
      const r4 = graph.createNode({
        shape: "flow-chart-rect",
        width: 70,
        height: 70,
        attrs: {
          body: {
            rx: '50%',
            ry: '50%',
          },
          text: {
            text: "链接节点",
          },
        },
      });
      const r5 = graph.createNode({
        shape: "orNode",
        width: 70,
        height: 70,
        
      });
      const r6 = graph.createNode({
        shape: "andNode",
        width: 70,
        height: 70,
        
      });
 
      // 系统设计图
      const imgs = [
        {
          image: getImg("ldb.png"),
        },
        {
          image: getImg("wft1.png"),
        },
        {
          image: getImg("wft2.png"),
        },
        {
          image: getImg("wft3.png"),
        },
        {
          image: getImg("wft4.png"),
        },
        {
          image: getImg("wft5.png"),
        },
        {
          image: getImg("lqt.png"),
        },
        {
          image: getImg("lqb-o.png"),
        },
        {
          image: getImg("ldb-o.png"),
        },
        {
          image: getImg("bh.png"),
        },
        {
          image: getImg("f1.png"),
        },
        {
          image: getImg("f2.png"),
        },
        {
          image: getImg("f3.png"),
        },
      ];
      const imgNodes = imgs.map((item) => {
        return graph.createNode({
          shape: "image", //可选值:Rect Circle Ellipse Polygon Polyline Path Image HTML TextBlock BorderedImage EmbeddedImage InscribedImage Cylinder
          imageUrl: item.image,
          attrs: {
            image: {
              // fill: 'yellow',
            },
          },
          width: 52,
          height: 52,
          ports: { ...customPorts },
        });
      });
      stencil.load([r1, r2, r3, r4,r5,r6], "basic");
      stencil.load(imgNodes, "custom-image");
    },
  },
};
</script>
<style>
.x6-widget-snapline-vertical {
  border-right-color: #ff4e50 !important;
}
.x6-widget-snapline-horizontal {
  border-bottom-color: #ff4e50 !important;
}
.x6-widget-selection-box {
  border: 1px dashed #5f95ff;
  margin-top: -3px;
  margin-left: -3px;
}
.x6-widget-selection-inner {
  border: 1px dashed #5f95ff;
}
 
@keyframes stroke {
  100% {
    stroke-dashoffset: -400;
  }
}
.animate-text1,
.animate-text2,
.animate-text3,
.animate-text4 {
  font-weight: bold;
  fill: none;
  stroke-width: 2px;
  stroke-dasharray: 90 310;
  animation: stroke 3s infinite linear;
}
.animate-text1 {
  stroke: #873bf4;
  text-shadow: 0 0 2px #873bf4;
  animation-delay: -1.5s;
}
.animate-text2 {
  stroke: #ff6e06;
  text-shadow: 0 0 2px #ff6e06;
  animation-delay: -3s;
}
</style>