完成全部页面分页组件的抽取

This commit is contained in:
2026-03-17 10:50:42 +08:00
parent 7211fcdfea
commit e266482f88
17 changed files with 619 additions and 52 deletions

View File

@@ -56,7 +56,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-origin"><text>{{ item.origin }}</text></view>
<view class="col col-translation"><text>{{ item.translation }}</text></view>
@@ -70,14 +70,33 @@
</view>
</view>
</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 为 fetchTranslationList() 调用
const dataList = ref([
{ id: 55493, origin: '秒杀活动', translation: '秒杀活动', code: '秒杀活动', type: '中文(zh-CN)' },
{ id: 55483, origin: '哥哥我', translation: '', code: '哥哥我', type: '中文(zh-CN)' },
@@ -88,8 +107,50 @@ const dataList = ref([
{ id: 25181, origin: '支付剩余时间', translation: '支付剩余时间', code: '支付剩余时间', type: '中文(zh-CN)' },
{ id: 24711, origin: '全部已读', translation: '全部已读', code: '全部已读', type: '中文(zh-CN)' },
{ id: 24701, origin: '获得拼团团长佣金', translation: '获得拼团团长佣金', code: '获得拼团团长佣金', type: '中文(zh-CN)' },
{ id: 24691, origin: '获得事业部推广订单佣金', translation: '获得事业部推广订单佣金', code: '获得事业部推广订单佣金', type: '中文(zh-CN)' }
{ id: 24691, origin: '获得事业部推广订单佣金', translation: '获得事业部推广订单佣金', code: '获得事业部推广订单佣金', type: '中文(zh-CN)' },
{ id: 24681, origin: '返回默认地址', translation: '返回默认地址', code: '返回默认地址', type: '中文(zh-CN)' },
{ id: 24671, origin: '我的购物车', translation: '我的购物车', code: '我的购物车', type: '中文(zh-CN)' },
{ id: 24661, origin: '监控山东', translation: '监控山东', code: '监控山东', type: '中文(zh-CN)' },
{ id: 24651, origin: '商品评价', translation: '商品评价', code: '商品评价', type: '中文(zh-CN)' },
{ id: 24641, origin: '手机号已绑定', translation: '手机号已绑定', code: '手机号已绑定', type: '中文(zh-CN)' },
{ id: 24631, origin: '订单列表', translation: '订单列表', code: '订单列表', type: '中文(zh-CN)' },
{ id: 24621, origin: '购买商品', translation: '购买商品', code: '购买商品', type: '中文(zh-CN)' },
{ id: 24611, origin: '会员中心', translation: '会员中心', code: '会员中心', type: '中文(zh-CN)' },
{ id: 24601, origin: '就此评价', translation: '就此评价', code: '就此评价', type: '中文(zh-CN)' }
])
// ========== 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' })
@@ -255,7 +316,7 @@ function deleteWord(item: any) {
.col-translation { flex: 2; }
.col-code { flex: 2; }
.col-type { width: 150px; }
.col-action { width: 150px; justify-content: flex-end; }
.col-action { width: 150px; justify-content: flex-end;display: flex; flex-direction: row; }
.action-btn {
color: #1890ff;