-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtool.js
51 lines (48 loc) · 1.11 KB
/
tool.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
let pub = {};
pub.l = (msg) => {
console.log('\n\n', msg, '\n\n');
};
pub.fail = (res, err) => {
res.status(err.status).send({
err: err.status,
msg: err.msg
});
};
pub.getPage = (item_count, page_index, page_size) => {
let page_count, offset, limit, has_next, has_previous
page_count = parseInt(item_count/page_size);
if (item_count % page_size > 0){
page_count = page_count+1;
}
if (item_count == 0 || page_index > page_count){
offset = 0;
limit = 0;
page_index = 1;
} else {
page_index = page_index;
offset = page_size * (page_index - 1);
limit = parseInt(page_size)
}
has_next = page_index < page_count;
has_previous = page_index > 1;
return {
item_count: item_count,
page_index: page_index,
page_size: page_size,
page_count: page_count,
offset: offset,
limit: limit,
has_next: has_next,
has_previous: has_previous,
};
}
pub.checkLogin = (req, res, next) => {
if (req.user.username) {
console.log(req.user.username)
next()
} else {
res.send({err: '请登录后再操作'})
}
}
module.exports = pub;