当前位置: 首页 > news >正文

Vue 学习随笔系列二十五 -- 多文件上传并支持修改

多文件上传表格展示

文章目录

  • 多文件上传表格展示
    • 1、实现效果
    • 2、源码实现


1、实现效果

新增/修改附件信息
在这里插入图片描述

展示附件信息
在这里插入图片描述

2、源码实现

<template><el-dialog:title="title":visible.sync="visible":before-close="handleClose"width="80%":close-on-click-modal="false"><div v-if="type!=='review'" class="content-box"><h3>附件信息</h3><el-table border stripe :data="reportFileInfoList"><el-table-column type="index" label="序号" width="55" align="center"></el-table-column><el-table-columnv-for="(item, index) in attachmentColumns":key="index":prop="item.prop":label="item.label":min-width="item.width"align="center"><template v-slot="scope"><div v-if="item.prop == 'fileName'"><el-tag v-for="(item, index) in scope.row.fileName":key="item"type=""closable@close="handleRemoveTag(scope.row, item)"> {{item}}</el-tag></div><span v-else> {{ scope.row[item.prop] }} </span></template></el-table-column><el-table-columnlabel="上传附件"width="120"align="center"><template v-slot="scope"><!-- <span class="opr-btn">上传附件</span> --><el-uploadclass="upload-demo"action="#":auto-upload="true":before-upload="beforeUpload":file-list="fileList":show-file-list="false"><el-button size="mini" type="text" @click="selectRow(scope.row)">点击上传</el-button></el-upload></template></el-table-column></el-table></div><!-- 查看详情部分 --><div v-if="type == 'review'" class="content-box"><h3>附件信息</h3><el-table border stripe v-if="type == 'review'":data="reportFileInfoListTemp"><el-table-column type="index" label="序号" width="55" align="center"></el-table-column><el-table-columnv-for="(item, index) in attachmentColumnsReview":key="index":prop="item.prop":label="item.label":min-width="item.width"align="center"></el-table-column></el-table></div><div slot="footer" class="dialog-footer"><el-button size="small" @click="handleClose">取 消</el-button><el-button size="small" type="primary" @click="handleSubmit">确 定</el-button></div></el-dialog>
</template><script>import { uploadFile } from "@/api/xxxx/index.js"export default {data() {return {visible: false,type: "add",fileType: "",reportFileInfoListTemp: [],reportFileInfoList: [{type: "发票",fileName: [],fileId: [],},{type: "附件信息",fileName: [],fileId: [],},{type: "电子附件",fileName: [],fileId: [],},],attachmentColumns: [{prop: "type",label: "附件类型",width: 120,},{prop: "fileName",label: "附件信息",width: 260,},],attachmentColumnsReview: [{prop: "type",label: "附件类型",width: 120,},{prop: "fileName",label: "附件信息",width: 260,},{prop: "fileFlowNo",label: "文件流水号",width: 120,},{prop: "fileStatus",label: "文件状态",width: 100,},],fileList: [],reportDealHisList: [],};},computed: {disabled() {return this.type === "review";},title() {if(this.type == "review") {return "查看信息"} else if(this.type == "add") {return "新增信息" } else {return "修改信息"}},},methods: {handleClose() {this.visible = false;this.reportFileInfoList = [{type: "发票",fileName: [],fileId: [],},{type: "附件信息",fileName: [],fileId: [],},{type: "电子附件",fileName: [],fileId: [],},],},// 合并 reportFileInfoListmergeReportFileInfoList(originalList) {const mergedMap = new Map();// 合并原始数据originalList.forEach(item => {if (mergedMap.has(item.type)) {const mergedItem = mergedMap.get(item.type);mergedItem.fileName.push(item.fileName);mergedItem.fileId.push(item.fileId);} else {mergedMap.set(item.type, {type: item.type,fileName: [item.fileName],fileId: [item.fileId]});}});// 确保包含 "发票", "附件信息", "电子附件" 类型const defaultTypes = ["发票", "附件信息", "电子附件"];defaultTypes.forEach(type => {if (!mergedMap.has(type)) {mergedMap.set(type, {type: type,fileName: [],fileId: []});}});return Array.from(mergedMap.values());},handleOpen(val) {this.visible = true;this.type = val.type;if(this.type == "add") {this.reportExpensesInfo.reportingPeriod = this.$moment().format("YYYY-MM");return}this.reportFileInfoListTemp = val.row.reportFileInfoList || [];const originalReportFileInfoList = val.row.reportFileInfoList || [];// 调用合并方法this.reportFileInfoList = this.mergeReportFileInfoList(originalReportFileInfoList);},handleSubmit() {this.$refs.form.validate((valid) => {if (!valid)  returnconst params = { reportFileInfoList: this.reportFileInfoListTemp,}this.$emit("handleSubmit", params);this.handleClose();})},beforeUpload(file) {const params = new FormData()params.append('file', file)uploadFile(params).then(res => {if(res.code == 200) {this.$message.success(res.msg)this.reportFileInfoListTemp.push({type: this.fileType,fileName: res.data.fileName,fileId: res.data.fileId,})this.reportFileInfoList = this.reportFileInfoList.map(item => {if(item.type == this.fileType) {item.fileId.push(res.data.fileId);item.fileName.push(res.data.fileName)} return item})}})return false;},selectRow(row) {this.fileType = row.type},// 移除文件handleRemoveTag(row, tag){// 删除 reportFileInfoListTemp 中 filename 和 tag 匹配的项this.reportFileInfoListTemp = this.reportFileInfoListTemp.filter(item => item.fileName !== tag);// 删除表格中 filename 与 tag 匹配的项this.reportFileInfoList= this.reportFileInfoList.map(item => {if(item.type == row.type) {const index = item.fileName.indexOf(tag);if (index > -1) {// 移除对应的文件名item.fileName.splice(index, 1);// 移除对应的文件IDitem.fileId.splice(index, 1); }}return item})}},
};
</script><style lang="scss" scoped>
.dialog-footer {text-align: center;
}.opr-btn {cursor: pointer;color: #409eff;
}
h3 {margin: 10px 0;
}
.el-tag {margin: 0 5px;
}
</style>

文章转载自:

http://iW2vjs47.Lhjmq.cn
http://yGqlhN56.Lhjmq.cn
http://3gDEnHC9.Lhjmq.cn
http://hjkkUySV.Lhjmq.cn
http://yYeth9Dq.Lhjmq.cn
http://h2INdzvF.Lhjmq.cn
http://NrvdSnph.Lhjmq.cn
http://2vHvF6M8.Lhjmq.cn
http://Vv5Ijjx3.Lhjmq.cn
http://MhzeQksQ.Lhjmq.cn
http://d0SdOWgS.Lhjmq.cn
http://jamyg5Zu.Lhjmq.cn
http://ZgGc0V00.Lhjmq.cn
http://HWTrNWnh.Lhjmq.cn
http://cKFthMoN.Lhjmq.cn
http://nypWkEKC.Lhjmq.cn
http://7dk1IRS4.Lhjmq.cn
http://yl63ENcX.Lhjmq.cn
http://nfC5x1rV.Lhjmq.cn
http://a8fTUPNt.Lhjmq.cn
http://wxxElNP6.Lhjmq.cn
http://kmiLz99Y.Lhjmq.cn
http://9QsK5YnM.Lhjmq.cn
http://wiexvjhx.Lhjmq.cn
http://pMURPPWL.Lhjmq.cn
http://H0zcHHZa.Lhjmq.cn
http://nGEoj3xg.Lhjmq.cn
http://1XKczbLh.Lhjmq.cn
http://cYneM2zO.Lhjmq.cn
http://szpOKaOL.Lhjmq.cn
http://www.dtcms.com/a/375583.html

相关文章:

  • 从0到1学习Vue框架Day03
  • 【Redis五种数据类型】
  • Redis 双向同步如何避免循环?【附实操演示】
  • Redis单线程模型为什么快?
  • At least one <template> or <script> is required in a single file component
  • 不止是DELETE:MySQL多表关联删除的JOIN语法实战详解
  • 动态控制rabbitmq中的消费者监听的启动和停止
  • C# 基于halcon的视觉工作流-章30-圆圆距离测量
  • Android Studio 构建项目时 Gradle 下载失败的解决方案
  • 【STM32项目开源】STM32单片机智能恒温箱控制系统
  • 苹果ios的系统app应用WebClip免签应用开源及方式原理
  • Java数据库连接JDBC完全解析
  • Node-RED 究竟是否适合工业场景?
  • zephyr开发环境搭建
  • OpenCV 实战:基于模板匹配的身份证号自动识别系统
  • java中将租户ID包装为JSQLParser的StringValue表达式对象,JSQLParser指的是?
  • CMake工程指南
  • 单北斗GNSS该如何在变形监测中发挥最大效能?
  • 大数据毕业设计-基于大数据的高考志愿填报推荐系统(高分计算机毕业设计选题·定制开发·真正大数据)
  • 分布式锁redis
  • Java学习之——“IO流“的进阶流之转换流的学习
  • git 如何直接拉去远程仓库的内容且忽略本地与远端不一致的commit
  • 每日一算:分发糖果
  • 神经算子学习
  • AI大模型入门1.1-python基础字符串代码
  • Tlias管理系统(多表查询-内连接外连接)
  • win11家庭版配置远程桌面
  • 8. LangChain4j + 提示词工程详细说明
  • ChatGPT大模型训练指南:如何借助动态代理IP提高训练效率
  • 利用git进行版本控制