实现分页组件多页面替换

This commit is contained in:
2026-03-16 15:10:07 +08:00
parent 64b714a0eb
commit b449826758
7 changed files with 413 additions and 352 deletions

View File

@@ -76,31 +76,30 @@
</view> </view>
<!-- 分页 --> <!-- 分页 -->
<view class="pagination-footer"> <CommonPagination
<view class="page-total"> v-if="total > 0"
<text class="total-txt">共 {{ total }} 条</text> :total="total"
</view> :loading="false"
<view class="page-select"> :currentPage="currentPage"
<text class="page-val">15条/页 ▼</text> :pageSize="pageSize"
</view> :pageSizeOptionLabels="pageSizeOptionLabels"
<view class="page-btns"> :pageSizeIndex="pageSizeIndex"
<text class="p-btn disabled"><</text> :visiblePages="visiblePages"
<text class="p-btn active">1</text> :totalPage="totalPage"
<text class="p-btn">></text> :jumpPageInput="jumpPageInput"
</view> @page-size-change="handlePageSizeChange"
<view class="page-jump"> @page-change="handlePageChange"
<text class="jump-txt">前往</text> @update:jumpPageInput="(val : string) => { jumpPageInput = val }"
<input class="jump-input" placeholder="1" /> @jump-page="handleJumpPage"
<text class="jump-txt">页</text> />
</view>
</view>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { ref } from 'vue' import { ref, computed } from 'vue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
interface RefundOrder { interface RefundOrder {
id: number id: number
@@ -118,6 +117,50 @@ interface RefundOrder {
const searchQuery = ref('') const searchQuery = ref('')
const total = ref(11) const total = ref(11)
// 分页状态适配层
const currentPage = ref(1)
const pageSize = ref(15)
let jumpPageInput = ''
const pageSizeOptions = [10, 15, 20, 30, 50]
const pageSizeOptionLabels = computed((): string[] => pageSizeOptions.map((s: number): string => `${s} 条/页`))
const pageSizeIndex = computed((): number => {
const i = pageSizeOptions.indexOf(pageSize.value)
return i === -1 ? 0 : i
})
const totalPage = computed((): number => Math.ceil(total.value / pageSize.value))
const visiblePages = computed((): number[] => {
const cur = currentPage.value
const tot = totalPage.value
if (tot <= 7) {
const pages: number[] = []
for (let i = 1; i <= tot; i++) pages.push(i)
return pages
}
if (cur <= 4) return [1, 2, 3, 4, 5, -1, tot]
if (cur >= tot - 3) return [1, -1, tot - 4, tot - 3, tot - 2, tot - 1, tot]
return [1, -1, cur - 1, cur, cur + 1, -1, tot]
})
const handlePageChange = (p: number) => {
if (p < 1 || p > totalPage.value || p === currentPage.value) return
currentPage.value = p
jumpPageInput = ''
}
const handlePageSizeChange = (e: any) => {
let val = 0
if (typeof e.detail.value === 'string') val = parseInt(e.detail.value)
else val = e.detail.value as number
pageSize.value = pageSizeOptions[val]
currentPage.value = 1
}
const handleJumpPage = () => {
let jumpTo = parseInt(jumpPageInput)
if (isNaN(jumpTo)) return
if (jumpTo < 1) jumpTo = 1
if (jumpTo > totalPage.value) jumpTo = totalPage.value
jumpPageInput = String(jumpTo)
if (jumpTo !== currentPage.value) currentPage.value = jumpTo
}
const orderList = ref<RefundOrder[]>([ const orderList = ref<RefundOrder[]>([
{ {
id: 1, id: 1,
@@ -376,34 +419,7 @@ const handleQuery = () => { console.log('Querying...') }
.op-txt { font-size: 14px; } .op-txt { font-size: 14px; }
.op-arrow { font-size: 10px; } .op-arrow { font-size: 10px; }
/* 分页 */ /* 分页区域已迁至 CommonPagination 组件 */
.pagination-footer {
padding: 24px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
gap: 12px;
}
.total-txt { font-size: 14px; color: #606266; }
.page-val { font-size: 14px; color: #606266; border: 1px solid #dcdfe6; padding: 4px 10px; border-radius: 4px; }
.page-btns { display: flex; flex-direction: row; gap: 8px; }
.p-btn {
width: 32px;
height: 32px;
border: 1px solid #dcdfe6;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
}
.p-btn.active { background-color: #2d8cf0; border-color: #2d8cf0; color: #fff; }
.p-btn.disabled { color: #c0c4cc; background-color: #f5f7fa; }
.page-jump { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.jump-txt { font-size: 14px; color: #606266; }
.jump-input { width: 40px; height: 32px; border: 1px solid #dcdfe6; text-align: center; border-radius: 4px; font-size: 14px; }
</style> </style>

View File

@@ -58,24 +58,22 @@
</view> </view>
<!-- 分页 --> <!-- 分页 -->
<view class="pagination-footer"> <CommonPagination
<view class="page-total"> v-if="total > 0"
<text class="total-txt">共 {{ total }} 条</text> :total="total"
</view> :loading="false"
<view class="page-select"> :currentPage="currentPage"
<text class="page-val">15条/页 ▼</text> :pageSize="pageSize"
</view> :pageSizeOptionLabels="pageSizeOptionLabels"
<view class="page-btns"> :pageSizeIndex="pageSizeIndex"
<text class="p-btn disabled"><</text> :visiblePages="visiblePages"
<text class="p-btn active">1</text> :totalPage="totalPage"
<text class="p-btn">></text> :jumpPageInput="jumpPageInput"
</view> @page-size-change="handlePageSizeChange"
<view class="page-jump"> @page-change="handlePageChange"
<text class="jump-txt">前往</text> @update:jumpPageInput="(val : string) => { jumpPageInput = val }"
<input class="jump-input" placeholder="1" /> @jump-page="handleJumpPage"
<text class="jump-txt">页</text> />
</view>
</view>
</view> </view>
</view> </view>
@@ -104,7 +102,8 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { ref } from 'vue' import { ref, computed } from 'vue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
interface CashierOrder { interface CashierOrder {
orderId: string orderId: string
@@ -117,6 +116,50 @@ interface CashierOrder {
const orderId = ref('') const orderId = ref('')
const username = ref('') const username = ref('')
const total = ref(12) const total = ref(12)
// 分页状态适配层
const currentPage = ref(1)
const pageSize = ref(15)
let jumpPageInput = ''
const pageSizeOptions = [10, 15, 20, 30, 50]
const pageSizeOptionLabels = computed((): string[] => pageSizeOptions.map((s: number): string => `${s} 条/页`))
const pageSizeIndex = computed((): number => {
const i = pageSizeOptions.indexOf(pageSize.value)
return i === -1 ? 0 : i
})
const totalPage = computed((): number => Math.ceil(total.value / pageSize.value))
const visiblePages = computed((): number[] => {
const cur = currentPage.value
const tot = totalPage.value
if (tot <= 7) {
const pages: number[] = []
for (let i = 1; i <= tot; i++) pages.push(i)
return pages
}
if (cur <= 4) return [1, 2, 3, 4, 5, -1, tot]
if (cur >= tot - 3) return [1, -1, tot - 4, tot - 3, tot - 2, tot - 1, tot]
return [1, -1, cur - 1, cur, cur + 1, -1, tot]
})
const handlePageChange = (p: number) => {
if (p < 1 || p > totalPage.value || p === currentPage.value) return
currentPage.value = p
jumpPageInput = ''
}
const handlePageSizeChange = (e: any) => {
let val = 0
if (typeof e.detail.value === 'string') val = parseInt(e.detail.value)
else val = e.detail.value as number
pageSize.value = pageSizeOptions[val]
currentPage.value = 1
}
const handleJumpPage = () => {
let jumpTo = parseInt(jumpPageInput)
if (isNaN(jumpTo)) return
if (jumpTo < 1) jumpTo = 1
if (jumpTo > totalPage.value) jumpTo = totalPage.value
jumpPageInput = String(jumpTo)
if (jumpTo !== currentPage.value) currentPage.value = jumpTo
}
const orderList = ref<CashierOrder[]>([ const orderList = ref<CashierOrder[]>([
{ orderId: 'hy536720518414336000', userInfo: '东流 | 76058', payPrice: 1.00, discountPrice: 0.00, payTime: '2026-01-21 01:35:43' }, { orderId: 'hy536720518414336000', userInfo: '东流 | 76058', payPrice: 1.00, discountPrice: 0.00, payTime: '2026-01-21 01:35:43' },
{ orderId: 'hy529509398574268416', userInfo: '半个栗子 | 81997', payPrice: 10000.00, discountPrice: 0.00, payTime: '2026-01-01 04:01:18' }, { orderId: 'hy529509398574268416', userInfo: '半个栗子 | 81997', payPrice: 10000.00, discountPrice: 0.00, payTime: '2026-01-01 04:01:18' },
@@ -270,34 +313,7 @@ const closeQrModal = () => {
.td-txt { font-size: 14px; color: #515a6e; } .td-txt { font-size: 14px; color: #515a6e; }
/* 分页 */ /* 分页区域已迁至 CommonPagination 组件 */
.pagination-footer {
padding: 24px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
gap: 12px;
}
.total-txt { font-size: 14px; color: #606266; }
.page-val { font-size: 14px; color: #606266; border: 1px solid #dcdfe6; padding: 4px 10px; border-radius: 4px; }
.page-btns { display: flex; flex-direction: row; gap: 8px; }
.p-btn {
width: 32px;
height: 32px;
border: 1px solid #dcdfe6;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
}
.p-btn.active { background-color: #2d8cf0; border-color: #2d8cf0; color: #fff; }
.p-btn.disabled { color: #c0c4cc; background-color: #f5f7fa; }
.page-jump { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.jump-txt { font-size: 14px; color: #606266; }
.jump-input { width: 40px; height: 32px; border: 1px solid #dcdfe6; text-align: center; border-radius: 4px; font-size: 14px; }
/* Modal 弹窗逻辑 */ /* Modal 弹窗逻辑 */
.modal-mask { .modal-mask {

View File

@@ -190,24 +190,22 @@
</view> </view>
<!-- 分页 --> <!-- 分页 -->
<view class="pagination-footer"> <CommonPagination
<view class="page-left"> v-if="filteredOrders.length > 0 || loading"
<text class="count-text">共 {{ filteredOrders.length }} 条</text> :total="filteredOrders.length"
<view class="page-size-select"> :loading="loading"
<text>10条/页</text> :currentPage="currentPage"
<view class="arrow-down"></view> :pageSize="pageSize"
</view> :pageSizeOptionLabels="pageSizeOptionLabels"
</view> :pageSizeIndex="pageSizeIndex"
<view class="page-right"> :visiblePages="visiblePages"
<view class="page-btn disabled"><text></text></view> :totalPage="totalPage"
<view class="page-num active"><text>1</text></view> :jumpPageInput="jumpPageInput"
<view class="page-num"><text>2</text></view> @page-size-change="handlePageSizeChange"
<view class="page-num"><text>3</text></view> @page-change="handlePageChange"
<view class="page-btns-more"><text>...</text></view> @update:jumpPageInput="(val : string) => { jumpPageInput = val }"
<view class="page-num"><text>10</text></view> @jump-page="handleJumpPage"
<view class="page-btn"><text></text></view> />
</view>
</view>
</view> </view>
</view> </view>
@@ -223,11 +221,58 @@
import { ref, computed, onMounted } from 'vue' import { ref, computed, onMounted } from 'vue'
import { supabase } from '@/components/supadb/aksupainstance.uts' import { supabase } from '@/components/supadb/aksupainstance.uts'
import OrderDetailDrawer from './components/OrderDetailDrawer.uvue' import OrderDetailDrawer from './components/OrderDetailDrawer.uvue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
const activeTab = ref(0) const activeTab = ref(0)
const loading = ref(false) const loading = ref(false)
const searchKeyword = ref('') const searchKeyword = ref('')
// 分页状态适配层
const currentPage = ref(1)
const pageSize = ref(10)
let jumpPageInput = ''
const pageSizeOptions = [10, 20, 30, 50, 100]
const pageSizeOptionLabels = computed((): string[] => pageSizeOptions.map((s: number): string => `${s} 条/页`))
const pageSizeIndex = computed((): number => {
const i = pageSizeOptions.indexOf(pageSize.value)
return i === -1 ? 0 : i
})
const totalPage = computed((): number => Math.ceil(filteredOrders.value.length / pageSize.value))
const visiblePages = computed((): number[] => {
const cur = currentPage.value
const tot = totalPage.value
if (tot <= 7) {
const pages: number[] = []
for (let i = 1; i <= tot; i++) pages.push(i)
return pages
}
if (cur <= 4) return [1, 2, 3, 4, 5, -1, tot]
if (cur >= tot - 3) return [1, -1, tot - 4, tot - 3, tot - 2, tot - 1, tot]
return [1, -1, cur - 1, cur, cur + 1, -1, tot]
})
const handlePageChange = (p: number) => {
if (loading.value || p < 1 || p > totalPage.value || p === currentPage.value) return
currentPage.value = p
jumpPageInput = ''
}
const handlePageSizeChange = (e: any) => {
if (loading.value) return
let val = 0
if (typeof e.detail.value === 'string') val = parseInt(e.detail.value)
else val = e.detail.value as number
pageSize.value = pageSizeOptions[val]
currentPage.value = 1
}
const handleJumpPage = () => {
if (loading.value) return
let jumpTo = parseInt(jumpPageInput)
if (isNaN(jumpTo)) return
if (jumpTo < 1) jumpTo = 1
if (jumpTo > totalPage.value) jumpTo = totalPage.value
jumpPageInput = String(jumpTo)
if (jumpTo !== currentPage.value) currentPage.value = jumpTo
}
// Dropdown 状态 // Dropdown 状态
const activeDropdownId = ref('') const activeDropdownId = ref('')
const showDetail = ref(false) const showDetail = ref(false)
@@ -931,65 +976,6 @@ onMounted(() => {
border-bottom: 4px solid #1890ff; border-bottom: 4px solid #1890ff;
margin-bottom: 3px; margin-bottom: 3px;
} }
.pagination-footer {
padding: 16px 20px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.page-left {
display: flex;
flex-direction: row;
align-items: center;
gap: 16px;
.count-text { font-size: 14px; color: #595959; }
}
.page-size-select {
height: 28px;
padding: 0 10px;
border: 1px solid #d9d9d9;
border-radius: 4px;
display: flex;
flex-direction: row;
align-items: center;
gap: 8px;
text { font-size: 12px; color: #595959; }
}
.page-right {
display: flex;
flex-direction: row;
align-items: center;
gap: 8px;
}
.page-num, .page-btn, .page-btns-more {
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #d9d9d9;
border-radius: 4px;
text { font-size: 14px; color: #595959; }
cursor: pointer;
}
.page-num.active {
border-color: #1890ff;
text { color: #1890ff; }
}
.page-btn.disabled {
opacity: 0.4;
cursor: not-allowed;
}
.page-btns-more { border: none; }
.order-time { .order-time {
font-size: 12px; font-size: 12px;
color: #999; color: #999;

View File

@@ -74,31 +74,30 @@
</view> </view>
<!-- 分页 --> <!-- 分页 -->
<view class="pagination-footer"> <CommonPagination
<view class="page-total"> v-if="total > 0"
<text class="total-txt">共 {{ total }} 条</text> :total="total"
</view> :loading="false"
<view class="page-select"> :currentPage="currentPage"
<text class="page-val">15条/页 ▼</text> :pageSize="pageSize"
</view> :pageSizeOptionLabels="pageSizeOptionLabels"
<view class="page-btns"> :pageSizeIndex="pageSizeIndex"
<text class="p-btn disabled"><</text> :visiblePages="visiblePages"
<text class="p-btn active">1</text> :totalPage="totalPage"
<text class="p-btn">></text> :jumpPageInput="jumpPageInput"
</view> @page-size-change="handlePageSizeChange"
<view class="page-jump"> @page-change="handlePageChange"
<text class="jump-txt">前往</text> @update:jumpPageInput="(val : string) => { jumpPageInput = val }"
<input class="jump-input" placeholder="1" /> @jump-page="handleJumpPage"
<text class="jump-txt">页</text> />
</view>
</view>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { ref } from 'vue' import { ref, computed } from 'vue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
interface WriteOffRecord { interface WriteOffRecord {
orderId: string orderId: string
@@ -115,6 +114,50 @@ interface WriteOffRecord {
const searchQuery = ref('') const searchQuery = ref('')
const total = ref(10) const total = ref(10)
// 分页状态适配层
const currentPage = ref(1)
const pageSize = ref(15)
let jumpPageInput = ''
const pageSizeOptions = [10, 15, 20, 30, 50]
const pageSizeOptionLabels = computed((): string[] => pageSizeOptions.map((s: number): string => `${s} 条/页`))
const pageSizeIndex = computed((): number => {
const i = pageSizeOptions.indexOf(pageSize.value)
return i === -1 ? 0 : i
})
const totalPage = computed((): number => Math.ceil(total.value / pageSize.value))
const visiblePages = computed((): number[] => {
const cur = currentPage.value
const tot = totalPage.value
if (tot <= 7) {
const pages: number[] = []
for (let i = 1; i <= tot; i++) pages.push(i)
return pages
}
if (cur <= 4) return [1, 2, 3, 4, 5, -1, tot]
if (cur >= tot - 3) return [1, -1, tot - 4, tot - 3, tot - 2, tot - 1, tot]
return [1, -1, cur - 1, cur, cur + 1, -1, tot]
})
const handlePageChange = (p: number) => {
if (p < 1 || p > totalPage.value || p === currentPage.value) return
currentPage.value = p
jumpPageInput = ''
}
const handlePageSizeChange = (e: any) => {
let val = 0
if (typeof e.detail.value === 'string') val = parseInt(e.detail.value)
else val = e.detail.value as number
pageSize.value = pageSizeOptions[val]
currentPage.value = 1
}
const handleJumpPage = () => {
let jumpTo = parseInt(jumpPageInput)
if (isNaN(jumpTo)) return
if (jumpTo < 1) jumpTo = 1
if (jumpTo > totalPage.value) jumpTo = totalPage.value
jumpPageInput = String(jumpTo)
if (jumpTo !== currentPage.value) currentPage.value = jumpTo
}
const recordList = ref<WriteOffRecord[]>([ const recordList = ref<WriteOffRecord[]>([
{ {
orderId: 'cp470547161164021760', orderId: 'cp470547161164021760',
@@ -342,34 +385,7 @@ const handleQuery = () => { console.log('Searching...') }
overflow: hidden; overflow: hidden;
} }
/* 分页 */ /* 分页区域已迁至 CommonPagination 组件 */
.pagination-footer {
padding: 24px 0 0 0;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
gap: 12px;
}
.total-txt { font-size: 14px; color: #606266; }
.page-val { font-size: 14px; color: #606266; border: 1px solid #dcdfe6; padding: 4px 10px; border-radius: 4px; }
.page-btns { display: flex; flex-direction: row; gap: 8px; }
.p-btn {
width: 32px;
height: 32px;
border: 1px solid #dcdfe6;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
}
.p-btn.active { background-color: #2d8cf0; border-color: #2d8cf0; color: #fff; }
.p-btn.disabled { color: #c0c4cc; background-color: #f5f7fa; }
.page-jump { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.jump-txt { font-size: 14px; color: #606266; }
.jump-input { width: 40px; height: 32px; border: 1px solid #dcdfe6; text-align: center; border-radius: 4px; font-size: 14px; }
</style> </style>

View File

@@ -65,22 +65,23 @@ class="group-item"
</view> </view>
</view> </view>
<!-- 分页模拟 --> <!-- 分页 -->
<view class="table-pagination"> <CommonPagination
<text class="page-total">共 {{ filteredLabels.length }} 条</text> v-if="filteredLabels.length > 0"
<view class="page-size-selector"> :total="filteredLabels.length"
<text>15条/页</text> :loading="false"
<text class="arrow-down">v</text> :currentPage="currentPage"
</view> :pageSize="pageSize"
<view class="page-numbers"> :pageSizeOptionLabels="pageSizeOptionLabels"
<text class="page-btn active">1</text> :pageSizeIndex="pageSizeIndex"
</view> :visiblePages="visiblePages"
<view class="page-jump"> :totalPage="totalPage"
<text>前往</text> :jumpPageInput="jumpPageInput"
<input class="jump-input" :value="'1'" /> @page-size-change="handlePageSizeChange"
<text>页</text> @page-change="handlePageChange"
</view> @update:jumpPageInput="(val : string) => { jumpPageInput = val }"
</view> @jump-page="handleJumpPage"
/>
</view> </view>
</view> </view>
</view> </view>
@@ -114,6 +115,7 @@ class="group-item"
<script setup lang="uts"> <script setup lang="uts">
import { ref, reactive, computed } from 'vue' import { ref, reactive, computed } from 'vue'
import StatusSwitch from '@/components/StatusSwitch.uvue' import StatusSwitch from '@/components/StatusSwitch.uvue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
interface Label { interface Label {
id: number; id: number;
@@ -181,6 +183,36 @@ function deleteLabel(label: Label) {
const idx = labels.indexOf(label) const idx = labels.indexOf(label)
if (idx > -1) { labels.splice(idx, 1) } if (idx > -1) { labels.splice(idx, 1) }
} }
// 分页适配状态
const currentPage = ref(1)
const pageSize = ref(15)
let jumpPageInput = ''
const pageSizeOptions = [10, 15, 20, 30, 50]
const pageSizeOptionLabels = computed(() => pageSizeOptions.map((n: number) => `${n}条/页`))
const pageSizeIndex = computed(() => {
const idx = pageSizeOptions.indexOf(pageSize.value)
return idx >= 0 ? idx : 0
})
const totalPage = computed(() => Math.max(1, Math.ceil(filteredLabels.value.length / pageSize.value)))
const visiblePages = computed(() => {
const total = totalPage.value
const cur = currentPage.value
if (total <= 7) return Array.from({ length: total }, (_: any, i: number) => i + 1)
if (cur <= 4) return [1, 2, 3, 4, 5, -1, total]
if (cur >= total - 3) return [1, -1, total - 4, total - 3, total - 2, total - 1, total]
return [1, -1, cur - 1, cur, cur + 1, -1, total]
})
const handlePageChange = (p: number) => { currentPage.value = p }
const handlePageSizeChange = (e: any) => {
const idx = Number(e.detail.value)
pageSize.value = pageSizeOptions[idx] ?? pageSizeOptions[0]
currentPage.value = 1
}
const handleJumpPage = () => {
const p = parseInt(jumpPageInput)
if (!isNaN(p) && p >= 1 && p <= totalPage.value) currentPage.value = p
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@@ -315,62 +347,7 @@ font-size: 12px;
.btn-op-red { color: #ff4d4f; font-size: 14px; cursor: pointer; } .btn-op-red { color: #ff4d4f; font-size: 14px; cursor: pointer; }
.v-line { width: 1px; height: 12px; background-color: #eee; margin: 0 10px; } .v-line { width: 1px; height: 12px; background-color: #eee; margin: 0 10px; }
/* 分页 */ /* 分页区域已迁至 CommonPagination 组件 */
.table-pagination {
padding-top: 20px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
}
.page-total { font-size: 13px; color: #666; margin-right: 12px; }
.page-size-selector {
display: flex;
flex-direction: row;
align-items: center;
border: 1px solid #dcdfe6;
padding: 0 8px;
height: 28px;
border-radius: 4px;
margin-right: 12px;
}
.page-size-selector text { font-size: 12px; }
.arrow-down { margin-left: 5px; color: #999; }
.page-numbers { display: flex; flex-direction: row; margin-right: 12px; }
.page-btn {
width: 28px;
height: 28px;
line-height: 28px;
text-align: center;
border: 1px solid #dcdfe6;
border-radius: 4px;
font-size: 13px;
margin: 0 2px;
}
.page-btn.active { background-color: #1890ff; color: #fff; border-color: #1890ff; }
.page-jump {
display: flex;
flex-direction: row;
align-items: center;
font-size: 13px;
color: #666;
}
.jump-input {
width: 40px;
height: 28px;
border: 1px solid #dcdfe6;
border-radius: 4px;
text-align: center;
margin: 0 8px;
}
/* Drawer styles */ /* Drawer styles */
.drawer-mask { .drawer-mask {

View File

@@ -162,30 +162,82 @@
</view> </view>
<!-- 5. 分页 --> <!-- 5. 分页 -->
<view class="pagination-row"> <CommonPagination
<text class="total">共 {{ total }} 条</text> v-if="total > 0"
<view class="page-ctrl"> :total="total"
<text class="page-btn disabled">{"<"}</text> :loading="false"
<text class="page-num active">1</text> :currentPage="currentPage"
<text class="page-num">2</text> :pageSize="pageSize"
<text class="page-btn">{">"}</text> :pageSizeOptionLabels="pageSizeOptionLabels"
</view> :pageSizeIndex="pageSizeIndex"
</view> :visiblePages="visiblePages"
:totalPage="totalPage"
:jumpPageInput="jumpPageInput"
@page-size-change="handlePageSizeChange"
@page-change="handlePageChange"
@update:jumpPageInput="(val : string) => { jumpPageInput = val }"
@jump-page="handleJumpPage"
/>
</view> </view>
</template> </template>
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { ref, onMounted, onUnmounted, watch } from 'vue' import { ref, onMounted, onUnmounted, watch, computed } from 'vue'
import { openRoute } from '@/layouts/admin/store/adminNavStore.uts' import { openRoute } from '@/layouts/admin/store/adminNavStore.uts'
import StatusSwitch from '@/components/StatusSwitch.uvue' import StatusSwitch from '@/components/StatusSwitch.uvue'
import supa, { ensureSupabaseReady } from '@/components/supadb/aksupainstance' import supa, { ensureSupabaseReady } from '@/components/supadb/aksupainstance'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
const hasShop = ref(false) const hasShop = ref(false)
const shopLoading = ref(true) const shopLoading = ref(true)
const total = ref(0) const total = ref(0)
// 分页状态适配层
const currentPage = ref(1)
const pageSize = ref(10)
let jumpPageInput = ''
const pageSizeOptions = [10, 20, 30, 50, 100]
const pageSizeOptionLabels = computed((): string[] => pageSizeOptions.map((s: number): string => `${s} 条/页`))
const pageSizeIndex = computed((): number => {
const i = pageSizeOptions.indexOf(pageSize.value)
return i === -1 ? 0 : i
})
const totalPage = computed((): number => Math.ceil(total.value / pageSize.value))
const visiblePages = computed((): number[] => {
const cur = currentPage.value
const tot = totalPage.value
if (tot <= 7) {
const pages: number[] = []
for (let i = 1; i <= tot; i++) pages.push(i)
return pages
}
if (cur <= 4) return [1, 2, 3, 4, 5, -1, tot]
if (cur >= tot - 3) return [1, -1, tot - 4, tot - 3, tot - 2, tot - 1, tot]
return [1, -1, cur - 1, cur, cur + 1, -1, tot]
})
const handlePageChange = (p: number) => {
if (p < 1 || p > totalPage.value || p === currentPage.value) return
currentPage.value = p
jumpPageInput = ''
}
const handlePageSizeChange = (e: any) => {
let val = 0
if (typeof e.detail.value === 'string') val = parseInt(e.detail.value)
else val = e.detail.value as number
pageSize.value = pageSizeOptions[val]
currentPage.value = 1
}
const handleJumpPage = () => {
let jumpTo = parseInt(jumpPageInput)
if (isNaN(jumpTo)) return
if (jumpTo < 1) jumpTo = 1
if (jumpTo > totalPage.value) jumpTo = totalPage.value
jumpPageInput = String(jumpTo)
if (jumpTo !== currentPage.value) currentPage.value = jumpTo
}
const activeStatus = ref('selling') const activeStatus = ref('selling')
const activeDropdownId = ref<number | null>(null) const activeDropdownId = ref<number | null>(null)
@@ -689,34 +741,7 @@ function moveToRecycle(id: number) {
.arrow { font-size: 10px; color: #1890ff; margin-left: 2px; } .arrow { font-size: 10px; color: #1890ff; margin-left: 2px; }
} }
.pagination-row { /* 分页区域已迁至 CommonPagination 组件 */
padding: 24px;
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
gap: 16px;
.total { font-size: 13px; color: #606266; }
}
.page-ctrl {
display: flex;
flex-direction: row;
gap: 8px;
.page-num, .page-btn {
width: 32px;
height: 32px;
border: 1px solid #dcdfe6;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
font-size: 13px;
color: #606266;
&.active { background: #1890ff; color: #fff; border-color: #1890ff; }
&.disabled { color: #c0c4cc; background: #f5f7fa; }
}
}
</style> </style>

View File

@@ -83,20 +83,29 @@
</view> </view>
<!-- 分页 --> <!-- 分页 -->
<view class="pagination-row"> <CommonPagination
<text class="total">共 {{ replyList.length }} 条</text> v-if="replyList.length > 0"
<view class="page-ctrl"> :total="replyList.length"
<text class="page-btn disabled">{"<"}</text> :loading="false"
<text class="page-num active">1</text> :currentPage="currentPage"
<text class="page-btn">{">"}</text> :pageSize="pageSize"
</view> :pageSizeOptionLabels="pageSizeOptionLabels"
</view> :pageSizeIndex="pageSizeIndex"
:visiblePages="visiblePages"
:totalPage="totalPage"
:jumpPageInput="jumpPageInput"
@page-size-change="handlePageSizeChange"
@page-change="handlePageChange"
@update:jumpPageInput="(val : string) => { jumpPageInput = val }"
@jump-page="handleJumpPage"
/>
</view> </view>
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { ref } from 'vue' import { ref, computed } from 'vue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
const replyList = ref([ const replyList = ref([
{ {
@@ -136,6 +145,36 @@ const replyList = ref([
time: '2024-09-12 14:20:12' time: '2024-09-12 14:20:12'
} }
]) ])
// 分页适配状态
const currentPage = ref(1)
const pageSize = ref(10)
let jumpPageInput = ''
const pageSizeOptions = [10, 20, 30, 50]
const pageSizeOptionLabels = computed(() => pageSizeOptions.map((n: number) => `${n}条/页`))
const pageSizeIndex = computed(() => {
const idx = pageSizeOptions.indexOf(pageSize.value)
return idx >= 0 ? idx : 0
})
const totalPage = computed(() => Math.max(1, Math.ceil(replyList.value.length / pageSize.value)))
const visiblePages = computed(() => {
const total = totalPage.value
const cur = currentPage.value
if (total <= 7) return Array.from({ length: total }, (_: any, i: number) => i + 1)
if (cur <= 4) return [1, 2, 3, 4, 5, -1, total]
if (cur >= total - 3) return [1, -1, total - 4, total - 3, total - 2, total - 1, total]
return [1, -1, cur - 1, cur, cur + 1, -1, total]
})
const handlePageChange = (p: number) => { currentPage.value = p }
const handlePageSizeChange = (e: any) => {
const idx = Number(e.detail.value)
pageSize.value = pageSizeOptions[idx] ?? pageSizeOptions[0]
currentPage.value = 1
}
const handleJumpPage = () => {
const p = parseInt(jumpPageInput)
if (!isNaN(p) && p >= 1 && p <= totalPage.value) currentPage.value = p
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@@ -249,19 +288,5 @@ const replyList = ref([
} }
.op-link { font-size: 13px; color: #1890ff; margin: 0 4px; cursor: pointer; &.red { color: #f5222d; } } .op-link { font-size: 13px; color: #1890ff; margin: 0 4px; cursor: pointer; &.red { color: #f5222d; } }
/* 分页区域已迁至 CommonPagination 组件 */
.pagination-row {
padding: 24px; display: flex; flex-direction: row; justify-content: flex-end; align-items: center; gap: 16px;
.total { font-size: 13px; color: #606266; }
}
.page-ctrl {
display: flex; flex-direction: row; gap: 8px;
.page-num, .page-btn {
width: 32px; height: 32px; border: 1px solid #dcdfe6; border-radius: 4px;
display: flex; align-items: center; justify-content: center; font-size: 13px;
&.active { background: #1890ff; color: #fff; }
&.disabled { background: #f5f5f5; color: #ccc; }
}
}
</style> </style>