fix:rating

This commit is contained in:
zzc
2026-06-08 06:47:04 +08:00
parent ada774a142
commit 27c244f3cd
2 changed files with 47 additions and 20 deletions

View File

@@ -42,4 +42,14 @@ export const fetchTopicRatingItems = async (itemId) => {
url: `/api/rating/topic/item/detail/${itemId}`, url: `/api/rating/topic/item/detail/${itemId}`,
method: "GET", method: "GET",
}); });
};
// 添加评分项
// data = { topicId: 'xxx', name: 'xxx', avatarUrl: 'xxx' }
export const topicItemAdd = async (data) => {
return request({
url: "/api/rating/topic/item/add",
method: "POST",
data,
});
}; };

View File

@@ -161,7 +161,8 @@ import { fetchTopicDetail, fetchTopicRatingItems } from "@/api/topic";
import { FILE_BASE_URL } from "@/utils/constants"; import { FILE_BASE_URL } from "@/utils/constants";
import RatingCard from "@/components/RatingCard/RatingCard.vue"; import RatingCard from "@/components/RatingCard/RatingCard.vue";
import SuccessPopup from "@/components/SuccessPopup/SuccessPopup.vue"; import SuccessPopup from "@/components/SuccessPopup/SuccessPopup.vue";
import { topicItemScore } from "@/api/topicItem"; import { topicItemScore, topicItemAdd } from "@/api/topicItem";
import { uploadImage } from "@/utils/common";
// 状态栏高度处理 // 状态栏高度处理
const statusBarHeight = ref(getStatusBarHeight() || 44); const statusBarHeight = ref(getStatusBarHeight() || 44);
@@ -216,30 +217,46 @@ const chooseAvatar = () => {
}); });
}; };
const confirmAddItem = () => { const confirmAddItem = async () => {
if (!newItem.value.name.trim()) { if (!newItem.value.name.trim()) {
uni.showToast({ title: '请输入名称', icon: 'none' }); uni.showToast({ title: '请输入名称', icon: 'none' });
return; return;
} }
if (!newItem.value.avatar) {
uni.showToast({ title: '请上传头像', icon: 'none' });
return;
}
// 模拟添加 try {
const newRatingItem = { uni.showLoading({ title: '添加中...' });
id: Date.now(),
rank: ratingItems.value.length + 1, // 1. 先通过 uni.uploadFile 上传头像图片
name: newItem.value.name, const uploadRes = await uploadImage(newItem.value.avatar);
avatar: newItem.value.avatar || `https://api.dicebear.com/7.x/avataaars/svg?seed=${Date.now()}`,
score: '0.0', // 2. 将上传成功后的图片 URL 和其他数据一起提交给添加接口
quote: '刚刚加入讨论,快来发表你的看法吧。', await topicItemAdd({
userAction: '' topicId: currentTopicId.value,
}; name: newItem.value.name,
avatarUrl: uploadRes
ratingItems.value.push(newRatingItem); });
// 重置并关闭 uni.hideLoading();
newItem.value = { name: '', avatar: '' }; uni.showToast({ title: '添加成功', icon: 'success' });
showAddPopup.value = false;
// 重置表单并关闭弹窗
uni.showToast({ title: '添加成功', icon: 'success' }); newItem.value = { name: '', avatar: '' };
showAddPopup.value = false;
// 重新加载列表数据
currentPage.value = 1;
hasMore.value = true;
loadItems(currentTopicId.value, 1);
} catch (error) {
uni.hideLoading();
uni.showToast({ title: '添加失败,请重试', icon: 'none' });
console.error('添加评分项失败:', error);
}
}; };
const ratingItems = ref([]); const ratingItems = ref([]);