vue2导入

父页面

<template>
  <div>
    <div>
      <el-button size="small" @click="excelFn">导入</el-button>
    </div>
    <div v-if="ExcelInSure">
      <excelln :names="names" @close="closeFn"></excelln>
    </div>
  </div>
</template>
<script>
import excelln from './excelln.vue'

export default {
  data() {
    return {
      ExcelInSure: false,
      names: '',
      templateDialogVisible: true,
      showProgress: false,
    }
  },
  components: { excelln },

  methods: {
    // 导入
    excelFn() {
      this.ExcelInSure = true
      this.names = 'WorkExecution'
    },
  },
}
</script>

子页面

<template>
  <el-dialog title="导入" :visible.sync="templateDialogVisible" width="50%" :before-close="onCancel">
    <div class="importFile-win">
      <div class="importFile-con">
        <el-upload
          class="upload-demo"
          style="position: relative"
          ref="upload"
          name="file"
          action="#"
          drag
          :http-request="handleFileUpload"
          :headers="curheaderObj"
          :file-list="fileList"
          :on-success="uploadSuccess"
          :on-error="uploadError"
          :before-upload="beforeUpload"
          :before-remove="beforeRemove"
          :auto-upload="false"
          accept=".xls,.xlsx"
          :limit="1"
        >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
        </el-upload>
        <div v-if="this.name !== 'WorkExecution'" class="downLoad-model">
          <a @click="download">点击模板下载</a>
          <span>只能上传xls/xlsx文件,且一次只能选择一个文件</span>
        </div>
        <div class="downLoad-message">{{ downloadMessage }}</div>
        <el-progress v-if="showProgress" type="circle" :percentage="percent" class="progress" />
      </div>
      <div class="dialog-footer">
        <el-button @click="onCancel">关闭</el-button>
        <el-button type="primary" @click="submitUpload" :loading="loadingList.importFile">上传</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { get, post } from '@/utils/request'
// 下载
export function xiazai() {
  return get('/123', null, { responseType: 'blob' })
}
// 导入
export function daoru(datas, config) {
  return post('/daoru', datas, config).then(res => res)
}
export function daoruapi(data) {
  return get('/456', data, { responseType: 'blob' }).then()
}

export function czyz(data) {
  return post('546', data).then()
}

