UNPKG

3.7 kBJavaScriptView Raw
1/**
2 * Bundle of @livelybone/vue-pagination
3 * Generated: 2019-03-05
4 * Version: 1.5.1
5 * License: MIT
6 * Author: livelybone(2631541504@qq.com)
7 */
8
9!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Pagination=t()}(this,function(){"use strict";var e,t,n,i,a,r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},o=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},s=Object.freeze({pages:1,page:1,pageSize:10,maxPageBtn:7}),c=Object.freeze({page:1,pageSize:10,currPageSize:10}),u=Object.freeze({enable:!0,text:"Go to",debonceTime:500}),p=Object.freeze({prev:"<",next:">"}),g={name:"Pagination",props:{noPage:Boolean,config:Object,input:Object,turnBtns:Object},data:function(){return{inputVal:"",timer:null}},computed:{myConfig:function(){return r({},this.noPage?c:s,this.config)},inputConfig:function(){return r({},u,this.input)},_turnBtns:function(){return r({},p,this.turnBtns)},pagesArr:function(){var e=this.myConfig,n=e.page,i=e.maxPageBtn,a=e.pages;return a<=i?[].concat(o(Array(a))).map(function(e,t){return t+1}):n<=(i+1)/2?[].concat(o(Array(i-1))).map(function(e,t){return t===i-2?"...":t+1}).concat([a]):a-(i-1)/2<=n?[1,"..."].concat([].concat(o(Array(i-2))).map(function(e,t){return a-t}).reverse()):[1,"..."].concat([].concat(o(Array(i-4))).map(function(e,t){return n-Math.floor((i-3)/2)+t+1})).concat(["...",a])},disabled:function(){return{pre:this.myConfig.page<=1,next:this.noPage?this.myConfig.pageSize>this.myConfig.currPageSize:this.myConfig.page>=this.myConfig.pages}},hide:function(){return!this.noPage&&this.myConfig.pages<=1||this.noPage&&this.myConfig.page<=1&&this.myConfig.pageSize>this.myConfig.currPageSize}},watch:{"myConfig.page":{handler:function(e){this.inputVal=+e},immediate:!0},inputVal:function(e){var t=+e;t!==+this.myConfig.page&&this.debonce(t)}},methods:{next:function(){var e=+this.myConfig.page+1;this.disabled.next||this.$emit("to",e)},prev:function(){var e=+this.myConfig.page-1;this.disabled.pre||this.$emit("to",e)},to:function(e){var t=Number(e);t&&this.$emit("to",t)},debonce:function(r){var o=this;clearTimeout(this.timer),this.timer=setTimeout(function(){var e=o.myConfig,t=e.page,n=e.pages,i=e.currPageSize,a=e.pageSize;0<r&&(o.noPage?a<=i||r<=+t:r<=n)&&o.to(r)},this.inputConfig.debonceTime)}}};return n=void 0,i=!(e={render:function(){var n=this,e=n.$createElement,i=n._self._c||e;return n.hide?n._e():i("div",{staticClass:"pagination"},[n.inputConfig.enable?[i("span",{staticClass:"label"},[n._v(n._s(n.inputConfig.text))]),n._v(" "),i("input",{directives:[{name:"model",rawName:"v-model",value:n.inputVal,expression:"inputVal"}],staticClass:"input",attrs:{type:"text"},domProps:{value:n.inputVal},on:{input:function(e){e.target.composing||(n.inputVal=e.target.value)}}})]:n._e(),n._v(" "),i("div",{staticClass:"page-btn",class:{disabled:n.disabled.pre},domProps:{innerHTML:n._s(n._turnBtns.prev)},on:{click:n.prev}}),n._v(" "),n.noPage?n._e():n._l(n.pagesArr,function(t,e){return i("div",{key:e,staticClass:"page-btn",class:{active:n.myConfig.page===t,disabled:!Number(t)},on:{click:function(e){n.to(t)}}},[n._v(n._s(t)+"\n ")])}),n._v(" "),i("div",{staticClass:"page-btn",class:{disabled:n.disabled.next},domProps:{innerHTML:n._s(n._turnBtns.next)},on:{click:n.next}})],2)},staticRenderFns:[]}),(a=("function"==typeof(t=g)?t.options:t)||{}).__file="Index.vue",a.render||(a.render=e.render,a.staticRenderFns=e.staticRenderFns,a._compiled=!0,i&&(a.functional=!0)),a._scopeId=n,a});