You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 4.2KB

10 kuukautta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons';
  2. import type { ActionType, ProColumns } from '@ant-design/pro-components';
  3. import {
  4. ProTable, TableDropdown, PageContainer, ModalForm, ProForm,
  5. ProFormDateRangePicker,
  6. ProFormSelect,
  7. ProFormText,
  8. } from '@ant-design/pro-components';
  9. import { Button, Dropdown, Space, Tag, Form } from 'antd';
  10. import { useRef, useState } from 'react';
  11. export const waitTimePromise = async (time: number = 100) => {
  12. return new Promise((resolve) => {
  13. setTimeout(() => {
  14. resolve(true);
  15. }, time);
  16. });
  17. };
  18. export const waitTime = async (time: number = 100) => {
  19. await waitTimePromise(time);
  20. };
  21. const columns: ProColumns[] = [
  22. {
  23. title: 'ID',
  24. dataIndex: 'id',
  25. },
  26. {
  27. title: '企业名称',
  28. dataIndex: 'name',
  29. },
  30. {
  31. title: '来源',
  32. dataIndex: 'state',
  33. },
  34. {
  35. title: '登录次数',
  36. dataIndex: 'app_id',
  37. },
  38. {
  39. title: 'ApiKey',
  40. dataIndex: 'api_key',
  41. },
  42. {
  43. title: 'SecretKey',
  44. dataIndex: 'secret_key',
  45. },
  46. {
  47. title: '操作',
  48. valueType: 'option',
  49. key: 'option',
  50. render: (text, record, _, action) => [
  51. <a
  52. key="editable"
  53. onClick={() => {
  54. action?.startEditable?.(record.id);
  55. }}
  56. >
  57. 编辑
  58. </a>,
  59. ],
  60. },
  61. ];
  62. export default () => {
  63. const [form] = Form.useForm<ProjectType.form>();
  64. const [data, setData] = useState([{id: 1}])
  65. return (
  66. <>
  67. <PageContainer>
  68. <ProTable
  69. dataSource={data}
  70. columns={columns}
  71. pagination={{
  72. pageSize: 5,
  73. onChange: (page) => console.log(page),
  74. }}
  75. toolBarRender={() => [
  76. <ModalForm<ProjectType.form>
  77. title="新增项目"
  78. trigger={
  79. <Button type="primary">
  80. <PlusOutlined />
  81. 新建表单
  82. </Button>
  83. }
  84. submitter={{
  85. render: (props, defaultDoms) => {
  86. return [
  87. <Button
  88. key="extra-reset"
  89. onClick={() => {
  90. props.reset();
  91. }}
  92. >
  93. 重置
  94. </Button>,
  95. ...defaultDoms,
  96. ];
  97. },
  98. }}
  99. form={form}
  100. autoFocusFirstInput
  101. modalProps={{
  102. destroyOnClose: true,
  103. onCancel: () => console.log('run'),
  104. }}
  105. submitTimeout={2000}
  106. onFinish={async (values) => {
  107. await waitTime(2000);
  108. console.log(values.name);
  109. return true;
  110. }}
  111. >
  112. <ProFormText
  113. name="name"
  114. label="项目名"
  115. placeholder="请输入项目名"
  116. />
  117. <ProFormSelect
  118. name="aip_id"
  119. label="选择百度接口"
  120. placeholder="请选择百度接口"
  121. />
  122. </ModalForm>
  123. ]}
  124. />
  125. </PageContainer>
  126. </>
  127. );
  128. };