123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <template>
- <view>
- <uni-section title="选择开始时间" type="line"
- style="width:80%;display: flex;align-items: center;margin:40rpx 0 20rpx 0">
- <uni-data-select v-model="value" :localdata="range" @change="change"></uni-data-select>
- </uni-section>
- <template v-if="clear">
- <view v-for="item in echartsData" :key="item.id" style="padding-right:20rpx">
- <view v-if="item.chartType==='pie'">
- <view class="title" v-if="echartsData.length">
- {{item.chartName}}
- </view>
- <pieEcharts :echartsData="item" @piePolling="piePolling" />
- </view>
- <view v-if="item.chartType==='bar'">
- <view class="title" v-if="echartsData.length">
- {{item.chartName}}
- </view>
- <barEcharts :echartsData="item" @barPolling="barPolling" />
- </view>
- <view v-if="item.chartType==='line'">
- <view class="title" v-if="echartsData.length">
- {{item.chartName}}
- </view>
- <lineEcharts :echartsData="item" @linePolling="linePolling" />
- </view>
- </view>
- </template>
- <u-empty text="暂无数据" icon="../../static/data.png" v-if="!echartsData.length"></u-empty>
- </view>
- </template>
- <script>
- import lineEcharts from '../../components/ecahrts/line-echarts.vue'
- import pieEcharts from '../../components/ecahrts/pie-echarts.vue'
- import barEcharts from '../../components/ecahrts/bar-echarts.vue'
- import {
- nowDate,
- timeToDate
- } from '../../utils/date.js'
- export default {
- components: {
- lineEcharts,
- pieEcharts,
- barEcharts
- },
- data() {
- return {
- queryParams: {
- page: 1,
- limit: 999
- },
- //图表数据
- echartsData: [],
- value: 3600000,
- startTime: null,
- range: [{
- value: 3600000,
- text: "近一小时"
- },
- {
- value: 10800000,
- text: "近三小时"
- },
- {
- value: 86400000,
- text: "近一天"
- },
- ],
- clear: true
- }
- },
- onShow() {
- this.clear = true
- this.value = null
- this.startTime = timeToDate(new Date().getTime() - 3600000)
- this.temperature()
- },
- onHide() {
- this.clear = false
- },
- methods: {
- //用户图表数据
- temperature() {
- this.echartsData = []
- uni.$http.get('/chart/getAllOkChart', this.queryParams).then(res => {
- const data = res.data
- if (data.code === 200) {
- const {
- reportTableList
- } = data.data
- reportTableList.map(item => {
- this.getChartData(item.id)
- })
- }
- })
- },
- getChartData(id) {
- let chartParams = {
- id: id,
- startTime: this.startTime,
- endTime: nowDate()
- }
- uni.$http.get('/chart/getChartById', chartParams).then(res => {
- const data = res.data
- if (data.code === 200) {
- this.echartsData.push(data.data)
- }
- })
- },
- change(e) {
- if (e) {
- this.startTime = timeToDate(new Date().getTime() - e)
- } else {
- this.startTime = timeToDate(new Date().getTime() - 3600000)
- this.echartsData = []
- clearInterval(this.barTime)
- clearInterval(this.lineTime)
- clearInterval(this.pieTime)
- }
- this.temperature()
- }
- }
- };
- </script>
- <style scoped>
- .title {
- margin: 34rpx 0 10rpx 20rpx;
- font-size: 28rpx;
- color: #666666;
- }
- ::v-deep .uni-section-content {
- width: 50%;
- margin-bottom: 20rpx;
- }
- </style>
|