功能:支持后台编辑作品点赞收藏数
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -44,6 +44,16 @@ public class ProductDTO {
|
||||
*/
|
||||
private String tags;
|
||||
|
||||
/**
|
||||
* 鍟嗗搧鐐硅禐鏁?
|
||||
*/
|
||||
private Integer likeCount;
|
||||
|
||||
/**
|
||||
* 鍟嗗搧鏀惰棌鏁?
|
||||
*/
|
||||
private Integer collectCount;
|
||||
|
||||
/**
|
||||
* 商品对应的服务大约耗时(如"30分钟")
|
||||
*/
|
||||
|
||||
+15
@@ -62,6 +62,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
productDO.setImageFileIds(productDTO.getImageFileIds());
|
||||
productDO.setPrice(productDTO.getPrice());
|
||||
productDO.setTags(productDTO.getTags());
|
||||
productDO.setLikeCount(normalizeInteractionCount(productDTO.getLikeCount()));
|
||||
productDO.setCollectCount(normalizeInteractionCount(productDTO.getCollectCount()));
|
||||
productDO.setApproximateDuration(productDTO.getApproximateDuration());
|
||||
productDO.setBookableArtists(bookableArtistSupport.filterValidBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists()));
|
||||
productDO.setAvailableCoupons(productDTO.getAvailableCoupons());
|
||||
@@ -84,6 +86,12 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
productDO.setImageFileIds(productDTO.getImageFileIds());
|
||||
productDO.setPrice(productDTO.getPrice());
|
||||
productDO.setTags(productDTO.getTags());
|
||||
if (productDTO.getLikeCount() != null) {
|
||||
productDO.setLikeCount(normalizeInteractionCount(productDTO.getLikeCount()));
|
||||
}
|
||||
if (productDTO.getCollectCount() != null) {
|
||||
productDO.setCollectCount(normalizeInteractionCount(productDTO.getCollectCount()));
|
||||
}
|
||||
productDO.setApproximateDuration(productDTO.getApproximateDuration());
|
||||
productDO.setBookableArtists(bookableArtistSupport.filterValidBookableArtists(productDTO.getShopId(), productDTO.getBookableArtists()));
|
||||
productDO.setAvailableCoupons(productDTO.getAvailableCoupons());
|
||||
@@ -348,6 +356,13 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
.count();
|
||||
}
|
||||
|
||||
private Integer normalizeInteractionCount(Integer count) {
|
||||
if (count == null || count < 0) {
|
||||
return 0;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private boolean containsAnyTagId(String tags, Set<String> targetTagIds) {
|
||||
if (!StringUtils.hasText(tags) || targetTagIds == null || targetTagIds.isEmpty()) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# 2026-03-30 后台作品管理支持编辑点赞数与收藏数
|
||||
|
||||
## 本次改动
|
||||
|
||||
- 后台作品管理新增可编辑字段:`点赞数`、`收藏数`。
|
||||
- 作品查看弹窗同步展示点赞数与收藏数,便于运营核对。
|
||||
- 前端表单提交时对点赞数与收藏数做非负整数归一化处理,防止提交负数或小数。
|
||||
- 后端 `ProductDTO` 新增 `likeCount`、`collectCount` 字段,作品创建和更新链路正式接收这两个值。
|
||||
- 后端保存时对点赞数与收藏数做兜底归一化:
|
||||
- 新建作品未传值时默认保存为 `0`
|
||||
- 更新作品时如果传入负数会自动归零
|
||||
- 更新作品时未传该字段则保持原值
|
||||
- 作品编辑暂存逻辑已同步纳入点赞数与收藏数,恢复草稿时不会丢失。
|
||||
|
||||
## 影响范围
|
||||
|
||||
- 前端:`Frontend/src/views/admin/ProductsView.vue`
|
||||
- 后端:
|
||||
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/dto/ProductDTO.java`
|
||||
- `YumiNail-Core/src/main/java/com/xiaowang/yuminailcore/service/impl/ProductServiceImpl.java`
|
||||
|
||||
## SQL 说明
|
||||
|
||||
- 本次无数据库结构变更。
|
||||
- `t_product.like_count`、`t_product.collect_count` 已存在,无需新增 SQL。
|
||||
|
||||
## 验证
|
||||
|
||||
- 前端执行 `npm run build` 通过。
|
||||
- `YumiNail-Core` 执行 `mvn -q -DskipTests compile` 通过。
|
||||
Reference in New Issue
Block a user