原生 input 中的 “type=file“ 上传文件

devtools/2024/9/23 9:34:51/

目标:实现文件上传功能

原型图:

HTML部分:

<div class="invoice-item"><div class="invoice-title">增值税专用发票</div><div class="invoice-box"><el-form-item label="标准模版:" class="Standard-Template"><div v-show="!isEdit && !ruleForm.taxInvoiceTemplateUrl"><span>待上传</span></div><div v-show="isEdit && !ruleForm.taxInvoiceTemplateUrl"><inputref="taxInvoiceTemplateRef"type="file"style="opacity: 0;position: absolute;left: -9999px;top: -9999px;"@change="taxInvoiceTempalteChange"><iclass="el-icon-upload2"style="color: #0075ff; font-size: 22px; cursor: pointer"@click="$refs.taxInvoiceTemplateRef.click()"/><spanstyle="margin-left: 8px":style="{ color: errorText3 ? 'red' : '#999999' }">{{ errorText3 || "支持上传5M以内.pdf格式的文档" }}</span></div><div v-show="ruleForm.taxInvoiceTemplateUrl"><i class="el-icon-document" /><span>{{ ruleForm.taxInvoiceTemplateName }}</span><iv-if="isEdit"class="el-icon-circle-close"style="cursor: pointer"@click="deleteDoc('taxDigitalInvoice')"/></div></el-form-item><el-form-itemlabel="备注信息超长模板:"class="Standard-Template"><divv-show="!isEdit && !ruleForm.taxInvoiceRemarkTemplateUrl"><span>待上传</span></div><divv-show="isEdit && !ruleForm.taxInvoiceRemarkTemplateUrl"><inputref="taxInvoiceRemarkTemplateRef"type="file"style="opacity: 0;position: absolute;left: -9999px;top: -9999px;"@change="taxInvoiceRemarkTemplateChange"><iclass="el-icon-upload2"style="color: #0075ff;font-size: 22px;cursor: pointer;padding-top: 10px;"@click="$refs.taxInvoiceRemarkTemplateRef.click()"/><spanstyle="margin-left: 0px; padding-top: 3px":style="{ color: errorText4 ? 'red' : '#999999' }">{{ errorText4 || "支持上传5M以内.pdf格式的文档" }}</span></div><div v-show="ruleForm.taxInvoiceRemarkTemplateUrl"><i class="el-icon-document" /><span>{{ ruleForm.taxInvoiceRemarkTemplateName }}</span><iv-if="isEdit"class="el-icon-circle-close"style="cursor: pointer"@click="deleteDoc('taxDigitalInvoiceRemarkInfo')"/></div></el-form-item></div></div>

JS部分:

javascript">import * as Api from '@/api/invoiceBasic'data() {return {errorText3: '',errorText4: '',ruleForm: {// 数电发票基础模板taxInvoiceTemplateUrl: '', // 增值税 标准模板taxInvoiceTemplateName: '',taxInvoiceRemarkTemplateUrl: '',taxInvoiceRemarkTemplateName: '',sellerShowAccount: '0',invoiceOperator: ''},rules: {invoiceOperator: [{ required: true, message: '请输入开票人', trigger: 'submit' }]}}},methods: {init() {this.getDetailData()},getDetailData() {this.pageLoading = trueApi.ticketConfigFind().then((res) => {const {taxInvoiceTemplateUrl, taxInvoiceTemplateName,taxInvoiceRemarkTemplateUrl, taxInvoiceRemarkTemplateName,sellerShowAccount, invoiceOperator} = res.data.bodythis.ruleForm.taxInvoiceTemplateUrl = taxInvoiceTemplateUrlthis.ruleForm.taxInvoiceTemplateName = taxInvoiceTemplateNamethis.ruleForm.taxInvoiceRemarkTemplateUrl = taxInvoiceRemarkTemplateUrlthis.ruleForm.taxInvoiceRemarkTemplateName = taxInvoiceRemarkTemplateName// this.ruleForm.taxInvoiceTemplateUrl = taxInvoiceTemplateUrl// this.ruleForm.taxInvoiceTemplateName = taxInvoiceTemplateName// this.ruleForm.ordinaryInvoiceTemplateUrl = ordinaryInvoiceTemplateUrl// this.ruleForm.ordinaryInvoiceTemplateName =//   ordinaryInvoiceTemplateNamethis.ruleForm.invoiceOperator = invoiceOperatorthis.ruleForm.sellerShowAccount = String(Number(sellerShowAccount))}).finally((_) => {this.pageLoading = false})},// 增值税专用发票 标准模板taxInvoiceTempalteChange(e) {const file = e.target.files[0]if (file.name.indexOf('.pdf') === -1 || file.size > 5 * 1024 * 1000) {this.errorText3 = '支持上传5M以内.pdf格式的文档'return}const f2 = new FormData()f2.append('file', file)Api.fastdfsUpload(f2).then((res) => {this.ruleForm.taxInvoiceTemplateName = file.namethis.ruleForm.taxInvoiceTemplateUrl = res.data.body})},// 增值税专用发票 - 备注信息超长taxInvoiceRemarkTemplateChange(e) {const file = e.target.files[0]if (file.name.indexOf('.pdf') === -1 || file.size > 5 * 1024 * 1000) {this.errorText4 = '支持上传5M以内.pdf格式的文档'return}const f3 = new FormData()f3.append('file', file)Api.fastdfsUpload(f3).then((res) => {this.ruleForm.taxInvoiceRemarkTemplateName = file.namethis.ruleForm.taxInvoiceRemarkTemplateUrl = res.data.body})},
},

