|
@@ -20,6 +20,7 @@ import {fieldCheck} from "../../../until/form/fieldVerify";
|
|
|
|
|
|
|
|
import {FormVerify} from "kind-form-verify";
|
|
import {FormVerify} from "kind-form-verify";
|
|
|
import {escapeHtml, unescapeHtml} from "@/until/unescapeHtml";
|
|
import {escapeHtml, unescapeHtml} from "@/until/unescapeHtml";
|
|
|
|
|
+import {isEmpty} from "../../../until/typeTool";
|
|
|
let ClassicEditor;
|
|
let ClassicEditor;
|
|
|
// let MyCustomPlugin;
|
|
// let MyCustomPlugin;
|
|
|
if (process.client) {
|
|
if (process.client) {
|
|
@@ -41,7 +42,13 @@ export default {
|
|
|
PopCard,
|
|
PopCard,
|
|
|
RoundedTitle
|
|
RoundedTitle
|
|
|
// Use the <ckeditor> component in this view.
|
|
// Use the <ckeditor> component in this view.
|
|
|
-
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ props: ['article'],
|
|
|
|
|
+ watch: {
|
|
|
|
|
+ article(val){
|
|
|
|
|
+ // 更新文章数据
|
|
|
|
|
+ this.editModel()
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
computed: {
|
|
computed: {
|
|
|
// 产品类型数据
|
|
// 产品类型数据
|
|
@@ -64,7 +71,6 @@ export default {
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return arr;
|
|
return arr;
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
@@ -79,12 +85,25 @@ export default {
|
|
|
formVerify.onLog = (msg) => {
|
|
formVerify.onLog = (msg) => {
|
|
|
console.log(msg);
|
|
console.log(msg);
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 判断是否为编辑文章
|
|
|
|
|
+ if(isEmpty(this.article)){
|
|
|
|
|
+ this.isEdit = true;
|
|
|
|
|
+
|
|
|
|
|
+ console.log(this.article);
|
|
|
|
|
+ console.log(this.form);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.initForm();
|
|
|
|
|
+
|
|
|
},
|
|
},
|
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
|
formVerify = null;
|
|
formVerify = null;
|
|
|
},
|
|
},
|
|
|
data(){
|
|
data(){
|
|
|
return {
|
|
return {
|
|
|
|
|
+ isEdit: false,
|
|
|
|
|
+ editId: null,
|
|
|
editor: ClassicEditor,
|
|
editor: ClassicEditor,
|
|
|
editorData: '<p>在此输入文章内容</p>',
|
|
editorData: '<p>在此输入文章内容</p>',
|
|
|
editorConfig: {
|
|
editorConfig: {
|
|
@@ -108,11 +127,11 @@ export default {
|
|
|
]
|
|
]
|
|
|
},
|
|
},
|
|
|
type: {
|
|
type: {
|
|
|
- val: '',
|
|
|
|
|
|
|
+ val: 'all',
|
|
|
init: '',
|
|
init: '',
|
|
|
msg: '',
|
|
msg: '',
|
|
|
state: 0,
|
|
state: 0,
|
|
|
- options: [],
|
|
|
|
|
|
|
+ options: this.$store.getters.allNewsTypes,
|
|
|
disables: ['all'],
|
|
disables: ['all'],
|
|
|
},
|
|
},
|
|
|
title: {
|
|
title: {
|
|
@@ -156,14 +175,42 @@ export default {
|
|
|
console.log('自定义插入图片按钮');
|
|
console.log('自定义插入图片按钮');
|
|
|
this.openImageSelect();
|
|
this.openImageSelect();
|
|
|
};
|
|
};
|
|
|
- this.initForm();
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
methods:{
|
|
methods:{
|
|
|
initForm(){
|
|
initForm(){
|
|
|
this.form.pType.val = dbField_esm.db_base.newsType.all;
|
|
this.form.pType.val = dbField_esm.db_base.newsType.all;
|
|
|
this.form.type.options = this.newsTypes;
|
|
this.form.type.options = this.newsTypes;
|
|
|
|
|
+ // 判断是否为编辑文章
|
|
|
initForm(this.form);
|
|
initForm(this.form);
|
|
|
|
|
+ this.form.cover.showText = this.form.cover.init;
|
|
|
|
|
+ // 强制更新页面
|
|
|
|
|
+ this.$forceUpdate()
|
|
|
|
|
+ },
|
|
|
|
|
+ editModel(){
|
|
|
|
|
+ this.isEdit = true;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ this.editId = this.article.id;
|
|
|
|
|
+ // 查找对应的 类型
|
|
|
|
|
+ this.form.title.init = this.article.title;
|
|
|
|
|
+ this.form.author.init = this.article.author;
|
|
|
|
|
+ this.form.source.init = this.article.source;
|
|
|
|
|
+ this.form.cover.init = this.article.image;
|
|
|
|
|
+ console.log(this.article.image)
|
|
|
|
|
+ this.form.remark.init = this.article.remark;
|
|
|
|
|
+ this.editorData = this.article.htmlContent;
|
|
|
|
|
+ this.initForm();
|
|
|
|
|
+ let type = this.form.type.options.find((item) => item.type_id === this.article.type_id)
|
|
|
|
|
+ if(type){
|
|
|
|
|
+ console.log(`find the article type`)
|
|
|
|
|
+ this.form.type.init = type.key;
|
|
|
|
|
+ this.form.type.val = type.key;
|
|
|
|
|
+ this.form.pType.init = type.parent_type;
|
|
|
|
|
+ this.form.pType.val = type.parent_type;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
},
|
|
},
|
|
|
openCoverSelect(){
|
|
openCoverSelect(){
|
|
|
console.log('打开文章封面选择窗口');
|
|
console.log('打开文章封面选择窗口');
|
|
@@ -211,8 +258,6 @@ export default {
|
|
|
return console.log('数据验证不通过');
|
|
return console.log('数据验证不通过');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
let formData = formVerify.getFormData();
|
|
let formData = formVerify.getFormData();
|
|
|
console.log('------');
|
|
console.log('------');
|
|
|
console.log(formData);
|
|
console.log(formData);
|
|
@@ -223,19 +268,24 @@ export default {
|
|
|
console.log(formData);
|
|
console.log(formData);
|
|
|
console.log(unescapeHtml(formData.content));
|
|
console.log(unescapeHtml(formData.content));
|
|
|
// 发送请求至后台
|
|
// 发送请求至后台
|
|
|
|
|
+ let queryPath = this.isEdit? apiMap.newsEdit : apiMap.newsAdd;
|
|
|
|
|
+ let actionText = this.isEdit? '修改文章': '新增文章';
|
|
|
|
|
+ if(this.isEdit){
|
|
|
|
|
+ formData.id = this.editId;
|
|
|
|
|
+ }
|
|
|
let [err,res] = await handle(this.$axios.post(
|
|
let [err,res] = await handle(this.$axios.post(
|
|
|
- apiMap.newsAdd.path,
|
|
|
|
|
|
|
+ queryPath.path,
|
|
|
formData
|
|
formData
|
|
|
));
|
|
));
|
|
|
if(err){
|
|
if(err){
|
|
|
console.log(err);
|
|
console.log(err);
|
|
|
- return this.$message.error('新增文章失败');
|
|
|
|
|
|
|
+ return this.$message.error(`${actionText}失败`);
|
|
|
}
|
|
}
|
|
|
let result = res.data;
|
|
let result = res.data;
|
|
|
if (result.code === rCode.OK){
|
|
if (result.code === rCode.OK){
|
|
|
- this.$message.success('新增文章成功');
|
|
|
|
|
|
|
+ this.$message.success(`${actionText}成功`);
|
|
|
}else{
|
|
}else{
|
|
|
- this.$message.error(`新增文章失败,${result.msg}`);
|
|
|
|
|
|
|
+ this.$message.error(`${actionText}失败,${result.msg}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -246,7 +296,7 @@ export default {
|
|
|
<template>
|
|
<template>
|
|
|
<div class="w-full p-2">
|
|
<div class="w-full p-2">
|
|
|
<rounded-title class="text-xl">
|
|
<rounded-title class="text-xl">
|
|
|
- <span>新增文章</span>
|
|
|
|
|
|
|
+ <span>{{ isEdit? "修改文章": "新增文章" }}</span>
|
|
|
<a href="/manger/news"
|
|
<a href="/manger/news"
|
|
|
class="px-10 h-full ml-5 rounded bg-blue-400 text-white cursor-pointer
|
|
class="px-10 h-full ml-5 rounded bg-blue-400 text-white cursor-pointer
|
|
|
hover:text-orange-500 ">文章中心</a>
|
|
hover:text-orange-500 ">文章中心</a>
|
|
@@ -291,7 +341,7 @@ export default {
|
|
|
<input-row class="my-2" :msg="form.cover.msg"
|
|
<input-row class="my-2" :msg="form.cover.msg"
|
|
|
label="文章封面">
|
|
label="文章封面">
|
|
|
<div class="rounded relative" style="width: 524px;height: 360px" >
|
|
<div class="rounded relative" style="width: 524px;height: 360px" >
|
|
|
- <image-viewer class="" :src="form.cover.showText"></image-viewer>
|
|
|
|
|
|
|
+ <image-viewer class="" :src="form.cover.showText?form.cover.showText.charAt(0) == '/'? form.cover.showText : '/public/'+form.cover.showText : '' " :alt="form.cover.showText" ></image-viewer>
|
|
|
<div class="absolute w-full h-full left-0 top-0
|
|
<div class="absolute w-full h-full left-0 top-0
|
|
|
justify-center text-white bg-gray-400
|
|
justify-center text-white bg-gray-400
|
|
|
items-center text-2xl flex opacity-0 hover:opacity-70"
|
|
items-center text-2xl flex opacity-0 hover:opacity-70"
|
|
@@ -305,7 +355,9 @@ export default {
|
|
|
<ckeditor class="mt-2" ref="ckeditor" :editor="editor" v-model="editorData" :config="editorConfig"></ckeditor>
|
|
<ckeditor class="mt-2" ref="ckeditor" :editor="editor" v-model="editorData" :config="editorConfig"></ckeditor>
|
|
|
|
|
|
|
|
<div class="mt-2">
|
|
<div class="mt-2">
|
|
|
- <a-button type="primary" @click="onSubmitHandle">新增文章</a-button>
|
|
|
|
|
|
|
+ <a-button type="primary" @click="onSubmitHandle">
|
|
|
|
|
+ {{isEdit?"保存修改":"新增文章"}}
|
|
|
|
|
+ </a-button>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|