@@ -15,15 +17,6 @@
:allowClear="true"
/>
-
-
@@ -77,11 +70,10 @@
@@ -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 ? "修改失败" : "发布失败",
+ });
});
},
},
diff --git a/src/router/index.js b/src/router/index.js
index 978bbfc1..1edef475 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -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',