index.vue
9.84 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<template>
<div class="lshs-content">
<div class="slot">
<div><span class="tip-title">范围属性变更:</span></div>
<div><span class="tip-title">宗地分割:</span></div>
<div><span class="tip-title">宗地合并:</span></div>
</div>
<div id="mountNode" ref="containerWidth"></div>
</div>
</template>
<script>
import G6 from '@antv/g6';
import insertCss from 'insert-css';
import { getLshs } from "./../../../../src/api/fwsxbg";
export default {
name:"",
components:{},
props:{},
data(){
insertCss(`
.g6-tooltip {
border-radius: 6px;
font-size: 12px;
color: #fff;
background-color: #000;
padding: 2px 8px;
text-align: center;
}
`);
return {
data : {}
}
},
created(){
},
mounted(){
this.getLshsData();
},
methods: {
initG6() {
const data = this.data;
const eWidth = this.$refs.containerWidth.clientWidth
console.log(eWidth+":width")
G6.registerNode(
'sql',
{
drawShape(cfg, group) {
const rect = group.addShape('rect', {
attrs: {
x: -75,
y: -25,
width: 150,
height: 50,
radius: 10,
stroke: '#5B8FF9',
fill: '#C6E5FF',
lineWidth: 1,
},
name: 'rect-shape',
});
if (cfg.name) {
group.addShape('text', {
attrs: {
text: cfg.name,
x: 0,
y: 0,
fill: '#00287E',
fontSize: 14,
textAlign: 'center',
textBaseline: 'middle',
fontWeight: 'bold',
},
name: 'text-shape',
});
}
return rect;
},
},
'single-node',
);
G6.registerEdge(
'circle-running',
{
afterDraw(cfg, group) {
const shape = group.get('children')[0];
const startPoint = shape.getPoint(0);
const circle = group.addShape('circle', {
attrs: {
x: startPoint.x,
y: startPoint.y,
fill: '#1890ff',
r: 3,
},
name: 'circle-shape',
});
circle.animate(
(ratio) => {
const tmpPoint = shape.getPoint(ratio);
return {
x: tmpPoint.x,
y: tmpPoint.y,
};
},
{
repeat: true,
duration: 3000,
},
);
},
},
'line',
);
const tooltip = new G6.Tooltip({
offsetX: 210,
offsetY: 210,
itemTypes: ['node', 'edge'],
getContent: (e) => {
const outDiv = document.createElement('div');
outDiv.style.width = 'fit-content';
outDiv.innerHTML = `
<ul>
<li> ${e.item.getModel().conf[0].label}:${e.item.getModel().conf[0].value}</li>
<li> ${e.item.getModel().conf[1].label}:${e.item.getModel().conf[1].value}</li>
<li> ${e.item.getModel().conf[2].label}:${e.item.getModel().conf[2].value}</li>
<li> ${e.item.getModel().conf[3].label}:${e.item.getModel().conf[3].value}</li>
<li> ${e.item.getModel().conf[4].label}:${e.item.getModel().conf[4].value}</li>
</ul>`
;
return outDiv;
},
});
const container = document.getElementById('mountNode');
console.log(container)
const graph = new G6.Graph({
container: 'mountNode',
width:1000,
height:1000,
layout: {
type: 'dagre',
nodesepFunc: (d) => {
if (d.id === '3') {
return 500;
}
return 50;
},
ranksep: 70,
controlPoints: true,
},
defaultNode: {
type: 'sql',
},
defaultEdge: {
type: 'polyline',
style: {
radius: 20,
offset: 45,
endArrow: true,
lineWidth: 2,
stroke: 'rgba(78,142,230,0.45)',
},
},
// defaultEdge: {
// type: 'cubic-vertical',
// style: {
// stroke: '#F6BD16',
// },
// },
nodeStateStyles: {
selected: {
stroke: '#d9d9d9',
fill: '#5394ef',
},
},
plugins: [tooltip],
modes: {
default: [
'drag-node',
'drag-canvas',
'zoom-canvas',
'click-select',
],
},
// modes: {
// default: [
// 'drag-canvas',
// 'zoom-canvas',
// 'click-select',
// {
// type: 'tooltip',
// formatText(model) {
// const cfg = model.conf;
// const text = [];
// cfg.forEach((row) => {
// text.push(row.label + ':' + row.value + '<br>');
// });
// return text.join('\n');
// },
// offset: -30,
// },
// ],
// },
fitView: true,
});
graph.data(data);
graph.render();
graph.on('node:mouseenter', e => {
graph.setItemState(e.item, 'active', true)
});
graph.on('node:mouseleave', e => {
graph.setItemState(e.item, 'active', false)
});
graph.on('edge:mouseenter', e => {
graph.setItemState(e.item, 'active', true)
});
graph.on('edge:mouseleave', e => {
graph.setItemState(e.item, 'active', false)
});
if (typeof window !== 'undefined')
window.onresize = () => {
if (!graph || graph.get('destroyed')) return;
if (!container || !container.scrollWidth || !container.scrollHeight) return;
graph.changeSize(container.scrollWidth, container.scrollHeight);
};
},
getLshsData(){
let _this = this;
const data = {
"bsm": "c0818d9e4286b35b8ee9b96d90b522aa",
"type": "zd"
};
getLshs(data).then((res)=>{
if(res.code===200){
_this.data=res.result;
_this.data = {"nodes":[
{"id":"836524edab33ab19bb0e0b4fd064cd77","dataType":"sql","name":"20201127宗地A",
"conf":[{"label":"宗地代码","value":"610102123666GA10002"},{"label":"项目名称","value":"20201127宗地A"},
{"label":"不动产单元号","value":"610102123666GA10002W00000000"},{"label":"坐落","value":"610102123666G10003W"},
{"label":"权利人","value":""}]},
{"id":"601130536a6bf6efc7a248af469e982c","dataType":"sql","name":"20201127宗地A222221",
"conf":[{"label":"宗地代码","value":null},{"label":"项目名称","value":"20201127宗地A222221"},
{"label":"不动产单元号","value":null},{"label":"坐落","value":null},{"label":"权利人","value":""}]},
{"id":"c0818d9e4286b35b8ee9b96d90b522aa","dataType":"sql","name":"20201127宗地A2222222",
"conf":[{"label":"宗地代码","value":null},{"label":"项目名称","value":"20201127宗地A2222222"},
{"label":"不动产单元号","value":null},{"label":"坐落","value":null},{"label":"权利人","value":""}]},
{"id":"601130536a6bf6efc7a248af469e982c1","dataType":"sql","name":"20201127宗地B",
"conf":[{"label":"宗地代码","value":null},{"label":"项目名称","value":"20201127宗地B"},
{"label":"不动产单元号","value":null},{"label":"坐落","value":null},{"label":"权利人","value":""}]},
{"id":"c0818d9e4286b35b8ee9b96d90b522aa1","dataType":"sql","name":"20201127宗地B1",
"conf":[{"label":"宗地代码","value":null},{"label":"项目名称","value":"20201127宗地B1"},
{"label":"不动产单元号","value":null},{"label":"坐落","value":null},{"label":"权利人","value":""}]},
{"id":"c0818d9e4286b35b8ee9b96d90b522aa12","dataType":"sql","name":"20201127宗地C",
"conf":[{"label":"宗地代码","value":null},{"label":"项目名称","value":"20201127宗地C"},
{"label":"不动产单元号","value":null},{"label":"坐落","value":null},{"label":"权利人","value":""}]},
],
"edges":[
{"source":"836524edab33ab19bb0e0b4fd064cd77","target":"601130536a6bf6efc7a248af469e982c"},
{"source":"836524edab33ab19bb0e0b4fd064cd77","target":"c0818d9e4286b35b8ee9b96d90b522aa"},
{"source":"c0818d9e4286b35b8ee9b96d90b522aa","target":"601130536a6bf6efc7a248af469e982c1"},
{"source":"c0818d9e4286b35b8ee9b96d90b522aa","target":"c0818d9e4286b35b8ee9b96d90b522aa1"},
{"source":"601130536a6bf6efc7a248af469e982c1","target":"c0818d9e4286b35b8ee9b96d90b522aa12"},
{"source":"c0818d9e4286b35b8ee9b96d90b522aa1","target":"c0818d9e4286b35b8ee9b96d90b522aa12"},
]};
this.initG6();
}
})
}
},
computed: {},
watch: {},
}
</script>
<style scoped lang="less">
.lshs-content{
width: 100%;
}
#mountNode{
margin-left: 200px;
}
.slot{
margin-left: 50px;
margin-top: 20px;
width: 300px;
}
.tip-title{
font-weight: 700;
}
</style>