修改search校验,同页搜索问题

This commit is contained in:
何童崇 2021-06-10 17:05:49 +08:00
parent 681d0b17e3
commit b38cdd4bb3
3 changed files with 27 additions and 9 deletions

View File

@ -24,7 +24,7 @@ export default ({history}) => {
}, 500)
}}
>
<Search placeholder="请输入项目关键字"
<Search placeholder="请输入搜索关键字"
className={`search-input mr20`}
onSearch={onGlobalSearch}
autoFocus={true}

View File

@ -36,15 +36,20 @@ const GlobalSearch = ({ location, showNotification, history }) => {
const [totalType4, setTotalType4] = useState(0);
const [totalType5, setTotalType5] = useState(0);
const [ref, setRef] = useState(undefined);
const [focus, setFocus] = useState(0);
useEffect(() => {
setTerm(defaultValue);
}, defaultValue)
useEffect(() => {
searchDataList();
}, [type, page, term, forcesearch]);
useEffect(() => {
if (ref) {
ref && ref.input.input.focus();
}
}, [focus])
function searchFun(val) {
setTerm(val);
@ -55,7 +60,8 @@ const GlobalSearch = ({ location, showNotification, history }) => {
function searchDataList() {
const url = https + '/search';
if (!term) {
showNotification('请输入关键字');
// showNotification('');
setFocus(focus + 1);
return;
}
axios.defaults.withCredentials = true;
@ -109,9 +115,12 @@ const GlobalSearch = ({ location, showNotification, history }) => {
useEffect(() => {
history.listen(historyLocation => {
setSearchValue(historyLocation.search.split("=")[1] || "");
setTerm(historyLocation.search.split("=")[1] || "");
})
}, [history]);
return (
<div className="suit-main clearfix">
<div className="search-head">
@ -119,14 +128,16 @@ const GlobalSearch = ({ location, showNotification, history }) => {
<Row className="search-box">
<Col xs={20} sm={16} lg={13} >
<Search
placeholder="输入关键字进行搜索"
placeholder="输入搜索关键字"
enterButton="搜索"
size="large"
onSearch={searchFun}
className="global-search"
className={{ 'global-search': true, "required-search": !searchValue }}
value={searchValue}
onChange={(e) => { setSearchValue(e.target.value) }}
ref={(el) => setRef(el)}
/>
{!searchValue && <span className="ant-form-explain">请输入搜索关键字</span>}
</Col>
</Row>
</div>
@ -232,7 +243,7 @@ const GlobalSearch = ({ location, showNotification, history }) => {
</div>
);
// }
}
export default SnackbarHOC()(TPMIndexHOC(GlobalSearch));

View File

@ -7,12 +7,19 @@
width: 1200px;
height: 110px;
margin: 0 auto;
.ant-form-explain{
color: #f5222d;
}
}
.global-search {
margin-top: 40px;
}
.required-search{
.ant-input{
border-color: #f5222d !important;
}
}
.ant-tabs-top {
background: #eef2f5;
}