文件上传下载

<el-button v-if="dataModelFlag[3]" type="primary" @click="getImportDialog">维度数据导入</el-button>

<el-dialog title="维度数据导入" :visible.sync="dialogFormVisibleImport" width="50%">
  <el-upload class="upload-demo upload-demo-auth" ref="upload" accept=".xls,.xlsx" ref="upLoadFile"
  action="https://jsonplaceholder.typicode.com/posts/" :on-preview="handlePrev" :on-remove="handleRemove"
  :on-change="perChange" :file-list="fileList" :auto-upload="false" :limit="1" :on-exceed="handleExceed">
    <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
  </el-upload>
  <div slot="footer" class="dialog-footer">
    <el-button type="primary" @click="getDimensionDataTemplate">下载模板</el-button>
    <el-button type="primary" @click="upLoadDimensionData" :disabled="prImport">导 入</el-button>
    <el-button type="primary" @click="dialogFormVisibleImport = false">取 消</el-button>
  </div>
</el-dialog>
//下载模板
dimensionExcelTemplate({commit,state},data){
  return new Promise((resolve, reject) => {
    getExport({
      url: urlConfig.dimensionMag.dimensionExcelTemplate,
      data: data,
      responseType: 'blob',
      headers: {
        Authorization: this.state.Login.token
      }
    }, function (res) {
      resolve(res)
    }, function (err) {
      reject(err)
    })
  })
},
//维度数据导入
dimensionTreeUpload({commit,state},data){
  return new Promise((resolve, reject) => {
    post({
      url: urlConfig.dimensionMag.dimensionTreeUpload,
      data: data,
      headers: {
        Authorization: this.state.Login.token
      }
    }, function (res) {
      resolve(res)
    }, function (err) {
      reject(err)
    })
  })
},
dialogFormVisibleImport: false,
param: '', //导入
fileList: [],
prImport:false,
 
//导入弹框
getImportDialog() {
  this.fileList = [] //this.$refs.upLoadFile.clearFiles()
  this.param = ''
  this.dialogFormVisibleImport = true
},
//下载模板
getDimensionDataTemplate() {
  let that = this
  let _data = {}
  that.$store.dispatch('dimensionExcelTemplate', _data).then(function (res) {
    console.log(res.data)
    let file = res.data
    let blob = new Blob([file])
    let url = URL.createObjectURL(blob)
    let fileName = decodeURIComponent("维度数据导入模板.xls")

    if (navigator.msSaveBlob) {
      that.$message({
        type: 'success',
        message: '下载成功'
      })
      return navigator.msSaveBlob(blob, fileName)
    } 
    else {
      let link = document.createElement('a')
      link.download = fileName
      link.href = url
      link.style.display = 'none'
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
      that.$message({
        type: 'success',
        message: '下载成功'
      })
    }
  }, function (err) {
    that.$message({
      type: 'error',
      message: '下载失败'
    })
  })
},
perChange(file) {
  console.log(file);
  this.param = new FormData();
  this.param.append('file', file.raw);
  this.param.append('applicationId', this.application_id)
  console.log(this.param)
},
handleRemove(file, fileList) {
  console.log(file, fileList);
  this.param = ''
},
handlePrev(file) {
  console.log(file);
},
handleExceed(files, fileList) {
  this.$message.warning(`当前限制选择 1个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
},
//导入
upLoadDimensionData() {
  let that = this
  console.log(that.param)
  if (that.param == ''){
    that.$message({
      message: '请选择导入文件',
      type: "warning"
    })
    return;
  }
  that.prImport = true
  that.$store.dispatch('dimensionTreeUpload', that.param).then(function (res) {
    that.prImport = false
    if (res.flag) {
      that.$message({
        message: '导入成功',
        type: "success",
        duration: 1000,
        onClose: function () {
          that.fileList = [] //that.$refs.upLoadFile.clearFiles()
          that.param = ''
          that.dialogFormVisibleImport = false
        }
      })
      that.getDimensionTypeList()
    }
    else {
      that.$message({
        message: res.message,
        type: "warning"
      })
    }
  }, function (err) {
    that.prImport = false
    that.$message({
      message: err.message,
      type: "error"
    })
  })
},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值