后台管理功能进行一些优化
This commit is contained in:
@@ -61,6 +61,9 @@
|
||||
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showViewModal(record)">
|
||||
查看
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('product:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
@@ -241,6 +244,117 @@
|
||||
</template>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<!-- 查看商品详情模态框 -->
|
||||
<a-modal
|
||||
v-model:open="viewModalVisible"
|
||||
title="查看商品详情"
|
||||
width="700px"
|
||||
@cancel="handleViewModalCancel"
|
||||
>
|
||||
<a-form
|
||||
:model="viewFormState"
|
||||
:label-col="{ span: 5 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<a-form-item label="商品名称">
|
||||
<a-input v-model:value="viewFormState.title" :disabled="true" />
|
||||
</a-form-item>
|
||||
<a-form-item label="商品描述">
|
||||
<a-textarea
|
||||
v-model:value="viewFormState.description"
|
||||
:rows="3"
|
||||
:disabled="true"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺">
|
||||
<a-select v-model:value="viewFormState.shopId" :disabled="true">
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="商品图片">
|
||||
<div class="product-images">
|
||||
<a-image
|
||||
v-for="(url, index) in viewImageUrls"
|
||||
:key="index"
|
||||
:width="80"
|
||||
:height="80"
|
||||
:src="url"
|
||||
style="object-fit: cover; border-radius: 4px; margin-right: 8px; margin-bottom: 8px;"
|
||||
:preview="false"
|
||||
/>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item label="价格">
|
||||
<a-input-number
|
||||
v-model:value="viewFormState.price"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="预计时长">
|
||||
<a-input-number
|
||||
v-model:value="viewFormState.approximateDuration"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="标签">
|
||||
<a-select
|
||||
v-model:value="viewFormState.tags"
|
||||
mode="multiple"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="tag in tags"
|
||||
:key="tag.id"
|
||||
:value="tag.id.toString()"
|
||||
>
|
||||
{{ tag.tagName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="可预约美甲师">
|
||||
<a-select
|
||||
v-model:value="viewFormState.bookableArtists"
|
||||
mode="multiple"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="artist in artists"
|
||||
:key="artist.id"
|
||||
:value="artist.id.toString()"
|
||||
>
|
||||
{{ artist.nickname }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="可用优惠券">
|
||||
<a-select
|
||||
v-model:value="viewFormState.availableCoupons"
|
||||
mode="multiple"
|
||||
:disabled="true"
|
||||
style="width: 100%"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="coupon in coupons"
|
||||
:key="coupon?.id"
|
||||
:value="coupon?.id?.toString()"
|
||||
>
|
||||
{{ coupon?.couponName || '' }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -258,6 +372,7 @@ const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const productList = ref<Product[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const viewModalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const currentProduct = ref<Product | null>(null)
|
||||
@@ -274,10 +389,23 @@ const previewImage = ref('')
|
||||
const imageFileList = ref<any[]>([])
|
||||
const uploadedFileIds = ref<string[]>([])
|
||||
const imageUrls = ref<Record<number, string[]>>({})
|
||||
const viewImageUrls = ref<string[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const isAdmin = ref(false)
|
||||
const formRef = ref<any>(null)
|
||||
|
||||
const viewFormState = reactive({
|
||||
shopId: undefined,
|
||||
title: '',
|
||||
description: '',
|
||||
imageFileIds: '',
|
||||
price: 0,
|
||||
tags: [] as string[],
|
||||
approximateDuration: undefined,
|
||||
bookableArtists: [] as string[],
|
||||
availableCoupons: [] as string[]
|
||||
})
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 10,
|
||||
@@ -585,6 +713,64 @@ const showEditModal = async (record: Product) => {
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showViewModal = async (record: Product) => {
|
||||
// 处理标签
|
||||
const tagsArray = record.tags ? record.tags.split(';').filter(tag => tag) : []
|
||||
// 处理美甲师
|
||||
const artistsArray = record.bookableArtists ? record.bookableArtists.split(',').filter(artist => artist) : []
|
||||
// 处理优惠券
|
||||
const couponsArray = record.availableCoupons ? record.availableCoupons.split(',').filter(coupon => coupon) : []
|
||||
// 处理预计时长,将字符串转换为数字
|
||||
const durationNumber = record.approximateDuration ? parseInt(record.approximateDuration.replace('分钟', '')) : undefined
|
||||
|
||||
Object.assign(viewFormState, {
|
||||
shopId: record.shopId,
|
||||
title: record.title,
|
||||
description: record.description,
|
||||
imageFileIds: record.imageFileIds,
|
||||
price: record.price,
|
||||
tags: tagsArray,
|
||||
approximateDuration: durationNumber,
|
||||
bookableArtists: artistsArray,
|
||||
availableCoupons: couponsArray
|
||||
})
|
||||
|
||||
// 加载图片URL
|
||||
if (record.imageFileIds) {
|
||||
const ids = record.imageFileIds.split(',')
|
||||
const urls: string[] = []
|
||||
|
||||
for (const id of ids) {
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[id]) {
|
||||
const signedUrl = await adminFileApi.getSignedUrl(Number(id))
|
||||
imageIdCache.value[id] = signedUrl
|
||||
}
|
||||
urls.push(imageIdCache.value[id])
|
||||
} catch (error) {
|
||||
console.error('获取签名链接失败:', error)
|
||||
urls.push(DEFAULT_PRODUCT_IMAGE)
|
||||
}
|
||||
}
|
||||
viewImageUrls.value = urls
|
||||
} else {
|
||||
viewImageUrls.value = [DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
// 获取该店铺的美甲师列表
|
||||
if (record.shopId) {
|
||||
await fetchArtists(record.shopId)
|
||||
}
|
||||
|
||||
viewModalVisible.value = true
|
||||
}
|
||||
|
||||
const handleViewModalCancel = () => {
|
||||
viewModalVisible.value = false
|
||||
viewImageUrls.value = []
|
||||
}
|
||||
|
||||
const beforeUpload = (file: File) => {
|
||||
const isImage = file.type.startsWith('image/')
|
||||
if (!isImage) {
|
||||
|
||||
Reference in New Issue
Block a user