Browse Source

笔记审核&&修改

dev_des
1054425342@qq.com 4 weeks ago
parent
commit
ad1a308d47
  1. 90
      pages/notes/detail.vue
  2. 159
      pages/notes/publish.vue

90
pages/notes/detail.vue

@ -1,5 +1,24 @@
<template> <template>
<view class="note-detail-container"> <view class="note-detail-container">
<!-- 审核状态提示 -->
<view
class="review-status-tip"
v-if="noteDetail.status === 0 || noteDetail.status === -1"
>
<uni-icons type="info" size="18" color="#ffffff"></uni-icons>
<text>{{
noteDetail.status === 0 ? "笔记审核中" : "笔记审核不通过"
}}</text>
<text
v-if="
noteDetail.status === -1 &&
noteDetail.logs &&
noteDetail.logs.length > 0
"
class="reason"
>原因{{ noteDetail.logs[0].reason }}</text
>
</view>
<!-- 笔记内容区域 --> <!-- 笔记内容区域 -->
<view class="content-scroll"> <view class="content-scroll">
<!-- 轮播图区域 --> <!-- 轮播图区域 -->
@ -193,9 +212,15 @@
<text>暂无评论快来发表第一条评论吧</text> <text>暂无评论快来发表第一条评论吧</text>
</view> </view>
</view> </view>
<!-- 底部占位 --> <!-- 底部占位 -->
<view class="bottom-placeholder"></view> <view class="bottom-placeholder"></view>
<!-- 编辑区域 -->
<view class="edit-area" @click="goToEdit" v-if="showEditArea">
<uni-icons type="compose" size="22" color="#666"></uni-icons>
<text>编辑</text>
</view>
<!-- 底部评论输入框 --> <!-- 底部评论输入框 -->
<view class="comment-input-section-box"> <view class="comment-input-section-box">
<view class="comment-input-section"> <view class="comment-input-section">
@ -292,12 +317,23 @@ export default {
tagNames: [], tagNames: [],
comments: [], comments: [],
}, },
userInfo: {
id: "",
},
}; };
}, },
computed: {
showEditArea() {
return this.noteDetail.userId == this.userInfo.id;
},
},
onLoad(options) { onLoad(options) {
this.userInfo = JSON.parse(uni.getStorageSync("userInfo"));
console.log(this.userInfo);
if (options.id) { if (options.id) {
this.noteId = options.id; this.noteId = options.id;
this.loadNoteDetail();
} else { } else {
uni.showToast({ uni.showToast({
title: "笔记ID不存在", title: "笔记ID不存在",
@ -308,6 +344,10 @@ export default {
}, 1500); }, 1500);
} }
}, },
onShow() {
this.loadNoteDetail();
this.userInfo = JSON.parse(uni.getStorageSync("userInfo"));
},
methods: { methods: {
swiperChange(e) { swiperChange(e) {
this.swiperIndex = e.detail.current; this.swiperIndex = e.detail.current;
@ -763,6 +803,13 @@ export default {
// }); // });
}, },
//
goToEdit() {
uni.navigateTo({
url: `/pages/notes/publish?id=${this.noteId}`,
});
},
// //
replyToComment(comment) { replyToComment(comment) {
// parentIdID // parentIdID
@ -1199,6 +1246,45 @@ export default {
font-size: 30rpx; font-size: 30rpx;
} }
} }
.review-status-tip {
width: 100%;
padding: 20rpx 32rpx;
background-color: #ff6b6b;
color: #ffffff;
font-size: 28rpx;
display: flex;
align-items: center;
gap: 12rpx;
box-sizing: border-box;
.reason {
margin-left: 10rpx;
font-size: 26rpx;
}
}
.edit-area {
position: fixed;
right: 40rpx;
bottom: 200rpx;
width: 100rpx;
height: 100rpx;
background-color: #ffffff;
border-radius: 50%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
z-index: 999;
text {
font-size: 24rpx;
color: #999999;
margin-top: 6rpx;
}
}
.banner-content { .banner-content {
width: 100%; width: 100%;
height: 1000rpx; height: 1000rpx;

159
pages/notes/publish.vue

@ -85,7 +85,9 @@
<!-- 底部发布按钮 --> <!-- 底部发布按钮 -->
<view class="bottom-publish"> <view class="bottom-publish">
<button class="publish-btn" @click="publishNote">发布笔记</button> <button class="publish-btn" @click="publishNote">
{{ isEditMode ? "保存修改" : "发布笔记" }}
</button>
</view> </view>
</view> </view>
</template> </template>
@ -97,6 +99,7 @@ export default {
return { return {
selectedImages: [], selectedImages: [],
noteForm: { noteForm: {
id: "", // ID
title: "", title: "",
content: "", content: "",
tags: [], // {id, name} tags: [], // {id, name}
@ -107,6 +110,7 @@ export default {
height: "200rpx", // height: "200rpx", //
width: "200rpx", // width: "200rpx", //
}, },
isEditMode: false, //
}; };
}, },
computed: { computed: {
@ -118,28 +122,39 @@ export default {
); );
}, },
}, },
mounted() { onLoad(options) {
this.getTagList(); //
this.getTagList().then(() => {
// noteId
if (options && options.id) {
this.noteForm.id = options.id;
this.isEditMode = true;
this.loadNoteDetail();
}
});
}, },
methods: { methods: {
// //
async getTagList() { async getTagList() {
try { return new Promise(async (resolve) => {
const res = await this.Post({}, "/framework/tag/list", "DES"); try {
if (res && res.data) { const res = await this.Post({}, "/framework/tag/list", "DES");
this.quickTags = res.data; if (res && res.data) {
this.quickTags = res.data;
}
} catch (error) {
console.error("获取标签列表失败:", error);
//
this.quickTags = [
{ id: "1", name: "DES" },
{ id: "2", name: "AGENT" },
{ id: "3", name: "时间银行" },
{ id: "4", name: "阅读体验" },
{ id: "5", name: "时间力" },
];
} }
} catch (error) { resolve();
console.error("获取标签列表失败:", error); });
//
this.quickTags = [
{ id: "1", name: "DES" },
{ id: "2", name: "AGENT" },
{ id: "3", name: "时间银行" },
{ id: "4", name: "阅读体验" },
{ id: "5", name: "时间力" },
];
}
}, },
// //
goBack() { goBack() {
@ -270,7 +285,7 @@ export default {
} }
}, },
// //
async publishNote() { async publishNote() {
console.log(this.noteForm, "0000"); console.log(this.noteForm, "0000");
if (!this.noteForm.images || this.noteForm.images.length === 0) { if (!this.noteForm.images || this.noteForm.images.length === 0) {
@ -289,13 +304,14 @@ export default {
} }
try { try {
uni.showLoading({ title: "发布中..." }); //
uni.showLoading({ title: this.isEditMode ? "保存中..." : "发布中..." });
// //
await this.submitNote(this.noteForm); await this.submitNote(this.noteForm);
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({
title: "发布成功", title: this.isEditMode ? "修改成功" : "发布成功",
icon: "none", icon: "none",
duration: 2000, duration: 2000,
}); });
@ -307,9 +323,98 @@ export default {
} catch (error) { } catch (error) {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({
title: error.message || "发布失败,请重试", title:
error.message ||
(this.isEditMode ? "修改失败,请重试" : "发布失败,请重试"),
icon: "none",
});
}
},
//
async loadNoteDetail() {
try {
uni.showLoading({ title: "加载中..." });
const res = await this.Post(
{ noteId: this.noteForm.id },
"/framework/note/getInfo/" + this.noteForm.id,
"DES"
);
if (res.code === 200 && res.data) {
const noteData = res.data;
//
this.noteForm.title = noteData.title || "";
this.noteForm.content = noteData.content || "";
//
if (noteData.coverImage) {
const imageUrls = noteData.coverImage.split(",");
this.noteForm.images = imageUrls;
// uni-file-picker
this.selectedImages = imageUrls.map((url) => ({
url: url,
extname: url.split(".").pop(),
name: url.split("/").pop(),
}));
}
//
if (noteData.tagNames && noteData.tagIds) {
// tagNamestagIds
const tagNames = noteData.tagNames.split(",");
const tagIds = noteData.tagIds.split(",");
this.noteForm.tags = tagIds.map((id, index) => ({
id: id,
name: tagNames[index] || "",
}));
} else if (noteData.tags) {
// tags"3,4"ids
const tagIds = noteData.tags.split(",");
// quickTags
this.noteForm.tags = tagIds.map((id) => {
const matchedTag = this.quickTags.find((tag) => tag.id == id);
if (matchedTag) {
return {
id: id,
name: matchedTag.name,
};
} else {
console.warn(`未找到ID为${id}的标签,请确保标签列表已正确加载`);
return {
id: id,
name: `标签${id}`, //
};
}
});
//
if (
this.noteForm.tags.some(
(tag) => !this.quickTags.find((qt) => qt.id === tag.id)
)
) {
console.warn("部分标签未在标签列表中找到,可能需要刷新标签列表");
}
}
} else {
uni.showToast({
title: res.msg || "获取笔记详情失败",
icon: "none",
});
}
} catch (error) {
console.error("加载笔记详情失败:", error);
uni.showToast({
title: "获取笔记详情失败",
icon: "none", icon: "none",
}); });
} finally {
uni.hideLoading();
} }
}, },
@ -324,7 +429,15 @@ export default {
method: "POST", method: "POST",
}; };
return this.Post(formData, "/framework/note/addNote", "DES"); // ID
if (this.isEditMode && this.noteForm.id) {
formData.id = this.noteForm.id;
formData.method = "PUT";
return this.Post(formData, "/framework/note/editNote", "DES");
} else {
return this.Post(formData, "/framework/note/addNote", "DES");
}
}, },
}, },
}; };

Loading…
Cancel
Save