Browse Source

上传组件

DESKTOP-O04BTUJ\muzen 2 years ago
parent
commit
7305b02fde
1 changed files with 16 additions and 11 deletions
  1. 16 11
      src/components/Upload/index.vue

+ 16 - 11
src/components/Upload/index.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="upload">
-    <el-upload v-if="hidden" :action="action" :headers="headers" :multiple="multiple" :data="data"
+    <el-upload v-if="hidden" :action="newAction" :headers="headers" :multiple="multiple" :data="data"
       :accept="accept" :show-file-list="showFileList" :list-type="listType" :on-progress="onProgress"
       :on-error="onError" :on-success="onSuccess" :before-upload="beforeUpload" :disabled="disabled">
       <el-button v-if="listType !== 'picture-card'" :type="btnType">{{ newTitle }}</el-button>
@@ -19,6 +19,10 @@ const baseUrl = process.env.VUE_APP_BASE_API
 import { getToken } from "@/utils/auth";
 export default {
   props: {
+    action: {
+      type: String,
+      default: ''
+    },
     // 图片
     url: String,
     // 类型
@@ -57,7 +61,7 @@ export default {
   data() {
     return {
       // 上传地址
-      action: `${baseUrl}/system/file/picture/upload`,
+      newAction: this.action,
       // 请求头
       headers: {
         Authorization: "Bearer " + getToken(),
@@ -98,16 +102,17 @@ export default {
     }
   },
   mounted() {
-    if (this.listType === 'picture-card') {
-      this.action = `${baseUrl}/system/file/picture/upload`
-      this.accept = '.jpg, .jpeg, .png, .bmp, .icon, .gif'
-    } else if (this.listType === 'text') {
-      this.action = `${baseUrl}/system/file/file/upload`
-    } else if (this.listType === 'audio') {
-      this.action = `${baseUrl}/system/file/mp3/upload`
-      this.accept = '.mp3, .wav, .aiff, .midi, .wma'
+    if (!this.action) {
+      if (this.listType === 'picture-card') {
+        this.newAction = `${baseUrl}/system/file/picture/upload`
+        this.accept = '.jpg, .jpeg, .png, .bmp, .icon, .gif'
+      } else if (this.listType === 'text') {
+        this.newAction = `${baseUrl}/system/file/file/upload`
+      } else if (this.listType === 'audio') {
+        this.newAction = `${baseUrl}/system/file/mp3/upload`
+        this.accept = '.mp3, .wav, .aiff, .midi, .wma'
+      }
     }
-
     this.newUrl = this.url ? this.url : ''
     this.hidden = this.url ? false : true
   },