| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380 |
- <template>
- <view class="detail-page">
- <!-- 自定义导航栏 -->
- <view class="custom-navbar">
- <view class="navbar-background">
- <view class="feather feather-small">🪶</view>
- </view>
- <view class="navbar-left" @click="goBack">
- <text class="back-icon">←</text>
- </view>
- <view class="navbar-title">
- <text class="main-title">💕 爱的故事</text>
- <text class="sub-title">两只羽毛的浪漫时光</text>
- </view>
- <view class="navbar-right" @click="showMoreMenu">
- <text class="more-icon">⋯</text>
- </view>
- </view>
-
- <!-- 内容区域 -->
- <scroll-view
- class="content-scroll"
- scroll-y
- :scroll-into-view="scrollIntoView"
- >
- <!-- 动态内容 -->
- <view v-if="dynamic" class="dynamic-detail">
- <!-- 用户信息 -->
- <view class="user-section">
- <image
- :src="getAvatar(dynamic)"
- class="avatar"
- mode="aspectFill"
- ></image>
- <view class="user-info">
- <text class="nickname">{{ getNickname(dynamic) }}</text>
- <text class="time">{{ formatTime(dynamic.createdAt) }}</text>
- </view>
- </view>
-
- <!-- 动态内容 -->
- <view class="content-section">
- <text class="content-text">{{ dynamic.content }}</text>
- </view>
-
- <!-- 媒体内容 -->
- <view v-if="dynamic.mediaUrls && dynamic.mediaUrls.length > 0" class="media-section">
- <view class="image-grid">
- <image
- v-for="(url, index) in dynamic.mediaUrls"
- :key="index"
- :src="url"
- class="media-image"
- mode="aspectFill"
- @click="previewImage(dynamic.mediaUrls, index)"
- ></image>
- </view>
- </view>
-
- <!-- 互动数据 -->
- <view class="stats-section">
- <text class="stat-item">{{ dynamic.likeCount || 0 }} 点赞</text>
- <text class="stat-item">{{ dynamic.commentCount || 0 }} 评论</text>
- <text class="stat-item">{{ dynamic.favoriteCount || 0 }} 收藏</text>
- <text class="stat-item">{{ dynamic.viewCount || 0 }} 浏览</text>
- </view>
- </view>
-
- <!-- 评论区域 -->
- <view id="comment-section" class="comment-section">
- <view class="section-title">
- <text class="title-text">评论区</text>
- <text class="title-count">{{ getCommentCount() }}</text>
- </view>
-
- <!-- 评论列表 -->
- <view v-if="commentList.length > 0" class="comment-list">
- <view
- v-for="comment in commentList"
- :key="comment.commentId"
- class="comment-item"
- >
- <image
- :src="getCommentAvatar(comment)"
- class="comment-avatar"
- ></image>
- <view class="comment-content">
- <text class="comment-nickname">{{ getCommentNickname(comment) }}</text>
- <text class="comment-text">{{ comment.content }}</text>
-
- <!-- 评论图片 -->
- <view v-if="getCommentImages(comment).length > 0" class="comment-images">
- <image
- v-for="(imgUrl, imgIndex) in getCommentImages(comment)"
- :key="imgIndex"
- :src="imgUrl"
- class="comment-image"
- mode="aspectFill"
- @click="previewCommentImage(getCommentImages(comment), imgIndex)"
- />
- </view>
-
- <view class="comment-footer">
- <text class="comment-time">{{ formatTime(comment.createdAt) }}</text>
- <view class="comment-actions">
- <text class="action" @click="toggleCommentLike(comment)">{{ (comment.isLiked ? '❤️' : '🤍') + ' ' + (comment.likeCount || 0) }}</text>
- <text class="action" @click="openReply(comment)">回复</text>
- </view>
- </view>
- <!-- 子回复(一级展示) -->
- <view class="reply-list" v-if="comment.replies && comment.replies.length">
- <view class="reply-item" v-for="reply in comment.replies" :key="'r-'+reply.commentId">
- <text class="reply-nickname">{{ getCommentNickname(reply) }}:</text>
- <text class="reply-text">{{ reply.content }}</text>
- </view>
- </view>
- </view>
- </view>
- </view>
-
- <!-- 暂无评论 -->
- <view v-else class="empty-comment">
- <view class="feather-decoration">
- <text class="feather-small">🪶</text>
- <text class="feather-small">🪶</text>
- </view>
- <text class="empty-icon">💕</text>
- <text class="empty-text">还没有人留下爱的足迹</text>
- <text class="empty-hint">成为第一个点赞这份美好的人吧~</text>
- </view>
- </view>
- </scroll-view>
-
- <!-- 底部操作栏 -->
- <view class="bottom-bar">
- <view class="input-area" @click="showCommentInput">
- <text class="love-prefix">💕</text>
- <text class="input-placeholder">留下你的爱意表达...</text>
- </view>
-
- <view class="action-buttons">
- <view class="action-btn" @click="handleLike">
- <text :class="['action-icon', dynamic && dynamic.isLiked ? 'active' : '']">
- {{ dynamic && dynamic.isLiked ? '❤️' : '🤍' }}
- </text>
- <text class="action-label">{{ (dynamic && dynamic.likeCount) ? dynamic.likeCount : 0 }}</text>
- </view>
-
- <view class="action-btn" @click="handleFavorite">
- <text :class="['action-icon', dynamic && dynamic.isFavorited ? 'active' : '']">
- {{ dynamic && dynamic.isFavorited ? '⭐' : '☆' }}
- </text>
- <text class="action-label">{{ (dynamic && dynamic.favoriteCount) ? dynamic.favoriteCount : 0 }}</text>
- </view>
-
- <!-- 精简:移除不必要的分享按钮 -->
- </view>
- </view>
-
- <!-- 更多菜单弹窗 -->
- <view v-if="showMenu" class="menu-popup">
- <view class="menu-mask" @click="hideMoreMenu"></view>
- <view class="menu-content">
- <!-- 如果是自己的动态,显示编辑和删除 -->
- <template v-if="isMyDynamic">
- <view class="menu-item" @click="handleEdit">
- <text class="menu-icon">✏️</text>
- <text class="menu-text">编辑动态</text>
- </view>
- <view class="menu-item" @click="handleDelete">
- <text class="menu-icon">🗑️</text>
- <text class="menu-text">删除动态</text>
- </view>
- </template>
- <!-- 如果不是自己的动态,显示举报 -->
- <template v-else>
- <view class="menu-item" @click="handleReport">
- <text class="menu-icon">🚩</text>
- <text class="menu-text">举报</text>
- </view>
- </template>
- <view class="menu-item cancel" @click="hideMoreMenu">
- <text class="menu-text">取消</text>
- </view>
- </view>
- </view>
-
- <!-- 评论输入弹窗 -->
- <view v-if="showInput" class="comment-popup">
- <view class="popup-mask" @click="hideCommentInput"></view>
- <view class="popup-content">
- <textarea
- v-model="commentText"
- placeholder="输入评论内容..."
- class="comment-textarea"
- :focus="showInput"
- maxlength="500"
- />
-
- <!-- 图片选择区域 -->
- <view class="image-section">
- <view class="image-list">
- <view v-for="(img, index) in commentImages" :key="index" class="image-item">
- <image :src="img" mode="aspectFill" class="preview-image"/>
- <text class="remove-image" @click="removeCommentImage(index)">×</text>
- </view>
- <view v-if="commentImages.length < 3" class="add-image" @click="chooseCommentImage">
- <text class="add-icon">📷</text>
- <text class="add-text">添加图片</text>
- </view>
- </view>
- </view>
-
- <view class="popup-footer">
- <text class="char-count">{{ commentText.length }}/500</text>
- <button class="submit-btn" @click="submitComment">发送</button>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import api from '@/utils/api.js'
- export default {
- data() {
- return {
- dynamicId: null,
- dynamic: null,
- commentList: [],
- commentTotal: 0, // 评论总数
- showInput: false,
- showMenu: false, // 显示更多菜单
- commentText: '',
- commentImages: [],
- scrollIntoView: '',
- currentUserId: 1,
- defaultAvatar: 'http://115.190.125.125:9001/static-images/default-avatar.svg',
- isLiking: false, // 正在点赞中,防止重复点击
- isFavoriting: false // 正在收藏中,防止重复点击
- }
- },
-
- computed: {
- // 判断是否是自己的动态
- isMyDynamic() {
- if (!this.dynamic || !this.currentUserId) return false
- return this.dynamic.userId === this.currentUserId ||
- (this.dynamic.user && this.dynamic.user.userId === this.currentUserId)
- }
- },
- onLoad(options) {
- if (options.id) {
- this.dynamicId = options.id
- // 从存储中获取当前用户ID
- const storedUserId = uni.getStorageSync('userId')
- if (storedUserId !== null && storedUserId !== undefined && storedUserId !== '') {
- this.currentUserId = parseInt(storedUserId)
- } else {
- // 尝试从 userInfo 中获取
- const userInfo = uni.getStorageSync('userInfo')
- if (userInfo && (userInfo.userId || userInfo.id || userInfo.user_id)) {
- this.currentUserId = parseInt(userInfo.userId || userInfo.id || userInfo.user_id)
- } else {
- // 未登录,设置为 null
- this.currentUserId = null
- }
- }
- this.loadDynamicDetail()
- this.loadComments()
- } else if (options.dynamicId) {
- this.dynamicId = options.dynamicId
- }
- if (this.dynamicId) {
- this.loadDynamicDetail()
- this.loadComments()
- // 如果需要滚动到评论区域
- if (options.scrollToComment === 'true') {
- this.$nextTick(() => {
- setTimeout(() => {
- this.scrollIntoView = 'comment-section'
- }, 500)
- })
- }
- }
- },
-
- methods: {
- // 兼容WXML:获取头像
- getAvatar(item) {
- if (item && item.user && item.user.avatarUrl) {
- return item.user.avatarUrl
- }
- return this.defaultAvatar
- },
- // 兼容WXML:获取昵称
- getNickname(item) {
- if (item && item.user && item.user.nickname) {
- return item.user.nickname
- }
- return '匿名用户'
- },
- // 评论头像
- getCommentAvatar(comment) {
- if (comment && comment.user && comment.user.avatarUrl) {
- return comment.user.avatarUrl
- }
- if (comment && comment.$orig && comment.$orig.user && comment.$orig.user.avatarUrl) {
- return comment.$orig.user.avatarUrl
- }
- return this.defaultAvatar
- },
- // 评论昵称
- getCommentNickname(comment) {
- if (comment && comment.user && comment.user.nickname) {
- return comment.user.nickname
- }
- if (comment && comment.$orig && comment.$orig.user && comment.$orig.user.nickname) {
- return comment.$orig.user.nickname
- }
- return '匿名用户'
- },
-
- // 获取评论图片列表(兼容字符串JSON、逗号分隔、数组等多种格式)
- getCommentImages(comment) {
- if (!comment) return []
-
- const pickFirstAvailable = (obj) => {
- if (!obj) return null
- return obj.imageUrls || obj.images || obj.image_list || obj.imageList || null
- }
- const raw = pickFirstAvailable(comment)
- if (!raw) return []
-
- const isLikelyImage = (u) => {
- if (typeof u !== 'string' || !u.trim()) return false
- const url = u.trim()
- const hasExt = /(\.png|\.jpg|\.jpeg|\.gif|\.webp|\.bmp)(\?|$)/i.test(url)
- const isHttp = /^https?:\/\//i.test(url)
- const isMinio = url.includes('dynamic-comments/')
- return hasExt || (isHttp && isMinio)
- }
-
- try {
- if (Array.isArray(raw)) {
- return raw.filter(isLikelyImage)
- }
- if (typeof raw === 'string') {
- const s = raw.trim()
- // JSON数组字符串: ["url1", "url2"]
- if (s.startsWith('[')) {
- const arr = JSON.parse(s)
- return Array.isArray(arr) ? arr.filter(isLikelyImage) : []
- }
- // 逗号分隔或带引号
- return s.split(',')
- .map(x => x.trim().replace(/^\[|\]$/g, '').replace(/^['\"]|['\"]$/g, ''))
- .filter(isLikelyImage)
- }
- } catch (e) {
- // ignore parse error
- }
- return []
- },
-
- // 预览评论图片
- previewCommentImage(urls, current) {
- uni.previewImage({
- urls: urls,
- current: current
- })
- },
- // 加载动态详情
- async loadDynamicDetail() {
- uni.showLoading({ title: '加载中...' })
-
- try {
- const res = await api.dynamic.getDetail(this.dynamicId, this.currentUserId)
- if (res) {
- // 处理数据,确保布尔值正确转换(与列表页保持一致)
- // 根据 dynamic_likes 和 dynamic_favorites 表判断:有记录显示 ❤️/⭐,无记录显示 🤍/☆
- this.dynamic = {
- ...res,
- isLiked: res.isLiked === true || res.isLiked === 1 || res.isLiked === 'true' || res.isLiked === '1',
- isFavorited: res.isFavorited === true || res.isFavorited === 1 || res.isFavorited === 'true' || res.isFavorited === '1'
- }
- }
- } catch (error) {
- console.error('加载详情失败:', error)
- uni.showToast({
- title: '加载失败',
- icon: 'none'
- })
- } finally {
- uni.hideLoading()
- }
- },
-
- // 处理点赞
- async handleLike() {
- if (!this.dynamic) return
- // 防止重复点击
- if (this.isLiking) return
-
- try {
- this.isLiking = true
-
- // 根据 dynamic_likes 表判断是否点赞(有记录显示 ❤️,无记录显示 🤍)
- const isLiked = this.dynamic.isLiked === true || this.dynamic.isLiked === 1 || this.dynamic.isLiked === 'true' || this.dynamic.isLiked === '1'
- const originalCount = this.dynamic.likeCount || 0
-
- // 立即更新UI(乐观更新)
- this.dynamic.isLiked = !isLiked
- this.dynamic.likeCount = isLiked ? Math.max(0, originalCount - 1) : originalCount + 1
-
- // 发送请求
- if (isLiked) {
- await api.dynamic.unlike(this.dynamic.dynamicId)
- } else {
- await api.dynamic.like(this.dynamic.dynamicId)
- }
-
- // 通知列表页同步状态(同时发送两个字段,确保状态完整同步)
- uni.$emit('dynamic-updated', {
- dynamicId: this.dynamic.dynamicId,
- isLiked: this.dynamic.isLiked,
- likeCount: this.dynamic.likeCount,
- isFavorited: this.dynamic.isFavorited,
- favoriteCount: this.dynamic.favoriteCount
- })
- } catch (error) {
- console.error('点赞失败:', error)
- // 请求失败,恢复原状态
- const currentIsLiked = Boolean(this.dynamic.isLiked === true || this.dynamic.isLiked === 1 || this.dynamic.isLiked === 'true')
- this.dynamic.isLiked = !currentIsLiked
- this.dynamic.likeCount = !currentIsLiked ? (this.dynamic.likeCount || 0) + 1 : Math.max(0, (this.dynamic.likeCount || 0) - 1)
- uni.showToast({
- title: '操作失败,请重试',
- icon: 'none'
- })
- } finally {
- // 延迟300毫秒后释放锁,防止快速点击
- setTimeout(() => {
- this.isLiking = false
- }, 300)
- }
- },
-
- // 处理收藏
- async handleFavorite() {
- if (!this.dynamic) return
- // 防止重复点击
- if (this.isFavoriting) return
-
- try {
- this.isFavoriting = true
-
- // 根据 dynamic_favorites 表判断是否收藏(有记录显示 ⭐,无记录显示 ☆)
- const isFavorited = this.dynamic.isFavorited === true || this.dynamic.isFavorited === 1 || this.dynamic.isFavorited === 'true' || this.dynamic.isFavorited === '1'
- const originalCount = this.dynamic.favoriteCount || 0
-
- // 立即更新UI(乐观更新)
- this.dynamic.isFavorited = !isFavorited
- this.dynamic.favoriteCount = isFavorited ? Math.max(0, originalCount - 1) : originalCount + 1
-
- if (isFavorited) {
- await api.dynamic.unfavorite(this.dynamic.dynamicId)
- } else {
- await api.dynamic.favorite(this.dynamic.dynamicId)
- uni.showToast({
- title: '收藏成功',
- icon: 'success'
- })
- }
-
- // 通知列表页同步状态(同时发送两个字段,确保状态完整同步)
- uni.$emit('dynamic-updated', {
- dynamicId: this.dynamic.dynamicId,
- isLiked: this.dynamic.isLiked,
- likeCount: this.dynamic.likeCount,
- isFavorited: this.dynamic.isFavorited,
- favoriteCount: this.dynamic.favoriteCount
- })
- } catch (error) {
- console.error('收藏失败:', error)
- // 请求失败,恢复原状态
- const currentIsFavorited = this.dynamic.isFavorited === true || this.dynamic.isFavorited === 1 || this.dynamic.isFavorited === 'true' || this.dynamic.isFavorited === '1'
- this.dynamic.isFavorited = !currentIsFavorited
- this.dynamic.favoriteCount = !currentIsFavorited ? (this.dynamic.favoriteCount || 0) + 1 : Math.max(0, (this.dynamic.favoriteCount || 0) - 1)
- uni.showToast({
- title: '操作失败,请重试',
- icon: 'none'
- })
- } finally {
- // 延迟300毫秒后释放锁,防止快速点击
- setTimeout(() => {
- this.isFavoriting = false
- }, 300)
- }
- },
-
- // 处理分享
- handleShare() {
- uni.showToast({
- title: '分享功能开发中',
- icon: 'none'
- })
- },
-
- // 显示评论输入
- showCommentInput() {
- this.showInput = true
- },
-
- // 隐藏评论输入
- hideCommentInput() {
- this.showInput = false
- this.commentText = ''
- this.commentImages = []
- },
-
- // 选择评论图片
- async chooseCommentImage() {
- uni.chooseImage({
- count: 3 - this.commentImages.length, // 最多3张
- sizeType: ['compressed'],
- success: async (res) => {
- const filePaths = res.tempFilePaths || []
- if (filePaths.length === 0) return
-
- // 立即显示预览
- this.commentImages.push(...filePaths)
-
- // 显示上传进度
- uni.showLoading({ title: `正在上传图片...` })
-
- try {
- // 逐个上传图片
- for (let i = 0; i < filePaths.length; i++) {
- const filePath = filePaths[i]
- try {
- const url = await api.dynamic.uploadSingle(filePath)
- // 替换本地路径为在线URL
- const localIndex = this.commentImages.indexOf(filePath)
- if (localIndex !== -1) {
- this.commentImages.splice(localIndex, 1, url)
- }
- } catch(error) {
- // 上传失败,移除这张图片
- const localIndex = this.commentImages.indexOf(filePath)
- if (localIndex !== -1) {
- this.commentImages.splice(localIndex, 1)
- }
- }
- }
- uni.hideLoading()
- } catch(e) {
- uni.hideLoading()
- uni.showToast({ title: '图片上传失败', icon: 'none' })
- }
- },
- fail: () => {
- uni.showToast({ title: '选择图片失败', icon: 'none' })
- }
- })
- },
-
- // 移除评论图片
- removeCommentImage(index) {
- this.commentImages.splice(index, 1)
- },
-
- // 加载评论
- async loadComments() {
- try {
- const res = await api.dynamic.getComments(this.dynamicId, 1, 20)
- this.commentList = res.records || []
- // 更新评论总数(优先使用接口返回的总数)
- if (res.total !== undefined && res.total !== null) {
- this.commentTotal = res.total
- // 同步更新动态的评论数
- if (this.dynamic) {
- this.dynamic.commentCount = res.total
- }
- } else if (this.commentList.length > 0) {
- // 如果没有总数,使用列表长度
- this.commentTotal = this.commentList.length
- // 如果动态的评论数为0,则更新
- if (this.dynamic && (!this.dynamic.commentCount || this.dynamic.commentCount === 0)) {
- this.dynamic.commentCount = this.commentList.length
- }
- } else {
- this.commentTotal = 0
- }
- } catch (e) {
- console.error('加载评论失败', e)
- }
- },
-
- // 获取评论数(优先使用实际统计的评论数,确保准确性)
- getCommentCount() {
- // 优先使用评论总数
- if (this.commentTotal > 0) {
- return this.commentTotal
- }
- // 其次使用评论列表长度
- if (this.commentList && this.commentList.length > 0) {
- return this.commentList.length
- }
- // 最后使用动态的评论数
- return this.dynamic ? (this.dynamic.commentCount || 0) : 0
- },
- // 提交评论
- async submitComment() {
- if (!this.commentText.trim()) {
- uni.showToast({
- title: '请输入评论内容',
- icon: 'none'
- })
- return
- }
- try {
- // 构造图片URL字符串
- const imageUrls = this.commentImages.length > 0 ? this.commentImages.join(',') : ''
- await api.dynamic.addComment(this.dynamicId, this.commentText, imageUrls)
- this.commentText = ''
- this.commentImages = []
- this.hideCommentInput()
- // 更新评论数量(乐观更新)
- if (this.dynamic) {
- this.dynamic.commentCount = (this.dynamic.commentCount || 0) + 1
- }
- this.commentTotal = (this.commentTotal || 0) + 1
- // 重新加载评论列表
- this.loadComments()
-
- uni.showToast({ title: '已发布', icon: 'success' })
- } catch (e) {
- uni.showToast({ title: '发布失败', icon: 'none' })
- }
- },
-
- // 评论点赞/取消
- async toggleCommentLike(comment) {
- try {
- if (comment.isLiked) {
- await api.dynamic.unlikeComment(comment.commentId)
- comment.isLiked = false
- comment.likeCount = Math.max(0, (comment.likeCount || 0) - 1)
- } else {
- await api.dynamic.likeComment(comment.commentId)
- comment.isLiked = true
- comment.likeCount = (comment.likeCount || 0) + 1
- }
- } catch (e) {
- // ignore
- }
- },
- // 打开回复框(设置parentCommentId)
- openReply(comment) {
- this.showInput = true
- this.scrollIntoView = ''
- // 简化:当前接口不区分parent,作为后续扩展
- },
-
- // 显示更多菜单
- showMoreMenu() {
- this.showMenu = true
- },
-
- // 隐藏更多菜单
- hideMoreMenu() {
- this.showMenu = false
- },
-
- // 处理编辑
- handleEdit() {
- this.hideMoreMenu()
- if (!this.dynamic || !this.dynamicId) {
- uni.showToast({
- title: '动态信息不存在',
- icon: 'none'
- })
- return
- }
- // 跳转到编辑页面
- const mediaUrls = Array.isArray(this.dynamic.mediaUrls)
- ? this.dynamic.mediaUrls
- : (this.dynamic.mediaUrls ? JSON.parse(this.dynamic.mediaUrls) : [])
- uni.navigateTo({
- url: `/pages/plaza/publish?edit=true&dynamicId=${this.dynamicId}&content=${encodeURIComponent(this.dynamic.content || '')}&mediaUrls=${encodeURIComponent(JSON.stringify(mediaUrls))}&mediaType=${this.dynamic.mediaType || 0}&visibility=${this.dynamic.visibility || 1}`
- })
- },
- // 处理删除
- handleDelete() {
- this.hideMoreMenu()
- if (!this.dynamicId) {
- uni.showToast({
- title: '动态ID不存在',
- icon: 'none'
- })
- return
- }
- uni.showModal({
- title: '确认删除',
- content: '确定要删除这条动态吗?删除后无法恢复。',
- confirmText: '删除',
- confirmColor: '#E91E63',
- success: async (res) => {
- if (res.confirm) {
- try {
- if (!this.currentUserId) {
- uni.showToast({
- title: '请先登录',
- icon: 'none'
- })
- return
- }
- uni.showLoading({
- title: '删除中...'
- })
- await api.dynamic.deleteUserDynamic(this.dynamicId, this.currentUserId)
- uni.hideLoading()
- uni.showToast({
- title: '删除成功',
- icon: 'success'
- })
- // 延迟返回上一页
- setTimeout(() => {
- uni.navigateBack()
- }, 1500)
- } catch (error) {
- uni.hideLoading()
- console.error('删除动态失败:', error)
- uni.showToast({
- title: error.message || '删除失败',
- icon: 'none'
- })
- }
- }
- }
- })
- },
- // 处理举报
- handleReport() {
- this.hideMoreMenu()
- if (!this.dynamicId) {
- uni.showToast({
- title: '动态ID不存在',
- icon: 'none'
- })
- return
- }
- // 跳转到举报页面
- uni.navigateTo({
- url: `/pages/plaza/report?id=${this.dynamicId}`
- })
- },
-
- // 预览图片
- previewImage(urls, current) {
- uni.previewImage({
- urls: urls,
- current: current
- })
- },
-
- // 格式化时间
- formatTime(timeStr) {
- if (!timeStr) return ''
-
- const time = new Date(timeStr)
- const now = new Date()
- const diff = now - time
-
- if (diff < 60000) return '刚刚'
- if (diff < 3600000) return Math.floor(diff / 60000) + '分钟前'
- if (diff < 86400000) return Math.floor(diff / 3600000) + '小时前'
- if (diff < 604800000) return Math.floor(diff / 86400000) + '天前'
-
- const year = time.getFullYear()
- const month = String(time.getMonth() + 1).padStart(2, '0')
- const day = String(time.getDate()).padStart(2, '0')
- const hour = String(time.getHours()).padStart(2, '0')
- const minute = String(time.getMinutes()).padStart(2, '0')
-
- if (year === now.getFullYear()) {
- return `${month}-${day} ${hour}:${minute}`
- }
- return `${year}-${month}-${day}`
- },
-
- // 返回
- goBack() {
- uni.navigateBack()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .detail-page {
- min-height: 100vh;
- background: #FFF0F5; // 与广场、发布页统一淡粉
-
- // 自定义导航栏
- .custom-navbar {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- height: 88rpx; // 更紧凑
- background: transparent; // 轻盈
- display: flex;
- align-items: center;
- padding: 0 30rpx;
- padding-top: 0;
- z-index: 1000;
- box-shadow: none;
- overflow: visible;
- position: relative;
-
- .navbar-background {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
-
- .feather-small {
- position: absolute;
- font-size: 40rpx;
- opacity: 0.15;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%) rotate(25deg);
- animation: float 4s ease-in-out infinite;
- }
- }
-
- .navbar-left,
- .navbar-right {
- width: 100rpx;
- z-index: 1;
- }
-
- .navbar-left {
- .back-icon {
- font-size: 40rpx;
- color: #E91E63;
- text-shadow: none;
- }
- }
-
- .navbar-title {
- flex: 1;
- text-align: center;
- z-index: 1;
-
- .main-title {
- display: block;
- font-size: 30rpx;
- font-weight: 700;
- color: #D81B60;
- text-shadow: none;
- margin-bottom: 2rpx;
- }
-
- .sub-title {
- display: block;
- font-size: 20rpx;
- color: #AD1457;
- letter-spacing: 1rpx;
- }
- }
-
- .navbar-right {
- display: flex;
- justify-content: flex-end;
- align-items: center;
-
- .more-icon {
- font-size: 48rpx;
- color: #E91E63;
- font-weight: bold;
- line-height: 1;
- transform: rotate(90deg);
- }
- }
- }
-
- // 内容滚动区域
- .content-scroll {
- margin-top: 88rpx;
- height: calc(100vh - 88rpx - 128rpx);
- padding-bottom: 16rpx;
-
- // 动态详情
- .dynamic-detail {
- background: #FFFFFF;
- padding: 24rpx;
- margin: 12rpx 12rpx 10rpx 12rpx;
- border-radius: 20rpx;
- box-shadow: 0 6rpx 18rpx rgba(233, 30, 99, 0.08);
- border: 2rpx solid rgba(255, 182, 193, 0.25);
- position: relative;
- overflow: hidden;
-
- .user-section {
- display: flex;
- align-items: center;
- margin-bottom: 30rpx;
-
- .avatar {
- width: 80rpx;
- height: 80rpx;
- border-radius: 50%;
- margin-right: 20rpx;
- }
-
- .user-info {
- flex: 1;
-
- .nickname {
- display: block;
- font-size: 30rpx;
- font-weight: bold;
- color: #333333;
- margin-bottom: 8rpx;
- }
-
- .time {
- font-size: 24rpx;
- color: #999999;
- }
- }
- }
-
- .content-section {
- margin-bottom: 30rpx;
-
- .content-text {
- font-size: 30rpx;
- line-height: 1.8;
- color: #333333;
- word-wrap: break-word;
- }
- }
-
- .media-section {
- margin-bottom: 16rpx;
-
- .image-grid {
- display: grid;
- grid-template-columns: repeat(3, 1fr);
- gap: 10rpx;
-
- .media-image {
- width: 100%;
- height: 200rpx;
- border-radius: 12rpx;
- }
- }
- }
-
- .stats-section {
- display: flex;
- padding-top: 30rpx;
- border-top: 1rpx solid #F0F0F0;
-
- .stat-item {
- flex: 1;
- text-align: center;
- font-size: 26rpx;
- color: #666666;
- }
- }
- }
-
- // 评论区域
- .comment-section {
- background: #FFFFFF;
- padding: 24rpx;
- margin: 0 12rpx 12rpx 12rpx;
- border-radius: 20rpx;
- box-shadow: 0 6rpx 18rpx rgba(233, 30, 99, 0.08);
- border: 2rpx solid rgba(255, 182, 193, 0.25);
- position: relative;
-
- .section-title {
- display: flex;
- align-items: center;
- margin-bottom: 16rpx;
-
- .title-text {
- font-size: 32rpx;
- font-weight: bold;
- color: #333333;
- margin-right: 10rpx;
- }
-
- .title-count {
- font-size: 24rpx;
- color: #999999;
- }
- }
-
- .comment-list {
- .comment-item {
- display: flex;
- margin-bottom: 18rpx;
-
- .comment-avatar {
- width: 60rpx;
- height: 60rpx;
- border-radius: 50%;
- margin-right: 20rpx;
- }
-
- .comment-content {
- flex: 1;
-
- .comment-nickname {
- display: block;
- font-size: 26rpx;
- color: #666666;
- margin-bottom: 6rpx;
- }
-
- .comment-text {
- display: block;
- font-size: 28rpx;
- line-height: 1.55;
- color: #333333;
- margin-bottom: 8rpx;
- }
-
- .comment-images {
- display: flex;
- flex-wrap: wrap;
- gap: 10rpx;
- margin: 12rpx 0;
-
- .comment-image {
- width: 150rpx;
- height: 150rpx;
- border-radius: 12rpx;
- overflow: hidden;
- }
- }
-
- .comment-footer {
- display: flex;
- justify-content: space-between;
-
- .comment-time,
- .comment-like {
- font-size: 22rpx;
- color: #999999;
- }
- }
- }
- }
- }
-
- .empty-comment {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 100rpx 0;
-
- .empty-icon {
- font-size: 100rpx;
- margin-bottom: 20rpx;
- }
-
- .empty-text {
- font-size: 26rpx;
- color: #999999;
- }
- }
- }
- }
-
- // 更多菜单弹窗
- .menu-popup {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 9998;
-
- .menu-mask {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.5);
- }
-
- .menu-content {
- position: absolute;
- bottom: 0;
- left: 0;
- right: 0;
- background-color: #FFFFFF;
- border-radius: 30rpx 30rpx 0 0;
- padding: 20rpx 30rpx;
- padding-bottom: calc(20rpx + constant(safe-area-inset-bottom));
- padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
- animation: slideUp 0.3s ease;
-
- .menu-item {
- height: 100rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 12rpx;
- margin-bottom: 16rpx;
- transition: background-color 0.3s ease;
-
- &:not(.cancel) {
- background: #FFF5F7;
-
- &:active {
- background: #FFE8EC;
- }
- }
-
- &.cancel {
- background: #F5F5F5;
- margin-top: 8rpx;
-
- &:active {
- background: #EEEEEE;
- }
- }
-
- .menu-icon {
- font-size: 36rpx;
- margin-right: 12rpx;
- }
-
- .menu-text {
- font-size: 30rpx;
- color: #333333;
- font-weight: 500;
- }
- }
- }
- }
-
- // 底部操作栏
- .bottom-bar {
- position: fixed;
- bottom: 0;
- left: 0;
- right: 0;
- background-color: #FFFFFF;
- padding: 20rpx 30rpx;
- display: flex;
- align-items: center;
- box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
- padding-bottom: constant(safe-area-inset-bottom);
- padding-bottom: env(safe-area-inset-bottom);
-
- .input-area {
- flex: 1;
- height: 70rpx;
- background-color: #F5F5F5;
- border-radius: 35rpx;
- padding: 0 30rpx;
- display: flex;
- align-items: center;
- margin-right: 20rpx;
-
- .input-placeholder {
- font-size: 26rpx;
- color: #999999;
- }
- }
-
- .action-buttons {
- display: flex;
- gap: 20rpx;
-
- .action-btn {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 12rpx 16rpx;
- border-radius: 24rpx;
- background: rgba(255, 182, 193, 0.1);
- transition: all 0.3s ease;
-
- &:active {
- transform: scale(0.95);
- background: rgba(233, 30, 99, 0.2);
- }
-
- .action-icon {
- font-size: 48rpx;
- margin-bottom: 6rpx;
-
- &.active {
- animation: heartbeat 0.6s ease-in-out;
- }
- }
-
- .action-label {
- font-size: 22rpx;
- color: #8B5A96;
- font-weight: 500;
- }
- }
- }
- }
-
- // 评论输入弹窗
- .comment-popup {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 9999;
-
- .popup-mask {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.5);
- }
-
- .popup-content {
- position: absolute;
- bottom: 0;
- left: 0;
- right: 0;
- background-color: #FFFFFF;
- border-radius: 30rpx 30rpx 0 0;
- padding: 30rpx;
- padding-bottom: calc(30rpx + constant(safe-area-inset-bottom));
- padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
-
- .comment-textarea {
- width: 100%;
- min-height: 200rpx;
- max-height: 400rpx;
- padding: 20rpx;
- background-color: #F5F5F5;
- border-radius: 12rpx;
- font-size: 28rpx;
- line-height: 1.6;
- margin-bottom: 20rpx;
- }
-
- .image-section {
- margin-bottom: 20rpx;
-
- .image-list {
- display: flex;
- flex-wrap: wrap;
- gap: 16rpx;
- }
-
- .image-item {
- position: relative;
- width: 120rpx;
- height: 120rpx;
- border-radius: 12rpx;
- overflow: hidden;
-
- .preview-image {
- width: 100%;
- height: 100%;
- }
-
- .remove-image {
- position: absolute;
- top: 8rpx;
- right: 8rpx;
- width: 32rpx;
- height: 32rpx;
- background: rgba(0,0,0,0.6);
- color: white;
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 24rpx;
- font-weight: bold;
- }
- }
-
- .add-image {
- width: 120rpx;
- height: 120rpx;
- background: #F5F5F5;
- border: 2rpx dashed #CCCCCC;
- border-radius: 12rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
-
- .add-icon {
- font-size: 32rpx;
- margin-bottom: 8rpx;
- }
-
- .add-text {
- font-size: 20rpx;
- color: #999999;
- }
- }
- }
-
- .popup-footer {
- display: flex;
- justify-content: space-between;
- align-items: center;
-
- .char-count {
- font-size: 24rpx;
- color: #999999;
- }
-
- .submit-btn {
- padding: 15rpx 50rpx;
- background: linear-gradient(135deg, #E91E63 0%, #FF6B9D 100%);
- color: #FFFFFF;
- border: none;
- border-radius: 50rpx;
- font-size: 28rpx;
- }
- }
- }
- }
- }
- @keyframes pulse {
- 0%, 100% {
- transform: scale(1);
- }
- 50% {
- transform: scale(1.2);
- }
- }
- @keyframes slideUp {
- from {
- transform: translateY(100%);
- }
- to {
- transform: translateY(0);
- }
- }
- </style>
|