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 = 63);
  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. /***/ 4:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/utils/util");
  182. /***/ }),
  183. /***/ 40:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/select");
  186. /***/ }),
  187. /***/ 41:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/option");
  190. /***/ }),
  191. /***/ 63:
  192. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  193. "use strict";
  194. __webpack_require__.r(__webpack_exports__);
  195. // 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&
  196. var render = function() {
  197. var _vm = this
  198. var _h = _vm.$createElement
  199. var _c = _vm._self._c || _h
  200. return _c(
  201. "ul",
  202. { staticClass: "el-pager", on: { click: _vm.onPagerClick } },
  203. [
  204. _vm.pageCount > 0
  205. ? _c(
  206. "li",
  207. {
  208. staticClass: "number",
  209. class: { active: _vm.currentPage === 1, disabled: _vm.disabled }
  210. },
  211. [_vm._v("1")]
  212. )
  213. : _vm._e(),
  214. _vm.showPrevMore
  215. ? _c("li", {
  216. staticClass: "el-icon more btn-quickprev",
  217. class: [_vm.quickprevIconClass, { disabled: _vm.disabled }],
  218. on: {
  219. mouseenter: function($event) {
  220. _vm.onMouseenter("left")
  221. },
  222. mouseleave: function($event) {
  223. _vm.quickprevIconClass = "el-icon-more"
  224. }
  225. }
  226. })
  227. : _vm._e(),
  228. _vm._l(_vm.pagers, function(pager) {
  229. return _c(
  230. "li",
  231. {
  232. key: pager,
  233. staticClass: "number",
  234. class: { active: _vm.currentPage === pager, disabled: _vm.disabled }
  235. },
  236. [_vm._v(_vm._s(pager))]
  237. )
  238. }),
  239. _vm.showNextMore
  240. ? _c("li", {
  241. staticClass: "el-icon more btn-quicknext",
  242. class: [_vm.quicknextIconClass, { disabled: _vm.disabled }],
  243. on: {
  244. mouseenter: function($event) {
  245. _vm.onMouseenter("right")
  246. },
  247. mouseleave: function($event) {
  248. _vm.quicknextIconClass = "el-icon-more"
  249. }
  250. }
  251. })
  252. : _vm._e(),
  253. _vm.pageCount > 1
  254. ? _c(
  255. "li",
  256. {
  257. staticClass: "number",
  258. class: {
  259. active: _vm.currentPage === _vm.pageCount,
  260. disabled: _vm.disabled
  261. }
  262. },
  263. [_vm._v(_vm._s(_vm.pageCount))]
  264. )
  265. : _vm._e()
  266. ],
  267. 2
  268. )
  269. }
  270. var staticRenderFns = []
  271. render._withStripped = true
  272. // CONCATENATED MODULE: ./packages/pagination/src/pager.vue?vue&type=template&id=7274f267&
  273. // 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&
  274. //
  275. //
  276. //
  277. //
  278. //
  279. //
  280. //
  281. //
  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. /* harmony default export */ var pagervue_type_script_lang_js_ = ({
  307. name: 'ElPager',
  308. props: {
  309. currentPage: Number,
  310. pageCount: Number,
  311. pagerCount: Number,
  312. disabled: Boolean
  313. },
  314. watch: {
  315. showPrevMore: function showPrevMore(val) {
  316. if (!val) this.quickprevIconClass = 'el-icon-more';
  317. },
  318. showNextMore: function showNextMore(val) {
  319. if (!val) this.quicknextIconClass = 'el-icon-more';
  320. }
  321. },
  322. methods: {
  323. onPagerClick: function onPagerClick(event) {
  324. var target = event.target;
  325. if (target.tagName === 'UL' || this.disabled) {
  326. return;
  327. }
  328. var newPage = Number(event.target.textContent);
  329. var pageCount = this.pageCount;
  330. var currentPage = this.currentPage;
  331. var pagerCountOffset = this.pagerCount - 2;
  332. if (target.className.indexOf('more') !== -1) {
  333. if (target.className.indexOf('quickprev') !== -1) {
  334. newPage = currentPage - pagerCountOffset;
  335. } else if (target.className.indexOf('quicknext') !== -1) {
  336. newPage = currentPage + pagerCountOffset;
  337. }
  338. }
  339. /* istanbul ignore if */
  340. if (!isNaN(newPage)) {
  341. if (newPage < 1) {
  342. newPage = 1;
  343. }
  344. if (newPage > pageCount) {
  345. newPage = pageCount;
  346. }
  347. }
  348. if (newPage !== currentPage) {
  349. this.$emit('change', newPage);
  350. }
  351. },
  352. onMouseenter: function onMouseenter(direction) {
  353. if (this.disabled) return;
  354. if (direction === 'left') {
  355. this.quickprevIconClass = 'el-icon-d-arrow-left';
  356. } else {
  357. this.quicknextIconClass = 'el-icon-d-arrow-right';
  358. }
  359. }
  360. },
  361. computed: {
  362. pagers: function pagers() {
  363. var pagerCount = this.pagerCount;
  364. var halfPagerCount = (pagerCount - 1) / 2;
  365. var currentPage = Number(this.currentPage);
  366. var pageCount = Number(this.pageCount);
  367. var showPrevMore = false;
  368. var showNextMore = false;
  369. if (pageCount > pagerCount) {
  370. if (currentPage > pagerCount - halfPagerCount) {
  371. showPrevMore = true;
  372. }
  373. if (currentPage < pageCount - halfPagerCount) {
  374. showNextMore = true;
  375. }
  376. }
  377. var array = [];
  378. if (showPrevMore && !showNextMore) {
  379. var startPage = pageCount - (pagerCount - 2);
  380. for (var i = startPage; i < pageCount; i++) {
  381. array.push(i);
  382. }
  383. } else if (!showPrevMore && showNextMore) {
  384. for (var _i = 2; _i < pagerCount; _i++) {
  385. array.push(_i);
  386. }
  387. } else if (showPrevMore && showNextMore) {
  388. var offset = Math.floor(pagerCount / 2) - 1;
  389. for (var _i2 = currentPage - offset; _i2 <= currentPage + offset; _i2++) {
  390. array.push(_i2);
  391. }
  392. } else {
  393. for (var _i3 = 2; _i3 < pageCount; _i3++) {
  394. array.push(_i3);
  395. }
  396. }
  397. this.showPrevMore = showPrevMore;
  398. this.showNextMore = showNextMore;
  399. return array;
  400. }
  401. },
  402. data: function data() {
  403. return {
  404. current: null,
  405. showPrevMore: false,
  406. showNextMore: false,
  407. quicknextIconClass: 'el-icon-more',
  408. quickprevIconClass: 'el-icon-more'
  409. };
  410. }
  411. });
  412. // CONCATENATED MODULE: ./packages/pagination/src/pager.vue?vue&type=script&lang=js&
  413. /* harmony default export */ var src_pagervue_type_script_lang_js_ = (pagervue_type_script_lang_js_);
  414. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  415. var componentNormalizer = __webpack_require__(0);
  416. // CONCATENATED MODULE: ./packages/pagination/src/pager.vue
  417. /* normalize component */
  418. var component = Object(componentNormalizer["a" /* default */])(
  419. src_pagervue_type_script_lang_js_,
  420. render,
  421. staticRenderFns,
  422. false,
  423. null,
  424. null,
  425. null
  426. )
  427. /* hot reload */
  428. if (false) { var api; }
  429. component.options.__file = "packages/pagination/src/pager.vue"
  430. /* harmony default export */ var pager = (component.exports);
  431. // EXTERNAL MODULE: external "element-ui/lib/select"
  432. var select_ = __webpack_require__(40);
  433. var select_default = /*#__PURE__*/__webpack_require__.n(select_);
  434. // EXTERNAL MODULE: external "element-ui/lib/option"
  435. var option_ = __webpack_require__(41);
  436. var option_default = /*#__PURE__*/__webpack_require__.n(option_);
  437. // EXTERNAL MODULE: external "element-ui/lib/input"
  438. var input_ = __webpack_require__(9);
  439. var input_default = /*#__PURE__*/__webpack_require__.n(input_);
  440. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  441. var locale_ = __webpack_require__(7);
  442. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  443. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  444. var util_ = __webpack_require__(4);
  445. // CONCATENATED MODULE: ./packages/pagination/src/pagination.js
  446. /* harmony default export */ var pagination = ({
  447. name: 'ElPagination',
  448. props: {
  449. pageSize: {
  450. type: Number,
  451. default: 10
  452. },
  453. small: Boolean,
  454. total: Number,
  455. pageCount: Number,
  456. pagerCount: {
  457. type: Number,
  458. validator: function validator(value) {
  459. return (value | 0) === value && value > 4 && value < 22 && value % 2 === 1;
  460. },
  461. default: 7
  462. },
  463. currentPage: {
  464. type: Number,
  465. default: 1
  466. },
  467. layout: {
  468. default: 'prev, pager, next, jumper, ->, total'
  469. },
  470. pageSizes: {
  471. type: Array,
  472. default: function _default() {
  473. return [10, 20, 30, 40, 50, 100];
  474. }
  475. },
  476. popperClass: String,
  477. prevText: String,
  478. nextText: String,
  479. background: Boolean,
  480. disabled: Boolean,
  481. hideOnSinglePage: Boolean
  482. },
  483. data: function data() {
  484. return {
  485. internalCurrentPage: 1,
  486. internalPageSize: 0,
  487. lastEmittedPage: -1,
  488. userChangePageSize: false
  489. };
  490. },
  491. render: function render(h) {
  492. var layout = this.layout;
  493. if (!layout) return null;
  494. if (this.hideOnSinglePage && (!this.internalPageCount || this.internalPageCount === 1)) return null;
  495. var template = h('div', { 'class': ['el-pagination', {
  496. 'is-background': this.background,
  497. 'el-pagination--small': this.small
  498. }] });
  499. var TEMPLATE_MAP = {
  500. prev: h('prev'),
  501. jumper: h('jumper'),
  502. pager: h('pager', {
  503. attrs: { currentPage: this.internalCurrentPage, pageCount: this.internalPageCount, pagerCount: this.pagerCount, disabled: this.disabled },
  504. on: {
  505. 'change': this.handleCurrentChange
  506. }
  507. }),
  508. next: h('next'),
  509. sizes: h('sizes', {
  510. attrs: { pageSizes: this.pageSizes }
  511. }),
  512. slot: h('slot', [this.$slots.default ? this.$slots.default : '']),
  513. total: h('total')
  514. };
  515. var components = layout.split(',').map(function (item) {
  516. return item.trim();
  517. });
  518. var rightWrapper = h('div', { 'class': 'el-pagination__rightwrapper' });
  519. var haveRightWrapper = false;
  520. template.children = template.children || [];
  521. rightWrapper.children = rightWrapper.children || [];
  522. components.forEach(function (compo) {
  523. if (compo === '->') {
  524. haveRightWrapper = true;
  525. return;
  526. }
  527. if (!haveRightWrapper) {
  528. template.children.push(TEMPLATE_MAP[compo]);
  529. } else {
  530. rightWrapper.children.push(TEMPLATE_MAP[compo]);
  531. }
  532. });
  533. if (haveRightWrapper) {
  534. template.children.unshift(rightWrapper);
  535. }
  536. return template;
  537. },
  538. components: {
  539. Prev: {
  540. render: function render(h) {
  541. return h(
  542. 'button',
  543. {
  544. attrs: {
  545. type: 'button',
  546. disabled: this.$parent.disabled || this.$parent.internalCurrentPage <= 1
  547. },
  548. 'class': 'btn-prev', on: {
  549. 'click': this.$parent.prev
  550. }
  551. },
  552. [this.$parent.prevText ? h('span', [this.$parent.prevText]) : h('i', { 'class': 'el-icon el-icon-arrow-left' })]
  553. );
  554. }
  555. },
  556. Next: {
  557. render: function render(h) {
  558. return h(
  559. 'button',
  560. {
  561. attrs: {
  562. type: 'button',
  563. disabled: this.$parent.disabled || this.$parent.internalCurrentPage === this.$parent.internalPageCount || this.$parent.internalPageCount === 0
  564. },
  565. 'class': 'btn-next', on: {
  566. 'click': this.$parent.next
  567. }
  568. },
  569. [this.$parent.nextText ? h('span', [this.$parent.nextText]) : h('i', { 'class': 'el-icon el-icon-arrow-right' })]
  570. );
  571. }
  572. },
  573. Sizes: {
  574. mixins: [locale_default.a],
  575. props: {
  576. pageSizes: Array
  577. },
  578. watch: {
  579. pageSizes: {
  580. immediate: true,
  581. handler: function handler(newVal, oldVal) {
  582. if (Object(util_["valueEquals"])(newVal, oldVal)) return;
  583. if (Array.isArray(newVal)) {
  584. this.$parent.internalPageSize = newVal.indexOf(this.$parent.pageSize) > -1 ? this.$parent.pageSize : this.pageSizes[0];
  585. }
  586. }
  587. }
  588. },
  589. render: function render(h) {
  590. var _this = this;
  591. return h(
  592. 'span',
  593. { 'class': 'el-pagination__sizes' },
  594. [h(
  595. 'el-select',
  596. {
  597. attrs: {
  598. value: this.$parent.internalPageSize,
  599. popperClass: this.$parent.popperClass || '',
  600. size: 'mini',
  601. disabled: this.$parent.disabled },
  602. on: {
  603. 'input': this.handleChange
  604. }
  605. },
  606. [this.pageSizes.map(function (item) {
  607. return h('el-option', {
  608. attrs: {
  609. value: item,
  610. label: item + _this.t('el.pagination.pagesize') }
  611. });
  612. })]
  613. )]
  614. );
  615. },
  616. components: {
  617. ElSelect: select_default.a,
  618. ElOption: option_default.a
  619. },
  620. methods: {
  621. handleChange: function handleChange(val) {
  622. if (val !== this.$parent.internalPageSize) {
  623. this.$parent.internalPageSize = val = parseInt(val, 10);
  624. this.$parent.userChangePageSize = true;
  625. this.$parent.$emit('update:pageSize', val);
  626. this.$parent.$emit('size-change', val);
  627. }
  628. }
  629. }
  630. },
  631. Jumper: {
  632. mixins: [locale_default.a],
  633. components: { ElInput: input_default.a },
  634. data: function data() {
  635. return {
  636. userInput: null
  637. };
  638. },
  639. watch: {
  640. '$parent.internalCurrentPage': function $parentInternalCurrentPage() {
  641. this.userInput = null;
  642. }
  643. },
  644. methods: {
  645. handleKeyup: function handleKeyup(_ref) {
  646. var keyCode = _ref.keyCode,
  647. target = _ref.target;
  648. // Chrome, Safari, Firefox triggers change event on Enter
  649. // Hack for IE: https://github.com/ElemeFE/element/issues/11710
  650. // Drop this method when we no longer supports IE
  651. if (keyCode === 13) {
  652. this.handleChange(target.value);
  653. }
  654. },
  655. handleInput: function handleInput(value) {
  656. this.userInput = value;
  657. },
  658. handleChange: function handleChange(value) {
  659. this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(value);
  660. this.$parent.emitChange();
  661. this.userInput = null;
  662. }
  663. },
  664. render: function render(h) {
  665. return h(
  666. 'span',
  667. { 'class': 'el-pagination__jump' },
  668. [this.t('el.pagination.goto'), h('el-input', {
  669. 'class': 'el-pagination__editor is-in-pagination',
  670. attrs: { min: 1,
  671. max: this.$parent.internalPageCount,
  672. value: this.userInput !== null ? this.userInput : this.$parent.internalCurrentPage,
  673. type: 'number',
  674. disabled: this.$parent.disabled
  675. },
  676. nativeOn: {
  677. 'keyup': this.handleKeyup
  678. },
  679. on: {
  680. 'input': this.handleInput,
  681. 'change': this.handleChange
  682. }
  683. }), this.t('el.pagination.pageClassifier')]
  684. );
  685. }
  686. },
  687. Total: {
  688. mixins: [locale_default.a],
  689. render: function render(h) {
  690. return typeof this.$parent.total === 'number' ? h(
  691. 'span',
  692. { 'class': 'el-pagination__total' },
  693. [this.t('el.pagination.total', { total: this.$parent.total })]
  694. ) : '';
  695. }
  696. },
  697. Pager: pager
  698. },
  699. methods: {
  700. handleCurrentChange: function handleCurrentChange(val) {
  701. this.internalCurrentPage = this.getValidCurrentPage(val);
  702. this.userChangePageSize = true;
  703. this.emitChange();
  704. },
  705. prev: function prev() {
  706. if (this.disabled) return;
  707. var newVal = this.internalCurrentPage - 1;
  708. this.internalCurrentPage = this.getValidCurrentPage(newVal);
  709. this.$emit('prev-click', this.internalCurrentPage);
  710. this.emitChange();
  711. },
  712. next: function next() {
  713. if (this.disabled) return;
  714. var newVal = this.internalCurrentPage + 1;
  715. this.internalCurrentPage = this.getValidCurrentPage(newVal);
  716. this.$emit('next-click', this.internalCurrentPage);
  717. this.emitChange();
  718. },
  719. getValidCurrentPage: function getValidCurrentPage(value) {
  720. value = parseInt(value, 10);
  721. var havePageCount = typeof this.internalPageCount === 'number';
  722. var resetValue = void 0;
  723. if (!havePageCount) {
  724. if (isNaN(value) || value < 1) resetValue = 1;
  725. } else {
  726. if (value < 1) {
  727. resetValue = 1;
  728. } else if (value > this.internalPageCount) {
  729. resetValue = this.internalPageCount;
  730. }
  731. }
  732. if (resetValue === undefined && isNaN(value)) {
  733. resetValue = 1;
  734. } else if (resetValue === 0) {
  735. resetValue = 1;
  736. }
  737. return resetValue === undefined ? value : resetValue;
  738. },
  739. emitChange: function emitChange() {
  740. var _this2 = this;
  741. this.$nextTick(function () {
  742. if (_this2.internalCurrentPage !== _this2.lastEmittedPage || _this2.userChangePageSize) {
  743. _this2.$emit('current-change', _this2.internalCurrentPage);
  744. _this2.lastEmittedPage = _this2.internalCurrentPage;
  745. _this2.userChangePageSize = false;
  746. }
  747. });
  748. }
  749. },
  750. computed: {
  751. internalPageCount: function internalPageCount() {
  752. if (typeof this.total === 'number') {
  753. return Math.max(1, Math.ceil(this.total / this.internalPageSize));
  754. } else if (typeof this.pageCount === 'number') {
  755. return Math.max(1, this.pageCount);
  756. }
  757. return null;
  758. }
  759. },
  760. watch: {
  761. currentPage: {
  762. immediate: true,
  763. handler: function handler(val) {
  764. this.internalCurrentPage = this.getValidCurrentPage(val);
  765. }
  766. },
  767. pageSize: {
  768. immediate: true,
  769. handler: function handler(val) {
  770. this.internalPageSize = isNaN(val) ? 10 : val;
  771. }
  772. },
  773. internalCurrentPage: {
  774. immediate: true,
  775. handler: function handler(newVal) {
  776. this.$emit('update:currentPage', newVal);
  777. this.lastEmittedPage = -1;
  778. }
  779. },
  780. internalPageCount: function internalPageCount(newVal) {
  781. /* istanbul ignore if */
  782. var oldPage = this.internalCurrentPage;
  783. if (newVal > 0 && oldPage === 0) {
  784. this.internalCurrentPage = 1;
  785. } else if (oldPage > newVal) {
  786. this.internalCurrentPage = newVal === 0 ? 1 : newVal;
  787. this.userChangePageSize && this.emitChange();
  788. }
  789. this.userChangePageSize = false;
  790. }
  791. }
  792. });
  793. // CONCATENATED MODULE: ./packages/pagination/index.js
  794. /* istanbul ignore next */
  795. pagination.install = function (Vue) {
  796. Vue.component(pagination.name, pagination);
  797. };
  798. /* harmony default export */ var packages_pagination = __webpack_exports__["default"] = (pagination);
  799. /***/ }),
  800. /***/ 7:
  801. /***/ (function(module, exports) {
  802. module.exports = require("element-ui/lib/mixins/locale");
  803. /***/ }),
  804. /***/ 9:
  805. /***/ (function(module, exports) {
  806. module.exports = require("element-ui/lib/input");
  807. /***/ })
  808. /******/ });