|
@@ -0,0 +1,408 @@
|
|
|
+<template>
|
|
|
+ <a-space>
|
|
|
+ <a-button type="primary" class="role_btn role_add" @click="showAddNode">添加节点</a-button>
|
|
|
+<!-- <a-button type="primary" class="role_btn role_add" @click="onDeleteALlNode">删除节点</a-button>-->
|
|
|
+<!-- <a-button type="primary" class="role_btn role_add" @click="onEditNode">编辑节点</a-button>-->
|
|
|
+ </a-space>
|
|
|
+
|
|
|
+ <!-- 添加点击对话框 -->
|
|
|
+ <a-modal v-model:visible="Visible" title="Title" @ok="handleOk">
|
|
|
+
|
|
|
+ <a-form
|
|
|
+ ref="formRef"
|
|
|
+ :model="formState"
|
|
|
+ :rules="rules"
|
|
|
+ :label-col="labelCol"
|
|
|
+ :wrapper-col="wrapperCol"
|
|
|
+ >
|
|
|
+ <a-form-item ref="name" name="name">
|
|
|
+ <label>name:</label>
|
|
|
+ <a-input v-model:value="formState.name" />
|
|
|
+ </a-form-item>
|
|
|
+
|
|
|
+ <a-form-item ref="host" name="host">
|
|
|
+ <label>host:</label>
|
|
|
+ <a-input v-model:value="formState.host" />
|
|
|
+ </a-form-item>
|
|
|
+
|
|
|
+ <a-form-item ref="port" name="port">
|
|
|
+ <label>port:</label>
|
|
|
+ <a-input v-model:value="formState.port" placeholder="输入服务器端口" />
|
|
|
+ </a-form-item>
|
|
|
+
|
|
|
+ <a-form-item ref="url" name="url">
|
|
|
+ <label>url:</label>
|
|
|
+ <a-input v-model:value="formState.url" placeholder="输入切换地址url"/>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item ref="urlstatus" name="urlstatus">
|
|
|
+ <label>urlstatus:</label>
|
|
|
+ <a-input v-model:value="formState.urlstatus" placeholder="输入状态"/>
|
|
|
+ </a-form-item
|
|
|
+ >
|
|
|
+ <a-form-item>
|
|
|
+ <label>ping类型:</label>
|
|
|
+ <a-select v-model:value="formState.pingType" placeholder="选择ping类型">
|
|
|
+ <a-select-option :value=0>icmp</a-select-option>
|
|
|
+ <a-select-option :value=1>tcpping</a-select-option>
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+
|
|
|
+<!-- <template #footer>-->
|
|
|
+<!-- <a-button key="back" @click="cancel">关闭</a-button>-->
|
|
|
+<!-- <a-button key="back" @click="resetForm">Reset</a-button>-->
|
|
|
+<!-- <a-button key="submit" type="primary" @click="onSubmit">Submit</a-button>-->
|
|
|
+<!-- </template>-->
|
|
|
+ <a-form-item :wrapper-col="{ span: 14, offset: 4 }">
|
|
|
+
|
|
|
+ <a-button v-if="formState.isedit === false" type="primary" @click="onSubmit(true)">编辑</a-button>
|
|
|
+ <a-button v-else type="primary" @click="onSubmit(false)">Create</a-button>
|
|
|
+
|
|
|
+ <a-button style="margin-left: 10px" @click="resetForm">Reset</a-button>
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
+ </a-modal>
|
|
|
+
|
|
|
+ <!-- 加载节点信息 -->
|
|
|
+ <a-table :row-selection="rowSelection" :columns="columns" :data-source="datalist" rowKey="id" :style="{ height: '100%', borderRight: 0 }">
|
|
|
+ <template v-slot:bodyCell="{column , record}">
|
|
|
+ <template v-if="column.dataIndex === 'delete'">
|
|
|
+ <a-popconfirm
|
|
|
+ v-if="datalist.length"
|
|
|
+ title="是否删除这条记录"
|
|
|
+ @confirm="onDeleteNode(record)"
|
|
|
+ >
|
|
|
+ <a>删除</a>
|
|
|
+ </a-popconfirm>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-if="column.dataIndex === 'edit'">
|
|
|
+ <a @click="onEditNode(record)">编辑</a>
|
|
|
+ <!-- <a-popconfirm-->
|
|
|
+ <!-- v-if="datalist.length"-->
|
|
|
+ <!-- title="编辑"-->
|
|
|
+ <!-- @confirm="onDeleteNode(record)"-->
|
|
|
+ <!-- >-->
|
|
|
+ <!-- <a>Delete</a>-->
|
|
|
+ <!-- </a-popconfirm>-->
|
|
|
+ </template>
|
|
|
+
|
|
|
+ </template>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ </a-table>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts">
|
|
|
+import {
|
|
|
+ computed,
|
|
|
+ defineComponent,
|
|
|
+ getCurrentInstance,
|
|
|
+ inject,
|
|
|
+ onMounted,
|
|
|
+ reactive,
|
|
|
+ ref,
|
|
|
+ toRaw,
|
|
|
+ toRefs,
|
|
|
+ unref
|
|
|
+} from "vue";
|
|
|
+import {INode, NodeAddParam, NodeStatus} from "/@/model/node";
|
|
|
+import {delNodeReqUse, editNodeReqUse, nodeAddReqUse, nodeConfigGetALLReqUse, nodeReqUse} from "/@/apis/node";
|
|
|
+import { ColumnProps } from "ant-design-vue/lib/table";
|
|
|
+import {it} from "node:test";
|
|
|
+import {message} from "ant-design-vue";
|
|
|
+import router from "/@/router";
|
|
|
+import NodeConfigInfo = namespace.NodeConfigInfo;
|
|
|
+type Key = ColumnProps['key'];
|
|
|
+export default defineComponent({
|
|
|
+ name:"node",
|
|
|
+ components:{
|
|
|
+
|
|
|
+ },
|
|
|
+ data(){
|
|
|
+ return {
|
|
|
+ labelCol: {
|
|
|
+ span: 4,
|
|
|
+ },
|
|
|
+ wrapperCol: {
|
|
|
+ span: 14,
|
|
|
+ },
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+
|
|
|
+ },
|
|
|
+ setup() {
|
|
|
+ const formRef = ref()
|
|
|
+ // const reload: any = inject('reload')
|
|
|
+ //const reload = inject("reload");
|
|
|
+ const columns = [
|
|
|
+ {
|
|
|
+ title: 'Id',
|
|
|
+ name: 'Id',
|
|
|
+ dataIndex: 'id',
|
|
|
+ key: 'id',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '服务器名称',
|
|
|
+ name: 'Name',
|
|
|
+ dataIndex: 'Name',
|
|
|
+ key: 'Name',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '服务器IP',
|
|
|
+ dataIndex: 'Host',
|
|
|
+ key: 'Host',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '服务器命令',
|
|
|
+ dataIndex: 'Sshcommand',
|
|
|
+ key: 'Sshcommand',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '服务器密码',
|
|
|
+ key: 'Sshpassword',
|
|
|
+ dataIndex: 'Sshpassword',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '服务器名称',
|
|
|
+ key: 'Sshusername',
|
|
|
+ dataIndex:'Sshusername',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '删除',
|
|
|
+ key: 'delete',
|
|
|
+ dataIndex: 'delete',
|
|
|
+ // slots: { customRender: 'delete' },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '编辑',
|
|
|
+ key: 'edit',
|
|
|
+ dataIndex: 'edit',
|
|
|
+ // slots: { customRender: 'edit' },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ let ids = ""
|
|
|
+ const state = reactive({
|
|
|
+ datalist : [] as NodeConfigInfo[],
|
|
|
+ selectedTableRow: [] as INode[],
|
|
|
+ loading : false,
|
|
|
+ Visible : false,
|
|
|
+ code: false,
|
|
|
+ })
|
|
|
+
|
|
|
+ const rowSelection = {
|
|
|
+ onChange: (selectedRowKeys: Key[], selectedRows) => {
|
|
|
+ //第一个参数控制选不选中,第二个参数是选中列表的数据的集合
|
|
|
+ state.selectedTableRow = selectedRows
|
|
|
+ console.log(state.selectedTableRow);
|
|
|
+ },
|
|
|
+ getCheckboxProps: (record) => ({
|
|
|
+ disabled: record.releaseState === "ONLINE", //控制禁用那个按钮
|
|
|
+ releaseState: record.releaseState,
|
|
|
+ }),
|
|
|
+ };
|
|
|
+
|
|
|
+ const getNodeList = async () => {
|
|
|
+ let data = <NodeConfigInfo>{}
|
|
|
+ const node_list = await nodeConfigGetALLReqUse(null)
|
|
|
+ for (let dataKey in node_list.data.NodeConfigItem) {
|
|
|
+ data.Id = node_list.data.NodeConfigItem[dataKey].Node.Id
|
|
|
+ data.Name = node_list.data.NodeConfigItem[dataKey].Node.Name
|
|
|
+ data.Host = node_list.data.NodeConfigItem[dataKey].Node.Host
|
|
|
+ if (node_list.data.NodeConfigItem[dataKey].NodeConfig != null)
|
|
|
+ {
|
|
|
+ for (let nodeConfig of node_list.data.NodeConfigItem[dataKey].NodeConfig) {
|
|
|
+ data.Sshpassword = nodeConfig.Sshpassword;
|
|
|
+ data.Sshcommand = nodeConfig.Sshcommand;
|
|
|
+ data.Sshusername = nodeConfig.Sshusername;
|
|
|
+ }
|
|
|
+ state.datalist.push(data)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(state.datalist);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ const addNodeList = async (data) => {
|
|
|
+
|
|
|
+ let ret = await nodeAddReqUse(data)
|
|
|
+
|
|
|
+ if (ret.code == 0)
|
|
|
+ {
|
|
|
+ console.log(state.Visible);
|
|
|
+ state.Visible = false
|
|
|
+ await getNodeList()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log(state.Visible);
|
|
|
+ state.Visible = true
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ const editNode = async (data) => {
|
|
|
+ let ret = await editNodeReqUse(data)
|
|
|
+ if (ret.code == 0)
|
|
|
+ {
|
|
|
+ console.log(state.Visible);
|
|
|
+ state.Visible = false
|
|
|
+ await getNodeList()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log(state.Visible);
|
|
|
+ state.Visible = true
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ const delNodeById = async (data) => {
|
|
|
+
|
|
|
+ let ret = await delNodeReqUse(data)
|
|
|
+ if (ret.code == 0)
|
|
|
+ {
|
|
|
+ console.log(state.Visible);
|
|
|
+ state.Visible = false
|
|
|
+ await getNodeList()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log(state.Visible);
|
|
|
+ state.Visible = true
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ onMounted( () =>{
|
|
|
+ getNodeList()
|
|
|
+ })
|
|
|
+
|
|
|
+ const formState = reactive({
|
|
|
+ id: 0,
|
|
|
+ name: "",
|
|
|
+ host: "",
|
|
|
+ port: 22,
|
|
|
+ url: "",
|
|
|
+ pingType: undefined,
|
|
|
+ isedit : false,
|
|
|
+ urlstatus: 0,
|
|
|
+ urlcount:0,
|
|
|
+ urlret: "",
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ const rules = {
|
|
|
+ name: [
|
|
|
+ { required: true, message: "输入服务器名称", trigger: "blur" },
|
|
|
+ { min: 1, max: 100, message: "Length should be 3 to 5", trigger: "blur" }
|
|
|
+ ],
|
|
|
+ host: [
|
|
|
+ { required: true, message: "输入服务器IP", trigger: "blur" },
|
|
|
+ { min: 1, max: 100, message: "Length should be 3 to 5", trigger: "blur" }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ const resetForm = () => {
|
|
|
+ formRef.value.resetFields();
|
|
|
+ };
|
|
|
+
|
|
|
+ const onSubmit = (isedit) =>{
|
|
|
+ const reqdata = {
|
|
|
+ "id" : toRaw(formState).id,
|
|
|
+ "name" : toRaw(formState).name,
|
|
|
+ "host" : toRaw(formState).host,
|
|
|
+ "port" : toRaw(formState).port,
|
|
|
+ "url" : toRaw(formState).url,
|
|
|
+ "pingType": toRaw(formState).pingType,
|
|
|
+ "urlstatus": toRaw(formState).urlstatus,
|
|
|
+ }
|
|
|
+ if (isedit){
|
|
|
+ editNode(reqdata)
|
|
|
+ } else {
|
|
|
+ addNodeList(reqdata)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const onEditNode = (record) => {
|
|
|
+ formState.id = record.id
|
|
|
+ formState.name = record.name
|
|
|
+ formState.host = record.host
|
|
|
+ formState.port = record.port
|
|
|
+ formState.url = record.url
|
|
|
+ formState.pingType = record.pingType
|
|
|
+ formState.urlstatus = record.urlstatus
|
|
|
+ formState.isedit = false
|
|
|
+ state.Visible = true
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ const showAddNode = () => {
|
|
|
+ formState.name = ""
|
|
|
+ formState.host = ""
|
|
|
+ formState.port = 22
|
|
|
+ formState.url = ""
|
|
|
+ formState.pingType = undefined
|
|
|
+ formState.urlstatus = 0
|
|
|
+ formState.isedit = true
|
|
|
+ state.Visible = true;
|
|
|
+ }
|
|
|
+ const handleOk= () =>{
|
|
|
+
|
|
|
+ //addNodeList(data.value)
|
|
|
+ state.Visible = false
|
|
|
+ }
|
|
|
+ // 对话框的中的取消按钮
|
|
|
+ const cancel = () => {
|
|
|
+ state.loading = false
|
|
|
+ state.Visible = false
|
|
|
+ }
|
|
|
+
|
|
|
+ const { datalist ,selectedTableRow,loading,Visible } = toRefs(state)
|
|
|
+
|
|
|
+ const onDeleteALlNode = () => {
|
|
|
+ const idsTmp = []
|
|
|
+ selectedTableRow.value.forEach(item => idsTmp.push(item.id))
|
|
|
+ ids = idsTmp.join(",")
|
|
|
+ console.log(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ const onDeleteNode = ( record )=>{
|
|
|
+ console.log(record.id);
|
|
|
+ delNodeById({
|
|
|
+ "id" : record.id
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return{
|
|
|
+
|
|
|
+ onDeleteALlNode,
|
|
|
+ showAddNode,
|
|
|
+ handleOk,
|
|
|
+ cancel,
|
|
|
+ onEditNode,
|
|
|
+ onDeleteNode,
|
|
|
+ rowSelection,
|
|
|
+ resetForm,
|
|
|
+ onSubmit,
|
|
|
+ datalist,
|
|
|
+ selectedTableRow,
|
|
|
+ formRef,
|
|
|
+ formState,
|
|
|
+ rules,
|
|
|
+ columns,
|
|
|
+ loading,
|
|
|
+ Visible,
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+
|
|
|
+</style>
|