pagination.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 72);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 10:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/input");
  182. /***/ }),
  183. /***/ 3:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/utils/util");
  186. /***/ }),
  187. /***/ 44:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/select");
  190. /***/ }),
  191. /***/ 45:
  192. /***/ (function(module, exports) {
  193. module.exports = require("element-ui/lib/option");
  194. /***/ }),
  195. /***/ 6:
  196. /***/ (function(module, exports) {
  197. module.exports = require("element-ui/lib/mixins/locale");
  198. /***/ }),
  199. /***/ 72:
  200. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  201. "use strict";
  202. __webpack_require__.r(__webpack_exports__);
  203. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/pagination/src/pager.vue?vue&type=template&id=7274f267&
  204. var render = function() {
  205. var _vm = this
  206. var _h = _vm.$createElement
  207. var _c = _vm._self._c || _h
  208. return _c(
  209. "ul",
  210. { staticClass: "el-pager", on: { click: _vm.onPagerClick } },
  211. [
  212. _vm.pageCount > 0
  213. ? _c(
  214. "li",
  215. {
  216. staticClass: "number",
  217. class: { active: _vm.currentPage === 1, disabled: _vm.disabled }
  218. },
  219. [_vm._v("1")]
  220. )
  221. : _vm._e(),
  222. _vm.showPrevMore
  223. ? _c("li", {
  224. staticClass: "el-icon more btn-quickprev",
  225. class: [_vm.quickprevIconClass, { disabled: _vm.disabled }],
  226. on: {
  227. mouseenter: function($event) {
  228. _vm.onMouseenter("left")
  229. },
  230. mouseleave: function($event) {
  231. _vm.quickprevIconClass = "el-icon-more"
  232. }
  233. }
  234. })
  235. : _vm._e(),
  236. _vm._l(_vm.pagers, function(pager) {
  237. return _c(
  238. "li",
  239. {
  240. key: pager,
  241. staticClass: "number",
  242. class: { active: _vm.currentPage === pager, disabled: _vm.disabled }
  243. },
  244. [_vm._v(_vm._s(pager))]
  245. )
  246. }),
  247. _vm.showNextMore
  248. ? _c("li", {
  249. staticClass: "el-icon more btn-quicknext",
  250. class: [_vm.quicknextIconClass, { disabled: _vm.disabled }],
  251. on: {
  252. mouseenter: function($event) {
  253. _vm.onMouseenter("right")
  254. },
  255. mouseleave: function($event) {
  256. _vm.quicknextIconClass = "el-icon-more"
  257. }
  258. }
  259. })
  260. : _vm._e(),
  261. _vm.pageCount > 1
  262. ? _c(
  263. "li",
  264. {
  265. staticClass: "number",
  266. class: {
  267. active: _vm.currentPage === _vm.pageCount,
  268. disabled: _vm.disabled
  269. }
  270. },
  271. [_vm._v(_vm._s(_vm.pageCount))]
  272. )
  273. : _vm._e()
  274. ],
  275. 2
  276. )
  277. }
  278. var staticRenderFns = []
  279. render._withStripped = true
  280. // CONCATENATED MODULE: ./packages/pagination/src/pager.vue?vue&type=template&id=7274f267&
  281. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/pagination/src/pager.vue?vue&type=script&lang=js&
  282. //
  283. //
  284. //
  285. //
  286. //
  287. //
  288. //
  289. //
  290. //
  291. //
  292. //
  293. //
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //
  300. //
  301. //
  302. //
  303. //
  304. //
  305. //
  306. //
  307. //
  308. //
  309. //
  310. //
  311. //
  312. //
  313. //
  314. /* harmony default export */ var pagervue_type_script_lang_js_ = ({
  315. name: 'ElPager',
  316. props: {
  317. currentPage: Number,
  318. pageCount: Number,
  319. pagerCount: Number,
  320. disabled: Boolean
  321. },
  322. watch: {
  323. showPrevMore: function showPrevMore(val) {
  324. if (!val) this.quickprevIconClass = 'el-icon-more';
  325. },
  326. showNextMore: function showNextMore(val) {
  327. if (!val) this.quicknextIconClass = 'el-icon-more';
  328. }
  329. },
  330. methods: {
  331. onPagerClick: function onPagerClick(event) {
  332. var target = event.target;
  333. if (target.tagName === 'UL' || this.disabled) {
  334. return;
  335. }
  336. var newPage = Number(event.target.textContent);
  337. var pageCount = this.pageCount;
  338. var currentPage = this.currentPage;
  339. var pagerCountOffset = this.pagerCount - 2;
  340. if (target.className.indexOf('more') !== -1) {
  341. if (target.className.indexOf('quickprev') !== -1) {
  342. newPage = currentPage - pagerCountOffset;
  343. } else if (target.className.indexOf('quicknext') !== -1) {
  344. newPage = currentPage + pagerCountOffset;
  345. }
  346. }
  347. /* istanbul ignore if */
  348. if (!isNaN(newPage)) {
  349. if (newPage < 1) {
  350. newPage = 1;
  351. }
  352. if (newPage > pageCount) {
  353. newPage = pageCount;
  354. }
  355. }
  356. if (newPage !== currentPage) {
  357. this.$emit('change', newPage);
  358. }
  359. },
  360. onMouseenter: function onMouseenter(direction) {
  361. if (this.disabled) return;
  362. if (direction === 'left') {
  363. this.quickprevIconClass = 'el-icon-d-arrow-left';
  364. } else {
  365. this.quicknextIconClass = 'el-icon-d-arrow-right';
  366. }
  367. }
  368. },
  369. computed: {
  370. pagers: function pagers() {
  371. var pagerCount = this.pagerCount;
  372. var halfPagerCount = (pagerCount - 1) / 2;
  373. var currentPage = Number(this.currentPage);
  374. var pageCount = Number(this.pageCount);
  375. var showPrevMore = false;
  376. var showNextMore = false;
  377. if (pageCount > pagerCount) {
  378. if (currentPage > pagerCount - halfPagerCount) {
  379. showPrevMore = true;
  380. }
  381. if (currentPage < pageCount - halfPagerCount) {
  382. showNextMore = true;
  383. }
  384. }
  385. var array = [];
  386. if (showPrevMore && !showNextMore) {
  387. var startPage = pageCount - (pagerCount - 2);
  388. for (var i = startPage; i < pageCount; i++) {
  389. array.push(i);
  390. }
  391. } else if (!showPrevMore && showNextMore) {
  392. for (var _i = 2; _i < pagerCount; _i++) {
  393. array.push(_i);
  394. }
  395. } else if (showPrevMore && showNextMore) {
  396. var offset = Math.floor(pagerCount / 2) - 1;
  397. for (var _i2 = currentPage - offset; _i2 <= currentPage + offset; _i2++) {
  398. array.push(_i2);
  399. }
  400. } else {
  401. for (var _i3 = 2; _i3 < pageCount; _i3++) {
  402. array.push(_i3);
  403. }
  404. }
  405. this.showPrevMore = showPrevMore;
  406. this.showNextMore = showNextMore;
  407. return array;
  408. }
  409. },
  410. data: function data() {
  411. return {
  412. current: null,
  413. showPrevMore: false,
  414. showNextMore: false,
  415. quicknextIconClass: 'el-icon-more',
  416. quickprevIconClass: 'el-icon-more'
  417. };
  418. }
  419. });
  420. // CONCATENATED MODULE: ./packages/pagination/src/pager.vue?vue&type=script&lang=js&
  421. /* harmony default export */ var src_pagervue_type_script_lang_js_ = (pagervue_type_script_lang_js_);
  422. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  423. var componentNormalizer = __webpack_require__(0);
  424. // CONCATENATED MODULE: ./packages/pagination/src/pager.vue
  425. /* normalize component */
  426. var component = Object(componentNormalizer["a" /* default */])(
  427. src_pagervue_type_script_lang_js_,
  428. render,
  429. staticRenderFns,
  430. false,
  431. null,
  432. null,
  433. null
  434. )
  435. /* hot reload */
  436. if (false) { var api; }
  437. component.options.__file = "packages/pagination/src/pager.vue"
  438. /* harmony default export */ var pager = (component.exports);
  439. // EXTERNAL MODULE: external "element-ui/lib/select"
  440. var select_ = __webpack_require__(44);
  441. var select_default = /*#__PURE__*/__webpack_require__.n(select_);
  442. // EXTERNAL MODULE: external "element-ui/lib/option"
  443. var option_ = __webpack_require__(45);
  444. var option_default = /*#__PURE__*/__webpack_require__.n(option_);
  445. // EXTERNAL MODULE: external "element-ui/lib/input"
  446. var input_ = __webpack_require__(10);
  447. var input_default = /*#__PURE__*/__webpack_require__.n(input_);
  448. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  449. var locale_ = __webpack_require__(6);
  450. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  451. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  452. var util_ = __webpack_require__(3);
  453. // CONCATENATED MODULE: ./packages/pagination/src/pagination.js
  454. /* harmony default export */ var pagination = ({
  455. name: 'ElPagination',
  456. props: {
  457. pageSize: {
  458. type: Number,
  459. default: 10
  460. },
  461. small: Boolean,
  462. total: Number,
  463. pageCount: Number,
  464. pagerCount: {
  465. type: Number,
  466. validator: function validator(value) {
  467. return (value | 0) === value && value > 4 && value < 22 && value % 2 === 1;
  468. },
  469. default: 7
  470. },
  471. currentPage: {
  472. type: Number,
  473. default: 1
  474. },
  475. layout: {
  476. default: 'prev, pager, next, jumper, ->, total'
  477. },
  478. pageSizes: {
  479. type: Array,
  480. default: function _default() {
  481. return [10, 20, 30, 40, 50, 100];
  482. }
  483. },
  484. popperClass: String,
  485. prevText: String,
  486. nextText: String,
  487. background: Boolean,
  488. disabled: Boolean,
  489. hideOnSinglePage: Boolean
  490. },
  491. data: function data() {
  492. return {
  493. internalCurrentPage: 1,
  494. internalPageSize: 0,
  495. lastEmittedPage: -1,
  496. userChangePageSize: false
  497. };
  498. },
  499. render: function render(h) {
  500. var layout = this.layout;
  501. if (!layout) return null;
  502. if (this.hideOnSinglePage && (!this.internalPageCount || this.internalPageCount === 1)) return null;
  503. var template = h('div', { 'class': ['el-pagination', {
  504. 'is-background': this.background,
  505. 'el-pagination--small': this.small
  506. }] });
  507. var TEMPLATE_MAP = {
  508. prev: h('prev'),
  509. jumper: h('jumper'),
  510. pager: h('pager', {
  511. attrs: { currentPage: this.internalCurrentPage, pageCount: this.internalPageCount, pagerCount: this.pagerCount, disabled: this.disabled },
  512. on: {
  513. 'change': this.handleCurrentChange
  514. }
  515. }),
  516. next: h('next'),
  517. sizes: h('sizes', {
  518. attrs: { pageSizes: this.pageSizes }
  519. }),
  520. slot: h('slot', [this.$slots.default ? this.$slots.default : '']),
  521. total: h('total')
  522. };
  523. var components = layout.split(',').map(function (item) {
  524. return item.trim();
  525. });
  526. var rightWrapper = h('div', { 'class': 'el-pagination__rightwrapper' });
  527. var haveRightWrapper = false;
  528. template.children = template.children || [];
  529. rightWrapper.children = rightWrapper.children || [];
  530. components.forEach(function (compo) {
  531. if (compo === '->') {
  532. haveRightWrapper = true;
  533. return;
  534. }
  535. if (!haveRightWrapper) {
  536. template.children.push(TEMPLATE_MAP[compo]);
  537. } else {
  538. rightWrapper.children.push(TEMPLATE_MAP[compo]);
  539. }
  540. });
  541. if (haveRightWrapper) {
  542. template.children.unshift(rightWrapper);
  543. }
  544. return template;
  545. },
  546. components: {
  547. Prev: {
  548. render: function render(h) {
  549. return h(
  550. 'button',
  551. {
  552. attrs: {
  553. type: 'button',
  554. disabled: this.$parent.disabled || this.$parent.internalCurrentPage <= 1
  555. },
  556. 'class': 'btn-prev', on: {
  557. 'click': this.$parent.prev
  558. }
  559. },
  560. [this.$parent.prevText ? h('span', [this.$parent.prevText]) : h('i', { 'class': 'el-icon el-icon-arrow-left' })]
  561. );
  562. }
  563. },
  564. Next: {
  565. render: function render(h) {
  566. return h(
  567. 'button',
  568. {
  569. attrs: {
  570. type: 'button',
  571. disabled: this.$parent.disabled || this.$parent.internalCurrentPage === this.$parent.internalPageCount || this.$parent.internalPageCount === 0
  572. },
  573. 'class': 'btn-next', on: {
  574. 'click': this.$parent.next
  575. }
  576. },
  577. [this.$parent.nextText ? h('span', [this.$parent.nextText]) : h('i', { 'class': 'el-icon el-icon-arrow-right' })]
  578. );
  579. }
  580. },
  581. Sizes: {
  582. mixins: [locale_default.a],
  583. props: {
  584. pageSizes: Array
  585. },
  586. watch: {
  587. pageSizes: {
  588. immediate: true,
  589. handler: function handler(newVal, oldVal) {
  590. if (Object(util_["valueEquals"])(newVal, oldVal)) return;
  591. if (Array.isArray(newVal)) {
  592. this.$parent.internalPageSize = newVal.indexOf(this.$parent.pageSize) > -1 ? this.$parent.pageSize : this.pageSizes[0];
  593. }
  594. }
  595. }
  596. },
  597. render: function render(h) {
  598. var _this = this;
  599. return h(
  600. 'span',
  601. { 'class': 'el-pagination__sizes' },
  602. [h(
  603. 'el-select',
  604. {
  605. attrs: {
  606. value: this.$parent.internalPageSize,
  607. popperClass: this.$parent.popperClass || '',
  608. size: 'mini',
  609. disabled: this.$parent.disabled },
  610. on: {
  611. 'input': this.handleChange
  612. }
  613. },
  614. [this.pageSizes.map(function (item) {
  615. return h('el-option', {
  616. attrs: {
  617. value: item,
  618. label: item + _this.t('el.pagination.pagesize') }
  619. });
  620. })]
  621. )]
  622. );
  623. },
  624. components: {
  625. ElSelect: select_default.a,
  626. ElOption: option_default.a
  627. },
  628. methods: {
  629. handleChange: function handleChange(val) {
  630. if (val !== this.$parent.internalPageSize) {
  631. this.$parent.internalPageSize = val = parseInt(val, 10);
  632. this.$parent.userChangePageSize = true;
  633. this.$parent.$emit('update:pageSize', val);
  634. this.$parent.$emit('size-change', val);
  635. }
  636. }
  637. }
  638. },
  639. Jumper: {
  640. mixins: [locale_default.a],
  641. components: { ElInput: input_default.a },
  642. data: function data() {
  643. return {
  644. userInput: null
  645. };
  646. },
  647. watch: {
  648. '$parent.internalCurrentPage': function $parentInternalCurrentPage() {
  649. this.userInput = null;
  650. }
  651. },
  652. methods: {
  653. handleKeyup: function handleKeyup(_ref) {
  654. var keyCode = _ref.keyCode,
  655. target = _ref.target;
  656. // Chrome, Safari, Firefox triggers change event on Enter
  657. // Hack for IE: https://github.com/ElemeFE/element/issues/11710
  658. // Drop this method when we no longer supports IE
  659. if (keyCode === 13) {
  660. this.handleChange(target.value);
  661. }
  662. },
  663. handleInput: function handleInput(value) {
  664. this.userInput = value;
  665. },
  666. handleChange: function handleChange(value) {
  667. this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(value);
  668. this.$parent.emitChange();
  669. this.userInput = null;
  670. }
  671. },
  672. render: function render(h) {
  673. return h(
  674. 'span',
  675. { 'class': 'el-pagination__jump' },
  676. [this.t('el.pagination.goto'), h('el-input', {
  677. 'class': 'el-pagination__editor is-in-pagination',
  678. attrs: { min: 1,
  679. max: this.$parent.internalPageCount,
  680. value: this.userInput !== null ? this.userInput : this.$parent.internalCurrentPage,
  681. type: 'number',
  682. disabled: this.$parent.disabled
  683. },
  684. nativeOn: {
  685. 'keyup': this.handleKeyup
  686. },
  687. on: {
  688. 'input': this.handleInput,
  689. 'change': this.handleChange
  690. }
  691. }), this.t('el.pagination.pageClassifier')]
  692. );
  693. }
  694. },
  695. Total: {
  696. mixins: [locale_default.a],
  697. render: function render(h) {
  698. return typeof this.$parent.total === 'number' ? h(
  699. 'span',
  700. { 'class': 'el-pagination__total' },
  701. [this.t('el.pagination.total', { total: this.$parent.total })]
  702. ) : '';
  703. }
  704. },
  705. Pager: pager
  706. },
  707. methods: {
  708. handleCurrentChange: function handleCurrentChange(val) {
  709. this.internalCurrentPage = this.getValidCurrentPage(val);
  710. this.userChangePageSize = true;
  711. this.emitChange();
  712. },
  713. prev: function prev() {
  714. if (this.disabled) return;
  715. var newVal = this.internalCurrentPage - 1;
  716. this.internalCurrentPage = this.getValidCurrentPage(newVal);
  717. this.$emit('prev-click', this.internalCurrentPage);
  718. this.emitChange();
  719. },
  720. next: function next() {
  721. if (this.disabled) return;
  722. var newVal = this.internalCurrentPage + 1;
  723. this.internalCurrentPage = this.getValidCurrentPage(newVal);
  724. this.$emit('next-click', this.internalCurrentPage);
  725. this.emitChange();
  726. },
  727. getValidCurrentPage: function getValidCurrentPage(value) {
  728. value = parseInt(value, 10);
  729. var havePageCount = typeof this.internalPageCount === 'number';
  730. var resetValue = void 0;
  731. if (!havePageCount) {
  732. if (isNaN(value) || value < 1) resetValue = 1;
  733. } else {
  734. if (value < 1) {
  735. resetValue = 1;
  736. } else if (value > this.internalPageCount) {
  737. resetValue = this.internalPageCount;
  738. }
  739. }
  740. if (resetValue === undefined && isNaN(value)) {
  741. resetValue = 1;
  742. } else if (resetValue === 0) {
  743. resetValue = 1;
  744. }
  745. return resetValue === undefined ? value : resetValue;
  746. },
  747. emitChange: function emitChange() {
  748. var _this2 = this;
  749. this.$nextTick(function () {
  750. if (_this2.internalCurrentPage !== _this2.lastEmittedPage || _this2.userChangePageSize) {
  751. _this2.$emit('current-change', _this2.internalCurrentPage);
  752. _this2.lastEmittedPage = _this2.internalCurrentPage;
  753. _this2.userChangePageSize = false;
  754. }
  755. });
  756. }
  757. },
  758. computed: {
  759. internalPageCount: function internalPageCount() {
  760. if (typeof this.total === 'number') {
  761. return Math.max(1, Math.ceil(this.total / this.internalPageSize));
  762. } else if (typeof this.pageCount === 'number') {
  763. return Math.max(1, this.pageCount);
  764. }
  765. return null;
  766. }
  767. },
  768. watch: {
  769. currentPage: {
  770. immediate: true,
  771. handler: function handler(val) {
  772. this.internalCurrentPage = this.getValidCurrentPage(val);
  773. }
  774. },
  775. pageSize: {
  776. immediate: true,
  777. handler: function handler(val) {
  778. this.internalPageSize = isNaN(val) ? 10 : val;
  779. }
  780. },
  781. internalCurrentPage: {
  782. immediate: true,
  783. handler: function handler(newVal) {
  784. this.$emit('update:currentPage', newVal);
  785. this.lastEmittedPage = -1;
  786. }
  787. },
  788. internalPageCount: function internalPageCount(newVal) {
  789. /* istanbul ignore if */
  790. var oldPage = this.internalCurrentPage;
  791. if (newVal > 0 && oldPage === 0) {
  792. this.internalCurrentPage = 1;
  793. } else if (oldPage > newVal) {
  794. this.internalCurrentPage = newVal === 0 ? 1 : newVal;
  795. this.userChangePageSize && this.emitChange();
  796. }
  797. this.userChangePageSize = false;
  798. }
  799. }
  800. });
  801. // CONCATENATED MODULE: ./packages/pagination/index.js
  802. /* istanbul ignore next */
  803. pagination.install = function (Vue) {
  804. Vue.component(pagination.name, pagination);
  805. };
  806. /* harmony default export */ var packages_pagination = __webpack_exports__["default"] = (pagination);
  807. /***/ })
  808. /******/ });