UploadFirmWareDialog.vue 5.37 KB
Newer Older
YazhouChen's avatar
YazhouChen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
<template>
  <!--本地上传配置文件对话框-->
  <el-dialog v-dialogDrag style="font-size: 10px;"
             width='450px'
             v-if="uploadConfigVisible"
             :title="$t('ProfileManagement.localUpload')"
             :visible.sync="uploadConfigVisible"
             @close="close">
    <el-upload
      action="doUpload"
      :limit="1"
      :before-upload="beforeUpload"
      style="margin-bottom: 10px;">
      <el-button slot="trigger" size="small" type="primary">{{ $t('FirmWareConfiguration.upload')}}</el-button>
      <div slot="tip" class="el-upload__tip">{{$t('common.importBinFile')}}</div>
      <div slot="tip" class="el-upload-list__item-name">{{fileName}}</div>
    </el-upload>
    <el-form :model="form" inline="true"  style="margin-bottom: -10px;" label-width="80px">
      <el-form-item :label="$t('FirmWareConfiguration.deviceType')+':'"  style="margin-bottom: 0px;">
        <el-select  size='mini'  style="width: 152px;" @change='ch' v-model="deviceTypeSelect" :placeholder="$t('FirmWareConfiguration.selectDeviceType')">
          <el-option v-for="item in deviceTypeList" :key="item.deviceTypeKey" :label="item.deviceTypeName"
                     :value="item.deviceTypeKey"></el-option>
        </el-select>
      </el-form-item>
      <!--<el-form-item :label="$t('FirmWareConfiguration.description')+':'"  style="margin-bottom: 3px;margin-left: -2px;">-->
        <!--<el-input type="textarea" autosize v-model="form.description" style="width: 152px;"></el-input>-->
      <!--</el-form-item>-->
    </el-form>
    <el-row style="margin-bottom: 0px;" slot="footer" class="dialog-footer">
      <el-button style="margin-bottom: -10px;" size='mini' type="primary" @click="submitUpload"
                 v-loading.fullscreen.lock="fullscreenLoading">{{$t("ProfileManagement.upload")}}
      </el-button>
      <el-button style="margin-bottom: -10px;" size='mini' @click="close">
        {{$t("common.cancel")}}
      </el-button>
    </el-row>

  </el-dialog>

</template>

<script>
  import ElButton from "../../../../node_modules/element-ui/packages/button/src/button.vue";
  import FirmWareService from '@/domain/services/FirmWareService.js'
  import HelperUtil from '../../../utils/HelperUtil'

  export default {
    components: {ElButton},
    props: ['command'],

    data: function () {
      return {
        deviceTypeList: [
          {
            deviceTypeKey: '0',
            deviceTypeName: this.$t('DeviceConfigurationManagement.traditional')
          },
          {
            deviceTypeKey: '1',
            deviceTypeName: 'SDN'
          }
        ],
        deviceTypeSelect: '0',
        // form:{
        //   deviceType: '',
        //   description: ''
        // },
        uploadConfigVisible: true,

        fileName: '',
        files: '',

        fullscreenLoading: false,
        tableHeight: window.innerHeight * 0.7,
        formLabelWidth: '120px'
      }
    },
    methods: {
      close: function () {
        console.log("关闭")
        this.command.done()
      },

      /**
       * @Description  : 导出文件之前执行
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
      beforeUpload (file) {
        console.log(file, '文件')
        this.files = file;
        // const extension = file.name.split('.')[1] === 'conf'
        const extension = file.name.substring(file.name.toString().length-4,file.name.toString().length)==".bin"
//        alert(file.name.substring(file.name.toString().length-5,file.name.toString().length))
//        const extension2 = file.name.split('.')[1] === 'xlsx'
        const isLt2M = file.size / 1024 / 1024 < 5
        if (!extension) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.UPLOAD_FILES_CAN_ONLY_BE_IN_BIN_FORMAT))
          return
        }
        // if (!isLt2M) {
        //   this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.UPLOADFILE_SIZE_CODE))
        //   return
        // }
        this.fileName = file.name
        return false // 返回false不会自动上传
      },

      submitUpload: function () {

        let _this = this
        if (this.fileName == "") {
          _this.InfoTip.warningTip(_this, HelperUtil.getCheckStatusCodeObjectByCode(_this.successCode.CHOOSE_UPLOADFILE_CODE))

          return false
        }
        console.log(this.files)
        let fileFormData = new FormData();
        fileFormData.append('file', this.files, this.files.name);
        let loadingInstance = _this.Loading.openLoading();
        FirmWareService.uploadLocalFirmWare(this.files.name, this.deviceTypeSelect,fileFormData).then(result => {
          _this.Loading.closeLoading(loadingInstance)
          _this.InfoTip.successTip(_this, HelperUtil.getStatusCodeObjectByCode(_this.successCode.OTHERS_CODE));
          _this.close();
        }).catch(err => {

          //失败
          _this.Loading.closeLoading(loadingInstance)
          _this.InfoTip.errorTip(_this, err);
//          _this.command.done();
        })
      },
      ch: function (vid) {
        let obj = {}
        obj = this.deviceTypeList.find((item) => {
          return item.deviceTypeKey === vid
        })
        this.deviceTypeSelect = obj.deviceTypeName
      }
    },
    created() {
      console.log('导入配置文件 初始化加载数据')

    }
  }
</script>