Commit 314b404f by 朱建香

2017/12/22

1.首页代码规范优化
parent 6049e46b
......@@ -90,8 +90,8 @@ class Loop{
this.time = setTimeout(() => {
this.clearTime();
this.canDo = false;
// this.fincb.error('timeout');
// this.fincb.complete();
this.fincb.error('timeout');
this.fincb.complete();
console.log("超时");
this.intervalcb = null;
this.fincb = null;
......
......@@ -147,7 +147,8 @@ uPublic.logout = function(opts){
});
}
uPublic.upDateRead = async function(key){
// 更新缓存中history存储的isReadFlag 和 time
uPublic.upDateRead = async function(key, time){
let oldHistory = {
alarm: {
time: null,
......@@ -163,7 +164,8 @@ uPublic.upDateRead = async function(key){
}
};
try{
oldHistory = await iot.storage.getMap('history');
let history = await iot.storage.getMap('history');
oldHistory = history ? history : oldHistory;
console.log(oldHistory);
}
catch (error){
......@@ -172,12 +174,15 @@ uPublic.upDateRead = async function(key){
let newHistory = oldHistory;
newHistory[key].isReadFlag = true;
iot.storage.setMap('history', newHistory, (response) => {
console.log(res);
}, () => {
});
newHistory[key].time = time;
let flag = await iot.storage.setMap('history', newHistory);
if(flag){
return false;
}
}
iot.ready(() => {
uPublic.recalc();
});
......
......@@ -61,18 +61,11 @@ function backTap(){
//tap 扫描绑定设备
function scanAddTap(){
// iot.navigator.openWindow({
// url: './scanCodeAdd.html',
// id: 'scanCodeAdd'
// });
mui.openWindow({
iot.navigator.openWindow({
url: './scanCodeAdd.html',
id: 'scanCodeAdd',
show: {
aniShow: "none"
},
waiting: {
autoShow: false
}
});
}
......
......@@ -40,7 +40,7 @@ function init() {
setTextPassword(pwd){
this.textPassword = pwd;
},
gettTextErrorTip(){
getTextErrorTip(){
return this.textErrorTip;
},
setTextErrorTip(tip){
......@@ -110,12 +110,12 @@ function initComponentsConfig() {
}
}
//页面渲染后,获取wifi名称
function resolve(self){
iot.business.sds.getSSId({
success: (response) => {
console.log(response);
self.textWiFiName = response.data.ssid;
console.log(self.textWiFiName);
},
error: (error) => {
console.log(error);
......@@ -130,11 +130,13 @@ function resolve(self){
});
}
//设置wifi密码
function passwordChange(self,text){
self.textPassword = text;
console.log('passwordChange: ' + self.textPassword);
self.setTextPassword(text);
console.log('passwordChange: ' + self.getTextPassword());
}
//重新mui.back
mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{ });
iot.navigator.back();
......@@ -147,8 +149,6 @@ function backTap(){
//tap 连接
function connectButtonTap(self){
// console.log(self.getTextWiFiName());
// console.log(self.getTextPassword());
if(self.getTextWiFiName() == null || self.getTextWiFiName().trim() == ''){
self.setTextErrorTip(Vue.t('wifiAdd.unbindWifiTip'));
}else if(self.getTextPassword() == null || self.getTextPassword().trim() == ''){
......@@ -189,10 +189,6 @@ function connectButtonTap(self){
}
//wifi连接成功,停止连接wifi
uComponents.changeCommLoadingStatusAndText(self, 0, Vue.t('wifiAdd.wifiBindSuccess'));
// iot.business.sds.stopFindWifi({
// success: (response) => {},
// error: (error) => {}
// });
}
},
error: (error) => {
......@@ -233,7 +229,6 @@ function connectButtonTap(self){
}
let deviceId = response.info.sn;
unbind(self, deviceId, productId);
// bind(self, deviceId, productId);
}else if(response.data == "fail"){
//连接失败
if(window.iotDebug){
......@@ -280,25 +275,7 @@ function connectButtonTap(self){
},config.wifi_add_timeout);
}
//tap loading button
function commLoadingButtonTap(self) {
if(self.getStatus() == 1){
//绑定成功
uComponents.hideCommLoading(self);
iot.navigator.fire(plus.webview.getWebviewById('device'),'returnPage',{});
iot.navigator.openWindow({
url: '../device/index.html',
id: 'device'
});
}else if(self.getStatus() == 2){
//绑定失败
uComponents.hideCommLoading(self);
self.setStatus(0);
uComponents.changeCommLoadingStatusAndText(self, 0, Vue.t('addDevice.loading'));
}
}
//云端绑定之前先解绑
function unbind(self, deviceId, productId){
console.log(deviceId);
iot.business.api.sendCustom('lock/unbindDevice',{
......@@ -332,6 +309,7 @@ function unbind(self, deviceId, productId){
});
}
//云端绑定
function bind(self, deviceId, productId){
iot.business.api.sendCustom('lock/bind',{
data: {
......@@ -370,3 +348,21 @@ function bind(self, deviceId, productId){
complete: () => {}
});
}
//tap loading button
function commLoadingButtonTap(self) {
if(self.getStatus() == 1){
//绑定成功
uComponents.hideCommLoading(self);
iot.navigator.fire(plus.webview.getWebviewById('device'),'returnPage',{});
iot.navigator.openWindow({
url: '../device/index.html',
id: 'device'
});
}else if(self.getStatus() == 2){
//绑定失败
uComponents.hideCommLoading(self);
self.setStatus(0);
uComponents.changeCommLoadingStatusAndText(self, 0, Vue.t('addDevice.loading'));
}
}
\ No newline at end of file
......@@ -79,15 +79,4 @@ function wifiAddButtonTap(){
url: './wifiAdd.html',
id: 'wifiAdd'
});
console.log("in");
// iot.business.sds.wifiDeviceConfig({
// success: function (response) {
// console.log('wifiDeviceConfig success');
// console.log(response);
// },
// error: function (error) {
// console.log('wifiDeviceConfig error');
// console.log(error);
// }
// });
}
\ No newline at end of file
......@@ -47,6 +47,7 @@ function init() {
setDeviceId(id){
this.deviceId = id;
},
//tap 点击加载更多
onListLoadTap(){
listLoadTap(this);
},
......@@ -82,7 +83,8 @@ function initComponentsConfig() {
}
}
function resolve(self) {
// 获取历史记录
function resolve(self) {
self.setDeviceId(iot.navigator.getExtras().deviceId);
uComponents.showLoading(self);
iot.business.api.sendCustom('lock/getHistoryRecord',
......@@ -93,18 +95,13 @@ function initComponentsConfig() {
start_id: self.getStartId(),
page_size: PAGE_SIZE
},
success: (response) => {
success: async (response) => {
console.log(response);
if(self.flag){
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;
// }, () => {
// });
uPublic.upDateRead('notify');
self.flag = await uPublic.upDateRead('notify', moment(record[0].time).unix());
}
}
let data = uPublic.checkResponseData(response.data);
......@@ -131,25 +128,20 @@ function initComponentsConfig() {
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 获取报警信息失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'获取报警信息失败');
// }
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
}
}
//tap <
function backTap(){
iot.navigator.aback();
}
//重写mui.back
mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("fire");
......
......@@ -106,12 +106,7 @@ function initComponentsConfig() {
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;
// }, () => {
// });
uPublic.upDateRead('alarm');
self.flag = await uPublic.upDateRead('alarm', moment(record[0].time).unix());
}
}
let data = uPublic.checkResponseData(response.data);
......@@ -152,12 +147,6 @@ function initComponentsConfig() {
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 获取劫持报警信息'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'获取劫持报警信息');
// }
uPublic.openRequestErrorAlert(self);
},
complete: () => {
......@@ -171,6 +160,7 @@ function backTap(){
iot.navigator.aback();
}
//重写mui.back
mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("fire");
......
......@@ -107,6 +107,7 @@ function backTap(){
iot.navigator.aback();
}
//重写mui.back
mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("fire");
......@@ -118,6 +119,7 @@ function listLoadTap(self) {
resolve(self);
}
//获取历史记录(整个设备)
function getHistoryRecord(self){
iot.business.api.sendCustom('lock/getHistoryRecord',
{
......@@ -127,29 +129,18 @@ function getHistoryRecord(self){
start_id: self.getStartId(),
page_size: PAGE_SIZE
},
success: (response) => {
success: async (response) => {
setListData(self, response);
if(self.flag){
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;
// }, () => {
// });
uPublic.upDateRead('open');
self.flag = await uPublic.upDateRead('open', moment(record[0].time).unix());
}
}
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 获取开门记录失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'获取开门记录失败');
// }
uPublic.openRequestErrorAlert(self);
},
complete: () => {
......@@ -158,6 +149,7 @@ function getHistoryRecord(self){
});
}
//获取个人历史记录
function getPersonalHistory(self, id){
iot.business.api.sendCustom('lock/getPersonalHistory',
{
......@@ -173,12 +165,6 @@ function getPersonalHistory(self, id){
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 获取个人开门历史记录'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'获取个人开门历史记录');
// }
uPublic.openRequestErrorAlert(self);
},
complete: () => {
......@@ -187,6 +173,7 @@ function getPersonalHistory(self, id){
});
}
//设置历史记录渲染列表
function setListData(self, response){
let data = uPublic.checkResponseData(response.data);
if(data){
......
......@@ -82,10 +82,6 @@ function initComponentsConfig() {
}
}
function alert(){
alert('aaa');
}
function nameChange(self,text){
self.setTextName(text);
self.setTextErrorTip('');
......@@ -97,6 +93,13 @@ function backTap(){
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){
if(self.getTextName() == null || self.getTextName().trim() == ''){
......@@ -123,12 +126,6 @@ function saveTap(self){
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 修改设备名称失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'修改设备名称失败');
// }
uComponents.openAlert(self, Vue.t('editName.editNameFailue'), {
text: Vue.t('btn.confirm'), callback: function () {
let opener = plus.webview.currentWebview().opener();
......
......@@ -18,6 +18,7 @@ function init() {
//项目 list组件
uPublic.componentsExtend(['grid-list']);
uPublic.closeSlideBack();
console.log(iot.navigator.getExtras());
const app = new Vue({
data:{
//配置组件
......@@ -197,6 +198,7 @@ function initComponentsConfig() {
}
}
//获取设备信息
function getDoorlockInfo(self){
uComponents.showLoading(self);
let productId = config.model;
......@@ -216,57 +218,14 @@ function getDoorlockInfo(self){
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 获取门锁信息失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'获取门锁信息失败');
// }
uPublic.openRequestErrorAlert(self);
},
complete: () => {
uComponents.hideLoading(self);
}
});
// iot.business.api.send('device/getList',{
// data: {
// sds: false,
// device_id: self.extras.deviceId,
// product_id: productId,
// parent_id: 0,
// start_id: 0,
// number: 10
// },
// success: (response) => {
// console.log(response);
// let data = uPublic.checkResponseData(response.data);
// if(data){
// self.setDoorlock(response.data[0]);
// self.setTextNickname(self.getDoorlock().nickname);
// console.log(self.getDoorlock());
// }
// },
// error: (error) => {
// //请求失败
// uPublic.openRequestErrorAlert(self);
// console.log(error);
// },
// complete: () => {
// uComponents.hideLoading(self);
// }
// },true);
}
//tap <
function backTap(){
iot.navigator.aback();
}
mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("fire");
iot.navigator.back();
}
//tap 修改设备昵称
function editNameTap(self){
......@@ -282,44 +241,40 @@ function editNameTap(self){
}
}
//tap 解绑门锁
//tap ‘解绑门锁’ 显示解绑门锁弹框
function unbindDoorlockButtonTap(self){
self.setUnbindShowDialog(true);
//uComponents.openConfirm(self, Vue.t('doorlockManage.unbindDialogTip'),
// {text: Vue.t('dialog.cancel'), callback: function () {}},
// {text: Vue.t('dialog.unbind'), callback: function () {
// uComponents.showLoading(self);
// iot.business.sds.unbindDevice({
// data: {
// uuid: self.extras.uuid
// },
// success: (response) => {
// console.log(response);
// unbind(self);
// },
// error: (error) => {
// console.log(error)
// },
// complete: () => {
//
// }
// });
// }}
// );
}
//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',
id: 'device'
});
//tap 确认解绑门锁
function confirmTap(self){
self.setUnbindShowDialog(false);
// sds解绑门锁
iot.business.sds.unbindDevice({
data: {
uuid: self.extras.uuid
},
success: (response) => {
console.log(response);
unbind(self);
},
error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: sds解绑设备失败'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'sds解绑设备失败');
}
uPublic.openRequestErrorAlert(self);
},
complete: () => {
}
});
}
// 云端解绑门锁
function unbind(self){
iot.business.api.sendCustom('lock/unbind',{
data: {
......@@ -335,12 +290,6 @@ function unbind(self){
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 云端解绑失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'云端解绑失败');
// }
self.setStateShowFlag(false);
self.setShowMsg(Vue.t('doorlockManage.unbindFailue'));
self.setUnbindSucceess(false);
......@@ -351,46 +300,44 @@ function unbind(self){
});
}
//function unbindUser(self){
// iot.business.api.sendCustom('lock/unbindUser',{
// data: {
// rel_id: self.getDoorlock().id,
// device_id: self.getDoorlock().device_id,
// user_id: self.getDoorlock().user_device_id
// },
// success: (response) => {
// self.setStateShowFlag(true);
// self.setShowMsg(Vue.t('doorlockUser.unbindSuccess'));
// self.setUnbindSucceess(true);
// },
// error: (error) => {
// console.log(error);
// self.setStateShowFlag(false);
// self.setShowMsg(Vue.t('doorlockUser.unbindFailue'));
// self.setUnbindSucceess(false);
// },
// complete: () => {
// uComponents.hideLoading(self);
// }
// });
//}
//选择是否清除所有信息,默认选择为‘清除所有信息’
function isClearSwitchTap(self, value){
self.setValueIsClear(value);
console.log(self.getValueIsClear());
}
//tap <
function backTap(){
iot.navigator.aback();
}
//重写mui.back
mui.back = function(){
iot.navigator.fire(plus.webview.currentWebview().opener(),'returnPage',{});
console.log("fire");
iot.navigator.back();
}
// 选择: 是否接收门铃消息推送
function doorbellSwitchTap(self, value){
self.setValueDoorbell(value);
setOption(self);
}
// 选择: 是否接收报警消息推送
function alarmSwitchTap(self, value){
self.setValueAlarm(value);
setOption(self);
}
// 选择: 是否接收开门消息推送
function opendoorSwitchTap(self, value){
self.setValueOpendoor(value);
setOption(self);
}
// 调用设置推送接口
function setOption(self){
// uComponents.showLoading(self);
iot.business.api.sendCustom('lock/setPushOption',
{
data: {
......@@ -404,54 +351,26 @@ function setOption(self){
},
error: (error) => {
console.log(error);
// if(window.iotDebug){
// iotDebug.push('end: 设置推送失败'+JSON.stringify(error));
// }
// if (window.iotDebug) {
// iotDebug.upload(iot,'设置推送失败');
// }
uPublic.openRequestErrorAlert(self);
},
complete: () => {
// uComponents.hideLoading(self);
}
});
}
//tap 取消解绑门锁
function cancelTap(self){
self.setUnbindShowDialog(false);
}
function confirmTap(self){
self.setUnbindShowDialog(false);
iot.business.sds.unbindDevice({
data: {
uuid: self.extras.uuid
},
success: (response) => {
console.log(response);
unbind(self);
},
error: (error) => {
console.log(error);
if(window.iotDebug){
iotDebug.push('end: sds解绑设备失败'+JSON.stringify(error));
}
if (window.iotDebug) {
iotDebug.upload(iot,'sds解绑设备失败');
}
uPublic.openRequestErrorAlert(self);
},
complete: () => {
}
//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',
id: 'device'
});
// unbind(self);
}
function isClearSwitchTap(self, value){
self.setValueIsClear(value);
console.log(self.getValueIsClear());
}
}
......@@ -144,7 +144,7 @@ function logoutButtonTap(self){
console.log("sdsLogout:"+response);
let sdsResponse = response;
iot.business.websql.delMaps(['utoken', 'userinfo'], (response) => {
iot.storage.delMaps(['notifyTime','alarmTime','openTime'], (response) => {
iot.storage.delMaps(['historyId','history'], (response) => {
console.log("clearMap"+response);
//打开首页
iot.navigator.openWindow({
......
......@@ -4928,6 +4928,7 @@ var App = function (_Base) {
url: params.url,
id: params.id,
styles: params.styles || {},
show: params.show,
extras: { IOTData: params.extras },
waiting: params.waiting || { autoShow: false }
});
......
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