sytemSet.vue 13.9 KB
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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
<template>
  <div style="padding-left: 28px;">
    <el-form ref="form" label-width="86px">
      <!-- 恢复出厂设置 -->
      <div class="lineBox big"><i class="el-icon-share"></i>恢复出厂设置</div>
      <div class="radioContent">
        <div class="lineBox">
          <el-button
            type="primary"
            size="small"
            class="primaryButton"
            @click="reset"
            >恢复出厂设置</el-button
          >
        </div>
        <div class="lineBox">
          <span class="tip">恢复出厂设置说明:完全恢复设备参数到出厂设置</span>
        </div>
      </div>
      <div class="line"></div>
      <!-- 数据备份 -->
      <div class="lineBox big"><i class="el-icon-share"></i>数据备份</div>
      <div class="radioContent">
        <div class="lineBox">
          <span class="upTit">参数导入</span
          ><span class="upTit2">选择导入文件</span>
          <div class="upInput">
            <el-input v-model="selectFilename"></el-input>
          </div>
          <span style="display: inline-block;">
            <el-upload
              class="upload-demo"
              ref="upload"
              :on-change="fileChange"
              :multiple="false"
              :show-file-list="false"
              :auto-upload="false"
              :action="exurl"
              :on-success="successback"
              :on-error="onerrorback"
            >
              <el-button
                slot="trigger"
                size="small"
                type="primary"
                class="primaryButton upButton"
                >浏览</el-button
              >
              <el-button
                size="small"
                type="primary"
                @click="submitUpload('config')"
                plain
                class="plainButton"
                >参数导入</el-button
              >
            </el-upload>
          </span>
        </div>
        <div class="lineBox">
          <span class="upTit">参数导出</span
          ><span class="upTit2"
            ><el-button
              size="small"
              type="primary"
              class="primaryButton"
              @click="exportparams"
              >参数导出</el-button
            ></span
          >
        </div>
      </div>

      <div class="line"></div>
      <div class="lineBox big"><i class="el-icon-share"></i>重启设置</div>
      <div class="radioContent">
        <div class="lineBox">
          <el-button
            size="small"
            type="primary"
            class="primaryButton"
            @click="manualRebootClick"
            >手动重启</el-button
          >
        </div>
        <div class="lineBox">
          <el-checkbox v-model="openRestart">开启定时重启</el-checkbox>
        </div>
        <el-form ref="inlineform" label-width="100px" inline>
          <div class="lineBox">
            <el-form-item label="每天:">
              <el-time-select
                :disabled="!openRestart"
                v-model="timeArr[0]"
                value-format="HH:mm"
                placeholder="选择时间"
              >
              </el-time-select>
            </el-form-item>
            <el-form-item label="每天:">
              <el-time-select
                :disabled="!openRestart"
                v-model="timeArr[1]"
                value-format="HH:mm"
                placeholder="选择时间"
              >
              </el-time-select>
            </el-form-item>
            <el-form-item label="每天:">
              <el-time-select
                :disabled="!openRestart"
                v-model="timeArr[2]"
                value-format="HH:mm"
                placeholder="选择时间"
              >
              </el-time-select>
            </el-form-item>
          </div>
          <div class="lineBox">
            <el-form-item label="每天:">
              <el-time-select
                :disabled="!openRestart"
                v-model="timeArr[3]"
                value-format="HH:mm"
                placeholder="选择时间"
              >
              </el-time-select>
            </el-form-item>
            <el-form-item label="每天:">
              <el-time-select
                :disabled="!openRestart"
                v-model="timeArr[4]"
                value-format="HH:mm"
                placeholder="选择时间"
              >
              </el-time-select>
            </el-form-item>
            <el-form-item label=" ">
              <span>自动进行校时(可设置多个时间点,不得超过5个)</span>
            </el-form-item>
            <el-form-item label=" ">
              <el-button
                type="primary"
                size="small"
                class="primaryButton rightButton"
                :disabled="!openRestart"
                @click="intervalRebootClick"
                >保存</el-button
              >
            </el-form-item>
          </div>
        </el-form>
      </div>
       <!-- 数据备份 -->
      <div class="lineBox big"><i class="el-icon-share"></i>设备鉴权</div>
         <div class="radioContent">
        <div class="lineBox">
          <span class="upTit">鉴权文件</span
          ><span class="upTit2">选择导入文件</span>
          <div class="upInput">
            <el-input v-model="authfilename"></el-input>
          </div>
          <span style="display: inline-block;">
            <el-upload
              class="upload-demo"
              ref="authupload"
              :on-change="authfileChange"
              :multiple="false"
              :show-file-list="false"
              :auto-upload="false"
              :action="authexurl"
              :on-success="authsuccessback"
              :data="updata"
              :on-error="onerrorback"
            >
              <el-button
                slot="trigger"
                size="small"
                type="primary"
                class="primaryButton upButton"
                >浏览</el-button
              >
                <el-button
                size="small"
                type="primary"
                @click="submitUpload('auth')"
                plain
                class="plainButton"
                >鉴权</el-button
              >
            </el-upload>
          </span>
        </div>
      </div>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      openRestart: false,
      selectFilename: "",
      authfilename:"",
      authfile:null,
      updata:{
        name:'',
        vchan_type:"authfile"
      },
      timeArr: [],
      exurl: window.config.https? `https://${location.host}/api/v1/devconf_fx/restore"`:`"http://${location.host}/api/v1/devconf_fx/restore`,
      authexurl:window.config.https?`https://${location.host}/api/v1/devconf_fx/devs/${localStorage.getItem("dev_unid")}/vfile_vchans`:`http://${location.host}/api/v1/devconf_fx/devs/${localStorage.getItem("dev_unid")}/vfile_vchans`,
      file: null,
      dev_unid: localStorage.getItem("dev_unid"),
      device_id: sessionStorage.getItem("device_id")
    };
  },
  components: {},
  mounted() {
    this.getRebootSetting();
  },
  methods: {
    getRebootSetting() {
      if (this.dev_unid != "" && this.device_id != "") {
        this.$api.ops
          .getRebootSetting({}, this.dev_unid, this.device_id)
          .then(res => {
            if (!res.ecode) {
              if (res.enabled == 1) {
                this.openRestart = true;
                this.timeArr = res.reboot_time;
              }
            } else {
              this.$message({
                type: "error",
                message: res.enote
              });
            }
          });
      } else {
        this.$message({
          type: "info",
          message: "未找到设备ID,请重新登录"
        });
      }
    },
    submitUpload(type) {
      if(type === 'config') {
        let importFileExt = this.file.name.substr(
        this.file.name.lastIndexOf(".")
        );
        this.$refs.upload.submit(); // 这里是执行文件上传的函数,其实也就是获取我们要上传的文件
      } else if(type === 'auth'){
        this.$refs.authupload.submit(); 
      }
  
    },

    successback() {
      this.$message({
        type: "success",
        message: "上传成功!"
      });
      this.selectFilename = "";
      this.file = null;
      this.$logs.oplogs(res,'serv_system',`参数导入`);
    },
    authsuccessback(){
       this.$message({
        type: "success",
        message: "上传成功!"
      });
      this.selectFilename = "";
      this.file = null;
      this.$logs.oplogs(res,'serv_system',`鉴权文件导入`);
    },
    onerrorback() {
      this.file = null;
    },
    fileChange(file, fileList) {
      this.selectFilename = file.name;
      this.file = file;
    },
     authfileChange(file, fileList) {
      this.authfilename = file.name;
      this.updata.name = file.name;
      this.authfile = file;
    },
    reset() {
      this.$confirm("此操作将恢复出厂设置, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          if (this.dev_unid != "" && this.device_id != "") {
            this.$api.ops
              .factoryReset({}, this.dev_unid, this.device_id)
              .then(res => {
                if (res.ecode == 200) {
                  this.$message({
                    type: "success",
                    message: "恢复出厂设置成功!"
                  });
                  this.$logs.oplogs(res,'serv_system',`恢复了出厂设置`);
                } else {
                  this.$message({
                    type: "error",
                    message: "恢复出厂设置失败!" + res.enote
                  });
                }
              });
          } else {
            this.$message({
              type: "info",
              message: "未找到设备ID,请重新登录"
            });
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    exportFileClick() {
      if (this.dev_unid != "" && this.device_id != "") {
        this.$api.ops
          .exportParams({}, this.dev_unid, this.device_id)
          .then(res => {
            if (res.ecode && res.ecode != 200) {
              this.$message({
                type: "error",
                message: res.enote
              });
            } else {
              let exportFileUrl = res.file_path;
              this.$logs.oplogs(res,'serv_system',`备份导出`);
              window.location.href = exportFileUrl;
            }
          });
      } else {
        this.$message({
          type: "info",
          message: "未找到设备ID,请重新登录"
        });
      }
    },
    exportparams() {
      this.$api.ops.exportback().then(res => {
        if (res.ecode && res.ecode != 200) {
          this.$message({
            type: "error",
            message: res.enote
          });
        } else {
          let exportFileUrl = res.enote;
          this.$logs.oplogs(res,'serv_system',`备份导出`);
          window.location.href = exportFileUrl;
        }
      });
    },
    manualRebootClick() {
      this.$confirm("此操作将重启设备, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          if (this.dev_unid != "" && this.device_id != "") {
            this.$api.ops
              .manualReboot({}, this.dev_unid, this.device_id)
              .then(res => {
                if (res.ecode == 200) {
                  this.$message({
                    type: "success",
                    message: "重启成功!"
                  });
                  this.$logs.oplogs(res,'serv_system',`手动重启`);
                } else {
                  this.$message({
                    type: "error",
                    message: "重启失败!" + res.enote
                  });
                }
              });
          } else {
            this.$message({
              type: "info",
              message: "未找到设备ID,请重新登录"
            });
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    intervalRebootClick() {
      //数组去空值
      let arr = [];
      this.timeArr.forEach(item => {
        if (item != "" && typeof item != "undefined") {
          arr.push(item);
        }
      });
      if (new Set(arr).size !== arr.length) {
        this.$message({
          type: "error",
          message: "定时时间重复,请重新选择"
        });
        return false;
      }
      let autoRebootParams = {
        enabled: 1,
        reboot_policy: "day",
        reboot_time: this.timeArr
      };
      this.$api.ops
        .intervalReboot(autoRebootParams, this.dev_unid, this.device_id)
        .then(res => {
          if (res.ecode == 200) {
            this.$message({
              type: "success",
              message: "自动重启配置成功!!"
            });
            this.getRebootSetting();
            this.$logs.oplogs(res,'serv_system',`设置定时重启`);
          } else {
            console.log("自动重启配置失败!");
          }
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.upButton {
  margin-right: 10px;
}
.upTit {
  margin-right: 44px;
}
.upTit2 {
  margin-right: 6px;
}
.upInput {
  display: inline-block;
  width: 250px;
  margin: 0 12px;
}
.tip {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.25);
}
.line {
  height: 1px;
  background: rgba(232, 232, 232, 1);
  margin-top: 18px;
  margin-bottom: 15px;
}
.lineBox {
  padding: 12px 0 12px 50px;
}
.radioContent {
  margin-left: 38px;
}
.rightButton {
  float: right;
  margin-right: 20%;
}
.inputBox {
  width: 220px;
}
.big i {
  font-size: 18px;
  color: #cccccc;
  margin-right: 22px;
}
</style>