资源简介
(function (Vue) {
Vue.component('pagination', {
props: {
pageNo: {
twoWay: true,
type: Number,
validator: function (value) {
return value > 0
},
default: 1
},
pageSize: {
twoWay: true,
type: Number,
validator: function (value) {
return value > 0
},
default: 10
},
totalResult: {
type: Number,
default: 0
},
displayNum: {
type: Number,
default: 6
},
edgeNum: {
type: Number,
default: 2
},
},
template: "<nav v-show=\"totalPages > 1\"><ul class=\"pagination\"><li v-if=\"!noPrevious\"><a style=\"cursor:pointer;\"v-on:click=\"selectPage(pageNo - 1)\"aria-label=\"Previous\"><span aria-hidden=\"true\">‹</span></a></li><li v-for=\"page in pages\"v-bind:class=\"{ \'active\': page.number == pageNo, \'disabled\': page.disabled }\"><a style=\"cursor:pointer;\"v-on:click=\"selectPage(page.number)\"v-text=\"page.text\"></a></li><li v-if=\"!noNext\"><a style=\"cursor:pointer;\"v-on:click=\"selectPage(pageNo 1)\"aria-label=\"Next\"><span aria-hidden=\"true\">›</span></a></li></ul></nav>",
replace: true,
inherit: false,
computed: {
noPrevious: function () {
return this.pageNo === 1;
},
noNext: function () {
return this.pageNo === this.totalPages;
},
pages: function () {
return getPages(this.pageNo, this.totalPages, this.edgeNum, this.displayNum);
},
totalPages: function () {
return getTotalPages(this.pageSize, this.totalResult);
},
},
methods: {
selectPage: function (num) {
if (this.pageNo != num && num > 0 && num <= this.totalPages) {
this.pageNo = num;
this.$dispatch('page-change');
}
},
selectSize: function (size) {
if (this.pageSize != size && size > 0) {
this.pageSize = size;
if (this.pageNo > this.totalPages) {
this.selectPage(this.totalPages);
}
else {
this.$dispatch('page-change');
}
}
},
},
});
function getTotalPages(pageSize, totalResult) {
var totalPages = pageSize < 1 ? 1 : Math.ceil(totalResult / pageSize);
return Math.max(totalPages || 0, 1);
}
// Create page object used in template
function makePage(number, text, isActive) {
return {
number: number,
text: text,
disabled: number === -1,
};
}
/**
* Calculate start and end point of pagination links depending on
* currentPage and num_display_entries.
* @return {Array}
*/
function getInterval(currentPage, pageCount, num_display_entries) {
//var num_display_entries = 6;
var ne_half = Math.ceil(num_display_entries / 2);
var np = pageCount;
var upper_limit = np - num_display_entries;
var start = currentPage > ne_half ? Math.max(Math.min(currentPage - ne_half, upper_limit), 0) : 0;
var end = currentPage > ne_half ? Math.min(currentPage ne_half, np) : Math.min(num_display_entries, np);
return [start, end];
}
function getPages(currentPage, totalPages, num_edge_entries, num_display_entries) {
var ret = [];
//var num_edge_entries = 2;
var skip_text = '...';
var np = totalPages;
var interval = getInterval(currentPage - 1, totalPages, num_display_entries);
// Generate starting points
if (interval[0] > 0 && num_edge_entries > 0) {
var end = Math.min(num_edge_entries, interval[0]);
for (var i = 0; i < end; i ) {
var page = makePage(i 1, i 1);
ret.push(page);
}
if (num_edge_entries < interval[0]) {
var page = makePage(-1, skip_text);
ret.push(page);
}
}
// Generate interval links
for (var i = interval[0]; i < interval[1]; i ) {
var page = makePage(i 1, i 1);
ret.push(page);
}
// Generate ending points
if (interval[1] < np && num_edge_entries > 0) {
if (np - num_edge_entries > interval[1]) {
var page = makePage(-1, skip_text);
ret.push(page);
}
var begin = Math.max(np - num_edge_entries, interval[1]);
for (var i = begin; i < np; i ) {
var page = makePage(i 1, i 1);
ret.push(page);
}
}
return ret;
}
})(Vue)
Vue.component('pagination', {
props: {
pageNo: {
twoWay: true,
type: Number,
validator: function (value) {
return value > 0
},
default: 1
},
pageSize: {
twoWay: true,
type: Number,
validator: function (value) {
return value > 0
},
default: 10
},
totalResult: {
type: Number,
default: 0
},
displayNum: {
type: Number,
default: 6
},
edgeNum: {
type: Number,
default: 2
},
},
template: "<nav v-show=\"totalPages > 1\"><ul class=\"pagination\"><li v-if=\"!noPrevious\"><a style=\"cursor:pointer;\"v-on:click=\"selectPage(pageNo - 1)\"aria-label=\"Previous\"><span aria-hidden=\"true\">‹</span></a></li><li v-for=\"page in pages\"v-bind:class=\"{ \'active\': page.number == pageNo, \'disabled\': page.disabled }\"><a style=\"cursor:pointer;\"v-on:click=\"selectPage(page.number)\"v-text=\"page.text\"></a></li><li v-if=\"!noNext\"><a style=\"cursor:pointer;\"v-on:click=\"selectPage(pageNo 1)\"aria-label=\"Next\"><span aria-hidden=\"true\">›</span></a></li></ul></nav>",
replace: true,
inherit: false,
computed: {
noPrevious: function () {
return this.pageNo === 1;
},
noNext: function () {
return this.pageNo === this.totalPages;
},
pages: function () {
return getPages(this.pageNo, this.totalPages, this.edgeNum, this.displayNum);
},
totalPages: function () {
return getTotalPages(this.pageSize, this.totalResult);
},
},
methods: {
selectPage: function (num) {
if (this.pageNo != num && num > 0 && num <= this.totalPages) {
this.pageNo = num;
this.$dispatch('page-change');
}
},
selectSize: function (size) {
if (this.pageSize != size && size > 0) {
this.pageSize = size;
if (this.pageNo > this.totalPages) {
this.selectPage(this.totalPages);
}
else {
this.$dispatch('page-change');
}
}
},
},
});
function getTotalPages(pageSize, totalResult) {
var totalPages = pageSize < 1 ? 1 : Math.ceil(totalResult / pageSize);
return Math.max(totalPages || 0, 1);
}
// Create page object used in template
function makePage(number, text, isActive) {
return {
number: number,
text: text,
disabled: number === -1,
};
}
/**
* Calculate start and end point of pagination links depending on
* currentPage and num_display_entries.
* @return {Array}
*/
function getInterval(currentPage, pageCount, num_display_entries) {
//var num_display_entries = 6;
var ne_half = Math.ceil(num_display_entries / 2);
var np = pageCount;
var upper_limit = np - num_display_entries;
var start = currentPage > ne_half ? Math.max(Math.min(currentPage - ne_half, upper_limit), 0) : 0;
var end = currentPage > ne_half ? Math.min(currentPage ne_half, np) : Math.min(num_display_entries, np);
return [start, end];
}
function getPages(currentPage, totalPages, num_edge_entries, num_display_entries) {
var ret = [];
//var num_edge_entries = 2;
var skip_text = '...';
var np = totalPages;
var interval = getInterval(currentPage - 1, totalPages, num_display_entries);
// Generate starting points
if (interval[0] > 0 && num_edge_entries > 0) {
var end = Math.min(num_edge_entries, interval[0]);
for (var i = 0; i < end; i ) {
var page = makePage(i 1, i 1);
ret.push(page);
}
if (num_edge_entries < interval[0]) {
var page = makePage(-1, skip_text);
ret.push(page);
}
}
// Generate interval links
for (var i = interval[0]; i < interval[1]; i ) {
var page = makePage(i 1, i 1);
ret.push(page);
}
// Generate ending points
if (interval[1] < np && num_edge_entries > 0) {
if (np - num_edge_entries > interval[1]) {
var page = makePage(-1, skip_text);
ret.push(page);
}
var begin = Math.max(np - num_edge_entries, interval[1]);
for (var i = begin; i < np; i ) {
var page = makePage(i 1, i 1);
ret.push(page);
}
}
return ret;
}
})(Vue)
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3094 2017-02-14 14:04 pagination-demo\index.html
文件 5300 2016-03-09 19:51 pagination-demo\vue-pagination.js
文件 2808 2017-02-14 14:08 pagination-demo\vue-table.js
目录 0 2016-07-08 17:28 pagination-demo
----------- --------- ---------- ----- ----
11202 4
----------- --------- ---------- ----- ----
文件 3094 2017-02-14 14:04 pagination-demo\index.html
文件 5300 2016-03-09 19:51 pagination-demo\vue-pagination.js
文件 2808 2017-02-14 14:08 pagination-demo\vue-table.js
目录 0 2016-07-08 17:28 pagination-demo
----------- --------- ---------- ----- ----
11202 4
- 上一篇:基于HTML5的Canvas在线绘图系统
- 下一篇:微信端上传-截图功能
相关资源
- js日期控件 demo
- zepto弹窗组件
- ocr文字识别组件源码(tesseract.js)
- Jquery分页Demo
- 图片左右滚动多用途,可单张,多张
- vue模拟微信
- 麻将骰子:.zip
- 同城打车-微信小程序源码.zip
- 图书管理系统-微信小程序源码.zip
- 网易云课堂-微信小程序源码.zip
- 新闻客户端-微信小程序源码.zip
- 相册;处理用户信息-微信小程序源码
- 小程序地图定位-微信小程序源码.zi
- 商城-微信小程序源码.zip
- 小程序页面生成器-微信小程序源码
- 今日头条-微信小程序源码.zip
- 健康菜谱-微信小程序源码.zip
- 电影推荐-微信小程序源码.zip
- 会议精灵-微信小程序源码.zip
- 豆瓣电影-微信小程序源码.zip
- 二手书-微信小程序源码.zip
- 仿网易云音乐-微信小程序源码.zip
- 电商小程序-微信小程序源码.zip
- 教务系统-微信小程序源码.zip
- 滴滴公交-查公交-微信小程序源码.z
- 云笔记-微信小程序源码.zip
- 百度小说-微信小程序源码.zip
- 移动小商城:基于node,包含前后台
- 备忘录-微信小程序源码.zip
- 小程序地图和小程序在地图上实现多
评论
共有 条评论