|
| 1 | +import React, { useRef, memo } from 'react'; |
| 2 | +import { Select, Row, Col, Form, Input, Button } from 'tdesign-react'; |
| 3 | +import { AddIcon, DeleteIcon } from 'tdesign-icons-react'; |
| 4 | +import { FormInstanceFunctions, SubmitContext } from 'tdesign-react/es/form/type'; |
| 5 | +import Permission from 'components/Permission'; |
| 6 | +import { WHITELIST_OPTIONS } from '../../../../constants'; |
| 7 | + |
| 8 | +const { FormItem } = Form; |
| 9 | + |
| 10 | +export type FormValueType = { |
| 11 | + name?: string; |
| 12 | + word?: string; |
| 13 | +}; |
| 14 | + |
| 15 | +export type SearchFormProps = { |
| 16 | + onSubmit?: (values: FormValueType) => void; |
| 17 | + onCancel?: () => void; |
| 18 | + onCreate?: () => void; |
| 19 | + onDelete?: () => void; |
| 20 | + deleteLoading?: boolean; |
| 21 | +}; |
| 22 | + |
| 23 | +const SearchForm: React.FC<SearchFormProps> = (props) => { |
| 24 | + const formRef = useRef<FormInstanceFunctions>(); |
| 25 | + const onSubmit = (e: SubmitContext) => { |
| 26 | + if (e.validateResult === true) { |
| 27 | + const params = formRef?.current?.getFieldsValue?.(true); |
| 28 | + if (props.onSubmit) { |
| 29 | + props.onSubmit({ ...params }); |
| 30 | + } |
| 31 | + } |
| 32 | + }; |
| 33 | + |
| 34 | + const onReset = () => { |
| 35 | + if (props.onCancel) { |
| 36 | + props.onCancel(); |
| 37 | + } |
| 38 | + }; |
| 39 | + |
| 40 | + const onCreate = () => { |
| 41 | + if (props.onCreate) { |
| 42 | + props.onCreate(); |
| 43 | + } |
| 44 | + }; |
| 45 | + |
| 46 | + const onDelete = () => { |
| 47 | + if (props.onDelete) { |
| 48 | + props.onDelete(); |
| 49 | + } |
| 50 | + }; |
| 51 | + |
| 52 | + return ( |
| 53 | + <div className='list-common-table-query'> |
| 54 | + <Form ref={formRef} onSubmit={onSubmit} onReset={onReset} labelWidth={80} colon> |
| 55 | + <Row> |
| 56 | + <Col flex='2'> |
| 57 | + <Row gutter={[16, 16]}> |
| 58 | + <Col span={6}> |
| 59 | + <FormItem label='分类' name='category'> |
| 60 | + <Select options={WHITELIST_OPTIONS} placeholder='请选择分类' /> |
| 61 | + </FormItem> |
| 62 | + </Col> |
| 63 | + <Col span={6}> |
| 64 | + <FormItem label='授权资源' name='resource'> |
| 65 | + <Input placeholder='请输入资源' clearable /> |
| 66 | + </FormItem> |
| 67 | + </Col> |
| 68 | + </Row> |
| 69 | + </Col> |
| 70 | + <Col> |
| 71 | + <Permission btn='system.whitelist.read'> |
| 72 | + <Button theme='primary' type='submit' style={{ marginLeft: '10px' }}> |
| 73 | + 查询 |
| 74 | + </Button> |
| 75 | + </Permission> |
| 76 | + <Permission btn='system.whitelist.read'> |
| 77 | + <Button type='reset' variant='base' theme='default' style={{ marginLeft: '8px' }}> |
| 78 | + 重置 |
| 79 | + </Button> |
| 80 | + </Permission> |
| 81 | + <Permission btn='system.whitelist.create'> |
| 82 | + <Button theme='primary' onClick={onCreate} icon={<AddIcon />} style={{ marginLeft: '8px' }}> |
| 83 | + 新建 |
| 84 | + </Button> |
| 85 | + </Permission> |
| 86 | + <Permission btn='system.whitelist.delete'> |
| 87 | + <Button |
| 88 | + theme='danger' |
| 89 | + loading={props.deleteLoading} |
| 90 | + onClick={onDelete} |
| 91 | + icon={<DeleteIcon />} |
| 92 | + style={{ marginLeft: '8px' }} |
| 93 | + > |
| 94 | + 删除 |
| 95 | + </Button> |
| 96 | + </Permission> |
| 97 | + </Col> |
| 98 | + </Row> |
| 99 | + </Form> |
| 100 | + </div> |
| 101 | + ); |
| 102 | +}; |
| 103 | + |
| 104 | +export default memo(SearchForm); |
0 commit comments