This commit is contained in:
李旭明 committed 2025-09-01 16:30:58 +08:00
1 parent 69b73a9373
commit e80446145f
13 files changed
+181 -52

No files matched your search

@@ -90,7 +90,7 @@
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import { ref, computed, onMounted, watch } from 'vue';
import { getActivityRatings } from '@/api/stgl/activity';
import { ActivityRatingVO } from '@/api/stgl/activity/types';
@@ -146,19 +146,23 @@ const formatDateTimeCompact = (dateStr?: string): string => {
// 加载评分数据
const loadRatings = async () => {
if (!props.activityId) return;
if (!props.activityId) {
ratings.value = [];
return;
}
loading.value = true;
try {
console.log('开始加载活动评分数据,活动ID:', props.activityId);
const res = await getActivityRatings(props.activityId);
ratings.value = res.data || [];
console.log('加载的评分数据:', ratings.value);
console.log('成功加载评分数据,活动ID:', props.activityId, '评分数量:', ratings.value.length);
} catch (error: any) {
// 如果是404错误,说明后端暂未实现该功能,静默处理
if (error.response?.status === 404) {
console.log('活动评分功能暂未实现');
console.log('活动评分功能暂未实现,活动ID:', props.activityId);
} else {
console.error('加载评分数据失败:', error);
console.error('加载评分数据失败,活动ID:', props.activityId, '错误:', error);
}
ratings.value = [];
} finally {
@@ -166,9 +170,15 @@ const loadRatings = async () => {
}
};
onMounted(() => {
loadRatings();
});
// 监听 activityId 变化,自动重新加载评分数据
watch(() => props.activityId, (newId, oldId) => {
console.log('活动ID发生变化:', oldId, '->', newId);
if (newId && newId !== oldId) {
loadRatings();
}
}, { immediate: true }); // immediate: true 确保组件挂载时也会执行一次
// 移除 onMounted,因为 watch 的 immediate: true 已经覆盖了这个功能
</script>
<style scoped>