pagination.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ exports: {},
  13. /******/ id: moduleId,
  14. /******/ loaded: false
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.loaded = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // __webpack_public_path__
  28. /******/ __webpack_require__.p = "/dist/";
  29. /******/ // Load entry module and return exports
  30. /******/ return __webpack_require__(0);
  31. /******/ })
  32. /************************************************************************/
  33. /******/ ({
  34. /***/ 0:
  35. /***/ function(module, exports, __webpack_require__) {
  36. module.exports = __webpack_require__(218);
  37. /***/ },
  38. /***/ 3:
  39. /***/ function(module, exports) {
  40. module.exports = function normalizeComponent (
  41. rawScriptExports,
  42. compiledTemplate,
  43. scopeId,
  44. cssModules
  45. ) {
  46. var esModule
  47. var scriptExports = rawScriptExports = rawScriptExports || {}
  48. // ES6 modules interop
  49. var type = typeof rawScriptExports.default
  50. if (type === 'object' || type === 'function') {
  51. esModule = rawScriptExports
  52. scriptExports = rawScriptExports.default
  53. }
  54. // Vue.extend constructor export interop
  55. var options = typeof scriptExports === 'function'
  56. ? scriptExports.options
  57. : scriptExports
  58. // render functions
  59. if (compiledTemplate) {
  60. options.render = compiledTemplate.render
  61. options.staticRenderFns = compiledTemplate.staticRenderFns
  62. }
  63. // scopedId
  64. if (scopeId) {
  65. options._scopeId = scopeId
  66. }
  67. // inject cssModules
  68. if (cssModules) {
  69. var computed = options.computed || (options.computed = {})
  70. Object.keys(cssModules).forEach(function (key) {
  71. var module = cssModules[key]
  72. computed[key] = function () { return module }
  73. })
  74. }
  75. return {
  76. esModule: esModule,
  77. exports: scriptExports,
  78. options: options
  79. }
  80. }
  81. /***/ },
  82. /***/ 60:
  83. /***/ function(module, exports) {
  84. module.exports = require("element-ui/lib/mixins/locale");
  85. /***/ },
  86. /***/ 218:
  87. /***/ function(module, exports, __webpack_require__) {
  88. 'use strict';
  89. exports.__esModule = true;
  90. var _pagination = __webpack_require__(219);
  91. var _pagination2 = _interopRequireDefault(_pagination);
  92. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  93. /* istanbul ignore next */
  94. _pagination2.default.install = function (Vue) {
  95. Vue.component(_pagination2.default.name, _pagination2.default);
  96. };
  97. exports.default = _pagination2.default;
  98. /***/ },
  99. /***/ 219:
  100. /***/ function(module, exports, __webpack_require__) {
  101. 'use strict';
  102. exports.__esModule = true;
  103. var _pager = __webpack_require__(220);
  104. var _pager2 = _interopRequireDefault(_pager);
  105. var _select = __webpack_require__(223);
  106. var _select2 = _interopRequireDefault(_select);
  107. var _option = __webpack_require__(224);
  108. var _option2 = _interopRequireDefault(_option);
  109. var _locale = __webpack_require__(60);
  110. var _locale2 = _interopRequireDefault(_locale);
  111. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  112. exports.default = {
  113. name: 'ElPagination',
  114. props: {
  115. pageSize: {
  116. type: Number,
  117. default: 10
  118. },
  119. small: Boolean,
  120. total: Number,
  121. pageCount: Number,
  122. currentPage: {
  123. type: Number,
  124. default: 1
  125. },
  126. layout: {
  127. default: 'prev, pager, next, jumper, ->, total'
  128. },
  129. pageSizes: {
  130. type: Array,
  131. default: function _default() {
  132. return [10, 20, 30, 40, 50, 100];
  133. }
  134. }
  135. },
  136. data: function data() {
  137. return {
  138. internalCurrentPage: 1,
  139. internalPageSize: 0
  140. };
  141. },
  142. render: function render(h) {
  143. var template = h(
  144. 'div',
  145. { 'class': 'el-pagination' },
  146. []
  147. );
  148. var layout = this.layout || '';
  149. if (!layout) return;
  150. var TEMPLATE_MAP = {
  151. prev: h(
  152. 'prev',
  153. null,
  154. []
  155. ),
  156. jumper: h(
  157. 'jumper',
  158. null,
  159. []
  160. ),
  161. pager: h(
  162. 'pager',
  163. {
  164. attrs: { currentPage: this.internalCurrentPage, pageCount: this.internalPageCount },
  165. on: {
  166. 'change': this.handleCurrentChange
  167. }
  168. },
  169. []
  170. ),
  171. next: h(
  172. 'next',
  173. null,
  174. []
  175. ),
  176. sizes: h(
  177. 'sizes',
  178. {
  179. attrs: { pageSizes: this.pageSizes }
  180. },
  181. []
  182. ),
  183. slot: h(
  184. 'my-slot',
  185. null,
  186. []
  187. ),
  188. total: h(
  189. 'total',
  190. null,
  191. []
  192. )
  193. };
  194. var components = layout.split(',').map(function (item) {
  195. return item.trim();
  196. });
  197. var rightWrapper = h(
  198. 'div',
  199. { 'class': 'el-pagination__rightwrapper' },
  200. []
  201. );
  202. var haveRightWrapper = false;
  203. if (this.small) {
  204. template.data.class += ' el-pagination--small';
  205. }
  206. components.forEach(function (compo) {
  207. if (compo === '->') {
  208. haveRightWrapper = true;
  209. return;
  210. }
  211. if (!haveRightWrapper) {
  212. template.children.push(TEMPLATE_MAP[compo]);
  213. } else {
  214. rightWrapper.children.push(TEMPLATE_MAP[compo]);
  215. }
  216. });
  217. if (haveRightWrapper) {
  218. template.children.push(rightWrapper);
  219. }
  220. return template;
  221. },
  222. components: {
  223. MySlot: {
  224. render: function render(h) {
  225. return this.$parent.$slots.default ? this.$parent.$slots.default[0] : '';
  226. }
  227. },
  228. Prev: {
  229. render: function render(h) {
  230. return h(
  231. 'button',
  232. {
  233. attrs: {
  234. type: 'button'
  235. },
  236. 'class': ['btn-prev', { disabled: this.$parent.internalCurrentPage <= 1 }],
  237. on: {
  238. 'click': this.$parent.prev
  239. }
  240. },
  241. [h(
  242. 'i',
  243. { 'class': 'el-icon el-icon-arrow-left' },
  244. []
  245. )]
  246. );
  247. }
  248. },
  249. Next: {
  250. render: function render(h) {
  251. return h(
  252. 'button',
  253. {
  254. attrs: {
  255. type: 'button'
  256. },
  257. 'class': ['btn-next', { disabled: this.$parent.internalCurrentPage === this.$parent.internalPageCount || this.$parent.internalPageCount === 0 }],
  258. on: {
  259. 'click': this.$parent.next
  260. }
  261. },
  262. [h(
  263. 'i',
  264. { 'class': 'el-icon el-icon-arrow-right' },
  265. []
  266. )]
  267. );
  268. }
  269. },
  270. Sizes: {
  271. mixins: [_locale2.default],
  272. props: {
  273. pageSizes: Array
  274. },
  275. watch: {
  276. pageSizes: {
  277. immediate: true,
  278. handler: function handler(value) {
  279. if (Array.isArray(value)) {
  280. this.$parent.internalPageSize = value.indexOf(this.$parent.pageSize) > -1 ? this.$parent.pageSize : this.pageSizes[0];
  281. }
  282. }
  283. }
  284. },
  285. render: function render(h) {
  286. var _this = this;
  287. return h(
  288. 'span',
  289. { 'class': 'el-pagination__sizes' },
  290. [h(
  291. 'el-select',
  292. {
  293. attrs: {
  294. value: this.$parent.internalPageSize
  295. },
  296. on: {
  297. 'input': this.handleChange
  298. }
  299. },
  300. [this.pageSizes.map(function (item) {
  301. return h(
  302. 'el-option',
  303. {
  304. attrs: {
  305. value: item,
  306. label: item + ' ' + _this.t('el.pagination.pagesize') }
  307. },
  308. []
  309. );
  310. })]
  311. )]
  312. );
  313. },
  314. components: {
  315. ElSelect: _select2.default,
  316. ElOption: _option2.default
  317. },
  318. methods: {
  319. handleChange: function handleChange(val) {
  320. if (val !== this.$parent.internalPageSize) {
  321. this.$parent.internalPageSize = val = parseInt(val, 10);
  322. this.$parent.$emit('size-change', val);
  323. }
  324. }
  325. }
  326. },
  327. Jumper: {
  328. mixins: [_locale2.default],
  329. data: function data() {
  330. return {
  331. oldValue: null
  332. };
  333. },
  334. methods: {
  335. handleFocus: function handleFocus(event) {
  336. this.oldValue = event.target.value;
  337. },
  338. handleChange: function handleChange(_ref) {
  339. var target = _ref.target;
  340. this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(target.value);
  341. this.oldValue = null;
  342. }
  343. },
  344. render: function render(h) {
  345. return h(
  346. 'span',
  347. { 'class': 'el-pagination__jump' },
  348. [this.t('el.pagination.goto'), h(
  349. 'input',
  350. {
  351. 'class': 'el-pagination__editor',
  352. attrs: { type: 'number',
  353. min: 1,
  354. max: this.internalPageCount,
  355. number: true },
  356. domProps: {
  357. 'value': this.$parent.internalCurrentPage
  358. },
  359. on: {
  360. 'change': this.handleChange,
  361. 'focus': this.handleFocus
  362. },
  363. style: { width: '30px' } },
  364. []
  365. ), this.t('el.pagination.pageClassifier')]
  366. );
  367. }
  368. },
  369. Total: {
  370. mixins: [_locale2.default],
  371. render: function render(h) {
  372. return typeof this.$parent.total === 'number' ? h(
  373. 'span',
  374. { 'class': 'el-pagination__total' },
  375. [this.t('el.pagination.total', { total: this.$parent.total })]
  376. ) : '';
  377. }
  378. },
  379. Pager: _pager2.default
  380. },
  381. methods: {
  382. handleCurrentChange: function handleCurrentChange(val) {
  383. this.internalCurrentPage = this.getValidCurrentPage(val);
  384. },
  385. prev: function prev() {
  386. var newVal = this.internalCurrentPage - 1;
  387. this.internalCurrentPage = this.getValidCurrentPage(newVal);
  388. },
  389. next: function next() {
  390. var newVal = this.internalCurrentPage + 1;
  391. this.internalCurrentPage = this.getValidCurrentPage(newVal);
  392. },
  393. getValidCurrentPage: function getValidCurrentPage(value) {
  394. value = parseInt(value, 10);
  395. var havePageCount = typeof this.internalPageCount === 'number';
  396. var resetValue = void 0;
  397. if (!havePageCount) {
  398. if (isNaN(value) || value < 1) resetValue = 1;
  399. } else {
  400. if (value < 1) {
  401. resetValue = 1;
  402. } else if (value > this.internalPageCount) {
  403. resetValue = this.internalPageCount;
  404. }
  405. }
  406. if (resetValue === undefined && isNaN(value)) {
  407. resetValue = 1;
  408. } else if (resetValue === 0) {
  409. resetValue = 1;
  410. }
  411. return resetValue === undefined ? value : resetValue;
  412. }
  413. },
  414. computed: {
  415. internalPageCount: function internalPageCount() {
  416. if (typeof this.total === 'number') {
  417. return Math.ceil(this.total / this.internalPageSize);
  418. } else if (typeof this.pageCount === 'number') {
  419. return this.pageCount;
  420. }
  421. return null;
  422. }
  423. },
  424. watch: {
  425. currentPage: {
  426. immediate: true,
  427. handler: function handler(val) {
  428. this.internalCurrentPage = val;
  429. }
  430. },
  431. pageSize: {
  432. immediate: true,
  433. handler: function handler(val) {
  434. this.internalPageSize = val;
  435. }
  436. },
  437. internalCurrentPage: function internalCurrentPage(newVal, oldVal) {
  438. var _this2 = this;
  439. newVal = parseInt(newVal, 10);
  440. /* istanbul ignore if */
  441. if (isNaN(newVal)) {
  442. newVal = oldVal || 1;
  443. } else {
  444. newVal = this.getValidCurrentPage(newVal);
  445. }
  446. if (newVal !== undefined) {
  447. this.$nextTick(function () {
  448. _this2.internalCurrentPage = newVal;
  449. if (oldVal !== newVal) {
  450. _this2.$emit('current-change', _this2.internalCurrentPage);
  451. }
  452. });
  453. } else {
  454. this.$emit('current-change', this.internalCurrentPage);
  455. }
  456. },
  457. internalPageCount: function internalPageCount(newVal) {
  458. /* istanbul ignore if */
  459. var oldPage = this.internalCurrentPage;
  460. if (newVal > 0 && oldPage === 0) {
  461. this.internalCurrentPage = 1;
  462. } else if (oldPage > newVal) {
  463. this.internalCurrentPage = newVal === 0 ? 1 : newVal;
  464. }
  465. }
  466. }
  467. };
  468. /***/ },
  469. /***/ 220:
  470. /***/ function(module, exports, __webpack_require__) {
  471. var Component = __webpack_require__(3)(
  472. /* script */
  473. __webpack_require__(221),
  474. /* template */
  475. __webpack_require__(222),
  476. /* scopeId */
  477. null,
  478. /* cssModules */
  479. null
  480. )
  481. module.exports = Component.exports
  482. /***/ },
  483. /***/ 221:
  484. /***/ function(module, exports) {
  485. 'use strict';
  486. exports.__esModule = true;
  487. //
  488. //
  489. //
  490. //
  491. //
  492. //
  493. //
  494. //
  495. //
  496. //
  497. //
  498. //
  499. //
  500. //
  501. //
  502. //
  503. //
  504. //
  505. //
  506. //
  507. //
  508. //
  509. //
  510. //
  511. //
  512. //
  513. //
  514. //
  515. //
  516. //
  517. //
  518. exports.default = {
  519. name: 'ElPager',
  520. props: {
  521. currentPage: Number,
  522. pageCount: Number
  523. },
  524. watch: {
  525. showPrevMore: function showPrevMore(val) {
  526. if (!val) this.quickprevIconClass = 'el-icon-more';
  527. },
  528. showNextMore: function showNextMore(val) {
  529. if (!val) this.quicknextIconClass = 'el-icon-more';
  530. }
  531. },
  532. methods: {
  533. onPagerClick: function onPagerClick(event) {
  534. var target = event.target;
  535. if (target.tagName === 'UL') {
  536. return;
  537. }
  538. var newPage = Number(event.target.textContent);
  539. var pageCount = this.pageCount;
  540. var currentPage = this.currentPage;
  541. if (target.className.indexOf('more') !== -1) {
  542. if (target.className.indexOf('quickprev') !== -1) {
  543. newPage = currentPage - 5;
  544. } else if (target.className.indexOf('quicknext') !== -1) {
  545. newPage = currentPage + 5;
  546. }
  547. }
  548. /* istanbul ignore if */
  549. if (!isNaN(newPage)) {
  550. if (newPage < 1) {
  551. newPage = 1;
  552. }
  553. if (newPage > pageCount) {
  554. newPage = pageCount;
  555. }
  556. }
  557. if (newPage !== currentPage) {
  558. this.$emit('change', newPage);
  559. }
  560. }
  561. },
  562. computed: {
  563. pagers: function pagers() {
  564. var pagerCount = 7;
  565. var currentPage = Number(this.currentPage);
  566. var pageCount = Number(this.pageCount);
  567. var showPrevMore = false;
  568. var showNextMore = false;
  569. if (pageCount > pagerCount) {
  570. if (currentPage > pagerCount - 2) {
  571. showPrevMore = true;
  572. }
  573. if (currentPage < pageCount - 2) {
  574. showNextMore = true;
  575. }
  576. }
  577. var array = [];
  578. if (showPrevMore && !showNextMore) {
  579. var startPage = pageCount - (pagerCount - 2);
  580. for (var i = startPage; i < pageCount; i++) {
  581. array.push(i);
  582. }
  583. } else if (!showPrevMore && showNextMore) {
  584. for (var _i = 2; _i < pagerCount; _i++) {
  585. array.push(_i);
  586. }
  587. } else if (showPrevMore && showNextMore) {
  588. var offset = Math.floor(pagerCount / 2) - 1;
  589. for (var _i2 = currentPage - offset; _i2 <= currentPage + offset; _i2++) {
  590. array.push(_i2);
  591. }
  592. } else {
  593. for (var _i3 = 2; _i3 < pageCount; _i3++) {
  594. array.push(_i3);
  595. }
  596. }
  597. this.showPrevMore = showPrevMore;
  598. this.showNextMore = showNextMore;
  599. return array;
  600. }
  601. },
  602. data: function data() {
  603. return {
  604. current: null,
  605. showPrevMore: false,
  606. showNextMore: false,
  607. quicknextIconClass: 'el-icon-more',
  608. quickprevIconClass: 'el-icon-more'
  609. };
  610. }
  611. };
  612. /***/ },
  613. /***/ 222:
  614. /***/ function(module, exports) {
  615. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  616. return _c('ul', {
  617. staticClass: "el-pager",
  618. on: {
  619. "click": _vm.onPagerClick
  620. }
  621. }, [(_vm.pageCount > 0) ? _c('li', {
  622. staticClass: "number",
  623. class: {
  624. active: _vm.currentPage === 1
  625. }
  626. }, [_vm._v("1")]) : _vm._e(), (_vm.showPrevMore) ? _c('li', {
  627. staticClass: "el-icon more btn-quickprev",
  628. class: [_vm.quickprevIconClass],
  629. on: {
  630. "mouseenter": function($event) {
  631. _vm.quickprevIconClass = 'el-icon-d-arrow-left'
  632. },
  633. "mouseleave": function($event) {
  634. _vm.quickprevIconClass = 'el-icon-more'
  635. }
  636. }
  637. }) : _vm._e(), _vm._l((_vm.pagers), function(pager) {
  638. return _c('li', {
  639. staticClass: "number",
  640. class: {
  641. active: _vm.currentPage === pager
  642. }
  643. }, [_vm._v(_vm._s(pager))])
  644. }), (_vm.showNextMore) ? _c('li', {
  645. staticClass: "el-icon more btn-quicknext",
  646. class: [_vm.quicknextIconClass],
  647. on: {
  648. "mouseenter": function($event) {
  649. _vm.quicknextIconClass = 'el-icon-d-arrow-right'
  650. },
  651. "mouseleave": function($event) {
  652. _vm.quicknextIconClass = 'el-icon-more'
  653. }
  654. }
  655. }) : _vm._e(), (_vm.pageCount > 1) ? _c('li', {
  656. staticClass: "number",
  657. class: {
  658. active: _vm.currentPage === _vm.pageCount
  659. }
  660. }, [_vm._v(_vm._s(_vm.pageCount))]) : _vm._e()], 2)
  661. },staticRenderFns: []}
  662. /***/ },
  663. /***/ 223:
  664. /***/ function(module, exports) {
  665. module.exports = require("element-ui/lib/select");
  666. /***/ },
  667. /***/ 224:
  668. /***/ function(module, exports) {
  669. module.exports = require("element-ui/lib/option");
  670. /***/ }
  671. /******/ });