|
@@ -0,0 +1,357 @@
|
|
1
|
+import { Api } from "@/api/api"
|
|
2
|
+import http from "@/http/http"
|
|
3
|
+import { ElMessage } from "element-plus"
|
|
4
|
+import { reactive, ref } from "vue"
|
|
5
|
+
|
|
6
|
+export interface IReportTrend {
|
|
7
|
+ st_date: string,
|
|
8
|
+ en_date: string,
|
|
9
|
+ date_group?: string,
|
|
10
|
+ dimension: string,
|
|
11
|
+ keyword?: string,
|
|
12
|
+ user_ids?: any[],
|
|
13
|
+ account_ids?: any[],
|
|
14
|
+ team_ids?: any[],
|
|
15
|
+ top_num: number,
|
|
16
|
+ project_ids?: any[],
|
|
17
|
+ department_ids?: any[]
|
|
18
|
+}
|
|
19
|
+
|
|
20
|
+export const ExpTrend = () => {
|
|
21
|
+ const isCollapsed = ref(false)
|
|
22
|
+ const trendLoading = ref(false)
|
|
23
|
+ const overviewRef = ref()
|
|
24
|
+ const topNumRef = ref()
|
|
25
|
+ const tabInfo = reactive({
|
|
26
|
+ value: 'trend',
|
|
27
|
+ list: [
|
|
28
|
+ { name: '趋势分析', id: 'trend' },
|
|
29
|
+ { name: '占比分析', id: 'ratio' },
|
|
30
|
+ ]
|
|
31
|
+ })
|
|
32
|
+ const overviewData = reactive<{ list: any[], [key: string]: any }>({
|
|
33
|
+ list: [
|
|
34
|
+ { name: '消耗', key: 'cost', unit: '元' },
|
|
35
|
+ { name: '展示数', key: 'view_count' },
|
|
36
|
+ { name: '千次展示均价(CPM)', key: 'thousand_display_price', unit: '元' },
|
|
37
|
+ { name: '点击数', key: 'valid_click_count' },
|
|
38
|
+ { name: '点击率', key: 'ctr' },
|
|
39
|
+ { name: '点击均价', key: 'cpc' },
|
|
40
|
+ { name: '转化数', key: 'conversions_count' },
|
|
41
|
+ { name: '转化率', key: 'conversions_rate' },
|
|
42
|
+ { name: '转化成本', key: 'conversions_cost', unit: '元' },
|
|
43
|
+ { name: '激活数', key: 'activated_count' },
|
|
44
|
+ { name: '注册数', key: 'app_register_count' },
|
|
45
|
+ ],
|
|
46
|
+ legendArr: [],
|
|
47
|
+ trendDataList: [],
|
|
48
|
+ ratioDataList: []
|
|
49
|
+ })
|
|
50
|
+ const topNumList = reactive([
|
|
51
|
+ { name: 'Top5数据', val: 5 },
|
|
52
|
+ { name: 'Top10数据', val: 10 },
|
|
53
|
+ ])
|
|
54
|
+ const trendInfo = reactive({
|
|
55
|
+ option: {},
|
|
56
|
+ heights: '320px',
|
|
57
|
+ })
|
|
58
|
+ const ratioInfo = reactive({
|
|
59
|
+ option: {},
|
|
60
|
+ heights: '320px',
|
|
61
|
+ })
|
|
62
|
+
|
|
63
|
+ /**数据报表 - 趋势分析 */
|
|
64
|
+ const reportTrendEvent = async (params: IReportTrend) => {
|
|
65
|
+ trendLoading.value = true;
|
|
66
|
+ let res: any = await http.get(Api.report_trend, params)
|
|
67
|
+ trendLoading.value = false;
|
|
68
|
+ if (res && res.errNo == '0') {
|
|
69
|
+ overviewData.trendDataList = res.rst;
|
|
70
|
+ getTrend(params.dimension)
|
|
71
|
+ } else {
|
|
72
|
+ ElMessage.error(res.errMsg)
|
|
73
|
+ }
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ /**数据报表 - 占比分析 */
|
|
77
|
+ const reportRatioEvent = async (params: IReportTrend) => {
|
|
78
|
+ trendLoading.value = true;
|
|
79
|
+ let res: any = await http.get(Api.report_ratio, params)
|
|
80
|
+ trendLoading.value = false;
|
|
81
|
+ if (res && res.errNo == '0') {
|
|
82
|
+ overviewData.ratioDataList = res.rst;
|
|
83
|
+ radiuCharts(params.dimension)
|
|
84
|
+ } else {
|
|
85
|
+ ElMessage.error(res.errMsg)
|
|
86
|
+ }
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+ const trendColor = ['#3B9FFF', '#4ECB73', '#F9D336', '#F1637B', '#9760E4', '#EF69FF', '#FCB161', '#62DDFF', '#C7C655', '#318730']
|
|
90
|
+ const getTrendOption = (yAxis, date, data) => {
|
|
91
|
+ return {
|
|
92
|
+ tooltip: {
|
|
93
|
+ trigger: 'axis',
|
|
94
|
+ },
|
|
95
|
+ grid: {
|
|
96
|
+ left: '7%',
|
|
97
|
+ right: '4%',
|
|
98
|
+ bottom: '10%'
|
|
99
|
+ },
|
|
100
|
+ xAxis: {
|
|
101
|
+ type: 'category',
|
|
102
|
+ boundaryGap: false,
|
|
103
|
+ data: date,
|
|
104
|
+ axisTick: {
|
|
105
|
+ show: false
|
|
106
|
+ },
|
|
107
|
+ axisLine: {
|
|
108
|
+ show: true,
|
|
109
|
+ lineStyle: {
|
|
110
|
+ color: '#cccccc'
|
|
111
|
+ }
|
|
112
|
+ },
|
|
113
|
+ axisLabel: {
|
|
114
|
+ color: '#666',
|
|
115
|
+ },
|
|
116
|
+ },
|
|
117
|
+ yAxis: yAxis,
|
|
118
|
+ series: data
|
|
119
|
+ }
|
|
120
|
+ }
|
|
121
|
+ /** 获取曲线数据 */
|
|
122
|
+ const getTrend = (dimension) => {
|
|
123
|
+ let time: any[] = [];
|
|
124
|
+ let dataInfo: any = {
|
|
125
|
+ trend_name: '',
|
|
126
|
+ trend: [],
|
|
127
|
+ data: []
|
|
128
|
+ };
|
|
129
|
+ overviewData.list.forEach((item) => {
|
|
130
|
+ if (item.key == overviewRef.value!.value) {
|
|
131
|
+ dataInfo.trend_name = item.name + (item.unit ? `(${item.unit})` : '')
|
|
132
|
+ }
|
|
133
|
+ });
|
|
134
|
+
|
|
135
|
+ let legendArr: any[] = []
|
|
136
|
+ let yAxis: any[] = []
|
|
137
|
+ yAxis.push({
|
|
138
|
+ name: dataInfo.trend_name,
|
|
139
|
+ type: 'value',
|
|
140
|
+ splitNumber: 4,
|
|
141
|
+ nameTextStyle: {
|
|
142
|
+ align: dataInfo.trend_name.length > 7 ? 'center' : 'right',
|
|
143
|
+ }
|
|
144
|
+ })
|
|
145
|
+
|
|
146
|
+ if (topNumRef.value?.value == 0) {//汇总
|
|
147
|
+ overviewData.trendDataList.forEach((item: any) => {
|
|
148
|
+ time.push(item.time)
|
|
149
|
+ dataInfo.trend.push(item[overviewRef.value!.value])
|
|
150
|
+ });
|
|
151
|
+ dataInfo.data.push({
|
|
152
|
+ name: '汇总',
|
|
153
|
+ type: 'line',
|
|
154
|
+ smooth: true,
|
|
155
|
+ itemStyle: {
|
|
156
|
+ color: trendColor[0]
|
|
157
|
+ },
|
|
158
|
+ data: dataInfo.trend
|
|
159
|
+ })
|
|
160
|
+ legendArr.push({
|
|
161
|
+ name: '汇总',
|
|
162
|
+ color: trendColor[0]
|
|
163
|
+ })
|
|
164
|
+ } else {
|
|
165
|
+ if (overviewData.trendDataList?.length > 0) {
|
|
166
|
+ overviewData.trendDataList[0].data.forEach((item: any) => {
|
|
167
|
+ time.push(item.time)
|
|
168
|
+ });
|
|
169
|
+ }
|
|
170
|
+ let name = '';
|
|
171
|
+ let id = '';
|
|
172
|
+ overviewData.trendDataList.forEach((item: any, index) => {
|
|
173
|
+ if (dimension == 'account') {//数据维度
|
|
174
|
+ name = item.account_name
|
|
175
|
+ id = item.account_id
|
|
176
|
+ }
|
|
177
|
+ if (dimension == 'user') {
|
|
178
|
+ name = item.username
|
|
179
|
+ }
|
|
180
|
+ if (dimension == 'team') {
|
|
181
|
+ name = item.name
|
|
182
|
+ }
|
|
183
|
+ if (dimension == 'project') {
|
|
184
|
+ name = item.name
|
|
185
|
+ }
|
|
186
|
+ let trendData: any[] = []
|
|
187
|
+ item.data?.forEach((s_item) => {
|
|
188
|
+ trendData.push(s_item[overviewRef.value!.value])
|
|
189
|
+ });
|
|
190
|
+ dataInfo.data.push({
|
|
191
|
+ name: `${name}${id != '' ? `(${id})` : ''}`,
|
|
192
|
+ type: 'line',
|
|
193
|
+ smooth: true,
|
|
194
|
+ itemStyle: {
|
|
195
|
+ color: trendColor[index]
|
|
196
|
+ },
|
|
197
|
+ data: trendData
|
|
198
|
+ })
|
|
199
|
+ legendArr.push({
|
|
200
|
+ name: name,
|
|
201
|
+ id: id,
|
|
202
|
+ color: trendColor[index]
|
|
203
|
+ })
|
|
204
|
+ });
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ overviewData.legendArr = legendArr
|
|
208
|
+
|
|
209
|
+ trendInfo.option = getTrendOption(yAxis, time, dataInfo.data)
|
|
210
|
+ }
|
|
211
|
+ /**占比图 */
|
|
212
|
+ const radiuCharts = (dimension) => {
|
|
213
|
+ let trend_name = ''
|
|
214
|
+ let totalValue = ''
|
|
215
|
+ overviewData.list.forEach((item) => {
|
|
216
|
+ if (item.key == overviewRef.value!.value) {
|
|
217
|
+ trend_name = item.name
|
|
218
|
+ }
|
|
219
|
+ });
|
|
220
|
+ let data: any[] = []
|
|
221
|
+ overviewData.ratioDataList.data.forEach((item) => {
|
|
222
|
+ if (dimension == 'account') {//数据维度
|
|
223
|
+ data.push({
|
|
224
|
+ value: item[`${overviewRef.value!.value}_pro`],
|
|
225
|
+ name: item.account_name,
|
|
226
|
+ id: item.account_id,
|
|
227
|
+ })
|
|
228
|
+ }
|
|
229
|
+ if (dimension == 'user') {
|
|
230
|
+ data.push({
|
|
231
|
+ value: item[`${overviewRef.value!.value}_pro`],
|
|
232
|
+ name: item.username,
|
|
233
|
+ })
|
|
234
|
+ }
|
|
235
|
+ if (dimension == 'team') {
|
|
236
|
+ data.push({
|
|
237
|
+ value: item[`${overviewRef.value!.value}_pro`],
|
|
238
|
+ name: item.name,
|
|
239
|
+ })
|
|
240
|
+ }
|
|
241
|
+ if (dimension == 'project') {
|
|
242
|
+ data.push({
|
|
243
|
+ value: item[`${overviewRef.value!.value}_pro`],
|
|
244
|
+ name: item.name,
|
|
245
|
+ })
|
|
246
|
+ }
|
|
247
|
+ });
|
|
248
|
+ totalValue = overviewData.ratioDataList.total[overviewRef.value!.value];
|
|
249
|
+ let option = {
|
|
250
|
+ title: {
|
|
251
|
+ zlevel: 0,
|
|
252
|
+ text: [`{name|${trend_name}}`, '{value|' + totalValue + '}'].join('\n'),
|
|
253
|
+ top: '38%',
|
|
254
|
+ left: '49.5%',
|
|
255
|
+ textAlign: 'center',
|
|
256
|
+ textStyle: {
|
|
257
|
+ rich: {
|
|
258
|
+ value: {
|
|
259
|
+ color: '#303133',
|
|
260
|
+ fontSize: 20,
|
|
261
|
+ lineHeight: 24,
|
|
262
|
+ },
|
|
263
|
+ name: {
|
|
264
|
+ color: '#303133',
|
|
265
|
+ fontSize: 20,
|
|
266
|
+ lineHeight: 35,
|
|
267
|
+ },
|
|
268
|
+ },
|
|
269
|
+ },
|
|
270
|
+ },
|
|
271
|
+ tooltip: {
|
|
272
|
+ trigger: 'item',
|
|
273
|
+ show: false
|
|
274
|
+ },
|
|
275
|
+ legend: {
|
|
276
|
+ top: '5%',
|
|
277
|
+ left: 'center',
|
|
278
|
+ show: false,
|
|
279
|
+ },
|
|
280
|
+ series: [
|
|
281
|
+ {
|
|
282
|
+ name: trend_name,
|
|
283
|
+ type: 'pie',
|
|
284
|
+ radius: ['40%', '70%'],
|
|
285
|
+ width: 600,
|
|
286
|
+ left: 'center',
|
|
287
|
+ itemStyle: {
|
|
288
|
+ normal: {
|
|
289
|
+ borderRadius: 10,
|
|
290
|
+ borderColor: '#fff',
|
|
291
|
+ borderWidth: 2,
|
|
292
|
+ color: function (colors) {
|
|
293
|
+ return trendColor[colors.dataIndex];
|
|
294
|
+ }
|
|
295
|
+ }
|
|
296
|
+ },
|
|
297
|
+ label: {
|
|
298
|
+ show: true,
|
|
299
|
+ alignTo: 'edge',
|
|
300
|
+ formatter(param) {
|
|
301
|
+ return `{name|${param.name}}\n${param.data.id ? `{id|${param.data.id}}:` : ''}{val|${param.percent}%}`
|
|
302
|
+ },
|
|
303
|
+ minMargin: 5,
|
|
304
|
+ edgeDistance: 10,
|
|
305
|
+ lineHeight: 15,
|
|
306
|
+ rich: {
|
|
307
|
+ name: {
|
|
308
|
+ color: '#888',
|
|
309
|
+ },
|
|
310
|
+ },
|
|
311
|
+ },
|
|
312
|
+ emphasis: {
|
|
313
|
+ label: {
|
|
314
|
+ show: true,
|
|
315
|
+ fontSize: 15,
|
|
316
|
+ fontWeight: 'bold'
|
|
317
|
+ }
|
|
318
|
+ },
|
|
319
|
+ labelLine: {
|
|
320
|
+ length: 15,
|
|
321
|
+ length2: 0,
|
|
322
|
+ maxSurfaceAngle: 80
|
|
323
|
+ },
|
|
324
|
+ labelLayout: function (params) {
|
|
325
|
+ const isLeft = params.labelRect.x < 600;
|
|
326
|
+ const points = params.labelLinePoints;
|
|
327
|
+ // Update the end point.
|
|
328
|
+ points[2][0] = isLeft
|
|
329
|
+ ? params.labelRect.x
|
|
330
|
+ : params.labelRect.x + params.labelRect.width;
|
|
331
|
+ return {
|
|
332
|
+ labelLinePoints: points
|
|
333
|
+ };
|
|
334
|
+ },
|
|
335
|
+ data: data
|
|
336
|
+ }
|
|
337
|
+ ]
|
|
338
|
+ };
|
|
339
|
+ ratioInfo.option = option
|
|
340
|
+ }
|
|
341
|
+
|
|
342
|
+ return {
|
|
343
|
+ isCollapsed,
|
|
344
|
+ tabInfo,
|
|
345
|
+ trendLoading,
|
|
346
|
+ topNumRef,
|
|
347
|
+ overviewRef,
|
|
348
|
+ overviewData,
|
|
349
|
+ topNumList,
|
|
350
|
+ trendInfo,
|
|
351
|
+ ratioInfo,
|
|
352
|
+ getTrend,
|
|
353
|
+ radiuCharts,
|
|
354
|
+ reportTrendEvent,
|
|
355
|
+ reportRatioEvent,
|
|
356
|
+ }
|
|
357
|
+}
|