zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
<template>
  <basic-container>
    <el-row :span="24">
      <el-col :md="4">
        <el-row >
          <el-date-picker
            class="input_width"
            v-model="beginTime"
            placeholder="选择开始时间"
            @change="check">
          </el-date-picker>
        </el-row>
        <el-row>
          <el-date-picker
            class="input_width"
            v-model="endTime"
            placeholder="选择结束时间"
            @change="check">
          </el-date-picker>
        </el-row>
        <el-row>
          <avue-tree
            class="input_width"
            :option="treeOption"
            :data="treeData"
            @node-click="nodeClick"/>
        </el-row>
      </el-col>
      <el-col :md="20">
        <el-row>
          <el-col :span="12">
            <v-chart :options="userCumulate"/>
          </el-col>
          <el-col :span="12">
            <v-chart :options="interfaceSummary"/>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <v-chart :options="upstreamMsgDistMonth"/>
          </el-col>
          <el-col :span="12">
            <v-chart :options="userShard"/>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
  </basic-container>
</template>
 
<style>
</style>
 
<script>
import ECharts from 'vue-echarts'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/bar'
import 'echarts/lib/component/legend'
import 'echarts/lib/component/title'
import 'echarts/lib/component/tooltip'
import { fetchAccountList, fetchStatistics } from '@/api/mp/wxaccount'
 
export default {
  components: {
    'v-chart': ECharts
  },
  data() {
    return {
      beginTime: new Date() - 3600 * 1000 * 24 * 7,
      endTime: new Date() - 3600 * 1000 * 24,
      q: {
        interval: undefined,
        appId: undefined
      },
      treeOption: {
        nodeKey: 'id',
        addBtn: false,
        menu: false,
        props: {
          labelText: '标题',
          label: 'name',
          value: 'appid',
          children: 'children'
        }
      },
      treeData: [],
      userCumulate: {
        color: ['#409EFF'],
        title: {
          text: '用户分析数据'
        },
        xAxis: {
          type: 'category',
          data: []
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          data: [],
          type: 'line',
          itemStyle: {
            normal: {
              lineStyle: {
                width: 5// 设置线条粗细
              }
            }
          }
        }]
      },
      userShard: {
        color: ['#409EFF'],
        title: {
          text: '图文分享数据'
        },
        xAxis: {
          type: 'category',
          data: []
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          data: [],
          type: 'line',
          itemStyle: {
            normal: {
              lineStyle: {
                width: 5// 设置线条粗细
              }
            }
          }
        }]
      },
      upstreamMsgDistMonth: {
        color: ['#409EFF'],
        title: {
          text: '消息分析数据'
        },
        xAxis: {
          type: 'category',
          data: []
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          data: [],
          type: 'line',
          itemStyle: {
            normal: {
              lineStyle: {
                width: 5// 设置线条粗细
              }
            }
          }
        }]
      },
      interfaceSummary: {
        color: ['#409EFF'],
        tooltip: {
          axisPointer: { // 坐标轴指示器,坐标轴触发有效
            type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
          }
        },
        title: {
          text: '接口分析数据'
        },
        xAxis: {
          type: 'category',
          data: []
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          data: [],
          type: 'bar'
        }]
      }
    }
  },
  created() {
    this.getAccountList()
  },
  methods: {
    nodeClick(data) {
      this.check()
      this.q.appId = data.appid
      this.q.interval = new Date(this.beginTime).getTime() + '-' + new Date(this.endTime).getTime()
      fetchStatistics(this.q).then(response => {
        this.userCumulate.series[0].data = response.data.data[0]
        this.userCumulate.xAxis.data = response.data.data[4]
        this.userShard.series[0].data = response.data.data[1]
        this.userShard.xAxis.data = response.data.data[4]
        this.upstreamMsgDistMonth.series[0].data = response.data.data[2]
        this.upstreamMsgDistMonth.xAxis.data = response.data.data[4]
        this.interfaceSummary.series[0].data = response.data.data[3]
        this.interfaceSummary.xAxis.data = response.data.data[4]
      })
    },
    getAccountList() {
      fetchAccountList().then(response => {
        this.treeData = response.data.data
        // 默认选中第一个
        if (this.treeData.length > 0) {
          this.nodeClick(this.treeData[0])
        }
      })
    },
    check() {
      const start = new Date(this.beginTime)
      const end = new Date(this.endTime)
 
      if (end.getDate() >= new Date()) {
        this.$message.error('统计结束日小于,请重新选择')
        return false
      }
 
      if (end.getTime() - start.getTime() > 3600 * 1000 * 24 * 7) {
        this.$message.error('时间间隔7天以内,请重新选择')
        return false
      }
    }
  }
}
</script>
 
<style scoped>
  .input_width {
    width: 80%;
  }
</style>