diff --git a/src/forge/Component/HeadSearch.jsx b/src/forge/Component/HeadSearch.jsx index 088817238..15ba6d448 100644 --- a/src/forge/Component/HeadSearch.jsx +++ b/src/forge/Component/HeadSearch.jsx @@ -24,7 +24,7 @@ export default ({history}) => { }, 500) }} > - { 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 (
@@ -119,14 +128,16 @@ const GlobalSearch = ({ location, showNotification, history }) => { { setSearchValue(e.target.value) }} + ref={(el) => setRef(el)} /> + {!searchValue && 请输入搜索关键字}
@@ -232,7 +243,7 @@ const GlobalSearch = ({ location, showNotification, history }) => {
); - // } } + export default SnackbarHOC()(TPMIndexHOC(GlobalSearch)); diff --git a/src/modules/search/index.scss b/src/modules/search/index.scss index 3617ed6f7..e3af7834e 100644 --- a/src/modules/search/index.scss +++ b/src/modules/search/index.scss @@ -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; }