Unverified Commit e48dd5a3 authored by yqwoe's avatar yqwoe Committed by GitHub

[Feature][Web] Menu permission control (#2200)

* feat: 菜单权限控制
parent ed6b27ed
...@@ -20,4 +20,4 @@ spring: ...@@ -20,4 +20,4 @@ spring:
url: jdbc:mysql://${MYSQL_ADDR:127.0.0.1:3306}/${MYSQL_DATABASE:dinky}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true url: jdbc:mysql://${MYSQL_ADDR:127.0.0.1:3306}/${MYSQL_DATABASE:dinky}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: ${MYSQL_USERNAME:dinky} username: ${MYSQL_USERNAME:dinky}
password: ${MYSQL_PASSWORD:dinky} password: ${MYSQL_PASSWORD:dinky}
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
\ No newline at end of file
...@@ -261,6 +261,8 @@ export default [ ...@@ -261,6 +261,8 @@ export default [
{ {
path: '/account/center', path: '/account/center',
footerRender: false, footerRender: false,
name: 'center',
hideInMenu: true,
component: './Other/PersonCenter', component: './Other/PersonCenter',
}, },
{ {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { API } from "./services/data"; import { API } from './services/data';
/** /**
* @see https://umijs.org/zh-CN/plugins/plugin-access * @see https://umijs.org/zh-CN/plugins/plugin-access
...@@ -24,5 +24,17 @@ export default function access(initialState: { currentUser?: API.CurrentUser } | ...@@ -24,5 +24,17 @@ export default function access(initialState: { currentUser?: API.CurrentUser } |
const { currentUser } = initialState ?? {}; const { currentUser } = initialState ?? {};
return { return {
canAdmin: currentUser && currentUser.user.superAdminFlag, canAdmin: currentUser && currentUser.user.superAdminFlag,
canAuth({ path, ...route }) {
if (currentUser && currentUser.user.superAdminFlag) {
return true;
}
//TODO根据path判断应用、目录、菜单、按钮,判断返回true,false
//TODOpath可以是window.location.href、key
return currentUser?.menuList?.some?.(
(item) => item?.path?.startsWith(path) || item?.path?.endsWith(path),
);
},
}; };
} }
...@@ -36,6 +36,24 @@ import { API } from "./services/data"; ...@@ -36,6 +36,24 @@ import { API } from "./services/data";
// const isDev = process.env.NODE_ENV === "development"; // const isDev = process.env.NODE_ENV === "development";
const loginPath = API_CONSTANTS.LOGIN_PATH; const loginPath = API_CONSTANTS.LOGIN_PATH;
const whiteList = ['/user','/user/login']
/**
* 初始化路由鉴权
* @param param0
*/
export function patchRoutes ({ routes }: any) {
Object.keys(routes).forEach(key=>{
let route = routes[key];
if(!whiteList.includes(route.path)){
routes[key] = {...route,access: 'canAuth'}
}
})
}
/** /**
* @see https://umijs.org/zh-CN/plugins/plugin-initial-state * @see https://umijs.org/zh-CN/plugins/plugin-initial-state
* */ * */
......
...@@ -18,19 +18,19 @@ ...@@ -18,19 +18,19 @@
*/ */
import React, {useEffect, useState} from "react";
import {Button, Space} from 'antd';
import {handleAddOrUpdate, handleRemoveById, queryDataByParams} from "@/services/BusinessCrud";
import {ProCard} from "@ant-design/pro-components";
import {MenuInfo} from "rc-menu/es/interface";
import {RIGHT_CONTEXT_MENU} from "@/pages/AuthCenter/Menu/components/MenuList/constants";
import {SysMenu} from "@/types/RegCenter/data";
import {PlusSquareTwoTone, ReloadOutlined} from "@ant-design/icons";
import OpHelper from "@/pages/AuthCenter/Menu/components/MenuList/OpHelper";
import {l} from "@/utils/intl";
import RightContextMenu from "@/components/RightContextMenu"; import RightContextMenu from "@/components/RightContextMenu";
import MenuForm from "@/pages/AuthCenter/Menu/components/MenuForm"; import MenuForm from "@/pages/AuthCenter/Menu/components/MenuForm";
import OpHelper from "@/pages/AuthCenter/Menu/components/MenuList/OpHelper";
import { RIGHT_CONTEXT_MENU } from "@/pages/AuthCenter/Menu/components/MenuList/constants";
import MenuTree from "@/pages/AuthCenter/Menu/components/MenuTree"; import MenuTree from "@/pages/AuthCenter/Menu/components/MenuTree";
import { handleAddOrUpdate, handleRemoveById, queryDataByParams } from "@/services/BusinessCrud";
import { SysMenu } from "@/types/RegCenter/data";
import { l } from "@/utils/intl";
import { PlusSquareTwoTone, ReloadOutlined } from "@ant-design/icons";
import { ProCard } from "@ant-design/pro-components";
import { Button, Space } from 'antd';
import { MenuInfo } from "rc-menu/es/interface";
import React, { useEffect, useState } from "react";
const MenuList: React.FC = () => { const MenuList: React.FC = () => {
/** /**
...@@ -245,7 +245,7 @@ const MenuList: React.FC = () => { ...@@ -245,7 +245,7 @@ const MenuList: React.FC = () => {
</> </>
} }
console.log(treeData,buildMenuFormTree(treeData,'',true))
/** /**
* render * render
*/ */
...@@ -279,4 +279,4 @@ const MenuList: React.FC = () => { ...@@ -279,4 +279,4 @@ const MenuList: React.FC = () => {
} }
; ;
export default MenuList; export default MenuList;
\ No newline at end of file
...@@ -36,7 +36,7 @@ type MenuTreeProps = { ...@@ -36,7 +36,7 @@ type MenuTreeProps = {
loading: boolean, loading: boolean,
} }
const MenuTree: React.FC<MenuTreeProps> = (props) => { const MenuTree: React.FC<MenuTreeProps> = (props) => {
const {treeData, selectedKeys, onNodeClick, onRightClick , loading} = props; const {treeData = [], selectedKeys, onNodeClick, onRightClick , loading} = props;
const [searchValue, setSearchValue] = useState(''); const [searchValue, setSearchValue] = useState('');
...@@ -74,4 +74,4 @@ const MenuTree: React.FC<MenuTreeProps> = (props) => { ...@@ -74,4 +74,4 @@ const MenuTree: React.FC<MenuTreeProps> = (props) => {
</> </>
} }
export default MenuTree; export default MenuTree;
\ No newline at end of file
...@@ -17,20 +17,19 @@ ...@@ -17,20 +17,19 @@
* *
*/ */
import SlowlyAppear from '@/components/Animation/SlowlyAppear';
import React from "react"; import MenuList from '@/pages/AuthCenter/Menu/components/MenuList';
import {PageContainer} from '@ant-design/pro-layout'; import { PageContainer } from '@ant-design/pro-layout';
import SlowlyAppear from "@/components/Animation/SlowlyAppear";
import MenuList from "@/pages/AuthCenter/Menu/components/MenuList";
export default () => { export default () => {
/** /**
* render * render
*/ */
return <SlowlyAppear> return (
<PageContainer title={false}> <SlowlyAppear>
<MenuList/> <PageContainer title={false}>
</PageContainer> <MenuList />
</SlowlyAppear> </PageContainer>
</SlowlyAppear>
);
}; };
...@@ -16,23 +16,24 @@ ...@@ -16,23 +16,24 @@
* limitations under the License. * limitations under the License.
* *
*/ */
import DevOverView from '@/pages/Home/DevOverView';
import {Col, Row} from 'antd'; import JobOverView from '@/pages/Home/JobOverView';
import JobOverView from "@/pages/Home/JobOverView"; import { PageContainer } from '@ant-design/pro-components';
import {PageContainer} from "@ant-design/pro-components"; import { Col, Row } from 'antd';
import DevOverView from "@/pages/Home/DevOverView";
export default () => { export default () => {
return <PageContainer title={false}> return (
<Row style={{marginTop: '5px', marginBottom: '10px'}}> <PageContainer title={false}>
<Col span={24}> <Row style={{ marginTop: '5px', marginBottom: '10px' }}>
<JobOverView/> <Col span={24}>
</Col> <JobOverView />
</Row> </Col>
<Row> </Row>
<Col span={24}> <Row>
<DevOverView/> <Col span={24}>
</Col> <DevOverView />
</Row> </Col>
</PageContainer> </Row>
} </PageContainer>
);
};
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