GateFlowDirection.nvue
3.61 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
<template>
<CardNvue :title="t('PreMallChart.mall_visitors_flow_direction.sankey')" :auto-height="true">
<template #content>
<ChartsNvue v-if="renderFlag === '1'" height="560rpx" ref="flowDirectRef" />
<view class="p-empty" v-if="renderFlag === '0'" style="margin-top: 40rpx;">
<image class="p-empty-img" src="/static/common/empty.png" mode=""></image>
<text class="p-empty-text chart-text">{{ t('maintenance.monitor.project.empty.text') }}</text>
</view>
</template>
</CardNvue>
</template>
<script setup>
import {
nextTick,
onMounted,
ref
} from 'vue'
import {
getGateFlowDirectionNewApi
} from '@/api'
import CardNvue from './Card.nvue'
import ChartsNvue from '@/components/Charts.nvue'
import {
t
} from '@/plugins/index.js'
const renderFlag = ref('')
const flowDirectRef = ref(null)
onMounted(() => {
// getTrendChartData()
})
const options = ref({})
const initData = (params) => {
options.value = params
nextTick(() => {
getTrendChartData()
})
}
defineExpose({
initData
})
const getTrendChartData = async () => {
try {
// 参数设置位置:
const params = {
accountIds: options.value.accountId,
endDate: options.value.endDate,
startDate: options.value.startDate,
mallId: options.value.storeId
}
const {
data
} = await getGateFlowDirectionNewApi(params)
if (data.length > 0) {
renderFlag.value = '1'
} else {
renderFlag.value = '0'
}
const option = {
tooltip: {
trigger: "item",
confine: true,
triggerOn: 'click'
},
color: [
"#e35241",
"#d83965",
"#f39c38",
"#9036aa",
"#6041b0",
"#4054af",
"#4396ec",
"#4fb9d1",
"#3f9488",
"#97c05c",
"#154bee",
],
animation: false,
series: [{
left: 0,
right: 0,
top: 10,
bottom: 5,
type: "sankey",
focusNodeAdjacency: "allEdges",
nodeAlign: "right",
label: {
position: 'right',
},
data: [],
links: [],
lineStyle: {
color: "source",
curveness: 0.5,
},
}],
}
const idataSet = new Set()
const links = []
data.forEach((item) => {
idataSet.add(item.source)
idataSet.add(item.target + ' ') // 增加空格,保证echarts不报错
links.push({
...item,
target: item.target + ' ',
})
});
option.series[0].data = [...idataSet].map(n => {
const lastStr = n[n.length - 1]
return {
name: n,
label: {
position: lastStr === ' ' ? 'left' : 'right'
}
}
})
option.series[0].links = links;
// #ifndef MP-WEIXIN
nextTick(() => {
setTimeout(() => {
flowDirectRef.value?.initCharts(option)
}, 0)
})
// #endif
// #ifdef MP-WEIXIN
let attempts = 0;
while (!flowDirectRef.value && attempts < 40) {
await new Promise(resolve => setTimeout(resolve, 50));
attempts++;
}
if (flowDirectRef.value?.initCharts) {
flowDirectRef.value?.initCharts(option);
} else {
console.warn('分区流向图表组件未加载完成', flowDirectRef.value);
}
// #endif
} catch (e) {
console.log(e);
}
}
</script>
<style>
</style>