-
zhangwei
2025-03-06 02ad32582e3a3b0e6f4b2d1b50593eff1d0558e3
src/components/tem/tem-upload-file.vue
@@ -142,6 +142,12 @@
               return ['album', 'camera']
            }
         },
         isSource: {
            type: Boolean,
            default () {
               return false
            }
         },
         //图片后缀名限制
         suffix: {
            type: Array,
@@ -311,6 +317,70 @@
                  'success_action_status': "200" //上传成功后响应状态码
               }
            })
            if (this.isSource) {
               uni.chooseImage({
                  count: max === -1 ? 9 : max - this.urls.length,
                  sizeType: this.sizeType,
                  sourceType: this.sourceType,
                  success: (e) => {
                     let imageArr = [];
                     for (let i = 0; i < e.tempFiles.length; i++) {
                        let len = this.urls.length;
                        if (len >= max && max !== -1) {
                           this.toast(`最多可上传${max}张图片`);
                           break;
                        }
                        //过滤图片类型
                        let path = e.tempFiles[i].path;
                        if (this.suffix.length > 0) {
                           let format = ""
                           // #ifdef H5
                           let type = e.tempFiles[i].type;
                           format = type.split('/')[1]
                           // #endif
                           // #ifndef H5
                           format = path.split(".")[(path.split(".")).length - 1];
                           // #endif
                           if (this.suffix.indexOf(format) == -1) {
                              let text = `只能上传 ${this.suffix.join(',')} 格式图片!`
                              this.toast(text);
                              continue;
                           }
                        }
                        //过滤超出大小限制图片
                        let size = e.tempFiles[i].size;
                        if (Number(this.size) * 1024 * 1024 < size) {
                           let err = `单张图片大小不能超过:${this.size}MB`
                           this.toast(err);
                           continue;
                        }
                        imageArr.push(path)
                        this.urls.push(path)
                        this.tempFiles.push(e.tempFiles[i])
                        this.status.push(this.immediate ? 'uploading' : 'preupload')
                     }
                     this.onComplete('choose')
                     let start = this.urls.length - imageArr.length
                     if (this.immediate) {
                        for (let j = 0; j < imageArr.length; j++) {
                           let index = start + j
                           let obj = JSON.parse(JSON.stringify(this.formDataNew))
                           obj.key = this.$util.generateTimestampWithRandom(imageArr[j])
                           this.uploadImage(index, imageArr[j], null, obj).then((res) => {
                              this._success(res)
                           }).catch((res) => {
                              this._error(res)
                           })
                        }
                     }
                  }
               })
            } else {
            wx.chooseMessageFile({
               count: max === -1 ? 9 : max - this.urls.length,
               type: this.fileType,
@@ -337,8 +407,7 @@
                        // #endif
                        console.log(format);
                        if (this.suffix.indexOf(format) == -1) {
                           // let text = `只能上传 ${this.suffix.join(',')} 格式!`
                           let text = `只能上传 doc,docx,pdf 格式!`
                              let text = `只能上传 ${this.suffix.join(',')} 格式!`
                           this.toast(text);
                           continue;
                        }
@@ -374,6 +443,8 @@
               },
               fail: () => {}
            })
            }
            // uni.chooseFile({
            //    count: max === -1 ? 9 : max - this.urls.length,
            //    extension: ['.doc', '.pdf', '.docx'],