fix: 发帖与修改帖子都是用tinymce

This commit is contained in:
Shu Guang 2025-05-17 22:41:07 +08:00
parent dc9387a4d1
commit a7f15e0ba7
2 changed files with 68 additions and 74 deletions

View File

@ -2,8 +2,10 @@
<div class="tinymce-editor fade-in">
<!-- 页面标题 -->
<div class="editor-header">
<h1 class="editor-title">创建新文章</h1>
<p class="editor-subtitle">分享你的知识经验和创意</p>
<h1 class="editor-title">{{ articleId ? "编辑文章" : "创建新文章" }}</h1>
<p class="editor-subtitle">
{{ articleId ? "完善你的知识分享" : "分享你的知识、经验和创意" }}
</p>
</div>
<!-- 文章标题输入 -->
@ -15,15 +17,6 @@
:allowClear="true"
/>
<!-- 文章简介输入 -->
<a-textarea
v-model="briefContent"
placeholder="请输入文章简介,简明扼要地介绍文章内容 (50-200字)"
:auto-size="{ minRows: 2, maxRows: 5 }"
class="article-brief-textarea"
:maxLength="200"
/>
<!-- 文章信息 -->
<div class="article-info-card fade-in-delay-1">
<div class="info-title">
@ -77,11 +70,10 @@
</div>
<div class="editor-footer">
<div class="word-count">字数{{ wordCount }}</div>
<div class="button-group">
<a-button type="primary" class="publish-btn" @click="SendTinymce">
<a-icon type="plus" />
发布文章
<a-icon :type="articleId ? 'edit' : 'plus'" />
{{ articleId ? "保存修改" : "发布文章" }}
</a-button>
</div>
</div>
@ -96,6 +88,7 @@ import {
SendSMS,
SendEmail,
AllArticle,
UpArtile,
} from "@/api";
import tinymce from "tinymce/tinymce"; //tinymcehidden
import Editor from "@tinymce/tinymce-vue"; //
@ -111,7 +104,6 @@ import "tinymce/plugins/charmap"; //特殊字符
import "tinymce/plugins/media"; //
import "tinymce/plugins/wordcount"; //
// import Cookies from "js-cookie";
const fonts = [
"宋体=宋体",
"微软雅黑=微软雅黑",
@ -176,6 +168,7 @@ export default {
message,
//
grades: [],
articleId: this.$route.query.id || "",
myValue: this.value,
ArticleTitle: "",
competitionId: "",
@ -219,6 +212,9 @@ export default {
},
},
mounted() {
if (this.articleId) {
this.GetAritle();
}
tinymce.init({});
// console.log(this.toolbar,'======')
this.GetAritle();
@ -240,24 +236,24 @@ export default {
});
},
methods: {
GetAritle() {
console.log(this.ArticleId);
if (this.ArticleId != "" || null) {
AllArticle().then((res) => {
res.data.forEach((item) => {
console.log(item);
if (item.articleId == this.ArticleId) {
console.log(item);
this.competitionId = item.competitionId;
(this.ArticleTitle = item.articleTitle),
(this.myValue = item.articleContent),
(this.articleType = item.articleType),
(this.briefContent = item.briefContent);
}
});
});
}
},
// GetAritle() {
// console.log(this.ArticleId);
// if (this.ArticleId != "" || null) {
// AllArticle().then((res) => {
// res.data.forEach((item) => {
// console.log(item);
// if (item.articleId == this.ArticleId) {
// console.log(item);
// this.competitionId = item.competitionId;
// (this.ArticleTitle = item.articleTitle),
// (this.myValue = item.articleContent),
// (this.articleType = item.articleType),
// (this.briefContent = item.briefContent);
// }
// });
// });
// }
// },
onClick(e) {
this.$emit("onClick", e, tinymce);
},
@ -265,6 +261,22 @@ export default {
clear() {
this.myValue = "";
},
GetAritle() {
AllArticle().then((res) => {
const article = res.data.find(
(item) => item.articleId == this.articleId
);
if (article) {
this.competitionId = article.competitionId;
this.ArticleTitle = article.articleTitle;
this.myValue = article.articleContent;
this.articleType = article.articleType;
this.briefContent = article.briefContent;
}
});
},
// importUpArtile
SendTinymce() {
const data = {
userId: this.$store.state.user.userId,
@ -275,50 +287,32 @@ export default {
articleContent: this.myValue,
};
createArticle(data)
// ID
const apiCall = this.articleId
? UpArtile({ ...data, articleId: this.articleId }) // ID
: createArticle(data); // ID
apiCall
.then((res) => {
if (res.code == 200) {
this.$message.success("发送成功");
this.articleId = res.data;
if (this.articleType == "公告") {
//
this.$modal.confirm({
title: `确认发送短信与邮件通知用户?`,
onOk: () => {
let data = {
competitionId: this.competitionId,
articleId: this.articleId,
};
this.$api
.SendEmail(data)
.then(() => {
this.$api.SendSMS(data).then(() => {
this.$message.success("短信邮件提醒成功!");
});
})
.catch((e) => {
this.$message.error(e.msg || "发送失败!");
throw e;
});
},
});
}
} else {
throw new Error("发布失败");
}
})
.then((notificationData) => {
if (notificationData) {
return SendEmail(notificationData)
.then(() => SendSMS(notificationData))
.then(() => {
this.$message.success("短信提醒与邮件提醒成功");
});
const successMsg = this.articleId ? "修改成功" : "发布成功";
this.$message.success(successMsg);
//
if (!this.articleId && this.articleType == "公告") {
// ......
}
//
setTimeout(() => {
this.$router.push("/account/center");
}, 1500);
})
.catch((error) => {
console.error(error);
this.$notify.error({ title: "错误", message: error.message });
this.$notify.error({
title: "错误",
message: this.articleId ? "修改失败" : "发布失败",
});
});
},
},

View File

@ -106,8 +106,8 @@ export const routes = [
{
path: '/community/edit',
name: 'EditArticle',
component: () => import('@/components/edit/EditContent'),
meta: { title: '编辑文章', auth: [0, 1, 2] },
component: () => import('@/components/edit/tinymce'),
meta: { title: '文章编辑', auth: [0,1,2], hidden: true },
},
{
path: '/community/pages',