From d5e466a233f8b402d67043c823045799c5bd0fbd Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Sat, 16 Jul 2022 09:57:10 +0800
Subject: [PATCH] 优化表单验证,修复动态变更验证规则不生效的问题

---
 forms/imagePicker/CImagePicker.vue |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/forms/imagePicker/CImagePicker.vue b/forms/imagePicker/CImagePicker.vue
index c184265..0eb0e69 100644
--- a/forms/imagePicker/CImagePicker.vue
+++ b/forms/imagePicker/CImagePicker.vue
@@ -32,7 +32,7 @@
 import Taro from '@tarojs/taro';
 import { $ } from '@tarojs/extend';
 import { AtInput, AtImagePicker, AtCurtain } from 'taro-ui-vue';
-import { Fetcher } from '@components/bases/Fetcher';
+import { $hostBoot } from '@components/bases/HostBoot';
 import { $fetchCommon } from '@fetchers/FCommon';
 import { Tools } from '@components/common/Tools';
 import CImageCompressor from './CImageCompressor.vue';
@@ -56,7 +56,9 @@
         },
     },
     data() {
-        return {};
+        return {
+            fileNames: {},
+        };
     },
     computed: {
         files() {
@@ -78,6 +80,10 @@
             const value = [];
             files.forEach(file => {
                 value.push(file.url);
+                // 记录原文件名
+                if (file.file && file.file.originalFileObj) {
+                    this.fileNames[file.url] = file.file.originalFileObj.name;
+                }
             });
             this.itemRes.onChange(value);
         },
@@ -169,14 +175,16 @@
             });
         },
         $uploadImage(callback) {
-            const url = Fetcher.host + $fetchCommon.getUploadImgURL();
+            let url = $fetchCommon.getUploadImgURL();
+            if (url.indexOf('http') < 0) {
+                url = $hostBoot.getHost() + url;
+            }
             const uploadTeam = [];
             const imgs = [];
             this.files.forEach(file => {
                 if (file.type === 'btn') {
                     return;
                 }
-                Tools.toast(file.url);
                 // 临时文件才上传
                 if (
                     file.url.indexOf('blob') >= 0 ||
@@ -200,6 +208,7 @@
                                 url,
                                 header,
                                 filePath: file.url,
+                                fileName: this.fileNames[file.url],
                                 name: 'file',
                                 formData: {},
                                 success(res) {
@@ -211,7 +220,9 @@
                                         resolve(
                                             $fetchCommon.transImgPath(
                                                 'fix',
-                                                res2.data.src
+                                                res2.data.src ||
+                                                    res2.data.file ||
+                                                    res2.data.url
                                             )
                                         );
                                     } else {

--
Gitblit v1.9.1