朋友圈

This commit is contained in:
2025-12-08 10:18:50 +08:00
parent 05a8422007
commit a9dfc56342
7 changed files with 72 additions and 27 deletions

View File

@@ -214,3 +214,6 @@ function viewAvatar() {

View File

@@ -63,7 +63,7 @@
<Avatar
:name="moment.user?.name || ''"
:avatar="moment.user?.avatar"
:size="48"
size="xl"
class="shrink-0"
/>
<div class="flex-1 min-w-0">
@@ -134,10 +134,21 @@
<!-- 点赞用户 -->
<div v-if="moment.likes && moment.likes.length > 0" class="mt-4 p-3 bg-white/5 rounded-xl">
<div class="flex items-center gap-2 text-sm">
<i class="fas fa-heart text-red-500"></i>
<span class="text-gray-400 line-clamp-1">
{{ moment.likes.map(l => l.user?.name).filter(Boolean).join('、') }}
</span>
<i class="fas fa-heart text-red-500 shrink-0"></i>
<div class="flex items-center gap-1 flex-wrap">
<template v-for="(like, idx) in moment.likes.slice(0, 8)" :key="like.id">
<Avatar
:name="like.user?.name || ''"
:avatar="like.user?.avatar"
size="sm"
class="shrink-0"
:title="like.user?.name"
/>
</template>
<span v-if="moment.likes.length > 8" class="text-gray-500 text-xs ml-1">
+{{ moment.likes.length - 8 }}
</span>
</div>
</div>
</div>
@@ -148,12 +159,20 @@
:key="comment.id"
class="flex items-start gap-2 p-2 bg-white/5 rounded-lg text-sm"
>
<span class="font-medium text-gray-300 shrink-0">{{ comment.user?.name }}</span>
<span v-if="comment.reply_to_user" class="text-gray-500 shrink-0">
回复 <span class="text-gray-400">{{ comment.reply_to_user.name }}</span>
</span>
<span class="text-gray-500">:</span>
<span class="text-gray-400 flex-1 break-words">{{ comment.content }}</span>
<Avatar
:name="comment.user?.name || ''"
:avatar="comment.user?.avatar"
size="sm"
class="shrink-0"
/>
<div class="flex-1 min-w-0">
<span class="font-medium text-gray-300">{{ comment.user?.name }}</span>
<span v-if="comment.reply_to_user" class="text-gray-500">
回复 <span class="text-gray-400">{{ comment.reply_to_user.name }}</span>
</span>
<span class="text-gray-500">: </span>
<span class="text-gray-400 break-words">{{ comment.content }}</span>
</div>
</div>
<!-- 展开更多评论 -->
<button
@@ -314,7 +333,7 @@ function closeCommentInput() {
}
async function handleComment() {
if (!commentingMoment.value || !commentText.trim() || commenting.value) return
if (!commentingMoment.value || !commentText.value.trim() || commenting.value) return
commenting.value = true
try {

View File

@@ -297,7 +297,7 @@ async function handlePublish() {
await momentStore.publishMoment(req)
emit('published')
} catch (error: any) {
toast.show(error.message || '发布失败', 'error')
toast.error(error.message || '发布失败')
} finally {
publishing.value = false
}
@@ -313,7 +313,7 @@ function handleImageSelect(e: Event) {
for (const file of toAdd) {
if (file.size > 10 * 1024 * 1024) {
toast.show('图片大小不能超过10MB', 'warning')
toast.warning('图片大小不能超过10MB')
continue
}
images.value.push({
@@ -343,7 +343,7 @@ function handleVideoSelect(e: Event) {
if (!file) return
if (file.size > 500 * 1024 * 1024) {
toast.show('视频大小不能超过500MB', 'warning')
toast.warning('视频大小不能超过500MB')
return
}

View File

@@ -310,7 +310,7 @@ async function handlePublish() {
await momentStore.publishMoment(req)
emit('published')
} catch (error: any) {
toast.show(error.message || '发布失败', 'error')
toast.error(error.message || '发布失败')
} finally {
publishing.value = false
}
@@ -326,7 +326,7 @@ function handleImageSelect(e: Event) {
for (const file of toAdd) {
if (file.size > 10 * 1024 * 1024) {
toast.show('图片大小不能超过10MB', 'warning')
toast.warning('图片大小不能超过10MB')
continue
}
images.value.push({
@@ -356,7 +356,7 @@ function handleVideoSelect(e: Event) {
if (!file) return
if (file.size > 500 * 1024 * 1024) {
toast.show('视频大小不能超过500MB', 'warning')
toast.warning('视频大小不能超过500MB')
return
}

View File

@@ -14,6 +14,8 @@ import type {
MomentNotifPayload,
} from '@/types/moment'
import { useToastStore } from './toast'
import router from '@/router'
import { storage } from '@/utils/storage'
export const useMomentStore = defineStore('moment', () => {
// ==========================================
@@ -143,11 +145,11 @@ export const useMomentStore = defineStore('moment', () => {
const newMoment = await momentApi.createMoment(data)
// 添加到列表顶部
moments.value.unshift(newMoment)
toast.show('发布成功', 'success')
toast.success('发布成功')
return newMoment
} catch (error) {
console.error('发布动态失败:', error)
toast.show('发布失败', 'error')
toast.error('发布失败')
throw error
}
}
@@ -164,10 +166,10 @@ export const useMomentStore = defineStore('moment', () => {
if (currentMoment.value?.id === id) {
currentMoment.value = null
}
toast.show('删除成功', 'success')
toast.success('删除成功')
} catch (error) {
console.error('删除动态失败:', error)
toast.show('删除失败', 'error')
toast.error('删除失败')
throw error
}
}
@@ -225,11 +227,11 @@ export const useMomentStore = defineStore('moment', () => {
moment.comment_count += 1
}
toast.show('评论成功', 'success')
toast.success('评论成功')
return newComment
} catch (error) {
console.error('评论失败:', error)
toast.show('评论失败', 'error')
toast.error('评论失败')
throw error
}
}
@@ -249,10 +251,10 @@ export const useMomentStore = defineStore('moment', () => {
moment.comment_count = Math.max(0, moment.comment_count - 1)
}
toast.show('删除成功', 'success')
toast.success('删除成功')
} catch (error) {
console.error('删除评论失败:', error)
toast.show('删除失败', 'error')
toast.error('删除失败')
throw error
}
}
@@ -394,7 +396,20 @@ export const useMomentStore = defineStore('moment', () => {
break
}
toast.show(message, 'info')
// 显示带操作按钮的 Toast
toast.showToast(message, 'info', 5000, undefined, {
label: '立即查看',
handler: () => {
// 切换到朋友圈 Tab
storage.setCurrentTab('moment')
// 如果不在聊天页面,则跳转
if (router.currentRoute.value.path !== '/chat') {
router.push('/chat')
}
// 触发页面刷新(通过事件或状态)
fetchMoments()
}
})
// 如果当前正在查看相关动态,刷新评论
if (currentMoment.value?.id === payload.moment_id) {

View File

@@ -122,3 +122,6 @@

View File

@@ -22,6 +22,11 @@ export default defineConfig({
ws: true,
changeOrigin: true,
},
'/upload': {
target: 'http://localhost:12080',
ws: true,
changeOrigin: true,
},
},
},
})