index.tsx
3.03 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React, { FC, useState, useEffect, useCallback } from 'react';
import { Table, Button, Space, Modal } from "antd";
import { PlusOutlined, ExclamationCircleOutlined } from "@ant-design/icons";
import { ColumnProps } from "antd/es/table";
import dayjs from 'dayjs';
import SystemModal from './SystemModal';
import { getSystemList, deleteSystem } from "../../api/system.api";
// const utc = require('dayjs/plugin/utc');
// dayjs.extend(utc);
const { Column } = Table;
const { confirm } = Modal;
interface System {
createTime: number
description: string
id: number
modifyTime: null
name: string
status: number
}
interface SystemSettingProp {}
const SystemSetting: FC<SystemSettingProp> = () => {
const [modalShow, setModalShow] = useState(false)
const [tableData, setTableData] = useState<System[]>()
const initData = useCallback(async () => {
try {
const result = await getSystemList()
if (result.data) {
setTableData(result.data)
}
} catch (error) {
console.error(error)
}
}, [])
/**
* 删除节点
*/
const onRemoveRow = (selectedRow: any) => {
console.log('onRemoveRow::', selectedRow)
confirm({
title: '你确定要删除吗?',
icon: <ExclamationCircleOutlined />,
okText: '确认',
okType: 'danger',
cancelText: '取消',
async onOk() {
console.log('OK');
const deleteRes = await deleteSystem(selectedRow.id) as any
console.log('deleteRes', deleteRes)
},
onCancel() {
console.log('Cancel');
},
});
}
useEffect(() => {
initData()
}, [initData])
return (
<div>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={ () => setModalShow(true) }
style={{ marginBottom: '10px' }}
>添加系统</Button>
<Table dataSource={tableData} rowKey="id">
<Column<ColumnProps<System>> title="系统ID" dataIndex="id" align="center" />
<Column<ColumnProps<System>> title="系统名称" dataIndex="name" align="center" />
<Column<ColumnProps<System>>
title="创建时间"
dataIndex="createTime"
align="center"
render={(text) => <span>{text ? dayjs(text).format('YYYY-MM-DD HH:mm:ss') : '--'}</span>}
/>
<Column<ColumnProps<System>>
title="操作"
align="center"
render={(_, record) => (
<Space>
<Button
type="link"
size="small"
>编辑</Button>
<Button
type="link"
size="small"
onClick={ () => {
onRemoveRow(record)
}}
>删除</Button>
</Space>
)}
/>
</Table>
<SystemModal
modalVisible={modalShow}
onCreate={ (value) => {
console.log(value)
initData()
setModalShow(false)
} }
onCancel={ () => setModalShow(false) }
/>
</div>
)
}
export default SystemSetting;