Browse Source

笔记审核&&修改

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

90
pages/notes/detail.vue

@ -1,5 +1,24 @@
<template>
<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">
<!-- 轮播图区域 -->
@ -193,9 +212,15 @@
<text>暂无评论快来发表第一条评论吧</text>
</view>
</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">
@ -292,12 +317,23 @@ export default {
tagNames: [],
comments: [],
},
userInfo: {
id: "",
},
};
},
computed: {
showEditArea() {
return this.noteDetail.userId == this.userInfo.id;
},
},
onLoad(options) {
this.userInfo = JSON.parse(uni.getStorageSync("userInfo"));
console.log(this.userInfo);
if (options.id) {
this.noteId = options.id;
this.loadNoteDetail();
} else {
uni.showToast({
title: "笔记ID不存在",
@ -308,6 +344,10 @@ export default {
}, 1500);
}
},
onShow() {
this.loadNoteDetail();
this.userInfo = JSON.parse(uni.getStorageSync("userInfo"));
},
methods: {
swiperChange(e) {
this.swiperIndex = e.detail.current;
@ -763,6 +803,13 @@ export default {
// });
},
//
goToEdit() {
uni.navigateTo({
url: `/pages/notes/publish?id=${this.noteId}`,
});
},
//
replyToComment(comment) {
// parentIdID
@ -1199,6 +1246,45 @@ export default {
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 {
width: 100%;
height: 1000rpx;

127
pages/notes/publish.vue

@ -85,7 +85,9 @@
<!-- 底部发布按钮 -->
<view class="bottom-publish">
<button class="publish-btn" @click="publishNote">发布笔记</button>
<button class="publish-btn" @click="publishNote">
{{ isEditMode ? "保存修改" : "发布笔记" }}
</button>
</view>
</view>
</template>
@ -97,6 +99,7 @@ export default {
return {
selectedImages: [],
noteForm: {
id: "", // ID
title: "",
content: "",
tags: [], // {id, name}
@ -107,6 +110,7 @@ export default {
height: "200rpx", //
width: "200rpx", //
},
isEditMode: false, //
};
},
computed: {
@ -118,12 +122,21 @@ export default {
);
},
},
mounted() {
this.getTagList();
onLoad(options) {
//
this.getTagList().then(() => {
// noteId
if (options && options.id) {
this.noteForm.id = options.id;
this.isEditMode = true;
this.loadNoteDetail();
}
});
},
methods: {
//
async getTagList() {
return new Promise(async (resolve) => {
try {
const res = await this.Post({}, "/framework/tag/list", "DES");
if (res && res.data) {
@ -140,6 +153,8 @@ export default {
{ id: "5", name: "时间力" },
];
}
resolve();
});
},
//
goBack() {
@ -270,7 +285,7 @@ export default {
}
},
//
//
async publishNote() {
console.log(this.noteForm, "0000");
if (!this.noteForm.images || this.noteForm.images.length === 0) {
@ -289,13 +304,14 @@ export default {
}
try {
uni.showLoading({ title: "发布中..." });
//
uni.showLoading({ title: this.isEditMode ? "保存中..." : "发布中..." });
//
await this.submitNote(this.noteForm);
uni.hideLoading();
uni.showToast({
title: "发布成功",
title: this.isEditMode ? "修改成功" : "发布成功",
icon: "none",
duration: 2000,
});
@ -307,12 +323,101 @@ export default {
} catch (error) {
uni.hideLoading();
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",
});
} finally {
uni.hideLoading();
}
},
//
async submitNote(noteData) {
// API
@ -324,7 +429,15 @@ export default {
method: "POST",
};
// 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