index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import React, { useState } from 'react';
  2. import { PageContainer } from '@ant-design/pro-components';
  3. import { Button, Card, Form, Input, Space, Table } from 'antd';
  4. import { PlusCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
  5. import type { ColumnsType } from 'antd/es/table';
  6. import moment from 'moment';
  7. interface DataType {
  8. name: string;
  9. record_id: string;
  10. }
  11. const RoleManagement: React.FC = () => {
  12. const [form] = Form.useForm();
  13. const [loading, setLoading] = useState(false);
  14. const [searchData] = useState({});
  15. const pagination = useState({});
  16. const [dataList] = useState([]);
  17. const onFinish = () => {};
  18. const onReset = () => {};
  19. const onAdd = () => {};
  20. const tableChange = (page: any) => {
  21. setLoading(true);
  22. const params = {
  23. q: 'page',
  24. current: page.current,
  25. pageSize: page.pageSize,
  26. ...searchData,
  27. };
  28. console.log(params);
  29. // 请求接口
  30. };
  31. const columns: ColumnsType<DataType> = [
  32. {
  33. title: '序号',
  34. align: 'center',
  35. key: 'index',
  36. render: (_: any, row: any, index: number) => index + 1,
  37. },
  38. {
  39. title: '角色名称',
  40. dataIndex: 'name',
  41. key: 'name',
  42. width: 250,
  43. },
  44. {
  45. title: '排序值',
  46. dataIndex: 'sequence',
  47. key: 'sequence',
  48. width: 250,
  49. },
  50. {
  51. title: '创建者',
  52. dataIndex: 'creator',
  53. key: 'creator',
  54. },
  55. {
  56. title: '创建时间',
  57. dataIndex: 'created_at',
  58. key: 'created_at',
  59. render: (v) => v && <span>{moment(v).format('YYYY-MM-DD HH:mm')}</span>,
  60. },
  61. {
  62. title: '备注',
  63. dataIndex: 'memo',
  64. key: 'memo',
  65. width: 250,
  66. },
  67. ];
  68. const paginationProps = {
  69. showSizeChanger: true,
  70. showQuickJumper: true,
  71. showTotal: (total: number) => {
  72. return <span> 共 {total}条 </span>;
  73. },
  74. ...pagination,
  75. };
  76. return (
  77. <PageContainer>
  78. <div>
  79. <Card>
  80. <Form form={form} layout="inline" onFinish={onFinish}>
  81. <Form.Item name="name" label="角色名称">
  82. <Input placeholder="请输入角色名称" />
  83. </Form.Item>
  84. <Form.Item style={{ marginBottom: '10px' }}>
  85. <Space>
  86. <Button type="primary" htmlType="submit">
  87. <SearchOutlined />
  88. 查询
  89. </Button>
  90. <Button htmlType="button" onClick={onReset}>
  91. <ReloadOutlined />
  92. 重置
  93. </Button>
  94. </Space>
  95. </Form.Item>
  96. </Form>
  97. <Button htmlType="button" type="primary" style={{ margin: '20px 0' }} onClick={onAdd}>
  98. <PlusCircleOutlined />
  99. 新增角色
  100. </Button>
  101. <Table
  102. columns={columns}
  103. dataSource={dataList}
  104. rowKey={(record) => record.record_id}
  105. pagination={paginationProps}
  106. loading={loading}
  107. onChange={tableChange}
  108. />
  109. </Card>
  110. </div>
  111. </PageContainer>
  112. );
  113. };
  114. export default RoleManagement;