ActivityCard.vue 2.98 KB
<!--
 * @Date: 2025-04-17 13:16:20
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2025-04-17 13:16:22
 * @FilePath: /reading-club-app/src/components/shared/ActivityCard.vue
 * @Description: 文件描述
-->
<template>
  <router-link
    :to="`/activity/${activity.id}`"
    class="block bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition duration-200"
  >
    <div class="relative pb-48 overflow-hidden">
      <img
        :src="activity.cover_image"
        :alt="activity.title"
        class="absolute inset-0 h-full w-full object-cover"
      />
      <div
        v-if="activity.tags && activity.tags.length"
        class="absolute top-0 left-0 p-4 flex flex-wrap gap-2"
      >
        <span
          v-for="tag in activity.tags"
          :key="tag"
          class="px-3 py-1 text-sm bg-green-500 text-white rounded-full"
        >
          {{ tag }}
        </span>
      </div>
    </div>

    <div class="p-6">
      <h3 class="text-xl font-semibold text-gray-800 mb-2">{{ activity.title }}</h3>
      <p class="text-gray-600 text-sm mb-4 line-clamp-2">{{ activity.description }}</p>

      <div class="flex items-center text-sm text-gray-500 mb-4">
        <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
        </svg>
        <span>{{ formatDateTime(activity.start_time) }}</span>
      </div>

      <div class="flex items-center text-sm text-gray-500 mb-4">
        <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
        </svg>
        <span>{{ activity.location }}</span>
      </div>

      <div class="flex items-center justify-between">
        <div class="flex items-center">
          <img
            :src="activity.organizer_avatar"
            :alt="activity.organizer_name"
            class="w-8 h-8 rounded-full mr-2"
          />
          <span class="text-sm text-gray-600">{{ activity.organizer_name }}</span>
        </div>
        <span class="text-sm font-medium text-green-500">
          {{ activity.participant_count }}人参与
        </span>
      </div>
    </div>
  </router-link>
</template>

<script setup>
import { defineProps } from 'vue'

const props = defineProps({
  activity: {
    type: Object,
    required: true
  }
})

// 格式化日期时间
const formatDateTime = (dateTimeStr) => {
  const date = new Date(dateTimeStr.replace(' ', 'T'))
  return new Intl.DateTimeFormat('zh-CN', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit'
  }).format(date)
}
</script>