ZZJ
2022-06-23 feaf0a9778879ef211c5587a513ba4cbdabb52d0
src/pages/settings/views/NetSettings.vue
@@ -17,7 +17,7 @@
          <!-- <span v-if="showStatus && i == 2" class="status">已连接</span> -->
        </div>
      </div>
      <div class="net-right">
      <div class="net-right" v-loading="configLoading">
        <div class="net-set" v-if="activePage == 0">
          <div class="title">网络设置</div>
          <el-form
@@ -382,6 +382,8 @@
import LoraGateway from "../components/LoraGateway";
import MqttGateway from "../components/MqttGateway";
import { isIPv4 } from "@/scripts/validate";
export default {
  components: {
    ipInput,
@@ -427,7 +429,43 @@
        gateway: "",
        ip: "",
      },
      wireFormRules: {},
      originalConfig: {},
      wireFormRules: {
        ip: [
          {
            required: true,
            message: "请输入IP地址",
            trigger: "change",
          },
          { validator: isIPv4, trigger: "change" },
        ],
        gateway: [
          {
            required: true,
            message: "请输入网关",
            trigger: "change",
          },
          { validator: isIPv4, trigger: "change" },
        ],
        dns: [
          {
            required: true,
            message: "请输入dns地址",
            trigger: "change",
          },
          { validator: isIPv4, trigger: "change" },
        ],
        subMask: [
          {
            required: true,
            message: "请输入子网掩码",
            trigger: "change",
          },
          { validator: isIPv4, trigger: "change" },
        ],
      },
      activePage: 0,
      activeWireItem: {},
      rules: {
@@ -460,6 +498,7 @@
      value: "",
      IPV4_hid: false,
      IPV6_hid: false,
      configLoading: false,
    };
  },
  mounted() {
@@ -523,6 +562,7 @@
      this.wireForm.gateway = "";
      this.wireForm.dns = "";
      this.wireForm.subMask = "";
      this.originalConfig = this.wireForm;
    },
    saveServerName() {
      setServerName({
@@ -546,23 +586,75 @@
      this.activePage = i;
    },
    saveWire(ifname) {
      let data = {
        ip: this.wireForm.ip,
        gateway: this.wireForm.gateway,
        dns: this.wireForm.dns,
        subMask: this.wireForm.subMask,
        ifname: this.activeWireItem.name,
      };
      setNetWorkCard(data).then(
        (res) => {
          if (res && res.success) {
            this.$message.success(res.data);
          }
        },
        (err) => {
          this.$message.error("保存失败:" + err.msg);
      this.$refs["wireForm"].validate((valid) => {
        if (valid) {
          let data = {
            ip: this.wireForm.ip,
            gateway: this.wireForm.gateway,
            dns: this.wireForm.dns,
            subMask: this.wireForm.subMask,
            ifname: this.activeWireItem.name,
          };
          let newUri =
            location.protocol +
            "//" +
            data.ip +
            (location.port == 80 ? "" : ":" + location.port);
          this.$confirm("确认需要修改服务器配置吗?", {
            center: true,
            cancelButtonClass: "comfirm-class-cancle",
            confirmButtonClass: "comfirm-class-sure",
          })
            .then(() => {
              this.configLoading = true;
              if (this.wireForm.ip !== this.originalConfig.ip) {
                this.configLoading = false;
                var changeIPTimer = setTimeout(() => {
                  this.$alert(
                    '<strong>您已修改了服务器ip, 请重新登录</strong><a target="_parent" href="' +
                      newUri +
                      '"> ' +
                      newUri +
                      "<a/>",
                    "提示",
                    {
                      dangerouslyUseHTMLString: true,
                      customClass: "noticeBox",
                    }
                  );
                }, 10000);
              }
              setNetWorkCard(data)
                .then((rsp) => {
                  this.configLoading = false;
                  if (rsp && rsp.success) {
                    this.$notify({
                      type: "success",
                      message: "服务器配置成功",
                    });
                  }
                })
                .catch((err) => {
                  clearTimeout(changeIPTimer);
                  this.configLoading = false;
                  this.$notify({
                    type: "error",
                    message: "保存失败",
                  });
                });
              this.$message({
                message: "操作完成,请稍后",
                type: "success",
              });
            })
            .catch((err) => {});
        } else {
          return false;
        }
      );
      });
    },
    wifiControl(val) {},
    checkWifi() {
@@ -580,6 +672,7 @@
            this.wireForm.gateway = res.data.gateway;
            this.wireForm.dns = res.data.dns;
            this.wireForm.subMask = res.data.subMask;
            this.originalConfig = JSON.parse(JSON.stringify(this.wireForm));
          }
        },
        (err) => {
@@ -596,6 +689,7 @@
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "confirmBox",
      }).then(() => {
        this.openWireDetail(item);
      });
@@ -772,7 +866,7 @@
      width: 100%;
    }
    .el-form-item {
      margin-bottom: 4px;
      margin-bottom: 14px;
    }
    .el-form-item__content {
      line-height: 48px;
@@ -1002,12 +1096,15 @@
          align-items: center;
          .el-switch__core {
            height: 14px;
            background-color: var(--colorCard) !important;
            border-color: var(--colorCard) !important;
          }
          .el-switch.is-checked .el-switch__core::after {
            left: 100%;
            margin-left: -12px;
          }
          .el-switch.is-checked .el-switch__core {
            background-color: var(--colorCard) !important;
            border-color: var(--colorCard) !important;
          }
          .el-switch__core:after {
@@ -1045,4 +1142,19 @@
    }
  }
}
.noticeBox p {
  text-align: center;
}
.confirmBox {
  text-align: center;
  p {
    text-align: center;
  }
  .el-message-box__status.el-icon-warning {
    margin-left: 75px;
  }
}
</style>