完成90%页面分页组件的抽取
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
<view class="table-cell action-cell" style="flex: 2;">操作</view>
|
||||
</view>
|
||||
<view class="table-body">
|
||||
<view class="table-row" v-for="(item, index) in printerList" :key="index">
|
||||
<view class="table-row" v-for="(item, index) in pagedList" :key="index">
|
||||
<view class="table-cell" style="flex: 0 0 60px;">{{ item.id }}</view>
|
||||
<view class="table-cell" style="flex: 2;">{{ item.name }}</view>
|
||||
<view class="table-cell" style="flex: 1.5;">{{ item.platform }}</view>
|
||||
@@ -52,26 +52,90 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分页 (模拟) -->
|
||||
<view class="pagination">
|
||||
<text class="total">共 1 条</text>
|
||||
<picker :range="['15条/页', '30条/页']">
|
||||
<view class="page-size">15条/页</view>
|
||||
</picker>
|
||||
</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>
|
||||
</view></template>
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, computed } from 'vue'
|
||||
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
|
||||
|
||||
const searchQuery = ref({ name: '' })
|
||||
const platforms = ['全部', '易联云', '飞鹅打印机']
|
||||
const selectedPlatform = ref(0)
|
||||
|
||||
// ========== MOCK DATA START ==========
|
||||
// TODO: 接真实接口时替换此处 printerList 为 fetchPrinterList() 调用
|
||||
const printerList = ref([
|
||||
{ id: 20, name: '总部底层打印机', platform: '易联云', account: 'hq_admin', copies: 2, add_time: '2025-02-01 10:00:00', status: true },
|
||||
{ id: 19, name: '广州仓库打印机', platform: '飞鹅打印机', account: 'gz_wh01', copies: 1, add_time: '2025-02-03 11:00:00', status: true },
|
||||
{ id: 18, name: '上海分拨打印机', platform: '易联云', account: 'sh_fp01', copies: 1, add_time: '2025-02-05 09:30:00', status: false },
|
||||
{ id: 17, name: '北京主打印机', platform: '易联云', account: 'bj_main', copies: 2, add_time: '2025-02-08 14:00:00', status: true },
|
||||
{ id: 16, name: '北京备打印机', platform: '飞鹅打印机', account: 'bj_bak01', copies: 1, add_time: '2025-02-10 08:30:00', status: true },
|
||||
{ id: 15, name: '化妙打印机', platform: '易联云', account: 'hm_pr01', copies: 3, add_time: '2025-02-12 10:20:00', status: true },
|
||||
{ id: 14, name: '客服部打印机', platform: '飞鹅打印机', account: 'cs_pr01', copies: 1, add_time: '2025-02-15 15:00:00', status: true },
|
||||
{ id: 13, name: '采购部打印机', platform: '易联云', account: 'cg_pr01', copies: 1, add_time: '2025-02-18 12:00:00', status: false },
|
||||
{ id: 12, name: '财务部打印机', platform: '飞鹅打印机', account: 'cw_pr01', copies: 2, add_time: '2025-02-20 09:00:00', status: true },
|
||||
{ id: 11, name: '运营部打印机', platform: '易联云', account: 'yy_pr01', copies: 1, add_time: '2025-02-22 11:30:00', status: true },
|
||||
{ id: 10, name: '成都网点打印机', platform: '飞鹅打印机', account: 'cd_np01', copies: 1, add_time: '2025-02-25 10:00:00', status: true },
|
||||
{ id: 9, name: '武汉网点打印机', platform: '易联云', account: 'wh_np01', copies: 2, add_time: '2025-03-01 14:00:00', status: false },
|
||||
{ id: 8, name: '深圳网点打印机', platform: '飞鹅打印机', account: 'sz_np01', copies: 1, add_time: '2025-03-05 09:00:00', status: true },
|
||||
{ id: 7, name: '杭州网点打印机', platform: '易联云', account: 'hz_np01', copies: 1, add_time: '2025-03-08 11:00:00', status: true },
|
||||
{ id: 6, name: '南京网点打印机', platform: '飞鹅打印机', account: 'nj_np01', copies: 2, add_time: '2025-03-10 12:00:00', status: true },
|
||||
{ id: 5, name: '苏州网点打印机', platform: '易联云', account: 'sz2_np01', copies: 1, add_time: '2025-03-12 15:00:00', status: false },
|
||||
{ id: 4, name: '小类目打印机', platform: '飞鹅打印机', account: 'xl_pr01', copies: 1, add_time: '2025-03-15 10:30:00', status: true },
|
||||
{ id: 3, name: '大档打印机', platform: '易联云', account: 'dd_pr01', copies: 3, add_time: '2025-03-18 09:00:00', status: true },
|
||||
{ id: 2, name: '二号打印', platform: '飞鹅打印机', account: '333', copies: 1, add_time: '2025-01-01 12:00:00', status: false },
|
||||
{ id: 1, name: '一号打印', platform: '易联云', account: '222', copies: 1, add_time: '2024-12-11 15:12:58', 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(() => printerList.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 printerList.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 onPlatformChange(e: any) {
|
||||
selectedPlatform.value = e.detail.value
|
||||
|
||||
Reference in New Issue
Block a user