Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Component separation
  • Loading branch information
MarkXiLee authored May 6, 2022
commit 732ae1b96cda5a43d2d8dd105396092c8de68d94
110 changes: 110 additions & 0 deletions client/src/components/Pagination.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<template>
<div class="row align-items-center justify-content-center bg-light">
<ul class="pagination text-center">
<li class="page-item" @click="previousPage">
<a class="page-link" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">Previous</span>
</a>
</li>
<li
v-for="pageIndex in range"
:key="pageIndex"
:class="{ 'page-item': true, active: pageIndex + startPage == page }"
>
<a class="page-link" @click="page = pageIndex + startPage">{{
pageIndex + startPage
}}</a>
</li>
<li
:class="{ 'page-item': true, disabled: page == pages }"
@click="nextPage"
>
<a class="page-link" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</div>
</template>

<script>
export default {
name: "Pagination",
props: {
pages: {
type: Number,
required: true
}
},
data() {
return {
range: 11,
page: 1,
timer: null
};
},
methods: {
previousPage() {
this.page -= 1;
if (this.page < 1) {
this.page = 1;
}
//this.$emit('fun','previous');
},
nextPage() {
this.page += 1;
if (this.page > this.pages) {
this.page = this.pages;
}
//this.$emit('fun','next');
}
},
watch: {
page(newPage, oldPage) {
if (newPage === oldPage) return;
if(oldPage>newPage)
{
this.$emit('fun','previous','down',oldPage-newPage);
}
if(oldPage<newPage)
{
this.$emit('fun','next','down',newPage-oldPage);
}
clearTimeout(this.timer);
this.timer = setTimeout(() => this.$emit("pagechange", this.page), 0);
}
},
computed: {
startPage() {
if (this.range > this.pages) {
return 0;
}

let range = Math.round(this.range / 2);
let start = this.page - range;

if (start < 0) return 0;

if (start > this.pages || start + this.range > this.pages) {
return this.pages - this.range;
}

return start;
}
},
created() {
if (this.range > this.pages) {
this.range = this.pages;
}
}
};
</script>

<style>
.page {
display: block;
margin: 0 auto;
}
</style>
111 changes: 111 additions & 0 deletions client/src/components/PaginationCopy.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<template>
<div class="row align-items-center justify-content-center bg-light">
<ul class="pagination text-center">
<li class="page-item" @click="previousPage">
<a class="page-link" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">Previous</span>
</a>
</li>
<li
v-for="pageIndex in range"
:key="pageIndex"
:class="{ 'page-item': true, active: pageIndex + startPage == page }"
>
<a class="page-link" @click="page = pageIndex + startPage">{{
pageIndex + startPage
}}</a>
</li>
<li
:class="{ 'page-item': true, disabled: page == pages }"
@click="nextPage" ref="upload"
>
<a class="page-link" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</div>
</template>

<script>
export default {
name: "PaginationCopy",
props: {
pages: {
type: Number,
required: true
}
},
data() {
return {
range: 11,
page: 1,
timer: null
};
},
methods: {
previousPage() {
this.page -= 1;
if (this.page < 1) {
this.page = 1;
}
},
nextPage() {
this.page += 1;
if (this.page > this.pages) {
this.page = this.pages;
}
}
},
watch: {
page(newPage, oldPage) {
if (newPage === oldPage) return;
if(this.$parent.pageSynchronous===1){
if(oldPage>newPage)
{
this.$emit('fun','previous','up',oldPage-newPage);
}
if(oldPage<newPage)
{
this.$emit('fun','next','up',newPage-oldPage);
}
}
else this.$emit('changePage');
clearTimeout(this.timer);
this.timer = setTimeout(() => this.$emit("pagechange", this.page), 0);
}
},
computed: {
startPage() {
if (this.range > this.pages) {
return 0;
}

let range = Math.round(this.range / 2);
let start = this.page - range;

if (start < 0) return 0;

if (start > this.pages || start + this.range > this.pages) {
return this.pages - this.range;
}

return start;
}
},
created() {
if (this.range > this.pages) {
this.range = this.pages;
}
}
};
</script>

<style>
.page {
display: block;
margin: 0 auto;
}
</style>