Browse Source

fix(uploader): taro场景 name 字段关联问题、上传成功返回值逻辑优化

richard1015 4 years ago
parent
commit
70cf614bf8

+ 0 - 1
src/packages/__VUE/uploader/index.scss

@@ -59,7 +59,6 @@
         color: $white;
         height: 30px;
         line-height: 30px;
-        text-align: c;
         background: rgba(0, 0, 0, 0.54);
       }
       &__c {

+ 7 - 1
src/packages/__VUE/uploader/index.taro.vue

@@ -32,7 +32,11 @@
         </view>
       </view>
       <view class="nut-uploader__upload" v-if="maximum - fileList.length">
-        <nut-icon color="#808080" :name="uploadIcon"></nut-icon>
+        <nut-icon
+          :size="uploadIconSize"
+          color="#808080"
+          :name="uploadIcon"
+        ></nut-icon>
         <nut-button class="nut-uploader__input" @click="chooseImage" />
       </view>
     </template>
@@ -87,6 +91,7 @@ export default create({
     headers: { type: Object, default: {} },
     data: { type: Object, default: {} },
     uploadIcon: { type: String, default: 'photograph' },
+    uploadIconSize: { type: [String, Number], default: '' },
     xhrState: { type: [Number, String], default: 200 },
     disabled: { type: Boolean, default: false },
     beforeDelete: {
@@ -132,6 +137,7 @@ export default create({
 
     const executeUpload = (fileItem: FileItem) => {
       const uploadOption = new UploadOptions();
+      uploadOption.name = props.name;
       uploadOption.url = props.url;
       for (const [key, value] of Object.entries(props.data)) {
         fileItem.formData[key] = value;

+ 6 - 1
src/packages/__VUE/uploader/index.vue

@@ -52,7 +52,11 @@
         </view>
       </view>
       <view class="nut-uploader__upload" v-if="maximum - fileList.length">
-        <nut-icon color="#808080" :name="uploadIcon"></nut-icon>
+        <nut-icon
+          :size="uploadIconSize"
+          color="#808080"
+          :name="uploadIcon"
+        ></nut-icon>
         <input
           class="nut-uploader__input"
           v-if="capture"
@@ -116,6 +120,7 @@ export default create({
     headers: { type: Object, default: {} },
     data: { type: Object, default: {} },
     uploadIcon: { type: String, default: 'photograph' },
+    uploadIconSize: { type: [String, Number], default: '' },
     xhrState: { type: [Number, String], default: 200 },
     withCredentials: { type: Boolean, default: false },
     multiple: { type: Boolean, default: false },

+ 5 - 4
src/packages/__VUE/uploader/uploader.ts

@@ -1,5 +1,6 @@
 export class UploadOptions {
   url = '';
+  name = 'file';
   formData?: FormData;
   method = 'post';
   xhrState = 200;
@@ -59,12 +60,12 @@ export class Uploader {
         ...options.headers
       }, //
       formData: options.formData,
-      name: 'files',
+      name: options.name,
       success(response: { errMsg: any; statusCode: number; data: string }) {
-        if (response.errMsg) {
-          options.onFailure?.(response, options);
-        } else if (options.xhrState === response.statusCode) {
+        if (options.xhrState === response.statusCode) {
           options.onSuccess?.(response, options);
+        } else {
+          options.onFailure?.(response, options);
         }
       },
       fail(e: any) {