fix: remove remaining list truncation gaps

This commit is contained in:
biss committed 2026-10-25 21:29:06 +08:00
1 parent 1ddfecbecc
commit 64b86d2a68
8 files changed
+153 -40

No files matched your search

+13 -3
View File
@@ -4,9 +4,10 @@ import { Delete, Refresh } from '@element-plus/icons-vue'
import http, { apiErrorMessage } from '../api/http'
type Reply = { id: string; content: string; isAnonymous: boolean; authorName: string; createdAt: string; canDelete: boolean }
type ReplyCursor = { createdAt: string; id: string }
type ReactionName = 'Like' | 'Insightful' | 'Agree' | 'Hooray' | 'Heart' | 'Rocket' | 'Eyes' | 'Laugh'
type ReactionOption = { type: ReactionName; emoji: string; label: string; countKey: string; activeKey: string }
type Comment = Reply & { replyCount: number; replies?: Reply[]; [key: string]: string | number | boolean | Reply[] | undefined }
type Comment = Reply & { replyCount: number; replies?: Reply[]; repliesHasMore?: boolean; repliesNextCursor?: ReplyCursor; [key: string]: string | number | boolean | Reply[] | ReplyCursor | undefined }
const reactionOptions: ReactionOption[] = [
{ type: 'Like', emoji: '👍', label: '赞', countKey: 'likeCount', activeKey: 'hasLiked' },
{ type: 'Insightful', emoji: '💡', label: '有启发', countKey: 'insightfulCount', activeKey: 'hasInsightful' },
@@ -44,8 +45,17 @@ function reacted(comment: Comment, option: ReactionOption) { return comment[opti
async function react(comment: Comment, type: ReactionName) { try { await http.post(`${base()}/comments/${comment.id}/reactions/${type}`); await load(true) } catch (error) { ElMessage.error(apiErrorMessage(error)) } }
async function toggleReplies(comment: Comment) {
replyOpen[comment.id] = !replyOpen[comment.id]; if (!replyOpen[comment.id] || comment.replies) return
await loadReplies(comment, true)
}
async function loadReplies(comment: Comment, reset = false) {
replyLoading[comment.id] = true
try { comment.replies = (await http.get(`${base()}/comments/${comment.id}/replies`)).data.items } catch (error) { ElMessage.error(apiErrorMessage(error)) } finally { replyLoading[comment.id] = false }
try {
const cursor = reset ? undefined : comment.repliesNextCursor
const data = (await http.get(`${base()}/comments/${comment.id}/replies`, { params: cursor ? { afterCreatedAt: cursor.createdAt, afterId: cursor.id } : undefined })).data
comment.replies = reset ? data.items : [...(comment.replies ?? []), ...data.items]
comment.repliesHasMore = data.hasMore
comment.repliesNextCursor = data.nextCursor ?? undefined
} catch (error) { ElMessage.error(apiErrorMessage(error)) } finally { replyLoading[comment.id] = false }
}
async function reply(comment: Comment) {
const text = drafts[comment.id]?.trim(); if (!text) return
@@ -64,7 +74,7 @@ watch(() => props.sheetId, () => load(true), { immediate: true })
<el-input v-model="content" type="textarea" :rows="3" maxlength="1000" show-word-limit placeholder="分享对这门课程成绩、学习收获或教学改进的看法" />
<div class="compose"><el-checkbox v-model="anonymous">匿名发布</el-checkbox><el-button type="primary" :loading="submitting" @click="submit">发布评论</el-button></div>
<el-empty v-if="!loading && !comments.length" :image-size="64" description="还没有评论,来说说你的看法吧" />
<ol v-else class="comments"><li v-for="comment in comments" :key="comment.id"><div class="meta"><strong>{{ comment.authorName || '未命名用户' }}</strong><span v-if="comment.isAnonymous">匿名</span><time>{{ new Date(comment.createdAt).toLocaleString('zh-CN') }}</time></div><p>{{ comment.content }}</p><div class="actions"><div class="reaction-bar"><button v-for="option in reactionOptions.filter(item => reactionCount(comment, item))" :key="option.type" type="button" class="reaction-chip" :class="{ active: reacted(comment, option) }" :aria-label="`${option.label} ${reactionCount(comment, option)}`" @click="react(comment, option.type)">{{ option.emoji }} <span>{{ reactionCount(comment, option) }}</span></button><el-popover placement="top-start" :width="260" trigger="click"><template #reference><el-button class="reaction-add" text size="small" aria-label="添加表情反应">😊</el-button></template><div class="reaction-picker" aria-label="选择表情反应"><button v-for="option in reactionOptions" :key="option.type" type="button" :class="{ active: reacted(comment, option) }" :aria-label="option.label" @click="react(comment, option.type)"><span>{{ option.emoji }}</span><small>{{ option.label }}</small></button></div></el-popover></div><el-button text size="small" @click="toggleReplies(comment)">回复{{ comment.replyCount ? ` (${comment.replyCount})` : '' }}</el-button><el-button v-if="comment.canDelete" text type="danger" size="small" :icon="Delete" @click="remove(comment)">删除</el-button></div><div v-if="replyOpen[comment.id]" class="replies" v-loading="replyLoading[comment.id]"><ol v-if="comment.replies?.length"><li v-for="item in comment.replies" :key="item.id"><div class="meta"><strong>{{ item.authorName }}</strong><span v-if="item.isAnonymous">匿名</span><time>{{ new Date(item.createdAt).toLocaleString('zh-CN') }}</time></div><p>{{ item.content }}</p><el-button v-if="item.canDelete" text type="danger" size="small" @click="remove(item)">删除</el-button></li></ol><el-input v-model="drafts[comment.id]" type="textarea" :rows="2" maxlength="1000" show-word-limit placeholder="回复这条评论" /><div class="compose"><el-checkbox v-model="replyAnonymous[comment.id]">匿名回复</el-checkbox><el-button type="primary" size="small" @click="reply(comment)">回复</el-button></div></div></li></ol>
<ol v-else class="comments"><li v-for="comment in comments" :key="comment.id"><div class="meta"><strong>{{ comment.authorName || '未命名用户' }}</strong><span v-if="comment.isAnonymous">匿名</span><time>{{ new Date(comment.createdAt).toLocaleString('zh-CN') }}</time></div><p>{{ comment.content }}</p><div class="actions"><div class="reaction-bar"><button v-for="option in reactionOptions.filter(item => reactionCount(comment, item))" :key="option.type" type="button" class="reaction-chip" :class="{ active: reacted(comment, option) }" :aria-label="`${option.label} ${reactionCount(comment, option)}`" @click="react(comment, option.type)">{{ option.emoji }} <span>{{ reactionCount(comment, option) }}</span></button><el-popover placement="top-start" :width="260" trigger="click"><template #reference><el-button class="reaction-add" text size="small" aria-label="添加表情反应">😊</el-button></template><div class="reaction-picker" aria-label="选择表情反应"><button v-for="option in reactionOptions" :key="option.type" type="button" :class="{ active: reacted(comment, option) }" :aria-label="option.label" @click="react(comment, option.type)"><span>{{ option.emoji }}</span><small>{{ option.label }}</small></button></div></el-popover></div><el-button text size="small" @click="toggleReplies(comment)">回复{{ comment.replyCount ? ` (${comment.replyCount})` : '' }}</el-button><el-button v-if="comment.canDelete" text type="danger" size="small" :icon="Delete" @click="remove(comment)">删除</el-button></div><div v-if="replyOpen[comment.id]" class="replies" v-loading="replyLoading[comment.id]"><ol v-if="comment.replies?.length"><li v-for="item in comment.replies" :key="item.id"><div class="meta"><strong>{{ item.authorName }}</strong><span v-if="item.isAnonymous">匿名</span><time>{{ new Date(item.createdAt).toLocaleString('zh-CN') }}</time></div><p>{{ item.content }}</p><el-button v-if="item.canDelete" text type="danger" size="small" @click="remove(item)">删除</el-button></li></ol><div v-if="comment.repliesHasMore" class="more"><el-button size="small" :loading="replyLoading[comment.id]" @click="loadReplies(comment)">加载更多回复</el-button></div><el-input v-model="drafts[comment.id]" type="textarea" :rows="2" maxlength="1000" show-word-limit placeholder="回复这条评论" /><div class="compose"><el-checkbox v-model="replyAnonymous[comment.id]">匿名回复</el-checkbox><el-button type="primary" size="small" @click="reply(comment)">回复</el-button></div></div></li></ol>
<div v-if="hasMore" class="more"><el-button :loading="loading" @click="load()">加载更多评论</el-button></div>
</section>
</template>