Commit c605af96 by 朱建香

20171225

parent 314b404f
...@@ -9,8 +9,9 @@ class Loop{ ...@@ -9,8 +9,9 @@ class Loop{
this.handle = null; this.handle = null;
this.watcher = null; this.watcher = null;
this.time = null; this.time = null;
this.url = params.request.url; // this.url = params.request.url;
this.opts = params.request.opts; // this.opts = params.request.opts;
this.loopContent = params.loopContent;
this.timeout = params.timeout | 30; this.timeout = params.timeout | 30;
this.fincb = params.fincb; this.fincb = params.fincb;
this.intervalTime = params.interval.delay; this.intervalTime = params.interval.delay;
...@@ -28,7 +29,6 @@ class Loop{ ...@@ -28,7 +29,6 @@ class Loop{
console.log("返回时间"+this.i+'-'+new Date().getTime()); console.log("返回时间"+this.i+'-'+new Date().getTime());
opts.success(data[this.i]); opts.success(data[this.i]);
},100); },100);
} }
clearTime(){ clearTime(){
...@@ -39,22 +39,10 @@ class Loop{ ...@@ -39,22 +39,10 @@ class Loop{
async sendRequest(){ async sendRequest(){
this.canSend = false; this.canSend = false;
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, {
var urlParams = {
type: this.opts.type,
data: this.opts.data
};
try{ try{
var response = null; var response = null;
if(withoutUgen){ response = await this.loopContent();
response = await iot.network.send(this.url, urlParams); console.log(response);
}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){
this.fincb.success(response); this.fincb.success(response);
...@@ -84,7 +72,6 @@ class Loop{ ...@@ -84,7 +72,6 @@ class Loop{
} }
} }
start(){ start(){
console.log("开始"); console.log("开始");
this.time = setTimeout(() => { this.time = setTimeout(() => {
......
...@@ -5,25 +5,11 @@ ...@@ -5,25 +5,11 @@
class unotify{ class unotify{
//在一个周期内获取cid //在一个周期内获取cid
static async getCid(successCallback, errorCallback){ static async getCid(successCallback, errorCallback){
var cid = null; UpdateCid((response) => {
try{ successCallback(response);
//利用promise,直到执行完代码再获取cid }, (error) => {
cid = await this.getCidPeriotic(3); errorCallback(error);
//获取后,在缓存中存储cid });
if(typeof successCallback == 'function'){
iot.storage.setMap('clientId', cid, (res) => {
console.log("已成功保存cid"+cid);
successCallback(cid);
}, () => {
});
}
}
catch (err){
console.log(err);
if(typeof errorCallback == 'function'){
errorCallback(a);
}
}
} }
//周期性获取cid,周期可调整 //周期性获取cid,周期可调整
static getCidPeriotic(times){ static getCidPeriotic(times){
...@@ -65,36 +51,36 @@ class unotify{ ...@@ -65,36 +51,36 @@ class unotify{
} }
} }
//长期不断循环获取cid,并更新cid //长期不断循环获取cid,并更新cid
// static async getCid(successCallback, errorCallback){ static async UpdateCid(successCallback, errorCallback){
// var cid = null; var cid = null;
// var oldCid = null; var oldCid = null;
// try{ try{
// cid = await this.getCidPeriotic(9); cid = await this.getCidPeriotic(9);
// if(cid != null && cid != oldCid){ if(cid != null && cid != oldCid){
// iot.business.api.send('user/updateCid',{ iot.business.api.send('user/updateCid',{
// data: { data: {
// clienId: cid clienId: cid
// }, },
// success: (response) => { success: (response) => {
// if(typeof successCallback == 'function'){ if(typeof successCallback == 'function'){
// successCallback('cid updateSuccess'); successCallback('cid updateSuccess');
// } }
// }, },
// error: (error) => { error: (error) => {
// console.log(error); console.log(error);
// errorCallback(error); errorCallback(error);
// } }
// }, true, false); }, true, false);
// }else{ }else{
// successCallback('cid not updated'); successCallback('cid not updated');
// } }
// } }
// catch (err){ catch (err){
// console.log(err); console.log(err);
// if(typeof errorCallback == 'function'){ if(typeof errorCallback == 'function'){
// errorCallback(err); errorCallback(err);
// } }
// } }
// } }
} }
export default unotify; export default unotify;
\ No newline at end of file
...@@ -114,12 +114,13 @@ function init() { ...@@ -114,12 +114,13 @@ function init() {
registerPushListener(this); registerPushListener(this);
let self = this; let self = this;
window.addEventListener('returnPage',function(event){ window.addEventListener('returnPage',function(event){
console.log('returnPage');
//获取设备信息 //获取设备信息
getDevices(self); getDevices(self);
//注册监听上报 //注册监听上报
registerPushListener(self); registerPushListener(self);
iot.navigator.closeAllBesidesItself();
}); });
}, },
methods:{ methods:{
setValueRemoteOpendoor(value){ setValueRemoteOpendoor(value){
...@@ -522,7 +523,8 @@ function getLockInfoSuccess(self, data){ ...@@ -522,7 +523,8 @@ function getLockInfoSuccess(self, data){
self.setIsFirstGetLockInfo(false); self.setIsFirstGetLockInfo(false);
} }
//存储最后一条历史记录的ID //存储最后一条历史记录的ID
let historyId = data.info.historyId; let historyId = null
historyId = data.info.historyId ? data.info.historyId : null;
iot.storage.setMap('historyId', historyId, (res) => { iot.storage.setMap('historyId', historyId, (res) => {
console.log(res); console.log(res);
}, () => { }, () => {
...@@ -656,23 +658,29 @@ function initDeviceInfo(self){ ...@@ -656,23 +658,29 @@ function initDeviceInfo(self){
} }
async function loopGetLockInfo(self, delay, timeout){ async function loopGetLockInfo(self, delay, timeout){
let oldHistoryId = null; let oldHistoryId = null;
try{ try{
oldHistoryId = await iot.storage.getMap('historyId'); let historyId = await iot.storage.getMap('historyId');
if(historyId){
oldHistoryId = historyId;
}
} }
catch (error){ catch (error){
console.log(error); console.log(error);
} }
console.log(oldHistoryId);
new Loop({ new Loop({
request: { loopContent: () => {
url: 'lock/getNewInfo', var urlParams = {
opts: { type: 'post',
type: 'post', data: {
data: {
history_id: oldHistoryId, history_id: oldHistoryId,
device_id: self.deviceId device_id: self.deviceId
} }
} };
return iot.business.api.send('lock/getNewInfo', urlParams, true, false);
// return plus.push.getClientInfo().clientid;
}, },
timeout: config.getHistoryTime*1000, timeout: config.getHistoryTime*1000,
interval:{ interval:{
......
...@@ -93,12 +93,12 @@ function backTap(){ ...@@ -93,12 +93,12 @@ function backTap(){
iot.navigator.back(); iot.navigator.back();
} }
//重写mui.back ////重写mui.back
mui.back = function(){ //mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{}); // iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("fire"); // console.log("fire");
iot.navigator.back(); // iot.navigator.back();
} //}
//tap 保存 //tap 保存
function saveTap(self){ function saveTap(self){
...@@ -115,10 +115,10 @@ function saveTap(self){ ...@@ -115,10 +115,10 @@ function saveTap(self){
console.log(response); console.log(response);
let data = uPublic.checkResponseData(response.data); let data = uPublic.checkResponseData(response.data);
if(data){ if(data){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log('returnPage');
uComponents.openAlert(self, Vue.t('editName.editNameSuccess'), { uComponents.openAlert(self, Vue.t('editName.editNameSuccess'), {
text: Vue.t('btn.confirm'), callback: function () { text: Vue.t('btn.confirm'), callback: function () {
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log('returnPage');
iot.navigator.back(); iot.navigator.back();
} }
}); });
......
...@@ -287,6 +287,7 @@ function unbind(self){ ...@@ -287,6 +287,7 @@ function unbind(self){
self.setStateShowFlag(true); self.setStateShowFlag(true);
self.setShowMsg(Vue.t('doorlockManage.unbindSuccess')); self.setShowMsg(Vue.t('doorlockManage.unbindSuccess'));
self.setUnbindSucceess(true); self.setUnbindSucceess(true);
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
}, },
error: (error) => { error: (error) => {
console.log(error); console.log(error);
...@@ -311,12 +312,12 @@ function backTap(){ ...@@ -311,12 +312,12 @@ function backTap(){
iot.navigator.aback(); iot.navigator.aback();
} }
//重写mui.back ////重写mui.back
mui.back = function(){ //mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{}); // iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("fire"); // console.log("fire");
iot.navigator.back(); // iot.navigator.back();
} //}
// 选择: 是否接收门铃消息推送 // 选择: 是否接收门铃消息推送
function doorbellSwitchTap(self, value){ function doorbellSwitchTap(self, value){
...@@ -347,6 +348,7 @@ function setOption(self){ ...@@ -347,6 +348,7 @@ function setOption(self){
opt_open: self.getValueOpendoor() opt_open: self.getValueOpendoor()
}, },
success: (response) => { success: (response) => {
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log(); console.log();
}, },
error: (error) => { error: (error) => {
...@@ -366,7 +368,6 @@ function cancelTap(self){ ...@@ -366,7 +368,6 @@ function cancelTap(self){
//tap 绑定成功弹框提示-->回到首页 //tap 绑定成功弹框提示-->回到首页
function unbindStateDialogTap(self){ function unbindStateDialogTap(self){
self.setStateShowFlag(false); self.setStateShowFlag(false);
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
if(self.getUnbindSucceess){ if(self.getUnbindSucceess){
iot.navigator.openWindow({ iot.navigator.openWindow({
url: '../device/index.html', url: '../device/index.html',
......
...@@ -31,9 +31,9 @@ function init() { ...@@ -31,9 +31,9 @@ function init() {
iotDebug.push('start: Debug'); iotDebug.push('start: Debug');
} }
var self = this; var self = this;
unotify.getCid(function(ret){ // unotify.getCid(function(ret){
console.log(ret); // console.log(ret);
self.setClientId(ret); // self.setClientId(ret);
if (plus.os.name == 'Android') { if (plus.os.name == 'Android') {
iot.permission.checkPermission(['READ_EXTERNAL_STORAGE'], function (res) { iot.permission.checkPermission(['READ_EXTERNAL_STORAGE'], function (res) {
console.log('success', res); console.log('success', res);
...@@ -44,9 +44,9 @@ function init() { ...@@ -44,9 +44,9 @@ function init() {
}else{ }else{
loginButtonTap(self); loginButtonTap(self);
} }
},function(err){ // },function(err){
console.log(err); // console.log(err);
}) // })
console.log('innnnnnn'); console.log('innnnnnn');
}, },
methods:{ methods:{
...@@ -212,7 +212,7 @@ function cloudsLogin(self, id){ ...@@ -212,7 +212,7 @@ function cloudsLogin(self, id){
error: (error) => { error: (error) => {
console.log(error); console.log(error);
if(window.iotDebug){ if(window.iotDebug){
iotDebug.push('end: 云端登陆失败'+JSON.stringify(error)); iotDebug.push('end: 云端 登陆失败'+JSON.stringify(error));
} }
if (window.iotDebug) { if (window.iotDebug) {
iotDebug.upload(iot,'云端登陆失败'); iotDebug.upload(iot,'云端登陆失败');
......
...@@ -138,8 +138,11 @@ function logoutButtonTap(self){ ...@@ -138,8 +138,11 @@ function logoutButtonTap(self){
// }, // },
// complete: () => {} // complete: () => {}
// }); // });
console.log("logout");
iot.business.user.logout({ iot.business.user.logout({
data: {}, data: {
// sds: false
},
success: (response) => { success: (response) => {
console.log("sdsLogout:"+response); console.log("sdsLogout:"+response);
let sdsResponse = response; let sdsResponse = response;
......
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