功能:支持后台编辑作品点赞收藏数

This commit is contained in:
xiaowang
2026-03-30 10:23:23 +08:00
parent f323356470
commit 184e1ffe4b
4 changed files with 129 additions and 0 deletions
+74
View File
@@ -182,6 +182,26 @@
placeholder="请输入价格"
/>
</a-form-item>
<a-form-item label="点赞数" name="likeCount">
<a-input-number
v-model:value="formState.likeCount"
:min="0"
:precision="0"
:step="1"
style="width: 100%"
placeholder="请输入点赞数量"
/>
</a-form-item>
<a-form-item label="收藏数" name="collectCount">
<a-input-number
v-model:value="formState.collectCount"
:min="0"
:precision="0"
:step="1"
style="width: 100%"
placeholder="请输入收藏数量"
/>
</a-form-item>
<a-form-item label="预计时长" name="approximateDuration">
<a-input-number
v-model:value="formState.approximateDuration"
@@ -338,6 +358,20 @@
style="width: 100%"
/>
</a-form-item>
<a-form-item label="点赞数">
<a-input-number
v-model:value="viewFormState.likeCount"
:disabled="true"
style="width: 100%"
/>
</a-form-item>
<a-form-item label="收藏数">
<a-input-number
v-model:value="viewFormState.collectCount"
:disabled="true"
style="width: 100%"
/>
</a-form-item>
<a-form-item label="预计时长">
<a-input-number
v-model:value="viewFormState.approximateDuration"
@@ -451,6 +485,8 @@ const viewFormState = reactive({
description: '',
imageFileIds: '',
price: 0,
likeCount: 0,
collectCount: 0,
tags: [] as string[],
approximateDuration: undefined,
bookableArtists: [] as string[],
@@ -472,16 +508,30 @@ const formState = reactive({
description: '',
imageFileIds: '',
price: 0,
likeCount: 0,
collectCount: 0,
tags: [] as string[],
approximateDuration: undefined,
bookableArtists: [] as string[],
availableCoupons: [] as string[]
})
const validateInteractionCount = async (_rule: any, value: number | undefined) => {
if (value === undefined || value === null) {
return Promise.resolve()
}
if (!Number.isInteger(Number(value)) || Number(value) < 0) {
return Promise.reject('请输入大于等于 0 的整数')
}
return Promise.resolve()
}
const formRules: any = {
title: [{ required: true, message: '请输入作品名称', trigger: 'blur' }],
description: [{ required: true, message: '请输入作品描述', trigger: 'blur' }],
price: [{ required: true, message: '请输入价格', trigger: 'blur' }],
likeCount: [{ validator: validateInteractionCount, trigger: 'change' }],
collectCount: [{ validator: validateInteractionCount, trigger: 'change' }],
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
tags: [{ required: true, message: '请选择标签', trigger: 'change' }],
bookableArtists: [{ required: true, message: '请选择美甲师', trigger: 'change' }]
@@ -513,6 +563,14 @@ const normalizeShopIdValue = (value: string | number | undefined | null) => {
return String(value)
}
const normalizeInteractionCount = (value: unknown) => {
const numericValue = Number(value)
if (!Number.isFinite(numericValue) || numericValue < 0) {
return 0
}
return Math.floor(numericValue)
}
const getCurrentUserInfo = () => {
try {
const userInfoStr = localStorage.getItem('adminUserInfo')
@@ -718,6 +776,8 @@ const showAddModal = async () => {
description: '',
imageFileIds: '',
price: 0,
likeCount: 0,
collectCount: 0,
tags: [],
approximateDuration: '',
bookableArtists: [],
@@ -743,6 +803,8 @@ const showEditModal = async (record: Product | Record<string, any>) => {
const recordDescription = 'description' in record ? record.description : (record as any).description
const recordImageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
const recordPrice = 'price' in record ? record.price : (record as any).price
const recordLikeCount = 'likeCount' in record ? record.likeCount : (record as any).likeCount
const recordCollectCount = 'collectCount' in record ? record.collectCount : (record as any).collectCount
const recordTags = 'tags' in record ? record.tags : (record as any).tags
const recordApproximateDuration = 'approximateDuration' in record ? record.approximateDuration : (record as any).approximateDuration
const recordBookableArtists = 'bookableArtists' in record ? record.bookableArtists : (record as any).bookableArtists
@@ -763,6 +825,8 @@ const showEditModal = async (record: Product | Record<string, any>) => {
description: recordDescription,
imageFileIds: recordImageFileIds,
price: recordPrice,
likeCount: normalizeInteractionCount(recordLikeCount),
collectCount: normalizeInteractionCount(recordCollectCount),
tags: tagsArray,
approximateDuration: durationNumber,
bookableArtists: artistsArray,
@@ -794,6 +858,8 @@ const showViewModal = async (record: Product | Record<string, any>) => {
const recordDescription = 'description' in record ? record.description : (record as any).description
const recordImageFileIds = 'imageFileIds' in record ? record.imageFileIds : (record as any).imageFileIds
const recordPrice = 'price' in record ? record.price : (record as any).price
const recordLikeCount = 'likeCount' in record ? record.likeCount : (record as any).likeCount
const recordCollectCount = 'collectCount' in record ? record.collectCount : (record as any).collectCount
const recordTags = 'tags' in record ? record.tags : (record as any).tags
const recordApproximateDuration = 'approximateDuration' in record ? record.approximateDuration : (record as any).approximateDuration
const recordBookableArtists = 'bookableArtists' in record ? record.bookableArtists : (record as any).bookableArtists
@@ -814,6 +880,8 @@ const showViewModal = async (record: Product | Record<string, any>) => {
description: recordDescription,
imageFileIds: recordImageFileIds,
price: recordPrice,
likeCount: normalizeInteractionCount(recordLikeCount),
collectCount: normalizeInteractionCount(recordCollectCount),
tags: tagsArray,
approximateDuration: durationNumber,
bookableArtists: artistsArray,
@@ -870,6 +938,8 @@ const buildDraftPayload = () => ({
description: formState.description,
imageFileIds: formState.imageFileIds,
price: formState.price,
likeCount: formState.likeCount,
collectCount: formState.collectCount,
tags: [...formState.tags],
approximateDuration: formState.approximateDuration,
bookableArtists: [...formState.bookableArtists],
@@ -915,6 +985,8 @@ const restoreDraft = async () => {
}
Object.assign(formState, draft.payload.formState)
formState.likeCount = normalizeInteractionCount(formState.likeCount)
formState.collectCount = normalizeInteractionCount(formState.collectCount)
syncUploadedFileIds(draft.payload.uploadedFileIds || [])
imageFileList.value = await buildImageFileListByIds(uploadedFileIds.value)
draftSavedAt.value = draft.savedAt
@@ -1115,6 +1187,8 @@ const handleModalOk = async () => {
const requestData = {
...formState,
imageFileIds: uploadedFileIds.value.join(','),
likeCount: normalizeInteractionCount(formState.likeCount),
collectCount: normalizeInteractionCount(formState.collectCount),
tags: tagsString,
bookableArtists: artistsString,
availableCoupons: couponsString,