فهرست منبع

feat:修改图片上传

linwenxin 1 سال پیش
والد
کامیت
6635b96681
2فایلهای تغییر یافته به همراه28 افزوده شده و 24 حذف شده
  1. 23 19
      src/components/file-upload/index.vue
  2. 5 5
      src/views/mallManagement/configCenter/slideshowConfig/index.vue

+ 23 - 19
src/components/file-upload/index.vue

@@ -1,13 +1,14 @@
 <template>
   <div>
-    <el-upload name="file" :class="['uploader', uid]" :action="oss_url" :data="dataObj" :multiple="multiple"
-      :accept="accept" :show-file-list="false" :on-success="uploadSuccess" :before-upload="beforeUpload" />
+    <el-upload name="file" :class="['uploader', uid]" :action="baseURL + 'common/upload'" :multiple="false"
+      :accept="accept" :show-file-list="false" :on-success="uploadSuccess" :before-upload="beforeUpload"
+      :headers="myHeaders" />
     <div class="images" v-if="modType === 'view'">
       <div v-for="(item, index) in files" :key="index" class="item">
         <div v-if="item.url" class="img">
-          <el-image v-if="checkFileType(item.url) == 'image'" ref="img" :src="imageURL + item.url"
-            :preview-src-list="previewImages" style="width: 120px; height: 120px" fit="cover" />
-          <el-image v-else ref="img" :src="imageURL + item.url" style="width: 120px; height: 120px" fit="cover">
+          <el-image v-if="checkFileType(item.url) == 'image'" ref="img" :src="item.url" :preview-src-list="previewImages"
+            style="width: 120px; height: 120px" fit="cover" />
+          <el-image v-else ref="img" :src="item.url" style="width: 120px; height: 120px" fit="cover">
             <div slot="error" class="image-slot">
               <img v-if="checkFileType(item.url) == 'word'" class="file" src="@/assets/common/word.png" />
               <img v-if="checkFileType(item.url) == 'excel'" class="file" src="@/assets/common/excel.png" />
@@ -45,7 +46,7 @@
 <script>
 import { getOssConfig } from '@/api/common'
 import { findElem } from '@/utils/util'
-
+import { getToken } from '@/utils/auth'
 export default {
   name: 'FileUpload',
   props: {
@@ -98,11 +99,13 @@ export default {
   },
   data() {
     return {
+      myHeaders: { 'x-token': getToken() },
+      baseURL: process.env.VUE_APP_BASE_API,
       imageURL: this.$imageUrl,
       oss_url: '',
       dataObj: {},
       uploadImageUrl: '',
-      waitUploadList: [],
+      // waitUploadList: [],
       fileName: '',
       files: this.fileList
     }
@@ -159,9 +162,10 @@ export default {
     }
   },
   created() {
-    getOssConfig().then(res => {
-      this.oss_url = res.data.host
-    })
+    // console.log(getOssConfig)
+    // getOssConfig().then(res => {
+    //   this.oss_url = res.data.host
+    // })
   },
   methods: {
     getUUID() {
@@ -236,8 +240,8 @@ export default {
       })
       this.getFileName(file.name)
       this.$emit('handleIsFileName', this.fileName)
-      this.dataObj = await this.getOssConfig(this.fileName)
-      this.waitUploadList.push(this.dataObj)
+      // this.dataObj = await this.getOssConfig(this.fileName)
+      // this.waitUploadList.push(this.dataObj)
     },
     // 文件上传成功
     uploadSuccess(res, file) {
@@ -250,22 +254,22 @@ export default {
       if (this.uploadImageUrl) {
         const index = findElem(this.files, 'url', this.uploadImageUrl)
         this.$set(this.files, index, {
-          name: this.dataObj.name,
-          url: this.dataObj.key,
+          name: file.name,
+          url: res.data.url,
           size: file.size,
           type: file.name.split(".")[file.name.split(".").length - 1]
         })
-        this.waitUploadList = []
+        // this.waitUploadList = []
       } else {
         this.getFileName(file.name)
-        const index = findElem(this.waitUploadList, 'name', this.fileName)
+        // const index = findElem(this.waitUploadList, 'name', this.fileName)
         this.files.push({
-          name: this.waitUploadList[index].name,
-          url: this.waitUploadList[index].key,
+          name: file.name,
+          url: res.data.url,
           size: file.size,
           type: file.name.split(".")[file.name.split(".").length - 1]
         })
-        this.waitUploadList.splice(index, 1)
+        // this.waitUploadList.splice(index, 1)
       }
       this.showFileList = true
       loading.close()

+ 5 - 5
src/views/mallManagement/configCenter/slideshowConfig/index.vue

@@ -133,8 +133,8 @@ export default {
       ...(() => {
         if (this.formData.type == 1) {
           this.formData.appid = ""
-          this.formData.link = ""
-          this.formData.goodsId = ""
+          this.formData.linkUrl = ""
+          // this.formData.goodsId = ""
           return [{
             md: 24,
             isShow: true,
@@ -166,14 +166,14 @@ export default {
             attributes: { placeholder: '请输入' },
             formItemAttributes: {
               label: '活动路径',
-              prop: 'link',
+              prop: 'linkUrl',
               rules: []
             }
           }]
         } else if (this.formData.type == 3) {
           this.formData.appid = ""
-          this.formData.link = ""
-          this.formData.goodsId = ""
+          this.formData.linkUrl = ""
+          // this.formData.goodsId = ""
           return [{
             md: 24,
             isShow: true,