1function Page(_ref) { 2 var pageSize = _ref.pageSize, 3 pageTotal = _ref.pageTotal, 4 curPage = _ref.curPage, 5 id = _ref.id, 6 getPage = _ref.getPage, 7 showPageTotalFlag = _ref.showPageTotalFlag, 8 showSkipInputFlag = _ref.showSkipInputFlag, 9 pageAmount = _ref.pageAmount, 10 dataTotal = _ref.dataTotal; 11 if(!pageSize){ 12 pageSize = 0 13 }; 14 if(!pageSize){ 15 pageSize = 0 16 }; 17 if(!pageTotal){ 18 pageTotal = 0 19 }; 20 if(!pageAmount){ 21 pageAmount = 0 22 }; 23 if(!dataTotal){ 24 dataTotal = 0 25 }; 26 this.pageSize = pageSize || 5; //åé¡µä¸ªæ° 27 this.pageTotal = pageTotal; //æ»å ±å¤å°é¡µ 28 this.pageAmount = pageAmount; //æ¯é¡µå¤å°æ¡ 29 this.dataTotal = dataTotal; //æ»å ±å¤å°æ°æ® 30 this.curPage = curPage || 1; //åå§é¡µç 31 this.ul = document.createElement('ul'); 32 this.id = id; 33 this.getPage = getPage; 34 this.showPageTotalFlag = showPageTotalFlag || false; //æ¯å¦æ¾ç¤ºæ°æ®ç»è®¡ 35 this.showSkipInputFlag = showSkipInputFlag || false; //æ¯å¦æ¯æè·³è½¬ 36 if(dataTotal >0 &&pageTotal>0){ 37 this.init(); 38 }else{ 39 console.error("æ»é¡µæ°æè æ»æ°æ®åæ°ä¸å¯¹") 40 } 41}; 42 43// ç»å®ä¾å¯¹è±¡æ·»å å ¬å ±å±æ§åæ¹æ³ 44Page.prototype = { 45 init: function init() { 46 var pagination = document.getElementById(this.id); 47 pagination.innerHTML = ''; 48 this.ul.innerHTML = ''; 49 pagination.appendChild(this.ul); 50 var that = this; 51 //é¦é¡µ 52 that.firstPage(); 53 //ä¸ä¸é¡µ 54 that.lastPage(); 55 //å页
56 that.getPages().forEach(function (item) { 57 var li = document.createElement('li'); 58 if (item == that.curPage) { 59 li.className = 'active'; 60 } else { 61 li.onclick = function () { 62 that.curPage = parseInt(this.innerHTML); 63 that.init(); 64 that.getPage(that.curPage); 65 }; 66 } 67 li.innerHTML = item; 68 that.ul.appendChild(li); 69 }); 70 //ä¸ä¸é¡µ 71 that.nextPage(); 72 //尾页 73 that.finalPage(); 74 75 //æ¯å¦æ¯æè·³è½¬ 76 if (that.showSkipInputFlag) { 77 that.showSkipInput(); 78 } 79 //æ¯å¦æ¾ç¤ºæ»é¡µæ°,æ¯é¡µä¸ªæ°,æ°æ® 80 if (that.showPageTotalFlag) { 81 that.showPageTotal(); 82 } 83 }, 84 //é¦é¡µ 85 firstPage: function firstPage() { 86 var that = this; 87 var li = document.createElement('li'); 88 li.innerHTML = 'é¦é¡µ'; 89 this.ul.appendChild(li); 90 li.onclick = function () { 91 var val = parseInt(1); 92 that.curPage = val; 93 that.getPage(that.curPage); 94 that.init(); 95 }; 96 }, 97 //ä¸ä¸é¡µ 98 lastPage: function lastPage() { 99 var that = this; 100 var li = document.createElement('li'); 101 li.innerHTML = '<'; 102 if (parseInt(that.curPage) > 1) { 103 li.onclick = function () { 104 that.curPage = parseInt(that.curPage) - 1; 105 that.init(); 106 that.getPage(that.curPage); 107 }; 108 } else { 109 li.className = 'disabled'; 110 } 111 this.ul.appendChild(li); 112 }, 113 //å页 114 getPages: function getPages() { 115 var pag = []; 116 if (this.curPage <= this.pageTotal) { 117 if (this.curPage < this.pageSize) { 118 //å½å页æ°å°äºæ¾ç¤ºæ¡æ° 119 var i = Math.min(this.pageSize, this.pageTotal); 120 while (i) { 121 pag.unshift(i--); 122 } 123 } else { 124 //å½å页æ°å¤§äºæ¾ç¤ºæ¡æ° 125 var middle = this.curPage - Math.floor(this.pageSize / 2), 126 //ä»åªéå¼å§ 127 i = this.pageSize; 128 if (middle > this.pageTotal - this.pageSize) { 129 middle = this.pageTotal - this.pageSize + 1; 130 } 131 while (i--) { 132 pag.push(middle++); 133 } 134 } 135 } else { 136 console.error('å½å页æ°ä¸è½å¤§äºæ»é¡µæ°'); 137 } 138 if (!this.pageSize) { 139 console.error('æ¾ç¤ºé¡µæ°ä¸è½ä¸ºç©ºæè 0'); 140 } 141 return pag; 142 }, 143 //ä¸ä¸é¡µ 144 nextPage: function nextPage() { 145 var that = this; 146 var li = document.createElement('li'); 147 li.innerHTML = '>'; 148 if (parseInt(that.curPage) < parseInt(that.pageTotal)) { 149 li.onclick = function () { 150 that.curPage = parseInt(that.curPage) + 1; 151 that.init(); 152 that.getPage(that.curPage); 153 }; 154 } else { 155 li.className = 'disabled'; 156 } 157 this.ul.appendChild(li); 158 }, 159 //尾页 160 finalPage: function finalPage() { 161 var that = this; 162 var li = document.createElement('li'); 163 li.innerHTML = '尾页'; 164 this.ul.appendChild(li); 165 li.onclick = function () { 166 var yyfinalPage = that.pageTotal; 167 var val = parseInt(yyfinalPage); 168 that.curPage = val; 169 that.getPage(that.curPage); 170 that.init(); 171 }; 172 }, 173 //æ¯å¦æ¯æè·³è½¬ 174 showSkipInput: function showSkipInput() { 175 var that = this; 176 var li = document.createElement('li'); 177 li.className = 'totalPage'; 178 var span1 = document.createElement('span'); 179 span1.innerHTML = '跳转å°'; 180 li.appendChild(span1); 181 var input = document.createElement('input'); 182 input.setAttribute("type","number"); 183 input.onkeydown = function (e) { 184 var oEvent = e || event; 185 if (oEvent.keyCode == '13') { 186 var val = parseInt(oEvent.target.value); 187 if (typeof val === 'number' && val <= that.pageTotal && val>0) { 188 that.curPage = val; 189 that.getPage(that.curPage); 190 }else{ 191 alert("请è¾å ¥æ£ç¡®çé¡µæ° !") 192 } 193 that.init(); 194 } 195 }; 196 li.appendChild(input); 197 var span2 = document.createElement('span'); 198 span2.innerHTML = '页'; 199 li.appendChild(span2); 200 this.ul.appendChild(li); 201 }, 202 //æ¯å¦æ¾ç¤ºæ»é¡µæ°,æ¯é¡µä¸ªæ°,æ°æ® 203 showPageTotal: function showPageTotal() { 204 var that = this; 205 var li = document.createElement('li'); 206 li.innerHTML = 'å ± ' + that.pageTotal + ' é¡µ'; 207 li.className = 'totalPage'; 208 this.ul.appendChild(li); 209 var li2 = document.createElement('li'); 210 li2.innerHTML = 'æ¯é¡µ ' + that.pageAmount + ' æ¡'; 211 li2.className = 'totalPage'; 212 this.ul.appendChild(li2); 213 var li3 = document.createElement('li'); 214 li3.innerHTML = 'å计 ' + that.dataTotal + ' æ¡æ°æ®'; 215 li3.className = 'totalPage'; 216 this.ul.appendChild(li3); 217 } 218};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.