vue 接后端java流文件执行下载

134 阅读1分钟
//executionDownLoad 接口名字
//函数 
fileDownload(){

    executionDownLoad({ 'id': this.form.id }).then(res => {

        const fileName = `执行阶段卷宗_${this.getCurrentTime()}.zip` // 导出文件名

        // const fileName = res.headers['filename'] // 导出文件名

        const blob = new Blob([res.data], { type: 'application/zip;Charset=UTF-8' })// 构造一个blob对象来处理数据

        const link = document.createElement('a') // 创建a标签

        link.download = fileName

        link.style.display = 'none'

        link.href = URL.createObjectURL(blob)

        document.body.appendChild(link)

        link.click() // 执行下载

        URL.revokeObjectURL(link.href)

        document.body.removeChild(link)

    })

},
//获取当前日期
getCurrentTime() {

    //获取当前时间并打印

    var _this = this;

      let yy = new Date().getFullYear();

      let mm = new Date().getMonth()+1;

      let dd = new Date().getDate();

    //   let hh = new Date().getHours();

    //   let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();

    //   let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();

      return yy+'/'+mm+'/'+dd;

},