From 261e25074b7f35010efccb86bf82f6fe36e4b10d Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@iotlink.com> Date: 星期三, 14 十月 2020 10:27:19 +0800 Subject: [PATCH] 添加硬件信息显示 --- src/pages/settings/components/ClusterManagement.vue | 322 +++++++++++++++++++++++++++++++++++------------------ 1 files changed, 212 insertions(+), 110 deletions(-) diff --git a/src/pages/settings/components/ClusterManagement.vue b/src/pages/settings/components/ClusterManagement.vue index cb07345..9a04946 100644 --- a/src/pages/settings/components/ClusterManagement.vue +++ b/src/pages/settings/components/ClusterManagement.vue @@ -7,7 +7,7 @@ <el-col :span="12"> <el-tabs v-model="activeName" id="e-alaycluster" v-if="!isHasColony"> <el-tab-pane label="鍒涘缓闆嗙兢" name="1" :disabled="isHasColony"> - <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px"> + <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px"> <el-form-item label="闆嗙兢鍚嶇О" prop="clustername"> <el-input v-model="ruleForm.clustername" placeholder="鎵嬪姩杈撳叆, 濡傗�滈泦缇鈥�" size="small"></el-input> </el-form-item> @@ -15,25 +15,29 @@ <el-input v-model="clusterid" placeholder="涓嶅厑璁歌緭鍏�,淇濆瓨鍚庡洖鏄�" disabled size="small"></el-input> </el-form-item> <el-form-item label="闆嗙兢瀵嗙爜" prop="clusterpwd" style="width:500px"> - <el-input v-model="ruleForm.clusterpwd" placeholder="璇疯緭鍏�6-12浣嶅瘑鐮�,鎴栫偣鍑荤敓鎴�" size="small"> + <el-input v-model="ruleForm.clusterpwd" placeholder="璇疯緭鍏�6浣嶅瘑鐮�,鎴栫偣鍑荤敓鎴�" size="small"> <el-button type="text" slot="suffix" @click="generatePassword">鐢熸垚瀵嗙爜</el-button> </el-input> </el-form-item> - - <!-- <el-form-item label="铏氭嫙IP" prop="virtualip"> - <ip-input :ip="ruleForm.virtualip" :on-blur="onIpBlur"></ip-input> - </el-form-item> --> + <el-form-item label="铏氭嫙/澶栭儴IP" prop="virtualIp"> + <ip-input :ip="ruleForm.virtualIp" :on-blur="onIpBlur"></ip-input> + </el-form-item> <el-form-item style="width:500px"> <el-button type="primary" size="small" @click="submitForm('ruleForm')">淇濆瓨</el-button> </el-form-item> </el-form> </el-tab-pane> - + <!-- 鍔犲叆宸叉湁闆嗙兢 --> - <el-tab-pane label="鍔犲叆宸叉湁闆嗙兢" name="3" :disabled="isHasColony"> + <el-tab-pane label="鍔犲叆宸叉湁闆嗙兢" name="2" :disabled="isHasColony"> <el-form label-width="80px" :model="joinForm" :rules="joinRules" ref="joinForm"> <el-form-item label="IP鍦板潃" style="width:440px"> - <el-input v-model="joinForm.clusterip" placeholder="璇疯緭鍏ラ泦缇ゅ唴浠绘剰IP鍦板潃" size="small"> + <el-input + v-model="joinForm.clusterip" + placeholder="璇疯緭鍏ラ泦缇ゅ唴浠绘剰IP鍦板潃" + size="small" + autocomplete="new-password" + > <el-button type="text" slot="suffix" @@ -54,6 +58,7 @@ placeholder="璇疯緭鍏ラ泦缇ゅ瘑鐮�" show-password size="small" + autocomplete="new-password" ></el-input> </el-form-item> <el-form-item style="width:440px"> @@ -64,7 +69,7 @@ </el-tabs> <!-- 鏈夐泦缇ょ殑鎯呭喌 --> <div v-if="isHasColony" id="h-alaycluster"> - <el-form :model="ruleForm" ref="ruleForm" label-width="80px"> + <el-form :model="ruleForm" ref="ruleForm" label-width="100px"> <el-form-item label="闆嗙兢鍚嶇О" prop="clustername"> <el-input v-model="ruleForm.clustername" placeholder="鎵嬪姩杈撳叆, 濡傗�滈泦缇鈥�" size="small"></el-input> </el-form-item> @@ -75,14 +80,14 @@ <el-input v-model="ruleForm.clusterpwd" disabled - placeholder="璇疯緭鍏�6-12浣嶅瘑鐮�,鎴栫偣鍑荤敓鎴�" + placeholder="璇疯緭鍏�6浣嶅瘑鐮�,鎴栫偣鍑荤敓鎴�" size="small" ></el-input> </el-form-item> - <!-- <el-form-item label="铏氭嫙IP" prop="virtualip"> - <ip-input :ip="ruleForm.virtualip" :on-blur="onIpBlur"></ip-input> - </el-form-item> --> + <el-form-item label="铏氭嫙IP" prop="virtualIp"> + <ip-input :ip="ruleForm.virtualIp" :on-blur="onIpBlur"></ip-input> + </el-form-item> <el-form-item style="width:440px;text-align: right;"> <el-button size="small" type="danger" @click="leave">閫�鍑洪泦缇�</el-button> <el-button @@ -95,80 +100,76 @@ </el-form> </div> </el-col> - <el-col :span="14" style="height: 100%;" v-if="members.length !== 0"> + <el-col :span="12" style="height: 100%;" v-if="members.length !== 0"> <serfDiagram ref="diagram" :members="members" :agent="agentName" v-loading="loading" @selected-node="joinNode" + class="nodes-svg" ></serfDiagram> </el-col> </el-row> - <div class="ui-top-view"> - <div class="ui-top-title">婕傜ЩIP</div> - </div> - <el-row> - <el-col :span="12"> - <el-form :model="vrIpForm" ref="vrIpForm" :rules="vrIpRules" style="padding:20px 40px;"> - <el-form-item label="铏氭嫙IP" prop="virtual_ip"> - <ip-input :ip="vrIpForm.virtual_ip" :on-blur="onIpBlur"></ip-input> - <el-switch v-model="vrIpForm.enable" style="margin-left:30px;"></el-switch> - </el-form-item> - <el-form-item style="width:500px"> - <el-button type="primary" size="small" @click="saveForm('vrIpForm')">淇濆瓨</el-button> - </el-form-item> - </el-form> - </el-col> - </el-row> + <div class="ui-top-view"> <div class="ui-top-title">瀛樺偍闆嗙兢绠$悊</div> </div> <el-row> <el-col :span="12"> <el-tabs id="e-dbcluster" v-model="sActiveName"> - <el-tab-pane label="鍒涘缓闆嗙兢" name="s-first"> - <el-button type="primary" style="float: none;margin: 20px 0px;" size="small">鍒涘缓瀛樺偍闆嗙兢</el-button> - <p>鐐瑰嚮灏嗘湰鏈哄垱寤轰负瀛樺偍闆嗙兢</p> + <el-tab-pane label="鍒涘缓闆嗙兢" name="s-first" v-if="sActiveName != 's-third1'"> + <el-button + type="primary" + style="float: left;margin: 20px 0px;" + size="small" + @click="createEsCluster()" + >鍒涘缓瀛樺偍闆嗙兢</el-button> + <!-- <p>鐐瑰嚮灏嗘湰鏈哄垱寤轰负瀛樺偍闆嗙兢</p> --> </el-tab-pane> - <el-tab-pane label="鍔犲叆宸叉湁闆嗙兢" name="s-second"> + <el-tab-pane label="鍔犲叆宸叉湁闆嗙兢" name="s-second" v-if="sActiveName != 's-third1'"> <el-form label-width="80px"> - <el-form-item label="IP鍦板潃" style="text-align: left;"> - <el-input v-model="clusterip2" placeholder="璇疯緭鍏ラ泦缇ゅ唴浠绘剰IP鍦板潃" size="small"> - <el-button - type="text" - slot="suffix" - v-show="!searchDis" - @click="searchColony" - >鎼滅储闆嗙兢</el-button> - </el-input> + <el-form-item label="IP鍦板潃" style="text-align: left;width: 300px;"> + <el-input + v-model="esNodeIp" + placeholder="璇疯緭鍏ラ泦缇ゅ唴浠绘剰IP鍦板潃" + size="small" + autocomplete="off" + ></el-input> + <el-checkbox + label="涓昏妭鐐�" + v-model="esNodeType" + style="margin-left: 20px;position: absolute;" + ></el-checkbox> </el-form-item> <el-form-item> - <el-button type="primary" @click="join('joinForm')" size="small">鍔犲叆闆嗙兢</el-button> + <el-button + type="primary" + @click="joinESCluster()" + size="small" + style="float: left;" + >鍔犲叆闆嗙兢</el-button> </el-form-item> </el-form> </el-tab-pane> - <el-tab-pane label="绠$悊闆嗙兢" name="s-third"> - <h3 style="text-align: left;margin: 10px 0px;"> - <b>闆嗙兢鍚嶇О</b> - <span>xxx</span> - </h3> - <el-table :data="tableData" style="width: 100%"> + <el-tab-pane label="闆嗙兢淇℃伅" name="s-third"> + <el-table :data="esNodes" style="width: 100%"> <el-table-column prop="nodeType" label="鑺傜偣绫诲瀷"></el-table-column> - <el-table-column prop="nodeName" label="鑺傜偣鍚嶇О"></el-table-column> - <el-table-column prop="nodeIp" label="鑺傜偣IP鍦板潃"></el-table-column> - <el-table-column prop="registerTime" label="娉ㄥ唽鏃堕棿"></el-table-column> + <el-table-column prop="name" label="鑺傜偣鍚嶇О"></el-table-column> + <el-table-column prop="ip" label="鑺傜偣IP鍦板潃" min-width="90px"></el-table-column> + <el-table-column prop="buildDate" label="娉ㄥ唽鏃堕棿" min-width="120px"></el-table-column> </el-table> </el-tab-pane> </el-tabs> </el-col> </el-row> + </div> </template> <script> import { - createColony, + createSerfCluster, randomPwd, search, getSearchNodes, @@ -178,11 +179,19 @@ joinCluster, leave, getVrrp, - setVrrp + setVrrp, + createESNode, + addESNode, + getEsClusterInfo } from "@/api/clusterManage"; + +import { + getDevInfo +} from "@/api/system"; + import serfDiagram from "@/components/serfDiagram"; import ipInput from "@/components/subComponents/IPInput"; - +import {isIPv4} from "@/scripts/validate"; export default { components: { serfDiagram, @@ -194,24 +203,31 @@ return callback(new Error("瀵嗙爜涓嶈兘涓虹┖")); } setTimeout(() => { - if (value.length > 16 || value.length < 6) { - callback(new Error("瀵嗙爜搴斾负6-16浣�!")); + // if (value.length > 16 || value.length < 6) { + // callback(new Error("瀵嗙爜搴斾负6-16浣�!")); + // } else { + // callback(); + // } + if (value.length != 6) { + callback(new Error("瀵嗙爜搴斾负6浣�!")); } else { callback(); } }, 1000); }; + return { activeName: "1", sActiveName: "s-first", clusterid: "", - clusterip2: "", + esNodeIp: "", + esNodeType: "", clusterpwd2: "", sClusterip: "", ruleForm: { clustername: "", clusterpwd: "", - //virtualip: "" + virtualIp: "" }, vrIpForm: { enable: true, @@ -233,41 +249,22 @@ { required: true, message: "璇疯緭鍏ラ泦缇ゅ悕绉�", trigger: "change" } ], clusterpwd: [{ validator: checkPwd, trigger: "change" }], - // virtualip: [ - // { required: true, message: "璇疯緭鍏ヨ櫄鎷烮P", trigger: "change" } - // ] - }, - vrIpRules: { - virtualip: [ - { required: true, message: "璇疯緭鍏ヨ櫄鎷烮P", trigger: "change" } + virtualIp: [ + { required: true, validator: isIPv4, trigger: "change" } ] }, + // vrIpRules: { + // virtualIp: [ + // { required: true, message: "璇疯緭鍏ヨ櫄鎷烮P", trigger: "change" } + // ] + // }, joinRules: { clusterpwd: [ { required: true, message: "璇疯緭鍏ラ泦缇ゅ瘑鐮�", trigger: "change" }, { validator: checkPwd, trigger: "change" } ] }, - tableData: [ - { - nodeType: "涓昏妭鐐�", - nodeName: "xxxx", - nodeIp: "192.168.12.102", - registerTime: "2016-04-04" - }, - { - nodeType: "涓昏妭鐐�", - nodeName: "xxxx", - nodeIp: "192.168.14.122", - registerTime: "2016-05-04" - }, - { - nodeType: "涓昏妭鐐�", - nodeName: "xxxx", - nodeIp: "192.168.10.132", - registerTime: "2016-02-12" - } - ], + esNodes: [], scheduleId: "", isHasColony: false, currentCluster: {}, @@ -278,7 +275,11 @@ members: [] }; }, - watch: {}, + mounted() { + this.findCluster(); + this.getVrrpInfo(); + this.getEsClusterNodes(); + }, methods: { cleanValue() { this.members = []; @@ -289,14 +290,15 @@ submitForm(formName) { this.$refs[formName].validate(valid => { if (valid) { - alert("submit!"); + debugger + //alert("submit!"); let json = { clusterId: this.clusterid, clusterName: this.ruleForm.clustername, password: this.ruleForm.clusterpwd, - //virtualip: this.ruleForm.virtualip + virtualIp: this.ruleForm.virtualIp }; - this.createColony(json).then(() => { + this.createCluster(json).then(() => { this.findCluster(); }); } else { @@ -305,8 +307,8 @@ } }); }, + saveForm(formName) { - debugger this.$refs[formName].validate(valid => { if (valid) { alert("submit!"); @@ -314,7 +316,7 @@ enable: this.vrIpForm.enable, serve_port: this.vrIpForm.serve_port, virtual_ip: this.vrIpForm.virtual_ip, - + }; setVrrp(json).then(() => { this.getVrrpInfo(); @@ -325,7 +327,8 @@ } }); }, - join(formName) { + + join (formName) { this.$refs[formName].validate(valid => { if (valid) { if (Object.keys(this.currentCluster).length === 0) { @@ -353,8 +356,8 @@ } }); }, - async createColony(json) { - let res = await createColony(json); + async createCluster(json) { + let res = await createSerfCluster(json); console.log(res, "鍒涘缓闆嗙兢"); this.$notify({ title: res.success ? "鎴愬姛" : "澶辫触", @@ -371,6 +374,7 @@ async searchColony() { this.$refs["joinForm"].validate(valid => { if (valid) { + this.members = []; let json = { password: this.joinForm.clusterpwd, ip: this.joinForm.clusterip @@ -468,9 +472,11 @@ this.clusterid = res.data.clusterId; this.ruleForm.clustername = res.data.clusterName; this.ruleForm.clusterpwd = res.data.clusterpwd - //this.ruleForm.virtualip = res.data.virtualip + this.ruleForm.virtualIp = res.data.virtualIp let list = res.data.nodes.map(i => { + debugger let obj = {}; + obj.device_type = i.device_type; obj.cluster_id = i.cluster_id; obj.clusterName = res.data.clusterName; obj.create_time = i.create_time; @@ -489,13 +495,13 @@ } } }, - getVrrpInfo(){ - getVrrp().then(res=>{ - if(res.success){ + getVrrpInfo() { + getVrrp().then(res => { + if (res.success) { this.vrIpForm.virtual_ip = res.data.virtual_ip; this.vrIpForm.enable = res.data.enable; } - }).catch(e=>{ + }).catch(e => { console.log(e) }) }, @@ -537,10 +543,11 @@ this.ruleForm.clusterpwd = "" this.clusterid = ""; this.isHasColony = false; - this.activeName = "1" + this.activeName = "1"; + this.members = []; } }).catch(() => { }); - + }, joinNode(event, node) { this.currentCluster.cluster_id = node.cluster_id; @@ -591,21 +598,113 @@ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; var uuid = []; - for (let i = 0; i < 16; i++) { + for (let i = 0; i < 6; i++) { uuid[i] = chars[0 | (Math.random() * 50)]; } this.ruleForm.clusterpwd = uuid.join(""); }, - onIpBlur(ip) { - this.vrIpForm.virtual_ip = ip; + + async getEsClusterNodes() { + let rsp = await getDevInfo(); + let hostIpAddr = ""; + if (rsp && rsp.success) { + hostIpAddr = rsp.data.ip; + } + + if (hostIpAddr.length) { + rsp = await getEsClusterInfo({ ip: hostIpAddr }); + if (rsp && rsp.success) { + this.esNodes = rsp.data.map(el => { + return { + // buildDate: "2018-06-11T23:38:03.357887Z", + buildDate: el.buildDate.split("T")[0] + " " + el.buildDate.split("T")[1].slice(0, 8), + ip: el.ip, + name: el.name, + nodeType: el.nodeType, + } + }) + + if (this.esNodes.length) { + this.sActiveName = 's-third'; + } + } + } + }, + createEsCluster() { + createESNode().then(rsp => { + if (rsp && rsp.success) { + this.$message({ + type: "success", + duration: 2000, + message: "鍒涘缓鎴愬姛" + }); + + this.getSearchNodes(); + } else { + this.$message({ + type: "error", + duration: 2000, + message: rsp.msg + }); + } + }).catch(rsp => { + this.$message({ + type: "error", + duration: 2000, + message: rsp.msg + }); + }) + }, + joinESCluster() { + if (!this.esNodeIp.length) { + this.$message({ + type: "error", + duration: 2000, + message: "璇疯緭鍏ユ纭殑ip鍦板潃" + }); + return; + } + + addESNode({ ip: this.esNodeIp, option: this.esNodeType ? "1" : "2" }).then(rsp => { + if (rsp && rsp.success) { + this.$message({ + type: "success", + duration: 2000, + message: "鍔犲叆鎴愬姛" + }); + + this.getSearchNodes(); + } else { + this.$message({ + type: "error", + duration: 2000, + message: rsp.msg + }); + } + }).catch(rsp => { + this.$message({ + type: "error", + duration: 2000, + message: rsp.msg + }); + }) + }, + onIpBlur (ip) { + //this.vrIpForm.virtual_ip = ip; + this.ruleForm.virtualIp = ip; + console.log(this.ruleForm.virtualIp) } + + + }, - mounted() { + mounted () { this.findCluster(); - this.getVrrpInfo(); + }, - created() { } + created () { } + }; </script> <style lang="scss"> @@ -677,4 +776,7 @@ height: 30px; line-height: 30px; } +.nodes-svg{ + background-color: aquamarine; +} </style> -- Gitblit v1.8.0