index.tsx
2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, { FC, useState, useEffect, useCallback } from 'react';
import { Table, Button, Space } from "antd";
import { PlusOutlined } from "@ant-design/icons";
import { ColumnProps } from "antd/es/table";
import dayjs from 'dayjs';
import ServiceModal from './ServiceModal';
import { getServiceList } from "../../api/service.api";
const { Column } = Table;
interface ServiceProp {
createTime: string
description: string
id: number
modifyTime: null
name: string
status: number
}
interface ServiceSettingProp {}
const ServiceSetting: FC<ServiceSettingProp> = () => {
const [modalShow, setModalShow] = useState(false)
const [tableData, setTableData] = useState<ServiceProp[]>()
const initData = useCallback(async () => {
try {
const result = await getServiceList()
console.log('initData', result.data)
if (result.data) {
setTableData(result.data)
}
} catch (error) {
console.log(error)
}
}, [])
useEffect(() => {
initData()
}, [initData])
return (
<div>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={ () => setModalShow(true) }
style={{ marginBottom: '10px' }}
>添加应用</Button>
<Table dataSource={tableData} rowKey="id">
<Column<ColumnProps<ServiceProp>> title="应用ID" dataIndex="id" align="center" />
<Column<ColumnProps<ServiceProp>> title="系统名称" dataIndex="systemName" align="center" />
<Column<ColumnProps<ServiceProp>> title="应用名称" dataIndex="name" align="center" />
<Column<ColumnProps<ServiceProp>>
title="创建时间"
dataIndex="createTime"
align="center"
render={(text) => <span>{text ? dayjs(text).format('YYYY-MM-DD HH:mm:ss') : '--'}</span>}
/>
<Column<ColumnProps<ServiceProp>>
title="操作"
align="center"
render={() => (
<Space>
<Button
type="link"
size="small"
>编辑</Button>
<Button
type="link"
size="small"
>删除</Button>
</Space>
)}
/>
</Table>
<ServiceModal
modalVisible={modalShow}
onCreate={ (value) => {
console.log(value)
setModalShow(false)
} }
onCancel={ () => setModalShow(false) }
/>
</div>
)
}
export default ServiceSetting;