Skip to content

Commit 31a38e3

Browse files
committed
add menu
1 parent 725907a commit 31a38e3

File tree

7 files changed

+62
-10
lines changed

7 files changed

+62
-10
lines changed

antd-pro/config/routes.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/**
1+

2+
/**
23
* @name umi 的路由配置
34
* @description 只支持 path,component,routes,redirect,wrappers,name,icon 的配置
45
* @param path path 只支持两种占位符配置,第一种是动态参数 :id 的形式,第二种是 * 通配符,通配符只能出现路由字符串的最后。
@@ -10,6 +11,7 @@
1011
* @param icon 配置路由的图标,取值参考 https://ant.design/components/icon-cn, 注意去除风格后缀和大小写,如想要配置图标为 <StepBackwardOutlined /> 则取值应为 stepBackward 或 StepBackward,如想要配置图标为 <UserOutlined /> 则取值应为 user 或者 User
1112
* @doc https://umijs.org/docs/guides/routes
1213
*/
14+
1315
export default [
1416
{
1517
path: '/login',

antd-pro/src/app.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import defaultSettings from '../config/defaultSettings';
88
import { errorConfig } from './requestErrorConfig';
99
import React from 'react';
1010
import { AvatarDropdown, AvatarName } from './components/RightContent/AvatarDropdown';
11+
import { loadLayoutMenus } from './components/Menu';
1112
const loginPath = '/user/login';
1213

1314
/**
@@ -59,6 +60,11 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
5960
return <AvatarDropdown>{avatarChildren}</AvatarDropdown>;
6061
},
6162
},
63+
menu:{
64+
request: async(params, defaultMenuData) =>{
65+
return await loadLayoutMenus();
66+
}
67+
},
6268
waterMarkProps: {
6369
content: initialState?.currentUser?.username,
6470
},
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
import { menus } from '@/services/api/account';
3+
4+
interface MenuProps {
5+
icon: string
6+
}
7+
8+
const Menus: React.FC<MenuProps> = (props) => {
9+
return (
10+
<img src={props.icon} style={{
11+
width: '20px'
12+
}} />
13+
)
14+
}
15+
16+
export async function loadLayoutMenus() {
17+
const response = await menus();
18+
if (response.success) {
19+
let childrens = response.data.children;
20+
if (childrens === null) {
21+
return [];
22+
}
23+
const search = (data: any) => {
24+
data.icon = <Menus icon={data.icon} />;
25+
data.children = data.children || [];
26+
data.children.forEach((item: any) => {
27+
search(item);
28+
});
29+
return data;
30+
}
31+
childrens = childrens.map(item => search(item));
32+
return childrens;
33+
} else {
34+
return [];
35+
}
36+
}

antd-pro/src/pages/components/menu/index.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const MenuPage: React.FC = () => {
6262
search: false,
6363
},
6464
{
65-
title: "编码",
66-
dataIndex: 'code',
65+
title: "地址",
66+
dataIndex: 'path',
6767
search: false,
6868
},
6969
{
@@ -248,15 +248,15 @@ const MenuPage: React.FC = () => {
248248
name="name"
249249
/>
250250
<ProFormText
251-
placeholder="请输入菜单编码"
252-
label="菜单编码"
251+
placeholder="请输入菜单地址"
252+
label="菜单地址"
253253
rules={[
254254
{
255255
required: true,
256-
message: "请输入菜单编码",
256+
message: "请输入菜单地址",
257257
},
258258
]}
259-
name="code"
259+
name="path"
260260
/>
261261
<ProFormText
262262
placeholder="请输入菜单图标"

antd-pro/src/services/api/account.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
/* eslint-disable */
33
import {history} from '@umijs/max';
44
import {stringify} from 'querystring';
5-
import {post} from "./index";
5+
import {post,get} from "./index";
6+
67

78

89
export function logout() {
@@ -32,3 +33,11 @@ export async function login(body: Account.LoginRequest) {
3233
return post('/user/login', body);
3334
}
3435

36+
37+
/**
38+
* 获取用户菜单
39+
* @returns 菜单列表
40+
*/
41+
export async function menus(){
42+
return get('/api/menu/tree');
43+
}

components-server/components/menu/menu-domain/src/main/java/com/codingapi/components/menu/domain/Menu.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Menu {
2222
private String name;
2323

2424
@Column(unique = true)
25-
private String code;
25+
private String path;
2626

2727
private String icon;
2828

components-server/components/menu/menu-infrastructure-db/src/main/java/com/codingapi/components/infrastructure/menu/jpa/JpaMenuRepository.java

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55

66
public interface JpaMenuRepository extends FastRepository<Menu,Integer> {
77

8-
Menu getMenuByCode(String code);
98
}

0 commit comments

Comments
 (0)