Commit c605af96 by 朱建香

20171225

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