fix: 发帖与修改帖子都是用tinymce
This commit is contained in:
parent
dc9387a4d1
commit
a7f15e0ba7
@ -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"; //tinymce默认hidden,不引入不显示
|
||||
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;
|
||||
}
|
||||
});
|
||||
},
|
||||
// 在import部分添加UpArtile
|
||||
|
||||
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 ? "修改失败" : "发布失败",
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user