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

@@ -1,13 +1,154 @@
<template>
<AdminLayout currentPage="external-account">
<view class="page">
<view class="header">
<text class="title">账号管理</text>
</view>
<view class="content">
<text class="tip">TODO: 账号管理</text>
</view>
</view>
</AdminLayout>
<view class="admin-page-container">
<view class="page-card">
<view class="search-wrap">
<view class="search-item">
<text class="label">平台类型:</text>
<input class="input" placeholder="请输入平台名称" v-model="searchKey" />
</view>
<button class="btn btn-primary" @click="onSearch">查询</button>
</view>
<view class="action-wrap">
<button class="btn btn-primary" @click="onAdd">添加账号</button>
</view>
<view class="table-wrap">
<view class="table-header">
<view class="th" style="flex: 0 0 60px;">ID</view>
<view class="th" style="flex: 2;">账号名称</view>
<view class="th" style="flex: 2;">平台类型</view>
<view class="th" style="flex: 2;">AppID/账号</view>
<view class="th" style="flex: 1;">状态</view>
<view class="th" style="flex: 2;">创建时间</view>
<view class="th" style="flex: 2;">操作</view>
</view>
<view class="table-body">
<view v-for="item in pagedList" :key="item.id" class="tr">
<view class="td" style="flex: 0 0 60px;">{{ item.id }}</view>
<view class="td" style="flex: 2;">{{ item.name }}</view>
<view class="td" style="flex: 2;">{{ item.platform }}</view>
<view class="td" style="flex: 2;">{{ item.appId }}</view>
<view class="td" style="flex: 1;">
<switch :checked="item.status" color="#1890ff" style="transform: scale(0.7);" />
</view>
<view class="td" style="flex: 2;">{{ item.createTime }}</view>
<view class="td" style="flex: 2;">
<text class="action-btn" @click="onEdit(item)">编辑</text>
<text class="action-btn-del" @click="onDel(item)">删除</text>
</view>
</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>
</view>
</template>
</template>
<script setup lang="uts">
import { ref, computed } from 'vue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
const searchKey = ref('')
type AccountItem = { id: number; name: string; platform: string; appId: string; status: boolean; createTime: string }
// ========== MOCK DATA START ==========
// TODO: 接真实接口时替换此处 accountList 为 fetchExternalAccountList() 调用
const accountList = ref<AccountItem[]>([
{ id: 20, name: '微信公众号', platform: '微信', appId: 'wx_public_001', status: true, createTime: '2025-01-01 10:00:00' },
{ id: 19, name: '微信小程序', platform: '微信', appId: 'wx_mini_001', status: true, createTime: '2025-01-02 10:00:00' },
{ id: 18, name: '支付宝商家版', platform: '支付宝', appId: 'alipay_shop_001', status: true, createTime: '2025-01-03 10:00:00' },
{ id: 17, name: '微信支付', platform: '微信支付', appId: 'wxpay_mch_001', status: true, createTime: '2025-01-04 10:00:00' },
{ id: 16, name: '百度小程序', platform: '百度', appId: 'baidu_mini_001', status: false, createTime: '2025-01-05 10:00:00' },
{ id: 15, name: '字节跳动小程序', platform: '字节跳动', appId: 'douyin_mini_001', status: true, createTime: '2025-01-06 10:00:00' },
{ id: 14, name: '阿里云短信', platform: '阿里云', appId: 'aliyun_sms_001', status: true, createTime: '2025-01-07 10:00:00' },
{ id: 13, name: '腾讯云短信', platform: '腾讯云', appId: 'tencent_sms_001', status: true, createTime: '2025-01-08 10:00:00' },
{ id: 12, name: '七牛云存储', platform: '七牛云', appId: 'qiniu_oss_001', status: false, createTime: '2025-01-09 10:00:00' },
{ id: 11, name: '阿里云OSS', platform: '阿里云', appId: 'aliyun_oss_001', status: true, createTime: '2025-01-10 10:00:00' },
{ id: 10, name: '腾讯云COS', platform: '腾讯云', appId: 'tencent_cos_001', status: true, createTime: '2025-01-11 10:00:00' },
{ id: 9, name: 'Apple登录', platform: 'Apple', appId: 'apple_signin_001', status: false, createTime: '2025-01-12 10:00:00' },
{ id: 8, name: '高德地图', platform: '高德地图', appId: 'amap_key_001', status: true, createTime: '2025-01-13 10:00:00' },
{ id: 7, name: '百度地图', platform: '百度', appId: 'bmap_key_001', status: true, createTime: '2025-01-14 10:00:00' },
{ id: 6, name: '联通支付', platform: '联通', appId: 'union_pay_001', status: false, createTime: '2025-01-15 10:00:00' },
{ id: 5, name: 'H5微信登录', platform: '微信', appId: 'wx_h5_001', status: true, createTime: '2025-01-16 10:00:00' },
{ id: 4, name: 'App微信登录', platform: '微信', appId: 'wx_app_001', status: true, createTime: '2025-01-17 10:00:00' },
{ id: 3, name: 'QQ登录', platform: 'QQ', appId: 'qq_login_001', status: false, createTime: '2025-01-18 10:00:00' },
{ id: 2, name: '微博登录', platform: '微博', appId: 'weibo_login_001', status: false, createTime: '2025-01-19 10:00:00' },
{ id: 1, name: '易联云打印', platform: '易联云', appId: 'yly_key_001', status: true, createTime: '2025-01-20 10:00:00' }
])
// ========== 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(() => accountList.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 accountList.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() { console.log('Search:', searchKey.value) }
function onAdd() { uni.showToast({ title: '添加账号', icon: 'none' }) }
function onEdit(item: AccountItem) { uni.showToast({ title: '编辑: ' + item.name, icon: 'none' }) }
function onDel(item: AccountItem) {
uni.showModal({ title: '提示', content: '确定删除该账号吗?', success: (res) => {
if (res.confirm) uni.showToast({ title: '已删除', icon: 'success' })
}})
}
</script>
<style scoped>
.admin-page-container { padding: 0; background-color: transparent; min-height: auto; }
.page-card { background-color: #fff; border-radius: 4px; padding: 20px; }
.search-wrap { display: flex; flex-direction: row; align-items: center; padding-bottom: 20px; border-bottom: 1px solid #f0f0f0; margin-bottom: 20px; }
.search-item { display: flex; flex-direction: row; align-items: center; margin-right: 20px; }
.label { font-size: 14px; color: #606266; margin-right: 8px; }
.input { width: 220px; height: 32px; padding: 0 10px; border: 1px solid #dcdfe6; border-radius: 4px; font-size: 14px; }
.btn { height: 32px; padding: 0 15px; font-size: 14px; border-radius: 4px; border: none; }
.btn-primary { background-color: #1890ff; color: #fff; }
.action-wrap { margin-bottom: 20px; }
.table-wrap { width: 100%; border: 1px solid #f0f0f0; }
.table-header { display: flex; flex-direction: row; background-color: #f8f8f9; }
.th { padding: 12px 10px; font-size: 13px; font-weight: bold; color: #515a6e; border-bottom: 1px solid #f0f0f0; text-align: center; }
.tr { display: flex; flex-direction: row; align-items: center; border-bottom: 1px solid #f0f0f0; min-height: 50px; }
.td { padding: 10px; font-size: 13px; color: #515a6e; text-align: center; }
.action-btn { font-size: 13px; color: #1890ff; margin-right: 8px; cursor: pointer; }
.action-btn-del { font-size: 13px; color: #ed4014; cursor: pointer; }
</style>