这个是大概思路
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<a class="f_blue ml-8">添加附件</a>
<input type="file" id="DevanningImg_file"
class="DevanningImg_file"
@change="handleFile()"
accept="image/png, image/jpeg, image/jpg"
multiple="multiple"
/>
<!-- 装箱图片、拆箱图片上传图片列表显示--开始 -->
<div class="browse" v-for="(item,index) in fileList" :key="item.imgName">
<span class="DevanningImg_showFile">{{`${item.imgName}(${item.imgSize})`}}</span>
<span class="showFile">
<a class="f_blue" @click="deleteFile(index)">删除</a>
<span class="ml8 mr8">|</span>
<a class="f_blue" @click="seeImg(index)">查看</a>
</span>
</div>
<script>
/**点击添加附件触发事件 */
handleFile(type) {
let file = document.getElementById("ReportBox_file");
this.myfile = file.files[0];//获取file文件
let formData = new FormData();
formData.append("myfile", this.myfile);
formData.append("actionType", "sendImg");
formData.append("orderType", this.orderType == "拆箱" ? 0 : 1);
service.uploadImg(this.selected[0].ID, formData).then(res => {
if (res.data.code == 0) {
window.el_message("success", "上传成功");
let ReportBox_obj = res.data.data;
this.ReportBox_fileList.push(ReportBox_obj);
}
});
},
//点击删除触发的事件
deleteFile(type, index) {
let file;
file = this.ReportBox__fileList[index];
this.ReportBox__fileList.splice(index, 1);
let params = {
actionType: "sendImg",
orderType: this.orderType == "拆箱" ? 0 : 1,
file: file.imgName
};
service.delUploadImg(this.selected[0].ID, params).then(res => {
if (res.data.code == 0) {
window.el_message("success", "删除成功");
}
});
},
//查看
seeImg(type, index) {
this.uploadImgCheck = true;
this.srcs = this.ReportBox_fileList[index].imgPath;
// window.open(
// this.srcs,
// "查看照片",
// "height=600, width=700, top=300, left=500, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
// );
},
</script>
</body>
</html>