完成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

@@ -34,7 +34,7 @@
<view class="th" style="flex: 2;">操作</view>
</view>
<view class="table-body">
<view v-for="item in stationList" :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: 2;">
<image class="station-img" :src="item.image" mode="aspectFill" />
@@ -53,12 +53,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 searchKey = ref('')
@@ -72,10 +89,63 @@ type StationItem = {
isshow: boolean
}
const stationList = reactive<StationItem[]>([
{ id: 46, image: '/static/logo.png', name: '提货点222', phone: '13769102384', address: '能看见你的困难', hours: '00:00:00 - 23:00:00', isshow: true },
// ========== MOCK DATA START ==========
// TODO: 接真实接口时替换此处 stationList 为 fetchStationList() 调用
const stationList = ref<StationItem[]>([
{ id: 65, image: '/static/logo.png', name: '北京朝阳门提货点', phone: '13012340001', address: '北京市朝阳区建国路1号', hours: '09:00 - 21:00', isshow: true },
{ id: 64, image: '/static/logo.png', name: '北京海淨区提货点', phone: '13012340002', address: '北京市海淨区中关村大腃4号', hours: '08:30 - 20:30', isshow: true },
{ id: 63, image: '/static/logo.png', name: '上海浦东新区提货点', phone: '13012340003', address: '上海市浦东新区张江高科2号', hours: '09:00 - 22:00', isshow: true },
{ id: 62, image: '/static/logo.png', name: '上海徐汇提货点', phone: '13012340004', address: '上海市徐汇区淮海中路100号', hours: '10:00 - 21:00', isshow: false },
{ id: 61, image: '/static/logo.png', name: '广州天河提货点', phone: '13012340005', address: '广州市天河区天河北路55号', hours: '09:00 - 21:00', isshow: true },
{ id: 60, image: '/static/logo.png', name: '广州越秀提货点', phone: '13012340006', address: '广州市越秀区环市东路18号', hours: '08:00 - 20:00', isshow: true },
{ id: 59, image: '/static/logo.png', name: '深圳南山提货点', phone: '13012340007', address: '深圳市南山区松白路7号', hours: '09:00 - 22:00', isshow: true },
{ id: 58, image: '/static/logo.png', name: '深圳福田提货点', phone: '13012340008', address: '深圳市福田区深南大道青年公指1号', hours: '09:00 - 21:00', isshow: false },
{ id: 57, image: '/static/logo.png', name: '成都武侯提货点', phone: '13012340009', address: '成都市武侯区為最居东路3号', hours: '09:00 - 21:00', isshow: true },
{ id: 56, image: '/static/logo.png', name: '成都高新提货点', phone: '13012340010', address: '成都市高新区天府大道三段501号', hours: '08:30 - 20:30', isshow: true },
{ id: 55, image: '/static/logo.png', name: '杭州西湖提货点', phone: '13012340011', address: '杭州市西湖区建途路21号', hours: '09:00 - 22:00', isshow: true },
{ id: 54, image: '/static/logo.png', name: '杭州滨江提货点', phone: '13012340012', address: '杭州市拱墅区餓山镇中路', hours: '10:00 - 21:00', isshow: false },
{ id: 53, image: '/static/logo.png', name: '武汉江汉提货点', phone: '13012340013', address: '武汉市江汉区建设大道100号', hours: '09:00 - 20:00', isshow: true },
{ id: 52, image: '/static/logo.png', name: '武汉武昌提货点', phone: '13012340014', address: '武汉市武昌区紫菓路58号', hours: '08:30 - 21:00', isshow: true },
{ id: 51, image: '/static/logo.png', name: '南京中山提货点', phone: '13012340015', address: '南京市中山区阳山路123号', hours: '09:00 - 21:00', isshow: true },
{ id: 50, image: '/static/logo.png', name: '南京冿淮提货点', phone: '13012340016', address: '南京市冿淮区广州路9号', hours: '09:00 - 20:30', isshow: true },
{ id: 49, image: '/static/logo.png', name: '苏州工业园提货点', phone: '13012340017', address: '苏州工业园区现代大道168号', hours: '09:00 - 21:00', isshow: false },
{ id: 48, image: '/static/logo.png', name: '苏州姑苏提货点', phone: '13012340018', address: '苏州市姑苏区干将东路66号', hours: '07:30 - 22:00', isshow: true },
{ id: 47, image: '/static/logo.png', name: '提货点222', phone: '13769102384', address: '能看见你的困难', hours: '00:00:00 - 23:00:00', isshow: true },
{ id: 44, image: '/static/logo.png', name: '美东科技', phone: '15912341234', address: '襄阳火车站', hours: '08:00:00 - 22:00:00', isshow: 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(() => stationList.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 stationList.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 onSearch() {
console.log('Search:', searchKey.value)