trackDialog.vue
18.6 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
<template>
<el-dialog :visible.sync="isShow" class="manage-dialog xy-dialog track-dialog" :close-on-click-modal="false" :before-close="closeDialog">
<div slot="title">
<span class="dialog-title">{{ $t('button.showTrack') }}</span>
<div class="replay" @click="rePlay">
<i class="icon font_family icon-reload" title="重新播放"></i>
</div>
</div>
<!-- <div class="total-box">
游逛区域: {{ zoneNum }} 个, 共停留 {{ totalZL }} 秒
</div> -->
<!-- 动线图 -->
<div class="track-box" v-loading="loading">
<div ref="graphContainer" class="graph-container">
<!-- <img :src="floorSrc" class="background-img" alt="" /> -->
<template v-for="(item, index) in graphBgList">
<img :id="item.id" :key="item.onlyId" :src="item.src" :data-index="index" @load="imgLoaded(item.id)" :style="{ height: item.height + 'px' }" class="background-img" />
</template>
<div class="graph-chart-container">
<!-- <div id="graphChart" class="graph-box"></div> -->
<div id="graphChart" class="graph-box" v-if="imgWidth && graphBgList.length > 0 && loadedImgList.length === graphBgList.length"></div>
</div>
</div>
<div class="track-list-right">
<el-scrollbar class="track-list-scrollbar" wrap-class="list-scrollbar" :native="false">
<ul class="catch-pic-list">
<li v-for="(picItem, index) in picList" :key="index" class="catch-pic-item">
<el-popover placement="right" title="" trigger="hover">
<img :src="picItem" class="catch-pic" @error="dealErrImg($event)" slot="reference" />
<img :src="picItem" class="zoomin-catch-pic" @error="dealErrImg($event)" />
</el-popover>
</li>
</ul>
</el-scrollbar>
</div>
</div>
</el-dialog>
</template>
<script>
// import defaultImg from './hwArea.jpg'
import defaultFace from '@/assets/img/behavior/default.png'
import defaultHwImg from '@/assets/img/customer/hwshg.jpg'
import defaultBlImg from '@/assets/img/customer/bailian.svg'
export default {
data() {
return {
isShow: false,
loading: true,
personUnid: '',
parameter: null,
// floorSrc: '',
graphBgList: [],
loadedImgList: [],
imgWidth: 0,
// firstFlag: true,
// naturalWidth: '',
// naturalHeight: '',
nodeDic: {},
graphData: [],
linkData: [],
myEchart: null,
picList: [],
dataLen: null,
timerObj: {},
linkTimer: {},
trafficData: [],
durationData: [],
idArr: [],
nodeInstance: {},
timeInstance: {},
totalKL: null,
totalZL: null,
// zoneNum: null,
// defaultImg: ''
}
},
watch: {
loadedImgList: {
handler(val) {
if (this.graphBgList.length && val.length === this.graphBgList.length) {
this.getChartData()
}
},
deep: true
}
},
methods: {
dialogInit(personUnid, _param) {
this.loading = true
this.personUnid = personUnid
this.parameter = _param
this.isShow = true
this.timerObj = {}
this.graphBgList = []
this.loadedImgList = []
this.$nextTick(() => {
const imageHeight = Math.floor(this.$refs.graphContainer.offsetHeight / _param.asis_bg.length)
this.graphBgList = _param.asis_bg.reduce((prev, cur) => {
cur.height = imageHeight
prev.push(cur)
return prev
}, [])
})
},
rePlay() {
if(!this.myEchart) return
for (let i = 0; i < this.dataLen; i++) {
clearTimeout(this.timerObj[i])
clearTimeout(this.linkTimer[i])
}
this.loading = true
this.myEchart.clear()
this.graphData = []
this.linkData = []
this.picList = []
this.trafficData = []
this.durationData = []
this.idArr = []
this.getChartData()
},
imgLoaded(domId) {
const { offsetWidth } = this.queryIdDom(domId)
this.imgWidth = offsetWidth > this.imgWidth ? offsetWidth : this.imgWidth
this.loadedImgList.push(offsetWidth)
},
dealErrImg(e) {
let ev = e || window.event;
ev.target.src = defaultFace;
},
getDomAttrs(nodeId) {
const { queryIdDom, gateFloorMap } = this
try {
const { dataset, offsetHeight, offsetWidth } = queryIdDom(nodeId)
const index = dataset.index
return {
width: offsetWidth,
height: offsetHeight,
index: index
}
} catch(err) {
console.log(err)
return {
width: 0,
height: 0,
index: 0
}
}
},
queryIdDom(id) {
return document.getElementById(id)
},
fetchTrack() {
const { asis_org, asis_time } = this.parameter
return new Promise(resolve => {
this.$api.customerReport.movingLineReport(this.personUnid, {
orgIds: asis_org,
orgType: 'mall',
startDate: asis_time,
endDate: asis_time,
})
.then(res => {
resolve(res)
})
.catch(err => {
console.error(err)
this.catchErrorHandle(err)
})
})
},
// 并发渲染
async getChartData() {
this.totalKL = null
this.totalZL = null
this.nodeInstance = {}
this.timeInstance = {}
this.nodeDic = {}
// this.zoneNum = null
const { data } = await this.fetchTrack()
// 初始化画布
this.initCanvas()
this.loading = false
// 处理node link pie
this.loadInOrder(data.data)
},
async loadInOrder(data) {
this.dataLen = data.length
// 布局定点
const containerFixedNode = [
{
id: -1, name: 'startPoint', value: -1, x: '0', y: '0', symbolSize: 0, label: { show: false }
},
{
id: -2, name: 'endPoint', value: -1, x: Math.max(...this.loadedImgList), y: this.$refs.graphContainer.offsetHeight, symbolSize: 0, label: { show: false }
}
]
this.graphData = [...containerFixedNode]
// 并发处理 node 和 links
const graphDataPromises = this.dealGraph(data)
// Graph Pie 按次序渲染
for (let i = 0, len = graphDataPromises.length; i < len; i++) {
await this.sleep(i, graphDataPromises[i], 1000)
}
},
// 按次序输出
sleep(index, data, time) {
return new Promise(resolve => {
this.timerObj[index] = setTimeout(() => {
this.drawChart(index, data)
resolve()
}, time)
})
},
dealGraph(data) {
data.forEach(item => {
// source
item.source = String(item.source)
if (item.source_floor) {
let sourceXY = this.dealXY(item.source_floor, item.sourceX, item.sourceY)
item.sourceX = String(sourceXY.x)
item.sourceY = String(sourceXY.y)
}
item.target = item.target ? String(item.target) : null
if (item.target_floor) {
let targetXY = this.dealXY(item.target_floor, item.targetX, item.targetY)
item.targetX = String(targetXY.x)
item.targetY = String(targetXY.y)
}
// nodeDic
if (!this.nodeDic[item.source]) {
this.nodeDic[item.source] = {
id: item.source,
name: item.sourceName,
x: item.sourceX,
y: item.sourceY
}
}
// nodeInstance
if (typeof this.nodeInstance[item.source] === 'undefined') {
this.nodeInstance[item.source] = 1
} else {
this.nodeInstance[item.source] += 1
}
// timeInstance
if (typeof this.timeInstance[item.source] === 'undefined') {
this.timeInstance[item.source] = item.sourceTrackTime
} else {
this.timeInstance[item.source] += item.sourceTrackTime
}
})
return data
},
addPics({ sourceCountdate, sourceChannelSeries, sourcePic }) {
const dateS = sourceCountdate.replace(/^(\d{4})-(\d{2})-(\d{2}).*$/, '$1$2$3')
const fullPicPath = `${window._vionConfig.picUrl}/picture/face/${dateS}/${sourceChannelSeries}/${sourcePic}`
this.picList.unshift(fullPicPath)
},
/**
* 处理 相对点位
* source_floor | target_floor
* sourceX | targetX
* sourceY | targetY
*/
dealXY(...args) {
if (!args[0]) return
const { getDomAttrs, normalWidth, normalHeight } = this
const { width, height, index } = getDomAttrs(args[0])
return {
x: args[1] ? (args[1] / normalWidth * width).toFixed(2) : 0,
y: args[2] ? ((args[2] / normalHeight * height) + height * (index - 0)).toFixed(2) : 0
}
},
initCanvas() {
// if (this.myEchart) return
let chartDom = document.getElementById('graphChart')
chartDom.style.width = this.imgWidth + 'px'
chartDom.style.height = this.$refs.graphContainer.offsetHeight + 'px'
if (this.$echarts.getInstanceByDom(chartDom)) {
this.$echarts.init(chartDom).dispose()
this.myEchart = this.$echarts.init(chartDom)
} else {
this.myEchart = this.$echarts.init(chartDom)
}
const option = {
tooltip: {},
color: '#4054af',
series: [
{
top: 0,
left: 0,
right: 0,
bottom: 1,
edgeSymbol: ['none', 'arrow'],
categories: [],
type: 'graph',
layout: 'none',
data: [],
links: [],
z: 3,
label: {
normal: {
show: true,
position: 'right',
formatter: '{b}'
}
},
lineStyle: {
normal: {
color: 'source',
curveness: 0.3
}
}
}
]
}
// this.myEchart.clear()
this.myEchart.setOption(option)
},
drawChart(index, data) {
this.dealNodeData(data)
// 抓拍图片
this.addPics(data)
this.dealPieData(data.sourceName)
const centerData = [data.sourceX, data.sourceY]
let option = this.myEchart.getOption()
if (option.series.length > 0) {
option.series[0].data = this.graphData
}
if(this.idArr.indexOf(data.source) > -1) {
option.series.forEach(item => {
if('kl' + item.id === 'kl' + data.source) {
item.data = this.trafficData
} else if('zl' + item.id === 'zl' + data.source) {
item.data = this.durationData
}
})
} else {
this.idArr.push(data.source)
option.series.push(...this.drawNodePie(data.source, centerData))
}
this.myEchart.setOption(option)
// 绘制 link
this.linkTimer[index] = setTimeout(() => {
this.dealLinkData(data)
option.series[0].links = this.linkData
this.myEchart.setOption(option)
}, 1000)
},
// 关系图 点位 node
dealNodeData({ source, sourceName, sourceX, sourceY }) {
if (source) {
const isExist = this.graphData.some(item => item.id === source)
if (isExist) {
this.graphData.forEach((item, index) => {
if (item.id === source) {
item.value += 1
item.symbolSize = 5
}
})
} else {
this.graphData.push({
id: source,
name: sourceName,
x: sourceX,
y: sourceY,
value: 1,
symbolSize: 5
})
}
}
},
// 关系图 线
dealLinkData({ source, target }) {
// if (this.linkData.length > 0) {
if (target) {
const isExist = this.linkData.some(item => {
return item.source === source && item.target === target
})
if (isExist) {
this.linkData.forEach((item, linkIndex) => {
if (item.source === source && item.target === target) {
item.value += 1;
item.lineStyle = {
normal: {
width: item.value
}
}
}
})
} else {
this.linkData.push({
source: source,
target: target,
value: 1
})
}
}
// } else {
// this.linkData.push({
// source: source,
// target: target,
// value: 1
// })
// }
},
// 饼图 匹配当前节点
dealPieData(sourceName) {
this.trafficData = []
this.durationData = []
this.trafficData = Object.keys(this.nodeInstance).reduce((prev, i) => {
// this.zoneNum++
this.totalKL += this.nodeInstance[i]
prev.push({
name: this.nodeDic[i].name,
value: this.nodeInstance[i]
})
return prev
}, [])
this.durationData = Object.keys(this.timeInstance).reduce((prev, i) => {
this.totalZL += this.timeInstance[i]
prev.push({
name: this.nodeDic[i].name,
value: this.timeInstance[i]
})
return prev
}, [])
this.trafficData.forEach((item,index) => {
if (item.name === sourceName) {
item.tooltip = {
show: true,
backgroundColor: 'rgba(0, 0, 0, .5)',
formatter: (params) => {
const { value } = params.data
let htmls = '', ratio = ''
htmls += `
<div style="font-size:14px;height:31px;color:#fff;border-radius:4px;line-height:31px;padding-left:15px;padding-right:15px; text-align: left;">
遊逛次数: ${value}
</div><div>
`
ratio = ((value / this.totalKL) * 100).toFixed(2) + '%'
htmls += `
<p style="font-size:13px; padding:4px 15px; color:#fff; text-align: left;">占比: ${ratio}</p>
</div>
`
return htmls
}
}
item.itemStyle = {
normal: {
color: '#5FC5F5'
},
emphasis: {
color: '#5FC5F5'
}
}
}
})
this.durationData.forEach((item,index) =>{
if (item.name === sourceName) {
item.tooltip = {
show: true,
backgroundColor: 'rgba(0, 0, 0, .5)',
formatter: (params) => {
const { value } = params.data
let htmls = ''
let ratio = ''
htmls += `
<div style="font-size:14px;height:31px;color:#fff;border-radius:4px;line-height:31px;padding-left:15px;padding-right:15px; text-align: left;">
滞留时间: ${value}
</div><div>
`
ratio = ((value / this.totalZL) * 100).toFixed(2) + '%'
htmls += `
<p style="font-size:13px; padding:4px 15px; color:#fff; text-align: left;">占比: ${ratio}</p>
</div>
`
return htmls
}
}
item.itemStyle = {
normal: {
color: '#8F99F0'
},
emphasis: {
color: '#8F99F0'
}
}
}
})
},
// 客流量 滞留时间 饼图
drawNodePie(source, centerData) {
const pieBaseOption = {
type: 'pie', // 客流量
center: centerData,
hoverAnimation: false,
label: {
show: false
},
labelLine: {
show: false
},
tooltip: {
show: false
},
itemStyle: {
normal: {
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
label: {
show: false
},
labelLine: {
show: false
}
}
}
}
return [
Object.assign({}, pieBaseOption, {
id: 'kl' + source,
radius: [20, 0],
data: this.trafficData,
color: '#e0f5ff'
}),
Object.assign({}, pieBaseOption, {
id: 'zl' + source,
radius: [30, 24],
data: this.durationData,
color: '#dbdffd'
})]
},
// 渲染图表
closeDialog() {
this.isShow = false;
for (let i = 0; i < this.dataLen; i++) {
clearTimeout(this.timerObj[i])
clearTimeout(this.linkTimer[i])
}
this.graphData = [];
this.linkData = [];
this.picList = [];
this.idArr = [];
this.nodeDic = {}
this.trafficData = [];
this.durationData = [];
this.myEchart && this.myEchart.clear();
},
}
}
</script>
<style scoped>
.track-box:after,
.track-box:before {
content: '';
display: table;
}
.track-box:after {
clear: both;
}
.graph-container {
/* display: inline-block; */
position: relative;
height: 700px;
width: 92%;
float: left;
text-align: center;
overflow-x: auto;
overflow-y: hidden;
}
.background-img {
/* width: auto;
height: 100%;
position: absolute;
top: 0;
left: auto; */
/* height: 100%; */
max-width: 100%;
max-height: 100%;
display: block;
margin: 0 auto;
}
.graph-chart-container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.graph-box {
margin: 0 auto;
}
.dialog-title {
color: #fff;
font-size: 16px;
}
.replay {
display: inline-block;
padding-left: 10px;
color: #fff;
cursor: pointer;
position: relative;
}
.replay:hover {
color: #164bee;
}
.icon-reload {
font-size: 14px;
}
.track-list-right {
float: right;
/* background-color: #e4e4e4; */
padding-left: 6px;
padding-right: 6px;
height: 700px;
box-sizing: border-box;
}
.catch-pic-list {
padding-right: 10px;
}
.catch-pic-item:not(:first-child) {
padding-top: 6px;
background-color: #e4e4e4;
}
.zoomin-catch-pic {
height: 200px;
}
.catch-pic {
height: 50px;
width: 50px;
vertical-align: middle;
}
.track-list-scrollbar {
height: 100% !important;
max-height: 700px !important;
}
.total-box {
text-align: center;
padding-bottom: 10px;
}
@media only screen and (max-width: 1680px) {
.graph-container {
height: 700px;
}
}
@media only screen and (max-width: 1440px) {
.graph-container {
/* 600 */
height: 700px;
}
}
@media only screen and (max-width: 1366px) {
.graph-container {
/* 600 */
height: 700px;
}
}
@media only screen and (max-width: 1280px) {
.graph-container {
/* 600 */
height: 700px;
}
}
</style>