fix: 发帖与修改帖子都是用tinymce
This commit is contained in:
parent
dc9387a4d1
commit
a7f15e0ba7
@ -2,8 +2,10 @@
|
|||||||
<div class="tinymce-editor fade-in">
|
<div class="tinymce-editor fade-in">
|
||||||
<!-- 页面标题 -->
|
<!-- 页面标题 -->
|
||||||
<div class="editor-header">
|
<div class="editor-header">
|
||||||
<h1 class="editor-title">创建新文章</h1>
|
<h1 class="editor-title">{{ articleId ? "编辑文章" : "创建新文章" }}</h1>
|
||||||
<p class="editor-subtitle">分享你的知识、经验和创意</p>
|
<p class="editor-subtitle">
|
||||||
|
{{ articleId ? "完善你的知识分享" : "分享你的知识、经验和创意" }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 文章标题输入 -->
|
<!-- 文章标题输入 -->
|
||||||
@ -15,15 +17,6 @@
|
|||||||
:allowClear="true"
|
: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="article-info-card fade-in-delay-1">
|
||||||
<div class="info-title">
|
<div class="info-title">
|
||||||
@ -77,11 +70,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="editor-footer">
|
<div class="editor-footer">
|
||||||
<div class="word-count">字数:{{ wordCount }}</div>
|
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<a-button type="primary" class="publish-btn" @click="SendTinymce">
|
<a-button type="primary" class="publish-btn" @click="SendTinymce">
|
||||||
<a-icon type="plus" />
|
<a-icon :type="articleId ? 'edit' : 'plus'" />
|
||||||
发布文章
|
{{ articleId ? "保存修改" : "发布文章" }}
|
||||||
</a-button>
|
</a-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -96,6 +88,7 @@ import {
|
|||||||
SendSMS,
|
SendSMS,
|
||||||
SendEmail,
|
SendEmail,
|
||||||
AllArticle,
|
AllArticle,
|
||||||
|
UpArtile,
|
||||||
} from "@/api";
|
} from "@/api";
|
||||||
import tinymce from "tinymce/tinymce"; //tinymce默认hidden,不引入不显示
|
import tinymce from "tinymce/tinymce"; //tinymce默认hidden,不引入不显示
|
||||||
import Editor from "@tinymce/tinymce-vue"; //编辑器引入
|
import Editor from "@tinymce/tinymce-vue"; //编辑器引入
|
||||||
@ -111,7 +104,6 @@ import "tinymce/plugins/charmap"; //特殊字符
|
|||||||
import "tinymce/plugins/media"; //插入编辑媒体
|
import "tinymce/plugins/media"; //插入编辑媒体
|
||||||
import "tinymce/plugins/wordcount"; // 字数统计
|
import "tinymce/plugins/wordcount"; // 字数统计
|
||||||
// import Cookies from "js-cookie";
|
// import Cookies from "js-cookie";
|
||||||
|
|
||||||
const fonts = [
|
const fonts = [
|
||||||
"宋体=宋体",
|
"宋体=宋体",
|
||||||
"微软雅黑=微软雅黑",
|
"微软雅黑=微软雅黑",
|
||||||
@ -176,6 +168,7 @@ export default {
|
|||||||
message,
|
message,
|
||||||
//初始化配置
|
//初始化配置
|
||||||
grades: [],
|
grades: [],
|
||||||
|
articleId: this.$route.query.id || "",
|
||||||
myValue: this.value,
|
myValue: this.value,
|
||||||
ArticleTitle: "",
|
ArticleTitle: "",
|
||||||
competitionId: "",
|
competitionId: "",
|
||||||
@ -219,6 +212,9 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
if (this.articleId) {
|
||||||
|
this.GetAritle();
|
||||||
|
}
|
||||||
tinymce.init({});
|
tinymce.init({});
|
||||||
// console.log(this.toolbar,'======')
|
// console.log(this.toolbar,'======')
|
||||||
this.GetAritle();
|
this.GetAritle();
|
||||||
@ -240,24 +236,24 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
GetAritle() {
|
// GetAritle() {
|
||||||
console.log(this.ArticleId);
|
// console.log(this.ArticleId);
|
||||||
if (this.ArticleId != "" || null) {
|
// if (this.ArticleId != "" || null) {
|
||||||
AllArticle().then((res) => {
|
// AllArticle().then((res) => {
|
||||||
res.data.forEach((item) => {
|
// res.data.forEach((item) => {
|
||||||
console.log(item);
|
// console.log(item);
|
||||||
if (item.articleId == this.ArticleId) {
|
// if (item.articleId == this.ArticleId) {
|
||||||
console.log(item);
|
// console.log(item);
|
||||||
this.competitionId = item.competitionId;
|
// this.competitionId = item.competitionId;
|
||||||
(this.ArticleTitle = item.articleTitle),
|
// (this.ArticleTitle = item.articleTitle),
|
||||||
(this.myValue = item.articleContent),
|
// (this.myValue = item.articleContent),
|
||||||
(this.articleType = item.articleType),
|
// (this.articleType = item.articleType),
|
||||||
(this.briefContent = item.briefContent);
|
// (this.briefContent = item.briefContent);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
onClick(e) {
|
onClick(e) {
|
||||||
this.$emit("onClick", e, tinymce);
|
this.$emit("onClick", e, tinymce);
|
||||||
},
|
},
|
||||||
@ -265,6 +261,22 @@ export default {
|
|||||||
clear() {
|
clear() {
|
||||||
this.myValue = "";
|
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() {
|
SendTinymce() {
|
||||||
const data = {
|
const data = {
|
||||||
userId: this.$store.state.user.userId,
|
userId: this.$store.state.user.userId,
|
||||||
@ -275,50 +287,32 @@ export default {
|
|||||||
articleContent: this.myValue,
|
articleContent: this.myValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
createArticle(data)
|
// 根据是否有ID决定调用创建还是更新
|
||||||
|
const apiCall = this.articleId
|
||||||
|
? UpArtile({ ...data, articleId: this.articleId }) // 编辑需要传ID
|
||||||
|
: createArticle(data); // 创建不需要ID
|
||||||
|
|
||||||
|
apiCall
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.code == 200) {
|
const successMsg = this.articleId ? "修改成功" : "发布成功";
|
||||||
this.$message.success("发送成功");
|
this.$message.success(successMsg);
|
||||||
this.articleId = res.data;
|
|
||||||
if (this.articleType == "公告") {
|
// 如果是新建且类型为公告,保留原有通知逻辑
|
||||||
// 询问是否进行短信和邮件通知
|
if (!this.articleId && 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("短信提醒与邮件提醒成功");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 跳转到文章列表
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$router.push("/account/center");
|
||||||
|
}, 1500);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(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',
|
path: '/community/edit',
|
||||||
name: 'EditArticle',
|
name: 'EditArticle',
|
||||||
component: () => import('@/components/edit/EditContent'),
|
component: () => import('@/components/edit/tinymce'),
|
||||||
meta: { title: '编辑文章', auth: [0, 1, 2] },
|
meta: { title: '文章编辑', auth: [0,1,2], hidden: true },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/community/pages',
|
path: '/community/pages',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user