Commit 6049e46b by 朱建香

2017/12/21

1.优化首页代码
2.用新的轮询方法获取开门记录
parent a01869c1
......@@ -39,18 +39,21 @@ class Loop{
async sendRequest(){
this.canSend = false;
var needAuth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var isDebug = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
// var send = this.opts.isCustom ? iot.business.api.sendCustom : iot.business.api.send;
var needAuth = this.opts.needAuth !== undefined ? this.opts.needAuth : true;
var isDebug = this.opts.isDebug !== undefined ? this.opts.isDebug : false;
var withoutUgen = this.opts.withoutUgen !== undefined ? this.opts.withoutUgen : false;
// iot.business.api.send(this.url, {
// iot.business.api.sendCustom(this.url, {
try{
let response = await iot.business.api.send(this.url, {
var urlParams = {
type: this.opts.type,
data: this.opts.data
}, needAuth, false, isDebug);
if(this.intervalcb!= null){
this.intervalcb.success(response);
};
try{
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(this.fincb!= null){
......@@ -60,6 +63,9 @@ class Loop{
this.clearTime();
this.canSend = false;
}else{
if(this.intervalcb!= null){
this.intervalcb.success(response);
}
this.canSend = true;
}
}
......@@ -90,11 +96,14 @@ class Loop{
this.intervalcb = null;
this.fincb = null;
},this.timeout);
console.log("第"+this.i+"次发送了请求");
console.log("发送时间"+new Date().getTime());
this.i++;
this.sendRequest();
this.watcher = setInterval(() => {
if(this.canSend && this.canDo){
this.canDo = false;
console.log("发送了请求");
console.log("第"+this.i+"次发送了请求");
console.log("发送时间"+new Date().getTime());
this.i++;
this.sendRequest();
......
......@@ -19,11 +19,11 @@ const iot = new UIOT({
cloud: {
// url: 'http://wx.iotface.com'
//96环境
// url: 'http://192.168.2.96:20000'
url: 'http://192.168.2.96:20000'
//96外网
// 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/'
},
......@@ -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(() => {
uPublic.recalc();
});
......@@ -275,189 +306,4 @@ iot.navigator.getCurrentWebView = function (){
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}
\ No newline at end of file
......@@ -99,11 +99,12 @@ function initComponentsConfig() {
let data = uPublic.checkResponseData(response.data);
if(data && data.record.length > 0){
let record = data.record;
iot.storage.setMap('notifyTime', moment(record[0].time).unix(), (res) => {
console.log(res);
self.flag = false;
}, () => {
});
// iot.storage.setMap('notifyTime', moment(record[0].time).unix(), (res) => {
// console.log(res);
// self.flag = false;
// }, () => {
// });
uPublic.upDateRead('notify');
}
}
let data = uPublic.checkResponseData(response.data);
......
......@@ -101,16 +101,17 @@ function initComponentsConfig() {
start_id: self.getStartId(),
page_size: PAGE_SIZE
},
success: (response) => {
success: async (response) => {
if(self.flag){
let data = uPublic.checkResponseData(response.data);
if(data && data.record.length > 0){
let record = data.record;
iot.storage.setMap('alarmTime', moment(record[0].time).unix(), (res) => {
console.log(res);
self.flag = false;
}, () => {
});
// iot.storage.setMap('alarmTime', moment(record[0].time).unix(), (res) => {
// console.log(res);
// self.flag = false;
// }, () => {
// });
uPublic.upDateRead('alarm');
}
}
let data = uPublic.checkResponseData(response.data);
......
......@@ -101,11 +101,9 @@ function init() {
flag: true,
time: null,
timeout: null,
handle: null,
remoteTime: null
},
mounted(){
uComponents.showLoading(this);
notificationListener(this);
let self = this;
......@@ -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){
iot.business.sds.getDevicesByUser({
success: (response) => {
......@@ -555,16 +446,11 @@ function getDevices(self){
uuid: self.uuid
},
success: (response) => {
console.log("getInfo");
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(data){
console.log(data);
if(data.hasOwnProperty('relAccounts')){
self.userInfo = data.relAccounts;
getLockInfo(self);
}
}
},
error: (error) => {
console.log(error);
......@@ -573,18 +459,7 @@ function getDevices(self){
});
}
}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;
self.setRemoteOpendoorDisabledFlag(true);
self.setValueRemoteOpendoor(0);
initDeviceInfo(self);
uComponents.hideLoading(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) => {
console.log("registerPushListener");
console.log(response);
let data = uPublic.checkResponseData(response.data.params.data);
let data = uPublic.checkResponseData(response.data);
if(data){
sdsDataPorcessing(self, data);
getLockInfoSuccess(self, data);
}else{
initDeviceInfo(self);
}
},
error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: 常链接失败'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'常链接失败');
}
uPublic.openRequestErrorAlert(self);
console.log(error);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
async function getRecordTime(self, data){
try{
self.notifyTime = await iot.storage.getMap('notifyTime');
self.alarmTime = await iot.storage.getMap('alarmTime');
self.openTime = await iot.storage.getMap('openTime');
}
catch (error) {
console.log(error);
}
let newNotifyTime = moment(data.notify_time).unix();
let newAlarmTime = moment(data.alarm_time).unix();
let newOpenTime = moment(data.open_time).unix();
let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss").unix();
if(self.notifyTime){
if(newNotifyTime != null && newNotifyTime - self.notifyTime > 0){
self.securityAlarmFlag = true;
self.notifyTime = newNotifyTime;
}else{
self.securityAlarmFlag = false;
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);
}
//存储最后一条历史记录的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{
if(newNotifyTime != null && now - newNotifyTime < 3600){
self.securityAlarmFlag = true;
self.notifyTime = newNotifyTime;
}else{
self.securityAlarmFlag = false;
msg = record[i].nickname;
}
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){
if(newAlarmTime != null && newAlarmTime - self.alarmTime > 0){
self.hijackAlarmFlag = true;
self.alarmTime = newAlarmTime;
uComponents.changeMarqueeText(self, self.newMsg);
if(self.newMsg.length >= 2){
self.activeFlag = true;
}else{
self.hijackAlarmFlag = false;
self.activeFlag = false;
}
}else{
if(newAlarmTime != null && now - newAlarmTime < 3600){
self.hijackAlarmFlag = true;
self.alarmTime = newAlarmTime;
uComponents.changeMarqueeText(self, [Vue.t('device.noNewMsg')]);
self.activeFlag = false;
}
}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'));
if(newOpenTime != null && newOpenTime - self.openTime > 0){
self.opendoorRecordFlag = true;
self.openTime = newOpenTime;
}else{
self.opendoorRecordFlag = false;
};
try{
oldHistory = await iot.storage.getMap('history');
console.log(oldHistory);
}
}else{
// console.log("openTime"+now.diff(newOpenTime, 'hours'));
if(newOpenTime != null && now.diff - newOpenTime < 3600){
self.opendoorRecordFlag = true;
self.openTime = newOpenTime;
}else{
self.opendoorRecordFlag = false;
catch (error) {
console.log(error);
}
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
function getRecordTimeMap(time) {
return new Promise(function (resolve, reject) {
// console.log(time);
iot.storage.getMap(time, (res) => {
if (res) {
// console.log('获取时间:'+moment(res).format('YYYY-MM-DD hh:mm:ss'));
resolve(res);
} else {
reject(res);
}
}, (err) => {
console.log(err);
if(openHistory.length && oldHistory.open.time != moment(openHistory[0].time).unix()){
newHistory.open.time = moment(openHistory[0].time).unix();
newHistory.open.isReadFlag = false;
}
if(historyRecord.hasOwnProperty('notify') && oldHistory.notify.time != moment(historyRecord.notify).unix()){
newHistory.notify.time = moment(historyRecord.notify).unix()
newHistory.open.isReadFlag = false;
}
iot.storage.setMap('history', newHistory, (response) => {
console.log(res);
}, () => {
});
})
}
function setValueOfSwitch(self, flag){
self.setOpendoorRecordDisabledFlag(flag);
self.setSecurityAlarmDisabledFlag(flag);
self.setDoorlockUserDisabledFlag(flag);
self.setHijackAlarmDisabledFlag(flag);
self.setDoorlockManageDisabledFlag(flag);
self.valueOpendoorRecord = !flag;
self.valueSecurityAlarm = !flag;
self.valueDoorlockUser = !flag;
self.valueHijackAlarm = !flag;
self.valueDoorlockManage = !flag;
iot.storage.getMap('history', (response) => {
self.securityAlarmFlag = !response.notify.isReadFlag;
self.hijackAlarmFlag = !response.alarm.isReadFlag;
self.opendoorRecordFlag = !response.open.isReadFlag;
}, () => {
});
}
function getDeviceStatus(self){
......@@ -742,55 +635,32 @@ function getDeviceStatus(self){
});
}
function getLockInfo(self){
console.log("getLockInfo");
iot.business.api.sendCustom('lock/getLockInfo',{
function getNewInfo(self){
console.log("getNewInfo");
iot.business.api.sendCustom('lock/getNewInfo',{
data: {
device_id: self.deviceId
},
success: (response) => {
console.log(response);
let data = uPublic.checkResponseData(response.data);
if(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;
// }
// let data = uPublic.checkResponseData(response.data);
// if(data){
// getLockInfoSuccess(self, data);
// }else{
// uComponents.changeMarqueeText(self, [Vue.t('device.defaultNewMsg')]);
// self.activeFlag = false;
// initDeviceInfo(self);
// }
}else{
},
error: (error) => {
uPublic.openRequestErrorAlert(self);
console.log(error);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
//云端获取设备信息失败
function initDeviceInfo(self){
setValueOfSwitch(self, true);
self.setLockId(null);
self.mac = null;
......@@ -801,123 +671,149 @@ function getLockInfo(self){
self.opendoorRecordFlag = false;
self.securityAlarmFlag = 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) => {
uPublic.openRequestErrorAlert(self);
console.log(error);
},
complete: () => {
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);
}
//拼接首页滚动的三条记录
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;
}).start();
}
async function getRecordTime(self, data){
console.log(getRecordTime);
try{
self.notifyTime = await iot.storage.getMap('notifyTime');
self.alarmTime = await iot.storage.getMap('alarmTime');
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){
self.activeFlag = true;
let newNotifyTime = data.notify_time == null? null : moment(data.notify_time).unix();
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{
self.activeFlag = false;
return false;
}
}else{
uComponents.changeMarqueeText(self, [Vue.t('device.noNewMsg')]);
self.activeFlag = false;
}
if(newTime != null && now - newTime < 3600){
return true;
oldTime = newTime;
}else{
uComponents.changeMarqueeText(self, [Vue.t('device.defaultNewMsg')]);
self.activeFlag = false;
return false;
}
}
}
////设置设备信息
//function setDevceInfo(self, data) {
// console.log(data);
// let notifyMode = ['1','2','3'];
// console.log(notifyMode.indexOf(data.notify_type.value));
// if(data.BatteryPercentage){
// self.setBatteryPercent(data.BatteryPercentage.value);
// if(data.BatteryPercentage.value >= 10){
// //向上取整
// self.setBatteryState(config.powerIcon[Math.ceil(data.BatteryPercentage.value/20)]);
// }else{
// self.setBatteryState(config.powerIcon[Math.round(data.BatteryPercentage.value/20)]);
// }
// }
// if(data.action.value == 'notify'){
// if(data.notify_type.value == 104){
// //门铃响了
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
// let time = moment(data.time.value, "YY-MM-DD-hh-mm-ss");
//// console.log('门铃时间差'+now.diff(time,'seconds')+'timeout'+config.ringBell_timeout);
// if(now.diff(time,'seconds') < config.ringBell_timeout && now.diff(time,'seconds') > 0){
// self.setRingingTime(time.format("HH:mm"));
// ringBell(self);
// }
// }else if(data.notify_type.value == 5){
// //请求远程开门
//// self.setRemoteOpendoorFlag(true);
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
// let time = moment(data.time.value, "YY-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);
// }
//
// }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);
// }
//}
function setValueOfSwitch(self, flag){
self.setOpendoorRecordDisabledFlag(flag);
self.setSecurityAlarmDisabledFlag(flag);
self.setDoorlockUserDisabledFlag(flag);
self.setHijackAlarmDisabledFlag(flag);
self.setDoorlockManageDisabledFlag(flag);
self.valueOpendoorRecord = !flag;
self.valueSecurityAlarm = !flag;
self.valueDoorlockUser = !flag;
self.valueHijackAlarm = !flag;
self.valueDoorlockManage = !flag;
}
function registerPushListener(self){
iot.business.sds.registerPushListener({
success: (response) => {
console.log("registerPushListener");
console.log(response);
let data = uPublic.checkResponseData(response.data.params.data);
if(data){
sdsDataPorcessing(self, data);
}
},
error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: 常链接失败'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'常链接失败');
}
uPublic.openRequestErrorAlert(self);
}
});
}
//sds消息处理方法
function sdsDataPorcessing(self, data){
......@@ -956,16 +852,11 @@ function sdsDataPorcessing(self, data){
break;
case '5':
//远程开门失败
setRemoteOpenDoorLoading(self, 2, Vue.t('remoteOpendoor.openDoorFailure'), Vue.t('remoteOpendoor.remoteOpendoorAgain'));
break;
}
break;
}
// if(data.ErrorCode.value == 1){
// //远程开门失败
// setRemoteOpenDoorLoading(self, 2, Vue.t('remoteOpendoor.openDoorFailure'), Vue.t('remoteOpendoor.remoteOpendoorAgain'));
// }
}
//设置电量百分比、电量icon
......@@ -1075,40 +966,6 @@ function pushAction(self, msg) {
payload = JSON.parse(msg.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){
}
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) {
// console.log("收到了click");
pushAction(self, msg);
// alert("click"+JSON.stringify(msg));
}, false);
// 应用从推送服务器接收到推送消息事件
plus.push.addEventListener('receive', function (msg) {
// alert("收到了receive");
// pushAction(self, msg);
// alert("receive"+JSON.stringify(msg));
}, false);
}
......@@ -1171,13 +1009,6 @@ function myInfoTap(self){
nickname: self.nickname
}
});
// uPublic.openWindow({
// url: '../myInfo/index.html',
// id: 'myInfo',
// extras: {
// nickname: self.nickname
// }
// });
}
//tap 绑定门锁
......@@ -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 开门记录
function opendoorRecordTap(self){
if(self.valueOpendoorRecord){
if(self.opendoorRecordFlag){
console.log("停止所以interval");
window.clearInterval(self.handle);
}
self.opendoorRecordFlag = false;
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
// setRecordTime('openTime', self.openTime.toISOString());
iot.navigator.openWindow({
url: './opendoorRecord.html',
id: 'opendoorRecord',
......@@ -1229,12 +1037,7 @@ function opendoorRecordTap(self){
function securityAlarmTap(self){
if(self.valueSecurityAlarm){
if(self.notifyTime != null){
if(self.securityAlarmFlag){
window.clearInterval(self.handle);
}
self.securityAlarmFlag = false;
// let now = moment(new Date(), "YYYY-MM-DD hh:mm:ss");
// setRecordTime('notifyTime', self.notifyTime);
}
iot.navigator.openWindow({
url: './alarmInfo.html',
......@@ -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 门锁用户
function doorlockUserTap(self){
if(self.valueDoorlockUser){
......@@ -1264,47 +1084,35 @@ function doorlockUserTap(self){
//tap 远程开门
function remoteOpendoorTap(self){
// if(self.valueRemoteOpendoor){
// iot.navigator.openWindow({
// url: './remoteOpendoor.html',
// id: 'remoteOpendoor',
// extras: {
// uuid: self.getUuid(),
// mac: self.mac
// }
// });
// }
if(self.valueRemoteOpendoor){
self.setTextPassword('');
self.setRemoteOpendoorShowFlag(true);
// self.setValueRemoteOpendoor(false);
// self.setRemoteOpendoorDisabledFlag(true);
}
}
//tap 劫持报警
function hijackAlarmTap(self){
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());
}
//tap 门锁管理
function doorlockManageTap(self){
if(self.valueDoorlockManage){
iot.navigator.openWindow({
url: './hijackRecord.html',
id: 'hijackRecord',
url: '../doorlockManage/index.html',
id: 'doorlockManage',
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 保存二维码到相册
function saveQRcodeButtonTap(){
alert('保存二维码到相册');
......@@ -1318,8 +1126,6 @@ function laterFollowTap(self){
//tap 远程开门页面返回
function backTap(self){
self.setRemoteOpendoorShowFlag(false);
// self.setValueRemoteOpendoor(false);
// self.setRemoteOpendoorDisabledFlag(true);
}
//远程开门密码
......@@ -1329,7 +1135,7 @@ function passwordChange(self,text){
console.log('passwordChange: ' + self.textPassword);
}
//tap 确定
//tap 确定(远程开门密码)
function confirmButtonTap(self){
if(self.getTextPassword() == null || self.getTextPassword().trim() == ''){
self.setTextErrorTip(Vue.t('remoteOpendoor.error.noPasswordTip'));
......@@ -1337,13 +1143,13 @@ function confirmButtonTap(self){
uComponents.showCommLoading(self);
self.setStatus(0);
uComponents.changeCommLoadingStatusAndText(self, 0, Vue.t('remoteOpendoor.loading'));
console.log(self.mac);
// console.log(self.mac);
let keyIv = crypto.enkey(self.mac.replace(/:/g,''));
console.log(keyIv);
// console.log(keyIv);
let pwd = crypto.encode(self.getTextPassword(), keyIv);
console.log(pwd);
let msg = crypto.decode(pwd, keyIv);
console.log(msg);
// console.log(pwd);
// let msg = crypto.decode(pwd, keyIv);
// console.log(msg);
iot.business.sds.setDeviceStatus({
data: {
uuid: self.getUuid(),
......@@ -1390,18 +1196,12 @@ function confirmButtonTap(self){
//tap comm-loading ‘确认’
function commLoadingButtonTap(self){
if(self.getStatus() == 1){
//绑定成功
//远程开门成功
uComponents.hideCommLoading(self);
self.setRemoteOpendoorShowFlag(false);
}else if(self.getStatus() == 2){
//绑定失败
//远程开门失败
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){
let data = uPublic.checkResponseData(response.data);
if(data && data.record.length > 0){
let record = data.record;
iot.storage.setMap('openTime', moment(record[0].time).unix(), (res) => {
console.log(res);
self.flag = false;
}, () => {
});
// iot.storage.setMap('openTime', moment(record[0].time).unix(), (res) => {
// console.log(res);
// self.flag = false;
// }, () => {
// });
uPublic.upDateRead('open');
}
}
},
......
......@@ -32,11 +32,11 @@ function init() {
extras: {},
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,
valueIsClear: true,
unbindShowDialog: false
......
......@@ -2158,9 +2158,7 @@ NetWork.send = function (url, params) {
if (params.error) params.error(err);
if (params.complete) params.complete();
});
console.log("callback");
} else {
console.log("promise");
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