feat: add BaseUserAvatar and unify avatar usage

This commit is contained in:
Tim
2025-09-24 00:26:51 +08:00
parent 26d1db79f4
commit efbb83924b
15 changed files with 263 additions and 91 deletions

View File

@@ -85,14 +85,15 @@
</div>
<div class="article-member-avatars-container">
<NuxtLink
<BaseUserAvatar
v-for="member in article.members"
:key="`${article.id}-${member.id}`"
class="article-member-avatar-item"
:to="`/users/${member.id}`"
>
<BaseImage class="article-member-avatar-item-img" :src="member.avatar" alt="avatar" />
</NuxtLink>
:user-id="member.id"
:avatar="member.avatar"
:username="member.username"
:width="25"
/>
</div>
<div class="article-comments main-info-text">
@@ -291,7 +292,11 @@ const {
description: p.content,
category: p.category,
tags: p.tags || [],
members: (p.participants || []).map((m) => ({ id: m.id, avatar: m.avatar })),
members: (p.participants || []).map((m) => ({
id: m.id,
avatar: m.avatar,
username: m.username,
})),
comments: p.commentCount,
views: p.views,
rssExcluded: p.rssExcluded || false,
@@ -333,7 +338,11 @@ const fetchNextPage = async () => {
description: p.content,
category: p.category,
tags: p.tags || [],
members: (p.participants || []).map((m) => ({ id: m.id, avatar: m.avatar })),
members: (p.participants || []).map((m) => ({
id: m.id,
avatar: m.avatar,
username: m.username,
})),
comments: p.commentCount,
views: p.views,
rssExcluded: p.rssExcluded || false,
@@ -383,7 +392,6 @@ watch([selectedCategory, selectedTags], ([newCategory, newTags]) => {
selectedCategoryGlobal.value = newCategory
selectedTagsGlobal.value = newTags
})
</script>
<style scoped>
@@ -631,14 +639,7 @@ watch([selectedCategory, selectedTags], ([newCategory, newTags]) => {
.article-member-avatar-item {
width: 25px;
height: 25px;
border-radius: 50%;
overflow: hidden;
}
.article-member-avatar-item-img {
width: 100%;
height: 100%;
object-fit: cover;
flex-shrink: 0;
}
.placeholder-container {

View File

@@ -44,7 +44,13 @@
<div v-if="item.replyTo" class="reply-preview info-content-text">
<div class="reply-header">
<next class="reply-icon" />
<BaseImage class="reply-avatar" :src="item.replyTo.sender.avatar" alt="avatar" />
<BaseUserAvatar
class="reply-avatar"
:user-id="item.replyTo.sender.id"
:avatar="item.replyTo.sender.avatar"
:username="item.replyTo.sender.username"
:width="20"
/>
<div class="reply-author">{{ item.replyTo.sender.username }}:</div>
</div>
<div class="reply-content" v-html="renderMarkdown(item.replyTo.content)"></div>
@@ -242,6 +248,8 @@ async function fetchMessages(page = 0) {
const newMessages = pageData.content.reverse().map((item) => ({
...item,
userId: item.sender.id,
userName: item.sender.username,
src: item.sender.avatar,
iconClick: () => {
openUser(item.sender.id)
@@ -327,6 +335,8 @@ async function sendMessage(content, clearInput) {
const newMessage = await response.json()
messages.value.push({
...newMessage,
userId: newMessage.sender.id,
userName: newMessage.sender.username,
src: newMessage.sender.avatar,
iconClick: () => {
openUser(newMessage.sender.id)
@@ -402,6 +412,8 @@ const subscribeToConversation = () => {
messages.value.push({
...parsedMessage,
userId: parsedMessage.sender.id,
userName: parsedMessage.sender.username,
src: parsedMessage.sender.avatar,
iconClick: () => openUser(parsedMessage.sender.id),
})

View File

@@ -33,11 +33,23 @@
@click="goToConversation(convo.id)"
>
<div class="conversation-avatar">
<BaseImage
:src="getOtherParticipant(convo)?.avatar || '/default-avatar.svg'"
:alt="getOtherParticipant(convo)?.username || '用户'"
<BaseUserAvatar
v-if="getOtherParticipant(convo)"
class="avatar-img"
@error="handleAvatarError"
:user-id="getOtherParticipant(convo).id"
:avatar="getOtherParticipant(convo).avatar"
:username="getOtherParticipant(convo).username"
:width="40"
@click.stop
/>
<BaseUserAvatar
v-else
class="avatar-img"
:user-id="convo.id"
:avatar="''"
username="用户"
:width="40"
:link="false"
/>
</div>
@@ -431,7 +443,6 @@ function minimize() {
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
}
.conversation-content {

View File

@@ -46,10 +46,14 @@
</div>
<div class="info-content-container author-info-container">
<div class="user-avatar-container" @click="gotoProfile">
<div class="user-avatar-item">
<BaseImage class="user-avatar-item-img" :src="author.avatar" alt="avatar" />
</div>
<div class="user-avatar-container">
<BaseUserAvatar
class="user-avatar-item"
:user-id="author.id"
:avatar="author.avatar"
:username="author.username"
:width="50"
/>
<div v-if="isMobile" class="info-content-header">
<div class="user-name">
{{ author.username }}
@@ -340,6 +344,7 @@ const mapComment = (
iconClick: () => navigateTo(`/users/${c.author.id}`),
parentUserName: parentUserName,
parentUserAvatar: parentUserAvatar,
parentUserId: parentUserId,
parentUserClick: parentUserId ? () => navigateTo(`/users/${parentUserId}`) : null,
})
@@ -379,6 +384,7 @@ const mapChangeLog = (l) => ({
id: l.id,
kind: 'log',
username: l.username,
userId: l.userId ?? l.username,
userAvatar: l.userAvatar,
type: l.type,
createdAt: l.time,
@@ -863,10 +869,6 @@ const jumpToHashComment = async () => {
}
}
const gotoProfile = () => {
navigateTo(`/users/${author.value.id}`, { replace: true })
}
const initPage = async () => {
scrollTo(0, 0)
await fetchTimeline()
@@ -960,6 +962,8 @@ onMounted(async () => {
.user-avatar-container {
display: flex;
flex-direction: row;
align-items: center;
gap: 10px;
}
.scroller-middle {
@@ -1172,18 +1176,13 @@ onMounted(async () => {
}
.user-avatar-container {
cursor: pointer;
cursor: default;
}
.user-avatar-item {
width: 50px;
height: 50px;
}
.user-avatar-item-img {
width: 100%;
height: 100%;
border-radius: 50%;
flex-shrink: 0;
}
.info-content {

View File

@@ -7,7 +7,13 @@
<div v-else>
<div class="profile-page-header">
<div class="profile-page-header-avatar">
<BaseImage :src="user.avatar" alt="avatar" class="profile-page-header-avatar-img" />
<BaseUserAvatar
class="profile-page-header-avatar-img"
:user-id="user.id"
:avatar="user.avatar"
:username="user.username"
:width="200"
/>
</div>
<div class="profile-page-header-user-info">
<div class="profile-page-header-user-info-name">{{ user.username }}</div>
@@ -651,8 +657,6 @@ watch(selectedTab, async (val) => {
.profile-page-header-avatar-img {
width: 200px;
height: 200px;
border-radius: 50%;
object-fit: cover;
}
.profile-page-header-user-info {