Browse Source

特殊的分页组件

pull/89/head
zq 3 days ago
parent
commit
d5d3021cd3
  1. 363
      src/components/Page.vue
  2. 29
      src/views/agent/checkOrderList.vue

363
src/components/Page.vue

@ -1,238 +1,279 @@
<template>
<div class="pagination">
<div class="pagination flex gap10">
<!-- 首页按钮 -->
<button
v-if="showHome"
@click="goToFirstPage"
class="pagination-button"
>
<GuipButton size="form" v-if="showFirstPage" @click="goToFirstPage" :disabled="page === 1">
首页
</button>
</GuipButton>
<!-- 上一页按钮 -->
<button
v-if="showPrev"
@click="goToPrevPage"
class="pagination-button"
>
<GuipButton size="form" v-if="showPrevPage" @click="goToPrevPage" :disabled="page === 1">
上一页
</button>
</GuipButton>
<!-- 当前页码显示 -->
<span v-if="showCurrent" class="current-page">{{ currentPage }}</span>
<!-- 当前页码 -->
<span v-if="showCurrentPage">{{ page }}</span>
<!-- 下一页按钮 -->
<button
v-if="showNext"
@click="goToNextPage"
class="pagination-button"
>
<GuipButton size="form" v-if="showNextPage" @click="goToNextPage" :disabled="!hasNextPage ">
下一页
</button>
<!-- 尾页按钮/状态 -->
<button
v-if="showLastButton"
@click="goToLastPage"
class="pagination-button"
>
</GuipButton>
<!-- 尾页按钮 -->
<GuipButton size="form" v-if="showLastPage" @click="goToLastPage">
尾页
</button>
<span v-if="showLastText" class="last-page">尾页</span>
<!-- 尾页时的页码显示 -->
<span v-if="endPageFlag" class="last-page-number">{{ totalPages }}</span>
<!-- 跳转控件 -->
<div class="page-jump">
<input
type="number"
v-model="jumpPage"
min="1"
class="jump-input"
>
<button @click="handleJump" class="jump-button">跳转</button>
</GuipButton>
<!-- 跳转输入 -->
<div class="page-jump flex gap10" v-if="showJump">
<input type="number" v-model.number="jumpPage" min="1" :max="totalPages">
<GuipButton size="form" @click="handleJump">跳转</GuipButton>
</div>
<!-- 尾页时的总记录数 -->
<span v-if="endPageFlag" class="total-records">{{ totalRecords }}条记录</span>
<!-- 总记录数 -->
<span v-if="showTotalRecords" class="total-records">{{ totalRecords }}条记录</span>
</div>
</template>
<script>
import GuipButton from '@/components/GuipButton.vue';
export default {
name: 'Pagination',
components:{GuipButton},
props: {
//
totalRecords: {
type: [Number,String],
required: true,
default: 0
},
//
totalPages: {
type: [Number,String],
required: true,
default: 1
},
//
currentPage: {
type: [Number,String],
required: true,
default: 1
},
// minid
nextMinId: {
type: [Number,String],
default: null
},
// maxid
prevMaxId: {
type: [Number,String],
default: null
// URL
apiUrl: {
type: String,
required: true
},
//
pageSize: {
type: Number,
default: 10
},
//
extraParams: {
type: Object,
default: () => ({})
}
},
data() {
return {
endPageFlag: false, //
jumpPage: null //
};
page: 1,
jumpPage: 1,
end_page:0,
hasNextPage: false,
minId: null,
maxId: null,
totalRecords: 0,
buttonType:'',
totalPages: 1,
isLoading: false,
token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NTAwNTM3MjQsIm5iZiI6MTc1MDA1MzcyNCwiZXhwIjoxNzUyNjQ1NzI0LCJ1c2VyIjoic3VidXNlciIsImxvZ2luX3R5cGUiOjAsImFpZCI6IjEifQ.xyIqBLelB-k6jCifgRevBJTyg_Qrm6m1e4OcHhOpepU',
}
},
computed: {
//
showHome() {
return this.currentPage > 1;
showFirstPage() {
return this.page > 2
},
//
showPrev() {
return this.currentPage > 1;
showPrevPage() {
return this.page > 1
},
//
showCurrent() {
return !this.endPageFlag;
showCurrentPage() {
return true
},
//
showNext() {
return !this.endPageFlag;
showNextPage() {
return this.hasNextPage
},
//
showLastButton() {
return !this.endPageFlag;
showLastPage() {
return !(this.end_page > 0) || this.hasNextPage
},
//
showJump() {
return true
},
//
showLastText() {
return this.endPageFlag;
//
showTotalRecords() {
return this.totalRecords > 0
}
},
created() {
this.fetchData()
},
methods: {
//
buildParams() {
const params = {
pagesize: this.pageSize,
page:this.page,
...this.extraParams
}
// maxidminid
if (this.page > 1) {
if (this.page === this.totalPages) {
//
params.maxid = this.maxId
} else {
//
if (this.buttonType == 'prev') {
params.maxid = this.maxId
} else {
params.minid = this.minId
}
}
}
if(this.end_page > 0){
delete params.page
delete params.maxid
delete params.minid
params.end_page = this.end_page
}else{
delete params.end_page
}
console.log(params,'params======');
return params
},
//
async fetchData() {
console.log('-----执行了');
this.isLoading = true
this.$emit('changeLoad',true)
try {
this.$http('POST', this.apiUrl, this.buildParams(), {
headers: {
'Auth': this.token
}
}).then(response => {
const data = response.data
this.hasNextPage = data.is_has_next_page
this.minId = data.minid || null
this.maxId = data.maxid || null
this.totalRecords = data.total_records || 0
if(this.totalRecords > 0){
//
this.totalPages = Math.ceil(this.totalRecords / this.pageSize)
this.page = this.totalPages || 1
this.jumpPage = this.page
}
//
this.$emit('update', data)
this.$emit('changeLoad',false)
})
} catch (error) {
console.error('分页请求失败:', error)
this.$emit('error', error)
this.$emit('changeLoad',false)
} finally {
this.isLoading = false
this.$emit('changeLoad',false)
}
},
//
goToFirstPage() {
this.endPageFlag = false;
this.$emit('page-change', {
page: 1,
isFirst: true
});
if (this.page === 1) return
this.page = 1
this.jumpPage = 1
this.end_page = 0;
this.buttonType = ''
this.fetchData()
},
//
goToPrevPage() {
this.endPageFlag = false;
this.$emit('page-change', {
page: this.currentPage - 1,
maxid: this.prevMaxId,
isPrev: true
});
if (this.page <= 1) return
this.page--
this.jumpPage = this.page
this.end_page = 0;
this.buttonType = 'prev'
this.fetchData()
},
//
goToNextPage() {
this.endPageFlag = false;
this.$emit('page-change', {
page: this.currentPage + 1,
minid: this.nextMinId,
isNext: true
});
if (!this.hasNextPage)return
this.page++
this.end_page = 0;
this.jumpPage = this.page
this.buttonType = 'next'
this.fetchData()
},
//
goToLastPage() {
this.endPageFlag = true;
this.$emit('page-change', {
page: this.totalPages,
isLast: true
});
// if (this.page === this.totalPages) return
// this.page = this.totalPages
// this.jumpPage = this.totalPages
this.end_page = 1;
this.buttonType = ''
this.fetchData()
},
//
handleJump() {
if (!this.jumpPage || this.jumpPage < 1) {
return;
}
if (this.totalPages > 0 && this.jumpPage > this.totalPages) {
return;
}
let page = parseInt(this.jumpPage)
this.endPageFlag = this.jumpPage === this.totalPages;
if (isNaN(page) || page < 1) {
page = 1
}
// else if (page > this.totalPages) {
// page = this.totalPages
// }
this.$emit('page-change', {
page: this.jumpPage,
isJump: true
});
if (page === this.page) return
this.jumpPage = null;
this.page = page
this.jumpPage = page
this.fetchData()
}
},
watch: {
apiUrl() {
this.page = 1
this.fetchData()
},
pageSize() {
this.page = 1
this.fetchData()
},
extraParams: {
deep: true,
handler() {
this.page = 1
this.fetchData()
}
}
}
};
}
</script>
<style scoped>
.pagination {
display: flex;
align-items: center;
gap: 8px;
margin-top: 20px;
flex-wrap: wrap;
justify-content: flex-end;
margin: 20px 0;
gap: 10px;
}
.pagination-button {
padding: 6px 12px;
border: 1px solid #ddd;
background: #f8f8f8;
border-radius: 4px;
cursor: pointer;
}
.pagination-button:hover {
background: #e8e8e8;
}
.current-page, .last-page, .last-page-number, .total-records {
padding: 0 8px;
font-size: 14px;
}
.page-jump {
display: flex;
gap: 4px;
}
.jump-input {
.page-jump input {
width: 50px;
padding: 4px;
padding: 5px;
border: 1px solid #ddd;
border-radius: 4px;
border-radius: 3px;
text-align: center;
}
.jump-button {
padding: 4px 8px;
border: 1px solid #ddd;
background: #f0f0f0;
border-radius: 4px;
cursor: pointer;
}
.jump-button:hover {
background: #e0e0e0;
.total-records {
margin-left: 10px;
color: #666;
}
</style>

29
src/views/agent/checkOrderList.vue

@ -36,7 +36,7 @@
<PromptText class="my-32" text='订单提示:电商订单,提交检测后会自动发货,请勿手动发货、代收款订单,退款须由平台操作,不可私自退款' :type="2" />
<GuipTable :tableData="orderList" ref="multipleTable" autoColumn="true" :loading="tableLoading">
<GuipTable :tableData="orderList" ref="multipleTable" autoColumn="true" :loading="tableLoading" max-height="400px">
<el-table-column prop="sitename" label="站点" fixed="left" min-width="60px">
<template slot-scope="scope">
<div class="flex">
@ -159,6 +159,13 @@
:next-min-id="orderListNextMinId"
:prev-max-id="orderListPrevMaxId"
@page-change="handlePageChange"></Page> -->
<Page
:api-url="'/agentnew/ajax_get_check_order_list'"
:page-size="10"
@update="handleUpdate"
@error="handleError"
@changeLoad="changeLoad"
/>
</el-form>
</div>
<GuipDialog :dialogVisible="dialogVisibleDelReport" title="删除报告" confirmText="删除" cancelText="取消" :show-close-button="false"
@ -178,7 +185,7 @@ import GuipSelect from '@/components/GuipSelect.vue';
import GuipInput from '@/components/GuipInput.vue';
import GuipToolTip from '@/components/GuipToolTip.vue';
import GuipDialog from '@/components/GuipDialog.vue';
// import Page from '@/components/Page.vue';
import Page from '@/components/Page.vue';
import PromptText from '@/components/PromptText.vue';
export default {
@ -189,7 +196,7 @@ export default {
GuipInput,
GuipToolTip,
GuipDialog,
// Page,
Page,
PromptText,
},
data() {
@ -220,12 +227,26 @@ export default {
dialogVisibleDelReport: false,
delReportId: '',
}
},
mounted() {
this.getOrderList()
// this.getOrderList()
},
methods: {
changeLoad(load){
this.tableLoading = load
},
handleUpdate(data) {
this.orderList = data.list;
this.searchStatusList = data.search_check_status
this.orderListTotalRecords = data.total_records
},
handleError(error) {
console.error('分页错误:', error)
//
},
getOrderList() {
var params = {
page: this.orderListCurrentPage,

Loading…
Cancel
Save