更新:增加“我的书单”功能

This commit is contained in:
2025-11-10 09:16:28 +08:00
parent 33f861fa14
commit 577e782cd8
25 changed files with 4515 additions and 37 deletions

View File

@@ -0,0 +1,168 @@
<template>
<view class="book-card" @click="handleClick">
<image :src="book.images" class="cover" mode="aspectFill" />
<view class="info">
<text class="title">{{ book.name }}</text>
<view class="actions">
<view
class="action-btn read"
:style="isIOS ? 'width: 100px' : ''"
@click.stop="handleRead"
>
<view class="btn-icon read-icon">
<image src="@/static/icon/icon_look.png" mode="aspectFit" />
</view>
<text>{{ $t('book.read') }}</text>
</view>
<view
class="action-btn listen"
:style="isIOS ? 'width: 100px' : ''"
@click.stop="handleListen"
>
<view class="btn-icon listen-icon">
<image src="@/static/icon/icon_listen.png" mode="aspectFit" />
</view>
<text>{{ $t('book.listen') }}</text>
</view>
<view
v-if="!isIOS"
class="action-btn review"
@click.stop="handleReview"
>
<view class="btn-icon review-icon">
<image src="@/static/icon/icon_pl.png" mode="aspectFit" />
</view>
<text>{{ $t('book.comment') }}</text>
</view>
</view>
</view>
</view>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import type { IBook } from '@/types/book'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
interface Props {
book: IBook
}
const props = defineProps<Props>()
const emit = defineEmits<{
click: []
read: []
listen: []
review: []
}>()
const isIOS = computed(() => {
// #ifdef APP-PLUS
return uni.getSystemInfoSync().platform === 'ios'
// #endif
// #ifndef APP-PLUS
return false
// #endif
})
const handleClick = () => emit('click')
const handleRead = () => emit('read')
const handleListen = () => emit('listen')
const handleReview = () => emit('review')
</script>
<style lang="scss" scoped>
.book-card {
display: flex;
background: #fff;
border-radius: 15rpx;
padding: 30rpx 0 30rpx 30rpx;
margin-top: 20rpx;
.cover {
width: 210rpx;
height: 270rpx;
border-radius: 10rpx;
flex-shrink: 0;
}
.info {
flex: 1;
width: calc(100% - 210rpx);
padding-left: 40rpx;
display: flex;
flex-direction: column;
.title {
padding-top: 40rpx;
display: block;
width: 95%;
font-size: 38rpx;
font-weight: bold;
color: #333;
line-height: 40rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.actions {
margin-top: 50rpx;
margin-left: -15rpx;
display: flex;
.action-btn {
width: 135rpx;
text-align: center;
.btn-icon {
border-radius: 50%;
width: 85rpx;
height: 85rpx;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
image {
width: 40rpx;
height: 40rpx;
}
}
.read-icon {
background: #6bba6b;
box-shadow: 0 0 10px rgba(107, 186, 107, 0.5);
}
.listen-icon {
background: #f7cb5e;
box-shadow: 0 0 10px rgba(247, 203, 94, 0.5);
}
.review-icon {
background: #888888;
box-shadow: 0 0 10px rgba(136, 136, 136, 0.5);
}
text {
display: block;
font-size: 26rpx;
text-align: center;
line-height: 44rpx;
padding-top: 10rpx;
color: #999;
}
}
.action-btn:last-child {
margin-right: 0;
}
}
}
}
</style>

View File

@@ -0,0 +1,237 @@
<template>
<view class="comment-list">
<view
v-for="comment in comments"
:key="comment.id"
class="comment-item"
>
<!-- 用户信息 -->
<view class="user-info">
<image
:src="comment.userEntity.avatar || defaultAvatar"
class="avatar"
mode="aspectFill"
/>
<view class="user-detail">
<text class="username">{{ getUserName(comment.userEntity) }}</text>
</view>
</view>
<!-- 评论内容 -->
<view class="content" v-html="comment.content" />
<!-- 操作按钮 -->
<view class="actions">
<view class="action-btn" @click="handleLike(comment)">
<wd-icon
:name="comment.isLike ? 'heart-filled' : 'heart'"
size="18px"
/>
<text>{{ comment.likeCount || 0 }}</text>
</view>
<view v-if="comment.pid === 0" class="action-btn" @click="handleReply(comment)">
<wd-icon name="chat" size="16px" />
<text>{{ comment.children?.length || 0 }}</text>
</view>
<view class="action-btn" @click="handleDelete(comment)">
<text class="time">{{ comment.createTime }}</text>
</view>
<view
v-if="isMyComment(comment)"
class="action-btn delete"
@click="handleDelete(comment)"
>
<wd-icon name="delete-outline" size="16px" />
<text>{{ $t('common.delete') }}</text>
</view>
</view>
<!-- 子评论 -->
<view v-if="comment.children?.length" class="children-comments">
<CommentList
:comments="comment.children"
@like="handleLike"
@reply="handleReply"
@delete="handleDelete"
/>
</view>
</view>
<!-- 加载更多 -->
<view v-if="hasMore" class="load-more" @click="handleLoadMore">
<text>{{ $t('common.loadMore') }}</text>
</view>
</view>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { useUserStore } from '@/stores/user'
import type { IComment } from '@/types/book'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
interface Props {
comments: IComment[]
hasMore?: boolean
}
const props = withDefaults(defineProps<Props>(), {
hasMore: false
})
const emit = defineEmits<{
like: [comment: IComment]
reply: [comment: IComment]
delete: [comment: IComment]
loadMore: []
}>()
const userStore = useUserStore()
const defaultAvatar = '/static/icon/morenAvavter.png'
const isMyComment = (comment: IComment) => {
return comment.userEntity.id === userStore.id
}
const getUserName = (user: any) => {
return user.nickname || user.name || 'TA'
}
const formatTime = (time: string) => {
if (!time) return ''
// 简单的时间格式化,可以根据需要优化
try {
const date = new Date(time)
const now = new Date()
const diff = now.getTime() - date.getTime()
const minute = 60 * 1000
const hour = 60 * minute
const day = 24 * hour
if (diff < minute) {
return t('common.justNow')
} else if (diff < hour) {
return `${Math.floor(diff / minute)}${t('common.minutesAgo')}`
} else if (diff < day) {
return `${Math.floor(diff / hour)}${t('common.hoursAgo')}`
} else if (diff < 7 * day) {
return `${Math.floor(diff / day)}${t('common.daysAgo')}`
} else {
return `${date.getMonth() + 1}-${date.getDate()}`
}
} catch (e) {
return time
}
}
const handleLike = (comment: IComment) => emit('like', comment)
const handleReply = (comment: IComment) => emit('reply', comment)
const handleDelete = (comment: IComment) => emit('delete', comment)
const handleLoadMore = () => emit('loadMore')
</script>
<style lang="scss" scoped>
.comment-list {
.comment-item {
padding: 20rpx 0;
border-bottom: 1rpx solid #f0f0f0;
.user-info {
display: flex;
align-items: center;
margin-bottom: 15rpx;
.avatar {
width: 60rpx;
height: 60rpx;
border-radius: 50%;
margin-right: 15rpx;
}
.user-detail {
flex: 1;
.username {
display: block;
font-size: 28rpx;
color: #333;
font-weight: 500;
line-height: 32rpx;
}
.time {
display: block;
font-size: 24rpx;
color: #999;
line-height: 28rpx;
margin-top: 5rpx;
}
}
}
.content {
font-size: 28rpx;
color: #333;
line-height: 40rpx;
margin-bottom: 15rpx;
word-break: break-all;
::v-deep img {
width: 45rpx !important;
height: 45rpx !important;
vertical-align: middle;
}
}
.actions {
display: flex;
align-items: center;
gap: 30rpx;
.action-btn {
display: flex;
align-items: center;
gap: 8rpx;
color: #666;
text {
font-size: 24rpx;
}
&.delete text {
color: #ff4703;
}
}
}
.children-comments {
margin-top: 20rpx;
margin-left: 75rpx;
padding-left: 20rpx;
border-left: 2rpx solid #f0f0f0;
.comment-item {
border-bottom: none;
padding: 15rpx 0;
&:last-child {
padding-bottom: 0;
}
}
}
}
.load-more {
padding: 30rpx 0;
text-align: center;
text {
font-size: 28rpx;
color: #999;
}
}
}
</style>