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

@@ -226,7 +226,7 @@ const handleSubmit = () => {
.cell-days { width: 120px; }
.cell-reward { flex: 1; }
.cell-status { width: 100px; text-align: center; }
.cell-op { width: 150px; text-align: right; }
.cell-op { width: 150px; text-align: right; display: flex; flex-direction: row; }
.op-link { color: #1890ff; font-size: 13px; cursor: pointer; }
.op-link.del { color: #ff4d4f; }

View File

@@ -29,7 +29,7 @@
</view>
<view class="table-body">
<view v-for="item in configList" :key="item.id" class="table-row">
<view v-for="item in pagedList" :key="item.id" class="table-row">
<view class="td cell-id">
<text class="td-txt">{{ item.id }}</text>
</view>
@@ -60,17 +60,22 @@
</view>
</view>
<view class="pagination-footer">
<view class="page-total">
<text class="total-txt">共 {{ configList.length }} 条</text>
</view>
<view class="page-select">
<view class="select-mock mini">
<text class="select-val">20条/页</text>
<text class="arrow">▼</text>
</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>
<!-- Drawer Overlay -->
@@ -116,8 +121,9 @@
</template>
<script setup lang="uts">
import { ref } from 'vue'
import { ref, computed } from 'vue'
import StatusSwitch from '@/components/StatusSwitch.uvue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
const showDrawer = ref(false)
const isAnimating = ref(false)
@@ -131,16 +137,63 @@ const formData = ref({
status: true
})
// ========== MOCK DATA START ==========
// TODO: 接真实接口时替换此处 configList 为 fetchConfigList() 调用
const configList = ref([
{
id: 2268,
start_hour: 6,
duration: 18,
image: '',
sort: 1,
status: true
}
{ id: 2268, start_hour: 0, duration: 2, image: '', sort: 1, status: true },
{ id: 2269, start_hour: 2, duration: 2, image: '', sort: 2, status: true },
{ id: 2270, start_hour: 4, duration: 2, image: '', sort: 3, status: true },
{ id: 2271, start_hour: 6, duration: 3, image: '', sort: 4, status: true },
{ id: 2272, start_hour: 9, duration: 3, image: '', sort: 5, status: true },
{ id: 2273, start_hour: 12, duration: 3, image: '', sort: 6, status: false },
{ id: 2274, start_hour: 15, duration: 3, image: '', sort: 7, status: true },
{ id: 2275, start_hour: 18, duration: 2, image: '', sort: 8, status: true },
{ id: 2276, start_hour: 20, duration: 2, image: '', sort: 9, status: true },
{ id: 2277, start_hour: 22, duration: 2, image: '', sort: 10, status: false },
{ id: 2278, start_hour: 8, duration: 4, image: '', sort: 11, status: true },
{ id: 2279, start_hour: 10, duration: 2, image: '', sort: 12, status: true },
{ id: 2280, start_hour: 13, duration: 2, image: '', sort: 13, status: true },
{ id: 2281, start_hour: 16, duration: 3, image: '', sort: 14, status: false },
{ id: 2282, start_hour: 19, duration: 1, image: '', sort: 15, status: true },
{ id: 2283, start_hour: 21, duration: 2, image: '', sort: 16, status: true },
{ id: 2284, start_hour: 7, duration: 3, image: '', sort: 17, status: true },
{ id: 2285, start_hour: 11, duration: 2, image: '', sort: 18, status: false },
{ id: 2286, start_hour: 14, duration: 4, image: '', sort: 19, status: true },
{ id: 2287, start_hour: 17, duration: 2, image: '', sort: 20, 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(() => configList.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 configList.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 ==========
const handleEdit = (item: any) => {
formData.value = { ...item }
@@ -313,16 +366,7 @@ const closeDrawer = () => {
.op-link { color: #1890ff; font-size: 13px; cursor: pointer; }
.op-split { color: #e8eaec; margin: 0 8px; }
/* 分页 */
.pagination-footer {
margin-top: 24px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
gap: 12px;
}
.total-txt { font-size: 13px; color: #606266; }
/* 分页区域已迁至 CommonPagination 组件 */
/* Drawer Styles */
.drawer-mask {