修改search校验,同页搜索问题
This commit is contained in:
parent
681d0b17e3
commit
b38cdd4bb3
|
@ -24,7 +24,7 @@ export default ({history}) => {
|
||||||
}, 500)
|
}, 500)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Search placeholder="请输入项目关键字"
|
<Search placeholder="请输入搜索关键字"
|
||||||
className={`search-input mr20`}
|
className={`search-input mr20`}
|
||||||
onSearch={onGlobalSearch}
|
onSearch={onGlobalSearch}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
|
|
|
@ -36,15 +36,20 @@ const GlobalSearch = ({ location, showNotification, history }) => {
|
||||||
const [totalType4, setTotalType4] = useState(0);
|
const [totalType4, setTotalType4] = useState(0);
|
||||||
const [totalType5, setTotalType5] = useState(0);
|
const [totalType5, setTotalType5] = useState(0);
|
||||||
|
|
||||||
|
const [ref, setRef] = useState(undefined);
|
||||||
|
const [focus, setFocus] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setTerm(defaultValue);
|
|
||||||
}, defaultValue)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
searchDataList();
|
searchDataList();
|
||||||
}, [type, page, term, forcesearch]);
|
}, [type, page, term, forcesearch]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (ref) {
|
||||||
|
ref && ref.input.input.focus();
|
||||||
|
}
|
||||||
|
}, [focus])
|
||||||
|
|
||||||
|
|
||||||
function searchFun(val) {
|
function searchFun(val) {
|
||||||
setTerm(val);
|
setTerm(val);
|
||||||
|
@ -55,7 +60,8 @@ const GlobalSearch = ({ location, showNotification, history }) => {
|
||||||
function searchDataList() {
|
function searchDataList() {
|
||||||
const url = https + '/search';
|
const url = https + '/search';
|
||||||
if (!term) {
|
if (!term) {
|
||||||
showNotification('请输入关键字');
|
// showNotification('请输入关键字');
|
||||||
|
setFocus(focus + 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
axios.defaults.withCredentials = true;
|
axios.defaults.withCredentials = true;
|
||||||
|
@ -109,9 +115,12 @@ const GlobalSearch = ({ location, showNotification, history }) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
history.listen(historyLocation => {
|
history.listen(historyLocation => {
|
||||||
setSearchValue(historyLocation.search.split("=")[1] || "");
|
setSearchValue(historyLocation.search.split("=")[1] || "");
|
||||||
|
setTerm(historyLocation.search.split("=")[1] || "");
|
||||||
})
|
})
|
||||||
}, [history]);
|
}, [history]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="suit-main clearfix">
|
<div className="suit-main clearfix">
|
||||||
<div className="search-head">
|
<div className="search-head">
|
||||||
|
@ -119,14 +128,16 @@ const GlobalSearch = ({ location, showNotification, history }) => {
|
||||||
<Row className="search-box">
|
<Row className="search-box">
|
||||||
<Col xs={20} sm={16} lg={13} >
|
<Col xs={20} sm={16} lg={13} >
|
||||||
<Search
|
<Search
|
||||||
placeholder="输入关键字进行搜索"
|
placeholder="请输入搜索关键字"
|
||||||
enterButton="搜索"
|
enterButton="搜索"
|
||||||
size="large"
|
size="large"
|
||||||
onSearch={searchFun}
|
onSearch={searchFun}
|
||||||
className="global-search"
|
className={{ 'global-search': true, "required-search": !searchValue }}
|
||||||
value={searchValue}
|
value={searchValue}
|
||||||
onChange={(e) => { setSearchValue(e.target.value) }}
|
onChange={(e) => { setSearchValue(e.target.value) }}
|
||||||
|
ref={(el) => setRef(el)}
|
||||||
/>
|
/>
|
||||||
|
{!searchValue && <span className="ant-form-explain">请输入搜索关键字</span>}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
@ -232,7 +243,7 @@ const GlobalSearch = ({ location, showNotification, history }) => {
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default SnackbarHOC()(TPMIndexHOC(GlobalSearch));
|
export default SnackbarHOC()(TPMIndexHOC(GlobalSearch));
|
||||||
|
|
|
@ -7,12 +7,19 @@
|
||||||
width: 1200px;
|
width: 1200px;
|
||||||
height: 110px;
|
height: 110px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
.ant-form-explain{
|
||||||
|
color: #f5222d;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.global-search {
|
.global-search {
|
||||||
margin-top: 40px;
|
margin-top: 40px;
|
||||||
}
|
}
|
||||||
|
.required-search{
|
||||||
|
.ant-input{
|
||||||
|
border-color: #f5222d !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
.ant-tabs-top {
|
.ant-tabs-top {
|
||||||
background: #eef2f5;
|
background: #eef2f5;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue