Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DoorLock
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
felix
DoorLock
Commits
89fc4d3d
Commit
89fc4d3d
authored
Dec 27, 2017
by
朱建香
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2017/12/27
#1:轮询方法优化 #4:getCid方法优化
parent
ca597bec
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
98 deletions
+5
-98
dev/src/public/uloop.js
+1
-60
dev/src/public/unotify.js
+4
-38
No files found.
dev/src/public/uloop.js
View file @
89fc4d3d
...
...
@@ -3,14 +3,13 @@
* loop
*/
//轮询通用方法:http://116.62.143.3:10080/iot-project-js/doorlock/issues/1
class
Loop
{
constructor
(
params
)
{
this
.
handle
=
null
;
this
.
watcher
=
null
;
this
.
time
=
null
;
// this.url = params.request.url;
// this.opts = params.request.opts;
this
.
loopContent
=
params
.
loopContent
;
this
.
timeout
=
params
.
timeout
||
10
;
this
.
fincb
=
params
.
fincb
;
...
...
@@ -22,15 +21,6 @@ class Loop{
this
.
i
=
0
;
}
requestsend
(
url
,
opts
,
needAuth
,
isPublic
,
i
){
let
data
=
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
0
,
0
,
0
];
console
.
log
(
"请求时间"
+
this
.
i
+
'-'
+
new
Date
().
getTime
());
setTimeout
(()
=>
{
console
.
log
(
"返回时间"
+
this
.
i
+
'-'
+
new
Date
().
getTime
());
opts
.
success
(
data
[
this
.
i
]);
},
100
);
}
clearTime
(){
clearInterval
(
this
.
handle
);
clearInterval
(
this
.
watcher
);
...
...
@@ -74,15 +64,6 @@ 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);
console
.
log
(
"第"
+
this
.
i
+
"次发送了请求"
);
console
.
log
(
"发送时间"
+
new
Date
().
getTime
());
this
.
i
++
;
...
...
@@ -114,43 +95,4 @@ class Loop{
},
this
.
intervalTime
);
}
}
//new Loop({
// request: {
// url: 'http://www.baidu.com',
// opts: {
// type: 'post',
// data: {}
// }
// },
// timeout: 6000,
// interval:{
// delay: 1000,
// cb: {
// success: (response) => {
// console.log('intervalcbSuccess:'+response);
// },
// error: (error) => {
// console.log('intervalcbSuccess:'+error);
// }
// }
// },
// fincb: {
// success: (response) => {
// console.log('fincbSuccess:'+response);
// },
// error: (error) => {
// console.log('fincbError:'+error);
// },
// complete: () => {}
// },
// stopcondition: (response) => {
// if(response == 1){
// return true;
// }else{
// return false;
// }
// }
//}).start();
export
default
Loop
;
//module.exports = Loop;
\ No newline at end of file
dev/src/public/unotify.js
View file @
89fc4d3d
...
...
@@ -4,6 +4,8 @@
*/
import
uloop
from
'./uloop'
;
//获取cid: http://116.62.143.3:10080/iot-project-js/doorlock/issues/4
class
unotify
{
//在一个周期内获取cid
static
getCid
(
successCallback
,
errorCallback
){
...
...
@@ -15,40 +17,10 @@ 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
){
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
,
...
...
@@ -77,9 +49,6 @@ class unotify{
complete
:
()
=>
{}
},
stopcondition
:
async
(
response
)
=>
{
// if(response.data.msg == 5){
// return true;
// }
if
(
response
!=
null
&&
response
!=
'null'
){
return
true
;
}
...
...
@@ -88,14 +57,10 @@ class unotify{
});
}
//单次获取cid
static
getCidOnce
(
i
){
static
getCidOnce
(){
var
clientInfo
=
plus
.
push
.
getClientInfo
();
if
(
clientInfo
&&
clientInfo
.
hasOwnProperty
(
'clientid'
)
&&
clientInfo
.
clientid
){
// if(i == 6){
return
(
clientInfo
.
clientid
);
// }else{
// return(null);
// }
}
else
{
return
(
null
);
}
...
...
@@ -112,6 +77,7 @@ class unotify{
clienId
:
cid
},
success
:
(
response
)
=>
{
console
.
log
(
response
);
if
(
typeof
successCallback
==
'function'
){
successCallback
(
'cid updateSuccess'
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment