#
luxiaotao1123
2024-02-15 333a2edeafc7ace144f3e3a005097174be6cda30
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import React from 'react';
import { Input, Button, Space, Select, DatePicker } from 'antd';
import moment from 'moment';
 
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>
    );
}
 
const DatetimeRangeFilter = (props) => {
    const [startDate, setStartDate] = React.useState(null);
    const [endDate, setEndDate] = React.useState(null);
 
    return (
        <div style={{ padding: 8 }}>
            <div>
                <Space direction="vertical" size={12}>
                    <DatePicker.RangePicker
                        showTime
                        onChange={dates => {
                            setStartDate(dates[0]?.toISOString());
                            setEndDate(dates[1]?.toISOString());
                        }}
                    />
                    <Space>
                        <Button
                            type="primary"
                            onClick={() => {
                                console.log(startDate, endDate);
                                props.confirm();
                                props.setSearchParam(prevState => ({
                                    ...prevState,
                                    [props.name]: [startDate, endDate]
                                }));
                                props.actionRef.current?.reload();
                            }}
                            size="small"
                        >
                            确定
                        </Button>
                        <Button
                            onClick={() => {
                                setStartDate(null);
                                setEndDate(null);
                                props.setSelectedKeys([]);
                                props.setSearchParam(prevState => {
                                    const nextState = { ...prevState };
                                    delete nextState[props.name];
                                    return nextState;
                                });
                                props.clearFilters();
                            }}
                            size="small"
                        >
                            重置
                        </Button>
                    </Space>
                </Space>
            </div>
        </div>
    );
}
 
 
export { TextFilter, SelectFilter, DatetimeRangeFilter };