export default {
  name: 'uploadExcel',
  data() {
    return {
      name: '',
      loadingList: {
        importFile: false,
      },
      templateDialogVisible: true,

      fileList: [],
      curheaderObj: {},
      downloadMessage: '',
      showProgress: false,
      percent: 0,
      dataexcel: this.excelData,
      idRouter: this.routerId,
    }
  },
  props: {
    names: {
      type: String,
      default: '',
    },
    excelData: {
      type: Object,
      default: () => {},
    },
    routerId: {
      type: String,
    },
  },
  watch: {
    excelData(newVlaue) {
      this.dataexcel = newVlaue
    },
    routerId(newVlaue) {
      this.idRouter = newVlaue
    },
  },
  created() {
    this.name = this.names
  },
  methods: {
    // 下载模板
    async download() {
      if (this.names === 'violations') await xiazai()
      if (this.names == 'TemplateImport')
        await daoruapi({ templateId: this.routerId, tableName: this.dataexcel.tableName })
      this.$message.success('下载模板成功')
    },
    handleFileUpload(fileObject) {
      if (this.name == 'WorkExecution') {
        this.showProgress = true
        var formData = new FormData()
        formData.append('file', fileObject.file)
        const Types = {
          WorkExecution: {
            method: czyz,
            fileName: 'xxxxxxxx',
          },
        }

        Types[this.names].method(formData).then(res => {
          fileObject.onSuccess(res)
          if (res.success && res.data) {
            this.downloadFile(res.data, Types[this.names].fileName)
          }
        })
      } else {
        this.showProgress = true
        var formDatas = new FormData()
        formDatas.append('file', fileObject.file)
        formDatas.append('templateTableId', this.dataexcel.id)
        formDatas.append('templateId', this.idRouter)
        // 请求
        const Type = {
          violations: {
            method: daoru,
            fileName: 'xxxx3',
          },
        }

        Type[this.names].method(formDatas).then(res => {
          fileObject.onSuccess(res)
          if (res.success && res.data) {
            this.downloadFile(res.data, Type[this.names].fileName)
          }
        })
      }
    },

    beforeRemove(file, fileList) {
      this.$confirm(`确定移除 ${file.name}?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消、',
        type: 'warning',
      })
        .then(function () {
          let index = fileList.findIndex(fileItem => fileItem.uid === file.uid)
          fileList.splice(index, 1)
          this.fileList = fileList
          this.$message.success(`删除${file.name}成功!`)
        })
        .catch(function () {})
      // 阻止其内部删除操作
      return false
    },
    // 关闭
    onCancel() {
      this.templateDialogVisible = false
      this.$emit('close', false)
    },
    submitUpload() {
      this.$refs.upload.submit()
    },
    //导入文件连接成功
    uploadSuccess(response, file, fileList) {
      if (response.code === 20000 && response.success === true) {
        this.showProgress = false
        if (response.success && response.data) {
          this.$message.success('文件导入完成,请注意查看结果')
          this.downloadMessage = response.message
        }
        if (response.success && !response.data) {
          this.$message.success('文件导入成功')
          // 提交后刷新列表
          this.onCancel()
        }
      }
    },
    downloadFile(response, fileName) {
      let bstr = window.atob(response)
      let n = bstr.length
      let u8arr = new Uint8Array(n)
      while (n--) {
        u8arr[n] = bstr.charCodeAt(n)
      }
      var blob = new Blob([u8arr], { type: 'application/vnd.ms-excel' })
      let url = window.URL.createObjectURL(blob)
      let aLink = document.createElement('a')
      aLink.style.display = 'none'
      aLink.href = url
      aLink.setAttribute('download', decodeURI(fileName))
      document.body.appendChild(aLink)
      aLink.click()
      document.body.removeChild(aLink) // 下载完成移除元素
      window.URL.revokeObjectURL(url) // 释放掉blob对象
    },
    uploadError(err, file, fileList) {
      this.showProgress = false
      this.$message.error('上传连接失败!')
      this.downloadMessage = err.message
      this.onCancel()
    },
  },
}
</script>
<style lang="scss">
.importFile-win {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;

  .dialog-footer {
    display: flex;
    justify-content: flex-end;
  }

  .importFile-con {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;

    .upload-demo {
      width: 100%;
      height: 200px;
      display: flex;
      justify-content: center;
      align-items: center;

      .el-upload--text,
      .el-upload-list {
        height: 100%;
        flex: 1;
      }

      .el-upload--text {
        .el-upload-dragger {
          width: auto;
          height: 100%;
          display: flex;
          justify-content: center;
          align-items: center;
          flex-direction: column;
        }
      }

      .el-upload-list {
        border: 1px dashed #d0d2d7;
        margin-left: 2px;
      }
    }

    .downLoad-model {
      width: 100%;
      padding: 10px 0;
      color: #0046ff;
      span {
        color: #f59b00;
        margin-left: 5px;
      }
    }

    .downLoad-message {
      width: 100%;
      padding: 10px 0;
      color: #f56c6c;
    }

    .progress {
      position: absolute;
      display: flex;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background: #fff;
    }
  }
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/277689.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【解决问题】pyinstaller打包python应用进行快速分发

pyinstaller打包python应用进行快速分发 问题起因先利其器再善其事试用运行 问题起因 有同学问我要接口的应用&#xff0c;于是试了一下python打包成exe的过程。 先利其器 主要使用pyinstaller&#xff0c;可以通过pip安装 pip install pyinstaller安装过程如图 再善其事…

文本的剪切和复制有区别吗?有什么区别

在电脑操作中&#xff0c;文本的剪切与复制是我们经常进行的操作。尽管它们看起来都是对文本的“复制”行为&#xff0c;但两者在使用和功能上存在明显的差异。本文将详细介绍剪切与复制的区别&#xff0c;以帮助您更好地理解它们的适用场景和作用&#xff0c;并介绍剪切后如何…

亚信安慧AntDB数据并行加载工具的实现(二)

3.功能性说明 本节对并行加载工具的部分支持的功能进行简要说明。 1) 支持表类型 并行加载工具支持普通表、分区表。 2) 支持指定导入字段 文件中并不是必须包含表中所有的字段&#xff0c;用户可以指定导入某些字段&#xff0c;但是指定的字段数要和文件中的字段数保持一…

ArcGIS高程点生成等高线

基本步骤&#xff1a;数据清洗→创建TIN→TIN转栅格→等值线→平滑线。 1.&#xff08;重要&#xff09;数据清理&#xff1a;删除高程点中的高程异常值数据。 2.创建TIN:系统工具→3D Analyst Tools→数据管理→TIN→创建TIN&#xff08;可直接搜索工具TIN&#xff09;。 单击…

1万亿元国债支持水利、应急行业,钡铼智能终端积极助力提升防灾抗洪建设需求

10月24日&#xff0c;十四届全国人大常委会第六次会议审议通过了国务院关于增加发行国债支持灾后恢复重建和提升防灾减灾救灾能力的议案。为贯彻落实中共中央政治局常委会会议精神&#xff0c;以强有力的资金保障有关工作落实&#xff0c;中央财政将在今年四季度增发2023年国债…

从零开始学Python系列课程第17课:容器型数据类型之列表(上)

前言 列表算是 Python 中比较常用的一种容器型数据类型&#xff0c;那么什么是列表&#xff0c;列表有什么样的作用致使它在 Python 中这么受欢迎呢&#xff1f;这便是接下来我们要一起讨论的问题。 在不久之前我们讲过变量&#xff0c;我们将数据使用变量保存&#xff0c;但是…

【数据结构和算法】独一无二的出现次数

其他系列文章导航 Java基础合集数据结构与算法合集 设计模式合集 多线程合集 分布式合集 ES合集 文章目录 其他系列文章导航 文章目录 前言 一、题目描述 二、题解 2.1 哈希类算法题注意事项 2.2 方法一&#xff1a;判断长度 2.3 方法二&#xff1a; set 判断 2.4 方法…

DG报错ORA-01111、ORA-01110、ORA-01157备库不同步

刚同步好没多久的dg备库&#xff0c;过两天查看同步状态发现备库数据不同步&#xff0c;重新开启同步也不能正常同步。 查看alert日志&#xff0c;查看报错如下&#xff1a; MRP0: Background Media Recovery terminated with error 1111 Errors in file D:\APP\ADMINISTRATOR…

红队打靶练习:DIGITALWORLD.LOCAL: FALL

目录 信息收集 1、arp 2、netdiscover 3、nmap 4、nikto 5、whatweb 6、小结 目录探测 1、gobuster 2、dirsearch WEB 80端口 /test.php 文件包含漏洞 SSH登录 提权 get root and flag 信息收集 1、arp ┌──(root㉿ru)-[~/kali] └─# arp-scan -l Interfa…

圆钢在线直线度测量仪的配置都有哪些?

圆钢产线有很多&#xff0c;并且很多都是需要对直线度尺寸进行检测的&#xff0c;这就是在线直线度测量仪的应用所在&#xff0c;在线检测远比人工检测能带给工厂更大的利益与效率。 在线直线度测量仪原理 直线度测量仪设置3台位置测量仪&#xff0c;每台位置测量仪内布置呈十字…

CMake中开启编译器代码优化加速

【写在前面】 写这篇博客是因为有一天晚上刷到了一篇公众号推文&#xff0c;讲的“如何将一段原本执行需要3秒的程序优化到只需要0.3秒”。长期开发上层应用软件&#xff0c;确实很难接触到一些编程效率优化方面的技巧。但是写C的人还是骨子里有一种潜意识&#xff0c;这代码跑…

云端赋能 算力加速 | 活动回顾

12月16日&#xff0c;华锐技术ACLUB联合火山引擎和AMD以“云端赋能 算力加速”为主题在上海举办了2023量化IT年度专属沙龙活动&#xff0c;会议围绕量化上云、极速行情、高性能处理器等前沿技术深入交流&#xff0c;近40位量化IT齐聚一堂&#xff0c;共同探讨量化行业如何在人工…

纯CSS实现马里奥效果,回忆一下童年吧

&#x1f4e2; 鸿蒙专栏&#xff1a;想学鸿蒙的&#xff0c;冲 &#x1f4e2; C语言专栏&#xff1a;想学C语言的&#xff0c;冲 &#x1f4e2; VUE专栏&#xff1a;想学VUE的&#xff0c;冲这里 &#x1f4e2; CSS专栏&#xff1a;想学CSS的&#xff0c;冲这里 &#x1f4…

使用 pytest 相关特性重构 appium_helloworld

一、前置说明 在 pytest 基础讲解 章节,介绍了 pytest 的特性和基本用法,现在我们可以使用 pytest 的一些机制,来重构 appium_helloworld 。 appium_helloworld 链接: 编写第一个APP自动化脚本 appium_helloworld ,将脚本跑起来 代码目录结构: pytest.ini 设置: [pyt…

QT UI自动化测试(1)

一、框架选择 想结合公司产品搭建一套自动化测试框架&#xff0c;一方面自己学习用&#xff0c;一方面也希望跟公司业务结合起来&#xff0c;双赢。公司软件最多的产品是部署在Linux系统上&#xff0c;基于QT QML开发的UI&#xff0c;本来奔着免费的自动化框架去的&#xff0c;…

如何编写一个javaAgent jar工具包超详细教程

介绍 Java Agent技术 Java Agent技术是JDK提供的用来编写Java工具的技术&#xff0c;使用这种技术生成一种特殊的jar包&#xff0c;这种jar包可以让Java程序 运行其中的代码。 Java Agent技术的两种模式 Java Agent技术实现了让Java程序执行独立的Java Agent程序中的代码…

在VMware安装CentOS 7:详细教程

安装准备工作 本地虚拟机&#xff1a;我这里使用的是VMware Workstation 17 Pro centos7系统ISO镜像&#xff1a;我这里使用的是CentOS-7-x86_64-DVD-2009.iso&#xff0c;具体的下载地址是在阿里云官方镜像站&#xff1a;centos-7.9.2009-isos-x86_64安装包下载_开源镜像站-阿…

Mybatis底层原理分析以及源码阅读

费话不多少先上图&#xff0c;我只喜欢画图分析&#xff0c;看图片&#xff1a; 有两个问题&#xff1a; 问题1&#xff1a; 我们一直在写Mapper/DAO只写了接口&#xff0c;没有写具体的实现吧&#xff1f; 【是的】 问题2&#xff1a; 没有写实现类就没办法实例化执行后续的操…

java进阶学习笔记

学习java深度学习&#xff0c;提升编程思维&#xff0c;适合掌握基础知识的工作者学习 1.反射和代理1.1 概念介绍1.2应用场景1.3 反射-reflect1.3.1 获得类-Class1.3.2 获得类的字段-Field1.3.3 动态访问和修改对象实例的字段1.3.4 获得类方法-Method1.3.5 调用方法.invoke1.3.…

c 语言, 随机数,一个不像随机数的随机数

c 语言&#xff0c; 随机数&#xff0c;一个不像随机数的随机数 使用两种方式获取随机数&#xff0c;总感觉使用比例的那个不太像随机数。 方法一&#xff1a; rand() 获取一个随机数&#xff0c;计算这个随机数跟最大可能值 RAND_MAX&#xff08;定义在 stdlib.h 中&#xf…
最新文章