From b016d1eb02dd09fd1ffcd24e4e6ddee72fd1b3d6 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 28 二月 2024 10:27:25 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/components/TableSearch/index.jsx | 105 +++++++++++++++++++++++++++++++++++-----------------
1 files changed, 71 insertions(+), 34 deletions(-)
diff --git a/zy-asrs-flow/src/components/TableSearch/index.jsx b/zy-asrs-flow/src/components/TableSearch/index.jsx
index 53d0d47..22c9019 100644
--- a/zy-asrs-flow/src/components/TableSearch/index.jsx
+++ b/zy-asrs-flow/src/components/TableSearch/index.jsx
@@ -1,18 +1,23 @@
import React from 'react';
import { Input, Button, Space, Select, DatePicker } from 'antd';
import Http from '@/utils/http';
+import moment from 'moment';
const NONE_OPTION = -9999;
+const DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const TextFilter = (props) => {
+ const [condition, setCondition] = React.useState('');
+
return (
<div style={{ padding: 8 }}>
<Input
style={{ width: 188, marginBottom: 8, display: 'block' }}
placeholder="璇疯緭鍏�"
- value={props.selectedKeys[0]}
+ value={condition}
onChange={e => {
- props.setSelectedKeys(e.target.value ? [e.target.value] : [])
+ props.setSelectedKeys(e.target.value ? [e.target.value] : []);
+ setCondition(e.target.value)
}}
/>
<Space>
@@ -20,10 +25,18 @@
type="primary"
onClick={() => {
props.confirm();
- props.setSearchParam(prevState => ({
- ...prevState,
- [props.name]: props.selectedKeys[0]
- }));
+ if (condition === '' || condition === null || condition === undefined) {
+ props.setSearchParam(prevState => {
+ const state = { ...prevState };
+ delete state[props.name];
+ return state;
+ })
+ } else {
+ props.setSearchParam(prevState => ({
+ ...prevState,
+ [props.name]: condition
+ }));
+ }
props.actionRef.current?.reload();
}}
size="small"
@@ -32,7 +45,19 @@
纭畾
</Button>
<Button
- onClick={() => props.clearFilters && props.clearFilters()}
+ onClick={() => {
+ setCondition('')
+ props.setSelectedKeys([]);
+ props.clearFilters()
+
+ props.confirm();
+ props.setSearchParam(prevState => {
+ const state = { ...prevState };
+ delete state[props.name];
+ return state;
+ })
+ props.actionRef.current?.reload();
+ }}
size="small"
style={{ width: 90 }}
>
@@ -94,6 +119,14 @@
setCurrentOption(NONE_OPTION)
props.setSelectedKeys([]);
props.clearFilters();
+
+ props.confirm();
+ props.setSearchParam(prevState => {
+ const state = { ...prevState };
+ delete state[props.name];
+ return state;
+ })
+ props.actionRef.current?.reload();
}}
size="small"
style={{ width: 90 }}
@@ -120,9 +153,9 @@
onChange={changeDates => {
setDates(changeDates);
if (changeDates && changeDates[0] && changeDates[1]) {
- const changeStartStr = changeDates[0]?.toISOString()
+ const changeStartStr = moment(changeDates[0]).format(DATE_FORMAT);
setStartDate(changeStartStr);
- const changeEndStr = changeDates[1]?.toISOString()
+ const changeEndStr = moment(changeDates[1]).format(DATE_FORMAT);
setEndDate(changeEndStr);
props.setSelectedKeys([changeStartStr + '-' + changeEndStr]);
}
@@ -158,6 +191,14 @@
setEndDate(null);
props.setSelectedKeys([]);
props.clearFilters();
+
+ props.confirm();
+ props.setSearchParam(prevState => {
+ const nextState = { ...prevState };
+ delete nextState[props.name + 'Range'];
+ return nextState;
+ });
+ props.actionRef.current?.reload();
}}
size="small"
>
@@ -173,32 +214,22 @@
const LinkFilter = (props) => {
const [currentOption, setCurrentOption] = React.useState();
const [options, setOptions] = React.useState([]);
-
+
const fetchData = async (value) => {
- const resp = await Http.doPostForm(`api/${props.name}/query`, { condition: value });
- return resp.data;
+ return await Http.doPostForm(`api/${props.major}/query`, { condition: value });
+ }
+
+ async function initOptions(value) {
+ const { data } = await fetchData(value);
+ setOptions(data);
}
React.useEffect(() => {
- async function init() {
- const data = await fetchData();
- setOptions(data);
- }
- init()
+ initOptions()
}, []);
- const handleSearch = async (value) => {
- console.log(value);
- const data = await fetchData(value);
- console.log(data);
- setOptions(data);
-
- setOptions([
- {
- label: '12',
- value: 'sadsa'
- }
- ]);
+ const handleSearch = (value) => {
+ initOptions(value)
}
return (
@@ -213,13 +244,10 @@
props.setSelectedKeys(value !== undefined && value !== null ? [value] : []);
}}
onSearch={handleSearch}
+ options={options.map(item => ({ value: item.value, label: item.label }))}
+ filterOption={false}
showSearch={true}
>
- {options.map(item => (
- <Select.Option key={item.value} value={item.value}>
- {item.label}
- </Select.Option>
- ))}
</Select>
</div>
<Space>
@@ -251,6 +279,15 @@
setCurrentOption(NONE_OPTION)
props.setSelectedKeys([]);
props.clearFilters();
+ initOptions()
+
+ props.confirm();
+ props.setSearchParam(prevState => {
+ const state = { ...prevState };
+ delete state[props.name];
+ return state;
+ })
+ props.actionRef.current?.reload();
}}
size="small"
style={{ width: 90 }}
--
Gitblit v1.9.1