mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-06 23:21:16 +08:00
Merge pull request #1022 from nagisa77/feature/user_list_and_avatar
Feature/user list and avatar
This commit is contained in:
@@ -3,10 +3,18 @@
|
||||
<div class="timeline-item" v-for="(item, idx) in items" :key="idx">
|
||||
<div
|
||||
class="timeline-icon"
|
||||
:class="{ clickable: !!item.iconClick }"
|
||||
@click="item.iconClick && item.iconClick()"
|
||||
:class="{ clickable: !!item.iconClick || hasLink(item) }"
|
||||
@click="onIconClick(item, $event)"
|
||||
>
|
||||
<BaseImage v-if="item.src" :src="item.src" class="timeline-img" alt="timeline item" />
|
||||
<BaseUserAvatar
|
||||
v-if="item.src"
|
||||
:src="item.src"
|
||||
:user-id="item.userId"
|
||||
:to="item.avatarLink"
|
||||
class="timeline-img"
|
||||
alt="timeline item"
|
||||
:disable-link="!hasLink(item) || !!item.iconClick"
|
||||
/>
|
||||
<component
|
||||
v-else-if="item.icon && (typeof item.icon !== 'string' || !item.icon.includes(' '))"
|
||||
:is="item.icon"
|
||||
@@ -22,11 +30,28 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BaseUserAvatar from '~/components/BaseUserAvatar.vue'
|
||||
|
||||
export default {
|
||||
name: 'BaseTimeline',
|
||||
components: { BaseUserAvatar },
|
||||
props: {
|
||||
items: { type: Array, default: () => [] },
|
||||
},
|
||||
methods: {
|
||||
hasLink(item) {
|
||||
if (!item) return false
|
||||
if (item.avatarLink) return true
|
||||
const id = item?.userId
|
||||
return id !== undefined && id !== null && id !== ''
|
||||
},
|
||||
onIconClick(item, event) {
|
||||
if (item && item.iconClick) {
|
||||
event.preventDefault()
|
||||
item.iconClick()
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -66,8 +91,12 @@ export default {
|
||||
.timeline-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.timeline-img :deep(.base-user-avatar-img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.timeline-emoji {
|
||||
|
||||
134
frontend_nuxt/components/BaseUserAvatar.vue
Normal file
134
frontend_nuxt/components/BaseUserAvatar.vue
Normal file
@@ -0,0 +1,134 @@
|
||||
<template>
|
||||
<NuxtLink
|
||||
:to="resolvedLink"
|
||||
class="base-user-avatar"
|
||||
:class="wrapperClass"
|
||||
:style="wrapperStyle"
|
||||
v-bind="wrapperAttrs"
|
||||
>
|
||||
<BaseImage :src="currentSrc" :alt="altText" class="base-user-avatar-img" @error="onError" />
|
||||
</NuxtLink>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useAttrs } from 'vue'
|
||||
import BaseImage from './BaseImage.vue'
|
||||
|
||||
const DEFAULT_AVATAR = '/default-avatar.svg'
|
||||
|
||||
const props = defineProps({
|
||||
userId: {
|
||||
type: [String, Number],
|
||||
default: null,
|
||||
},
|
||||
src: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: [Number, String],
|
||||
default: null,
|
||||
},
|
||||
rounded: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
disableLink: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
to: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
})
|
||||
|
||||
const attrs = useAttrs()
|
||||
|
||||
const currentSrc = ref(props.src || DEFAULT_AVATAR)
|
||||
|
||||
watch(
|
||||
() => props.src,
|
||||
(value) => {
|
||||
currentSrc.value = value || DEFAULT_AVATAR
|
||||
},
|
||||
)
|
||||
|
||||
const resolvedLink = computed(() => {
|
||||
if (props.to) return props.to
|
||||
if (props.userId !== null && props.userId !== undefined && props.userId !== '') {
|
||||
return `/users/${props.userId}`
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
const altText = computed(() => props.alt || '用户头像')
|
||||
|
||||
const sizeStyle = computed(() => {
|
||||
if (!props.width && props.width !== 0) return null
|
||||
const value = typeof props.width === 'number' ? `${props.width}px` : props.width
|
||||
if (!value) return null
|
||||
return { width: value, height: value }
|
||||
})
|
||||
|
||||
const wrapperStyle = computed(() => {
|
||||
const attrStyle = attrs.style
|
||||
return [sizeStyle.value, attrStyle]
|
||||
})
|
||||
|
||||
const wrapperClass = computed(() => [attrs.class, { 'is-rounded': props.rounded }])
|
||||
|
||||
const wrapperAttrs = computed(() => {
|
||||
const { class: _class, style: _style, ...rest } = attrs
|
||||
return rest
|
||||
})
|
||||
|
||||
function onError() {
|
||||
if (currentSrc.value !== DEFAULT_AVATAR) {
|
||||
currentSrc.value = DEFAULT_AVATAR
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.base-user-avatar {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
background-color: var(--avatar-placeholder-color, #f0f0f0);
|
||||
/* 先用box-sizing: border-box,保证加border后宽高不变,圆形不变形 */
|
||||
box-sizing: border-box;
|
||||
border: 1.5px solid var(--normal-border-color);
|
||||
transition: all 0.6s ease;
|
||||
}
|
||||
|
||||
.base-user-avatar:hover {
|
||||
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.base-user-avatar:active {
|
||||
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.base-user-avatar.is-rounded {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.base-user-avatar:not(.is-rounded) {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.base-user-avatar-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
@@ -26,11 +26,12 @@
|
||||
<span v-if="level >= 2" class="reply-item">
|
||||
<next class="reply-icon" />
|
||||
<span class="reply-info">
|
||||
<BaseImage
|
||||
<BaseUserAvatar
|
||||
class="reply-avatar"
|
||||
:src="comment.parentUserAvatar || '/default-avatar.svg'"
|
||||
alt="avatar"
|
||||
@click="comment.parentUserClick && comment.parentUserClick()"
|
||||
:src="comment.parentUserAvatar"
|
||||
:user-id="comment.parentUserId"
|
||||
:alt="comment.parentUserName"
|
||||
:disable-link="!comment.parentUserId"
|
||||
/>
|
||||
<span class="reply-user-name">{{ comment.parentUserName }}</span>
|
||||
</span>
|
||||
@@ -111,6 +112,7 @@ import BaseTimeline from '~/components/BaseTimeline.vue'
|
||||
import CommentEditor from '~/components/CommentEditor.vue'
|
||||
import DropdownMenu from '~/components/DropdownMenu.vue'
|
||||
import ReactionsGroup from '~/components/ReactionsGroup.vue'
|
||||
import BaseUserAvatar from '~/components/BaseUserAvatar.vue'
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
|
||||
@@ -259,6 +261,7 @@ const submitReply = async (parentUserName, text, clear) => {
|
||||
text: data.content,
|
||||
parentUserName: parentUserName,
|
||||
parentUserAvatar: props.comment.avatar,
|
||||
parentUserId: props.comment.userId,
|
||||
reactions: [],
|
||||
reply: (data.replies || []).map((r) => ({
|
||||
id: r.id,
|
||||
@@ -270,10 +273,12 @@ const submitReply = async (parentUserName, text, clear) => {
|
||||
reply: [],
|
||||
openReplies: false,
|
||||
src: r.author.avatar,
|
||||
userId: r.author.id,
|
||||
iconClick: () => navigateTo(`/users/${r.author.id}`),
|
||||
})),
|
||||
openReplies: false,
|
||||
src: data.author.avatar,
|
||||
userId: data.author.id,
|
||||
iconClick: () => navigateTo(`/users/${data.author.id}`),
|
||||
})
|
||||
clear()
|
||||
|
||||
@@ -70,7 +70,14 @@
|
||||
<DropdownMenu v-if="isLogin" ref="userMenu" :items="headerMenuItems">
|
||||
<template #trigger>
|
||||
<div class="avatar-container">
|
||||
<img class="avatar-img" :src="avatar" alt="avatar" />
|
||||
<BaseUserAvatar
|
||||
class="avatar-img"
|
||||
:user-id="authState.userId"
|
||||
:src="avatar"
|
||||
alt="avatar"
|
||||
:width="32"
|
||||
:disable-link="true"
|
||||
/>
|
||||
<down />
|
||||
</div>
|
||||
</template>
|
||||
@@ -93,6 +100,7 @@ import { computed, nextTick, ref, watch } from 'vue'
|
||||
import DropdownMenu from '~/components/DropdownMenu.vue'
|
||||
import ToolTip from '~/components/ToolTip.vue'
|
||||
import SearchDropdown from '~/components/SearchDropdown.vue'
|
||||
import BaseUserAvatar from '~/components/BaseUserAvatar.vue'
|
||||
import { authState, clearToken, loadCurrentUser } from '~/utils/auth'
|
||||
import { useUnreadCount } from '~/composables/useUnreadCount'
|
||||
import { useChannelsUnreadCount } from '~/composables/useChannelsUnreadCount'
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<template>
|
||||
<div :id="`change-log-${log.id}`" class="change-log-container">
|
||||
<div class="change-log-text">
|
||||
<BaseImage
|
||||
<BaseUserAvatar
|
||||
v-if="log.userAvatar"
|
||||
class="change-log-avatar"
|
||||
:src="log.userAvatar"
|
||||
:to="log.username ? `/users/${log.username}` : ''"
|
||||
alt="avatar"
|
||||
@click="() => navigateTo(`/users/${log.username}`)"
|
||||
:disable-link="!log.username"
|
||||
/>
|
||||
<span v-if="log.username" class="change-log-user">{{ log.username }}</span>
|
||||
<span v-if="log.type === 'CONTENT'" class="change-log-content">变更了文章内容</span>
|
||||
@@ -55,10 +56,8 @@
|
||||
import { computed } from 'vue'
|
||||
import { html } from 'diff2html'
|
||||
import { createTwoFilesPatch } from 'diff'
|
||||
import { useIsMobile } from '~/utils/screen'
|
||||
import 'diff2html/bundles/css/diff2html.min.css'
|
||||
import BaseImage from '~/components/BaseImage.vue'
|
||||
import { navigateTo } from 'nuxt/app'
|
||||
import BaseUserAvatar from '~/components/BaseUserAvatar.vue'
|
||||
import { themeState } from '~/utils/theme'
|
||||
import ArticleCategory from '~/components/ArticleCategory.vue'
|
||||
import ArticleTags from '~/components/ArticleTags.vue'
|
||||
@@ -135,6 +134,12 @@ const diffHtml = computed(() => {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.change-log-avatar :deep(.base-user-avatar-img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.change-log-time {
|
||||
font-size: 12px;
|
||||
opacity: 0.6;
|
||||
|
||||
@@ -53,24 +53,24 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="prize-member-container">
|
||||
<BaseImage
|
||||
<BaseUserAvatar
|
||||
v-for="p in lotteryParticipants"
|
||||
:key="p.id"
|
||||
class="prize-member-avatar"
|
||||
:user-id="p.id"
|
||||
:src="p.avatar"
|
||||
alt="avatar"
|
||||
@click="gotoUser(p.id)"
|
||||
/>
|
||||
<div v-if="lotteryEnded && lotteryWinners.length" class="prize-member-winner">
|
||||
<medal-one class="medal-icon"></medal-one>
|
||||
<span class="prize-member-winner-name">获奖者: </span>
|
||||
<BaseImage
|
||||
<BaseUserAvatar
|
||||
v-for="w in lotteryWinners"
|
||||
:key="w.id"
|
||||
class="prize-member-avatar"
|
||||
:user-id="w.id"
|
||||
:src="w.avatar"
|
||||
alt="avatar"
|
||||
@click="gotoUser(w.id)"
|
||||
/>
|
||||
<div v-if="lotteryWinners.length === 1" class="prize-member-winner-name">
|
||||
{{ lotteryWinners[0].username }}
|
||||
@@ -87,6 +87,7 @@ import { toast } from '~/main'
|
||||
import { useRuntimeConfig } from '#imports'
|
||||
import { useIsMobile } from '~/utils/screen'
|
||||
import { useCountdown } from '~/composables/useCountdown'
|
||||
import BaseUserAvatar from '~/components/BaseUserAvatar.vue'
|
||||
|
||||
const props = defineProps({
|
||||
lottery: { type: Object, required: true },
|
||||
@@ -106,8 +107,6 @@ const hasJoined = computed(() => {
|
||||
return lotteryParticipants.value.some((p) => p.id === Number(authState.userId))
|
||||
})
|
||||
|
||||
const gotoUser = (id) => navigateTo(`/users/${id}`, { replace: true })
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
const joinLottery = async () => {
|
||||
@@ -247,10 +246,15 @@ const joinLottery = async () => {
|
||||
height: 30px;
|
||||
margin-left: 3px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.prize-member-avatar :deep(.base-user-avatar-img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.prize-member-winner {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
></div>
|
||||
</div>
|
||||
<div class="poll-participants">
|
||||
<BaseImage
|
||||
<BaseUserAvatar
|
||||
v-for="p in pollOptionParticipants[idx] || []"
|
||||
:key="p.id"
|
||||
class="poll-participant-avatar"
|
||||
:user-id="p.id"
|
||||
:src="p.avatar"
|
||||
alt="avatar"
|
||||
@click="gotoUser(p.id)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -119,6 +119,7 @@ import { getToken, authState } from '~/utils/auth'
|
||||
import { toast } from '~/main'
|
||||
import { useRuntimeConfig } from '#imports'
|
||||
import { useCountdown } from '~/composables/useCountdown'
|
||||
import BaseUserAvatar from '~/components/BaseUserAvatar.vue'
|
||||
|
||||
const props = defineProps({
|
||||
poll: { type: Object, required: true },
|
||||
@@ -152,8 +153,6 @@ watch([hasVoted, pollEnded], ([voted, ended]) => {
|
||||
if (voted || ended) showPollResult.value = true
|
||||
})
|
||||
|
||||
const gotoUser = (id) => navigateTo(`/users/${id}`, { replace: true })
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
const voteOption = async (idx) => {
|
||||
@@ -429,4 +428,10 @@ const submitMultiPoll = async () => {
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.poll-participant-avatar :deep(.base-user-avatar-img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -24,10 +24,12 @@
|
||||
</template>
|
||||
<template #option="{ option }">
|
||||
<div class="search-option-item">
|
||||
<BaseImage
|
||||
:src="option.avatar || '/default-avatar.svg'"
|
||||
<BaseUserAvatar
|
||||
:src="option.avatar"
|
||||
:user-id="option.id"
|
||||
:alt="option.username"
|
||||
class="avatar"
|
||||
@error="handleAvatarError"
|
||||
:disable-link="true"
|
||||
/>
|
||||
<div class="result-body">
|
||||
<div class="result-main" v-html="highlight(option.username)"></div>
|
||||
@@ -49,6 +51,7 @@ import Dropdown from '~/components/Dropdown.vue'
|
||||
import { stripMarkdown } from '~/utils/markdown'
|
||||
import { useIsMobile } from '~/utils/screen'
|
||||
import { getToken } from '~/utils/auth'
|
||||
import BaseUserAvatar from '~/components/BaseUserAvatar.vue'
|
||||
const config = useRuntimeConfig()
|
||||
const API_BASE_URL = config.public.apiBaseUrl
|
||||
|
||||
@@ -87,10 +90,6 @@ const highlight = (text) => {
|
||||
return text.replace(reg, (m) => `<span class="highlight">${m}</span>`)
|
||||
}
|
||||
|
||||
const handleAvatarError = (e) => {
|
||||
e.target.src = '/default-avatar.svg'
|
||||
}
|
||||
|
||||
watch(selected, async (val) => {
|
||||
if (!val) return
|
||||
const user = results.value.find((u) => u.id === val)
|
||||
@@ -179,6 +178,12 @@ defineExpose({
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.avatar :deep(.base-user-avatar-img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<div class="user-list">
|
||||
<BasePlaceholder v-if="users.length === 0" text="暂无用户" icon="inbox" />
|
||||
<div v-for="u in users" :key="u.id" class="user-item" @click="handleUserClick(u)">
|
||||
<BaseImage :src="u.avatar" alt="avatar" class="user-avatar" />
|
||||
<div v-for="u in users" :key="u.id" class="user-item">
|
||||
<BaseUserAvatar :src="u.avatar" :user-id="u.id" alt="avatar" class="user-avatar" />
|
||||
<div class="user-info">
|
||||
<div class="user-name">{{ u.username }}</div>
|
||||
<div v-if="u.introduction" class="user-intro">{{ u.introduction }}</div>
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
<script setup>
|
||||
import BasePlaceholder from '~/components/BasePlaceholder.vue'
|
||||
import BaseUserAvatar from '~/components/BaseUserAvatar.vue'
|
||||
|
||||
defineProps({
|
||||
users: { type: Array, default: () => [] },
|
||||
@@ -27,20 +28,27 @@ const handleUserClick = (user) => {
|
||||
.user-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
.user-item {
|
||||
padding-top: 20px;
|
||||
padding-bottom: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid var(--normal-border-color);
|
||||
}
|
||||
.user-avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.user-avatar :deep(.base-user-avatar-img) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.user-info {
|
||||
|
||||
Reference in New Issue
Block a user