whyczyk
2021-03-22 fc74998431982dc1385d2930adcf339cbf15ffd6
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();