Skip to content

Commit 6ef4cf9

Browse files
authored
refactor: permission (pure-admin#357)
* refactor: permission * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * fix: 修复`mix`混合模式导航在生产环境左侧菜单一定机率不显示的问题 * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update
1 parent cedc84d commit 6ef4cf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+604
-385
lines changed

locales/en.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ menus:
3232
hsRole: Role Manage
3333
hsDept: Dept Manage
3434
hseditor: Editor
35-
hserror: Error Page
35+
hsabnormal: Abnormal Page
3636
hsfourZeroFour: "404"
3737
hsfourZeroOne: "403"
3838
hsFive: "500"

locales/zh-CN.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ menus:
3232
hsRole: 角色管理
3333
hsDept: 部门管理
3434
hseditor: 编辑器
35-
hserror: 错误页面
35+
hsabnormal: 异常页面
3636
hsfourZeroFour: "404"
3737
hsfourZeroOne: "403"
3838
hsFive: "500"

mock/asyncRoutes.ts

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
// 根据角色动态生成路由
1+
// 模拟后端动态生成路由
22
import { MockMethod } from "vite-plugin-mock";
33

4-
// http://mockjs.com/examples.html#Object
4+
/**
5+
* roles:页面级别权限,这里模拟二种 "admin"、"common"
6+
* admin:管理员角色
7+
* common:普通角色
8+
*/
9+
510
const systemRouter = {
611
path: "/system",
712
meta: {
@@ -15,23 +20,26 @@ const systemRouter = {
1520
name: "User",
1621
meta: {
1722
icon: "flUser",
18-
title: "menus.hsUser"
23+
title: "menus.hsUser",
24+
roles: ["admin"]
1925
}
2026
},
2127
{
2228
path: "/system/role/index",
2329
name: "Role",
2430
meta: {
2531
icon: "role",
26-
title: "menus.hsRole"
32+
title: "menus.hsRole",
33+
roles: ["admin"]
2734
}
2835
},
2936
{
3037
path: "/system/dept/index",
3138
name: "Dept",
3239
meta: {
3340
icon: "dept",
34-
title: "menus.hsDept"
41+
title: "menus.hsDept",
42+
roles: ["admin"]
3543
}
3644
},
3745
{
@@ -41,7 +49,8 @@ const systemRouter = {
4149
meta: {
4250
icon: "dict",
4351
title: "menus.hsDict",
44-
keepAlive: true
52+
keepAlive: true,
53+
roles: ["admin"]
4554
}
4655
}
4756
]
@@ -52,13 +61,14 @@ const permissionRouter = {
5261
meta: {
5362
title: "menus.permission",
5463
icon: "lollipop",
55-
rank: 7
64+
rank: 10
5665
},
5766
children: [
5867
{
5968
path: "/permission/page/index",
6069
name: "PermissionPage",
6170
meta: {
71+
roles: ["admin", "common"],
6272
title: "menus.permissionPage"
6373
}
6474
},
@@ -67,7 +77,8 @@ const permissionRouter = {
6777
name: "PermissionButton",
6878
meta: {
6979
title: "menus.permissionButton",
70-
authority: []
80+
roles: ["admin", "common"],
81+
auths: ["btn_add", "btn_edit", "btn_delete"]
7182
}
7283
}
7384
]
@@ -78,30 +89,33 @@ const frameRouter = {
7889
meta: {
7990
icon: "monitor",
8091
title: "menus.hsExternalPage",
81-
rank: 10
92+
rank: 7
8293
},
8394
children: [
8495
{
8596
path: "/iframe/pure",
8697
name: "FramePure",
8798
meta: {
8899
title: "menus.hsPureDocument",
89-
frameSrc: "http://yiming_chang.gitee.io/pure-admin-doc"
100+
frameSrc: "http://yiming_chang.gitee.io/pure-admin-doc",
101+
roles: ["admin", "common"]
90102
}
91103
},
92104
{
93105
path: "/external",
94106
name: "http://yiming_chang.gitee.io/pure-admin-doc",
95107
meta: {
96-
title: "menus.externalLink"
108+
title: "menus.externalLink",
109+
roles: ["admin", "common"]
97110
}
98111
},
99112
{
100113
path: "/iframe/ep",
101114
name: "FrameEp",
102115
meta: {
103116
title: "menus.hsEpDocument",
104-
frameSrc: "https://element-plus.org/zh-CN/"
117+
frameSrc: "https://element-plus.org/zh-CN/",
118+
roles: ["admin", "common"]
105119
}
106120
}
107121
]
@@ -119,55 +133,40 @@ const tabsRouter = {
119133
path: "/tabs/index",
120134
name: "Tabs",
121135
meta: {
122-
title: "menus.hstabs"
136+
title: "menus.hstabs",
137+
roles: ["admin", "common"]
123138
}
124139
},
125140
{
126141
path: "/tabs/query-detail",
127142
name: "TabQueryDetail",
128143
meta: {
129144
// 不在menu菜单中显示
130-
showLink: false
145+
showLink: false,
146+
roles: ["admin", "common"]
131147
}
132148
},
133149
{
134150
path: "/tabs/params-detail/:id",
135151
component: "params-detail",
136152
name: "TabParamsDetail",
137153
meta: {
138-
showLink: false
154+
showLink: false,
155+
roles: ["admin", "common"]
139156
}
140157
}
141158
]
142159
};
143160

144-
// 添加不同按钮权限到/permission/button页面中
145-
function setDifAuthority(authority, routes) {
146-
routes.children[1].meta.authority = [authority];
147-
return routes;
148-
}
149-
150161
export default [
151162
{
152163
url: "/getAsyncRoutes",
153164
method: "get",
154-
response: ({ query }) => {
155-
if (query.name === "admin") {
156-
return {
157-
code: 0,
158-
info: [
159-
tabsRouter,
160-
frameRouter,
161-
systemRouter,
162-
setDifAuthority("v-admin", permissionRouter)
163-
]
164-
};
165-
} else {
166-
return {
167-
code: 0,
168-
info: [tabsRouter, setDifAuthority("v-test", permissionRouter)]
169-
};
170-
}
165+
response: () => {
166+
return {
167+
success: true,
168+
data: [systemRouter, permissionRouter, frameRouter, tabsRouter]
169+
};
171170
}
172171
}
173172
] as MockMethod[];

mock/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default [
66
method: "post",
77
response: () => {
88
return {
9-
code: 0,
9+
success: true,
1010
data: {
1111
list: [
1212
{

mock/login.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// 根据角色动态生成路由
2+
import { MockMethod } from "vite-plugin-mock";
3+
4+
export default [
5+
{
6+
url: "/login",
7+
method: "post",
8+
response: ({ body }) => {
9+
if (body.username === "admin") {
10+
return {
11+
success: true,
12+
data: {
13+
username: "admin",
14+
// 一个用户可能有多个角色
15+
roles: ["admin"],
16+
accessToken: "eyJhbGciOiJIUzUxMiJ9.admin",
17+
refreshToken: "eyJhbGciOiJIUzUxMiJ9.adminRefresh",
18+
expires: "2023/10/30 00:00:00"
19+
}
20+
};
21+
} else {
22+
return {
23+
success: true,
24+
data: {
25+
username: "common",
26+
// 一个用户可能有多个角色
27+
roles: ["common"],
28+
accessToken: "eyJhbGciOiJIUzUxMiJ9.common",
29+
refreshToken: "eyJhbGciOiJIUzUxMiJ9.commonRefresh",
30+
expires: "2023/10/30 00:00:00"
31+
}
32+
};
33+
}
34+
}
35+
}
36+
] as MockMethod[];

mock/map.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export default [
2929
method: "get",
3030
response: () => {
3131
return {
32-
code: 0,
33-
info: mapList()
32+
success: true,
33+
data: mapList()
3434
};
3535
}
3636
}

mock/refreshToken.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { MockMethod } from "vite-plugin-mock";
2+
3+
// 模拟刷新token接口
4+
export default [
5+
{
6+
url: "/refreshToken",
7+
method: "post",
8+
response: ({ body }) => {
9+
if (body.refreshToken) {
10+
return {
11+
success: true,
12+
data: {
13+
accessToken: "eyJhbGciOiJIUzUxMiJ9.admin",
14+
refreshToken: "eyJhbGciOiJIUzUxMiJ9.adminRefresh",
15+
// `expires`选择这种日期格式是为了方便调试,后端直接设置时间戳或许更方便(每次都应该递增)。如果后端返回的是时间戳格式,前端开发请来到这个目录`src/utils/auth.ts`,把第`38`行的代码换成expires = data.expires即可。
16+
expires: "2023/10/30 23:59:59"
17+
}
18+
};
19+
} else {
20+
return {
21+
success: false,
22+
data: {}
23+
};
24+
}
25+
}
26+
}
27+
] as MockMethod[];

mock/system.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default [
66
method: "post",
77
response: () => {
88
return {
9-
code: 0,
9+
success: true,
1010
data: {
1111
list: [
1212
{
@@ -71,7 +71,7 @@ export default [
7171
method: "post",
7272
response: () => {
7373
return {
74-
code: 0,
74+
success: true,
7575
data: [
7676
{
7777
name: "杭州总公司",
@@ -212,7 +212,7 @@ export default [
212212
method: "post",
213213
response: () => {
214214
return {
215-
code: 0,
215+
success: true,
216216
data: {
217217
list: [
218218
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@pureadmin/components": "^1.1.0",
3636
"@pureadmin/descriptions": "^1.1.0",
3737
"@pureadmin/table": "^1.2.0",
38-
"@pureadmin/utils": "^1.1.4",
38+
"@pureadmin/utils": "^1.1.5",
3939
"@vueuse/core": "^9.3.0",
4040
"@vueuse/motion": "^2.0.0-beta.12",
4141
"@vueuse/shared": "^9.3.0",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/list.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { http } from "../utils/http";
22

33
type Result = {
4+
success: boolean;
45
data?: {
56
/** 列表数据 */
67
list: Array<any>;
78
};
8-
code?: number;
9-
msg?: string;
109
};
1110

1211
/** 卡片列表 */

src/api/mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { http } from "../utils/http";
22

33
type Result = {
4-
code: number;
5-
info: Array<any>;
4+
success: boolean;
5+
data: Array<any>;
66
};
77

88
/** 地图数据 */

src/api/routes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { http } from "../utils/http";
22

33
type Result = {
4-
code: number;
5-
info: Array<any>;
4+
success: boolean;
5+
data: Array<any>;
66
};
77

8-
export const getAsyncRoutes = (params?: object) => {
9-
return http.request<Result>("get", "/getAsyncRoutes", { params });
8+
export const getAsyncRoutes = () => {
9+
return http.request<Result>("get", "/getAsyncRoutes");
1010
};

0 commit comments

Comments
 (0)