feat: 优化后台商品管理与移动端个人中心

This commit is contained in:
yml2213
2026-11-05 19:10:48 +08:00
parent f01329e049
commit 53574236ef
5 changed files with 1042 additions and 446 deletions
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { computed } from 'vue'
import { ArrowLeft, ArrowRight, DArrowLeft, DArrowRight } from '@element-plus/icons-vue'
import { computed, ref, watch } from 'vue'
interface Props {
currentPage: number
@@ -23,6 +24,18 @@ const currentCount = computed(() => {
const start = (props.currentPage - 1) * props.pageSize
return Math.min(props.pageSize, props.total - start)
})
const jumpPage = ref<number | undefined>(props.currentPage)
watch(
() => props.currentPage,
page => {
jumpPage.value = page
}
)
watch(totalPages, pages => {
if (jumpPage.value && jumpPage.value > pages) jumpPage.value = pages
})
function handleSizeChange(size: number) {
emit('update:pageSize', size)
@@ -36,36 +49,120 @@ function prevPage() {
emit('pageChange')
}
function firstPage() {
if (props.currentPage <= 1) return
emit('update:currentPage', 1)
emit('pageChange')
}
function nextPage() {
if (props.currentPage >= totalPages.value) return
emit('update:currentPage', props.currentPage + 1)
emit('pageChange')
}
function lastPage() {
if (props.currentPage >= totalPages.value) return
emit('update:currentPage', totalPages.value)
emit('pageChange')
}
function jumpToPage() {
const requested = Number(jumpPage.value)
if (!Number.isFinite(requested)) {
jumpPage.value = props.currentPage
return
}
const page = Math.min(Math.max(Math.trunc(requested), 1), totalPages.value)
jumpPage.value = page
if (page === props.currentPage) return
emit('update:currentPage', page)
emit('pageChange')
}
</script>
<template>
<div class="table-pagination">
<span class="pagination-summary">当前页 {{ currentCount }} 条,共 {{ total }} 条</span>
<span class="pagination-summary">
共 <strong>{{ total }}</strong> 条
<em>本页 {{ currentCount }} 条</em>
</span>
<div class="pagination-controls">
<span class="pagination-size-label">每页</span>
<el-select
:model-value="pageSize"
class="page-size-select"
size="small"
:disabled="loading"
@update:model-value="handleSizeChange"
>
<el-option :value="10" label="10条" />
<el-option :value="20" label="20条" />
<el-option :value="50" label="50条" />
<el-option :value="100" label="100条" />
<el-option :value="10" label="10 条" />
<el-option :value="20" label="20 条" />
<el-option :value="50" label="50 条" />
<el-option :value="100" label="100 条" />
</el-select>
<span class="pagination-page">{{ currentPage }}/{{ totalPages }}页</span>
<el-button size="small" :disabled="currentPage <= 1 || loading" @click="prevPage"
>上页</el-button
>
<el-button size="small" :disabled="currentPage >= totalPages || loading" @click="nextPage"
>下页</el-button
>
<div class="pagination-nav">
<el-button
class="pagination-nav-btn"
size="small"
:icon="DArrowLeft"
:disabled="currentPage <= 1 || loading"
aria-label="第一页"
@click="firstPage"
/>
<el-button
class="pagination-nav-btn"
size="small"
:icon="ArrowLeft"
:disabled="currentPage <= 1 || loading"
aria-label="上一页"
@click="prevPage"
/>
<span class="pagination-page">
<strong>{{ currentPage }}</strong>
<i>/</i>
{{ totalPages }}
</span>
<el-button
class="pagination-nav-btn"
size="small"
:icon="ArrowRight"
:disabled="currentPage >= totalPages || loading"
aria-label="下一页"
@click="nextPage"
/>
<el-button
class="pagination-nav-btn"
size="small"
:icon="DArrowRight"
:disabled="currentPage >= totalPages || loading"
aria-label="最后一页"
@click="lastPage"
/>
</div>
<div class="pagination-jump">
<span>前往</span>
<el-input-number
v-model="jumpPage"
class="pagination-jump-input"
size="small"
:min="1"
:max="totalPages"
:precision="0"
:controls="false"
:disabled="loading || totalPages <= 1"
@keyup.enter="jumpToPage"
/>
<span>页</span>
<el-button
class="pagination-jump-btn"
size="small"
:disabled="loading || totalPages <= 1"
@click="jumpToPage"
>
跳转
</el-button>
</div>
</div>
</div>
</template>
@@ -11,6 +11,7 @@ import {
type AdminListingQuery,
type Listing,
} from '@/features/listings'
import AdminTablePagination from '@/features/admin/components/AdminTablePagination.vue'
import { useAdminTable } from '@/features/admin/composables/useAdminTable'
import { adminPath } from '@/shared/utils/adminPath'
import { formatCentWithSymbol } from '@/shared/utils/money'
@@ -79,14 +80,6 @@ const {
const listings = computed(() => listingPage.value.items)
const totalListings = computed(() => listingPage.value.total)
const publishedCount = computed(
() => listings.value.filter(item => item.status === 'published').length
)
const rentedCount = computed(() => listings.value.filter(item => item.status === 'rented').length)
const pendingCount = computed(
() => listings.value.filter(item => item.review_status === 'pending').length
)
const totalPages = computed(() => Math.max(1, Math.ceil(totalListings.value / pageSize.value)))
const insuranceOptions = computed(() =>
publishOptions.value.insurance_options.length
? publishOptions.value.insurance_options
@@ -372,36 +365,6 @@ function levelSlotLabel(value: string) {
return value ? value.replace(/级$/, '') : '-'
}
function setStatusFilter(status: string) {
filters.status = (filters.status === status ? '' : status) as AdminListingQuery['status']
filters.review_status = ''
void queryListings()
}
function setReviewStatusFilter(reviewStatus: string) {
filters.review_status = (
filters.review_status === reviewStatus ? '' : reviewStatus
) as AdminListingQuery['review_status']
filters.status = ''
void queryListings()
}
async function handlePageSizeChange(size: number) {
pageSize.value = size
currentPage.value = 1
await loadListings()
}
async function prevPage() {
currentPage.value = Math.max(1, currentPage.value - 1)
await loadListings()
}
async function nextPage() {
currentPage.value = Math.min(totalPages.value, currentPage.value + 1)
await loadListings()
}
async function copyTableScreenshot() {
try {
const blob = await createTableScreenshotBlob()
@@ -690,43 +653,25 @@ function formatQuantity(value: number) {
</div>
<div class="listing-control-panel">
<!-- 统计指标行 -->
<div class="listing-stats-row">
<div
class="stat-card clickable"
:class="{ active: !filters.status && !filters.review_status }"
@click="resetFilters"
>
<span class="stat-label">全部商品</span>
<strong class="stat-value">{{ totalListings }}</strong>
<div class="listing-filter-toolbar">
<div class="listing-filter-summary">
<strong>筛选条件</strong>
<span>
共 <b>{{ totalListings }}</b> 件商品
</span>
</div>
<div
class="stat-card clickable"
:class="{ active: filters.status === 'published' }"
@click="setStatusFilter('published')"
>
<span class="stat-label">已上架</span>
<strong class="stat-value">{{ publishedCount }}</strong>
</div>
<div
class="stat-card clickable"
:class="{ active: filters.status === 'rented' }"
@click="setStatusFilter('rented')"
>
<span class="stat-label">已锁定</span>
<strong class="stat-value">{{ rentedCount }}</strong>
</div>
<div
class="stat-card clickable"
:class="{ active: filters.review_status === 'pending' }"
@click="setReviewStatusFilter('pending')"
>
<span class="stat-label">待审核</span>
<strong class="stat-value">{{ pendingCount }}</strong>
<div class="listing-action-strip">
<el-button @click="resetFilters">重置</el-button>
<el-button type="primary" :icon="Search" :loading="loading" @click="queryListings"
>查询</el-button
>
<el-button :disabled="!listings.length" @click="copyTableScreenshot">复制截图</el-button>
<el-button :disabled="!listings.length" @click="downloadTableScreenshot"
>下载截图</el-button
>
</div>
</div>
<!-- 筛选和操作行 -->
<div class="listing-filter-row">
<el-form class="listing-filter-bar" label-position="top">
<el-form-item class="filter-keyword" label="编号">
@@ -813,7 +758,7 @@ function formatQuantity(value: number) {
<el-option label="极品专区" value="premium" />
</el-select>
</el-form-item>
<el-form-item class="filter-select" label="资产">
<el-form-item class="filter-select filter-asset" label="资产">
<el-popover
:visible="activeFilterPopover === 'asset'"
trigger="click"
@@ -980,16 +925,6 @@ function formatQuantity(value: number) {
</el-popover>
</el-form-item>
</el-form>
<div class="listing-action-strip">
<el-button @click="resetFilters">重置</el-button>
<el-button type="primary" :icon="Search" :loading="loading" @click="queryListings"
>查询</el-button
>
<el-button :disabled="!listings.length" @click="copyTableScreenshot">复制截图</el-button>
<el-button :disabled="!listings.length" @click="downloadTableScreenshot"
>下载截图</el-button
>
</div>
</div>
</div>
@@ -1095,29 +1030,13 @@ function formatQuantity(value: number) {
</el-table-column>
</el-table>
<div class="table-pagination">
<span class="pagination-summary"
>当前页 {{ listings.length }} 条,共 {{ totalListings }} 条</span
>
<div class="pagination-controls">
<span class="pagination-size-label">每页</span>
<el-select
:model-value="pageSize"
class="page-size-select"
size="small"
@update:model-value="handlePageSizeChange"
>
<el-option :value="10" label="10条" />
<el-option :value="20" label="20条" />
<el-option :value="50" label="50条" />
<el-option :value="100" label="100条" />
</el-select>
<span class="pagination-page">{{ currentPage }}/{{ totalPages }}页</span>
<el-button size="small" :disabled="currentPage <= 1" @click="prevPage">上页</el-button>
<el-button size="small" :disabled="currentPage >= totalPages" @click="nextPage"
>下页</el-button
>
</div>
</div>
<AdminTablePagination
v-if="totalListings > 0"
v-model:current-page="currentPage"
v-model:page-size="pageSize"
:total="totalListings"
:loading="loading"
@page-change="loadListings"
/>
</section>
</template>