许成详 6 years ago
parent
commit
b1f2bb4b13

+ 3
- 3
src/components/brokenLineGraph/index.vue View File

@@ -1,7 +1,7 @@
1 1
 <template>
2 2
   <div class="component">
3 3
     <h6 class="title">{{data.title}}</h6>
4
-    <div id="brokenLineGraph" ref="box"></div>
4
+    <div :id="'brokenLineGraph' + index" ref="box"></div>
5 5
   </div>
6 6
 </template>
7 7
 
@@ -10,7 +10,7 @@ import G2 from '@antv/g2'
10 10
 
11 11
 export default {
12 12
   name: '',
13
-  props: ['data'],
13
+  props: ['data', 'index'],
14 14
   data () {
15 15
     return {
16 16
     }
@@ -27,7 +27,7 @@ export default {
27 27
     init () {
28 28
       var _that = this
29 29
       var chart = new G2.Chart({
30
-        container: 'brokenLineGraph',
30
+        container: 'brokenLineGraph' + _that.index,
31 31
         forceFit: true,
32 32
         width: _that.$refs.box.clientWidth,
33 33
         height: 400

+ 146
- 0
src/components/dashboard/index.vue View File

@@ -0,0 +1,146 @@
1
+<template>
2
+  <div class="component">
3
+    <h6 class="title">{{data.title}}</h6>
4
+    <div :id="'dashboard' + index" ref="box"></div>
5
+  </div>
6
+</template>
7
+
8
+<script>
9
+import G2 from '@antv/g2'
10
+
11
+export default {
12
+  name: '',
13
+  props: ['data', 'index'],
14
+  data () {
15
+    return {
16
+    }
17
+  },
18
+  components: {
19
+    G2,
20
+  },
21
+  mounted () {
22
+    this.$nextTick(function () {
23
+      this.init()
24
+    })
25
+  },
26
+  methods: {
27
+    init () {
28
+      var _that = this
29
+      var Shape = G2.Shape
30
+      // 自定义Shape 部分
31
+      Shape.registerShape('point', 'pointer', {
32
+        drawShape: function drawShape (cfg, group) {
33
+          var center = this.parsePoint({ // 获取极坐标系下画布中心点
34
+            x: 0,
35
+            y: 0
36
+          })
37
+          // 绘制指针
38
+          group.addShape('line', {
39
+            attrs: {
40
+              x1: center.x,
41
+              y1: center.y,
42
+              x2: cfg.x,
43
+              y2: cfg.y,
44
+              stroke: cfg.color,
45
+              lineWidth: 5,
46
+              lineCap: 'round'
47
+            }
48
+          })
49
+          return group.addShape('circle', {
50
+            attrs: {
51
+              x: center.x,
52
+              y: center.y,
53
+              r: 8,
54
+              stroke: cfg.color,
55
+              lineWidth: 4.5,
56
+              fill: '#fff'
57
+            }
58
+          })
59
+        }
60
+      })
61
+      var chart = new G2.Chart({
62
+        container: 'dashboard' + _that.index,
63
+        forceFit: true,
64
+        width: _that.$refs.box.clientWidth,
65
+        height: 400,
66
+        padding: [0, 0, 30, 0]
67
+      })
68
+      chart.source(_that.data.list)
69
+
70
+      chart.coord('polar', {
71
+        startAngle: -9 / 8 * Math.PI,
72
+        endAngle: 1 / 8 * Math.PI,
73
+        radius: 0.75
74
+      })
75
+      chart.scale('value', {
76
+        min: 0,
77
+        max: 9,
78
+        tickInterval: 1,
79
+        nice: false
80
+      })
81
+
82
+      chart.axis('1', false)
83
+      chart.axis('value', {
84
+        zIndex: 2,
85
+        line: null,
86
+        label: {
87
+          offset: -16,
88
+          textStyle: {
89
+            fontSize: 18,
90
+            textAlign: 'center',
91
+            textBaseline: 'middle'
92
+          }
93
+        },
94
+        subTickCount: 4,
95
+        subTickLine: {
96
+          length: -8,
97
+          stroke: '#fff',
98
+          strokeOpacity: 1
99
+        },
100
+        tickLine: {
101
+          length: -17,
102
+          stroke: '#fff',
103
+          strokeOpacity: 1
104
+        },
105
+        grid: null
106
+      })
107
+      chart.legend(false)
108
+      chart.point().position('value*1').shape('pointer').color('#1890FF').active(false)
109
+
110
+      // 绘制仪表盘背景
111
+      chart.guide().arc({
112
+        zIndex: 0,
113
+        top: false,
114
+        start: [0, 0.945],
115
+        end: [9, 0.945],
116
+        style: { // 底灰色
117
+          stroke: '#CBCBCB',
118
+          lineWidth: 18
119
+        }
120
+      })
121
+      // 绘制指标
122
+      chart.guide().arc({
123
+        zIndex: 1,
124
+        start: [0, 0.945],
125
+        end: [_that.data.list[0].value, 0.945],
126
+        style: {
127
+          stroke: '#1890FF',
128
+          lineWidth: 18
129
+        }
130
+      })
131
+      // 绘制指标数字
132
+      chart.guide().html({
133
+        position: ['50%', '100%'],
134
+        html: '<div style="width: 300px;text-align: center;">' + '<p style="font-size: 20px; color: #545454;margin: 0;">' + _that.data.title + '</p>' + '<p style="font-size: 36px;color: #545454;margin: 0;">' + _that.data.list[0].value * 10 + '%</p>' + '</div>'
135
+      })
136
+
137
+      chart.render()
138
+    },
139
+  }
140
+}
141
+</script>
142
+
143
+<!-- Add "scoped" attribute to limit CSS to this component only -->
144
+<style lang="scss" scoped>
145
+@import "page.scss";
146
+</style>

+ 26
- 0
src/components/dashboard/page.scss View File

@@ -0,0 +1,26 @@
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
+

+ 3
- 3
src/components/histogram/index.vue View File

@@ -1,7 +1,7 @@
1 1
 <template>
2 2
   <div class="component">
3 3
     <h6 class="title">{{data.title}}</h6>
4
-    <div id="histogram" ref="box"></div>
4
+    <div :id="'histogram' + index" ref="box"></div>
5 5
   </div>
6 6
 </template>
7 7
 
@@ -10,7 +10,7 @@ import G2 from '@antv/g2'
10 10
 
11 11
 export default {
12 12
   name: '',
13
-  props: ['data'],
13
+  props: ['data', 'index'],
14 14
   data () {
15 15
     return {
16 16
     }
@@ -27,7 +27,7 @@ export default {
27 27
     init () {
28 28
       var _that = this
29 29
       var chart = new G2.Chart({
30
-        container: 'histogram',
30
+        container: 'histogram' + _that.index,
31 31
         forceFit: true,
32 32
         width: _that.$refs.box.clientWidth,
33 33
         height: 400

+ 3
- 3
src/components/pieDiagram/index.vue View File

@@ -1,7 +1,7 @@
1 1
 <template>
2 2
   <div class="component">
3 3
     <h6 class="title">{{data.title}}</h6>
4
-    <div id="pieDiagram" ref="box"></div>
4
+    <div :id="'pieDiagram' + index" ref="box"></div>
5 5
   </div>
6 6
 </template>
7 7
 
@@ -10,7 +10,7 @@ import G2 from '@antv/g2'
10 10
 
11 11
 export default {
12 12
   name: '',
13
-  props: ['data'],
13
+  props: ['data', 'index'],
14 14
   data () {
15 15
     return {
16 16
     }
@@ -27,7 +27,7 @@ export default {
27 27
     init () {
28 28
       var _that = this
29 29
       var chart = new G2.Chart({
30
-        container: 'pieDiagram',
30
+        container: 'pieDiagram' + _that.index,
31 31
         forceFit: true,
32 32
         width: _that.$refs.box.clientWidth,
33 33
         height: 400

+ 3
- 3
src/components/ringChart/index.vue View File

@@ -1,7 +1,7 @@
1 1
 <template>
2 2
   <div class="component">
3 3
     <h6 class="title">{{data.title}}</h6>
4
-    <div id="ringChart" ref="box"></div>
4
+    <div :id="'ringChart' + index" ref="box"></div>
5 5
   </div>
6 6
 </template>
7 7
 
@@ -10,7 +10,7 @@ import G2 from '@antv/g2'
10 10
 
11 11
 export default {
12 12
   name: '',
13
-  props: ['data'],
13
+  props: ['data', 'index'],
14 14
   data () {
15 15
     return {
16 16
     }
@@ -27,7 +27,7 @@ export default {
27 27
     init () {
28 28
       var _that = this
29 29
       var chart = new G2.Chart({
30
-        container: 'ringChart',
30
+        container: 'ringChart' + _that.index,
31 31
         forceFit: true,
32 32
         width: _that.$refs.box.clientWidth,
33 33
         height: 400

+ 12
- 6
src/pages/system/dashboard/index.vue View File

@@ -13,19 +13,22 @@
13 13
     <div class="flex-h" v-for="(item,index) in pageData" :key="index">
14 14
       <div class="flex-item" v-for="(subItem,subIndex) in item" :key="subIndex">
15 15
         <div v-if="subItem.type === 'dashboardList'">
16
-          <dashboardList :data="subItem.data"></dashboardList>
16
+          <dashboardList :data="subItem.data" :index="index + '-' + subIndex"></dashboardList>
17 17
         </div>
18 18
         <div v-if="subItem.type === 'histogram'">
19
-          <histogram :data="subItem.data"></histogram>
19
+          <histogram :data="subItem.data" :index="index + '-' + subIndex"></histogram>
20 20
         </div>
21 21
         <div v-if="subItem.type === 'pieDiagram'">
22
-          <pieDiagram :data="subItem.data"></pieDiagram>
22
+          <pieDiagram :data="subItem.data" :index="index + '-' + subIndex"></pieDiagram>
23 23
         </div>
24 24
         <div v-if="subItem.type === 'brokenLineGraph'">
25
-          <brokenLineGraph :data="subItem.data"></brokenLineGraph>
25
+          <brokenLineGraph :data="subItem.data" :index="index + '-' + subIndex"></brokenLineGraph>
26 26
         </div>
27 27
         <div v-if="subItem.type === 'ringChart'">
28
-          <ringChart :data="subItem.data"></ringChart>
28
+          <ringChart :data="subItem.data" :index="index + '-' + subIndex"></ringChart>
29
+        </div>
30
+        <div v-if="subItem.type === 'dashboard'">
31
+          <dashboard :data="subItem.data" :index="index + '-' + subIndex"></dashboard>
29 32
         </div>
30 33
       </div>
31 34
     </div>
@@ -39,6 +42,7 @@ import histogram from '../../../components/histogram/index'
39 42
 import pieDiagram from '../../../components/pieDiagram/index'
40 43
 import brokenLineGraph from '../../../components/brokenLineGraph/index'
41 44
 import ringChart from '../../../components/ringChart/index'
45
+import dashboard from '../../../components/dashboard/index'
42 46
 
43 47
 export default {
44 48
   name: '',
@@ -60,7 +64,8 @@ export default {
60 64
           { type: 'ringChart', remark: '环形图', data: { title: '本月课程预约', list: [{ item: '健身课程', count: 40, percent: 0.4 }, { item: '社交课程', count: 21, percent: 0.21 }, { item: '教育课程', count: 17, percent: 0.17 }, { item: '健康课程', count: 13, percent: 0.13 }, { item: '艺术课程', count: 9, percent: 0.09 }] } },
61 65
         ],
62 66
         [
63
-          { type: '', remark: '', data: { title: '', list: [] } },
67
+          { type: 'dashboard', remark: '仪表盘', data: { title: '参与率', list: [{ value: 5.6 }] } },
68
+          { type: 'dashboard', remark: '仪表盘', data: { title: '参与率', list: [{ value: 3.1 }] } },
64 69
         ],
65 70
       ],
66 71
     }
@@ -71,6 +76,7 @@ export default {
71 76
     pieDiagram,
72 77
     brokenLineGraph,
73 78
     ringChart,
79
+    dashboard,
74 80
   },
75 81
   computed: {
76 82
     ...mapState({