#
luxiaotao1123
2024-02-15 29d8ea5199ae5ee6a2bb21cdd5a78664f16e0902
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
import React from 'react';
import { Input, Button, Space, Select } from 'antd';
 
const NONE_OPTION = -9999;
 
const TextFilter = (props) => {
    return (
        <div style={{ padding: 8 }}>
            <Input
                style={{ width: 188, marginBottom: 8, display: 'block' }}
                placeholder="请输入"
                value={props.selectedKeys[0]}
                onChange={e => {
                    props.setSelectedKeys(e.target.value ? [e.target.value] : [])
                }}
            />
            <Space>
                <Button
                    type="primary"
                    onClick={() => {
                        props.confirm();
                        props.setSearchParam(prevState => ({
                            ...prevState,
                            [props.name]: props.selectedKeys[0]
                        }));
                        props.actionRef.current?.reload();
                    }}
                    size="small"
                    style={{ width: 90 }}
                >
                    确定
                </Button>
                <Button
                    onClick={() => props.clearFilters && props.clearFilters()}
                    size="small"
                    style={{ width: 90 }}
                >
                    重置
                </Button>
            </Space>
        </div>
    );
}
 
const SelectFilter = (props) => {
    const [currentOption, setCurrentOption] = React.useState();
 
    return (
        <div style={{ padding: 8 }}>
            <div>
                <Select
                    style={{ width: 188, marginBottom: 8, display: 'block' }}
                    placeholder="请选择"
                    value={currentOption === NONE_OPTION ? undefined : currentOption}
                    onChange={value => {
                        setCurrentOption(value)
                        props.setSelectedKeys(value !== undefined && value !== null ? [value] : []);
                    }}
                >
                    {props.data.map(item => (
                        <Select.Option key={item.value} value={item.value}>
                            {item.label}
                        </Select.Option>
                    ))}
                </Select>
            </div>
            <Space>
                <Button
                    type="primary"
                    onClick={() => {
                        props.confirm();
                        if (currentOption === NONE_OPTION) {
                            props.setSearchParam(prevState => {
                                const state = { ...prevState };
                                delete state[props.name];
                                return state;
                            })
                        } else {
                            props.setSearchParam(prevState => ({
                                ...prevState,
                                [props.name]: currentOption
                            }));
                        }
                        props.actionRef.current?.reload();
                    }}
                    size="small"
                    style={{ width: 90 }}
                >
                    确定
                </Button>
                <Button
                    onClick={() => {
                        setCurrentOption(NONE_OPTION)
                        props.setSelectedKeys([]);
                        props.clearFilters();
                    }}
                    size="small"
                    style={{ width: 90 }}
                >
                    重置
                </Button>
            </Space>
        </div>
    );
}
 
export { TextFilter, SelectFilter };