From ad85ca6fdd062671047118a7d58776f9a0cf60d7 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 14 十一月 2023 14:38:59 +0800
Subject: [PATCH] 集群切换添加密码

---
 src/pages/settings/views/clusterManagement.vue |   75 +++++++++++++++++++++++++++++++------
 1 files changed, 63 insertions(+), 12 deletions(-)

diff --git a/src/pages/settings/views/clusterManagement.vue b/src/pages/settings/views/clusterManagement.vue
index 6db3aa5..98825dc 100644
--- a/src/pages/settings/views/clusterManagement.vue
+++ b/src/pages/settings/views/clusterManagement.vue
@@ -253,7 +253,8 @@
         clusterip: [{ validator: isIPv4, trigger: "blur" }],
         clusterpwd: [{ validator: checkPwd, required: true, trigger: "blur" }]
       },
-      quitInput: ""
+      clusterPassword: "",
+      clusterPasswordInput: ""
     }
   },
   components: {
@@ -482,7 +483,7 @@
     exitCluster() {
       const h = this.$createElement
       let res = {}
-      this.quitInput = ""
+      this.clusterPasswordInput = ""
       this.$msgbox({
         title: "",
         message: h(
@@ -494,7 +495,7 @@
             h("span", { class: "icon iconfont warn-icon" }, "\ue71c"),
             h("span", { class: "warn-title" }, "閫�鍑洪泦缇�"),
             h("input", {
-              attrs: { placeholder: "璇疯緭鍏ラ泦缇ゅ瘑鐮�", id: "quit-input", class: "warn-title" },
+              attrs: { placeholder: "璇疯緭鍏ラ泦缇ゅ瘑鐮�", id: "cluster-password", class: "warn-title" },
               value: "",
               on: { input: this.onQuitInputChange }
             })
@@ -513,7 +514,7 @@
         async () => {
           clearInterval(this.intervalTimer)
           try {
-            res = await leave({ password: this.quitInput })
+            res = await leave({ password: this.clusterPasswordInput })
             if (res && res.success) {
               this.showCurCluster = false
               this.ruleForm.virtualIp = ""
@@ -539,7 +540,7 @@
       )
     },
     onQuitInputChange() {
-      this.quitInput = document.getElementById("quit-input").value
+      this.clusterPasswordInput = document.getElementById("cluster-password").value
     },
     clearInput(typ) {
       if (typ == 1) {
@@ -639,13 +640,63 @@
       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("鍒囨崲澶辫触")
-      }
+      const h = this.$createElement
+      this.clusterPasswordInput = ""
+      this.$msgbox({
+        title: "",
+        message: h(
+          "div",
+          {
+            style: "display: flex;  flex-direction: column; justify-content: center; align-items: center;"
+          },
+          [
+            h("span", { class: "icon iconfont warn-icon" }, "\ue71c"),
+            h("span", { class: "warn-title" }, "鍒囨崲涓昏妭鐐�"),
+            h("input", {
+              attrs: { placeholder: "璇疯緭鍏ラ泦缇ゅ瘑鐮�", id: "cluster-password", class: "warn-title" },
+              value: "",
+              on: { input: this.onQuitInputChange }
+            })
+          ]
+        ),
+        // showInput: true,
+        showCancelButton: true,
+        showClose: true,
+        confirmButtonText: "纭畾",
+        cancelButtonText: "鍙栨秷",
+        customClass: "del-account-message-box"
+      })
+        .then(
+          // () => {
+          //   this.showCurCluster = false;
+          // }
+          async () => {
+            clearInterval(this.intervalTimer)
+            try {
+              let res = await update2Master({
+                clusterId: this.clusterid,
+                nodeId: this.ruleForm.localId,
+                password: this.clusterPasswordInput
+              })
+              if (res && res.success) {
+                this.$message.success("鍒囨崲鎴愬姛")
+                this.findCluster()
+              } else {
+                this.$message.warning("鍒囨崲澶辫触, 璇锋鏌ュ瘑鐮�")
+                this.masterNode = false
+              }
+            } catch (err) {
+              console.log(err)
+              this.$notify.error({
+                title: "澶辫触",
+                message: err.msg
+              })
+            }
+          }
+        )
+        .catch(() => {
+          this.masterNode = false
+        })
     }
   }
 }

--
Gitblit v1.8.0