完成全部页面分页组件的抽取
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
</view>
|
||||
|
||||
<view class="table-body">
|
||||
<view v-for="item in dataList" :key="item.id" class="table-row">
|
||||
<view v-for="item in pagedList" :key="item.id" class="table-row">
|
||||
<view class="col col-id"><text>{{ item.id }}</text></view>
|
||||
<view class="col col-name"><text>{{ item.name }}</text></view>
|
||||
<view class="col col-code"><text>{{ item.code }}</text></view>
|
||||
@@ -52,18 +52,33 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分页 (模拟) -->
|
||||
<view class="pagination">
|
||||
<!-- 这里可以放分页组件 -->
|
||||
</view>
|
||||
<CommonPagination
|
||||
v-if="true"
|
||||
: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>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, computed } from 'vue'
|
||||
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
|
||||
|
||||
// ========== MOCK DATA START ==========
|
||||
// TODO: 接真实接口时替换此处 dataList 为 fetchLogisticsList() 调用
|
||||
const dataList = ref([
|
||||
{ id: 2, name: '顺丰速运', code: 'shunfeng', sort: 0, show: true },
|
||||
{ id: 3, name: '圆通速递', code: 'yuantong', sort: 0, show: true },
|
||||
@@ -77,8 +92,48 @@ const dataList = ref([
|
||||
{ id: 11, name: 'EMS', code: 'ems', sort: 0, show: true },
|
||||
{ id: 12, name: '德邦物流', code: 'debangwuliu', sort: 0, show: true },
|
||||
{ id: 13, name: '德邦快递', code: 'debangkuaidi', sort: 0, show: true },
|
||||
{ id: 14, name: '众邮快递', code: 'zhongyouex', sort: 0, show: true }
|
||||
{ id: 14, name: '众邮快递', code: 'zhongyouex', sort: 0, show: true },
|
||||
{ id: 15, name: '安能快运', code: 'annengkuaiyun', sort: 0, show: true },
|
||||
{ id: 16, name: '壹米滴答', code: 'yimidida', sort: 0, show: false },
|
||||
{ id: 17, name: '宅急送', code: 'zhaijisong', sort: 0, show: true },
|
||||
{ id: 18, name: '苏宁物流', code: 'suning', sort: 0, show: true },
|
||||
{ id: 19, name: '中通快运', code: 'zhongtongkuaiyun', sort: 0, show: true },
|
||||
{ id: 20, name: '芝麻开门', code: 'zhimakaimen', sort: 0, show: false },
|
||||
{ id: 21, name: '优速快递', code: 'youshuwuliu', sort: 0, show: 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(() => dataList.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 dataList.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() {
|
||||
uni.showToast({ title: '查询中...', icon: 'none' })
|
||||
|
||||
Reference in New Issue
Block a user