update upload

qianlishi 3 years ago
parent 3339556efd
commit 50691b05c5

@ -13,10 +13,7 @@
:before-upload="handleBeforeUpload" :before-upload="handleBeforeUpload"
:class="fileList && fileList.length >= limit ? 'hide_box' : ''" :class="fileList && fileList.length >= limit ? 'hide_box' : ''"
> >
<i slot="default" class="el-icon-plus" /> <i class="el-icon-plus" />
<div slot="file" slot-scope="{ file }" class="imgBox">
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
</div>
</el-upload> </el-upload>
<el-dialog :visible.sync="dialogVisibleImageUpload" :modal="false"> <el-dialog :visible.sync="dialogVisibleImageUpload" :modal="false">
<img width="100%" :src="imageUploadUrl" alt="" /> <img width="100%" :src="imageUploadUrl" alt="" />
@ -86,13 +83,7 @@ export default {
}, },
methods: { methods: {
handleRemove(file) { handleRemove(file) {
const fileList = []; this.fileList = [];
this.fileList.forEach(el => {
if (el.fileId != file.fileId) {
fileList.push(el);
}
});
this.fileList = fileList;
this.change(); this.change();
}, },
handlePictureCardPreview(file) { handlePictureCardPreview(file) {
@ -101,20 +92,18 @@ export default {
}, },
// //
handleSuccess(response, file, fileList) { handleSuccess(response, file, fileList) {
console.log(fileList);
if (response.code != 200) { if (response.code != 200) {
this.$message.error("上传失败"); this.$message.error("上传失败");
return; return;
} }
this.fileList.push({ this.fileList.push({
url: file.response.data.urlPath, url: file.response.data.urlPath
fileId: file.response.data.fileId
}); });
this.change(); this.change();
}, },
// //
change() { change() {
const fileList = this.fileList[0]["fileId"]; const fileList = (this.fileList.length > 0 && this.fileList[0].url) || "";
this.$emit("input", fileList); this.$emit("input", fileList);
this.$emit("change", fileList); this.$emit("change", fileList);
}, },
@ -136,7 +125,7 @@ export default {
if (!val) { if (!val) {
this.fileList = []; this.fileList = [];
} else { } else {
const list = [{ url: this.viewUrl + val, fileId: val }]; const list = [{ url: val }];
this.fileList = list; this.fileList = list;
} }
} }
@ -153,7 +142,7 @@ export default {
width: 60px; width: 60px;
height: 60px; height: 60px;
} }
.hide_box .el-upload--picture-card { .hide_box /deep/ .el-upload--picture-card {
display: none; display: none;
} }
.el-upload-list__item { .el-upload-list__item {

Loading…
Cancel
Save