templateManage.vue 2.64 KB
<!--
 * @Author: panda
 * @Date: 2021-10-21 14:20:51
 * @LastEditTime: 2021-10-21 16:50:32
 * @LastEditors: Please set LastEditors
 * @Description: 导出导入模板管理
 * @FilePath: /BS6/src/views/public/templateManage.vue
-->
<template>
  <el-dialog
    :title="$t('button.template')"
    :lock-scroll="false"
    :visible="dialogVisible"
    width="30%"
    @close="closeClick"
    class="upDatadialog"
  >
  <div class="btn-box">
    <el-button  size="small" icon="el-icon-download" @click="downloadtemplate" class="downbbtn">{{ $t('button.downloadtemplate') }}</el-button>
      <el-upload
      class="upload"
      :action="uploadurl"
      :data="updata"
      :before-upload="beforeUpload"
      :on-success="uploadSuccess"
      :limit="1"
      :file-list="fileList">
    <el-button  size="small" icon="el-icon-upload2">{{ $t('button.uploadData') }}</el-button>
  </el-upload>
  </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogVisible = false">{{ $t('button.cancel') }}</el-button>
      <el-button size="small" type="primary">{{ $t('button.confirm') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
const { platform } = window._vionConfig
export default {
  data() {
    return {
      dialogVisible: false,
      exporturl:'',
      type:'',
      fileList:[],
      exportData:"",
      uploadurl:'',
      updata:{
        platform: platform,
        authorization:'',
      }
    
    };
  },
  methods: {
    //Excel 上传限制
    beforeUpload(file) {
      let isExcel = ['xls','xlsx'].includes(file.name.substring(file.name.lastIndexOf('.')+1));
      if (!isExcel) {
        this.$message.error(this.$t("请上传Excel格式文件"));
      }
      return isExcel;
    },
    /**
     * @description: 初始化导入导出数据
     * @param {*} type 导入或导出类型
     * @return {*}
     */    
    dialogInit(type) {
      this.type = type;
      this.exporturl = `${window._vionConfig.apiUrl}/${type}/template?authorization=${this.$cookie.get("atoken")}`;
      this.updata.authorization = this.$cookie.get("atoken")
      this.uploadurl = `${window._vionConfig.apiUrl}/${type}/importExcel`
      this.dialogVisible = true;
    },
    /**
     * @description: 下载模板
     * @param {*}
     * @return {*}
     */    
    downloadtemplate(){
      window.open(this.exporturl)
    },
    uploadSuccess(){
      this.$message({
         message: '上传成功!',
        type: 'success'
      })
      this.$emit('refresh')
    },
    closeClick(){
      this.dialogVisible = false;
    },
  }
};
</script>

<style>
.downbbtn{
  margin-right: 20px;
  float: left;
}
.upload{
  float: left;
}
</style>