y595705120 3 years ago
parent
commit
ac599b5377
2 changed files with 38 additions and 31 deletions
  1. 26 18
      src/components/Tinymce/components/EditorImage.vue
  2. 12 13
      src/pages/other/file-add.vue

+ 26 - 18
src/components/Tinymce/components/EditorImage.vue

@@ -7,12 +7,13 @@
       <el-upload
         :multiple="true"
         :file-list="fileList"
+        action="/api/artical/uploadFile"
+        :headers="headers"
         :show-file-list="true"
         :on-remove="handleRemove"
         :on-success="handleSuccess"
         :before-upload="beforeUpload"
         class="editor-slide-upload"
-        action="https://httpbin.org/post"
         list-type="picture-card"
       >
         <el-button size="small" type="primary">
@@ -30,7 +31,7 @@
 </template>
 
 <script>
-// import { getToken } from 'api/qiniu'
+import { authDB } from '@/db'
 
 export default {
   name: 'EditorSlideUpload',
@@ -44,7 +45,11 @@ export default {
     return {
       dialogVisible: false,
       listObj: {},
-      fileList: []
+      fileList: [],
+      headers:{
+        'x-token': authDB.get('token'),
+        'x-user-id': authDB.get('uid')
+      },
     }
   },
   methods: {
@@ -53,24 +58,25 @@ export default {
     },
     handleSubmit() {
       const arr = Object.keys(this.listObj).map(v => this.listObj[v])
-      if (!this.checkAllSuccess()) {
-        this.$message('Please wait for all images to be uploaded successfully. If there is a network problem, please refresh the page and upload again!')
-        return
-      }
+      // if (!this.checkAllSuccess()) {
+      //   this.$message('Please wait for all images to be uploaded successfully. If there is a network problem, please refresh the page and upload again!')
+      //   return
+      // }
+      console.log( "this.listObj", this.listObj)
       this.$emit('successCBK', arr)
       this.listObj = {}
       this.fileList = []
       this.dialogVisible = false
     },
     handleSuccess(response, file) {
-      const uid = file.uid
-      const objKeyArr = Object.keys(this.listObj)
-      for (let i = 0, len = objKeyArr.length; i < len; i++) {
-        if (this.listObj[objKeyArr[i]].uid === uid) {
-          this.listObj[objKeyArr[i]].url = response.files.file
-          this.listObj[objKeyArr[i]].hasSuccess = true
-          return
-        }
+      const uid = response.data.filename
+      this.listObj[uid] = {
+        uid,
+        hasSuccess: true,
+        width: file.width,
+        height: file.height,
+        url : "http://smoa.ndjsxh.cn:8888/api/preview/"+ uid
+        // url : "http://localhost:8000/api/preview/"+ uid
       }
     },
     handleRemove(file) {
@@ -87,13 +93,15 @@ export default {
       const _self = this
       const _URL = window.URL || window.webkitURL
       const fileName = file.uid
+
+
       this.listObj[fileName] = {}
       return new Promise((resolve, reject) => {
         const img = new Image()
         img.src = _URL.createObjectURL(file)
-        img.onload = function() {
-          _self.listObj[fileName] = { hasSuccess: false, uid: file.uid, width: this.width, height: this.height }
-        }
+        // img.onload = function() {
+        //   _self.listObj[fileName] = { hasSuccess: false, uid: file.uid, width: this.width, height: this.height }
+        // }
         resolve(true)
       })
     }

+ 12 - 13
src/pages/other/file-add.vue

@@ -37,13 +37,13 @@
         </el-row>
 
          <el-form-item label="文件标题"  prop="title">
-             <el-input  v-model="info.title" type="textarea"></el-input>
+             <el-input  v-model="info.title" type="text"></el-input>
          </el-form-item>
-         
+
          <el-form-item label="文章简介"  prop="title">
-          
+
           </el-form-item>
-          
+
 
          <el-form-item label="" class="mt20" prop="brief" label-width="0">
            <tinymce v-model="info.brief" :height="500" />
@@ -151,15 +151,14 @@
          });
       },
       onSubmit(){
-        console.log( this.info )
-        // this.$refs["elForm"].validate((valid) => {
-        //   if (!valid) return;
-        //   addArtical( this.info ).then(res=>{
-        //     if( res.code == 200){
-        //       this.showFinish()
-        //     }
-        //   })
-        // })
+        this.$refs["elForm"].validate((valid) => {
+          if (!valid) return;
+          addArtical( this.info ).then(res=>{
+            if( res.code == 200){
+              this.showFinish()
+            }
+          })
+        })
       }
     }
   }