完成90%页面分页组件的抽取
This commit is contained in:
@@ -46,7 +46,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-user"><text>{{ item.user }}</text></view>
|
||||
<view class="col col-action"><text>{{ item.action }}</text></view>
|
||||
@@ -58,17 +58,30 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分页 -->
|
||||
<view class="pagination">
|
||||
<text class="page-info">共 583387 条 15条/页</text>
|
||||
</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 dataList = ref([
|
||||
{ id: 585387, user: '5 / demo', action: '系统日志', link: 'system/log', ip: '223.104.72.77', type: 'system', time: '2026-02-11 18:49' },
|
||||
@@ -81,8 +94,49 @@ const dataList = ref([
|
||||
{ id: 585380, user: '5 / demo', action: '定时任务类型', link: 'system/crontab/mark', ip: '223.104.72.77', type: 'system', time: '2026-02-11 18:47' },
|
||||
{ id: 585379, user: '5 / demo', action: '定时任务列表', link: 'system/crontab/list', ip: '223.104.72.77', type: 'system', time: '2026-02-11 18:47' },
|
||||
{ id: 585378, user: '5 / demo', action: '保存组合数据', link: 'setting/group', ip: '223.104.72.77', type: 'system', time: '2026-02-11 18:47' },
|
||||
{ id: 585377, user: '5 / demo', action: '保存系统配置分类', link: 'setting/config_class', ip: '223.104.72.77', type: 'system', time: '2026-02-11 18:47' }
|
||||
{ id: 585377, user: '5 / demo', action: '保存系统配置分类', link: 'setting/config_class', ip: '223.104.72.77', type: 'system', time: '2026-02-11 18:47' },
|
||||
{ id: 585376, user: '5 / demo', action: '神识别相册管理', link: 'system/gallery', ip: '115.29.168.1', type: 'system', time: '2026-02-11 18:45' },
|
||||
{ id: 585375, user: '3 / admin', action: '订单列表', link: 'order/list', ip: '116.228.88.5', type: 'system', time: '2026-02-11 18:43' },
|
||||
{ id: 585374, user: '3 / admin', action: '商品列表', link: 'product/list', ip: '116.228.88.5', type: 'system', time: '2026-02-11 18:42' },
|
||||
{ id: 585373, user: '3 / admin', action: '用户列表', link: 'user/list', ip: '116.228.88.5', type: 'system', time: '2026-02-11 18:41' },
|
||||
{ id: 585372, user: '5 / demo', action: '分销分红记录', link: 'distribution/brokerage', ip: '223.104.72.77', type: 'system', time: '2026-02-11 18:40' },
|
||||
{ id: 585371, user: '5 / demo', action: '财务提现列表', link: 'finance/withdraw', ip: '223.104.72.77', type: 'system', time: '2026-02-11 18:39' },
|
||||
{ id: 585370, user: '3 / admin', action: '商品分类列表', link: 'product/category', ip: '116.228.88.5', type: 'system', time: '2026-02-11 18:38' },
|
||||
{ id: 585369, user: '1 / 超级管理员', action: '系统监控', link: 'system/monitor', ip: '127.0.0.1', type: 'system', time: '2026-02-11 18:37' }
|
||||
])
|
||||
// ========== 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