v-page 2.0.8 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,47 +1,75 @@
1
- {
2
- "name": "v-page",
3
- "description": "A simple pagination bar, based on Vue2.x",
4
- "version": "2.0.8",
5
- "author": "TerryZ <terry5@foxmail.com>",
6
- "main": "dist/v-page.js",
7
- "license": "MIT",
8
- "scripts": {
9
- "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
10
- "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/TerryZ/v-page.git"
15
- },
16
- "keywords": [
17
- "front-end",
18
- "web",
19
- "vue",
20
- "vuejs",
21
- "page",
22
- "pagination"
23
- ],
24
- "dependencies": {
25
- "vue": "^2.6.10"
26
- },
27
- "browserslist": [
28
- "> 1%",
29
- "last 2 versions",
30
- "not ie <= 8"
31
- ],
32
- "devDependencies": {
33
- "babel-core": "^6.26.0",
34
- "babel-loader": "^7.1.2",
35
- "babel-preset-env": "^1.6.0",
36
- "babel-preset-stage-3": "^6.24.1",
37
- "cross-env": "^5.0.5",
38
- "css-loader": "^0.28.7",
39
- "file-loader": "^1.1.4",
40
- "node-sass": "^4.12.0",
41
- "sass-loader": "^6.0.7",
42
- "vue-loader": "^13.0.5",
43
- "vue-template-compiler": "^2.6.10",
44
- "webpack": "^3.6.0",
45
- "webpack-dev-server": "^3.1.14"
46
- }
47
- }
1
+ {
2
+ "name": "v-page",
3
+ "description": "A simple pagination bar, based on Vue2",
4
+ "version": "2.1.0",
5
+ "author": "TerryZ <terry5@foxmail.com>",
6
+ "main": "dist/v-page.js",
7
+ "files": [
8
+ "/dist",
9
+ "/types"
10
+ ],
11
+ "typings": "types/index.d.ts",
12
+ "license": "MIT",
13
+ "scripts": {
14
+ "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
15
+ "build": "cross-env NODE_ENV=production webpack --progress --hide-modules",
16
+ "test:unit": "mocha-webpack --webpack-config webpack.config.js --require tests/unit/setup.js tests/unit/**/*.spec.js",
17
+ "cover": "cross-env NODE_ENV=coverage nyc --reporter=lcov --reporter=text npm run test:unit"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/TerryZ/v-page.git"
22
+ },
23
+ "keywords": [
24
+ "front-end",
25
+ "web",
26
+ "vue",
27
+ "vuejs",
28
+ "page",
29
+ "pagination"
30
+ ],
31
+ "browserslist": [
32
+ "> 1%",
33
+ "last 2 versions",
34
+ "not ie <= 8"
35
+ ],
36
+ "devDependencies": {
37
+ "@vue/test-utils": "^1.2.2",
38
+ "babel-core": "^6.26.3",
39
+ "babel-loader": "^7.1.2",
40
+ "babel-plugin-transform-runtime": "^6.23.0",
41
+ "babel-polyfill": "^6.26.0",
42
+ "babel-preset-env": "^1.6.0",
43
+ "babel-preset-es2015": "^6.24.1",
44
+ "babel-preset-stage-0": "^6.24.1",
45
+ "babel-runtime": "^6.26.0",
46
+ "chai": "^4.3.4",
47
+ "codecov": "^3.5.0",
48
+ "cross-env": "^5.0.5",
49
+ "css-loader": "^0.28.11",
50
+ "file-loader": "^1.1.11",
51
+ "istanbul-instrumenter-loader": "^3.0.1",
52
+ "jsdom": "^15.1.1",
53
+ "jsdom-global": "^3.0.2",
54
+ "mocha": "^6.1.4",
55
+ "mocha-webpack": "^1.1.0",
56
+ "nyc": "^14.1.1",
57
+ "sass": "^1.43.4",
58
+ "sass-loader": "^7.3.1",
59
+ "typescript": "^4.3.5",
60
+ "vue": "^2.6.14",
61
+ "vue-loader": "^13.7.3",
62
+ "vue-style-loader": "^4.1.3",
63
+ "vue-template-compiler": "^2.6.14",
64
+ "webpack": "^3.6.0",
65
+ "webpack-dev-server": "^3.1.14",
66
+ "webpack-node-externals": "^1.7.2"
67
+ },
68
+ "nyc": {
69
+ "include": [
70
+ "src/Page.js"
71
+ ],
72
+ "instrument": false,
73
+ "sourceMap": false
74
+ }
75
+ }
@@ -0,0 +1,69 @@
1
+ export module 'v-page' {
2
+ import Vue from 'vue'
3
+
4
+ /**
5
+ * Pagination plugin for Vue
6
+ */
7
+ declare class Page extends Vue {
8
+ /**
9
+ * the number of current page
10
+ */
11
+ value: number
12
+ /**
13
+ * the number of total record
14
+ */
15
+ totalRow: number
16
+ /**
17
+ * v-page language
18
+ * `cn` by default
19
+ */
20
+ language?: string = 'cn'
21
+ /**
22
+ * page size list
23
+ */
24
+ pageSizeMenu?: boolean|number[] = [10, 20, 50, 100]
25
+ /**
26
+ * alignment direction
27
+ */
28
+ align?: string = 'right'
29
+ /**
30
+ * disabled the pagination
31
+ */
32
+ disabled?: boolean = false
33
+ /**
34
+ * whether to display the border
35
+ */
36
+ border?: boolean = true
37
+ /**
38
+ * whether to display page info bar
39
+ */
40
+ info?: boolean = true
41
+ /**
42
+ * whether to display page number buttons
43
+ */
44
+ pageNumber?: boolean = true
45
+ /**
46
+ * whether to display first page button
47
+ */
48
+ first?: boolean = true
49
+ /**
50
+ * whether to display last page button
51
+ */
52
+ last?: boolean = true
53
+ /**
54
+ * whether add `All` item in page length list
55
+ */
56
+ displayAll?: boolean = false
57
+
58
+ $emit(eventName: 'input'): this
59
+ /**
60
+ * page change event
61
+ * @param eventName
62
+ */
63
+ $emit(eventName: 'page-change'): this
64
+ }
65
+
66
+ export { Page }
67
+
68
+ export default Page
69
+ }
package/.babelrc DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "presets": [
3
- ["env", { "modules": false }],
4
- "stage-3"
5
- ]
6
- }
package/.editorconfig DELETED
@@ -1,9 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- indent_style = space
6
- indent_size = 2
7
- end_of_line = lf
8
- insert_final_newline = true
9
- trim_trailing_whitespace = true
package/src/Page.js DELETED
@@ -1,232 +0,0 @@
1
- import './page.scss';
2
- import languages from './language';
3
-
4
- const FIRST = 1;
5
-
6
- export default {
7
- name: "v-page",
8
- props: {
9
- value: {
10
- type: Number,
11
- default: 0
12
- },
13
- totalRow: {
14
- type: Number,
15
- default: 0
16
- },
17
- /**
18
- * page size list
19
- * false: close page size menu bar
20
- * array: custom page sizes menu
21
- */
22
- pageSizeMenu: {
23
- type: [Boolean, Array],
24
- default: function () {
25
- return [10, 20, 50, 100];
26
- }
27
- },
28
- language: {
29
- type: String,
30
- default: 'cn'
31
- },
32
- /**
33
- * pagination alignment direction
34
- * 'left'
35
- * 'center'
36
- * 'right'(default)
37
- */
38
- align: {
39
- type: String,
40
- default: 'right'
41
- },
42
- disabled: {
43
- type: Boolean,
44
- default: false
45
- },
46
- border: {
47
- type: Boolean,
48
- default: true
49
- },
50
- info: {
51
- type: Boolean,
52
- default: true
53
- },
54
- pageNumber: {
55
- type: Boolean,
56
- default: true
57
- },
58
- /**
59
- * first page button
60
- */
61
- first: {
62
- type: Boolean,
63
- default: true
64
- },
65
- /**
66
- * last page button
67
- */
68
- last: {
69
- type: Boolean,
70
- default: true
71
- }
72
- },
73
- data() {
74
- return {
75
- pageSize: this.pageSizeMenu === false ? 10 : this.pageSizeMenu[0],
76
- lastPageSize: -1,
77
- currentPage: 0,
78
- pageNumberSize: 5,
79
- i18n: languages[this.language] || languages['cn']
80
- };
81
- },
82
- computed: {
83
- totalPage(){
84
- return Math.ceil(this.totalRow / this.pageSize);
85
- },
86
- pageNumbers() {
87
- let start = 1, end, half = Math.floor(this.pageNumberSize / 2);
88
- if (this.totalPage < this.pageNumberSize) end = this.totalPage;
89
- else if (this.currentPage <= half) end = this.pageNumberSize;
90
- else if (this.currentPage >= (this.totalPage - half)) {
91
- start = this.totalPage - this.pageNumberSize + 1;
92
- end = this.totalPage;
93
- } else {
94
- start = this.currentPage - half;
95
- end = start + this.pageNumberSize - 1;
96
- }
97
-
98
- return Array.apply(null, {length:end-start+1}).map((val,index)=>start+index);
99
- },
100
- pageInfo() {
101
- return this.i18n.pageInfo.replace('#pageNumber#', this.currentPage)
102
- .replace('#totalPage#', this.totalPage)
103
- .replace('#totalRow#', this.totalRow);
104
- },
105
- classes(){
106
- return {
107
- 'v-pagination--no-border': !this.border,
108
- 'v-pagination--right': this.align === 'right',
109
- 'v-pagination--center': this.align === 'center',
110
- 'v-pagination--disabled': this.disabled
111
- };
112
- },
113
- isFirst(){
114
- return this.currentPage === FIRST;
115
- },
116
- isLast(){
117
- return this.currentPage === this.totalPage;
118
- }
119
- },
120
- watch: {
121
- value(val){
122
- if(typeof val === 'number' && val > 0) this.goPage(val, false);
123
- }
124
- },
125
- render(h){
126
- const items = [];
127
- //page length list
128
- if(Array.isArray(this.pageSizeMenu) && this.pageSizeMenu.length){
129
- items.push(h('li',{class:'v-pagination__list'},[h('a',[
130
- h('span',this.i18n.pageLength),
131
- h('select',{
132
- attrs:{disabled: this.disabled},
133
- on:{
134
- change: e => {
135
- if(e.srcElement && e.srcElement.value){
136
- this.pageSize = Number(e.srcElement.value);
137
- }
138
- this.goPage();
139
- }
140
- }
141
- },this.pageSizeMenu.map(val=>{
142
- return h('option',{attrs:{value:val}},val);
143
- }))
144
- ])]));
145
- }
146
- //page info
147
- if(this.info){
148
- items.push(h('li',{class:'v-pagination__info'},[h('a', this.pageInfo)]));
149
- }
150
- /**
151
- * page number generator
152
- * @param classes
153
- * @param num
154
- * @param text
155
- * @return VNode
156
- */
157
- const genItem = (classes, num, text) => {
158
- return h('li',{class:classes},[
159
- h('a',{
160
- attrs:{href:'javascript:void(0);'},
161
- on:{click:()=>this.switchPage(num)}
162
- }, text)
163
- ]);
164
- };
165
- //first
166
- if(this.first){
167
- items.push(genItem({disabled:this.isFirst}, 'first', this.i18n.first));
168
- }
169
- //previous
170
- items.push(genItem({disabled:this.isFirst}, 'previous', this.i18n.previous));
171
- //page numbers
172
- if(this.pageNumber){
173
- this.pageNumbers.forEach(val => {
174
- items.push(genItem({active:val === this.currentPage}, val, val));
175
- });
176
- }
177
- //next
178
- items.push(genItem({disabled:this.isLast}, 'next', this.i18n.next));
179
- //last
180
- if(this.last){
181
- items.push(genItem({disabled:this.isLast}, 'last', this.i18n.last));
182
- }
183
- return h('div',{
184
- class:{
185
- 'v-pagination': true,
186
- ...this.classes
187
- }
188
- },[h('ul', items)]);
189
- },
190
- methods: {
191
- goPage(pNum = FIRST, respond = true) {
192
- if(typeof pNum !== 'number') return;
193
- let num = pNum < FIRST ? FIRST : pNum;
194
- if(pNum > this.totalPage && this.totalPage > 0) num = this.totalPage;
195
-
196
- //exit when duplicate operation
197
- if(num === this.currentPage && this.pageSize === this.lastPageSize) return;
198
-
199
- this.currentPage = num;
200
- // update v-model value
201
- if(respond) this.$emit('input', this.currentPage);
202
- this.lastPageSize = this.pageSize;
203
- this.change();
204
- },
205
- reload(){
206
- this.change();
207
- },
208
- change(){
209
- this.$emit('page-change', {
210
- pageNumber: this.currentPage,
211
- pageSize: Number(this.pageSize)
212
- });
213
- },
214
- position(target){
215
- if (typeof target === 'string') {
216
- switch (target) {
217
- case 'first': return FIRST;
218
- case 'previous': return this.currentPage - 1;
219
- case 'next': return this.currentPage + 1;
220
- case 'last': return this.totalPage;
221
- }
222
- } else if (typeof target === 'number') return target;
223
- },
224
- switchPage(target) {
225
- if (this.disabled) return;
226
- this.goPage(this.position(target));
227
- }
228
- },
229
- mounted() {
230
- this.goPage(this.value ? this.value : FIRST);
231
- }
232
- }
package/src/index.js DELETED
@@ -1,21 +0,0 @@
1
- import vPage from './Page';
2
-
3
- const Plugin = {
4
- install(Vue, options = {}){
5
- if(Object.keys(options).length){
6
- if(options.language) vPage.props.language.default = options.language;
7
- if(options.align) vPage.props.align.default = options.align;
8
- if(typeof options.info === 'boolean') vPage.props.info.default = options.info;
9
- if(typeof options.border === 'boolean') vPage.props.border.default = options.border;
10
- if(typeof options.pageNumber === 'boolean') vPage.props.pageNumber.default = options.pageNumber;
11
- if(typeof options.first === 'boolean') vPage.props.first.default = options.first;
12
- if(typeof options.last === 'boolean') vPage.props.last.default = options.last;
13
- if(typeof options.pageSizeMenu !== 'undefined')
14
- vPage.props.pageSizeMenu.default = options.pageSizeMenu;
15
- }
16
- Vue.component(vPage.name, vPage);
17
- }
18
- };
19
-
20
- export {vPage};
21
- export default Plugin;
package/src/language.js DELETED
@@ -1,28 +0,0 @@
1
- const languages = {
2
- cn: {
3
- pageLength: '每页记录数 ',
4
- pageInfo: `当前显示第 #pageNumber# / #totalPage# 页(共#totalRow#条记录)`,
5
- first: '首页',
6
- previous: '«',
7
- next: '»',
8
- last: '尾页'
9
- },
10
- en: {
11
- pageLength: 'Page length ',
12
- pageInfo: 'Current #pageNumber# / #totalPage# (total #totalRow# records)',
13
- first: 'First',
14
- previous: '«',
15
- next: '»',
16
- last: 'Last'
17
- },
18
- jp: {
19
- pageLength: 'ページごとの記録数',
20
- pageInfo: '現在の第 #pageNumber# / #totalPage# ページ(全部で #totalRow# 条の記録)',
21
- first: 'トップページ',
22
- previous: '«',
23
- next: '»',
24
- last: '尾のページ'
25
- }
26
- };
27
-
28
- export default languages;
package/src/page.scss DELETED
@@ -1,112 +0,0 @@
1
- $borderRadius: 2px;
2
- @mixin disabled {
3
- color: #999;cursor: default;
4
- &:hover { color: #999;background-color: white;box-shadow: none;z-index: auto; }
5
- }
6
- @mixin vendor-prefix($name, $value) {
7
- @each $vendor in ('-webkit-', '-moz-', '-ms-', '-o-', '') {
8
- #{$vendor}#{$name}: #{$value};
9
- }
10
- }
11
-
12
- div.v-pagination {
13
- margin: 0;display: block;
14
-
15
- &.v-pagination--right { text-align: right; }
16
- &.v-pagination--center { text-align: center; }
17
- &.v-pagination--disabled {
18
- li {
19
- a { @include disabled; }
20
- &.active a { background-color: #f6f6f6; }
21
- }
22
- }
23
-
24
- & > ul {
25
- display: inline-block;
26
- list-style: none;
27
- margin: 0;
28
- padding: 0;
29
- @include vendor-prefix('box-shadow', 0 1px 2px rgba(0, 0, 0, 0.05));
30
-
31
- & > li {
32
- text-align: center;margin: 0;display: inline;
33
-
34
- & > a {
35
- margin: 0 0 0 -1px;
36
- position: relative;
37
- border: 1px solid #DEE2E6;
38
- padding: 6px 12px;
39
- line-height: 1.43;
40
- box-shadow: none;
41
- background-color: white;
42
- font-size: 14px;
43
- display: inline-block;
44
- text-decoration: none;
45
- color: #333;
46
- @include vendor-prefix('transition', all .5s cubic-bezier(.175, .885, .32, 1));
47
-
48
- &:hover {
49
- z-index: 2;
50
- @include vendor-prefix('box-shadow', 0 0 8px rgba(0, 0, 0, 0.2));
51
- }
52
- }
53
-
54
- &.disabled > a,
55
- &.v-pagination__list > a,
56
- &.v-pagination__info > a { @include disabled; }
57
-
58
- &.active > a {
59
- cursor: default;color: #999;background-color: #eee;
60
- &:hover { box-shadow: none;z-index: auto; }
61
- }
62
-
63
- &:first-child > a {
64
- border-left-width: 1px;
65
- @include vendor-prefix('border-bottom-left-radius', $borderRadius);
66
- @include vendor-prefix('border-top-left-radius', $borderRadius);
67
- }
68
-
69
- &:last-child > a {
70
- @include vendor-prefix('border-top-right-radius', $borderRadius);
71
- @include vendor-prefix('border-bottom-right-radius', $borderRadius);
72
- }
73
-
74
- &.v-pagination__list {
75
- select {
76
- margin-left: 5px;
77
- width: auto !important;
78
- font-size: 12px;
79
- padding: 0;
80
- border: 1px solid #ccc;
81
- color: #333;
82
- outline: 0;
83
-
84
- &:hover {
85
- @include vendor-prefix('box-shadow', 0 0 2px rgba(0, 0, 0, 0.2));
86
- }
87
-
88
- &[disabled] { color: #999; }
89
- }
90
- }
91
- }
92
- }
93
-
94
- &.v-pagination--no-border {
95
- & > ul {
96
- box-shadow: none;
97
-
98
- & > li {
99
- &:not(.active):not(.disabled):not(.v-pagination__info):not(.v-pagination__list) a:hover {
100
- box-shadow: none;z-index: auto;background-color: #ddd;
101
- }
102
-
103
- &.active a { background-color: #f6f6f6;color: #aaa; }
104
-
105
- & > a {
106
- border: 0;
107
- &:hover { z-index: auto; }
108
- }
109
- }
110
- }
111
- }
112
- }