liuxiaolong
2019-05-06 2ab7a76a38fbf8fa107bf6371f5410ba54e1d394
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
234
235
236
237
238
239
<template>
  <b-card no-body class="pt-2" style="height: 100%;">
    <h4 class="fw900 flex-row-between pl-4 pr-4 pt-4 pb-2">
      人员进出流量趋势
      <b-button-group size="sm">
        <b-button :variant="chartType === 'today'?'primary':'default'" @click="chartType = 'today'">今日</b-button>
        <b-button :variant="chartType === 'week'?'primary':'default'" @click="chartType = 'week'">本周</b-button>
        <b-button :variant="chartType === 'month'?'primary':'default'" @click="chartType = 'month'">本月</b-button>
      </b-button-group>
    </h4>
    <vue-echart :options="lineOptions" :theme="polarTheme" :auto-resize="true"></vue-echart>
  </b-card>
</template>
<style>
.echarts {
  height: 100% !important;
  width: 100% !important;
}
</style>
<script>
import ECharts from 'vue-echarts/components/ECharts.vue'
import 'echarts/lib/chart/line'
import 'echarts/theme/shine'
import { getTeacherSignCountData } from '@/server/home.js'
let lineOption = {
  tooltip: {
    trigger: 'axis',
    position: function(pt) {
      return [pt[0], '10%']
    }
  },
  grid: {
    top: '5%',
    left: '3%',
    right: '4%',
    bottom: '18%',
    containLabel: true
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: []
  },
  yAxis: {
    type: 'value',
    boundaryGap: [0, '100%']
  },
  dataZoom: [
    {
      type: 'inside',
      start: 0,
      end: 10
    },
    {
      start: 0,
      end: 10,
      // handleIcon:
      //   'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
      handleSize: '80%',
      handleStyle: {
        color: '#fff',
        shadowBlur: 3,
        shadowColor: 'rgba(0, 0, 0, 0.6)',
        shadowOffsetX: 2,
        shadowOffsetY: 2
      }
    }
  ],
  series: [
    {
      name: '进',
      type: 'line',
      smooth: true,
      symbol: 'none',
      sampling: 'average',
      itemStyle: {
        color: '#075a00'
      },
      data: []
    },
    {
      name: '出',
      type: 'line',
      smooth: true,
      symbol: 'none',
      sampling: 'average',
      itemStyle: {
        color: '#ffa407'
      },
      data: []
    }
  ]
}
export default {
  name: 'AnalysisLineChart',
  props: {},
  data() {
    return {
      userInfo: this.$store.getters.basicUserInfo,
      /* 图表 */
      lineOptions: lineOption,
      polarTheme: 'shine',
      chartType: 'today'
    }
  },
  methods: {
    /* 查询图表数据 */
    async getTeacherSignCountData() {
      let res = await getTeacherSignCountData({
        orgId: this.userInfo.orgId,
        type: 'teacher',
        signDate: this.$moment().format('YYYY-MM-DD')
      })
      if (
        res &&
        !isNaN(parseInt(res.unsigned)) &&
        !isNaN(parseInt(res.signed))
      ) {
        const countNum = parseInt(res.unsigned) + parseInt(res.signed)
        this.lineOptions.series[0].data = [
          { value: res.unsigned, name: '未签到', countNum },
          { value: res.signed, name: '已签到', countNum }
        ]
      }
    },
    randomData(sTime, value) {
      value = value + Math.random() * 18 - 10
      return {
        name: this.$moment(sTime).format('HH:mm:ss'),
        value: Math.round(value)
      }
    },
    setChartData() {
      let value1 = Math.random() * 100
      let value2 = Math.random() * 80
      let sTime = this.$moment('00:00:00', 'HH:mm;ss').valueOf()
      let date = []
      let data1 = []
      let data2 = []
      for (let i = 0; i < 1 * 60 * 24; i++) {
        sTime += 60 * 1000
        date.push(this.randomData(sTime, value1).name)
        data1.push(this.randomData(sTime, value1))
        data2.push(this.randomData(sTime, value2))
      }
      this.lineOptions.xAxis.data = date
      this.lineOptions.series[0].data = data1
      this.lineOptions.series[1].data = data2
    },
    dayRandomData(sTime, value) {
      value = value + Math.random() * 18 - 10
      return {
        name: this.$moment(sTime).format('YYYY-MM-DD'),
        value: Math.round(value)
      }
    },
    setDayChartData() {
      let value1 = Math.random() * 100
      let value2 = Math.random() * 80
      let sTime = this.$moment('00:00:00', 'HH:mm;ss').valueOf()
      let date = []
      let data1 = []
      let data2 = []
      for (let i = 0; i < 30; i++) {
        sTime += 1000 * 60 * 60 * 24
        date.push(this.dayRandomData(sTime, value1).name)
        data1.push(this.dayRandomData(sTime, value1))
        data2.push(this.dayRandomData(sTime, value2))
      }
      this.lineOptions.xAxis.data = date
      this.lineOptions.series[0].data = data1
      this.lineOptions.series[1].data = data2
    }
  },
  created() {
    this.setChartData()
  },
  components: {
    'vue-echart': ECharts
  },
  watch: {
    chartType(val) {
      if (val === 'today') {
        this.setChartData()
      }
      if (val === 'week') {
        this.setDayChartData()
      }
      if (val === 'month') {
        this.setDayChartData()
      }
    }
  }
}
</script>
 
<style lang="scss" scoped>
.btn-content {
  display: flex;
  justify-content: flex-end;
}
.alarm-box {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 9;
  .badge-default {
    background: #ccc;
  }
}
div,
ul,
li,
img,
span,
a,
p {
  /* 抑制选中 */
  -moz-user-select: none;
  -webkit-user-select: none;
  user-select: none;
}
.mapDeviceType-box {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 9;
  background: rgba(255, 255, 255, 0.8);
}
.mapDeviceType-box .mapDeviceType-item {
  /* .icon{} */
  .content {
    line-height: 20px;
  }
}
.fw900{
  font-weight: 900;
}
</style>