feat: 添加登录功能与文章编辑功能

refactor: 重构API服务与全局状态管理

style: 优化UI样式与布局

fix: 修复文章列表与详情页的显示问题

docs: 更新类型定义与注释

chore: 更新依赖包与配置文件
This commit is contained in:
qingfeng1121
2025-10-30 19:00:59 +08:00
parent 85bf3214cc
commit 6d90b5842f
27 changed files with 2400 additions and 304 deletions

View File

@@ -45,6 +45,8 @@
👍
</span>
<span class="reply-button" @click="handleReply(comment, reply)">回复</span>
<!-- 删除按钮 -->
<span class="delete-button" @click="handleDelete(reply.messageid)" v-if=" globalStore.Login">删除</span>
</div>
</div>
</div>
@@ -241,9 +243,9 @@ const fetchMessages = async () => {
let articleid = props.comments || null
if (!articleid) {
// 安全获取文章ID如果globalStore中没有articlebutn则返回null
const articleData = globalStore.getValue('articlebutn')
articleid = (articleData && typeof articleData === 'object' && 'id' in articleData) ? articleData.id : null
// 安全获取文章ID如果globalStore中没有articleInfo则返回null
const articleData = globalStore.getValue('articleInfo')
articleid = (articleData && typeof articleData === 'object' && 'articleid' in articleData) ? articleData.articleid : null
}
form.articleid = articleid
@@ -251,7 +253,6 @@ const fetchMessages = async () => {
// 根据是否有文章ID选择不同的API调用
if (articleid) {
res = await messageService.getMessagesByArticleId(articleid)
console.log(`获取文章ID=${articleid}的相关留言列表`)
} else {
res = await messageService.getAllMessages()
// 过滤掉articleid不为空的留言只保留articleid为空或不存在的留言
@@ -460,7 +461,30 @@ const handleLike = async (msg) => {
msg.isLiking = false
}
}
// 处理删除
const handleDelete = async (msg) => {
try {
// 显示加载状态或禁用按钮
// msg.isDeleting = true
if (!confirm('确定删除吗?')) {
return
}
const res = await messageService.deleteMessage(msg.messageid)
if (res.success) {
// 从列表中移除
messageBoardData.value = messageBoardData.value.filter(item => item.messageid !== msg.messageid)
ElMessage.success('删除成功')
} else {
ElMessage.error('删除失败:' + (res.message || '未知错误'))
}
} catch (error) {
console.error('删除失败:', error)
ElMessage.error('网络错误,请稍后重试')
} finally {
// msg.isDeleting = false
}
}
</script>
<style scoped lang="scss">
@@ -603,7 +627,18 @@ const handleLike = async (msg) => {
color: #409eff;
background-color: rgba(64, 158, 255, 0.1);
}
// 删除按钮
.delete-button {
cursor: pointer;
transition: color 0.3s ease;
padding: 4px 8px;
border-radius: 4px;
display: inline-block;
}
.delete-button:hover {
color: #e74c3c;
background-color: rgba(231, 76, 60, 0.1);
}
/* 回复列表容器 */
.reply-list-container {
margin-top: 16px;