@tak-ps/vue-tabler 3.5.0 → 3.6.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/CHANGELOG.md +4 -0
- package/components/Pager.vue +122 -0
- package/lib.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class='pagination m-0 ms-auto'>
|
|
3
|
+
<div>
|
|
4
|
+
<template v-if='parseInt(total) <= parseInt(limit)'>
|
|
5
|
+
<button @click='page(0)' class='btn mx-1' >
|
|
6
|
+
<HomeIcon class='icon'/>Home
|
|
7
|
+
</button>
|
|
8
|
+
</template>
|
|
9
|
+
<template v-else>
|
|
10
|
+
<button @click='page(0)' class='btn mx-1' :class='{ "btn-primary": current === 0 }'>
|
|
11
|
+
<HomeIcon class='icon'/>Home
|
|
12
|
+
</button>
|
|
13
|
+
|
|
14
|
+
<template v-if='end > 5 && current > 3'>
|
|
15
|
+
<span class=''> ... </span>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<template v-if='parseInt(total) / parseInt(limit) > 2'>
|
|
19
|
+
<button
|
|
20
|
+
:key=i
|
|
21
|
+
v-for='i in middle'
|
|
22
|
+
@click='page(i)'
|
|
23
|
+
class='btn mx-1'
|
|
24
|
+
v-text='i + 1'
|
|
25
|
+
:class='{ "btn-primary": current === i }'
|
|
26
|
+
>
|
|
27
|
+
</button>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<template v-if='end > 5 && current < end - spread'>
|
|
31
|
+
<span class=''> ... </span>
|
|
32
|
+
</template>
|
|
33
|
+
<button
|
|
34
|
+
@click='page(end - 1)'
|
|
35
|
+
class='btn mx-1'
|
|
36
|
+
v-text='end'
|
|
37
|
+
:class='{ "btn-primary": current === end - 1 }'
|
|
38
|
+
></button>
|
|
39
|
+
</template>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script>
|
|
45
|
+
import {
|
|
46
|
+
HomeIcon
|
|
47
|
+
} from 'vue-tabler-icons';
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
name: 'TablerPager',
|
|
51
|
+
props: [ 'total', 'limit' ],
|
|
52
|
+
data: function() {
|
|
53
|
+
return this.create();
|
|
54
|
+
},
|
|
55
|
+
watch: {
|
|
56
|
+
total: function() {
|
|
57
|
+
const set = this.create();
|
|
58
|
+
|
|
59
|
+
this.spread = set.spread;
|
|
60
|
+
this.middle = set.middle;
|
|
61
|
+
this.current = set.current;
|
|
62
|
+
this.end = set.end;
|
|
63
|
+
},
|
|
64
|
+
limit: function() {
|
|
65
|
+
const set = this.create();
|
|
66
|
+
|
|
67
|
+
this.spread = set.spread;
|
|
68
|
+
this.middle = set.middle;
|
|
69
|
+
this.current = set.current;
|
|
70
|
+
this.end = set.end;
|
|
71
|
+
},
|
|
72
|
+
current: function() {
|
|
73
|
+
if (this.end < 5) return; // All buttons are shown already
|
|
74
|
+
|
|
75
|
+
let start;
|
|
76
|
+
if (this.current <= 3) {
|
|
77
|
+
start = 0;
|
|
78
|
+
} else if (this.current >= this.end - 4) {
|
|
79
|
+
start = this.end - this.spread - 2;
|
|
80
|
+
} else {
|
|
81
|
+
start = this.current - 3;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.middle = this.middle.map((ele, i) => {
|
|
85
|
+
return start + i + 1;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
methods: {
|
|
90
|
+
create: function() {
|
|
91
|
+
const end = Math.ceil(parseInt(this.total) / parseInt(this.limit));
|
|
92
|
+
let spread; //Number of pages in between home button and last page
|
|
93
|
+
if (end <= 2) {
|
|
94
|
+
spread = 0;
|
|
95
|
+
} else if (end >= 7) {
|
|
96
|
+
spread = 5;
|
|
97
|
+
} else {
|
|
98
|
+
spread = end - 2;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Array containing middle page number
|
|
102
|
+
let middleAr = new Array(spread).fill(1, 0, spread).map((ele, i) => {
|
|
103
|
+
return 1 + i;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
spread: spread,
|
|
108
|
+
middle: middleAr,
|
|
109
|
+
current: 0,
|
|
110
|
+
end: end
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
page: function(page) {
|
|
114
|
+
this.current = page;
|
|
115
|
+
this.$emit('page', this.current);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
components: {
|
|
119
|
+
HomeIcon
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
</script>
|
package/lib.js
CHANGED