1515 *
1616 */
1717import React , { useState , useEffect } from 'react' ;
18- import { Table , Space , Button , Popover , Select } from 'antd' ;
18+ import { Table , Space , Button , Popover , Select , Modal , Form , Input , Popconfirm , AutoComplete } from 'antd' ;
1919import Icon from '@ant-design/icons' ;
2020import moment from 'moment' ;
21+ import _ from 'lodash' ;
2122import { useSelector } from 'react-redux' ;
2223import PageLayout from '@/components/pageLayout' ;
23- import { getN9EServers , updateN9EServerCluster } from '@/services/help' ;
24+ import { getN9EServers , updateN9EServerCluster , addN9EServers , deleteN9EServers } from '@/services/help' ;
2425import { getCommonClusters } from '@/services/common' ;
2526import { RootState as AccountRootState , accountStoreState } from '@/store/accountInterface' ;
2627import SystemInfoSvg from '../../../../public/image/system-info.svg' ;
@@ -38,23 +39,21 @@ function ClusterEditor({ id, defaultValue, clusters, onSave }) {
3839 destroyTooltipOnHide
3940 content = {
4041 < Space >
41- < Select
42+ < AutoComplete
4243 style = { { minWidth : 200 } }
4344 placeholder = '选择集群'
45+ options = { _ . map ( clusters , ( item ) => {
46+ return {
47+ label : item ,
48+ value : item ,
49+ } ;
50+ } ) }
4451 allowClear
4552 value = { cluster }
4653 onChange = { ( val ) => {
4754 setCluster ( val ) ;
4855 } }
49- >
50- { clusters . map ( ( item ) => {
51- return (
52- < Select . Option key = { item } value = { item } >
53- { item }
54- </ Select . Option >
55- ) ;
56- } ) }
57- </ Select >
56+ />
5857 < Button
5958 type = 'primary'
6059 onClick = { ( ) => {
@@ -78,11 +77,13 @@ function ClusterEditor({ id, defaultValue, clusters, onSave }) {
7877 ) ;
7978}
8079
81- export default function Migrate ( ) {
80+ export default function Servers ( ) {
8281 const { profile } = useSelector < AccountRootState , accountStoreState > ( ( state ) => state . account ) ;
8382 const [ data , setData ] = useState ( [ ] ) ;
8483 const [ loading , setLoading ] = useState ( false ) ;
8584 const [ clusters , setClusters ] = useState ( [ ] ) ;
85+ const [ form ] = Form . useForm ( ) ;
86+ const [ visible , setVisible ] = useState ( false ) ;
8687 const fetchData = ( ) => {
8788 getN9EServers ( )
8889 . then ( ( res ) => {
@@ -100,8 +101,6 @@ export default function Migrate() {
100101 fetchData ( ) ;
101102 } , [ ] ) ;
102103
103- console . log ( 'profile' , profile ) ;
104-
105104 return (
106105 < PageLayout
107106 title = {
@@ -114,54 +113,129 @@ export default function Migrate() {
114113 < div >
115114 < div style = { { padding : 20 } } >
116115 { profile . admin ? (
117- < Table
118- rowKey = 'id'
119- loading = { loading }
120- dataSource = { data }
121- pagination = { false }
122- columns = { [
123- {
124- title : '引擎实例' ,
125- dataIndex : 'instance' ,
126- key : 'instance' ,
127- } ,
128- {
129- title : '告警集群' ,
130- dataIndex : 'cluster' ,
131- key : 'cluster' ,
132- } ,
133- {
134- title : '上次心跳时间' ,
135- dataIndex : 'clock' ,
136- key : 'clock' ,
137- render : ( text ) => {
138- return moment . unix ( text ) . format ( 'YYYY-MM-DD HH:mm:ss' ) ;
116+ < div >
117+ < div
118+ style = { {
119+ display : 'flex' ,
120+ justifyContent : 'flex-end' ,
121+ } }
122+ >
123+ < Button
124+ onClick = { ( ) => {
125+ setVisible ( true ) ;
126+ } }
127+ >
128+ 新增
129+ </ Button >
130+ </ div >
131+ < Table
132+ rowKey = 'id'
133+ loading = { loading }
134+ dataSource = { data }
135+ pagination = { false }
136+ columns = { [
137+ {
138+ title : '引擎实例' ,
139+ dataIndex : 'instance' ,
140+ key : 'instance' ,
139141 } ,
140- } ,
141- {
142- title : '操作' ,
143- render : ( record ) => {
144- return (
145- < Space >
146- < ClusterEditor
147- id = { record . id }
148- defaultValue = { record . cluster || undefined }
149- clusters = { clusters }
150- onSave = { ( ) => {
151- fetchData ( ) ;
152- } }
153- />
154- </ Space >
155- ) ;
142+ {
143+ title : '告警集群' ,
144+ dataIndex : 'cluster' ,
145+ key : 'cluster' ,
156146 } ,
157- } ,
158- ] }
159- />
147+ {
148+ title : '上次心跳时间' ,
149+ dataIndex : 'clock' ,
150+ key : 'clock' ,
151+ render : ( text ) => {
152+ return moment . unix ( text ) . format ( 'YYYY-MM-DD HH:mm:ss' ) ;
153+ } ,
154+ } ,
155+ {
156+ title : '操作' ,
157+ width : 150 ,
158+ render : ( record ) => {
159+ return (
160+ < Space >
161+ < ClusterEditor
162+ id = { record . id }
163+ defaultValue = { record . cluster || undefined }
164+ clusters = { clusters }
165+ onSave = { ( ) => {
166+ fetchData ( ) ;
167+ } }
168+ />
169+ < Popconfirm
170+ title = '确认删除?'
171+ onConfirm = { ( ) => {
172+ deleteN9EServers ( [ record . id ] ) . then ( ( ) => {
173+ fetchData ( ) ;
174+ } ) ;
175+ } }
176+ >
177+ < a style = { { color : '#f53146' } } > 删除</ a >
178+ </ Popconfirm >
179+ </ Space >
180+ ) ;
181+ } ,
182+ } ,
183+ ] }
184+ />
185+ </ div >
160186 ) : (
161187 < div > 您没有权限查看</ div >
162188 ) }
163189 </ div >
164190 </ div >
191+ < Modal
192+ title = '新增'
193+ visible = { visible }
194+ onCancel = { ( ) => {
195+ setVisible ( false ) ;
196+ } }
197+ footer = { [
198+ < Button
199+ key = 'cancel'
200+ onClick = { ( ) => {
201+ setVisible ( false ) ;
202+ } }
203+ >
204+ 取消
205+ </ Button > ,
206+ < Button
207+ key = 'ok'
208+ type = 'primary'
209+ onClick = { ( ) => {
210+ form . validateFields ( ) . then ( ( values ) => {
211+ addN9EServers ( values ) . then ( ( ) => {
212+ setVisible ( false ) ;
213+ fetchData ( ) ;
214+ } ) ;
215+ } ) ;
216+ } }
217+ >
218+ 提交
219+ </ Button > ,
220+ ] }
221+ >
222+ < Form form = { form } >
223+ < Form . Item label = '引擎实例' name = 'instance' rules = { [ { required : true , message : '请填写引擎实例' } ] } >
224+ < Input />
225+ </ Form . Item >
226+ < Form . Item label = '告警集群' name = 'cluster' rules = { [ { required : true , message : '请选择告警集群' } ] } >
227+ < AutoComplete
228+ options = { _ . map ( clusters , ( item ) => {
229+ return {
230+ label : item ,
231+ value : item ,
232+ } ;
233+ } ) }
234+ allowClear
235+ />
236+ </ Form . Item >
237+ </ Form >
238+ </ Modal >
165239 </ PageLayout >
166240 ) ;
167241}
0 commit comments