فهرست منبع

文件批量上传

zhaoxiaohai 3 سال پیش
والد
کامیت
1b71ea39df
3فایلهای تغییر یافته به همراه47 افزوده شده و 43 حذف شده
  1. 45 41
      components/My_UploadFiles/index.js
  2. 1 1
      components/My_UploadFiles/index.wxml
  3. 1 1
      project.config.json

+ 45 - 41
components/My_UploadFiles/index.js

@@ -106,51 +106,55 @@ Component({
                 file,
                 callback
             } = event.detail;
-            /* 校验文件大小 */
-            if (file.size > 10485760) {
-                wx.showToast({
-                    title: '文件体积大于10Mb',
-                    icon: "none",
-                    duration: 3000
-                })
-                return callback(false)
-            }
-            /* 校验文件格式 */
-            const suffix = ['jpg', 'jpeg', 'png', 'gif', 'pdf'],
-                index = file.url.lastIndexOf("."),
-                ext = file.url.substr(index + 1);
-            if (!suffix.some((value) => value == ext)) {
-                wx.showToast({
-                    title: '错误文件格式',
-                    icon: "none",
-                    duration: 3000
-                })
-                return callback(false)
+            for (let i = 0; i < file.length; i++) {
+                /* 校验文件大小 */
+                if (file[i].size > 10485760) {
+                    wx.showToast({
+                        title: '文件体积大于10Mb',
+                        icon: "none",
+                        duration: 3000
+                    })
+                    return callback(false)
+                }
+                /* 校验文件格式 */
+                const suffix = ['jpg', 'jpeg', 'png', 'gif', 'pdf'],
+                    index = file[i].url.lastIndexOf("."),
+                    ext = file[i].url.substr(index + 1);
+                if (!suffix.some((value) => value == ext)) {
+                    wx.showToast({
+                        title: '错误文件格式',
+                        icon: "none",
+                        duration: 3000
+                    })
+                    return callback(false)
+                }
+                callback(true)
             }
-            callback(true)
         },
         /* 上传图片 */
         afterRead(event) {
-            // 初始化数据
-            let that = this,
-                data = this.requestType(event.detail.file);
-            //发送请求
-            wx.getFileSystemManager().readFile({
-                filePath: event.detail.file.url,
-                success: result => {
-                    //返回临时文件路径
-                    const fileData = result.data
-                    _Http.basic(data).then(res => {
-                        console.log(res)
-                        if(res.msg!="成功")return wx.showToast({
-                          title: res.data,
-                          icon:"none"
-                        })
-                        that.uploadFile(res, fileData)
-                    }).catch(err => {})
-                },
-                fail: console.error
-            })
+            for (let i = 0; i < event.detail.file.length; i++) {
+                // 初始化数据
+                let that = this,
+                    data = this.requestType(event.detail.file[i]);
+                //发送请求
+                wx.getFileSystemManager().readFile({
+                    filePath: event.detail.file[i].url,
+                    success: result => {
+                        //返回临时文件路径
+                        const fileData = result.data
+                        _Http.basic(data).then(res => {
+                            console.log(res)
+                            if (res.msg != "成功") return wx.showToast({
+                                title: res.data,
+                                icon: "none"
+                            })
+                            that.uploadFile(res, fileData)
+                        }).catch(err => {})
+                    },
+                    fail: console.error
+                })
+            }
         },
         /* 上传成功反馈 */
         uploadFile(res, data) {

+ 1 - 1
components/My_UploadFiles/index.wxml

@@ -1,4 +1,4 @@
-<van-uploader  file-list="{{ upType!='userImage'?fileList:'' }}" disabled="{{fisadministrator}}" preview-size='{{previewSize}}' max-count="{{maxCount}}" bind:after-read="afterRead" deletable="{{ true }}" use-before-read bind:before-read="beforeRead" bind:delete="imagesDelete"><!-- multiple="{{true}}" -->
+<van-uploader file-list="{{ upType!='userImage'?fileList:'' }}" disabled="{{fisadministrator}}" preview-size='{{previewSize}}' max-count="{{maxCount}}" bind:after-read="afterRead" deletable="{{ true }}" use-before-read bind:before-read="beforeRead" bind:delete="imagesDelete" multiple="{{true}}">
     <!-- 默认样式 -->
     <view wx:if="{{UploadShow}}" style="height: 100%; display: flex; align-items: center;">
         <view class="upImage_ltem">

+ 1 - 1
project.config.json

@@ -46,7 +46,7 @@
         "useCompilerPlugins": false
     },
     "compileType": "miniprogram",
-    "libVersion": "2.19.6",
+    "libVersion": "2.21.1",
     "appid": "wx5dc7fd18b6335214",
     "projectname": "%E5%B8%83%E4%B8%87%E5%AE%B6%E5%B0%8F%E7%A8%8B%E5%BA%8F",
     "debugOptions": {