From 6199a2238efcc2449c79aa228e40cb75c59cf663 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期二, 24 十月 2023 19:16:24 +0800 Subject: [PATCH] 集群退出添加密码 --- src/pages/settings/views/clusterManagement.vue | 108 +++++++++++++++++++++++++++++++++++------------------- 1 files changed, 70 insertions(+), 38 deletions(-) diff --git a/src/pages/settings/views/clusterManagement.vue b/src/pages/settings/views/clusterManagement.vue index daf57d2..6db3aa5 100644 --- a/src/pages/settings/views/clusterManagement.vue +++ b/src/pages/settings/views/clusterManagement.vue @@ -5,8 +5,16 @@ <!-- <cloud-node :nodes="innerNodes"></cloud-node> --> <net-node :innerNodes="innerNodes"></net-node> - <div class="cls-bar">瑙嗛鍒嗘瀽闆嗙兢绠$悊</div> - + <div class="cls-bar"> + <div class="title">鑺傜偣鐘舵��</div> + <div class="input-area"> + <div class="text" v-show="!isFillingName"> + {{ ruleForm.state }} + </div> + <el-switch v-model="masterNode" :disabled="masterNode" style="margin-top:5px" @change="change2Master"> + </el-switch> + </div> + </div> <div class="cls-bar"> <div class="title">闆嗙兢鍚嶇О</div> <div class="input-area"> @@ -168,7 +176,8 @@ stopSearching, findCluster, updateClusterName, - joinCluster + joinCluster, + update2Master } from "@/api/clusterManage" // import cloudNode from "../components/CloudNode"; import NetNode from "../components/NetNode" @@ -195,6 +204,7 @@ } } return { + masterNode: false, innerNodes: [], intervalTimer: null, isFillingName: false, @@ -210,7 +220,9 @@ ruleForm: { clustername: "", clusterpwd: "", - virtualIp: "" + virtualIp: "", + state: "", + localId: "" }, selfForm: { virtualIp: "", @@ -222,7 +234,7 @@ clusterpwd: "" }, isSearch: false, - showCurCluster: true, + showCurCluster: false, loading: false, joinLoading: false, isHasColony: false, @@ -240,7 +252,8 @@ clusterid: [{ validator: checkID, trigger: "blur" }], clusterip: [{ validator: isIPv4, trigger: "blur" }], clusterpwd: [{ validator: checkPwd, required: true, trigger: "blur" }] - } + }, + quitInput: "" } }, components: { @@ -250,9 +263,9 @@ }, mounted() { this.findCluster() - this.intervalTimer = setInterval(() => { - this.findCluster() - }, 30000) + // this.intervalTimer = setInterval(() => { + // this.findCluster() + // }, 30000) }, beforeDestroy() { clearInterval(this.intervalTimer) @@ -350,25 +363,27 @@ }, join(formName) { let _this = this + _this.joinLoading = true + let data = { + clusterId: _this.joinForm.clusterid, + password: _this.joinForm.clusterpwd, + nodeIps: [_this.joinForm.clusterip] + } + _this + .joinCluster(data) + .then(() => { + _this.joinLoading = false + _this.findCluster() + }) + .catch((e) => { + _this.joinLoading = false + }) + this.$refs[formName].validate((valid) => { + console.log("join") if (valid) { - _this.joinLoading = true - let data = { - clusterId: _this.joinForm.clusterid, - password: _this.joinForm.clusterpwd, - nodeIps: [_this.joinForm.clusterip] - } - debugger - _this - .joinCluster(data) - .then(() => { - _this.joinLoading = false - _this.findCluster() - }) - .catch((e) => { - _this.joinLoading = false - }) } else { + onsole.log("鍙傛暟閿欒") return false } }) @@ -467,7 +482,7 @@ exitCluster() { const h = this.$createElement let res = {} - + this.quitInput = "" this.$msgbox({ title: "", message: h( @@ -478,9 +493,14 @@ [ h("span", { class: "icon iconfont warn-icon" }, "\ue71c"), h("span", { class: "warn-title" }, "閫�鍑洪泦缇�"), - h("span", { class: "warn-dec" }, "纭畾閫�鍑洪泦缇ゅ悧锛�") + h("input", { + attrs: { placeholder: "璇疯緭鍏ラ泦缇ゅ瘑鐮�", id: "quit-input", class: "warn-title" }, + value: "", + on: { input: this.onQuitInputChange } + }) ] ), + // showInput: true, showCancelButton: true, showClose: true, confirmButtonText: "纭畾", @@ -491,10 +511,10 @@ // this.showCurCluster = false; // } async () => { + clearInterval(this.intervalTimer) try { - res = await leave() + res = await leave({ password: this.quitInput }) if (res && res.success) { - clearInterval(this.intervalTimer) this.showCurCluster = false this.ruleForm.virtualIp = "" this.ruleForm.clustername = "" @@ -515,16 +535,11 @@ message: err.msg }) } - }, - (err) => { - clearInterval(this.intervalTimer) - this.showCurCluster = false - this.ruleForm.virtualIp = "" - this.ruleForm.clustername = "" - this.ruleForm.clusterpwd = "" - this.clusterid = "" } ) + }, + onQuitInputChange() { + this.quitInput = document.getElementById("quit-input").value }, clearInput(typ) { if (typ == 1) { @@ -586,6 +601,7 @@ if (res && res.success) { if (res.data && res.data.clusterId) { this.isHasColony = true + this.showCurCluster = true this.clusterid = res.data.clusterId this.ruleForm.clustername = res.data.clusterName this.ruleForm.clusterpwd = "******" @@ -605,6 +621,13 @@ obj.nodeName = i.node_name obj.Address = i.node_ip obj.role = i.drift_state ? i.drift_state : "pc" + obj.online = i.online + + if (obj.id == res.data.localId) { + this.ruleForm.state = i.drift_state + this.ruleForm.localId = res.data.localId + this.masterNode = i.drift_state === "master" + } return obj }) } else { @@ -614,6 +637,15 @@ }, clearInnerNodes() { this.innerNodes = [] + }, + async change2Master() { + let res = await update2Master({ clusterId: this.clusterid, nodeId: this.ruleForm.localId }) + if (res && res.success) { + this.$message.success("鍒囨崲鎴愬姛") + this.findCluster() + } else { + this.$message.warning("鍒囨崲澶辫触") + } } } } @@ -625,7 +657,7 @@ } .cluster-guanli { margin: 0 auto; - width: 760px; + // width: 760px; padding: 0 10px; .btns { margin-top: 30px !important; -- Gitblit v1.8.0