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);
......
...@@ -101,11 +101,9 @@ function init() { ...@@ -101,11 +101,9 @@ function init() {
flag: true, flag: true,
time: null, time: null,
timeout: null, timeout: null,
handle: null,
remoteTime: null remoteTime: null
}, },
mounted(){ mounted(){
uComponents.showLoading(this); uComponents.showLoading(this);
notificationListener(this); notificationListener(this);
let self = this; let self = this;
...@@ -431,113 +429,6 @@ function initComponentsConfig() { ...@@ -431,113 +429,6 @@ function initComponentsConfig() {
} }
} }
function loopGetLockInfo(self, delay, timeout){
// if(self.handle == null){
// self.handle = setInterval(function(){
// getLockInfo(self);
// },delay*1000);
// let time = setTimeout(function () {
// window.clearInterval(self.handle);
// window.clearTimeout(time);
// self.handle = null;
// }, timeout * 1000);
// }
new Loop({
request: {
url: 'lock/getLockInfo',
opts: {
type: 'post',
isCustom: true,
data: {
device_id: self.deviceId
}
}
},
timeout: 10000,
interval:{
delay: 3000,
cb: {
success: (response) => {
console.log('intervalcbSuccess:'+JSON.stringify(response));
},
error: (error) => {
console.log('intervalcbError:'+JSON.stringify(error));
}
}
},
fincb: {
success: (response) => {
console.log("insuccess");
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
getLockInfoSuccess(self, data);
}else{
setValueOfSwitch(self, true);
self.setLockId(null);
self.mac = null;
self.deviceId = null;
self.uuid = null;
uComponents.changeMarqueeText(self, [Vue.t('device.defaultNewMsg')]);
self.activeFlag = false;
self.opendoorRecordFlag = false;
self.securityAlarmFlag = false;
self.hijackAlarmFlag = false;
}
},
error: (error) => {
// uPublic.openRequestErrorAlert(self);
console.log(error);
},
complete: () => {
uComponents.hideLoading(self);
}
},
stopcondition: async (response) => {
let data = response.data;
console.log(data.open_time);
var notifyTime = null;
var alarmTime = null;
var openTime = null;
try{
notifyTime = await iot.storage.getMap('notifyTime');
alarmTime = await iot.storage.getMap('alarmTime');
openTime = await iot.storage.getMap('openTime');
}
catch (error) {
console.log(error);
}
let newNotifyTime = null;
let newAlarmTime = null;
let newOpenTime = null;
if(data.open_time != null){
newOpenTime = moment(data.open_time).unix();
}
if(data.alarm_time != null){
newAlarmTime = moment(data.alarm_time).unix();
}
if(data.notify_time != null){
newNotifyTime = moment(data.notify_time).unix();
}
console.log(openTime);
console.log(newOpenTime);
console.log(alarmTime);
console.log(newAlarmTime);
console.log(notifyTime);
console.log(newNotifyTime);
if(openTime != newOpenTime || alarmTime != newAlarmTime || notifyTime != newNotifyTime){
console.log("innnnnnn");
return true;
}
}
}).start();
}
function getDevices(self){ function getDevices(self){
iot.business.sds.getDevicesByUser({ iot.business.sds.getDevicesByUser({
success: (response) => { success: (response) => {
...@@ -555,16 +446,11 @@ function getDevices(self){ ...@@ -555,16 +446,11 @@ function getDevices(self){
uuid: self.uuid uuid: self.uuid
}, },
success: (response) => { success: (response) => {
console.log("getInfo");
console.log(response); console.log(response);
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
if(data){ if(data){
console.log(data);
if(data.hasOwnProperty('relAccounts')){
self.userInfo = data.relAccounts;
getLockInfo(self); getLockInfo(self);
} }
}
}, },
error: (error) => { error: (error) => {
console.log(error); console.log(error);
...@@ -573,18 +459,7 @@ function getDevices(self){ ...@@ -573,18 +459,7 @@ function getDevices(self){
}); });
} }
}else{ }else{
setValueOfSwitch(self, true); initDeviceInfo(self);
self.setLockId(null);
self.mac = null;
self.deviceId = null;
self.uuid = null;
uComponents.changeMarqueeText(self, [Vue.t('device.defaultNewMsg')]);
self.activeFlag = false;
self.opendoorRecordFlag = false;
self.securityAlarmFlag = false;
self.hijackAlarmFlag = false;
self.setRemoteOpendoorDisabledFlag(true);
self.setValueRemoteOpendoor(0);
uComponents.hideLoading(self); uComponents.hideLoading(self);
} }
}, },
...@@ -602,119 +477,137 @@ function getDevices(self){ ...@@ -602,119 +477,137 @@ function getDevices(self){
}); });
} }
function registerPushListener(self){
iot.business.sds.registerPushListener({ function getLockInfo(self){
console.log("getLockInfo");
iot.business.api.sendCustom('lock/getLockInfo',{
data: {
device_id: self.deviceId
},
success: (response) => { success: (response) => {
console.log("registerPushListener");
console.log(response); console.log(response);
let data = uPublic.checkResponseData(response.data.params.data); let data = uPublic.checkResponseData(response.data);
if(data){ if(data){
sdsDataPorcessing(self, data); getLockInfoSuccess(self, data);
}else{
initDeviceInfo(self);
} }
}, },
error: (error) => { error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: 常链接失败'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'常链接失败');
}
uPublic.openRequestErrorAlert(self); uPublic.openRequestErrorAlert(self);
console.log(error);
},
complete: () => {
uComponents.hideLoading(self);
} }
}); });
} }
async function getRecordTime(self, data){ function getLockInfoSuccess(self, data){
try{ //判断云端是否绑定
self.notifyTime = await iot.storage.getMap('notifyTime'); if(data.lock_id){
self.alarmTime = await iot.storage.getMap('alarmTime'); //获取‘未读’小红点状态
self.openTime = await iot.storage.getMap('openTime'); // getRecordTime(self, data);
} //更改按钮为‘可点击’样式
catch (error) { setValueOfSwitch(self, false);
console.log(error); //设置门锁信息
} self.setLockInfo(data);
let newNotifyTime = moment(data.notify_time).unix(); self.setLockId(data.lock_id);
let newAlarmTime = moment(data.alarm_time).unix(); self.setRole(data.role);
let newOpenTime = moment(data.open_time).unix(); //判断是否第一次获取门锁信息
let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss").unix(); if(self.isFirstGetLockInfo){
if(self.notifyTime){ getDeviceStatus(self);
if(newNotifyTime != null && newNotifyTime - self.notifyTime > 0){ self.setIsFirstGetLockInfo(false);
self.securityAlarmFlag = true;
self.notifyTime = newNotifyTime;
}else{
self.securityAlarmFlag = false;
} }
//存储最后一条历史记录的ID
let historyId = data.info.historyId;
iot.storage.setMap('historyId', historyId, (res) => {
console.log(res);
}, () => {
});
//存储历史、安全、劫持记录的时间
let historyRecord = data.info.history;
updateHistoryMap(self, historyRecord);
//拼接首页滚动的三条记录
let record = data.info.history.open;
if(record && record.length){
self.newMsg = [];
for(let i=0; i< record.length; i++){
let msg = '';
if(record[i].nickname == null){
msg = ' ID:' + record[i].openId;
}else{ }else{
if(newNotifyTime != null && now - newNotifyTime < 3600){ msg = record[i].nickname;
self.securityAlarmFlag = true;
self.notifyTime = newNotifyTime;
}else{
self.securityAlarmFlag = false;
} }
self.newMsg.push(moment(record[i].time).format("YY.MM.DD HH:mm") + msg + Vue.t('opendoorRecord.'+config.openDoorMode[record[i].mode]+''));
} }
if(self.alarmTime){ uComponents.changeMarqueeText(self, self.newMsg);
if(newAlarmTime != null && newAlarmTime - self.alarmTime > 0){ if(self.newMsg.length >= 2){
self.hijackAlarmFlag = true; self.activeFlag = true;
self.alarmTime = newAlarmTime;
}else{ }else{
self.hijackAlarmFlag = false; self.activeFlag = false;
} }
}else{ }else{
if(newAlarmTime != null && now - newAlarmTime < 3600){ uComponents.changeMarqueeText(self, [Vue.t('device.noNewMsg')]);
self.hijackAlarmFlag = true; self.activeFlag = false;
self.alarmTime = newAlarmTime; }
}else{ }else{
self.hijackAlarmFlag = false; uComponents.changeMarqueeText(self, [Vue.t('device.defaultNewMsg')]);
self.activeFlag = false;
} }
}
async function updateHistoryMap(self, historyRecord){
let oldHistory = {
alarm: {
time: null,
isReadFlag: true
},
notify: {
time: null,
isReadFlag: true
},
open: {
time: null,
isReadFlag: true
} }
if(self.openTime){ };
// console.log("openTime"+newOpenTime.diff(self.openTime, 'seconds')); try{
if(newOpenTime != null && newOpenTime - self.openTime > 0){ oldHistory = await iot.storage.getMap('history');
self.opendoorRecordFlag = true; console.log(oldHistory);
self.openTime = newOpenTime;
}else{
self.opendoorRecordFlag = false;
} }
}else{ catch (error) {
// console.log("openTime"+now.diff(newOpenTime, 'hours')); console.log(error);
if(newOpenTime != null && now.diff - newOpenTime < 3600){
self.opendoorRecordFlag = true;
self.openTime = newOpenTime;
}else{
self.opendoorRecordFlag = false;
} }
console.log(oldHistory.open.time);
let openHistory = historyRecord.open;
let newHistory = oldHistory;
console.log(historyRecord.hasOwnProperty('alarm') && oldHistory.alarm.time != moment(historyRecord.alarm).unix());
if(historyRecord.hasOwnProperty('alarm') && oldHistory.alarm.time != moment(historyRecord.alarm).unix()){
newHistory.alarm.time = moment(historyRecord.alarm).unix();
newHistory.alarm.isReadFlag = false;
} }
}
//获取websql上的firstLogin if(openHistory.length && oldHistory.open.time != moment(openHistory[0].time).unix()){
function getRecordTimeMap(time) { newHistory.open.time = moment(openHistory[0].time).unix();
return new Promise(function (resolve, reject) { newHistory.open.isReadFlag = false;
// console.log(time); }
iot.storage.getMap(time, (res) => { if(historyRecord.hasOwnProperty('notify') && oldHistory.notify.time != moment(historyRecord.notify).unix()){
if (res) { newHistory.notify.time = moment(historyRecord.notify).unix()
// console.log('获取时间:'+moment(res).format('YYYY-MM-DD hh:mm:ss')); newHistory.open.isReadFlag = false;
resolve(res); }
} else {
reject(res); iot.storage.setMap('history', newHistory, (response) => {
} console.log(res);
}, (err) => { }, () => {
console.log(err);
}); });
})
}
function setValueOfSwitch(self, flag){ iot.storage.getMap('history', (response) => {
self.setOpendoorRecordDisabledFlag(flag); self.securityAlarmFlag = !response.notify.isReadFlag;
self.setSecurityAlarmDisabledFlag(flag); self.hijackAlarmFlag = !response.alarm.isReadFlag;
self.setDoorlockUserDisabledFlag(flag); self.opendoorRecordFlag = !response.open.isReadFlag;
self.setHijackAlarmDisabledFlag(flag); }, () => {
self.setDoorlockManageDisabledFlag(flag); });
self.valueOpendoorRecord = !flag;
self.valueSecurityAlarm = !flag;
self.valueDoorlockUser = !flag;
self.valueHijackAlarm = !flag;
self.valueDoorlockManage = !flag;
} }
function getDeviceStatus(self){ function getDeviceStatus(self){
...@@ -742,55 +635,32 @@ function getDeviceStatus(self){ ...@@ -742,55 +635,32 @@ function getDeviceStatus(self){
}); });
} }
function getLockInfo(self){ function getNewInfo(self){
console.log("getLockInfo"); console.log("getNewInfo");
iot.business.api.sendCustom('lock/getLockInfo',{ iot.business.api.sendCustom('lock/getNewInfo',{
data: { data: {
device_id: self.deviceId device_id: self.deviceId
}, },
success: (response) => { success: (response) => {
console.log(response); console.log(response);
let data = uPublic.checkResponseData(response.data); // let data = uPublic.checkResponseData(response.data);
if(data){ // if(data){
getLockInfoSuccess(self, data); // getLockInfoSuccess(self, data);
// getRecordTime(self, data);
// //判断云端是否绑定
// if(data.lock_id){
// setValueOfSwitch(self, false);
// self.setLockInfo(data);
// self.setLockId(data.lock_id);
// self.setRole(data.role);
// if(self.isFirstGetLockInfo){
// getDeviceStatus(self);
// self.setIsFirstGetLockInfo(false);
// }
// if(data.info && data.info.length){
// self.newMsg = [];
// for(let i=0; i< data.info.length; i++){
// let msg = '';
// if(data.info[i].nickname == null){
// msg = ' ID:' + data.info[i].openId;
// }else{
// msg = data.info[i].nickname;
// }
// self.newMsg.push(moment(data.info[i].time).format("YY.MM.DD HH:mm") + msg + Vue.t('opendoorRecord.'+config.openDoorMode[data.info[i].mode]+''));
//// }
// }
// uComponents.changeMarqueeText(self, self.newMsg);
// if(self.newMsg.length >= 2){
// self.activeFlag = true;
// }else{
// self.activeFlag = false;
// }
// }else{
// uComponents.changeMarqueeText(self, [Vue.t('device.noNewMsg')]);
// self.activeFlag = false;
// }
// }else{ // }else{
// uComponents.changeMarqueeText(self, [Vue.t('device.defaultNewMsg')]); // initDeviceInfo(self);
// self.activeFlag = false;
// } // }
}else{ },
error: (error) => {
uPublic.openRequestErrorAlert(self);
console.log(error);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
//云端获取设备信息失败
function initDeviceInfo(self){
setValueOfSwitch(self, true); setValueOfSwitch(self, true);
self.setLockId(null); self.setLockId(null);
self.mac = null; self.mac = null;
...@@ -801,123 +671,149 @@ function getLockInfo(self){ ...@@ -801,123 +671,149 @@ function getLockInfo(self){
self.opendoorRecordFlag = false; self.opendoorRecordFlag = false;
self.securityAlarmFlag = false; self.securityAlarmFlag = false;
self.hijackAlarmFlag = false; self.hijackAlarmFlag = false;
self.setRemoteOpendoorDisabledFlag(true);
self.setValueRemoteOpendoor(0);
}
async function loopGetLockInfo(self, delay, timeout){
let oldHistoryId = null;
try{
oldHistoryId = await iot.storage.getMap('historyId');
}
catch (error){
console.log(error);
}
new Loop({
request: {
url: 'lock/getNewInfo',
opts: {
type: 'post',
data: {
history_id: oldHistoryId,
device_id: self.deviceId
}
} }
}, },
timeout: 20000,
interval:{
delay: 3000,
cb: {
success: (response) => {
console.log('intervalcbSuccess:'+JSON.stringify(response));
},
error: (error) => {
console.log('intervalcbError:'+JSON.stringify(error));
}
}
},
fincb: {
success:(response) => {
console.log(response);
let historyRecord = response.data.history;
updateHistoryMap(self, historyRecord);
},
error: (error) => { error: (error) => {
uPublic.openRequestErrorAlert(self);
console.log(error); console.log(error);
}, },
complete: () => { complete: () => {
uComponents.hideLoading(self); uComponents.hideLoading(self);
} }
},
stopcondition: async (response) => {
console.log(response);
let data = response.data;
if(data.hasOwnProperty('historyId')){
let newHistoryId = data.historyId;
if(oldHistoryId != newHistoryId){
iot.storage.setMap('historyId', newHistoryId, (res) => {
console.log(res);
}, () => {
}); });
} return true;
}
}
function getLockInfoSuccess(self, data){
//判断云端是否绑定
if(data.lock_id){
//获取‘未读’小红点状态
getRecordTime(self, data);
//更改按钮为‘可点击’样式
setValueOfSwitch(self, false);
//设置门锁信息
self.setLockInfo(data);
self.setLockId(data.lock_id);
self.setRole(data.role);
//判断是否第一次获取门锁信息
if(self.isFirstGetLockInfo){
getDeviceStatus(self);
self.setIsFirstGetLockInfo(false);
} }
//拼接首页滚动的三条记录 }).start();
if(data.info && data.info.length){ }
self.newMsg = [];
for(let i=0; i< data.info.length; i++){ async function getRecordTime(self, data){
let msg = ''; console.log(getRecordTime);
if(data.info[i].nickname == null){ try{
msg = ' ID:' + data.info[i].openId; self.notifyTime = await iot.storage.getMap('notifyTime');
}else{ self.alarmTime = await iot.storage.getMap('alarmTime');
msg = data.info[i].nickname; self.openTime = await iot.storage.getMap('openTime');
} }
self.newMsg.push(moment(data.info[i].time).format("YY.MM.DD HH:mm") + msg + Vue.t('opendoorRecord.'+config.openDoorMode[data.info[i].mode]+'')); catch (error) {
console.log(error);
} }
uComponents.changeMarqueeText(self, self.newMsg);
if(self.newMsg.length >= 2){ let newNotifyTime = data.notify_time == null? null : moment(data.notify_time).unix();
self.activeFlag = true; let newAlarmTime = data.alarm_time == null? null : moment(data.alarm_time).unix();
let newOpenTime = data.open_time == null? null : moment(data.open_time).unix();
self.securityAlarmFlag = showNewMessage(self.notifyTime, newNotifyTime);
self.hijackAlarmFlag = showNewMessage(self.alarmTime, newAlarmTime);
self.opendoorRecordFlag = showNewMessage(self.openTime, newOpenTime);
}
function showNewMessage(oldTime, newTime, flag){
let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss").unix();
console.log(oldTime);
console.log(newTime);
if(oldTime){
if(newTime != null && newTime - oldTime > 0){
return true;
oldTime = newTime;
}else{ }else{
self.activeFlag = false; return false;
} }
}else{ }else{
uComponents.changeMarqueeText(self, [Vue.t('device.noNewMsg')]); if(newTime != null && now - newTime < 3600){
self.activeFlag = false; return true;
} oldTime = newTime;
}else{ }else{
uComponents.changeMarqueeText(self, [Vue.t('device.defaultNewMsg')]); return false;
self.activeFlag = false; }
} }
} }
////设置设备信息 function setValueOfSwitch(self, flag){
//function setDevceInfo(self, data) { self.setOpendoorRecordDisabledFlag(flag);
// console.log(data); self.setSecurityAlarmDisabledFlag(flag);
// let notifyMode = ['1','2','3']; self.setDoorlockUserDisabledFlag(flag);
// console.log(notifyMode.indexOf(data.notify_type.value)); self.setHijackAlarmDisabledFlag(flag);
// if(data.BatteryPercentage){ self.setDoorlockManageDisabledFlag(flag);
// self.setBatteryPercent(data.BatteryPercentage.value); self.valueOpendoorRecord = !flag;
// if(data.BatteryPercentage.value >= 10){ self.valueSecurityAlarm = !flag;
// //向上取整 self.valueDoorlockUser = !flag;
// self.setBatteryState(config.powerIcon[Math.ceil(data.BatteryPercentage.value/20)]); self.valueHijackAlarm = !flag;
// }else{ self.valueDoorlockManage = !flag;
// self.setBatteryState(config.powerIcon[Math.round(data.BatteryPercentage.value/20)]); }
// }
// } function registerPushListener(self){
// if(data.action.value == 'notify'){ iot.business.sds.registerPushListener({
// if(data.notify_type.value == 104){ success: (response) => {
// //门铃响了 console.log("registerPushListener");
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss"); console.log(response);
// let time = moment(data.time.value, "YY-MM-DD-hh-mm-ss"); let data = uPublic.checkResponseData(response.data.params.data);
//// console.log('门铃时间差'+now.diff(time,'seconds')+'timeout'+config.ringBell_timeout); if(data){
// if(now.diff(time,'seconds') < config.ringBell_timeout && now.diff(time,'seconds') > 0){ sdsDataPorcessing(self, data);
// self.setRingingTime(time.format("HH:mm")); }
// ringBell(self); },
// } error: (error) => {
// }else if(data.notify_type.value == 5){ console.log(error);
// //请求远程开门 if(window.iotDebug){
//// self.setRemoteOpendoorFlag(true); iotDebug.push('end: 常链接失败'+JSON.stringify(error));
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss"); }
// let time = moment(data.time.value, "YY-MM-DD-hh-mm-ss"); if (window.iotDebug) {
//// console.log(now.diff(time,'seconds')); iotDebug.upload(iot,'常链接失败');
// if(now.diff(time,'seconds') < config.remote_timeout && now.diff(time,'seconds') > 0){ }
// self.setValueRemoteOpendoor(true); uPublic.openRequestErrorAlert(self);
// self.setRemoteOpendoorDisabledFlag(false); }
// setTimeout(function(){ });
// self.setValueRemoteOpendoor(false); }
// self.setRemoteOpendoorDisabledFlag(true);
// },(300-now.diff(time,'seconds'))*1000);
// }
//
// }else if(notifyMode.indexOf(data.notify_type.value) != -1){
// loopGetLockInfo(self, config.intervalTime, config.getHistoryTime);
// }
// }
// if(data.action.value == 'lock_log' && (data.lock_action.value == '1' || data.lock_action.value == '4')){
// //开门或远程开门成功
// loopGetLockInfo(self, config.intervalTime, config.getHistoryTime);
// if(data.lock_action.value == '4'){
// uComponents.changeCommLoadingStatusAndText(self, 1, Vue.t('remoteOpendoor.openDoorSuccess'));
// uComponents.changeCommButtonText(self, Vue.t('btn.confirm'));
// self.setValueRemoteOpendoor(false);
// self.setRemoteOpendoorDisabledFlag(true);
// self.setStatus(1);
// }
// }
// if(data.ErrorCode.value == 1){
// //远程开门失败
// uComponents.changeCommLoadingStatusAndText(self, 2, Vue.t('remoteOpendoor.openDoorFailure'));
// uComponents.changeCommButtonText(self, Vue.t('remoteOpendoor.remoteOpendoorAgain'));
// self.setStatus(2);
// }
//}
//sds消息处理方法 //sds消息处理方法
function sdsDataPorcessing(self, data){ function sdsDataPorcessing(self, data){
...@@ -956,16 +852,11 @@ function sdsDataPorcessing(self, data){ ...@@ -956,16 +852,11 @@ function sdsDataPorcessing(self, data){
break; break;
case '5': case '5':
//远程开门失败 //远程开门失败
setRemoteOpenDoorLoading(self, 2, Vue.t('remoteOpendoor.openDoorFailure'), Vue.t('remoteOpendoor.remoteOpendoorAgain')); setRemoteOpenDoorLoading(self, 2, Vue.t('remoteOpendoor.openDoorFailure'), Vue.t('remoteOpendoor.remoteOpendoorAgain'));
break; break;
} }
break; break;
} }
// if(data.ErrorCode.value == 1){
// //远程开门失败
// setRemoteOpenDoorLoading(self, 2, Vue.t('remoteOpendoor.openDoorFailure'), Vue.t('remoteOpendoor.remoteOpendoorAgain'));
// }
} }
//设置电量百分比、电量icon //设置电量百分比、电量icon
...@@ -1075,40 +966,6 @@ function pushAction(self, msg) { ...@@ -1075,40 +966,6 @@ function pushAction(self, msg) {
payload = JSON.parse(msg.payload); payload = JSON.parse(msg.payload);
} }
notifyDataProcessing(self, payload); notifyDataProcessing(self, payload);
// if(payload.type == "open"){
// //开门推送
// getLockInfo(self);
// }else if(payload.type == "notify"){
// //安全报警
// getLockInfo(self);
// }else if(payload.type == "alarm"){
// //劫持报警
// getLockInfo(self);
// }else if(payload.type == "ring"){
// //门铃
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
// let time = moment(payload.time, "YYYY-MM-DD hh:mm:ss");
// console.log(now.diff(time,'seconds'));
// if(now.diff(time,'seconds') < config.ringBell_timeout && now.diff(time,'seconds') > 0){
// if(!self.getRingTime()){
// self.setRingingTime(time.format("HH:mm"));
// ringBell(self);
// }
// }
// }else if(payload.type == "remoteOpen"){
// //远程开门通知
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
// let time = moment(payload.time, "YYYY-MM-DD hh:mm:ss");
// console.log(now.diff(time,'seconds'));
// if(now.diff(time,'seconds') < config.remote_timeout && now.diff(time,'seconds') > 0){
// self.setValueRemoteOpendoor(true);
// self.setRemoteOpendoorDisabledFlag(false);
// setTimeout(function(){
// self.setValueRemoteOpendoor(false);
// self.setRemoteOpendoorDisabledFlag(true);
// },(300-now.diff(time,'seconds'))*1000);
// }
// }
} }
//推送消息处理方法 //推送消息处理方法
...@@ -1133,31 +990,12 @@ function notifyDataProcessing(self, payload){ ...@@ -1133,31 +990,12 @@ function notifyDataProcessing(self, payload){
} }
function notificationListener(self) { function notificationListener(self) {
// if (plus.os.name == 'Android') {
// setInterval(function () {
// var pushMsgArray = plus.push.getAllMessage();
//// console.log(pushMsgArray);
// if (pushMsgArray) {
// var pushMsgLength = pushMsgArray.length;
// if (pushMsgLength) {
// var pushMsg = pushMsgArray[(pushMsgArray.length - 1)];
// pushAction(self, pushMsg);
// plus.push.clear();
// }
// }
// }, 2000);
// }
// 从系统消息中心点击消息启动应用事件 // 从系统消息中心点击消息启动应用事件
plus.push.addEventListener('click', function (msg) { plus.push.addEventListener('click', function (msg) {
// console.log("收到了click");
pushAction(self, msg); pushAction(self, msg);
// alert("click"+JSON.stringify(msg));
}, false); }, false);
// 应用从推送服务器接收到推送消息事件 // 应用从推送服务器接收到推送消息事件
plus.push.addEventListener('receive', function (msg) { plus.push.addEventListener('receive', function (msg) {
// alert("收到了receive");
// pushAction(self, msg);
// alert("receive"+JSON.stringify(msg));
}, false); }, false);
} }
...@@ -1171,13 +1009,6 @@ function myInfoTap(self){ ...@@ -1171,13 +1009,6 @@ function myInfoTap(self){
nickname: self.nickname nickname: self.nickname
} }
}); });
// uPublic.openWindow({
// url: '../myInfo/index.html',
// id: 'myInfo',
// extras: {
// nickname: self.nickname
// }
// });
} }
//tap 绑定门锁 //tap 绑定门锁
...@@ -1188,33 +1019,10 @@ function bindDoorlockTap(){ ...@@ -1188,33 +1019,10 @@ function bindDoorlockTap(){
}); });
} }
//tap 门锁管理
function doorlockManageTap(self){
if(self.valueDoorlockManage){
iot.navigator.openWindow({
url: '../doorlockManage/index.html',
id: 'doorlockManage',
extras: {
deviceId: self.deviceId,
uuid: self.getUuid(),
lockInfo: self.getLockInfo()
}
});
}
}
//tap 开门记录 //tap 开门记录
function opendoorRecordTap(self){ function opendoorRecordTap(self){
if(self.valueOpendoorRecord){ if(self.valueOpendoorRecord){
if(self.opendoorRecordFlag){
console.log("停止所以interval");
window.clearInterval(self.handle);
}
self.opendoorRecordFlag = false; self.opendoorRecordFlag = false;
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
// setRecordTime('openTime', self.openTime.toISOString());
iot.navigator.openWindow({ iot.navigator.openWindow({
url: './opendoorRecord.html', url: './opendoorRecord.html',
id: 'opendoorRecord', id: 'opendoorRecord',
...@@ -1229,12 +1037,7 @@ function opendoorRecordTap(self){ ...@@ -1229,12 +1037,7 @@ function opendoorRecordTap(self){
function securityAlarmTap(self){ function securityAlarmTap(self){
if(self.valueSecurityAlarm){ if(self.valueSecurityAlarm){
if(self.notifyTime != null){ if(self.notifyTime != null){
if(self.securityAlarmFlag){
window.clearInterval(self.handle);
}
self.securityAlarmFlag = false; self.securityAlarmFlag = false;
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
// setRecordTime('notifyTime', self.notifyTime);
} }
iot.navigator.openWindow({ iot.navigator.openWindow({
url: './alarmInfo.html', url: './alarmInfo.html',
...@@ -1246,6 +1049,23 @@ function securityAlarmTap(self){ ...@@ -1246,6 +1049,23 @@ function securityAlarmTap(self){
} }
} }
//tap 劫持报警
function hijackAlarmTap(self){
if(self.valueHijackAlarm){
console.log(self.alarmTime);
if(self.alarmTime != null){
self.hijackAlarmFlag = false;
}
iot.navigator.openWindow({
url: './hijackRecord.html',
id: 'hijackRecord',
extras: {
deviceId: self.deviceId
}
});
}
}
//tap 门锁用户 //tap 门锁用户
function doorlockUserTap(self){ function doorlockUserTap(self){
if(self.valueDoorlockUser){ if(self.valueDoorlockUser){
...@@ -1264,47 +1084,35 @@ function doorlockUserTap(self){ ...@@ -1264,47 +1084,35 @@ function doorlockUserTap(self){
//tap 远程开门 //tap 远程开门
function remoteOpendoorTap(self){ function remoteOpendoorTap(self){
// if(self.valueRemoteOpendoor){
// iot.navigator.openWindow({
// url: './remoteOpendoor.html',
// id: 'remoteOpendoor',
// extras: {
// uuid: self.getUuid(),
// mac: self.mac
// }
// });
// }
if(self.valueRemoteOpendoor){ if(self.valueRemoteOpendoor){
self.setTextPassword(''); self.setTextPassword('');
self.setRemoteOpendoorShowFlag(true); self.setRemoteOpendoorShowFlag(true);
// self.setValueRemoteOpendoor(false);
// self.setRemoteOpendoorDisabledFlag(true);
} }
} }
//tap 劫持报警 //tap 门锁管理
function hijackAlarmTap(self){ function doorlockManageTap(self){
if(self.valueDoorlockManage){
if(self.valueHijackAlarm){
console.log(self.alarmTime);
if(self.alarmTime != null){
if(self.hijackAlarmFlag){
window.clearInterval(self.handle);
}
self.hijackAlarmFlag = false;
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
// setRecordTime('alarmTime', self.alarmTime.toISOString());
}
iot.navigator.openWindow({ iot.navigator.openWindow({
url: './hijackRecord.html', url: '../doorlockManage/index.html',
id: 'hijackRecord', id: 'doorlockManage',
extras: { extras: {
deviceId: self.deviceId deviceId: self.deviceId,
uuid: self.getUuid(),
lockInfo: self.getLockInfo()
} }
}); });
} }
} }
//tap 门铃(停止响铃)
function stopDoorbellRing(self){
self.setDoorbellRingingFlag(false);
self.setRingTime(0);
window.clearInterval(self.time);
window.clearTimeout(self.timeout);
}
//tap 保存二维码到相册 //tap 保存二维码到相册
function saveQRcodeButtonTap(){ function saveQRcodeButtonTap(){
alert('保存二维码到相册'); alert('保存二维码到相册');
...@@ -1318,8 +1126,6 @@ function laterFollowTap(self){ ...@@ -1318,8 +1126,6 @@ function laterFollowTap(self){
//tap 远程开门页面返回 //tap 远程开门页面返回
function backTap(self){ function backTap(self){
self.setRemoteOpendoorShowFlag(false); self.setRemoteOpendoorShowFlag(false);
// self.setValueRemoteOpendoor(false);
// self.setRemoteOpendoorDisabledFlag(true);
} }
//远程开门密码 //远程开门密码
...@@ -1329,7 +1135,7 @@ function passwordChange(self,text){ ...@@ -1329,7 +1135,7 @@ function passwordChange(self,text){
console.log('passwordChange: ' + self.textPassword); console.log('passwordChange: ' + self.textPassword);
} }
//tap 确定 //tap 确定(远程开门密码)
function confirmButtonTap(self){ function confirmButtonTap(self){
if(self.getTextPassword() == null || self.getTextPassword().trim() == ''){ if(self.getTextPassword() == null || self.getTextPassword().trim() == ''){
self.setTextErrorTip(Vue.t('remoteOpendoor.error.noPasswordTip')); self.setTextErrorTip(Vue.t('remoteOpendoor.error.noPasswordTip'));
...@@ -1337,13 +1143,13 @@ function confirmButtonTap(self){ ...@@ -1337,13 +1143,13 @@ function confirmButtonTap(self){
uComponents.showCommLoading(self); uComponents.showCommLoading(self);
self.setStatus(0); self.setStatus(0);
uComponents.changeCommLoadingStatusAndText(self, 0, Vue.t('remoteOpendoor.loading')); uComponents.changeCommLoadingStatusAndText(self, 0, Vue.t('remoteOpendoor.loading'));
console.log(self.mac); // console.log(self.mac);
let keyIv = crypto.enkey(self.mac.replace(/:/g,'')); let keyIv = crypto.enkey(self.mac.replace(/:/g,''));
console.log(keyIv); // console.log(keyIv);
let pwd = crypto.encode(self.getTextPassword(), keyIv); let pwd = crypto.encode(self.getTextPassword(), keyIv);
console.log(pwd); // console.log(pwd);
let msg = crypto.decode(pwd, keyIv); // let msg = crypto.decode(pwd, keyIv);
console.log(msg); // console.log(msg);
iot.business.sds.setDeviceStatus({ iot.business.sds.setDeviceStatus({
data: { data: {
uuid: self.getUuid(), uuid: self.getUuid(),
...@@ -1390,18 +1196,12 @@ function confirmButtonTap(self){ ...@@ -1390,18 +1196,12 @@ function confirmButtonTap(self){
//tap comm-loading ‘确认’ //tap comm-loading ‘确认’
function commLoadingButtonTap(self){ function commLoadingButtonTap(self){
if(self.getStatus() == 1){ if(self.getStatus() == 1){
//绑定成功 //远程开门成功
uComponents.hideCommLoading(self); uComponents.hideCommLoading(self);
self.setRemoteOpendoorShowFlag(false); self.setRemoteOpendoorShowFlag(false);
}else if(self.getStatus() == 2){ }else if(self.getStatus() == 2){
//绑定失败 //远程开门失败
uComponents.hideCommLoading(self); uComponents.hideCommLoading(self);
} }
} }
function stopDoorbellRing(self){
self.setDoorbellRingingFlag(false);
self.setRingTime(0);
window.clearInterval(self.time);
window.clearTimeout(self.timeout);
}
...@@ -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