luyanan 6 years ago
parent
commit
387d7ba04a

+ 150 - 0
src/views/dashboard/admin/components/LineChart.vue

@ -0,0 +1,150 @@
1
<template>
2
  <div :class="className" :style="{height:height,width:width}"></div>
3
</template>
4
5
<script>
6
import echarts from 'echarts'
7
require('echarts/theme/macarons') // echarts theme
8
import { debounce } from '@/utils'
9
10
export default {
11
  props: {
12
    className: {
13
      type: String,
14
      default: 'chart'
15
    },
16
    width: {
17
      type: String,
18
      default: '100%'
19
    },
20
    height: {
21
      type: String,
22
      default: '350px'
23
    },
24
    autoResize: {
25
      type: Boolean,
26
      default: true
27
    },
28
    chartData: {
29
      type: Object
30
    }
31
  },
32
  data() {
33
    return {
34
      chart: null
35
    }
36
  },
37
  mounted() {
38
    this.initChart()
39
    if (this.autoResize) {
40
      this.__resizeHanlder = debounce(() => {
41
        if (this.chart) {
42
          this.chart.resize()
43
        }
44
      }, 100)
45
      window.addEventListener('resize', this.__resizeHanlder)
46
    }
47
48
    // 监听侧边栏的变化
49
    const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
50
    sidebarElm.addEventListener('transitionend', this.__resizeHanlder)
51
  },
52
  beforeDestroy() {
53
    if (!this.chart) {
54
      return
55
    }
56
    if (this.autoResize) {
57
      window.removeEventListener('resize', this.__resizeHanlder)
58
    }
59
60
    const sidebarElm = document.getElementsByClassName('sidebar-container')[0]
61
    sidebarElm.removeEventListener('transitionend', this.__resizeHanlder)
62
63
    this.chart.dispose()
64
    this.chart = null
65
  },
66
  watch: {
67
    chartData: {
68
      deep: true,
69
      handler(val) {
70
        this.setOptions(val)
71
      }
72
    }
73
  },
74
  methods: {
75
    setOptions({ expectedData, actualData } = {}) {
76
      this.chart.setOption({
77
        xAxis: {
78
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
79
          boundaryGap: false,
80
          axisTick: {
81
            show: false
82
          }
83
        },
84
        grid: {
85
          left: 10,
86
          right: 10,
87
          bottom: 20,
88
          top: 30,
89
          containLabel: true
90
        },
91
        tooltip: {
92
          trigger: 'axis',
93
          axisPointer: {
94
            type: 'cross'
95
          },
96
          padding: [5, 10]
97
        },
98
        yAxis: {
99
          axisTick: {
100
            show: false
101
          }
102
        },
103
        legend: {
104
          data: ['expected', 'actual']
105
        },
106
        series: [{
107
          name: 'expected', itemStyle: {
108
            normal: {
109
              color: '#FF005A',
110
              lineStyle: {
111
                color: '#FF005A',
112
                width: 2
113
              }
114
            }
115
          },
116
          smooth: true,
117
          type: 'line',
118
          data: expectedData,
119
          animationDuration: 2800,
120
          animationEasing: 'cubicInOut'
121
        },
122
        {
123
          name: 'actual',
124
          smooth: true,
125
          type: 'line',
126
          itemStyle: {
127
            normal: {
128
              color: '#3888fa',
129
              lineStyle: {
130
                color: '#3888fa',
131
                width: 2
132
              },
133
              areaStyle: {
134
                color: '#f3f8ff'
135
              }
136
            }
137
          },
138
          data: actualData,
139
          animationDuration: 2800,
140
          animationEasing: 'quadraticOut'
141
        }]
142
      })
143
    },
144
    initChart() {
145
      this.chart = echarts.init(this.$el, 'macarons')
146
      this.setOptions(this.chartData)
147
    }
148
  }
149
}
150
</script>

+ 79 - 0
src/views/dashboard/admin/index.vue

@ -0,0 +1,79 @@
1
<template>
2
  <div class="dashboard-editor-container">
3
4
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
5
      <line-chart :chart-data="lineChartData"></line-chart>
6
    </el-row>
7
8
   <!--  <el-row :gutter="32">
9
      <el-col :xs="24" :sm="24" :lg="8">
10
        <div class="chart-wrapper">
11
          <raddar-chart></raddar-chart>
12
        </div>
13
      </el-col>
14
      <el-col :xs="24" :sm="24" :lg="8">
15
        <div class="chart-wrapper">
16
          <pie-chart></pie-chart>
17
        </div>
18
      </el-col>
19
      <el-col :xs="24" :sm="24" :lg="8">
20
        <div class="chart-wrapper">
21
          <bar-chart></bar-chart>
22
        </div>
23
      </el-col>
24
    </el-row> -->
25
  </div>
26
</template>
27
28
29
<script>
30
import LineChart from './components/LineChart'
31
32
const lineChartData = {
33
  newVisitis: {
34
    expectedData: [100, 120, 161, 134, 105, 160, 165],
35
    actualData: [120, 82, 91, 154, 162, 140, 145]
36
  },
37
  messages: {
38
    expectedData: [200, 192, 120, 144, 160, 130, 140],
39
    actualData: [180, 160, 151, 106, 145, 150, 130]
40
  },
41
  purchases: {
42
    expectedData: [80, 100, 121, 104, 105, 90, 100],
43
    actualData: [120, 90, 100, 138, 142, 130, 130]
44
  },
45
  shoppings: {
46
    expectedData: [130, 140, 141, 142, 145, 150, 160],
47
    actualData: [120, 82, 91, 154, 162, 140, 130]
48
  }
49
}
50
51
export default {
52
  name: 'dashboard-admin',
53
  components: {
54
    LineChart
55
  },
56
  data() {
57
    return {
58
      lineChartData: lineChartData.newVisitis
59
    }
60
  },
61
  methods: {
62
    handleSetLineChartData(type) {
63
      this.lineChartData = lineChartData[type]
64
    }
65
  }
66
}
67
</script>
68
69
<style rel="stylesheet/scss" lang="scss" scoped>
70
.dashboard-editor-container {
71
  padding: 32px;
72
  background-color: rgb(240, 242, 245);
73
  .chart-wrapper {
74
    background: #fff;
75
    padding: 16px 16px 0;
76
    margin-bottom: 32px;
77
  }
78
}
79
</style>

+ 71 - 0
src/views/dashboard/other/index.vue

@ -0,0 +1,71 @@
1
<template>
2
  <div class="dashboard-editor-container">
3
    <div class=" clearfix">
4
      <pan-thumb style="float: left" :image="avatar"> Your roles:
5
        <span class="pan-info-roles" :key='item' v-for="item in roles">{{item}}</span>
6
      </pan-thumb>
7
      <div class="info-container">
8
        <span class="display_name">{{name}}</span>
9
        <span style="font-size:20px;padding-top:20px;display:inline-block;">Editor's Dashboard</span>
10
      </div>
11
    </div>
12
    <div>
13
      <img class="emptyGif" :src="emptyGif">
14
    </div>
15
  </div>
16
</template>
17
18
<script>
19
import { mapGetters } from 'vuex'
20
import PanThumb from '@/components/PanThumb'
21
22
export default {
23
  name: 'dashboard-editor',
24
  components: { PanThumb },
25
  data() {
26
    return {
27
      emptyGif: 'https://wpimg.wallstcn.com/0e03b7da-db9e-4819-ba10-9016ddfdaed3'
28
    }
29
  },
30
  computed: {
31
    ...mapGetters([
32
      'name',
33
      'avatar',
34
      'roles'
35
    ])
36
  }
37
}
38
</script>
39
40
<style rel="stylesheet/scss" lang="scss" scoped>
41
  .emptyGif {
42
    display: block;
43
    width: 45%;
44
    margin: 0 auto;
45
  }
46
47
  .dashboard-editor-container {
48
    background-color: #e3e3e3;
49
    min-height: 100vh;
50
    padding: 50px 60px 0px;
51
    .pan-info-roles {
52
      font-size: 12px;
53
      font-weight: 700;
54
      color: #333;
55
      display: block;
56
    }
57
    .info-container {
58
      position: relative;
59
      margin-left: 190px;
60
      height: 150px;
61
      line-height: 200px;
62
      .display_name {
63
        font-size: 48px;
64
        line-height: 48px;
65
        color: #212121;
66
        position: absolute;
67
        top: 25px;
68
      }
69
    }
70
  }
71
</style>