fix:rating
This commit is contained in:
@@ -43,3 +43,13 @@ export const fetchTopicRatingItems = async (itemId) => {
|
||||
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,
|
||||
});
|
||||
};
|
||||
@@ -161,7 +161,8 @@ import { fetchTopicDetail, fetchTopicRatingItems } from "@/api/topic";
|
||||
import { FILE_BASE_URL } from "@/utils/constants";
|
||||
import RatingCard from "@/components/RatingCard/RatingCard.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);
|
||||
|
||||
@@ -216,30 +217,46 @@ const chooseAvatar = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const confirmAddItem = () => {
|
||||
const confirmAddItem = async () => {
|
||||
if (!newItem.value.name.trim()) {
|
||||
uni.showToast({ title: '请输入名称', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!newItem.value.avatar) {
|
||||
uni.showToast({ title: '请上传头像', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
// 模拟添加
|
||||
const newRatingItem = {
|
||||
id: Date.now(),
|
||||
rank: ratingItems.value.length + 1,
|
||||
try {
|
||||
uni.showLoading({ title: '添加中...' });
|
||||
|
||||
// 1. 先通过 uni.uploadFile 上传头像图片
|
||||
const uploadRes = await uploadImage(newItem.value.avatar);
|
||||
|
||||
// 2. 将上传成功后的图片 URL 和其他数据一起提交给添加接口
|
||||
await topicItemAdd({
|
||||
topicId: currentTopicId.value,
|
||||
name: newItem.value.name,
|
||||
avatar: newItem.value.avatar || `https://api.dicebear.com/7.x/avataaars/svg?seed=${Date.now()}`,
|
||||
score: '0.0',
|
||||
quote: '刚刚加入讨论,快来发表你的看法吧。',
|
||||
userAction: ''
|
||||
};
|
||||
avatarUrl: uploadRes
|
||||
});
|
||||
|
||||
ratingItems.value.push(newRatingItem);
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '添加成功', icon: 'success' });
|
||||
|
||||
// 重置并关闭
|
||||
// 重置表单并关闭弹窗
|
||||
newItem.value = { name: '', avatar: '' };
|
||||
showAddPopup.value = false;
|
||||
|
||||
uni.showToast({ title: '添加成功', icon: 'success' });
|
||||
// 重新加载列表数据
|
||||
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([]);
|
||||
|
||||
Reference in New Issue
Block a user