-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhelps.js
More file actions
60 lines (58 loc) · 2.61 KB
/
helps.js
File metadata and controls
60 lines (58 loc) · 2.61 KB
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
52
53
54
55
56
57
58
59
60
/**
* @author xiaojue
* @fileoverview view中的帮助函数
*/
var ejs = require('ejs');
module.exports = function(app) {
app.locals.createPaginationItem = function(currentPage, pageCount, pageMax, paginationMaxCount) {
var fixedCurrentPage = 1,
offset = Math.ceil(paginationMaxCount / 2);
fixedCurrentPage = (currentPage - offset) >= 1 ? (currentPage - offset) : 1;
if (pageCount > paginationMaxCount) {
/*当前页处于分页的中间位置*/
fixedCurrentPage = currentPage >= offset + 1 ? (currentPage - offset) : 1;
/*修正startIndex,分页按钮数总是paginationMaxCount*/
if (pageCount - fixedCurrentPage + 1 < paginationMaxCount) {
fixedCurrentPage -= paginationMaxCount - pageCount + currentPage - offset - 1;
}
}
/*修正fixedCurrentPage出现0*/
fixedCurrentPage = fixedCurrentPage > 0 ? fixedCurrentPage : 1;
var str = ejs.render('<% for(var i = fixedCurrentPage;i <= pageCount&&i<(paginationMaxCount+fixedCurrentPage); i++){%>' +
'<li data-action="J_page" <% if(i == currentPage){ %>class="active goto"<%}%> ><a href="javascript:;"><%= i %></a></li>' +
'<% } %>', {
fixedCurrentPage: fixedCurrentPage,
pageCount: pageCount,
paginationMaxCount: paginationMaxCount,
currentPage: currentPage
});
return str;
};
app.locals.createNavBarByLimit = function(userInfo,limit){
var limited = userInfo.limited;
var str = '';
for(limitItem in limited){
if(limit[limitItem]){
var href = limit[limitItem].href;
var name = limit[limitItem].name;
var path = limit[limitItem].path;
var className = limit[limitItem].className;
str += '<li><a href="#!' + href + '"><i class="' + className + '"></i>' + name;
if(limited[limitItem].length){
str += '<span class="fa arrow"></span></a><ul class="nav nav-second-level collapse">';
limited[limitItem].forEach(function(v, k){
var pathItem = path[v];
if(pathItem && pathItem.display){
str += '<li><a href="#!' + pathItem.path + '">' + pathItem.name + '</a></li>';
}
})
str += '</ul>';
}else{
str += '</a>';
}
str += '</li>';
}
}
return str;
}
};