Index.vue 3.36 KB
<!--
 * @Date: 2025-12-19 15:40:34
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2025-12-19 16:00:08
 * @FilePath: /mlaj/src/views/recall/Index.vue
 * @Description: 文件描述
-->
<template>
  <div class="min-h-screen bg-[#F0FBF9] flex flex-col items-center pt-20 pb-10 px-6 relative overflow-hidden">
    <!-- 头像 -->
    <div class="relative mb-6">
        <img
            :src="userAvatar || defaultAvatar"
            class="w-24 h-24 rounded-full border-4 border-white shadow-lg object-cover"
            alt="User Avatar"
        />
    </div>

    <!-- 欢迎语 -->
    <h1 class="text-2xl font-bold text-[#1A3B34] mb-2">{{ userName }}</h1>
    <h2 class="text-xl font-bold text-[#1A3B34] mb-4">欢迎回归美乐爱觉宇宙</h2>
    <p class="text-slate-500 text-sm mb-12">您与Behalo的故事从这里开始</p>

    <!-- 时间卡片 -->
    <div class="bg-white rounded-3xl p-8 shadow-xl w-full max-w-sm text-center mb-auto relative z-10">
      <p class="text-slate-500 mb-4">您加入Behalo的时间</p>
      <div class="text-3xl font-bold text-[#1A3B34] mb-4 tracking-wide">{{ joinDateFormatted }}</div>
      <div class="text-slate-500">
        已有 <span class="text-[#1A3B34] font-bold text-lg">{{ durationString }}</span>
      </div>
    </div>

    <!-- 底部引导 -->
    <div class="flex flex-col items-center mt-12 animate-bounce cursor-pointer">
      <ChevronDoubleDownIcon class="w-6 h-6 text-[#4ADE80] mb-2" />
      <span class="text-[#4ADE80] font-medium text-sm">向上滑动,探索更多历程</span>
    </div>
  </div>
</template>

<script setup>
import { computed, onMounted } from 'vue';
import { useAuth } from '@/contexts/auth';
import { ChevronDoubleDownIcon } from '@heroicons/vue/24/solid';
import dayjs from 'dayjs';

// 状态
const { currentUser } = useAuth();
// 使用一个通用的默认头像URL,实际项目中应替换为本地资源或配置的默认图
const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/default_avatar.png';

const userAvatar = computed(() => {
    let avatar = currentUser.value?.avatar;
    if (avatar && avatar.includes('cdn.ipadbiz.cn')) {
        avatar += '?imageMogr2/thumbnail/200x/strip/quality/70';
    }
    return avatar;
});

const userName = computed(() => currentUser.value?.name || '旅行者');

// 加入时间逻辑
// 优先使用 created_at,如果没有则尝试 reg_time,最后回退到当前时间(防止报错)
const joinDate = computed(() => {
    return currentUser.value?.created_at || currentUser.value?.reg_time || new Date();
});

const joinDateFormatted = computed(() => {
    return dayjs(joinDate.value).format('YYYY年M月D日');
});

const durationString = computed(() => {
    const start = dayjs(joinDate.value);
    const now = dayjs();
    const years = now.diff(start, 'year');
    const months = now.diff(start, 'month') % 12;

    // 如果不满一个月,显示天数
    if (years === 0 && months === 0) {
        const days = now.diff(start, 'day');
        return `${days} 天`;
    }

    if (years > 0) {
        return `${years} 年 ${months} 个月`;
    } else {
        return `${months} 个月`;
    }
});

onMounted(() => {
    // 调试用,确认用户信息字段
    console.log('Recall Page - Current User:', currentUser.value);
});
</script>

<style scoped>
/* 针对不同屏幕尺寸的微调可以放在这里,或者直接使用 Tailwind */
</style>