Files
schoolNews/schoolNewsWeb/src/views/user-center/MyAchievementsView.vue

555 lines
13 KiB
Vue
Raw Normal View History

2025-10-16 18:03:46 +08:00
<template>
<div class="my-achievements">
<div class="achievements-header">
<h2>我的成就</h2>
<div class="achievement-stats">
2025-10-25 17:45:47 +08:00
<div class="stat-item">
<span class="stat-label">已获得</span>
<span class="stat-value">{{ earnedCount }}</span>
<span class="stat-total"> / {{ totalCount }}</span>
</div>
<div class="stat-item">
<span class="stat-label">完成率</span>
<span class="stat-value">{{ completionRate }}%</span>
</div>
2025-10-16 18:03:46 +08:00
</div>
</div>
2025-10-25 17:45:47 +08:00
<!-- 成就类型筛选 -->
<div class="filter-tabs">
<el-radio-group v-model="selectedType" @change="filterAchievements">
<el-radio-button :label="undefined">全部</el-radio-button>
<el-radio-button
v-for="option in achievementTypeOptions"
:key="option.value"
:label="option.value"
>
{{ option.label }}
</el-radio-button>
</el-radio-group>
<el-checkbox v-model="showOnlyEarned" @change="filterAchievements">
仅显示已获得
</el-checkbox>
</div>
<!-- 加载状态 -->
<div v-if="loading" class="loading-container">
<el-skeleton :rows="3" animated />
</div>
<!-- 成就网格 -->
<div v-else class="achievements-grid">
2025-10-16 18:03:46 +08:00
<div
class="achievement-item"
2025-10-25 17:45:47 +08:00
v-for="achievement in filteredAchievements"
:key="achievement.achievementID"
:class="{ earned: achievement.obtained, locked: !achievement.obtained }"
2025-10-16 18:03:46 +08:00
>
<div class="achievement-icon">
2025-10-25 17:45:47 +08:00
<el-image
:src="getIconUrl(achievement.icon)"
:alt="achievement.name"
fit="contain"
>
<template #error>
<div class="image-placeholder">
<el-icon><Trophy /></el-icon>
</div>
</template>
</el-image>
<div class="achievement-badge" v-if="achievement.obtained">
<el-icon><Check /></el-icon>
</div>
<div class="achievement-level" v-if="achievement.level">
Lv.{{ achievement.level }}
</div>
2025-10-16 18:03:46 +08:00
</div>
<div class="achievement-info">
2025-10-25 17:45:47 +08:00
<div class="achievement-header">
<h3>{{ achievement.name }}</h3>
<el-tag
:type="achievement.type === 1 ? 'success' : 'primary'"
size="small"
>
{{ getAchievementTypeLabel(achievement.type) }}
</el-tag>
</div>
2025-10-16 18:03:46 +08:00
<p class="achievement-description">{{ achievement.description }}</p>
2025-10-25 17:45:47 +08:00
<!-- 条件说明 -->
<div class="achievement-condition">
<el-icon><InfoFilled /></el-icon>
<span>{{ formatConditionValue(achievement.conditionType, achievement.conditionValue) }}</span>
</div>
<!-- 进度条 -->
<div class="achievement-progress" v-if="!achievement.obtained">
<div class="progress-info">
<span class="progress-label">进度</span>
<span class="progress-text">
{{ achievement.currentValue || 0 }} / {{ achievement.targetValue || achievement.conditionValue }}
</span>
2025-10-16 18:03:46 +08:00
</div>
2025-10-25 17:45:47 +08:00
<el-progress
:percentage="achievement.progressPercentage || 0"
:color="progressColor"
:show-text="false"
/>
2025-10-16 18:03:46 +08:00
</div>
2025-10-25 17:45:47 +08:00
<!-- 获得信息 -->
<div class="achievement-footer" v-if="achievement.obtained">
<div class="achievement-date">
<el-icon><Calendar /></el-icon>
<span>{{ formatDate(achievement.obtainTime) }}</span>
</div>
<div class="achievement-points" v-if="achievement.points">
<el-icon><Star /></el-icon>
<span>+{{ achievement.points }} 积分</span>
</div>
</div>
<!-- 未获得时显示积分奖励 -->
<div class="achievement-reward" v-else-if="achievement.points">
<el-icon><Present /></el-icon>
<span>奖励 {{ achievement.points }} 积分</span>
2025-10-16 18:03:46 +08:00
</div>
</div>
</div>
</div>
2025-10-25 17:45:47 +08:00
<!-- 空状态 -->
<el-empty
v-if="!loading && filteredAchievements.length === 0"
description="暂无成就数据"
/>
2025-10-16 18:03:46 +08:00
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
2025-10-25 17:45:47 +08:00
import { ElMessage } from 'element-plus';
import { Trophy, Check, InfoFilled, Calendar, Star, Present } from '@element-plus/icons-vue';
import { achievementApi } from '@/apis/achievement';
import type { AchievementVO } from '@/types';
import { AchievementEnumHelper } from '@/types/enums/achievement-enums';
import { PUBLIC_IMG_PATH } from '@/config';
2025-10-16 18:03:46 +08:00
2025-10-25 17:45:47 +08:00
// 响应式数据
const loading = ref(false);
const achievements = ref<AchievementVO[]>([]);
const selectedType = ref<number | undefined>(undefined);
const showOnlyEarned = ref(false);
2025-10-16 18:03:46 +08:00
2025-10-25 17:45:47 +08:00
// 枚举选项
const achievementTypeOptions = AchievementEnumHelper.getAllAchievementTypeOptions();
// 进度条颜色
const progressColor = [
{ color: '#f56c6c', percentage: 30 },
{ color: '#e6a23c', percentage: 60 },
{ color: '#5cb87a', percentage: 100 }
];
// 已获得数量
2025-10-16 18:03:46 +08:00
const earnedCount = computed(() => {
2025-10-25 17:45:47 +08:00
return achievements.value.filter(a => a.obtained).length;
2025-10-16 18:03:46 +08:00
});
2025-10-25 17:45:47 +08:00
// 总数量
2025-10-16 18:03:46 +08:00
const totalCount = computed(() => {
return achievements.value.length;
});
2025-10-25 17:45:47 +08:00
// 完成率
const completionRate = computed(() => {
if (totalCount.value === 0) return 0;
return Math.round((earnedCount.value / totalCount.value) * 100);
});
// 筛选后的成就列表
const filteredAchievements = computed(() => {
let result = achievements.value;
// 按类型筛选
if (selectedType.value !== undefined) {
result = result.filter(a => a.type === selectedType.value);
}
// 仅显示已获得
if (showOnlyEarned.value) {
result = result.filter(a => a.obtained);
}
// 排序:已获得的在前,按等级排序
return result.sort((a, b) => {
if (a.obtained !== b.obtained) {
return a.obtained ? -1 : 1;
}
return (a.level || 0) - (b.level || 0);
});
});
// 获取成就类型标签
function getAchievementTypeLabel(type?: number): string {
if (type === undefined) return '未知';
return AchievementEnumHelper.getAchievementTypeDescription(type);
}
// 格式化条件值显示
function formatConditionValue(conditionType?: number, conditionValue?: number): string {
if (conditionType === undefined || conditionValue === undefined) return '';
return AchievementEnumHelper.formatConditionValue(conditionType, conditionValue);
}
// 格式化日期
function formatDate(dateStr?: string): string {
if (!dateStr) return '';
const date = new Date(dateStr);
return date.toLocaleDateString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit'
});
}
// 获取图标完整路径
function getIconUrl(icon?: string): string {
if (!icon) return '';
// 如果是http或https开头直接返回
if (icon.startsWith('http://') || icon.startsWith('https://')) {
return icon;
}
// 否则拼接默认成就图标路径
const path = `${PUBLIC_IMG_PATH}/achievement`;
return icon.startsWith('/') ? `${path}${icon}` : `${path}/${icon}`;
}
// 筛选成就
function filterAchievements() {
// 触发计算属性重新计算
}
// 加载成就数据
async function loadAchievements() {
try {
loading.value = true;
const result = await achievementApi.getMyAchievements();
achievements.value = result.dataList || [];
} catch (error) {
console.error('加载成就数据失败:', error);
ElMessage.error('加载成就数据失败');
} finally {
loading.value = false;
}
}
2025-10-16 18:03:46 +08:00
onMounted(() => {
2025-10-25 17:45:47 +08:00
loadAchievements();
2025-10-16 18:03:46 +08:00
});
</script>
<style lang="scss" scoped>
.my-achievements {
2025-10-25 17:45:47 +08:00
padding: 20px 0;
2025-10-16 18:03:46 +08:00
.achievements-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 32px;
h2 {
2025-10-25 17:45:47 +08:00
font-size: 28px;
2025-10-16 18:03:46 +08:00
font-weight: 600;
color: #141F38;
2025-10-25 17:45:47 +08:00
margin: 0;
2025-10-16 18:03:46 +08:00
}
}
}
.achievement-stats {
2025-10-25 17:45:47 +08:00
display: flex;
gap: 32px;
2025-10-16 18:03:46 +08:00
2025-10-25 17:45:47 +08:00
.stat-item {
display: flex;
align-items: baseline;
gap: 8px;
.stat-label {
font-size: 14px;
color: #666;
}
.stat-value {
font-size: 24px;
font-weight: 600;
color: #C62828;
}
.stat-total {
font-size: 16px;
color: #999;
}
2025-10-16 18:03:46 +08:00
}
}
2025-10-25 17:45:47 +08:00
.filter-tabs {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24px;
padding: 16px;
background: #f8f9fa;
border-radius: 8px;
}
.loading-container {
padding: 40px 0;
}
2025-10-16 18:03:46 +08:00
.achievements-grid {
display: grid;
2025-10-25 17:45:47 +08:00
grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
2025-10-16 18:03:46 +08:00
gap: 20px;
2025-10-25 17:45:47 +08:00
margin-bottom: 20px;
2025-10-16 18:03:46 +08:00
}
.achievement-item {
display: flex;
gap: 16px;
padding: 20px;
border: 2px solid #e0e0e0;
2025-10-25 17:45:47 +08:00
border-radius: 12px;
2025-10-16 18:03:46 +08:00
transition: all 0.3s;
2025-10-25 17:45:47 +08:00
background: white;
2025-10-16 18:03:46 +08:00
&.earned {
2025-10-25 17:45:47 +08:00
border-color: #52c41a;
background: linear-gradient(135deg, #f6ffed, #ffffff);
2025-10-16 18:03:46 +08:00
.achievement-icon {
2025-10-25 17:45:47 +08:00
:deep(.el-image__inner) {
2025-10-16 18:03:46 +08:00
filter: none;
}
}
}
&.locked {
2025-10-25 17:45:47 +08:00
opacity: 0.75;
2025-10-16 18:03:46 +08:00
.achievement-icon {
2025-10-25 17:45:47 +08:00
:deep(.el-image__inner) {
2025-10-16 18:03:46 +08:00
filter: grayscale(100%);
}
}
}
&:hover.earned {
2025-10-25 17:45:47 +08:00
box-shadow: 0 4px 16px rgba(82, 196, 26, 0.3);
transform: translateY(-2px);
}
&:hover.locked {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
2025-10-16 18:03:46 +08:00
}
}
.achievement-icon {
position: relative;
2025-10-25 17:45:47 +08:00
width: 80px;
height: 80px;
2025-10-16 18:03:46 +08:00
flex-shrink: 0;
2025-10-25 17:45:47 +08:00
:deep(.el-image) {
2025-10-16 18:03:46 +08:00
width: 100%;
height: 100%;
2025-10-25 17:45:47 +08:00
}
.image-placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: #f5f5f5;
border-radius: 8px;
color: #ccc;
font-size: 32px;
2025-10-16 18:03:46 +08:00
}
}
.achievement-badge {
position: absolute;
2025-10-25 17:45:47 +08:00
top: -4px;
2025-10-16 18:03:46 +08:00
right: -4px;
2025-10-25 17:45:47 +08:00
width: 28px;
height: 28px;
background: #52c41a;
2025-10-16 18:03:46 +08:00
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
2025-10-25 17:45:47 +08:00
font-size: 16px;
2025-10-16 18:03:46 +08:00
font-weight: 600;
2025-10-25 17:45:47 +08:00
border: 3px solid white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.achievement-level {
position: absolute;
bottom: -4px;
left: 50%;
transform: translateX(-50%);
padding: 2px 8px;
background: #1890ff;
color: white;
font-size: 12px;
font-weight: 600;
border-radius: 10px;
2025-10-16 18:03:46 +08:00
border: 2px solid white;
2025-10-25 17:45:47 +08:00
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
2025-10-16 18:03:46 +08:00
}
.achievement-info {
flex: 1;
2025-10-25 17:45:47 +08:00
display: flex;
flex-direction: column;
gap: 8px;
2025-10-16 18:03:46 +08:00
2025-10-25 17:45:47 +08:00
.achievement-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
h3 {
font-size: 18px;
font-weight: 600;
color: #141F38;
margin: 0;
flex: 1;
}
2025-10-16 18:03:46 +08:00
}
}
.achievement-description {
font-size: 14px;
color: #666;
2025-10-25 17:45:47 +08:00
line-height: 1.6;
margin: 0;
}
.achievement-condition {
display: flex;
align-items: center;
gap: 6px;
font-size: 13px;
color: #999;
padding: 6px 12px;
background: #fafafa;
border-radius: 6px;
:deep(.el-icon) {
font-size: 14px;
}
2025-10-16 18:03:46 +08:00
}
.achievement-progress {
2025-10-25 17:45:47 +08:00
.progress-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
.progress-label {
font-size: 13px;
color: #666;
font-weight: 500;
}
.progress-text {
font-size: 13px;
color: #1890ff;
font-weight: 600;
}
}
2025-10-16 18:03:46 +08:00
2025-10-25 17:45:47 +08:00
:deep(.el-progress) {
.el-progress-bar__outer {
background-color: #f0f0f0;
}
2025-10-16 18:03:46 +08:00
}
2025-10-25 17:45:47 +08:00
}
.achievement-footer {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 8px;
border-top: 1px solid #f0f0f0;
2025-10-16 18:03:46 +08:00
2025-10-25 17:45:47 +08:00
.achievement-date,
.achievement-points {
display: flex;
align-items: center;
gap: 6px;
font-size: 13px;
color: #666;
:deep(.el-icon) {
font-size: 14px;
}
}
.achievement-points {
color: #faad14;
font-weight: 600;
2025-10-16 18:03:46 +08:00
}
2025-10-25 17:45:47 +08:00
}
.achievement-reward {
display: flex;
align-items: center;
gap: 6px;
font-size: 13px;
color: #faad14;
font-weight: 600;
padding: 6px 12px;
background: #fffbe6;
border-radius: 6px;
2025-10-16 18:03:46 +08:00
2025-10-25 17:45:47 +08:00
:deep(.el-icon) {
font-size: 14px;
2025-10-16 18:03:46 +08:00
}
}
2025-10-25 17:45:47 +08:00
// 响应式设计
@media (max-width: 1200px) {
.achievements-grid {
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}
}
@media (max-width: 768px) {
.achievements-grid {
grid-template-columns: 1fr;
}
.achievement-stats {
flex-direction: column;
gap: 16px;
}
.filter-tabs {
flex-direction: column;
gap: 16px;
align-items: stretch;
}
2025-10-16 18:03:46 +08:00
}
</style>