CSS部分:

.invoice-item {

      float: left;

      width: 430px;

      height: 140px;

      // height: 126px;

      border-radius: 12px;

      margin-top: 12px;

      margin-bottom: 22px;

      background: linear-gradient(to right, #cfe8ff, #f8fcff);

      .invoice-box {

        width: 100%;

        .remark-Template {

          /deep/ .el-form-item {

            margin-bottom: 0px;

          }

        }

        /deep/ .el-form-item__label {

          width: fit-content !important;

          padding-left: 20px;

          font-weight: 600;

          font-size: 12px;

          color: #101010;

        }

        /deep/ .el-form-item__content {

          text-align: right;

          padding-right: 20px;

          margin-left: 180px !important;

        }

      }

    }

    .invoice-title {

      font-weight: 600;

      font-size: 16px;

      color: #0075ff;

      padding: 20px;

      padding-bottom: 8px;

    }

效果:


http://www.ppmy.cn/devtools/114000.html

相关文章

C#笔记11 获取线程及其信息,什么是优先级、单元状态、线程状态、执行状态、线程名称以及其他属性?

前文讲完了在C#中线程怎么创建&#xff0c;怎么删除&#xff0c;怎么启动&#xff0c;怎么阻止。 现在来看看线程本身的属性。 当前线程 首先要获得当前线程&#xff0c;才能获取线程信息&#xff0c;此属性用于获取当前运行的线程。此属性可用于获取代码当前执行所在的线程…

实战16-RVP定义完成适配

新增文件 //设计搞总宽度 const DRAFT_WIDTH 360//将元素的设计搞大小转化为真机中的大小 export default function rvp(val: number) {/*计算元素真正的大小&#xff1b;* 元素在设计稿的大小 / 设计搞总宽度 x / 真机宽度 (保证元素在不同设备占比相同)x 元素在设计稿的大…

探索Go语言中的随机数生成、矩阵运算与数独验证

1. Go中的随机数生成 在许多编程任务中&#xff0c;随机数的生成是不可或缺的。Go语言通过 math/rand 包提供了伪随机数生成方式。伪随机数由种子(seed)决定&#xff0c;如果种子相同&#xff0c;生成的数列也会相同。为了确保每次程序运行时产生不同的随机数&#xff0c;我们…

CSS3中的@media查询

CSS3的media查询是一种强大的功能&#xff0c;允许我们根据不同的媒体类型和设备特性来应用不同的样式规则。这使得我们能够创建响应式设计&#xff0c;确保网站或应用在各种设备和屏幕尺寸上都能提供良好的用户体验。本文将详细探讨media查询的定义、语法、使用场景及常见问题…

听劝!千万别让外贸信息差害惨你!

在竞争激烈的外贸行业中&#xff0c;一个老客户的华丽转型案例&#xff0c;深刻地向我们揭示了信息差的至关重要性。天津谊*进出口有限公司曾经在传统外贸模式下艰难前行的企业&#xff0c;通过敏锐地捕捉信息、巧妙地利用信息差&#xff0c;成功实现了令人瞩目的蜕变。本文将从…

linux--防火墙

linux防火墙 ubuntu 1&#xff0c; 关于ufw 查看防火墙&#xff1a; sudo ufw status 关闭防火墙&#xff1a; sudo ufw disable 开启&#xff1a; sudo ufw enable 2&#xff0c;firewalld 执行&#xff1a; systemctl status firewalld 出现&#xff1a; Unit fi…

鸿蒙开发(NEXT/API 12)【获取服务器资源】远场通信服务

场景介绍 获取服务器资源&#xff0c;使用GET请求。 开发步骤 导入模块。 import { rcp } from kit.RemoteCommunicationKit; import { BusinessError } from kit.BasicServicesKit;发起请求。""请根据实际情况替换为想要请求的URL地址。 const session rcp.cr…

前后端分离——瑞吉外卖

文章目录 1. 前后端分离开发1.1 介绍1.2 开发流程1.3 前端技术栈 2. Yapi2.1 介绍2.2 使用 3. Swagger3.1 介绍3.2 使用方式1、导入knife4j的maven坐标2、导入knife4j相关配置类 3.3 常用注解 4. 项目部署4.1 部署架构4.2 部署环境说明4.3 部署前端项目4.4 部署后端项目 1. 前后…