首页 > 微信 > 详细

微信小程序Rx 引入 调用合并的方法

时间:2020-09-25 09:44:18      阅读:47      评论:0      收藏:0      [点我收藏+]
submit(){
const {radio,dateStartText,dateendText} =this.data
console.log(radio)
if(radio==‘‘){
Toast(‘请选择子设备‘)
return;
}
// if(!dateStartText||!dateendText){
// Toast(‘请选择日期‘)
// return;
// }
let arrData=wx.getStorageSync(‘subDeviceData‘)
arrData=arrData.filter(item=>item.name)

let dataType={}
let dataArrsy=[]
let timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;

arrData.forEach((item,index)=>{
console.log(item.deviceName)
dataArrsy.push(dataType={
IotId:item.iotId,
identifier:item.radio,
time:timestamp,
// endTime:this.data.dateendText,
// pageSize:100,
// productKey:item.productKey,
deviceName:item.deviceName
})

})
console.log(dataArrsy,‘dataArrsy‘)
function sum(arr) {//数组的数字相加
return arr.reduce(function(prev, curr, idx, arr){
return prev + curr;
});
}
const httpList=[]
const numLength=[]
for(var i=0;i<arrData.length;i++){
httpList.push(this.getproxy(dataArrsy[i],dataArrsy[i].deviceName))
}
Rx.Observable.forkJoin(httpList)
.subscribe(resp => {
resp.forEach((item,index)=>{
numLength.push(item.data.length)
})
console.log(sum(numLength)==0,sum(numLength))
if(sum(numLength)==0){
wx.showToast({
title:‘暂无数据可以展示‘, // 提示的内容,
icon: ‘none‘, // 图标,
mask: true, // 显示透明蒙层,防止触摸穿透,
success: res => { }
});
return;
}
wx.setStorageSync(‘radio‘, radio)
wx.setStorageSync(‘deviceProperties‘, resp)
wx.setStorageSync(‘chooseService‘, resp)
wx.navigateTo({
url: ‘/pages/index/listSWG/exhibition/charts‘,
})
})
},
getproxy(data,deviceName){
return new Rx.Observable(observer=>{
http.request({
url: ‘p-net-deviceProperties-time‘,
method: ‘POST‘,
data,
success: (res) => {
if (res.code==‘ok‘) {
console.log(res)
res.deviceName=deviceName
observer.next(res);
observer.complete();
} else {
Toast(res.data || res.message)
wx.showToast({
title: res.data, // 提示的内容,
icon: ‘none‘, // 图标,
mask: true, // 显示透明蒙层,防止触摸穿透,
success: res => { }
});
observer.error(res);
}
}
})
})
},

  

微信小程序Rx 引入 调用合并的方法

原文:https://www.cnblogs.com/alone2015/p/13728158.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!