Commit ca597bec by 朱建香

2017/12/26

#1.轮询方法完善(已完成)
2.整理less
#4.getCid用通用方法调用(已完成)
parent c605af96
......@@ -12,7 +12,7 @@ class Loop{
// this.url = params.request.url;
// this.opts = params.request.opts;
this.loopContent = params.loopContent;
this.timeout = params.timeout | 30;
this.timeout = params.timeout || 10;
this.fincb = params.fincb;
this.intervalTime = params.interval.delay;
this.intervalcb = params.interval.cb;
......@@ -62,7 +62,7 @@ class Loop{
if(this.intervalcb.error(error)){
this.canSend = true;
}else{
if(this.fincb!= null){
if(this.fincb!= null){
this.fincb.error(error);
this.fincb.complete();
this.clearTime();
......@@ -74,15 +74,15 @@ class Loop{
start(){
console.log("开始");
this.time = setTimeout(() => {
this.clearTime();
this.canDo = false;
this.fincb.error('timeout');
this.fincb.complete();
console.log("超时");
this.intervalcb = null;
this.fincb = null;
},this.timeout);
// this.time = setTimeout(() => {
// this.clearTime();
// this.canDo = false;
// this.fincb.error('timeout');
// this.fincb.complete();
// console.log("超时");
// this.intervalcb = null;
// this.fincb = null;
// },this.timeout);
console.log("第"+this.i+"次发送了请求");
console.log("发送时间"+new Date().getTime());
this.i++;
......@@ -96,9 +96,22 @@ class Loop{
this.sendRequest();
}
},1000);
let times = 1;
this.handle = setInterval(() => {
this.canDo = true;
},3000);
times++;
console.log('times'+times);
if(times > this.timeout){
this.clearTime();
this.canDo = false;
this.fincb.error('timeout');
this.fincb.complete();
this.intervalcb = null;
this.fincb = null;
}else{
this.canDo = true;
}
},this.intervalTime);
}
}
......
......@@ -2,10 +2,12 @@
* @class
* unotify
*/
import uloop from './uloop';
class unotify{
//在一个周期内获取cid
static async getCid(successCallback, errorCallback){
UpdateCid((response) => {
static getCid(successCallback, errorCallback){
this.UpdateCid((response) => {
successCallback(response);
}, (error) => {
errorCallback(error);
......@@ -13,28 +15,76 @@ class unotify{
}
//周期性获取cid,周期可调整
static getCidPeriotic(times){
// var self = this;
// return new Promise(function(resolve, reject){
// var i = 0;
// var cid = null;
// var handle = null;
// i++;
// cid = self.getCidOnce(i);
// console.log("第"+i+"次"+"获取的cid为"+cid);
// if(cid != null && cid != 'null' || i >= times){
// window.clearInterval(handle);
// resolve(cid);
// }else{
// handle = setInterval(function(){
// i++;
// cid = self.getCidOnce(i);
// console.log("第"+i+"次"+"获取的cid为"+cid);
// if(cid != null && cid != 'null' || i >= times){
// window.clearInterval(handle);
// resolve(cid);
// }
// },1000);
// }
// });
var self = this;
return new Promise(function(resolve, reject){
var i = 0;
var cid = null;
var handle = null;
i++;
cid = self.getCidOnce(i);
console.log("第"+i+"次"+"获取的cid为"+cid);
if(cid != null && cid != 'null' || i >= times){
window.clearInterval(handle);
resolve(cid);
}else{
handle = setInterval(function(){
i++;
cid = self.getCidOnce(i);
console.log("第"+i+"次"+"获取的cid为"+cid);
if(cid != null && cid != 'null' || i >= times){
window.clearInterval(handle);
resolve(cid);
new uloop({
loopContent: () => {
// var urlParams = {
// type: 'get',
// data: {},
// };
// return iot.network.send('http://192.168.2.75:3000/get', urlParams);
console.log(self.getCidOnce());
return self.getCidOnce();
},
timeout: times,
interval:{
delay: 1000,
cb: {
success: (response) => {
console.log('intervalcbSuccess:'+JSON.stringify(response));
},
error: (error) => {
console.log('intervalcbError:'+JSON.stringify(error));
}
}
},1000);
}
},
fincb: {
success: (response) => {
console.log('fincbSuccess:'+JSON.stringify(response));
resolve(response);
},
error: (error) => {
console.log('fincbSuccess:'+JSON.stringify(error));
if(error == 'timeout'){
resolve(null);
}
},
complete: () => {}
},
stopcondition: async (response) => {
// if(response.data.msg == 5){
// return true;
// }
if(response != null && response != 'null' ){
return true;
}
}
}).start();
});
}
//单次获取cid
......
......@@ -12,7 +12,8 @@ import moment from 'moment';
import crypto from '../../public/crypto.js';
import config from '../../public/config.js';
import {iot, uPublic, uComponents} from '../../public/public.js';
import Loop from '../../public/loop.js';
import uloop from '../../public/uloop.js';
import unotify from '../../public/unotify.js';
iot.ready(init);
function init() {
......@@ -112,6 +113,11 @@ function init() {
getDevices(this);
//注册监听上报
registerPushListener(this);
unotify.getCid((response) => {
console.log(response);
},(error) => {
console.log(error);
});
let self = this;
window.addEventListener('returnPage',function(event){
console.log('returnPage');
......@@ -500,6 +506,7 @@ function getLockInfo(self){
},
error: (error) => {
uPublic.openRequestErrorAlert(self);
initDeviceInfo(self);
console.log(error);
},
complete: () => {
......@@ -670,7 +677,7 @@ async function loopGetLockInfo(self, delay, timeout){
console.log(error);
}
console.log(oldHistoryId);
new Loop({
new uloop({
loopContent: () => {
var urlParams = {
type: 'post',
......@@ -682,7 +689,7 @@ async function loopGetLockInfo(self, delay, timeout){
return iot.business.api.send('lock/getNewInfo', urlParams, true, false);
// return plus.push.getClientInfo().clientid;
},
timeout: config.getHistoryTime*1000,
timeout: 3,
interval:{
delay: config.intervalTime*1000,
cb: {
......
......@@ -77,14 +77,6 @@ function init() {
setRole(role){
this.role = role;
},
//
// onSwipeLeftRow(index){
// swipeLeftRow(this, index);
// },
// onSwipeRightRow(){
// swipeRightRow(this);
// },
//
onTapLoad(){
// tapLoad();
},
......@@ -132,12 +124,6 @@ function getUserList(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: () => {
......@@ -146,7 +132,6 @@ function getUserList(self){
});
}
//
function sortRule(a,b){
return a.role - b.role;
}
......@@ -228,16 +213,7 @@ function addUserTap(self){
}
});
}
//
//// 向左滑动用户列表,修改用户列表下标
//function swipeLeftRow(self, index) {
// self.userListIndex = index;
//}
//// 向右滑动用户列表,修改用户列表下标
//function swipeRightRow(self) {
// self.userListIndex = null;
//}
//
// 点击组件列表 通知事件和当前点击列表下标
function onTapUserList(self, listIndex) {
iot.navigator.openWindow({
......@@ -291,12 +267,6 @@ function deleteUser(self, index){
},
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('doorlockUser.deleteFailure'), {
text: Vue.t('btn.confirm'), callback: function () {
}
......
......@@ -98,30 +98,7 @@ function qrcodeButtonTap(self){
let data = uPublic.checkResponseData(response.data);
if(data){
let qrKey = response.data.qrKey;
let data = {
qrKey: qrKey,
lockId: self.extras.lockId,
relId: self.extras.id
}
data = JSON.stringify(data);
let qr = self.$refs.qrcode;
QRCode.toCanvas(qr, data, {
scale: 5,
margin: 2
},(error) => {
if (error) {
console.log(error)
} else {
console.log('success');
uComponents.hideLoading(self);
qr.style.width = "5.333rem";
qr.style.height = "5.333rem";
console.log(qr.style);
setTimeout(() => {
self.setQrCodeDisabled(true);
},qrcode_timeout);
}
});
createQrcode(self, qrKey);
}else{}
},
error: (error) => {
......@@ -134,9 +111,38 @@ function qrcodeButtonTap(self){
}
//请求失败
uPublic.openRequestErrorAlert(self);
}
},
complete: () => {
uComponents.hideLoading(self);
}
});
setTimeout(() => {
self.setQrCodeDisabled(true);
},config.qrcode_timeout)
}
\ No newline at end of file
}
function createQrcode(self, qrKey){
let data = {
qrKey: qrKey,
lockId: self.extras.lockId,
relId: self.extras.id
}
data = JSON.stringify(data);
let qr = self.$refs.qrcode;
QRCode.toCanvas(qr, data, {
scale: 5,
margin: 2
},(error) => {
if (error) {
console.log(error)
} else {
console.log('success');
qr.style.width = "5.333rem";
qr.style.height = "5.333rem";
console.log(qr.style);
setTimeout(() => {
self.setQrCodeDisabled(true);
},qrcode_timeout);
}
});
}
......@@ -8,7 +8,7 @@
*/
import {iot, uPublic, uComponents} from '../../public/public.js';
import unotify from '../../public/unotify.js';
iot.ready(init);
function init() {
......@@ -31,23 +31,16 @@ function init() {
iotDebug.push('start: Debug');
}
var self = this;
// 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);
loginButtonTap(self);
}, function (err) {
console.log('error', err);
});
}else{
loginButtonTap(self);
}
// },function(err){
// console.log(err);
// })
console.log('innnnnnn');
if (plus.os.name == 'Android') {
iot.permission.checkPermission(['READ_EXTERNAL_STORAGE'], function (res) {
console.log('success', res);
loginButtonTap(self);
}, function (err) {
console.log('error', err);
});
}else{
loginButtonTap(self);
}
},
methods:{
getShowLoginButtonFlag(){
......@@ -93,23 +86,8 @@ function initComponentsConfig() {
}
}
//sds登陆
function loginButtonTap(self){
// if(window.iotDebug){
// iotDebug.push('start: initSDSLogin');
// }
// window.SDSPlugin.login({},(res)=>{
// console.log(res);
//// alert(res);
// var data = uPublic.checkResponseData(res.data);
// if(data){
//// alert("sds登陆成功");
// cloudsLogin(self, data.UserID);
// }
// },(err)=>{
// alert(error);
// console.log(err);
// })
console.log("loginButton");
iot.business.sds.checkSDSInit({
data: {},
success: (response) => {
......@@ -168,9 +146,9 @@ console.log("loginButton");
},
complete: () => {}
});
}
//云端登陆
function cloudsLogin(self, id){
uComponents.showLoading(self);
if(window.iotDebug){
......@@ -179,8 +157,8 @@ function cloudsLogin(self, id){
iot.business.api.send('user/sds_login',{
data: {
username: id,
clienId: self.getClientId()
// clienId: null
// clienId: self.getClientId()
clienId: null
},
success: (response) => {
if(window.iotDebug){
......
......@@ -119,26 +119,6 @@ function logoutButtonTap(self){
uComponents.openConfirm(self, Vue.t('myInfo.logoutDialogTip'),
{text: Vue.t('dialog.cancel'), callback: function () {}},
{text: Vue.t('dialog.confirm'), callback: function () {
// uPublic.logout({
// data: {
// sds: true
// },
// success: (response) => {
// console.log(response);
// iot.navigator.openWindow({
// url: '../login/index.html',
// id: 'login',
// extras: {
// needClose: true
// }
// });
// },
// error: (error) => {
// console.log(error);
// },
// complete: () => {}
// });
console.log("logout");
iot.business.user.logout({
data: {
// sds: false
......
......@@ -187,10 +187,11 @@
.custom-comm-loading();
//
.scanContent {
position: fixed;
top: 1.173rem;
bottom: 0;
left: 0;
width: 100%;
position: fixed;
top: 1.173rem;
bottom: 0;
left: 0;
width: 100%;
}
\ No newline at end of file
......@@ -468,4 +468,15 @@
.remoteOpendoorPage{
.mask(1051,@BODY-BG-COLOR);
}
//
.custom-marquee .u-marquee-text {
display: block;
line-height: 0.96rem;
}
.active .u-marquee-text {
-webkit-animation: none;
animation: none;
}
\ No newline at end of file
......@@ -220,6 +220,11 @@
}
}
//
.nameDisabled:before{
display: none;
}
.custom-isClearSwitch-switch {
width: 5.333rem;
height: auto;
......
......@@ -328,4 +328,9 @@
}
}
.mediaPosition(true);
\ No newline at end of file
.mediaPosition(true);
//
.userInfo-title-disabled:after {
display: none;
}
\ No newline at end of file
......@@ -224,14 +224,14 @@
&.u-switch-on .u-switch-handle{
background-color: transparent;
&:before{
content: '\e6a9';
content: '\e6aa';
left: 0;
}
}
&.u-switch-off .u-switch-handle{
background-color: transparent;
&:before{
content: '\e6aa';
content: '\e6a9';
left: 0;
}
}
......
......@@ -1199,7 +1199,7 @@ p {
}
.u-marquee .u-marquee-text {
/*display: inline-block;*/
display: inline-block;
line-height: 0.667rem;
}
......@@ -1212,6 +1212,7 @@ p {
.custom-marquee .u-marquee-text {
line-height: 0.96rem;
display: block;
}
.custom-marquee:before {
......@@ -1248,7 +1249,7 @@ p {
color: #91929a;
}
/*.active .u-marquee-text {
.active .u-marquee-text {
-webkit-animation: marquee 5s linear infinite;
animation: marquee 5s linear infinite;
}
......@@ -1263,9 +1264,9 @@ p {
-webkit-transform: translate(0,-100%);
transform: translate(0,-100%);
}
}*/
}
/*@keyframes marquee {
@keyframes marquee {
from {
-webkit-transform: translate(0,0.533rem);
transform: translate(0,0.533rem);
......@@ -1275,7 +1276,7 @@ p {
-webkit-transform: translate(0,-100%);
transform: translate(0,-100%);
}
}*/
}
.deviceHandle {
position: absolute;
......@@ -1620,4 +1621,14 @@ p {
height: 100%;
z-index: 1051;
background-color: #242635;
}
.custom-marquee .u-marquee-text {
display: block;
line-height: 0.96rem;
}
.active .u-marquee-text {
-webkit-animation: none;
animation: none;
}
\ No newline at end of file
......@@ -849,10 +849,6 @@ p {
line-height: 1;
}
.nameDisabled:before{
display: none;
}
.doorlockManage li:after {
content: '';
position: absolute;
......@@ -958,47 +954,8 @@ p {
left: 0;
}
.unbindState-dialog {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1051;
background-color: rgba(36, 38, 53, 0.9);
}
.unbindState-dialog div {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 8.933rem;
height: 5.68rem;
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-box-orient: vertical;
-webkit-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
align-items: center;
color: #00ffff;
font-size: 0.427rem;
border: 1px solid;
border-radius: 0.133rem;
}
.unbindState-dialog div img {
display: block;
width: 1.733rem;
height: 1.733rem;
margin-bottom: 0.373rem;
.nameDisabled:before {
display: none;
}
.custom-isClearSwitch-switch {
......@@ -1049,7 +1006,7 @@ p {
}
.custom-isClearSwitch-switch.u-switch-on .u-switch-handle:before {
content: '\e6aa';
content: '\e6aa';
left: 0;
}
......@@ -1060,4 +1017,47 @@ p {
.custom-isClearSwitch-switch.u-switch-off .u-switch-handle:before {
content: '\e6a9';
left: 0;
}
.unbindState-dialog {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1051;
background-color: rgba(36, 38, 53, 0.9);
}
.unbindState-dialog div {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 8.933rem;
height: 5.68rem;
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-box-orient: vertical;
-webkit-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
align-items: center;
color: #00ffff;
font-size: 0.427rem;
border: 1px solid;
border-radius: 0.133rem;
}
.unbindState-dialog div img {
display: block;
width: 1.733rem;
height: 1.733rem;
margin-bottom: 0.373rem;
}
\ No newline at end of file
......@@ -723,10 +723,6 @@ p {
line-height: 1;
}
.userInfo-title-disabled:after {
display: none;
}
.userInfoLink li.userInfo .userInfo-subtitle {
position: relative;
}
......@@ -1098,4 +1094,8 @@ p {
.guide-dialog .guideStep6 {
bottom: 1.2rem;
}
}
.userInfo-title-disabled:after {
display: none;
}
\ No newline at end of file
......@@ -993,7 +993,7 @@ p {
}
.custom-setHijack-switch.u-switch-on .u-switch-handle:before {
content: '\e6aa';
content: '\e6aa';
left: 0;
}
......
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