@befly-addon/admin 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ import { normalizePathnameListInput } from "befly-shared/utils/normalizePathnameListInput";
2
+
1
3
  import adminRoleTable from "../../tables/role.json";
2
4
 
3
5
  export default {
@@ -7,6 +9,13 @@ export default {
7
9
  apiPaths: adminRoleTable.apis
8
10
  },
9
11
  handler: async (befly, ctx) => {
12
+ let apiPaths: string[] = [];
13
+ try {
14
+ apiPaths = normalizePathnameListInput(ctx.body.apiPaths, "apiPaths", true);
15
+ } catch (error: any) {
16
+ return befly.tool.No(`参数不合法:${error?.message || "未知错误"}`);
17
+ }
18
+
10
19
  // 查询角色是否存在
11
20
  const role = await befly.db.getOne({
12
21
  table: "addon_admin_role",
@@ -22,12 +31,12 @@ export default {
22
31
  table: "addon_admin_role",
23
32
  where: { code: ctx.body.roleCode },
24
33
  data: {
25
- apis: ctx.body.apiPaths
34
+ apis: apiPaths
26
35
  }
27
36
  });
28
37
 
29
38
  // 增量刷新 Redis 权限缓存
30
- await befly.cache.refreshRoleApiPermissions(role.code, ctx.body.apiPaths || []);
39
+ await befly.cache.refreshRoleApiPermissions(role.code, apiPaths);
31
40
 
32
41
  return befly.tool.Yes("操作成功");
33
42
  }
package/apis/role/apis.ts CHANGED
@@ -17,7 +17,7 @@ export default {
17
17
  }
18
18
 
19
19
  // 数据库自动将 array_text 转换为数组
20
- const apiPaths = role.apis || [];
20
+ const apiPaths = Array.isArray(role.apis) ? role.apis : [];
21
21
 
22
22
  return befly.tool.Yes("操作成功", { apiPaths: apiPaths });
23
23
  }
package/apis/role/ins.ts CHANGED
@@ -1,9 +1,22 @@
1
+ import { normalizePathnameListInput } from "befly-shared/utils/normalizePathnameListInput";
2
+
1
3
  import adminRoleTable from "../../tables/role.json";
2
4
 
3
5
  export default {
4
6
  name: "创建角色",
5
7
  fields: adminRoleTable,
6
8
  handler: async (befly, ctx) => {
9
+ let apiPaths: string[] = [];
10
+ let menuPaths: string[] = [];
11
+
12
+ try {
13
+ apiPaths = normalizePathnameListInput(ctx.body.apis, "apis", true);
14
+
15
+ menuPaths = normalizePathnameListInput(ctx.body.menus, "menus", false);
16
+ } catch (error: any) {
17
+ return befly.tool.No(`参数不合法:${error?.message || "未知错误"}`);
18
+ }
19
+
7
20
  // 检查角色代码是否已存在
8
21
  const existing = await befly.db.getOne({
9
22
  table: "addon_admin_role",
@@ -20,15 +33,15 @@ export default {
20
33
  name: ctx.body.name,
21
34
  code: ctx.body.code,
22
35
  description: ctx.body.description,
23
- menus: ctx.body.menus || [],
24
- apis: ctx.body.apis || [],
36
+ menus: menuPaths,
37
+ apis: apiPaths,
25
38
  sort: ctx.body.sort
26
39
  // state 由框架自动设置为 1
27
40
  }
28
41
  });
29
42
 
30
43
  // 增量刷新角色权限缓存
31
- await befly.cache.refreshRoleApiPermissions(ctx.body.code, ctx.body.apis || []);
44
+ await befly.cache.refreshRoleApiPermissions(ctx.body.code, apiPaths);
32
45
 
33
46
  return befly.tool.Yes("操作成功", { id: roleId });
34
47
  }
@@ -1,3 +1,5 @@
1
+ import { normalizePathnameListInput } from "befly-shared/utils/normalizePathnameListInput";
2
+
1
3
  import adminRoleTable from "../../tables/role.json";
2
4
 
3
5
  export default {
@@ -7,6 +9,13 @@ export default {
7
9
  menuPaths: adminRoleTable.menus
8
10
  },
9
11
  handler: async (befly, ctx) => {
12
+ let menuPaths: string[] = [];
13
+ try {
14
+ menuPaths = normalizePathnameListInput(ctx.body.menuPaths, "menuPaths", false);
15
+ } catch (error: any) {
16
+ return befly.tool.No(`参数不合法:${error?.message || "未知错误"}`);
17
+ }
18
+
10
19
  // 查询角色是否存在
11
20
  const role = await befly.db.getOne({
12
21
  table: "addon_admin_role",
@@ -22,7 +31,7 @@ export default {
22
31
  table: "addon_admin_role",
23
32
  where: { code: ctx.body.roleCode },
24
33
  data: {
25
- menus: ctx.body.menuPaths
34
+ menus: menuPaths
26
35
  }
27
36
  });
28
37
 
@@ -17,7 +17,7 @@ export default {
17
17
  }
18
18
 
19
19
  // 数据库自动将 array_text 转换为数组
20
- const menuPaths = role.menus || [];
20
+ const menuPaths = Array.isArray(role.menus) ? role.menus : [];
21
21
 
22
22
  return befly.tool.Yes("操作成功", menuPaths);
23
23
  }
package/apis/role/upd.ts CHANGED
@@ -1,9 +1,22 @@
1
+ import { normalizePathnameListInput } from "befly-shared/utils/normalizePathnameListInput";
2
+
1
3
  import adminRoleTable from "../../tables/role.json";
2
4
 
3
5
  export default {
4
6
  name: "更新角色",
5
7
  fields: adminRoleTable,
6
8
  handler: async (befly, ctx) => {
9
+ let apiPaths: string[] = [];
10
+ let menuPaths: string[] = [];
11
+
12
+ try {
13
+ apiPaths = normalizePathnameListInput(ctx.body.apis, "apis", true);
14
+
15
+ menuPaths = normalizePathnameListInput(ctx.body.menus, "menus", false);
16
+ } catch (error: any) {
17
+ return befly.tool.No(`参数不合法:${error?.message || "未知错误"}`);
18
+ }
19
+
7
20
  // 检查角色代码是否被其他角色占用
8
21
  const existing = await befly.db.getList({
9
22
  table: "addon_admin_role",
@@ -24,15 +37,15 @@ export default {
24
37
  name: ctx.body.name,
25
38
  code: ctx.body.code,
26
39
  description: ctx.body.description,
27
- menus: ctx.body.menus || [],
28
- apis: ctx.body.apis || [],
40
+ menus: menuPaths,
41
+ apis: apiPaths,
29
42
  sort: ctx.body.sort
30
43
  // state 字段不在此处更新,需要禁用/启用时单独处理
31
44
  }
32
45
  });
33
46
 
34
47
  // 增量刷新角色权限缓存
35
- await befly.cache.refreshRoleApiPermissions(ctx.body.code, ctx.body.apis || []);
48
+ await befly.cache.refreshRoleApiPermissions(ctx.body.code, apiPaths);
36
49
 
37
50
  return befly.tool.Yes("操作成功");
38
51
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@befly-addon/admin",
3
- "version": "1.2.4",
4
- "gitHead": "a281633b6f8be7c941aa7e6a3f677bfc18b65ddc",
3
+ "version": "1.2.5",
4
+ "gitHead": "549fff1035081111a5ba32b5088e7c37907fa894",
5
5
  "private": false,
6
6
  "description": "Befly - 管理后台功能组件",
7
7
  "keywords": [
@@ -47,8 +47,9 @@
47
47
  "preview": "vite preview"
48
48
  },
49
49
  "dependencies": {
50
- "befly": "^3.10.4",
51
- "befly-vite": "^1.2.3",
50
+ "befly": "^3.10.5",
51
+ "befly-shared": "^1.3.3",
52
+ "befly-vite": "^1.2.4",
52
53
  "nodemailer": "^7.0.12",
53
54
  "ua-parser-js": "^2.0.7"
54
55
  },