张延森 3 년 전
부모
커밋
4405f3f566
5개의 변경된 파일98개의 추가작업 그리고 11개의 파일을 삭제
  1. 10
    1
      src/api/stat.js
  2. 11
    3
      src/components/ECharts/Line.vue
  3. 3
    1
      src/components/ECharts/index.vue
  4. 1
    1
      src/views/dashboard/components/Statistic.vue
  5. 73
    5
      src/views/dashboard/index.vue

+ 10
- 1
src/api/stat.js 파일 보기

@@ -2,4 +2,13 @@ import request from '@/utils/request'
2 2
 
3 3
 export const getStatTotal = () => request({
4 4
   url: '/admin/stat-total'
5
-})
5
+})
6
+
7
+
8
+export const getStatPV = (params) => request({
9
+  url: '/admin/pv', params
10
+})
11
+
12
+export const getStatUV = (params) => request({
13
+  url: '/admin/uv', params
14
+})

+ 11
- 3
src/components/ECharts/Line.vue 파일 보기

@@ -1,10 +1,13 @@
1 1
 <template>
2
-  <echarts :option="option" :loading="loading"></echarts>
2
+  <echarts :option="opt" :loading="loading"></echarts>
3 3
 </template>
4 4
 
5 5
 <script>
6 6
 export default {
7 7
   name: 'LineChart',
8
+  components: {
9
+    echarts: () => import('./index.vue')
10
+  },
8 11
   props: {
9 12
     option: {
10 13
       type: Object,
@@ -25,14 +28,19 @@ export default {
25 28
         yAxis: {
26 29
           type: 'value'
27 30
         },
31
+        tooltip: {
32
+          trigger: 'axis'
33
+        },
34
+        dataset: {
35
+          dimensions: ['key', 'value'],
36
+          source: this.value,
37
+        },
28 38
         series: [
29 39
           {
30 40
             type: 'line',
31 41
             smooth: true
32 42
           }
33 43
         ],
34
-        dimensions: ['key', 'value'],
35
-        source: this.value,
36 44
         ...this.option,
37 45
       }
38 46
     }

+ 3
- 1
src/components/ECharts/index.vue 파일 보기

@@ -54,6 +54,7 @@ export default {
54 54
       handler(v) {
55 55
         if (this.echartsRef) {
56 56
           this.echartsRef.setOption(v)
57
+          console.log('-------------', v)
57 58
         }
58 59
       },
59 60
       immediate: true
@@ -70,7 +71,7 @@ export default {
70 71
   },
71 72
   mounted() {
72 73
     this.echartsRef = echarts.init(this.$el)
73
-    this.echartsRef.setOption(v)
74
+    this.echartsRef.setOption(this.option)
74 75
   }
75 76
 }
76 77
 </script>
@@ -79,5 +80,6 @@ export default {
79 80
 .echart {
80 81
   width: 100%;
81 82
   height: 100%;
83
+  min-height: 400px;
82 84
 }
83 85
 </style>

+ 1
- 1
src/views/dashboard/components/Statistic.vue 파일 보기

@@ -9,7 +9,7 @@
9 9
 export default {
10 10
   name: 'Statistic',
11 11
   props: {
12
-    title: String,
12
+    title: [String, Number],
13 13
     value: String,
14 14
   }
15 15
 }

+ 73
- 5
src/views/dashboard/index.vue 파일 보기

@@ -2,7 +2,7 @@
2 2
   <div class="dashboard-container">
3 3
     <div class="dashboard-text">欢迎使用{{ name }}</div>
4 4
 
5
-    <el-row type="flex" class="row-bg" justify="space-between">
5
+    <el-row class="sec" type="flex" justify="space-between">
6 6
       <el-col :span="6">
7 7
         <statistic title="报名总数" :value="total.reg" />
8 8
       </el-col>
@@ -13,34 +13,98 @@
13 13
         <statistic title="UV 总数" :value="total.uv" />
14 14
       </el-col>
15 15
     </el-row>
16
+
17
+    <el-row class="sec" type="flex" justify="space-between" gutter="24">
18
+      <el-col :span="12">
19
+        <el-card>
20
+          <div slot="header">
21
+            <span>PV访问</span>
22
+          </div>
23
+          <line-chart :value="pv" />
24
+        </el-card>
25
+      </el-col>
26
+      <el-col :span="12">
27
+        <el-card>
28
+          <div slot="header">
29
+            <span>UV访问</span>
30
+          </div>
31
+          <line-chart :value="uv" />
32
+        </el-card>
33
+      </el-col>
34
+    </el-row>
35
+
16 36
   </div>
17 37
 </template>
18 38
 
19 39
 <script>
20 40
 import { mapGetters } from 'vuex'
21
-import { getStatTotal } from '@/api/stat'
41
+import { getStatTotal, getStatPV, getStatUV } from '@/api/stat'
42
+
43
+const formateNum = n => n > 9 ? `${n}` : `0${n}`
22 44
 
23 45
 export default {
24 46
   name: 'Dashboard',
25 47
   components: {
26
-    Statistic: () => import('./components/Statistic.vue')
48
+    Statistic: () => import('./components/Statistic.vue'),
49
+    LineChart: () => import('@/components/ECharts/Line.vue'),
27 50
   },
28 51
   computed: {
29
-    ...mapGetters(['name'])
52
+    ...mapGetters(['name']),
53
+    lineParam() {
54
+      // 为了包含今天, 需要少计算1天
55
+      const mills = (this.days - 1) * 24 * 60 * 60 * 1000
56
+      const start = new Date(this.today - mills)
57
+      const year = start.getFullYear()
58
+      const mon = start.getMonth() + 1
59
+      const dt = start.getDate()
60
+
61
+      return {
62
+        startDate: `${year}-${formateNum(mon)}-${formateNum(dt)}`,
63
+        days: this.days,
64
+      }
65
+    }
30 66
   },
31 67
   data() {
32 68
     return {
33
-      total: {}
69
+      total: {},
70
+      today: new Date(),
71
+      days: 15, // 默认统计 15 天的
72
+      pv: [],
73
+      uv: [],
74
+      loading: {
75
+        pv: false,
76
+        uv: false,
77
+      }
34 78
     }
35 79
   },
36 80
   mounted() {
37 81
     this.statTotal()
82
+    this.statPV()
83
+    this.statUV()
38 84
   },
39 85
   methods: {
40 86
     statTotal() {
41 87
       getStatTotal().then(res => {
42 88
         this.total = res
43 89
       })
90
+    },
91
+    statPV() {
92
+      this.loading.pv = true
93
+      getStatPV(this.lineParam).then(res => {
94
+        this.pv = res
95
+        this.loading.pv = false
96
+      }).catch(() => {
97
+        this.loading.pv = false
98
+      })
99
+    },
100
+    statUV() {
101
+      this.loading.uv = true
102
+      getStatUV(this.lineParam).then(res => {
103
+        this.uv = res
104
+        this.loading.uv = false
105
+      }).catch(() => {
106
+        this.loading.uv = false
107
+      })
44 108
     }
45 109
   }
46 110
 }
@@ -56,4 +120,8 @@ export default {
56 120
     line-height: 46px;
57 121
   }
58 122
 }
123
+
124
+.sec {
125
+  margin: 24px 0;
126
+}
59 127
 </style>