diff --git a/src/components/ActivityCard.vue b/src/components/ActivityCard.vue index 33b7247..02e4ab4 100644 --- a/src/components/ActivityCard.vue +++ b/src/components/ActivityCard.vue @@ -2,10 +2,11 @@
-
+
+ class="w-full h-full object-cover" + @error="handleImageError" />
{{ truncateDescription(activity.activityName, 10) }} @@ -59,15 +60,18 @@ import { defineComponent, computed, defineProps, watch, ref } from 'vue'; import { Icon } from '@iconify/vue'; import config from 'config'; +import { getGradientColor } from '../utils/gradientColors'; -const gradients = { - blue: 'bg-gradient-to-br from-blue-400 to-indigo-600', - green: 'bg-gradient-to-br from-green-400 to-emerald-600', - purple: 'bg-gradient-to-br from-purple-400 to-fuchsia-600', - orange: 'bg-gradient-to-br from-orange-400 to-red-600', - teal: 'bg-gradient-to-br from-teal-400 to-cyan-600', +const isImageValid = ref(true); + +const handleImageError = () => { + isImageValid.value = false; }; +const gradientClass = computed(() => { + return getGradientColor(props.activity); +}); + defineComponent(['Icon']); const props = defineProps({ @@ -109,13 +113,6 @@ watch(() => props.serviceLocation, (newValue) => { }, { deep: true, immediate: true }); const baseURL = config.baseURL; -const gradientClass = computed(() => { - if (props.activity.gradientColor && gradients[props.activity.gradientColor]) { - return gradients[props.activity.gradientColor]; - } - const colors = Object.values(gradients); - return colors[Math.floor(Math.random() * colors.length)]; -}); const getStatusClass = (status) => { switch (status) { diff --git a/src/components/ActivityDetail.vue b/src/components/ActivityDetail.vue index 2de235f..a232cd2 100644 --- a/src/components/ActivityDetail.vue +++ b/src/components/ActivityDetail.vue @@ -1,16 +1,19 @@ \ No newline at end of file diff --git a/src/i18n/locales/en_US.json b/src/i18n/locales/en_US.json index cc7fcda..6cb36fa 100644 --- a/src/i18n/locales/en_US.json +++ b/src/i18n/locales/en_US.json @@ -180,6 +180,29 @@ "duration": "Duration" } }, + "activityDetail": { + "recruitmentStatus": "Recruitment Status", + "activityDuration": "Activity Duration", + "hours": "hours", + "activityDate": "Activity Date", + "activityAddress": "Activity Address", + "copyAddress": "Copy Address", + "showMap": "Show Map", + "hideMap": "Hide Map", + "mapUnavailable": "Map service is currently unavailable", + "organizerInfo": "Organizer Information", + "organizer": "Organizer", + "email": "Email", + "copyEmail": "Copy Email", + "activityDetails": "Activity Details", + "signingUp": "Signing Up...", + "signUpNow": "Sign Up Now", + "signUpSuccess": "Sign up successful", + "signUpFailed": "Sign up failed", + "copySuccess": "Copy successful", + "copyFailed": "Copy failed", + "fetchFailed": "Failed to fetch activity details" + }, "userRecordInquiry": { "stats": { "totalHours": "Total Hours", diff --git a/src/i18n/locales/zh_CN.json b/src/i18n/locales/zh_CN.json index e665cb0..94e244f 100644 --- a/src/i18n/locales/zh_CN.json +++ b/src/i18n/locales/zh_CN.json @@ -179,6 +179,29 @@ "duration": "活动时长" } }, + "activityDetail": { + "recruitmentStatus": "招募人数", + "activityDuration": "活动时间", + "hours": "小时", + "activityDate": "活动日期", + "activityAddress": "活动地址", + "copyAddress": "复制地址", + "showMap": "显示地图", + "hideMap": "隐藏地图", + "mapUnavailable": "地图服务暂不可用", + "organizerInfo": "主办方信息", + "organizer": "举办者", + "email": "邮箱", + "copyEmail": "复制邮箱", + "activityDetails": "活动详情", + "signingUp": "报名中...", + "signUpNow": "立即报名", + "signUpSuccess": "报名成功", + "signUpFailed": "报名失败", + "copySuccess": "复制成功", + "copyFailed": "复制失败", + "fetchFailed": "获取活动详情失败" + }, "userRecordInquiry": { "stats": { "totalHours": "累计时长", diff --git a/src/utils/gradientColors.js b/src/utils/gradientColors.js new file mode 100644 index 0000000..74bafc2 --- /dev/null +++ b/src/utils/gradientColors.js @@ -0,0 +1,38 @@ +// 定义渐变色配置 +export const gradients = { + blue: 'bg-gradient-to-br from-blue-400 to-indigo-600', + green: 'bg-gradient-to-br from-green-400 to-emerald-600', + purple: 'bg-gradient-to-br from-purple-400 to-fuchsia-600', + orange: 'bg-gradient-to-br from-orange-400 to-red-600', + teal: 'bg-gradient-to-br from-teal-400 to-cyan-600', + pink: 'bg-gradient-to-br from-pink-400 to-rose-600', + amber: 'bg-gradient-to-br from-amber-400 to-orange-600', + indigo: 'bg-gradient-to-br from-indigo-400 to-purple-600', + red: 'bg-gradient-to-br from-red-400 to-pink-600', + yellow: 'bg-gradient-to-br from-yellow-400 to-amber-600', +}; + +// 根据字符串生成确定的数字 +export function getHashCode(str) { + let hash = 0; + for (let i = 0; i < str.length; i++) { + const char = str.charCodeAt(i); + hash = (hash << 5) - hash + char; + hash = hash & hash; + } + return Math.abs(hash); +} + +// 根据活动信息获取渐变色 +export function getGradientColor(activity) { + if (!activity) { + return gradients.blue; + } + + const identifier = activity.activityId || activity.activityName || ''; + const hashCode = getHashCode(identifier); + const gradientKeys = Object.keys(gradients); + const index = hashCode % gradientKeys.length; + + return gradients[gradientKeys[index]]; +} \ No newline at end of file