directives.js
6.38 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
* Created by DEV005 on 2015/8/21.
* gaoxin
*/
angular.module("xn.directive.pagination", ["xn/template/pagination/page.html"])
.directive("xnPagination",[ "$timeout", function ($timeout) {
return {
restrict: "AC",
templateUrl: "xn/template/pagination/templates.html",
scope: {
vm: '=ngModel',
onChange: '&'
},
replace: true,
require: "?ngModel",
link: function (scope, elem, attrs, ngModel) {
if (!ngModel) return;
scope.disabled={
isFirst:false,
isLast :false
};
scope.$watch("vm.totalCount", function () {
scope.vm.pageSize = parseInt(scope.vm.pageSize);
scope.vm.totalPageNum = Math.ceil(scope.vm.totalCount / scope.vm.pageSize);
});
//监控当前页数判断是否是第一页或者最后一页
scope.$watch("vm.pageNumber", function () {
var maxPage = Math.ceil(scope.vm.totalCount / scope.vm.pageSize);
if (scope.vm.pageNumber == 1) {
scope.disabled.isFirst = true;
}
else {
scope.disabled.isFirst = false;
}
if (scope.vm.pageNumber == maxPage) {
scope.disabled.isLast = true;
} else {
scope.disabled.isLast = false;
}
});
//改变页面显示条数
scope.changePageSize = function () {
var ifNum = /^[1-9]\d*$/;
if (ifNum.test(scope.vm.pageSize)) {
scope.vm.totalPageNum = Math.ceil(scope.vm.totalCount / scope.vm.pageSize);
} else {
scope.vm.pageSize = 1;
}
scope.vm.pageNumber = 1;
//$timeout(function () {
// scope.changePageSize();
//
//},850);
scope.onChange();
};
//改变当前页码
scope.changePageNum = function (choice) {
if (scope.vm.pageSize == "") {
scope.vm.pageSize = 10;
}
var maxPage = Math.ceil(scope.vm.totalCount / scope.vm.pageSize);
if(scope.vm.pageNumber > maxPage || scope.vm.pageNumber <= 0){
scope.vm.pageNumber=1;
}
//转到第一页
if ("first" == choice) {
if (scope.vm.pageNumber == 1) {
} else {
scope.vm.pageNumber = 1;
}
scope.onChange();
}
//转到上一页
if ("previous" == choice) {
if (scope.vm.pageNumber == 1) {
scope.disabled.isFirst=true;
}else{
scope.vm.pageNumber = scope.vm.pageNumber - 1;
}
scope.onChange();
}
if ("current" == choice) {
}
//转到下一页
if ("next" == choice) {
if (scope.vm.pageNumber < maxPage) {
scope.vm.pageNumber = scope.vm.pageNumber + 1;
} else {
scope.disabled.isLast=true;
}
scope.onChange();
}
//转到最后一页
if ("last" == choice) {
if (scope.vm.pageNumber == maxPage) {
scope.disabled.isLast=true;
}else{
scope.vm.pageNumber = maxPage;
}
scope.onChange();
}
};
}
};
}]);
angular.module("xn/template/pagination/page.html", []).run(["$templateCache", function ($templateCache) {
"use strict";
$templateCache.put("xn/template/pagination/templates.html",
"<div class=\"xn-directive-page\" >" +
"<div class=\"f-left pl-25\">" +
"<span class=\" pr-10\">显示</span>" +
"<input type=\"text\" class=\"form-control w-50 f-left text-center input-box\" ng-model =\"vm.pageSize\" ng-change=\"changePageSize() \">" +
"<span class=\"pl-10\">条</span>" +
"</div>" +
"<div class=\"f-left\">" +
"<span class=\"f-left pl-10 pr-10\">共</span>" +
"<span class='text-center'>{{vm.totalCount}}</span>" +
"<span class=\"pl-10\">条</span>" +
"</div>" +
"<div class=\"f-right pagination-right pr-25\">" +
"<span class=\"f-left pr-10\">" +
"<i class=\"pagination-ico arrow-first\" ng-click=\"changePageNum('first')\" ng-class=\"disabled.isFirst?'disablei':''\"></i>" +
"</span>" +
"<span class=\"f-left pr-10 forward\">" +
"<i class=\"pagination-ico arrow-left\" ng-click=\"changePageNum('previous')\" ng-class=\"disabled.isFirst?'disablei' :''\"></i>" +
"</span>" +
"<span class=\"f-left pr-10\">第</span>" +
"<input type=\"text\" class=\"form-control w-50 f-left text-center input-box\" ng-model=\"vm.pageNumber\" ng-change=\"changePageNum('current')\">" +
"<span class=\"pl-10 f-left\">页</span>" +
"<span class=\"pl-10 back f-left\">" +
"<i class=\" pagination-ico arrow-right\" ng-click=\"changePageNum('next')\" ng-class=\"disabled.isLast?'disablei':''\"></i>" +
"</span>" +
"<span class=\"pl-10 f-left\">" +
"<i class=\"pagination-ico arrow-last\" ng-click=\"changePageNum('last')\" ng-class=\"disabled.isLast?'disablei':''\"></i>" +
"</span>" +
"</div>" +
"</div> "
);
}]);