handleparam.vue 4.32 KB
<template>
  <div class="paramset-box">
    <el-dialog
      :title="curtype === 'export' ? '配置导出' : '配置导入'"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <div class="setparams-box">
        <el-form
          label-width="80px"
          :model="paramform"
          v-show="curtype === 'upload'"
        >
          <!-- <el-form-item label="类型">
            <el-select v-model="paramform.fileType">
              <el-option
                v-for="type in types"
                :key="type.type_code"
                :value="type.type_code"
                :label="type.conf_name"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="名称">
            <el-input v-model="paramform.name"></el-input>
          </el-form-item> -->
          <el-form-item label="文件">
            <el-upload
              class="upload-demo"
              ref="paramsup"
              :action="uploadurl"
              :on-change="handlePreview"
              multiple
              :limit="1"
              :auto-upload="false"
              :on-success="sucessfile"
              :file-list="fileList"
              :on-error="errorfile"
              :headers="updata"
            >
              <el-button size="small" slot="trigger" type="primary"
                >点击上传</el-button
              >
              <div slot="tip" class="el-upload__tip">只能上传tar.gz文件.</div>
            </el-upload>
          </el-form-item>
        </el-form>
        <el-form
          label-width="80px"
          :model="exportform"
          v-show="curtype === 'export'"
        >
          <el-form-item label="类型">
            <el-select v-model="paramform.fileType">
              <el-option
                v-for="type in types"
                :key="type.type_code"
                :value="type.type_code"
                :label="type.conf_name"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose()">取 消</el-button>
        <el-button type="primary" @click="uploadparams()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// import {config} from '../../../../public/js/config'
export default {
  data() {
    return {
      dialogVisible: false,
      paramform: {
        fileType: ""
      },
      exportform: {},
      fileList: [],
      types: [],
      curtype: "",
      upfile: "",
      uploadurl: "",
      subtaskid: "",
      subtask_name:"",
      headers:{
        authorization:localStorage.getItem("atoken")
      }
    };
  },
  methods: {
    show(type, subid, subdata) {
      this.curtype = type;
      this.subtaskid = subid;
      this.subtask_name = subdata.subtask_name;
      this.dialogVisible = true;
      this.uploadurl = `${window.config.https?'https':'http'}://${location.host}/api/v1/devconf_fx/import/${this.subtaskid}`;
      this.fileList = [];
      this.$store.commit("setocxstate", 0);
    },
    handlePreview(file, fileList) {
      let modalFileExt = file.name.slice(-7);
      if (modalFileExt !== ".tar.gz") {
        this.$message({
          type: "warning",
          message: '仅支持"*.tar.gz"文件'
        });
        this.$refs.paramsup.clearFiles();
        return false;
      }
    },
    uploadparams() {
      let file_text = "";
      this.$refs.paramsup.submit();
    },
    sucessfile() {
      this.$message({
        message: "导入成功请重新点击任务查看!",
        type: "success"
      });
      this.dialogVisible = false;
      this.$store.commit("setocxstate", 1);
      this.fileList = [];
      this.$logs.oplogs({},'serv_scene',`配置导入成功,任务名称:${this.subtask_name}`);
    },
    errorfile(err){
      console.log(err);
    },

    submitParamSet() {},
    handleClose(done) {
      (this.dialogVisible = false), this.$store.commit("setocxstate", 1);
    },
    getTypes() {
      let params = {
        offset: 0,
        limit: ""
      };
      this.$api.device.getConfParam(params).then(res => {
        this.types = res.list_data;
      });
    }
  }
};
</script>

<style lang="stylus" scoped>
.setparams-box{
  width 400px
  margin 0 auto
}
.paramset-box{
  overflow hidden
}
</style>