完善未完成功能:修复关注列表/评论发布/编辑器草稿等页面

This commit is contained in:
2026-08-06 00:10:19 +08:00
parent b3c6fc67c9
commit 315bc474d6
28 changed files with 2979 additions and 4276 deletions
+89 -102
View File
@@ -1,6 +1,5 @@
<template>
<view>
<view class="">
<button @click="get()">get</button>
<button @click="del()">del</button>
@@ -14,118 +13,106 @@
</template>
<script>
import { onMounted } from 'vue'
export default {
data() {
return {
setup() {
onMounted(() => {
// 模拟 onLoad
})
async function get() {
let query = { article_id: "1" }
const res = await uniCloud.importObject("comments").getComments(query)
console.log("成功获取评论:", res)
}
},
methods: {
async get() {
console.log();
let query ={article_id:"1"};
const res = await uniCloud.importObject("comments").getComments(query);
async function del() {
let id = "map[$oid:67b45c598a5c78c37f605029]"
const res = await uniCloud.importObject("comments").deleteComment(id)
console.log(res)
}
console.log("成功获取评论:", res);
},
async del() {
let id = "map[$oid:67b45c598a5c78c37f605029]";
const res = await uniCloud.importObject("comments").deleteComment(id);
console.log(res);
},
async add() {
try {
// 获取当前用户信息(需确保已登录)
const uniIdToken = uni.getStorageSync('uni_id_token');
if (!uniIdToken) {
uni.showToast({ title: '请先登录', icon: 'none' });
return;
}
async function add() {
try {
const uniIdToken = uni.getStorageSync('uni_id_token')
if (!uniIdToken) {
uni.showToast({ title: '请先登录', icon: 'none' })
return
}
// 构建符合后端接口规范的评论对象
const comment = {
article_id: "67bbac72c6de56f8256d76b1",
content: "测试评论",
parent_id: 0,
};
const comment = {
article_id: "67bbac72c6de56f8256d76b1",
content: "测试评论",
parent_id: 0,
}
// 调用云对象方法
const commentObj = uniCloud.importObject("comments");
const res = await commentObj.addComment(comment);
// 处理响应结果
if (res.code === 200) {
uni.showToast({ title: '评论成功' });
console.log('评论详情:', {
id: res.data.comment_id,
depth: res.data.depth,
rootComment: res.data.root_id || '一级评论'
});
// 更新前端显示(示例)
// this.$refs.commentList.unshift({
// _id: res.data.comment_id,
// content: comment.content,
// create_time: new Date().toISOString(),
// depth: res.data.depth,
// reply_count: 0
// });
}
} catch (e) {
console.error('评论失败:', e);
// 错误分类处理(根据后端错误码映射)
const errorHandler = {
'PERMISSION_DENIED': '登录状态失效,请重新登录',
'INVALID_PARAMS': '评论内容不能为空',
'CONTENT_BLOCKED': '包含违禁词汇: ' + e.message.split(':')[1],
'PARENT_COMMENT_NOT_FOUND': '回复的评论不存在'
};
uni.showToast({
title: errorHandler[e.errorType] || '评论失败,请稍后重试',
icon: 'none'
});
}
},
async update() {
let comment_id = "67bdf451dab53f685048dccc";
let comment = {
content: "修改后"
const commentObj = uniCloud.importObject("comments")
const res = await commentObj.addComment(comment)
if (res.code === 200) {
uni.showToast({ title: '评论成功' })
console.log('评论详情:', {
id: res.data.comment_id,
depth: res.data.depth,
rootComment: res.data.root_id || '一级评论'
})
}
} catch (e) {
console.error('评论失败:', e)
const errorHandler = {
'PERMISSION_DENIED': '登录状态失效,请重新登录',
'INVALID_PARAMS': '评论内容不能为空',
'CONTENT_BLOCKED': '包含违禁词汇: ' + e.message.split(':')[1],
'PARENT_COMMENT_NOT_FOUND': '回复的评论不存在'
}
uni.showToast({
title: errorHandler[e.errorType] || '评论失败,请稍后重试',
icon: 'none'
})
}
const res = await uniCloud.importObject("comments").updateComment(comment_id, comment);
console.log(res);
},
async relikeComment() {
let comment_like_id="67bdd9cd5a6f8bd7032c949a";
let comment_id="67b466c9ce5ec9e5aa41a25d";
const res = await uniCloud.importObject("comments").relikeComment(comment_like_id, comment_id);
},
async likeComment() {
let user_id="67b466c9ce5ec9e5aa41a25d";
let comment_id = "67b466c9ce5ec9e5aa41a25d";
const res = await uniCloud.importObject("comments").likeComment(user_id, comment_id);
},
to() {
uni.navigateTo({
url:"/uni_modules/uni-cms-article/pages/list/list"
})
},
to1() {
uni.navigateTo({
url:"/uni_modules/uni-cms-article/pages/detail/detail"
})
}
async function update() {
let comment_id = "67bdf451dab53f685048dccc"
let comment = { content: "修改后" }
const res = await uniCloud.importObject("comments").updateComment(comment_id, comment)
console.log(res)
}
async function relikeComment() {
let comment_like_id = "67bdd9cd5a6f8bd7032c949a"
let comment_id = "67b466c9ce5ec9e5aa41a25d"
const res = await uniCloud.importObject("comments").relikeComment(comment_like_id, comment_id)
}
async function likeComment() {
let user_id = "67b466c9ce5ec9e5aa41a25d"
let comment_id = "67b466c9ce5ec9e5aa41a25d"
const res = await uniCloud.importObject("comments").likeComment(user_id, comment_id)
}
function to() {
uni.navigateTo({ url: "/uni_modules/uni-cms-article/pages/list/list" })
}
function to1() {
uni.navigateTo({ url: "/uni_modules/uni-cms-article/pages/detail/detail" })
}
return {
get,
del,
add,
update,
likeComment,
relikeComment,
to,
to1
}
}
}
</script>
<style>
</style>