完成90%页面分页组件的抽取

This commit is contained in:
2026-03-17 09:01:11 +08:00
parent 7e814d349e
commit 7211fcdfea
29 changed files with 2331 additions and 539 deletions

View File

@@ -29,7 +29,7 @@
<view class="th" style="flex: 2;">操作</view>
</view>
<view class="table-body">
<view v-for="item in verifierList" :key="item.id" class="tr">
<view v-for="item in pagedList" :key="item.id" class="tr">
<view class="td" style="flex: 1;">{{ item.id }}</view>
<view class="td" style="flex: 1.5;">
<image class="avatar" :src="item.avatar" mode="aspectFill" />
@@ -48,12 +48,29 @@
</view>
</view>
</view>
<CommonPagination
v-if="total > 0"
:total="total"
:loading="false"
:currentPage="currentPage"
:pageSize="pageSize"
:pageSizeOptionLabels="pageSizeOptionLabels"
:pageSizeIndex="pageSizeIndex"
:visiblePages="visiblePages"
:totalPage="totalPage"
:jumpPageInput="jumpPageInput"
@page-size-change="handlePageSizeChange"
@page-change="handlePageChange"
@update:jumpPageInput="(val: string) => { jumpPageInput.value = val }"
@jump-page="handleJumpPage"
/>
</view>
</view>
</template>
<script setup lang="uts">
import { ref, reactive } from 'vue'
import { ref, computed } from 'vue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
const stationRange = ['所有', '提货点222', '美东科技']
const stationText = ref('请选择')
@@ -68,9 +85,63 @@ type VerifierItem = {
status: boolean
}
const verifierList = reactive<VerifierItem[]>([
// ========== MOCK DATA START ==========
// TODO: 接真实接口时替换此处 verifierList 为 fetchVerifierList() 调用
const verifierList = ref<VerifierItem[]>([
{ id: 113, avatar: '/static/logo.png', wechatName: '林小星', name: '13800000001', station: '提货点222', addTime: '2025-11-01 09:00:00', status: true },
{ id: 112, avatar: '/static/logo.png', wechatName: '吴明', name: '13800000002', station: '美东科技', addTime: '2025-10-30 10:20:00', status: true },
{ id: 111, avatar: '/static/logo.png', wechatName: '赵姐', name: '13800000003', station: '提货点222', addTime: '2025-10-29 11:40:00', status: false },
{ id: 110, avatar: '/static/logo.png', wechatName: '高先', name: '13800000004', station: '美东科技', addTime: '2025-10-28 08:30:00', status: true },
{ id: 109, avatar: '/static/logo.png', wechatName: '孙明', name: '13800000005', station: '提货点222', addTime: '2025-10-27 14:00:00', status: true },
{ id: 108, avatar: '/static/logo.png', wechatName: '周波', name: '13800000006', station: '美东科技', addTime: '2025-10-26 16:10:00', status: true },
{ id: 107, avatar: '/static/logo.png', wechatName: '郑军', name: '13800000007', station: '提货点222', addTime: '2025-10-25 09:50:00', status: false },
{ id: 106, avatar: '/static/logo.png', wechatName: '谢婷', name: '13800000008', station: '美东科技', addTime: '2025-10-24 13:20:00', status: true },
{ id: 105, avatar: '/static/logo.png', wechatName: '谢军', name: '13800000009', station: '提货点222', addTime: '2025-10-23 11:00:00', status: true },
{ id: 104, avatar: '/static/logo.png', wechatName: '马芳', name: '13800000010', station: '美东科技', addTime: '2025-10-22 12:30:00', status: true },
{ id: 103, avatar: '/static/logo.png', wechatName: '李迪', name: '13800000011', station: '提货点222', addTime: '2025-10-21 10:00:00', status: false },
{ id: 102, avatar: '/static/logo.png', wechatName: '张玉', name: '13800000012', station: '美东科技', addTime: '2025-10-20 15:40:00', status: true },
{ id: 101, avatar: '/static/logo.png', wechatName: '王海', name: '13800000013', station: '提货点222', addTime: '2025-10-19 08:20:00', status: true },
{ id: 100, avatar: '/static/logo.png', wechatName: '刘云', name: '13800000014', station: '美东科技', addTime: '2025-10-18 09:10:00', status: true },
{ id: 99, avatar: '/static/logo.png', wechatName: '陈山', name: '13800000015', station: '提货点222', addTime: '2025-10-17 11:30:00', status: false },
{ id: 98, avatar: '/static/logo.png', wechatName: '吴州', name: '13800000016', station: '美东科技', addTime: '2025-10-16 14:50:00', status: true },
{ id: 97, avatar: '/static/logo.png', wechatName: '魏桂', name: '13800000017', station: '提货点222', addTime: '2025-10-15 10:20:00', status: true },
{ id: 96, avatar: '/static/logo.png', wechatName: '彭冬', name: '13800000018', station: '美东科技', addTime: '2025-10-14 16:00:00', status: true },
{ id: 95, avatar: '/static/logo.png', wechatName: '夏迪', name: '13800000019', station: '提货点222', addTime: '2025-10-23 10:45:07', status: true },
{ id: 94, avatar: '/static/logo.png', wechatName: '地球人', name: '15920014197', station: '美东科技', addTime: '2025-10-22 10:33:07', status: true }
])
// ========== MOCK DATA END ==========
// ========== PAGINATION STATE ==========
const currentPage = ref(1)
const pageSize = ref(15)
const jumpPageInput = ref('')
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 total = computed(() => verifierList.value.length)
const totalPage = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
const pagedList = computed(() => {
const start = (currentPage.value - 1) * pageSize.value
return verifierList.value.slice(start, start + pageSize.value)
})
const visiblePages = computed((): number[] => {
const t = totalPage.value; const cur = currentPage.value
if (t <= 7) return Array.from({ length: t }, (_: any, i: number) => i + 1)
if (cur <= 4) return [1, 2, 3, 4, 5, -1, t]
if (cur >= t - 3) return [1, -1, t - 4, t - 3, t - 2, t - 1, t]
return [1, -1, cur - 1, cur, cur + 1, -1, t]
})
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.value)
if (!isNaN(p) && p >= 1 && p <= totalPage.value) currentPage.value = p
}
// ========== END PAGINATION STATE ==========
function onStationChange(e: any) {
const index = parseInt(e.detail.value.toString())