修复菜单bug

This commit is contained in:
何童崇 2022-03-17 17:43:40 +08:00
parent 7318922eaf
commit 53f531a68a
4 changed files with 86 additions and 93 deletions

View File

@ -6,60 +6,41 @@ const { SubMenu } = Menu;
export default (props) => {
const { current_user, children, history, location: { pathname } } = props;
const { current_user, children, history, menuList, location: { pathname } } = props;
const setting = (localStorage.chromesetting && JSON.parse(localStorage.chromesetting)) || {};
const urlConfig = JSON.parse(localStorage.menuList) || [];
// import urlConfig from "./config";
console.log('urlConfig', urlConfig);
console.log(props);
const [openKeys, setOpenKeys] = useState();
const [openKeys, setOpenKeys] = useState([]);
const [current, setCurrent] = useState();
const [keyPath, setKeyPath] = useState();
const [acitve, setActive] = useState({});
const [titleObj,setTitleObj] =useState({});
const [locationObj, setLocationObj] = useState({});
const [parentKeyObj,setParentKeyObj] =useState({});
const [allRouter,setAllRouter] =useState([]);
const [rootSubmenuKeys,setRootSubmenuKeys] =useState([]);
const titleObjNew = {};
const locationObjNew = {};
const parentKeyObjNew = {};
const allRouterNew = [];
const rootSubmenuKeysNew = [];
const titleObj = {};
const locationObj = {};
const parentKeyObj = {};
const allRouter = [];
const rootSubmenuKeys = [];
function titleFun(menus) {
menus.forEach(i => {
titleObjNew[i.key] = i.title;
locationObjNew[i.location] = i;
i.location && allRouterNew.push(i.location);
!i.parentKey && rootSubmenuKeysNew.push(i.key);
titleObj[i.key] = i.title;
locationObj[i.location] = i;
i.key = i.key + '';
i.parentKey = i.parentKey + '';
i.location && allRouter.push(i.location);
i.parentKey=='0' && rootSubmenuKeys.push(i.key);
if (Array.isArray(i.children) && i.children.length > 0) {
titleFun(i.children);
i.parentKey && (parentKeyObjNew[i.key] = i.parentKey);
i.parentKey && (parentKeyObj[i.key] = i.parentKey + '');
}
})
}
useEffect(()=>{
urlConfig.length && titleFun(urlConfig);
console.log(urlConfig);
// setTitleObj(titleObjNew);
// setLocationObj(locationObjNew);
// setParentKeyObj(parentKeyObjNew);
// setAllRouter(allRouterNew);
// setRootSubmenuKeys(rootSubmenuKeysNew);
},[urlConfig]);
menuList.length && titleFun(menuList);
useEffect(() => {
sessionStorage.setItem("current_user", JSON.stringify(current_user));
}, [current_user.login]);
useEffect(() => {
if (locationObj[pathname]) {
setCurrent(locationObj[pathname] ? [locationObj[pathname].key] : []);
@ -70,13 +51,13 @@ export default (props) => {
parentKeyObj[myKey] && defaultOpenKeys.push(parentKeyObj[myKey]);
setActive(locationObj[pathname]);
setOpenKeys(defaultOpenKeys);
console.log('defaultOpenKeys');
console.log(defaultOpenKeys);
}
}, [locationObj[pathname]])
function handleClick(e) {
console.log(e.item);
setCurrent([e.key]);
setKeyPath(e.keyPath.reverse());
}
@ -110,7 +91,6 @@ export default (props) => {
}
function head(keyPath) {
console.log(titleObj);
return keyPath ? keyPath.map((i, index) => {
return <span key={index}>{titleObj[i]}{index !== keyPath.length - 1 && ' / '}</span>
}) : <span></span>
@ -125,6 +105,9 @@ export default (props) => {
}
function onOpenChange(newOpenKeys) {
console.log(1111111111111111111111111111)
console.log(newOpenKeys);
console.log(rootSubmenuKeys);
const latestOpenKey = newOpenKeys.find(key => openKeys.indexOf(key) === -1);
if (rootSubmenuKeys.indexOf(latestOpenKey) === -1) {
setOpenKeys(newOpenKeys);
@ -139,12 +122,17 @@ export default (props) => {
//
if (allRouter.includes(historyLocation.pathname)) {
setCurrent([locationObj[historyLocation.pathname].key]);
setKeyPath([locationObj[pathname].parentKey, locationObj[pathname].key])
setKeyPath([locationObj[pathname].parentKey, locationObj[pathname].key]);
}
})
}, [history]);
console.log(acitve);
console.log(1111111);
console.log(rootSubmenuKeys);
console.log(menuList);
return (
<Fragment>
<div className="layouts">
@ -155,7 +143,7 @@ export default (props) => {
onOpenChange={onOpenChange}
openKeys={openKeys}
>
{urlConfig.length && getMenuList(urlConfig)}
{menuList.length && getMenuList(menuList)}
</Menu>
</div>
<div className="managements">

View File

@ -3,8 +3,8 @@ import javaFetch from '../javaFetch';
let settings=localStorage.chromesetting&&JSON.parse(localStorage.chromesetting);
// let actionUrl = settings && settings.api_urls? settings.api_urls.task :'https://task.osredm.com';
let actionUrl = 'http://10.47.38.60:8088'
let actionUrl = settings && settings.api_urls? settings.api_urls.task :'https://task.osredm.com';
// let actionUrl = 'http://10.47.38.60:8088'
const service = javaFetch(actionUrl);
export const httpUrl = actionUrl;

View File

@ -54,18 +54,10 @@ class NewHeader extends Component {
settings: null,
goshowqqgtounp: false,
visiblemyss: false,
isExpert: false,
visible:false, //浮动消息框展示控制
}
}
componentDidMount() {
getUserInfo().then(response =>{
// response && this.setState({isExpert: response.data && response.data.expert});
if(response){
this.setState({isExpert: response.data && response.data.expert});
localStorage.setItem('menuList', JSON.stringify(response.data.menuNodes));
}
});
// this.getAppdata();
this.geturlsdata();
window._header_componentHandler = this;

View File

@ -3,7 +3,7 @@ import Header from '../../forge/Head/Header';
import NewHeader from './NewHeader';
import NewFooter from './NewFooter';
import { downloadFile } from 'educoder';
import { getCurrentExpert } from 'src/military/expert/api';
import { getCurrentExpert, getUserInfo } from 'src/military/expert/api';
import axios from 'axios';
import { Spin } from 'antd';
import './TPMIndex.css';
@ -28,13 +28,14 @@ export function TPMIndexHOC(WrappedComponent, headFoot) {
dataquerys: {},
isloginCancel: undefined,
mygetHelmetapi: null,
giteaVisible:false,
email:undefined,
completeProfile:false,
showCP:false,
showNotice:true,
giteaVisible: false,
email: undefined,
completeProfile: false,
showCP: false,
showNotice: true,
gopage: undefined,
Footerdown: undefined,
menuList:[],
}
}
@ -158,11 +159,11 @@ export function TPMIndexHOC(WrappedComponent, headFoot) {
fetchUsers = () => {
if (this.props.match.path === "/") {
this.setState({
publicNav:true
publicNav: true
})
}else{
} else {
this.setState({
publicNav:false
publicNav: false
})
}
let url = `/users/get_user_info.json`;
@ -171,21 +172,21 @@ export function TPMIndexHOC(WrappedComponent, headFoot) {
this.initCommonState(response.data)
this.setState({
tpmLoading: false,
completeProfile:response.data.profile_completed
completeProfile: response.data.profile_completed
})
if(response.data && response.data.login){
if(response.data.need_edit_info){
if (response.data && response.data.login) {
if (response.data.need_edit_info) {
this.setState({
giteaVisible:true,
email:response.data.email
giteaVisible: true,
email: response.data.email
})
}
}
if(response.data && response.data.login){
if(response.data.need_edit_info){
if (response.data && response.data.login) {
if (response.data.need_edit_info) {
this.setState({
giteaVisible:true,
email:response.data.email
giteaVisible: true,
email: response.data.email
})
}
}
@ -195,7 +196,7 @@ export function TPMIndexHOC(WrappedComponent, headFoot) {
// 考虑到以后部分系统不会用到专家评审系统所以这里没有使用Promise.All
getCurrentExpert().then(res => {
if(res){
if (res) {
let isExpert = false;
let expertId = '';
let expertDraft = false;
@ -218,6 +219,18 @@ export function TPMIndexHOC(WrappedComponent, headFoot) {
}).catch((error) => {
console.log(error)
});
getUserInfo().then(response => {
// response && this.setState({isExpert: response.data && response.data.expert});
if (response) {
// this.setState({ isExpert: response.data && response.data.expert });
// localStorage.setItem('menuList', JSON.stringify(response.data.menuNodes));
this.setState({menuList:response.data.menuNodes})
}
}).catch((error) => {
console.log(error)
});
}
}).catch((error) => {
console.log(error)
@ -244,55 +257,55 @@ export function TPMIndexHOC(WrappedComponent, headFoot) {
return this.state.current_user && this.state.current_user.login != ''
}
onOk =(values)=>{
onOk = (values) => {
let url = `/users/sync_user_info.json`;
const { current_user } = this.state;
axios.post(url,{
login:current_user && current_user.login,
axios.post(url, {
login: current_user && current_user.login,
...values
}).then(result=>{
if(result && result.data && result.data.status === 0){
}).then(result => {
if (result && result.data && result.data.status === 0) {
this.setState({
giteaVisible:false,
email:undefined
giteaVisible: false,
email: undefined
})
window.location.reload();
}
}).catch(error=>{})
}).catch(error => { })
}
hideSystemNotice=()=>{
hideSystemNotice = () => {
this.setState({
showNotice:false
showNotice: false
})
}
showCompeleteDialog=()=>{
showCompeleteDialog = () => {
this.setState({
showCP:true
showCP: true
})
}
render() {
let { isRender , current_user , giteaVisible , email , completeProfile , showCP , showNotice , publicNav , mygetHelmetapi ,Footerdown} = this.state;
let { isRender, current_user, giteaVisible, email, completeProfile, showCP, showNotice, publicNav, mygetHelmetapi, Footerdown } = this.state;
const common = {
showLoginDialog: this.showLoginDialog,
checkIfLogin: this.checkIfLogin,
resetUserInfo:this.fetchUsers,
showCompeleteDialog:this.showCompeleteDialog
resetUserInfo: this.fetchUsers,
showCompeleteDialog: this.showCompeleteDialog
};
return (
<div className="indexHOC">
<SystemNotice
<SystemNotice
showNotice={showNotice}
system_notification={mygetHelmetapi && mygetHelmetapi.system_notification}
history={this.props.history}
system_notification={mygetHelmetapi && mygetHelmetapi.system_notification}
history={this.props.history}
login={current_user && current_user.login}
hideSystemNotice={this.hideSystemNotice}
/>
<EducoderAccount visible={giteaVisible} email={email} onOk={this.onOk}/>
<ProfileModal
visible={!completeProfile && showCP}
onCancel={()=>{this.setState({showCP:false})}}
<EducoderAccount visible={giteaVisible} email={email} onOk={this.onOk} />
<ProfileModal
visible={!completeProfile && showCP}
onCancel={() => { this.setState({ showCP: false }) }}
history={this.props.history}
/>
{isRender === true ? <LoginDialog
@ -306,7 +319,7 @@ export function TPMIndexHOC(WrappedComponent, headFoot) {
size="large" tip={this._gLoadingTip || "加载中..."}
>
<div className="newContainer newContainers">
{!publicNav && <div style={{height:"70px"}}></div> }
{!publicNav && <div style={{ height: "70px" }}></div>}
{
current_user &&
<WrappedComponent initCommonState={(user) => this.initCommonState(user)}