ZM—封装方法、接收数据

封装doAct()、list()方法,接收数据

项目要求:

还没有搞懂平台内部代码,只能大概的看一下。
要求:接入接口。


doAct()方法:

这个方法收到的是后台传的数据。

// 提交执行服务的动作,比如自定义动作
http.doAct = async (servId, act, params) => {
    const res = await http.post(`/${servId}.${act}.do`, params)
    if (res.status == 200) {
        return res.data
    } else throw res
}

使用方法:
在vue方法中定义方法
async异步(具体我也不懂)
doAct内的第一个参数是后台给的地址,第二个参数是后台写的方法。

async get() {
    const res = await this.$http.doAct("STAFF_DATA_SERV", "getMdcdmkStaffData");
    this.tableData = res.tableData || '' 
    this.drawLineSafe();
},
async ecahrttt(){
   const res = await this.$http.doAct("STAFF_DATA_SERV", "getMdcdmkDevData");
   this.homeEchartsData = res.homeEchartsData
},

dataList()方法:

此方法是获取数据集的数据,数据集内数据格式是什么它输出的格式就是什么。

dataList () {
            return this.dataSet && this.dataSet.data;
        },

使用方法:

data() {
            return {
                homeEchartsData: {
                    // planData1: '2703.05',
                    // planData2: '2081.00',
                    // planData3: '400.00',
                    // planData4: '400.80',
                    // realData1: '0',
                    // realData2: '0',
                    // realData3: '0',
                    // realData4: '200',
                },
            };
        },
          watch:{
             dataList(newVal,oldVal){
            	this.homeEchartsData=newVal[0]
            	this.drawLinedljingji(this.$refs.generate,'发电煤耗',(this.homeEchartsData.planData1/4*5).toFixed(0),'#FBFDB9','#FF3F36',this.homeEchartsData.realData1);
            },
        },

list()方法:

方法接收的也是平台绑定的数据集的数据,与dataList()不同的是list()对数据进行处理,
此时打印出的返回的结果是数组,常用于折线图、柱状图等图表数据的接收。

list() {
      if (this.item.xDim) {
        var entries = {};
        this.dataList.forEach(item => {
          // console.log(Object.entries(item))
          Object.entries(item).forEach(itemSec => {
            let [key, value] = itemSec
            if (entries[key] == undefined) {
              entries[key] = [];
            }
            entries[key].push(value)
          })
        })
      }
      return {
        entries
      };
    },

使用方法:
常用于数据集接收数据,方法写在watch里,对数据进行监听。

watch:{
     list(newVal,oldVal){
     //  console.log(newVal)
     this.homeEchartsData=newVal.entries?newVal.entries:''//解决无数据时报错
     this.drawdllinesIndex(this.homeEchartsData);
   },
},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值