diff --git a/template/admin/src/components/uploadImg/index.vue b/template/admin/src/components/uploadImg/index.vue index cbbc3008f..03b26d9a5 100644 --- a/template/admin/src/components/uploadImg/index.vue +++ b/template/admin/src/components/uploadImg/index.vue @@ -8,7 +8,7 @@ width="1024px" @closed="closed" > -
+
@@ -43,6 +43,8 @@ :data="uploadData" :headers="header" :before-upload="beforeUpload" + :multiple="true" + :limit="limit" >
{ return e.url; }); - onlineUpload({ pid: this.treeId, images: urls }).then((res) => { - this.$Message.success('上传成功'); - this.$emit('uploadSuccess'); - this.uploadModal = false; - }); + if (urls.length) { + if (this.loading) return; + this.loading = true; + onlineUpload({ pid: this.treeId, images: urls }) + .then((res) => { + this.$Message.success('上传成功'); + this.$emit('uploadSuccess'); + this.uploadModal = false; + this.loading = false; + }) + .catch((err) => { + this.loading = false; + this.$Message.error(err.msg); + }); + } } else if (this.ruleForm.type == 2) { let attId = this.ruleForm.imgList.map((e) => { return e.att_id; @@ -243,6 +262,7 @@ export default { resolve(); // this.$emit('uploadImgSuccess', res.data); } else { + this.loading = false; this.$message({ message: '上传失败', type: 'error', @@ -251,6 +271,7 @@ export default { } }) .catch((err) => { + this.loading = false; this.$Message.error(err.msg); }); }); @@ -281,12 +302,25 @@ export default { handleDownload(file) { console.log(file); }, - fileChange(file, fileList) { - console.log(file, fileList); - this.ruleForm.imgList = fileList; - compressImg(file.raw).then((res) => { - if (fileList.length) fileList[fileList.length - 1].raw = res; + async fileChange(file, fileList) { + if (file.size >= 2097152) { + await this.comImg(file.raw).then((res) => { + fileList.map((e) => { + if (e.uid === file.uid) { + e.raw = res; + } + }); + this.ruleForm.imgList = fileList; + }); + } else { this.ruleForm.imgList = fileList; + } + }, + comImg(file) { + return new Promise((resolve, reject) => { + compressImg(file).then((res) => { + resolve(res); + }); }); }, loadData(item, callback) {