CreateSnapshotDialog.vue 7.64 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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
<template>
  <!-- 子网创建对话框 -->
  <el-dialog
    @close="close"
    @opened="createSnapshotInit"
    v-dialogDrag
    :title=title
    style="font-size: 10px;" width='450px'
    :visible.sync="createSnapshotVisible">
    <el-form :model="form" inline="true">
      <el-form-item :label="$t('SnapShotManagement.SnapShotName')+':'" :label-width="formLabelWidth"
                    style="margin-bottom: -10px;">
        <el-input size='mini' :placeholder="$t('common.placeholder')" v-model="form.snapshotName"
                  v-on:blur="snapshotNameCheck" autocomplete="off" style="width: 190px;"></el-input>
      </el-form-item>
      <el-form-item :label="$t('SnapShotManagement.description')+':'" :label-width="formLabelWidth"
                    style="margin-bottom: -10px; ">
        <el-input type="text" size="mini" :placeholder="$t('common.placeholder')" v-model="form.description"
                  autocomplete="off" style="width: 190px;"></el-input>
      </el-form-item>
      <el-form-item :label="$t('SnapShotManagement.backupFile')+':'" :label-width="formLabelWidth"
                    style="margin-bottom: -10px;">
        <template>
          <el-checkbox-group v-model="checkedBackups" @change="handleCheckedOptionChange">
            <el-checkbox v-for="(checkedBack) in backups" :label="checkedBack" :key="checkedBack">{{checkedBack}}</el-checkbox>
          </el-checkbox-group>
        </template>

      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size='mini' type="primary" @click="createSnapshot">
        {{$t("common.createBtn")}}
      </el-button>
      <el-button size='mini' @click="close">{{$t("common.cancel")}}</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import SnapshotService from '@/domain/services/SnapshotService.js'
  import legitimacyCheck from "../../../utils/legitimacyCheck";
  import HelperUtil from"../../../utils/HelperUtil";

  const backups = ['拓扑信息', '用户信息']
  export default {
    props: ['command'],
    data: function () {
      return {

        checkAll: false,
        checkedBackups: [],
        backups: backups,
        isIndeterminate: true,

        title: this.command.title,
        initList: this.command.target,
        createSnapshotVisible: false,
        formLabelWidth: '120px',
        form: {
          snapshotName: '',
          description: '',
          saveOptions: []
        },
      }
    },
    methods: {

      handleCheckedOptionChange (value) {
        // alert(this.checkedBackups)
        let checkedCount = value.length;
        this.checkAll = checkedCount === this.checkedBackups.length;
        this.isIndeterminate = checkedCount > 0 && checkedCount < this.checkedBackups.length;
      },

      close () {
        this.command.done();
      },

      //------------------------------------创建开始-------------------------------------------------------------------
      createSnapshotInit () {
        this.form.snapshotName = this.initList.snapshotName
        this.form.description = this.initList.description
      },

      createSnapshot () {
        if (!this.snapshotNameCheck()) {
          return
        }
        if (this.checkedBackups.length === 0) {
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.PLEASE_SELECT_AT_LEAST_ONE_SAVE_OPTIONS))
          return
        }
        else {
          let snapshot = {};
          snapshot.snapshotKey = '';
          snapshot.snapshotName = this.form.snapshotName;
          snapshot.description = this.form.description;
          snapshot.delFlag = 0;
          snapshot.timestamp = '';
          let opt = this.changeCheckedBackups()
          switch (opt) {
            case 0:
              this.addSnapshotTopology(snapshot, opt)
                  break
            case 1:
              this.addSnapshotUser(snapshot, opt)
                  break
            default:
              this.addSnapshotAll(snapshot, opt)
                  break
          }
          // SnapshotService.addSnapshot(snapshot, this.checkedCities).then(result => {
          //   //成功
          //   this.InfoTip.successTip(this,HelperUtil.getStatusCodeObjectByCode(this.successCode.ADD_CODE));
          //   this.command.done();
          // }).catch(err => {
          //   this.InfoTip.errorTip(this,err);
          //
          // });
        }
      },
      //
      addSnapshotTopology: function (snapshotInit, options) {
        SnapshotService.addSnapshot(snapshotInit, options).then(result => {
          //成功
          this.InfoTip.successTip(this, HelperUtil.getStatusCodeObjectByCode(this.successCode.ADD_CODE))
          this.command.done()
        }).catch(err => {
          this.InfoTip.errorTip(this, err)

        })
      },

      addSnapshotUser: function (snapshotInit, options) {
        SnapshotService.addSnapshot(snapshotInit, options).then(result => {
          //成功
          this.InfoTip.successTip(this, HelperUtil.getStatusCodeObjectByCode(this.successCode.ADD_CODE))
          this.command.done()
        }).catch(err => {
          this.InfoTip.errorTip(this,err)

        })
      },

      addSnapshotAll: function (snapshotInit, options) {
        SnapshotService.addSnapshot(snapshotInit, options).then(result => {
          //成功
          this.InfoTip.successTip(this, HelperUtil.getStatusCodeObjectByCode(this.successCode.ADD_CODE))
          this.command.done()
        }).catch(err => {
          this.InfoTip.errorTip(this, err)

        })
      },

      changeCheckedBackups: function () {
        let select = ''
        if(this.checkedBackups.length > 1) {
          select = 2
        } else {
          if(this.checkedBackups[0] == '拓扑信息') {
            select = 0
          } else if (this.checkedBackups[0] == '用户信息') {
            select = 1
          }
        }
        return select
      },

      //------------------------------------创建结束-------------------------------------------------------------------

      //------------------------------------验证开始-------------------------------------------------------------------
      /**
       * @Description  :子网名称校验: 不能为空
       * @author       :
       * @param        :
       * @return       :
       * @exception    :
       * @date         :
       */
      snapshotNameCheck: function () {
        let subnetCheck = legitimacyCheck()
        if (!subnetCheck.textNullCheck(this.form.snapshotName)) {
          //输入不可为空
          this.InfoTip.warningTip_alarm(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.TEXT_NULL_CODE),this.$t('SnapShotManagement.SnapShotName'))
          return false
        }
        if(!this.textLengthCheck(this.form.snapshotName)) return false
        return true
      },
      /**
       * @Description  :文本框所输入的字符长度校验: 控制在20之内
       * @author       : bjh
       * @param        :
       * @return       :
       * @exception    :
       * @date         : 2019/1/15 16:09
       */
      textLengthCheck: function (checkString) {
        let subnetCheck = legitimacyCheck()
        if (!subnetCheck.textLengthCheck(checkString)) {
          //所输文本长度必须控制在20之内
          this.InfoTip.warningTip(this, HelperUtil.getCheckStatusCodeObjectByCode(this.successCode.LENGTH_CODE))
          return false
        }
        return true
      },
      //------------------------------------验证结束-------------------------------------------------------------------

    },

    created() {
      console.log('快照创建初始化加载数据')
    },

    mounted(){
      this.createSnapshotVisible = true;
    }
  }
</script>