Commit 582fead405ffa49053bf414c618ffeb60035a0e3
1 parent
20bf581a
v3.8.2 组件ImageUpload支持多图同时选择上传
Showing
1 changed file
with
12 additions
and
3 deletions
yudao-ui-admin/src/components/ImageUpload/index.vue
| 1 | <template> | 1 | <template> |
| 2 | <div class="component-upload-image"> | 2 | <div class="component-upload-image"> |
| 3 | <el-upload | 3 | <el-upload |
| 4 | + multiple | ||
| 4 | :action="uploadImgUrl" | 5 | :action="uploadImgUrl" |
| 5 | list-type="picture-card" | 6 | list-type="picture-card" |
| 6 | :on-success="handleUploadSuccess" | 7 | :on-success="handleUploadSuccess" |
| @@ -70,6 +71,8 @@ export default { | @@ -70,6 +71,8 @@ export default { | ||
| 70 | }, | 71 | }, |
| 71 | data() { | 72 | data() { |
| 72 | return { | 73 | return { |
| 74 | + number: 0, | ||
| 75 | + uploadList: [], | ||
| 73 | dialogImageUrl: "", | 76 | dialogImageUrl: "", |
| 74 | dialogVisible: false, | 77 | dialogVisible: false, |
| 75 | hideUpload: false, | 78 | hideUpload: false, |
| @@ -124,9 +127,14 @@ export default { | @@ -124,9 +127,14 @@ export default { | ||
| 124 | }, | 127 | }, |
| 125 | // 上传成功回调 | 128 | // 上传成功回调 |
| 126 | handleUploadSuccess(res) { | 129 | handleUploadSuccess(res) { |
| 127 | - this.fileList.push({ name: res.fileName, url: res.fileName }); | ||
| 128 | - this.$emit("input", this.listToString(this.fileList)); | ||
| 129 | - this.loading.close(); | 130 | + this.uploadList.push({ name: res.fileName, url: res.fileName }); |
| 131 | + if (this.uploadList.length === this.number) { | ||
| 132 | + this.fileList = this.fileList.concat(this.uploadList); | ||
| 133 | + this.uploadList = []; | ||
| 134 | + this.number = 0; | ||
| 135 | + this.$emit("input", this.listToString(this.fileList)); | ||
| 136 | + this.loading.close(); | ||
| 137 | + } | ||
| 130 | }, | 138 | }, |
| 131 | // 上传前loading加载 | 139 | // 上传前loading加载 |
| 132 | handleBeforeUpload(file) { | 140 | handleBeforeUpload(file) { |
| @@ -163,6 +171,7 @@ export default { | @@ -163,6 +171,7 @@ export default { | ||
| 163 | text: "上传中", | 171 | text: "上传中", |
| 164 | background: "rgba(0, 0, 0, 0.7)", | 172 | background: "rgba(0, 0, 0, 0.7)", |
| 165 | }); | 173 | }); |
| 174 | + this.number++; | ||
| 166 | }, | 175 | }, |
| 167 | // 文件个数超出 | 176 | // 文件个数超出 |
| 168 | handleExceed() { | 177 | handleExceed() { |