From fc74998431982dc1385d2930adcf339cbf15ffd6 Mon Sep 17 00:00:00 2001 From: whyczyk <525500596@qq.com> Date: 星期一, 22 三月 2021 13:40:47 +0800 Subject: [PATCH] 模块定时请求提交 --- src/components/charts/latticeBar.vue | 86 +++++++++++++++++++++++-------------------- 1 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/components/charts/latticeBar.vue b/src/components/charts/latticeBar.vue index 7f83cbb..9315fa1 100644 --- a/src/components/charts/latticeBar.vue +++ b/src/components/charts/latticeBar.vue @@ -172,48 +172,54 @@ this.$options.chartData = sendData; this.organizeData(sendData) } else { - let userId = localStorage.getItem('userId'); - let params = { - userId: userId - } - chargeAnalysis(params).then((res) => { - if (res.data.code == 1) { - let optionData = { - xData: [], - series: [{ - name: '鏀剧數', - data: [], - color: '#90ec7d' - }, { - name: '鍏呯數', - data: [], - color: '#ff6b6b' - }] - } - let resData = res.data.data; - for (let key in resData.reCharge) { - if (typeof resData.reCharge[key] == 'string') { - optionData.series[0].data.push(Number(resData.reCharge[key].split('%')[0])) - } else { - optionData.series[0].data.push(resData.reCharge[key]) - } - } - for (let key in resData.disCharge) { - optionData.xData.push(key) - if (typeof resData.disCharge[key] == 'string') { - optionData.series[1].data.push(Number(resData.disCharge[key].split('%')[0])) - } else { - optionData.series[1].data.push(resData.disCharge[key]) - } - } - this.$options.chartData = optionData; - this.organizeData(optionData) - } - }).catch((err) => { - console.log(err) - }); + this.postData() + setInterval(() => { + this.postData() + }, 3000) } }, + postData() { + let userId = localStorage.getItem('userId'); + let params = { + userId: userId + } + chargeAnalysis(params).then((res) => { + if (res.data.code == 1) { + let optionData = { + xData: [], + series: [{ + name: '鏀剧數', + data: [], + color: '#90ec7d' + }, { + name: '鍏呯數', + data: [], + color: '#ff6b6b' + }] + } + let resData = res.data.data; + for (let key in resData.reCharge) { + if (typeof resData.reCharge[key] == 'string') { + optionData.series[0].data.push(Number(resData.reCharge[key].split('%')[0])) + } else { + optionData.series[0].data.push(resData.reCharge[key]) + } + } + for (let key in resData.disCharge) { + optionData.xData.push(key) + if (typeof resData.disCharge[key] == 'string') { + optionData.series[1].data.push(Number(resData.disCharge[key].split('%')[0])) + } else { + optionData.series[1].data.push(resData.disCharge[key]) + } + } + this.$options.chartData = optionData; + this.organizeData(optionData) + } + }).catch((err) => { + console.log(err) + }); + }, resize() { setTimeout(() => { this.$options.chart.resize(); -- Gitblit v1.9.1