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

点击上传文件

一、页面样式:
(1)点击前:
在这里插入图片描述
(2)点击后:
在这里插入图片描述

设计:①自定义elementPlus图标;②使用Tooltip实现鼠标悬浮按钮上出现文字提示;③上传与更换的切换样式;
前端:通过chooseVideochooseVideoFile这两个方法,分别去①限制点击上传的文件类型;②获取到上传的文件this.fileInfo.selectedFilethis.fileInfo.selectedVideoFile传给后端进一步处理;③通过拿到的文件直接可以fileInfo.selectedFile.name获取到文件名;
在这里插入图片描述
二、前端代码

<el-dialog v-model="addVideoFile" :before-close="closeDialog" title="新增视频"  width="800px"><el-form :model="fileInfo" label-position="left" label-width="100px"><el-form-item label="视频:"><span v-if="fileInfo.selectedFile" style="margin-right: 5px;color: black">{{fileInfo.selectedFile.name}}</span><el-button type="primary" @click="chooseVideo">{{ fileInfo.selectedFile ? "更换视频" : "上传视频" }}<el-icon class="el-icon--right"><UploadFilled /></el-icon></el-button></el-form-item><el-form-item label="压缩包:"><span v-if="fileInfo.selectedVideoFile" style="margin-right: 5px;color: black">{{fileInfo.selectedVideoFile.name}}</span><el-tooltip content="支持word/excel/pdf/zip/exe/md/rar/mp4/txt文件" placement="bottom" effect="light"><el-button type="primary" @click="chooseVideoFile">{{ fileInfo.selectedVideoFile ? "更换压缩包" : "上传压缩包" }}<el-icon class="el-icon--right"><Briefcase /></el-icon></el-button></el-tooltip></el-form-item></el-form><template #footer><span class="dialog-footer"><el-button @click="addVideoFile = false; ">取消</el-button><el-button type="primary" @click="addVideoList">确认</el-button></span></template></el-dialog>
// 点击新增视频openAddVideoFile(){this.resetVideoFile();this.addVideoFile = true;},closeDialog() {this.addVideoFile = false;},//清空新增弹框数据resetVideoFile(){this.fileInfo.id = null;this.fileInfo.title = '';this.fileInfo.content = '';this.fileInfo.url = '';},//点击上传视频chooseVideo() {const fileInput = document.createElement("input");fileInput.style.display = "none";fileInput.type = "file";fileInput.accept = "video/*"; // 限制接受所有视频类型fileInput.onchange = () => {if (fileInput.files) {if (this.addVideoFile === true){this.fileInfo.selectedFile = fileInput.files[0];console.log("********************this.fileInfo.selectedFile",this.fileInfo.selectedFile);}}fileInput.remove();};// 触发文件选择对话框fileInput.click();},chooseVideoFile(){const fileInput = document.createElement("input");fileInput.style.display = "none";fileInput.type = "file";fileInput.accept = ".doc,.docx,application/pdf,.xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,.zip,application/x-msdownload,.md,application/x-rar-compressed,video/mp4,text/plain";fileInput.onchange = () => {if (fileInput.files) {if (this.addVideoFile === true){this.fileInfo.selectedVideoFile = fileInput.files[0];console.log("********************this.fileInfo.selectedVideoFile",this.fileInfo.selectedVideoFile);}}fileInput.remove();};// 触发文件选择对话框fileInput.click();},// 新增视频提交addVideoList(){if(this.$dataFormat.isEmpty(this.fileInfo.title)||this.$dataFormat.isEmpty(this.fileInfo.content)||this.$dataFormat.isEmpty(this.fileInfo.selectedVideoFile)){ElMessage({message: '请先补全信息',type: 'warning',})return;}// 检查是否选择了文件if (this.fileInfo.selectedFile || this.fileInfo.selectedVideoFile){let url = "/ArDownLoad/addVideoList";let data = {type:2,//查视频管理的所有数据fileType:'v',//v:视频title: this.fileInfo.title,content:this.fileInfo.content,url:this.fileInfo.selectedFile,videoUrl:this.fileInfo.selectedVideoFile,}this.$request.postForm(url,data).then(res =>{this.$msg.warning('新增成功!')this.addVideoFile = false;this.videoFilter();}).catch(() => {})}},

三、后端代码
调用了文件处理的封装方法,哈哈

http://www.lryc.cn/news/337076.html

相关文章:

  • 文件上传【2】--靶场通关
  • uniapp请求后端接口
  • 第十三章 OpenGL ES-RGB、HSV、HSL模型介绍
  • 微软卡内基梅隆大学:无外部干预,GPT4等大语言模型难以自主探索
  • 探索设计模式的魅力:简单工厂模式
  • 【数据结构】-----双链表(小白必看!!!)
  • 【数据结构】考研真题攻克与重点知识点剖析 - 第 8 篇:排序
  • 数字乡村可视化大数据-DIY拖拽式设计
  • 数据集学习
  • 【解决】npm run dev Syntax Error: TypeError: eslint.CLIEngine is not a constructor
  • Android 如何通过屏幕大小来适配不同大小的图片
  • 【面试题】细说mysql中的各种锁
  • TMS320F280049 EPWM模块--TZ子模块(6)
  • 数字乡村创新实践探索农业现代化路径:科技赋能农业产业升级、提升乡村治理效能与农民幸福感
  • linux中rpm包与deb包的区别及使用
  • Linux中安装seata
  • 预印本仓库ArXiv——防止论文录用前被别人剽窃
  • LNMP 架构
  • 谈谈Python中的单元测试和集成测试
  • 【2024】Prometheus通过node_exporter都监控了什么
  • Centos7配置秘钥实现集群免密登录
  • Android匿名共享内存(Ashmem)
  • MySOL之旅--------MySQL数据库基础( 3 )
  • 阿药陪你学Java(第零讲)
  • 华院计算参编《金融业人工智能平台技术要求》标准
  • vue3-element-admin二次开发遇到的问题总结,持续更新中
  • SpringMVC数据接收(全面/详细注释)
  • golang 冒泡、选择、插入、快速排序法
  • vue3 +Taro 页面实现scroll-view 分页功能
  • 【http】常见http headers