BigW Consortium Gitlab

Commit 39a8f1aa by Regis

regex for number check

parent 4dd82e1d
...@@ -9,9 +9,14 @@ ...@@ -9,9 +9,14 @@
'pagenum', 'pagenum',
], ],
methods: { methods: {
pagenumberstatus(n) { pagestatus(n) {
if (n - 1 === +this.pagenum) return 'active'; if (n - 1 === +this.pagenum) return true;
return ''; return false;
},
prevstatus(index) {
if (index > 0) return false;
if (+this.pagenum < 2) return true;
return false;
}, },
createSection(n) { return Array.from(Array(n)).map((e, i) => i); }, createSection(n) { return Array.from(Array(n)).map((e, i) => i); },
}, },
...@@ -22,7 +27,7 @@ ...@@ -22,7 +27,7 @@
const pages = this.createSection(+this.last + 1); const pages = this.createSection(+this.last + 1);
pages.shift(); pages.shift();
if (+this.pagenum !== 1) items.push({ text: 'Prev' }); items.push({ text: 'Prev', class: this.prevstatus() });
pages.forEach(i => items.push({ text: i })); pages.forEach(i => items.push({ text: i }));
...@@ -34,8 +39,8 @@ ...@@ -34,8 +39,8 @@
}, },
template: ` template: `
<div class="gl-pagination"> <div class="gl-pagination">
<ul class="pagination clearfix" v-for='(item, index) in getItems'> <ul class="pagination clearfix" v-for='(item, i) in getItems'>
<li :class='pagenumberstatus(index + 1)'> <li :class="{active: pagestatus(i + 1), disabled: prevstatus(i)}">
<span @click='changepage($event, last)'>{{item.text}}</span> <span @click='changepage($event, last)'>{{item.text}}</span>
</li> </li>
</ul> </ul>
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
}, },
changepage(event, last) { changepage(event, last) {
const text = event.target.innerText; const text = event.target.innerText;
if (typeof text === 'number') this.pagenum = +text; if (/^-?[\d.]+(?:e-?\d+)?$/.test(text)) this.pagenum = +text;
if (text === 'Last »') this.pagenum = last; if (text === 'Last »') this.pagenum = last;
if (text === 'Next') this.pagenum = +this.pagenum + 1; if (text === 'Next') this.pagenum = +this.pagenum + 1;
if (text === 'Prev') this.pagenum = +this.pagenum - 1; if (text === 'Prev') this.pagenum = +this.pagenum - 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment