Browse Source

添加新增文章

aaa 3 years ago
parent
commit
cf099708e4

+ 2 - 0
src/api/modules/article.js

@@ -9,5 +9,7 @@ export default {
     INTERFACE_GET_CATEGORIES: "categories",
     // 文章分类子集
     INTERFACE_GET_CATEGORIES_CATEGROYID: "categories/{categoryId}",
+    // 新建文章
+    INTERFACE_POST_ADMIN_MATERIALS: "admin/materials"
   }
 };

+ 6 - 0
src/api/modules/file.js

@@ -0,0 +1,6 @@
+export default {
+    API_LIST_File: {
+      // 查询所有试题类型-父类
+      INTERFACE_POST_IMAGE_UPLOAD: "/image/upload",
+    }
+  };

+ 14 - 22
src/components/tinymce/TinymceEditor.vue

@@ -1,6 +1,12 @@
 <template>
   <div class="tinymce-editor">
-    <Editor :id="tinymceId" :init="init" :disabled="disabled" v-model="myValue" @onClick="onClick"></Editor>
+    <Editor
+      :id="tinymceId"
+      :init="init"
+      :disabled="disabled"
+      v-model="myValue"
+      @onClick="onClick"
+    ></Editor>
   </div>
 </template>
 
@@ -112,27 +118,13 @@ export default {
           } else if (blobInfo.blob().type == isAccord) {
             failure("图片格式错误");
           } else {
-            // let formData = new FormData();
-            // // 服务端接收文件的参数名,文件数据,文件名
-            // formData.append("file", blobInfo.blob(), blobInfo.filename());
-            // axios({
-            //   method: "POST",
-            //   headers: {
-            //     Authorization: "bearer " + Cookies.get("access_token")
-            //   },
-            //   // 这里是你的上传地址
-            //   url: "",
-            //   data: formData
-            // })
-            //   .then(res => {
-            //     console.log(res);
-            //     // 这里返回的是你图片的地址
-            //     success(res.data.data.url);
-            //   })
-            //   .catch(() => {
-            //     failure("上传失败");
-            //   });
-            success("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3374430706,2610126421&fm=11&gp=0.jpg");
+            let formData = new FormData();
+            // 服务端接收文件的参数名,文件数据,文件名
+            formData.append("image-file", blobInfo.blob(), blobInfo.filename());
+            window.$_http.post("/image/upload", formData).then(res => {
+              console.log("--upload--" + JSON.stringify(res));
+              success(res.data.url);
+            });
           }
         }
       }

+ 33 - 18
src/views/articleManagement/articleCreate.vue

@@ -49,7 +49,7 @@
           </a-select>
         </a-form-item>
 
-        <a-form-item label="工类别">
+        <a-form-item label="工类别">
           <a-select
             v-decorator="[
               'engineerType',
@@ -95,9 +95,9 @@
 </template>
 
 <script>
-import { formatePathParams } from '@/filters';
+import { formatePathParams } from "@/filters";
 export default {
-  name: 'articleCreate',
+  name: "articleCreate",
   props: {},
   components: {
     // components: (reslove) => {
@@ -106,17 +106,17 @@ export default {
   },
   data() {
     return {
-      content: '输入内容',
+      content: "输入内容",
       //   展示预览
       previewVisible: false,
-      form: this.$form.createForm(this, { name: 'articleCreate' }),
+      form: this.$form.createForm(this, { name: "articleCreate" }),
       articalParentClassArr: [],
       articalChildClassArr: [],
       engineerTypeArray: [],
       articalParentClass: {},
       articalChildClass: {},
-      engineerType: '',
-      learnDate: '',
+      engineerType: "",
+      learnDate: ""
     };
   },
   created() {
@@ -136,7 +136,7 @@ export default {
     getArticalParentClass() {
       this.$_http
         .get(this.$_API.INTERFACE_GET_CATEGORIES)
-        .then((res) => {
+        .then(res => {
           this.articalParentClassArr = res.data;
           this.loading = false;
         })
@@ -146,7 +146,7 @@ export default {
     },
     // 查询文章分类子集
     getArticalChildClass() {
-      let pathParamsData = { categoryId: '' };
+      let pathParamsData = { categoryId: "" };
       this.$_http
         .get(
           formatePathParams(
@@ -154,7 +154,7 @@ export default {
             pathParamsData
           )
         )
-        .then((res) => {
+        .then(res => {
           this.articalChildClassArr = res.data;
           this.loading = false;
         })
@@ -166,7 +166,7 @@ export default {
     getEngineersWork() {
       this.$_http
         .get(this.$_API.INTERFACE_GET_ENGINEERINGWORK_LIST)
-        .then((res) => {
+        .then(res => {
           this.engineerTypeArray = res.data;
         });
     },
@@ -180,7 +180,7 @@ export default {
       // 子类选项清空
       this.articalChildClassArr = [];
       this.form.setFieldsValue({
-        articalChildClass: '',
+        articalChildClass: ""
       });
     },
     // 文章分类子类变化
@@ -200,18 +200,33 @@ export default {
       e.preventDefault();
 
       this.form.setFieldsValue({
-        articalParentClass: this.articalParentClass.name,
+        articalParentClass: this.articalParentClass.name
       });
       this.form.setFieldsValue({
-        articalChildClass: this.articalChildClass.name,
+        articalChildClass: this.articalChildClass.name
       });
       this.form.setFieldsValue({
-        engineerType: this.engineerType.name,
+        engineerType: this.engineerType.name
       });
 
       this.form.validateFields((err, values) => {
         if (!err) {
-          console.log('Received values of form: ', values);
+          // 新建文章
+          console.log("--submit--" + JSON.stringify(values));
+          let params = {
+            name: "test",
+            description: "aaa",
+            type: "ARTICLE",
+            contents: this.content,
+            tages: [this.learnDate],
+            engineerTypes: [this.engineerType],
+            links: []
+          };
+          this.$_http
+            .post(this.$_API.INTERFACE_POST_ADMIN_MATERIALS, params)
+            .then(res => {
+              console.log("---上传文章----" + JSON.stringify(res));
+            });
         }
       });
     },
@@ -222,8 +237,8 @@ export default {
     // 关闭预览
     closepreview() {
       this.previewVisible = false;
-    },
-  },
+    }
+  }
 };
 </script>