Commit 3f27b99a authored by 邓晓峰's avatar 邓晓峰

feat: 添加全局菜单搜索

parent 47a9c1b6
Pipeline #34808 passed with stages
in 29 minutes 32 seconds
...@@ -201,7 +201,9 @@ const GlobalHeaderRight = props => { ...@@ -201,7 +201,9 @@ const GlobalHeaderRight = props => {
<HeaderSearch <HeaderSearch
className={`${styles.action} ${styles.search} ${styles.extendsearch}`} className={`${styles.action} ${styles.search} ${styles.extendsearch}`}
placeholder={intl.formatMessage({id:'component.search.menu.placeholder'})} placeholder={intl.formatMessage({id:'component.search.menu.placeholder'})}
offset="46px"
defaultValue="" defaultValue=""
mode="tiled"
options={options} options={options}
{...props} {...props}
onSelect={handleSelect} onSelect={handleSelect}
......
This diff is collapsed.
...@@ -10,7 +10,8 @@ import useMergeValue from 'use-merge-value'; ...@@ -10,7 +10,8 @@ import useMergeValue from 'use-merge-value';
import { SearchOutlined } from '@ant-design/icons'; import { SearchOutlined } from '@ant-design/icons';
import styles from './index.less'; import styles from './index.less';
import SearchPanel from './panel'; import SearchPanel from './Panel';
import ExtendPanel from './ExtendPanel';
const HeaderSearch = props => { const HeaderSearch = props => {
const { const {
...@@ -162,7 +163,8 @@ const HeaderSearch = props => { ...@@ -162,7 +163,8 @@ const HeaderSearch = props => {
prefix={<SearchOutlined className="site-form-item-icon" />} prefix={<SearchOutlined className="site-form-item-icon" />}
/> />
</div> </div>
<SearchPanel {
props.mode && props.mode === 'tiled' ? <ExtendPanel
value={keyword} value={keyword}
{...props} {...props}
target={wrapperRef} target={wrapperRef}
...@@ -171,7 +173,28 @@ const HeaderSearch = props => { ...@@ -171,7 +173,28 @@ const HeaderSearch = props => {
className={focus ? styles.active : styles.hidden} className={focus ? styles.active : styles.hidden}
style={{ style={{
left: `${targetOffset}px`, left: `${targetOffset}px`,
top: isShowWidget ? '42px' : '52px', top: isShowWidget ? '42px' : props.offset || '52px',
}}
onEsc={onEsc}
onNavUp={onNavUp}
onNavDown={onNavDown}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onWillSearch={onWillSearch}
onFocusChange={onFocusChange}
willSearch={willSearch}
onClose={onClose}
console={willMenu}
/>: <SearchPanel
value={keyword}
{...props}
target={wrapperRef}
inputRef={inputRef}
test={focus}
className={focus ? styles.active : styles.hidden}
style={{
left: `${targetOffset}px`,
top: isShowWidget ? '42px' : props.offset || '52px',
}} }}
onEsc={onEsc} onEsc={onEsc}
onNavUp={onNavUp} onNavUp={onNavUp}
...@@ -184,6 +207,8 @@ const HeaderSearch = props => { ...@@ -184,6 +207,8 @@ const HeaderSearch = props => {
onClose={onClose} onClose={onClose}
console={willMenu} console={willMenu}
/> />
}
</div> </div>
); );
}; };
......
...@@ -254,13 +254,13 @@ const BasicLayout = props => { ...@@ -254,13 +254,13 @@ const BasicLayout = props => {
const [childrenRoutes, setChildrenRoutes] = useState([]); const [childrenRoutes, setChildrenRoutes] = useState([]);
const [selectedKeys, setSelectedKeys] = useState([]); const [selectedKeys, setSelectedKeys] = useState([]);
const [tabActiveKey, setTabActiveKey] = useState("1"); const [tabActiveKey, setTabActiveKey] = useState("1");
// const [currentRoutes, setCurrentRoutes] = useState([]);
const [siteAction, setSiteAction] = useState( const [siteAction, setSiteAction] = useState(
() => new Site(props, setSiteLoading), () => new Site(props, setSiteLoading),
); );
const basename = getBaseName(); const basename = getBaseName();
const history = useHistory(); const history = useHistory();
const currentRoutes = props.route.routes[props.currentMenuIndex]; let currentRoutes = props.route.routes[props.currentMenuIndex]
useEffect(() => { useEffect(() => {
const initSelectRoute = findPathByLeafId( const initSelectRoute = findPathByLeafId(
`${props.location.pathname}`, `${props.location.pathname}`,
...@@ -277,9 +277,15 @@ const BasicLayout = props => { ...@@ -277,9 +277,15 @@ const BasicLayout = props => {
currentChildrenRoute = initSelectRoute currentChildrenRoute = initSelectRoute
} }
let childrenName = currentChildrenRoute ? currentChildrenRoute.name: parentMenuName; let childrenName = currentChildrenRoute ? currentChildrenRoute.name: parentMenuName;
if(currentChildrenRoute.routes) {
setTabActiveKey(currentChildrenRoute.routes[0].path)
} else {
setTabActiveKey(currentChildrenRoute.path);
}
const initSelectIndex = currentRoutes.routes.findIndex(item => item.name === childrenName); const initSelectIndex = currentRoutes.routes.findIndex(item => item.name === childrenName);
setSelectIndex(initSelectIndex); setSelectIndex(initSelectIndex);
currentChildrenRoute && currentChildrenRoute.routes ? setChildrenRoutes(currentChildrenRoute.routes): setChildrenRoutes([currentChildrenRoute]) currentChildrenRoute && currentChildrenRoute.routes ? setChildrenRoutes(currentChildrenRoute.routes): setChildrenRoutes([currentChildrenRoute]);
} else { } else {
setChildrenRoutes([ setChildrenRoutes([
{ {
...@@ -291,6 +297,14 @@ const BasicLayout = props => { ...@@ -291,6 +297,14 @@ const BasicLayout = props => {
} }
}, []); }, []);
window.share && window.share.event && window.share.event.on('event:updateCurrentChildrenRoutes', ({currentPath, currentRoute, selectedIndex}) => {
currentRoute && currentRoute.parent && currentRoute.parent.routes ? setChildrenRoutes(currentRoute.parent.routes): setChildrenRoutes([currentRoute]);
setSelectIndex(selectedIndex);
setTabActiveKey(currentPath)
});
useEffect(() => { useEffect(() => {
siteAction.setGlobalConfig(props.global); siteAction.setGlobalConfig(props.global);
if (!Cookies.get('token')) { if (!Cookies.get('token')) {
...@@ -326,13 +340,10 @@ const BasicLayout = props => { ...@@ -326,13 +340,10 @@ const BasicLayout = props => {
window.share.event.on('updateSite', res => setCityData(res)); window.share.event.on('updateSite', res => setCityData(res));
return () => { return () => {
window.share.event.removeAllListeners('updateSite'); window.share.event.removeAllListeners('updateSite');
// sessionStorage.removeItem('tabNav')
// sessionStorage.removeItem('tabActiveKey')
}; };
}, []); }, []);
const handlerSecond = (item, index) => { const handlerSecond = (item, index) => {
let current = void 0; let current = void 0;
if(item && item.routes) { if(item && item.routes) {
setChildrenRoutes(item.routes); setChildrenRoutes(item.routes);
...@@ -341,9 +352,16 @@ const BasicLayout = props => { ...@@ -341,9 +352,16 @@ const BasicLayout = props => {
setChildrenRoutes([item]); setChildrenRoutes([item]);
current = item; current = item;
} }
setTabActiveKey("1"); setTabActiveKey(current.path);
window.history.pushState(null, '', `/civbase${current.path}`);
setSelectIndex(index); setSelectIndex(index);
if(current.routes) {
setSelectedKeys([current.routes[0].href]);
window.history.pushState(null, '', `/civbase${current.routes[0].path}`);
} else {
window.history.pushState(null, '', `/civbase${current.path}`);
}
} }
const handleToggleSystem = () => { const handleToggleSystem = () => {
...@@ -545,7 +563,7 @@ const BasicLayout = props => { ...@@ -545,7 +563,7 @@ const BasicLayout = props => {
</div> </div>
</div> </div>
<div className={layoutStyles['menu-item-children']} style={{width: collapse ? 'calc(100% - 46px)': 'calc(100% - 100px)'}}> <div className={layoutStyles['menu-item-children']} style={{width: collapse ? 'calc(100% - 46px)': 'calc(100% - 100px)'}}>
<Tabs activeKey={tabActiveKey} tabBarGutter={30} tabPosition="top" onTabClick={(event) => handleSelectMenuItem(event)}> <Tabs activeKey={tabActiveKey} defaultActiveKey={tabActiveKey} tabBarGutter={30} tabPosition="top" onTabClick={(event) => handleSelectMenuItem(event)}>
{childrenRoutes.map((item, index) => ( {childrenRoutes.map((item, index) => (
<> <>
<TabPane <TabPane
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment