顶部导航栏搜索框还原

This commit is contained in:
谢思 2021-11-18 17:08:03 +08:00
parent 4e18d13b6b
commit fe0fab7b61
2 changed files with 35 additions and 19 deletions

View File

@ -1,21 +1,41 @@
import React, { useState } from "react";
import { Input} from "antd";
import './Component.scss';
import { Input ,notification} from "antd";
const { Search } = Input;
export default ({history}) => {
const [searchValue, setSearchValue] = useState("");
const [openSearch, setOpenSearch] = useState(false);
function onGlobalSearch(e) {
window.location.href = `/search?value=${e.target.value}`;
function onGlobalSearch(value) {
history.push('/search?value=' + value);
// window.location.href = `search?value=` + value;
// history.push({
// pathname:'/search',
// state:value
// })
}
return (
<React.Fragment>
<div className="headSerach aboutSubTitle" onBlur={()=>{setTimeout(() => {
setSearchValue("");
}, 500)}}>
<i className = "iconfont icon-bianzu11 font-15" onClick={()=>onGlobalSearch({target:{value:searchValue}})}></i>
<Input placeholder="请输入搜索关键字" onPressEnter={onGlobalSearch} onChange={(value)=>setSearchValue(value.target.value)} value={searchValue}></Input>
</div>
{
openSearch ?
<div
onBlur={() => {
setTimeout(() => {
setOpenSearch(false)
}, 500)
}}
>
<Search placeholder="请输入搜索关键字"
className={`search-input mr20`}
onSearch={onGlobalSearch}
autoFocus={true}
style={{width:'260px'}}
/>
</div>
:
<i className="iconfont icon-sousuo font-18 ml30" onClick={() => {
setOpenSearch(true)
}} />
}
</React.Fragment>
)
};

View File

@ -34,14 +34,10 @@ function Login(props){
} else {
//
cookie.save('autologin',values.remember);
if(search){
const searchParams = new URLSearchParams(search.substring(1));
const goPage = searchParams.get("go_page");
//
goPage && (window.location.href = goPage);
return;
}
window.location.href = "/"+response.data.login;
const searchParams = new URLSearchParams(search.substring(1));
const goPage = searchParams.get("go_page");
//
window.location.href = goPage ? goPage : `/${response.data.login}`
}
}).catch((error) => {
console.log('error',error);