feat: 编写首页

This commit is contained in:
砂糖
2025-08-09 17:59:00 +08:00
parent 7e160a1623
commit ee01e075cd
5 changed files with 739 additions and 1122 deletions

View File

@@ -0,0 +1,88 @@
<template>
<div class="user-greeting-row">
<img :src="avatar" class="user-avatar" alt="用户头像" />
<div class="greeting-text">
<div class="greeting-title">{{ greeting }}{{ name }}</div>
<div class="greeting-desc">愿你天黑有灯下雨有伞</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import useUserStore from '@/store/modules/user';
// 接收父组件传递的props可选也可内部获取
const props = defineProps({
// 允许父组件自定义问候语描述
greetingDesc: {
type: String,
default: '愿你天黑有灯,下雨有伞'
}
});
// 响应式数据
const avatar = ref('');
const name = ref('');
const greeting = ref('');
// 用户Store
const userStore = useUserStore();
// 获取问候语
const getGreeting = () => {
const hour = new Date().getHours();
if (hour < 6) return '凌晨好';
if (hour < 9) return '早上好';
if (hour < 12) return '上午好';
if (hour < 14) return '中午好';
if (hour < 18) return '下午好';
if (hour < 21) return '晚上好';
return '夜深了';
};
// 生命周期钩子
onMounted(() => {
// 从用户Store获取用户信息
avatar.value = userStore.avatar;
name.value = userStore.name;
// 获取问候语
greeting.value = getGreeting();
});
</script>
<style scoped>
.user-greeting-row {
display: flex;
align-items: center;
gap: 24px;
margin-bottom: 24px;
}
.user-avatar {
width: 80px;
height: 80px;
border-radius: 50%;
object-fit: cover;
border: 2px solid #e0e0e0;
background: #fff;
}
.greeting-text {
display: flex;
flex-direction: column;
justify-content: center;
}
.greeting-title {
font-size: 28px;
font-weight: 600;
color: #333;
}
.greeting-desc {
font-size: 16px;
color: #888;
margin-top: 4px;
}
</style>

File diff suppressed because it is too large Load Diff