zhangzengfei
2021-06-11 fa7044f3ccc9a91bc2bc117d1a06f650d86554f2
src/pages/settings/components/ClusterManagement.vue
@@ -222,7 +222,7 @@
    ipInput,
    cloudNode
  },
  data () {
  data() {
    const checkPwd = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("密码不能为空"));
@@ -306,7 +306,7 @@
      showJoinConfirm: false
    };
  },
  mounted () {
  mounted() {
    this.findCluster();
    let _this = this;
    this.intervalTimer = setInterval(() => {
@@ -314,20 +314,20 @@
    }, 30000);
    //this.getEsClusterNodes();
  },
  beforeDestroy () {
  beforeDestroy() {
    clearInterval(this.intervalTimer);
  },
  methods: {
    checkPsd (psd) {
    checkPsd(psd) {
      return psd.trim().length === 6
    },
    cleanValue () {
      this.members = [];
    },
    sHandleClick (tab, event) {
      console.log(tab, event);
    },
    submitForm (formName) {
    // cleanValue() {
    //   this.members = [];
    // },
    // sHandleClick(tab, event) {
    //   console.log(tab, event);
    // },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          //alert("submit!");
@@ -347,27 +347,27 @@
      });
    },
    saveForm (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
          let json = {
            enable: this.vrIpForm.enable,
            serve_port: this.vrIpForm.serve_port,
            virtual_ip: this.vrIpForm.virtual_ip,
    // saveForm(formName) {
    //   this.$refs[formName].validate(valid => {
    //     if (valid) {
    //       alert("submit!");
    //       let json = {
    //         enable: this.vrIpForm.enable,
    //         serve_port: this.vrIpForm.serve_port,
    //         virtual_ip: this.vrIpForm.virtual_ip,
          };
          setVrrp(json).then(() => {
            this.getVrrpInfo();
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //       };
    //       setVrrp(json).then(() => {
    //         this.getVrrpInfo();
    //       });
    //     } else {
    //       console.log("error submit!!");
    //       return false;
    //     }
    //   });
    // },
    join (formName) {
    join(formName) {
      let _this = this;
      this.$refs[formName].validate(valid => {
        if (valid) {
@@ -403,7 +403,7 @@
        }
      });
    },
    async createCluster (json) {
    async createCluster(json) {
      let res = await createSerfCluster(json);
      console.log(res, "创建集群");
      this.$notify({
@@ -412,13 +412,13 @@
        type: res.success ? "success" : "error"
      });
    },
    async randomPwd () {
    async randomPwd() {
      let res = await randomPwd();
      if (res && res.success) {
        this.ruleForm.clusterpwd = res.data;
      }
    },
    async searchColony () {
    async searchColony() {
      this.isSearch = true;
      this.$refs["joinForm"].clearValidate();
      this.$refs["joinForm"].validateField('clusterpwd');
@@ -448,7 +448,7 @@
      }
      //});
    },
    async search (json) {
    async search(json) {
      let res = await search(json);
      if (res && res.success) {
        console.log(res, "搜索集群");
@@ -461,7 +461,7 @@
      }, 10 * 1000);
    },
    //搜索集群
    async getSearchNodes () {
    async getSearchNodes() {
      let res = await getSearchNodes();
      if (res && res.success) {
        let list = res.data.map(i => {
@@ -485,12 +485,12 @@
        });
      }
    },
    setSchedule () {
    setSchedule() {
      this.scheduleId = window.setInterval(() => {
        this.getSearchNodes();
      }, 1000);
    },
    async stopSearch () {
    async stopSearch() {
      if (!this.loading) {
        return true;
      }
@@ -515,7 +515,7 @@
        // },2000)
      })
    },
    async findCluster () {
    async findCluster() {
      let res = await findCluster();
      if (res && res.success) {
        if (res.data && res.data.clusterId) {
@@ -552,17 +552,17 @@
        }
      }
    },
    getVrrpInfo () {
      getVrrp().then(res => {
        if (res.success) {
          this.vrIpForm.virtual_ip = res.data.virtual_ip;
          this.vrIpForm.enable = res.data.enable;
        }
      }).catch(e => {
        console.log(e)
      })
    },
    async updateCluster () {
    // getVrrpInfo() {
    //   getVrrp().then(res => {
    //     if (res.success) {
    //       this.vrIpForm.virtual_ip = res.data.virtual_ip;
    //       this.vrIpForm.enable = res.data.enable;
    //     }
    //   }).catch(e => {
    //     console.log(e)
    //   })
    // },
    async updateCluster() {
      if (this.ruleForm.clustername === "") {
        this.$message({
          type: "error",
@@ -582,7 +582,7 @@
        type: res.success ? "success" : "error"
      });
    },
    async joinCluster (json) {
    async joinCluster(json) {
      let res = await joinCluster(json);
      if (res.success) {
        this.members = []
@@ -593,7 +593,7 @@
        type: res.success ? "success" : "error"
      });
    },
    leave () {
    leave() {
      this.$confirm(`确定退出集群吗?`, {
        center: true,
        cancelButtonClass: "comfirm-class-cancle",
@@ -614,11 +614,19 @@
          this.members = [];
          this.innerNodes = [];
        }
      }).catch(() => { });
      }).catch(() => {
         this.ruleForm.clustername = "";
          this.ruleForm.clusterpwd = ""
          this.clusterid = "";
          this.isHasColony = false;
          this.activeName = "1";
          this.members = [];
          this.innerNodes = [];
       });
    },
    joinNode (event, node) {
      console.log('join',node)
    joinNode(event, node) {
      console.log('join', node)
      let _this = this;
      this.currentCluster.cluster_id = node.cluster_id;
      if (this.activeName === "3") {
@@ -627,7 +635,6 @@
        return;
      }
      if (this.activeName === "2") {
        debugger
        if (_this.showJoinConfirm) return;
        this.$confirm("是否要加入节点 " + node.nodeName + "?", "加入集群", {
@@ -684,7 +691,7 @@
        // });
      }
    },
    generatePassword () {
    generatePassword() {
      var chars =
        "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
      var uuid = [];
@@ -696,7 +703,7 @@
      this.ruleForm.clusterpwd = uuid.join("");
    },
    async getEsClusterNodes () {
    async getEsClusterNodes() {
      let rsp = await getDevInfo();
      let hostIpAddr = "";
      if (rsp && rsp.success) {
@@ -722,7 +729,7 @@
        }
      }
    },
    createEsCluster () {
    createEsCluster() {
      createESNode().then(rsp => {
        if (rsp && rsp.success) {
          this.$message({
@@ -747,7 +754,7 @@
        });
      })
    },
    joinESCluster () {
    joinESCluster() {
      if (!this.esNodeIp.length) {
        this.$message({
          type: "error",
@@ -781,7 +788,7 @@
        });
      })
    },
    onIpBlur (ip) {
    onIpBlur(ip) {
      //this.vrIpForm.virtual_ip = ip;
      this.ruleForm.virtualIp = ip;
      console.log(this.ruleForm.virtualIp)
@@ -789,7 +796,7 @@
  },
  created () { }
  created() { }
};
</script>