forked from Gitlink/forgeplus-react
管理后台左侧菜单(未完)
This commit is contained in:
parent
da41f9582e
commit
7318922eaf
|
@ -3,13 +3,12 @@ import { Table, Pagination } from 'antd';
|
|||
import './index.scss';
|
||||
|
||||
export default (props) => {
|
||||
const { loading, dataSource, columns, handleRow, total, setCurPage, current, rowSelection, expandedRowRender, expandIconColumnIndex, expandIconAsCell, onShowSizeChange, showSizeChanger, pagination, scroll, indentSize } = props;
|
||||
const {handleRow, total, setCurPage, current, onShowSizeChange, showSizeChanger, pagination} = props;
|
||||
|
||||
return (
|
||||
<div className='pagination-table'>
|
||||
<Table
|
||||
{...props}
|
||||
rowKey={(row,i) => row.id || i}
|
||||
pagination={false}
|
||||
onRow={handleRow}
|
||||
/>
|
||||
|
|
|
@ -45,11 +45,10 @@ export async function menuList(parentId,params) {
|
|||
return res;
|
||||
}
|
||||
// 树形结构返回所有菜单列表
|
||||
export async function treeList(parentId,params) {
|
||||
export async function treeList() {
|
||||
let res = await fetch({
|
||||
url: `/api/menu/treeList`,
|
||||
method: 'get',
|
||||
params,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
@ -97,7 +96,7 @@ export async function deleteRole(roleId){
|
|||
return res;
|
||||
}
|
||||
|
||||
//为用户赋予菜单
|
||||
//为角色赋予菜单
|
||||
export async function allocMenu(roleId, menuIds){
|
||||
let res = await fetch({
|
||||
url: `/api/role/allocMenu?roleId=${roleId}&menuIds=${menuIds}`,
|
||||
|
@ -105,7 +104,7 @@ export async function allocMenu(roleId, menuIds){
|
|||
});
|
||||
return res;
|
||||
}
|
||||
//
|
||||
//通过角色id获取菜单列表
|
||||
export async function listMenu(roleId) {
|
||||
let res = await fetch({
|
||||
url: `/api/role/listMenu/${roleId}`,
|
||||
|
@ -128,4 +127,12 @@ export async function adminUserList() {
|
|||
method: 'get',
|
||||
});
|
||||
return res;
|
||||
}
|
||||
// 获取用户角色
|
||||
export async function getUserRole(adminId) {
|
||||
let res = await fetch({
|
||||
url: `/api/admin/role/${adminId}`,
|
||||
method: 'get',
|
||||
});
|
||||
return res;
|
||||
}
|
|
@ -1,48 +1,79 @@
|
|||
import React, { useState, useEffect, Fragment } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Menu } from "antd";
|
||||
import urlConfig from "./config";
|
||||
import "./index.scss";
|
||||
const { SubMenu } = Menu;
|
||||
|
||||
const titleObj = {};
|
||||
const locationObj = {};
|
||||
const parentKeyObj = {};
|
||||
const allRouter = [];
|
||||
const rootSubmenuKeys = [];
|
||||
function titleFun(menus) {
|
||||
menus.forEach(i => {
|
||||
titleObj[i.key] = i.title;
|
||||
locationObj[i.location] = i;
|
||||
i.location && allRouter.push(i.location);
|
||||
!i.parentKey && rootSubmenuKeys.push(i.key);
|
||||
if (Array.isArray(i.children) && i.children.length > 0) {
|
||||
titleFun(i.children);
|
||||
i.parentKey && (parentKeyObj[i.key] = i.parentKey);
|
||||
}
|
||||
})
|
||||
}
|
||||
titleFun(urlConfig);
|
||||
|
||||
export default (props) => {
|
||||
const { current_user, children, history, 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 [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 = [];
|
||||
|
||||
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);
|
||||
if (Array.isArray(i.children) && i.children.length > 0) {
|
||||
titleFun(i.children);
|
||||
i.parentKey && (parentKeyObjNew[i.key] = i.parentKey);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
useEffect(()=>{
|
||||
urlConfig.length && titleFun(urlConfig);
|
||||
console.log(urlConfig);
|
||||
// setTitleObj(titleObjNew);
|
||||
// setLocationObj(locationObjNew);
|
||||
// setParentKeyObj(parentKeyObjNew);
|
||||
// setAllRouter(allRouterNew);
|
||||
// setRootSubmenuKeys(rootSubmenuKeysNew);
|
||||
},[urlConfig]);
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
sessionStorage.setItem("current_user", JSON.stringify(current_user));
|
||||
}, [current_user.login]);
|
||||
|
||||
let initCurrent = locationObj[pathname] ? [locationObj[pathname].key] : [];
|
||||
let initKeyPath = locationObj[pathname] ? [locationObj[pathname].parentKey, locationObj[pathname].key] : [];
|
||||
|
||||
const defaultOpenKeys = [];
|
||||
const myKey = pathname && locationObj[pathname] && locationObj[pathname].parentKey;
|
||||
defaultOpenKeys.push(myKey ? myKey : "task");
|
||||
parentKeyObj[myKey] && defaultOpenKeys.push(parentKeyObj[myKey]);
|
||||
|
||||
const [openKeys, setOpenKeys] = useState(defaultOpenKeys);
|
||||
const [current, setCurrent] = useState(initCurrent);
|
||||
const [keyPath, setKeyPath] = useState(initKeyPath);
|
||||
const [acitve, setActive] = useState(locationObj[pathname] || {});
|
||||
useEffect(() => {
|
||||
if (locationObj[pathname]) {
|
||||
setCurrent(locationObj[pathname] ? [locationObj[pathname].key] : []);
|
||||
setKeyPath(locationObj[pathname] ? [locationObj[pathname].parentKey, locationObj[pathname].key] : []);
|
||||
const defaultOpenKeys = [];
|
||||
const myKey = pathname && locationObj[pathname] && locationObj[pathname].parentKey;
|
||||
defaultOpenKeys.push(myKey ? myKey : "task");
|
||||
parentKeyObj[myKey] && defaultOpenKeys.push(parentKeyObj[myKey]);
|
||||
setActive(locationObj[pathname]);
|
||||
setOpenKeys(defaultOpenKeys);
|
||||
}
|
||||
}, [locationObj[pathname]])
|
||||
|
||||
|
||||
|
||||
function handleClick(e) {
|
||||
console.log(e.item);
|
||||
|
@ -69,9 +100,9 @@ export default (props) => {
|
|||
} else {
|
||||
return (
|
||||
<Menu.Item title={item.title} key={item.key}>
|
||||
<Link to={item.location} onClick={() => { itemClick(item) }}>{item.title}</Link>
|
||||
{/* {item.urltype == "self" ? <Link target={item.target} to={item.location}>{item.title}</Link>
|
||||
: <a target={item.target} href={`${setting[item.urltype] + item.location}`}>{item.title}</a>} */}
|
||||
{/* <Link to={item.location} onClick={() => { itemClick(item) }}>{item.title}</Link> */}
|
||||
{item.location ? <Link to={item.location} onClick={() => { itemClick(item) }}>{item.title}</Link>
|
||||
: item.title}
|
||||
</Menu.Item>
|
||||
);
|
||||
}
|
||||
|
@ -79,9 +110,10 @@ export default (props) => {
|
|||
}
|
||||
|
||||
function head(keyPath) {
|
||||
return keyPath.map((i, index) => {
|
||||
console.log(titleObj);
|
||||
return keyPath ? keyPath.map((i, index) => {
|
||||
return <span key={index}>{titleObj[i]}{index !== keyPath.length - 1 && ' / '}</span>
|
||||
})
|
||||
}) : <span>无</span>
|
||||
}
|
||||
|
||||
function iframeLoad() {
|
||||
|
@ -99,7 +131,6 @@ export default (props) => {
|
|||
} else {
|
||||
setOpenKeys(latestOpenKey ? [latestOpenKey] : []);
|
||||
}
|
||||
console.log(newOpenKeys);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -113,8 +144,7 @@ export default (props) => {
|
|||
})
|
||||
}, [history]);
|
||||
|
||||
console.log(acitve.urltype);
|
||||
|
||||
console.log(acitve);
|
||||
return (
|
||||
<Fragment>
|
||||
<div className="layouts">
|
||||
|
@ -125,7 +155,7 @@ export default (props) => {
|
|||
onOpenChange={onOpenChange}
|
||||
openKeys={openKeys}
|
||||
>
|
||||
{getMenuList(urlConfig)}
|
||||
{urlConfig.length && getMenuList(urlConfig)}
|
||||
</Menu>
|
||||
</div>
|
||||
<div className="managements">
|
||||
|
|
|
@ -257,6 +257,7 @@ export default Form.create()(({ form}) => {
|
|||
<div className="center-content">
|
||||
<PaginationTable
|
||||
loading={loading}
|
||||
rowKey={row=> row.key}
|
||||
dataSource={dataList}
|
||||
columns={columns}
|
||||
total={total}
|
||||
|
|
|
@ -3,7 +3,8 @@ import javaFetch from '../javaFetch';
|
|||
|
||||
|
||||
let settings = localStorage.chromesetting && JSON.parse(localStorage.chromesetting);
|
||||
let actionUrl = settings && settings.api_urls && settings.api_urls.task ? settings.api_urls.task : 'https://task.osredm.com';
|
||||
// let actionUrl = settings && settings.api_urls && settings.api_urls.task ? settings.api_urls.task : 'https://task.osredm.com';
|
||||
let actionUrl = 'http://10.47.38.60:8088';
|
||||
const service = javaFetch(actionUrl);
|
||||
export const httpUrl = actionUrl;
|
||||
export const main_web_site_url = settings && settings.main_web_site_url;
|
||||
|
|
|
@ -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://111.8.36.180:8094'
|
||||
// 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;
|
||||
|
|
|
@ -648,7 +648,7 @@ export default Form.create()(({ form, showNotification, match, history, state })
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="center-content">
|
||||
<div className="center-content taskListCont">
|
||||
<PaginationTable
|
||||
loading={loading}
|
||||
rowKey={(row) => row.id}
|
||||
|
|
|
@ -206,7 +206,7 @@
|
|||
padding: 3px 8px;
|
||||
}
|
||||
}
|
||||
.center-content{
|
||||
.taskListCont{
|
||||
.publishMode{
|
||||
position: relative;
|
||||
&:before{
|
||||
|
|
|
@ -60,7 +60,11 @@ class NewHeader extends Component {
|
|||
}
|
||||
componentDidMount() {
|
||||
getUserInfo().then(response =>{
|
||||
response && this.setState({isExpert: response.data && response.data.expert});
|
||||
// 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();
|
||||
|
|
Loading…
Reference in New Issue