Преглед изворни кода

支持文件&图片组件自定义地址&参数

RuoYi пре 1 година
родитељ
комит
bbd112d5a3

+ 12 - 2
ruoyi-ui/src/components/FileUpload/index.vue

@@ -5,6 +5,7 @@
5 5
       :action="uploadFileUrl"
6 6
       :before-upload="handleBeforeUpload"
7 7
       :file-list="fileList"
8
+      :data="data"
8 9
       :limit="limit"
9 10
       :on-error="handleUploadError"
10 11
       :on-exceed="handleExceed"
@@ -48,6 +49,15 @@ export default {
48 49
   props: {
49 50
     // 值
50 51
     value: [String, Object, Array],
52
+    // 上传接口地址
53
+    action: {
54
+      type: String,
55
+      default: "/file/upload"
56
+    },
57
+    // 上传携带的参数
58
+    data: {
59
+      type: Object
60
+    },
51 61
     // 数量限制
52 62
     limit: {
53 63
       type: Number,
@@ -78,7 +88,7 @@ export default {
78 88
     return {
79 89
       number: 0,
80 90
       uploadList: [],
81
-      uploadFileUrl: process.env.VUE_APP_BASE_API + "/file/upload", // 上传文件服务器地址
91
+      uploadFileUrl: process.env.VUE_APP_BASE_API + this.action, // 上传文件服务器地址
82 92
       headers: {
83 93
         Authorization: "Bearer " + getToken(),
84 94
       },
@@ -152,7 +162,7 @@ export default {
152 162
     // 上传失败
153 163
     handleUploadError(err) {
154 164
       this.$modal.msgError("上传文件失败,请重试");
155
-      this.$modal.closeLoading()
165
+      this.$modal.closeLoading();
156 166
     },
157 167
     // 上传成功回调
158 168
     handleUploadSuccess(res, file) {

+ 11 - 1
ruoyi-ui/src/components/ImageUpload/index.vue

@@ -6,6 +6,7 @@
6 6
       list-type="picture-card"
7 7
       :on-success="handleUploadSuccess"
8 8
       :before-upload="handleBeforeUpload"
9
+      :data="data"
9 10
       :limit="limit"
10 11
       :on-error="handleUploadError"
11 12
       :on-exceed="handleExceed"
@@ -48,6 +49,15 @@ import { getToken } from "@/utils/auth";
48 49
 export default {
49 50
   props: {
50 51
     value: [String, Object, Array],
52
+    // 上传接口地址
53
+    action: {
54
+      type: String,
55
+      default: "/file/upload"
56
+    },
57
+    // 上传携带的参数
58
+    data: {
59
+      type: Object
60
+    },
51 61
     // 图片数量限制
52 62
     limit: {
53 63
       type: Number,
@@ -76,7 +86,7 @@ export default {
76 86
       dialogImageUrl: "",
77 87
       dialogVisible: false,
78 88
       hideUpload: false,
79
-      uploadImgUrl: process.env.VUE_APP_BASE_API + "/file/upload", // 上传的图片服务器地址
89
+      uploadImgUrl: process.env.VUE_APP_BASE_API + this.action, // 上传的图片服务器地址
80 90
       headers: {
81 91
         Authorization: "Bearer " + getToken(),
82 92
       },