Commit 6049e46b by 朱建香

2017/12/21

1.优化首页代码
2.用新的轮询方法获取开门记录
parent a01869c1
...@@ -39,18 +39,21 @@ class Loop{ ...@@ -39,18 +39,21 @@ class Loop{
async sendRequest(){ async sendRequest(){
this.canSend = false; this.canSend = false;
var needAuth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; var needAuth = this.opts.needAuth !== undefined ? this.opts.needAuth : true;
var isDebug = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var isDebug = this.opts.isDebug !== undefined ? this.opts.isDebug : false;
// var send = this.opts.isCustom ? iot.business.api.sendCustom : iot.business.api.send; var withoutUgen = this.opts.withoutUgen !== undefined ? this.opts.withoutUgen : false;
// iot.business.api.send(this.url, { // iot.business.api.send(this.url, {
// iot.business.api.sendCustom(this.url, { // iot.business.api.sendCustom(this.url, {
try{ var urlParams = {
let response = await iot.business.api.send(this.url, {
type: this.opts.type, type: this.opts.type,
data: this.opts.data data: this.opts.data
}, needAuth, false, isDebug); };
if(this.intervalcb!= null){ try{
this.intervalcb.success(response); var response = null;
if(withoutUgen){
response = await iot.network.send(this.url, urlParams);
}else{
response = await iot.business.api.send(this.url, urlParams, needAuth, false, isDebug);
} }
if(await this.stopcondition(response)){ if(await this.stopcondition(response)){
if(this.fincb!= null){ if(this.fincb!= null){
...@@ -60,6 +63,9 @@ class Loop{ ...@@ -60,6 +63,9 @@ class Loop{
this.clearTime(); this.clearTime();
this.canSend = false; this.canSend = false;
}else{ }else{
if(this.intervalcb!= null){
this.intervalcb.success(response);
}
this.canSend = true; this.canSend = true;
} }
} }
...@@ -90,11 +96,14 @@ class Loop{ ...@@ -90,11 +96,14 @@ class Loop{
this.intervalcb = null; this.intervalcb = null;
this.fincb = null; this.fincb = null;
},this.timeout); },this.timeout);
console.log("第"+this.i+"次发送了请求");
console.log("发送时间"+new Date().getTime());
this.i++;
this.sendRequest(); this.sendRequest();
this.watcher = setInterval(() => { this.watcher = setInterval(() => {
if(this.canSend && this.canDo){ if(this.canSend && this.canDo){
this.canDo = false; this.canDo = false;
console.log("发送了请求"); console.log("第"+this.i+"次发送了请求");
console.log("发送时间"+new Date().getTime()); console.log("发送时间"+new Date().getTime());
this.i++; this.i++;
this.sendRequest(); this.sendRequest();
......
...@@ -19,11 +19,11 @@ const iot = new UIOT({ ...@@ -19,11 +19,11 @@ const iot = new UIOT({
cloud: { cloud: {
// url: 'http://wx.iotface.com' // url: 'http://wx.iotface.com'
//96环境 //96环境
// url: 'http://192.168.2.96:20000' url: 'http://192.168.2.96:20000'
//96外网 //96外网
// url: 'http://jycinema.u-gen.net' // url: 'http://jycinema.u-gen.net'
//正式 //正式
url: 'https://cloud.iot.u-gen.net/' // url: 'https://cloud.iot.u-gen.net/'
//正式测试 //正式测试
// url: 'https://cloud.iot.u-gen.net/test-openapi/' // url: 'https://cloud.iot.u-gen.net/test-openapi/'
}, },
...@@ -147,6 +147,37 @@ uPublic.logout = function(opts){ ...@@ -147,6 +147,37 @@ uPublic.logout = function(opts){
}); });
} }
uPublic.upDateRead = async function(key){
let oldHistory = {
alarm: {
time: null,
isReadFlag: true
},
notify: {
time: null,
isReadFlag: true
},
open: {
time: null,
isReadFlag: true
}
};
try{
oldHistory = await iot.storage.getMap('history');
console.log(oldHistory);
}
catch (error){
console.log(error);
}
let newHistory = oldHistory;
newHistory[key].isReadFlag = true;
iot.storage.setMap('history', newHistory, (response) => {
console.log(res);
}, () => {
});
}
iot.ready(() => { iot.ready(() => {
uPublic.recalc(); uPublic.recalc();
}); });
...@@ -275,189 +306,4 @@ iot.navigator.getCurrentWebView = function (){ ...@@ -275,189 +306,4 @@ iot.navigator.getCurrentWebView = function (){
return plus.webview.currentWebview(); return plus.webview.currentWebview();
} }
//function requestsend(url, opts, needAuth, isPublic, i){
// let data = [0,1,1,0,0,1,0,1,0,0,0];
// console.log("请求时间"+i+'-'+new Date().getTime());
// setTimeout(function(){
// console.log("返回时间"+i+'-'+new Date().getTime());
// opts.success(data[i]);
// },1000);
//
//}
//
//function clearTime(interval, intervalTwo, timeout){
// window.clearInterval(interval);
// window.clearInterval(intervalTwo);
// window.clearTimeout(timeout);
//}
//
//function sendRequest(url, params, fincb, intervalcb, handle, watcher, time, canSend, stopcondition, i){
// canSend(false);
// requestsend(url, {
// type: 'post',
// data: params.data,
// success: (response) => {
// intervalcb.success(response);
// if(stopcondition(response)){
// fincb.success(response);
// clearTime(handle, watcher, time);
// canSend(false);
// }else{
// canSend(true);
// }
// },
// error: (error) => {
// intervalcb.error(error);
// if(intervalcb.error(error)){
// canSend(true);
// }else{
// fincb.error(error);
// clearTime(handle, watcher, time);
// }
// },
// complete: () => {}
// }, true, false, i);
//
//}
//
//
//uComponents.loop = function(request, timeout, interval, fincb, stopcondition){
// var handle = null;
// var watcher = null;
// var time = null;
// var url = request.url;
// var opts = request.opts;
// var intervalTime = interval.delay;
// var intervalcb = interval.opts;
// var flag = true;
// var canSend = true;
// var canDo = true;
// var i = 0;
// console.log("开始");
// time = setTimeout(function(){
// clearTime(handle, watcher, time);
// canDo = false;
// fincb.error('timeout');
// console.log("超时");
// intervalcb.success = function(){
// return;
// };
// },timeout);
// sendRequest(url, opts, fincb, intervalcb, handle, watcher, time, function(res){
// canSend = res;
// if(canSend){
// watcher = setInterval(function(){
// if(canSend && canDo){
// canDo = false;
// console.log("发送了请求");
// console.log("发送时间"+new Date().getTime());
// i++;
// sendRequest(url, opts, fincb, intervalcb, handle, watcher, time, function(res){
// canSend = res;
// }, stopcondition, i);
// }
// },1000);
// }
// }, stopcondition, i);
// handle = setInterval(function(){
// canDo = true;
// },1000);
//// //一开始执行一次,发送一次请求
//// requestsend(url, {
//// data: {},
//// success: (response) => {
//// intervalcb.success(response);
//// if(stopcondition(response)){
//// //首次请求结果符合条件的话,结束整个方法
//// fincb.success(response);
//// clearTime(handle, time);
//// }else{
//// //首次请求结果不符合条件的话,每隔intervalTime时间发送请求
//// handle = setInterval(() => {
//// i++;
//// console.log(i);
//// if(flag){
//// flag = false;
//// requestsend(url, {
//// data: {},
//// success: (response) => {
//// intervalcb.success(response);
//// if(stopcondition(response)){
//// fincb.success(response);
//// clearTime(handle, time);
//// }
//// flag = true;
//// },
//// error: (error) => {
//// if(intervalcb.error(error)){
//// flag = false;
//// }else{
//// fincb.error(error);
//// clearTime(handle, time);
//// }
//// },
//// complete: {}
//// }, i);
//// }
//// },intervalTime);
//// }
//// },
//// error: (error) => {
//// intervalcb.error(error);
//// fincb.error(error);
//// clearTime(handle, time);
//// },
//// complete: {}
//// }, 0);
//}
//
////传递的参数依次是:
////1.request: 请求参数(数据类型: map,包括:url、header等);
////2.timeout: 整个方法的超时时间;
////3.interval: 发送请求的间隔时间、callback;
////4.fincb: 整个方法的callback;
////5.stopcondition: 请求停止所要符合的条件
//function sendloop(){
// uComponents.loop({url:'getLockInfo',opts: {
// success: (response) => {
// console.log(response);
// },
// error: (error) => {
// console.log(error);
// }
// }},6000, {
// delay: 1000,
// opts: {
// success: (response) => {
// console.log('intervalcbSuccess:'+response);
// },
// error: (error) => {
// console.log('intervalcbSuccess:'+error);
// }
// }
// }, {
// success: (response) => {
// console.log('fincbSuccess:'+response);
// },
// error: (error) => {
// console.log('fincbError'+error);
// }
// }, (response) => {
// if(response == 1){
// return true;
// }else{
// return false;
// }
// });
//}
//sendloop();
//setTimeout(function(){
// sendloop();
// setTimeout(function(){
// sendloop();
// },3000)
//
//},1000)
export {iot, uPublic, uComponents} export {iot, uPublic, uComponents}
\ No newline at end of file
...@@ -99,11 +99,12 @@ function initComponentsConfig() { ...@@ -99,11 +99,12 @@ function initComponentsConfig() {
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
if(data && data.record.length > 0){ if(data && data.record.length > 0){
let record = data.record; let record = data.record;
iot.storage.setMap('notifyTime', moment(record[0].time).unix(), (res) => { // iot.storage.setMap('notifyTime', moment(record[0].time).unix(), (res) => {
console.log(res); // console.log(res);
self.flag = false; // self.flag = false;
}, () => { // }, () => {
}); // });
uPublic.upDateRead('notify');
} }
} }
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
......
...@@ -101,16 +101,17 @@ function initComponentsConfig() { ...@@ -101,16 +101,17 @@ function initComponentsConfig() {
start_id: self.getStartId(), start_id: self.getStartId(),
page_size: PAGE_SIZE page_size: PAGE_SIZE
}, },
success: (response) => { success: async (response) => {
if(self.flag){ if(self.flag){
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
if(data && data.record.length > 0){ if(data && data.record.length > 0){
let record = data.record; let record = data.record;
iot.storage.setMap('alarmTime', moment(record[0].time).unix(), (res) => { // iot.storage.setMap('alarmTime', moment(record[0].time).unix(), (res) => {
console.log(res); // console.log(res);
self.flag = false; // self.flag = false;
}, () => { // }, () => {
}); // });
uPublic.upDateRead('alarm');
} }
} }
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
......
...@@ -133,11 +133,12 @@ function getHistoryRecord(self){ ...@@ -133,11 +133,12 @@ function getHistoryRecord(self){
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
if(data && data.record.length > 0){ if(data && data.record.length > 0){
let record = data.record; let record = data.record;
iot.storage.setMap('openTime', moment(record[0].time).unix(), (res) => { // iot.storage.setMap('openTime', moment(record[0].time).unix(), (res) => {
console.log(res); // console.log(res);
self.flag = false; // self.flag = false;
}, () => { // }, () => {
}); // });
uPublic.upDateRead('open');
} }
} }
}, },
......
...@@ -32,11 +32,11 @@ function init() { ...@@ -32,11 +32,11 @@ function init() {
extras: {}, extras: {},
unbindSucceess: false, unbindSucceess: false,
//门铃消息推送 //门铃消息推送
valueDoorbell: iot.navigator.getExtras().lockInfo.options[0], valueDoorbell: iot.navigator.getExtras().lockInfo.options.ring,
//报警消息推送 //报警消息推送
valueAlarm: iot.navigator.getExtras().lockInfo.options[1], valueAlarm: iot.navigator.getExtras().lockInfo.options.alarm,
//开发消息推送 //开发消息推送
valueOpendoor: iot.navigator.getExtras().lockInfo.options[2], valueOpendoor: iot.navigator.getExtras().lockInfo.options.open,
role: null, role: null,
valueIsClear: true, valueIsClear: true,
unbindShowDialog: false unbindShowDialog: false
......
...@@ -2158,9 +2158,7 @@ NetWork.send = function (url, params) { ...@@ -2158,9 +2158,7 @@ NetWork.send = function (url, params) {
if (params.error) params.error(err); if (params.error) params.error(err);
if (params.complete) params.complete(); if (params.complete) params.complete();
}); });
console.log("callback");
} else { } else {
console.log("promise");
return fetchPromise; return fetchPromise;
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment