功能:更新消息中心和 YumiNail 模块
This commit is contained in:
@@ -1,26 +1,38 @@
|
||||
<template>
|
||||
<div class="products">
|
||||
<a-page-header title="作品管理" sub-title="管理美甲作品" />
|
||||
<a-page-header v-if="!isMobile" title="作品管理" sub-title="管理美甲作品" />
|
||||
|
||||
<section v-else class="admin-page-intro">
|
||||
<span class="admin-page-intro__eyebrow">经营</span>
|
||||
<h1 class="admin-page-intro__title">作品管理</h1>
|
||||
<div class="admin-page-intro__meta">
|
||||
<span class="admin-page-chip">作品 {{ productList.length }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<a-card :bordered="false">
|
||||
<template #title v-if="isMobile">
|
||||
作品列表
|
||||
</template>
|
||||
<template #extra>
|
||||
<a-space>
|
||||
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
|
||||
<a-input-search
|
||||
v-model:value="searchText"
|
||||
placeholder="搜索作品名称"
|
||||
style="width: 250px"
|
||||
:style="isMobile ? { width: '100%' } : { width: '250px' }"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="hasPermission('product:create')" type="primary" @click="showAddModal">
|
||||
<a-button v-if="!isMobile && hasPermission('product:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
新增作品
|
||||
</a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="productList"
|
||||
:loading="loading"
|
||||
@@ -91,12 +103,47 @@
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<AdminMobileCardList v-else :items="productList" empty-description="暂无作品数据">
|
||||
<template #item="{ item }">
|
||||
<article class="admin-mobile-card">
|
||||
<a-image
|
||||
class="admin-mobile-card__cover admin-mobile-card__cover--wide"
|
||||
:src="getProductImages(item)[0] || DEFAULT_PRODUCT_IMAGE"
|
||||
:preview="false"
|
||||
/>
|
||||
<div class="admin-mobile-card__head" style="margin-top: 14px">
|
||||
<div class="admin-mobile-card__body">
|
||||
<div class="admin-mobile-card__title">{{ item.title }}</div>
|
||||
<div class="admin-mobile-card__subtitle">{{ item.shopName || getShopName(item.shopId) }}</div>
|
||||
</div>
|
||||
<span class="admin-mobile-card__badge">¥{{ item.price }}</span>
|
||||
</div>
|
||||
<div class="admin-mobile-card__description">{{ item.description || '暂无描述' }}</div>
|
||||
<div class="admin-mobile-card__rows">
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>预计时长</span>
|
||||
<strong>{{ item.approximateDuration || '--' }} 分钟</strong>
|
||||
</div>
|
||||
<div class="admin-mobile-card__row">
|
||||
<span>互动数据</span>
|
||||
<strong>赞 {{ item.likeCount || 0 }} / 藏 {{ item.collectCount || 0 }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-mobile-card__actions">
|
||||
<a-button size="small" @click="showViewModal(item)">查看</a-button>
|
||||
<a-button v-if="hasPermission('product:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
|
||||
<a-button v-if="hasPermission('product:delete')" size="small" danger @click="handleDelete(item)">删除</a-button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
</AdminMobileCardList>
|
||||
</a-card>
|
||||
|
||||
<a-modal
|
||||
<AdminResponsiveModal
|
||||
v-model:open="modalVisible"
|
||||
:title="isEdit ? '编辑作品' : '新增作品'"
|
||||
width="700px"
|
||||
:desktop-width="700"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
:confirmLoading="modalLoading"
|
||||
@@ -302,13 +349,13 @@
|
||||
</a-form-item>
|
||||
</template>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<!-- 查看作品详情模态框 -->
|
||||
<a-modal
|
||||
<AdminResponsiveModal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看作品详情"
|
||||
width="700px"
|
||||
:desktop-width="700"
|
||||
@cancel="handleViewModalCancel"
|
||||
>
|
||||
<a-form
|
||||
@@ -427,7 +474,13 @@
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</AdminResponsiveModal>
|
||||
|
||||
<AdminMobileFab
|
||||
:visible="isMobile && hasPermission('product:create') && !modalVisible && !viewModalVisible"
|
||||
label="新增作品"
|
||||
@click="showAddModal"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -446,8 +499,13 @@ import { MAX_IMAGE_UPLOAD_SIZE, compressImageIfNeeded, formatFileSize } from '@/
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { sameId } from '@/utils/id'
|
||||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const productList = ref<Product[]>([])
|
||||
@@ -477,6 +535,20 @@ const uploadTaskMap = new Map<string, ChunkUploadTask<any>>()
|
||||
const activeUploadCount = ref(0)
|
||||
const isUploadPending = computed(() => activeUploadCount.value > 0)
|
||||
const draftSavedAt = ref<number | null>(null)
|
||||
const requestTokens = reactive({
|
||||
shops: 0,
|
||||
tags: 0,
|
||||
artists: 0,
|
||||
coupons: 0,
|
||||
products: 0
|
||||
})
|
||||
|
||||
const nextRequestToken = (key: keyof typeof requestTokens) => {
|
||||
requestTokens[key] += 1
|
||||
return requestTokens[key]
|
||||
}
|
||||
|
||||
const isLatestRequestToken = (key: keyof typeof requestTokens, token: number) => requestTokens[key] === token
|
||||
|
||||
const viewFormState = reactive({
|
||||
shopId: undefined,
|
||||
@@ -593,6 +665,7 @@ const canManageAvailableCoupons = () => {
|
||||
const isCouponSelectionDisabled = computed(() => !canManageAvailableCoupons())
|
||||
|
||||
const fetchShops = async () => {
|
||||
const requestToken = nextRequestToken('shops')
|
||||
loadingShops.value = true
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
@@ -600,11 +673,16 @@ const fetchShops = async () => {
|
||||
// 检查用户类型和权限
|
||||
if (currentUser && currentUser.type === 3 && currentUser.shopId) {
|
||||
// 美甲师直接使用自己的店铺ID,不需要获取店铺列表
|
||||
shops.value = []
|
||||
formState.shopId = currentUser.shopId
|
||||
if (isLatestRequestToken('shops', requestToken)) {
|
||||
shops.value = []
|
||||
formState.shopId = currentUser.shopId
|
||||
}
|
||||
} else {
|
||||
const response = await adminShopApi.listAllShops() as any
|
||||
const res = response || []
|
||||
if (!isLatestRequestToken('shops', requestToken)) {
|
||||
return
|
||||
}
|
||||
// 根据用户权限控制店铺列表的显示
|
||||
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
|
||||
// 如果是店长,只显示用户所属的店铺
|
||||
@@ -620,11 +698,14 @@ const fetchShops = async () => {
|
||||
// 权限不足时不显示错误提示
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
loadingShops.value = false
|
||||
if (isLatestRequestToken('shops', requestToken)) {
|
||||
loadingShops.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchTags = async (shopId?: IdType) => {
|
||||
const requestToken = nextRequestToken('tags')
|
||||
loadingTags.value = true
|
||||
try {
|
||||
let response
|
||||
@@ -633,25 +714,36 @@ const fetchTags = async (shopId?: IdType) => {
|
||||
} else {
|
||||
response = await adminTagApi.listAllTags() as any
|
||||
}
|
||||
if (!isLatestRequestToken('tags', requestToken)) {
|
||||
return
|
||||
}
|
||||
tags.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取标签列表失败', error)
|
||||
message.error('获取标签列表失败')
|
||||
} finally {
|
||||
loadingTags.value = false
|
||||
if (isLatestRequestToken('tags', requestToken)) {
|
||||
loadingTags.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchArtists = async (shopId?: IdType) => {
|
||||
const requestToken = nextRequestToken('artists')
|
||||
loadingArtists.value = true
|
||||
try {
|
||||
const response = await adminArtistApi.listArtists(shopId) as any
|
||||
if (!isLatestRequestToken('artists', requestToken)) {
|
||||
return
|
||||
}
|
||||
artists.value = response || []
|
||||
} catch (error) {
|
||||
console.error('获取美甲师列表失败', error)
|
||||
message.error('获取美甲师列表失败')
|
||||
} finally {
|
||||
loadingArtists.value = false
|
||||
if (isLatestRequestToken('artists', requestToken)) {
|
||||
loadingArtists.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,26 +759,34 @@ const syncAvailableCouponSelection = () => {
|
||||
|
||||
const fetchCoupons = async (shopId?: IdType) => {
|
||||
if (!shopId) {
|
||||
nextRequestToken('coupons')
|
||||
coupons.value = []
|
||||
formState.availableCoupons = []
|
||||
return
|
||||
}
|
||||
|
||||
const requestToken = nextRequestToken('coupons')
|
||||
loadingCoupons.value = true
|
||||
try {
|
||||
const response = await adminCouponApi.listAllCoupons(shopId)
|
||||
const res = typeof response === 'object' && 'data' in response ? response.data : response
|
||||
if (!isLatestRequestToken('coupons', requestToken)) {
|
||||
return
|
||||
}
|
||||
coupons.value = (res as any[]) || []
|
||||
syncAvailableCouponSelection()
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
} finally {
|
||||
loadingCoupons.value = false
|
||||
if (isLatestRequestToken('coupons', requestToken)) {
|
||||
loadingCoupons.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchProductList = async () => {
|
||||
const requestToken = nextRequestToken('products')
|
||||
loading.value = true
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
@@ -701,24 +801,40 @@ const fetchProductList = async () => {
|
||||
}
|
||||
|
||||
const response = await adminProductApi.listProducts(params) as any
|
||||
productList.value = response?.list || []
|
||||
if (!isLatestRequestToken('products', requestToken)) {
|
||||
return
|
||||
}
|
||||
const nextProducts = response?.list || []
|
||||
productList.value = nextProducts
|
||||
pagination.total = response?.total || 0
|
||||
|
||||
await loadImageUrls(response?.list || [])
|
||||
|
||||
const nextImageUrls = await loadImageUrls(nextProducts, requestToken)
|
||||
if (nextImageUrls && isLatestRequestToken('products', requestToken)) {
|
||||
imageUrls.value = nextImageUrls
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取作品列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
if (isLatestRequestToken('products', requestToken)) {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const loadImageUrls = async (products: Product[]) => {
|
||||
const loadImageUrls = async (products: Product[], requestToken?: number) => {
|
||||
const nextImageUrls: Record<string, string[]> = {}
|
||||
for (const product of products) {
|
||||
if (requestToken && !isLatestRequestToken('products', requestToken)) {
|
||||
return null
|
||||
}
|
||||
if (product.imageFileIds) {
|
||||
const ids = product.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
if (requestToken && !isLatestRequestToken('products', requestToken)) {
|
||||
return null
|
||||
}
|
||||
if (id) {
|
||||
try {
|
||||
// 检查缓存
|
||||
@@ -735,14 +851,15 @@ const loadImageUrls = async (products: Product[]) => {
|
||||
}
|
||||
|
||||
if (product.id) {
|
||||
imageUrls.value[String(product.id)] = urls
|
||||
nextImageUrls[String(product.id)] = urls
|
||||
}
|
||||
} else {
|
||||
if (product.id) {
|
||||
imageUrls.value[String(product.id)] = [DEFAULT_PRODUCT_IMAGE]
|
||||
nextImageUrls[String(product.id)] = [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
}
|
||||
}
|
||||
return nextImageUrls
|
||||
}
|
||||
|
||||
const getProductImages = (product: Product | Record<string, any>): string[] => {
|
||||
|
||||
Reference in New Issue
Block a user