befly 3.24.19 → 3.24.20
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.
- package/apis/_apis.js +20 -0
- package/apis/admin/delete.js +3 -1
- package/apis/admin/detail.js +1 -3
- package/apis/admin/select.js +9 -7
- package/apis/admin/update.js +2 -2
- package/apis/api/all.js +6 -11
- package/apis/api/select.js +18 -19
- package/apis/dict/_dict.js +24 -0
- package/apis/dict/all.js +6 -4
- package/apis/dict/detail.js +9 -5
- package/apis/dict/insert.js +4 -11
- package/apis/dict/items.js +5 -6
- package/apis/dict/select.js +13 -9
- package/apis/dict/update.js +9 -13
- package/apis/dictType/select.js +4 -4
- package/apis/email/config.js +9 -11
- package/apis/email/logList.js +14 -4
- package/apis/email/send.js +10 -3
- package/apis/email/verify.js +9 -7
- package/apis/loginLog/select.js +11 -4
- package/apis/menu/all.js +13 -19
- package/apis/menu/select.js +19 -14
- package/apis/operateLog/select.js +13 -4
- package/apis/role/_role.js +21 -0
- package/apis/role/all.js +1 -3
- package/apis/role/apiSave.js +8 -15
- package/apis/role/apis.js +4 -10
- package/apis/role/delete.js +28 -36
- package/apis/role/detail.js +4 -10
- package/apis/role/insert.js +12 -10
- package/apis/role/menuSave.js +9 -15
- package/apis/role/menus.js +4 -10
- package/apis/role/save.js +19 -23
- package/apis/role/select.js +12 -9
- package/apis/role/update.js +14 -15
- package/apis/source/imageList.js +3 -3
- package/apis/sysConfig/get.js +11 -23
- package/apis/sysConfig/insert.js +22 -27
- package/apis/sysConfig/select.js +11 -5
- package/apis/sysConfig/update.js +33 -38
- package/apis/tongJi/_tongJi.js +41 -0
- package/apis/tongJi/cacheHealth.js +8 -30
- package/apis/tongJi/errorList.js +26 -27
- package/apis/tongJi/errorReport.js +26 -43
- package/apis/tongJi/errorStats.js +17 -48
- package/apis/tongJi/fallbackReset.js +7 -15
- package/apis/tongJi/infoReport.js +20 -32
- package/apis/tongJi/infoStats.js +5 -17
- package/apis/tongJi/onlineReport.js +50 -56
- package/apis/tongJi/onlineStats.js +97 -111
- package/checks/config.js +44 -1
- package/configs/beflyConfig.json +10 -1
- package/index.js +25 -0
- package/lib/dbHelper.js +1 -1
- package/lib/dbParse.js +61 -99
- package/lib/dbUtil.js +101 -21
- package/lib/redisHelper.js +25 -0
- package/lib/sqlBuilder.js +6 -0
- package/package.json +1 -1
- package/plugins/email.js +3 -6
- package/router/api.js +0 -7
- package/utils/email.js +3 -0
- package/apis/admin/cacheRefresh.js +0 -122
- package/apis/dashboard/configStatus.js +0 -39
- package/apis/dashboard/performanceMetrics.js +0 -23
- package/apis/dashboard/permissionStats.js +0 -27
- package/apis/dashboard/systemInfo.js +0 -19
- package/lib/requestMetrics.js +0 -203
package/apis/menu/select.js
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
+
import { queryFields } from "#root/apis/_apis.js";
|
|
2
|
+
import menuTable from "#root/tables/menu.json";
|
|
3
|
+
|
|
1
4
|
export default {
|
|
2
5
|
name: "获取菜单列表",
|
|
3
6
|
method: "POST",
|
|
4
7
|
body: "none",
|
|
5
8
|
auth: true,
|
|
6
9
|
fields: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
keyword: { name: "关键词", input: "string", min: 0, max: 50 },
|
|
10
|
-
state: { name: "状态", input: "integer", min: 0, max: 2 }
|
|
10
|
+
...queryFields,
|
|
11
|
+
state: menuTable.state
|
|
11
12
|
},
|
|
12
13
|
required: [],
|
|
13
|
-
handler: async (befly) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
handler: async (befly, ctx) => {
|
|
15
|
+
const menus = await befly.mysql.getList({
|
|
16
|
+
table: "beflyMenu",
|
|
17
|
+
page: ctx.body.page,
|
|
18
|
+
limit: ctx.body.limit,
|
|
19
|
+
where: {
|
|
20
|
+
name$like$or: ctx.body.keyword,
|
|
21
|
+
path$like$or: ctx.body.keyword,
|
|
22
|
+
parentPath$like$or: ctx.body.keyword,
|
|
23
|
+
state: ctx.body.state
|
|
24
|
+
},
|
|
25
|
+
orderBy: ["sort#ASC", "id#ASC"]
|
|
26
|
+
});
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
} catch (error) {
|
|
21
|
-
befly.logger.error("获取菜单列表失败", error);
|
|
22
|
-
return befly.tool.No("操作失败");
|
|
23
|
-
}
|
|
28
|
+
return befly.tool.Yes("操作成功", menus.data);
|
|
24
29
|
}
|
|
25
30
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { queryFields } from "#root/apis/_apis.js";
|
|
2
|
+
import operateLogTable from "#root/tables/operateLog.json";
|
|
3
|
+
|
|
1
4
|
export default {
|
|
2
5
|
name: "获取操作日志列表",
|
|
3
6
|
method: "POST",
|
|
4
7
|
body: "none",
|
|
5
8
|
auth: true,
|
|
6
9
|
fields: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
keyword: { name: "关键词", input: "string", min: 0, max: 50 },
|
|
10
|
-
state: { name: "状态", input: "integer", min: 0, max: 2 }
|
|
10
|
+
...queryFields,
|
|
11
|
+
state: operateLogTable.state
|
|
11
12
|
},
|
|
12
13
|
required: [],
|
|
13
14
|
handler: async (befly, ctx) => {
|
|
@@ -15,6 +16,14 @@ export default {
|
|
|
15
16
|
table: "beflyOperateLog",
|
|
16
17
|
page: ctx.body.page,
|
|
17
18
|
limit: ctx.body.limit,
|
|
19
|
+
where: {
|
|
20
|
+
username$like$or: ctx.body.keyword,
|
|
21
|
+
nickname$like$or: ctx.body.keyword,
|
|
22
|
+
module$like$or: ctx.body.keyword,
|
|
23
|
+
action$like$or: ctx.body.keyword,
|
|
24
|
+
path$like$or: ctx.body.keyword,
|
|
25
|
+
state: ctx.body.state
|
|
26
|
+
},
|
|
18
27
|
orderBy: ["operateTime#DESC"]
|
|
19
28
|
});
|
|
20
29
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const systemRoleCodes = ["dev", "user", "admin", "guest"];
|
|
2
|
+
|
|
3
|
+
export async function getRoleByCode(befly, roleCode, fields = undefined) {
|
|
4
|
+
return await befly.mysql.getOne({
|
|
5
|
+
table: "beflyRole",
|
|
6
|
+
fields: fields,
|
|
7
|
+
where: {
|
|
8
|
+
code: roleCode
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function getRoleById(befly, id, fields = undefined) {
|
|
14
|
+
return await befly.mysql.getOne({
|
|
15
|
+
table: "beflyRole",
|
|
16
|
+
fields: fields,
|
|
17
|
+
where: {
|
|
18
|
+
id: id
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
package/apis/role/all.js
CHANGED
package/apis/role/apiSave.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import roleTable from "#root/tables/role.json";
|
|
2
|
+
|
|
3
|
+
import { getRoleByCode } from "./_role.js";
|
|
3
4
|
|
|
4
5
|
export default {
|
|
5
6
|
name: "保存角色接口权限",
|
|
@@ -7,27 +8,19 @@ export default {
|
|
|
7
8
|
body: "none",
|
|
8
9
|
auth: true,
|
|
9
10
|
fields: {
|
|
10
|
-
roleCode:
|
|
11
|
-
apiPaths:
|
|
11
|
+
roleCode: roleTable.code,
|
|
12
|
+
apiPaths: roleTable.apis
|
|
12
13
|
},
|
|
13
|
-
required: [],
|
|
14
|
+
required: ["roleCode"],
|
|
14
15
|
handler: async (befly, ctx) => {
|
|
15
16
|
const apiPaths = ctx.body.apiPaths || [];
|
|
16
17
|
|
|
17
|
-
const role = await befly.
|
|
18
|
-
table: "beflyRole",
|
|
19
|
-
where: { code: ctx.body.roleCode }
|
|
20
|
-
});
|
|
18
|
+
const role = await getRoleByCode(befly, ctx.body.roleCode);
|
|
21
19
|
|
|
22
20
|
if (!role.data || !role.data.id) {
|
|
23
21
|
return befly.tool.No("角色不存在");
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
const roleCode = role.data.code;
|
|
27
|
-
if (!isNonEmptyString(roleCode)) {
|
|
28
|
-
return befly.tool.No("角色不存在");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
24
|
await befly.mysql.updData({
|
|
32
25
|
table: "beflyRole",
|
|
33
26
|
where: { code: ctx.body.roleCode },
|
|
@@ -36,7 +29,7 @@ export default {
|
|
|
36
29
|
}
|
|
37
30
|
});
|
|
38
31
|
|
|
39
|
-
await befly.cache.refreshRoleApis(
|
|
32
|
+
await befly.cache.refreshRoleApis(role.data.code, apiPaths);
|
|
40
33
|
|
|
41
34
|
return befly.tool.Yes("操作成功");
|
|
42
35
|
}
|
package/apis/role/apis.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isNonEmptyString } from "#root/utils/is.js";
|
|
1
|
+
import roleTable from "#root/tables/role.json";
|
|
3
2
|
|
|
4
3
|
export default {
|
|
5
4
|
name: "获取角色接口权限",
|
|
@@ -7,16 +6,11 @@ export default {
|
|
|
7
6
|
body: "none",
|
|
8
7
|
auth: true,
|
|
9
8
|
fields: {
|
|
10
|
-
roleCode:
|
|
9
|
+
roleCode: roleTable.code
|
|
11
10
|
},
|
|
12
|
-
required: [],
|
|
11
|
+
required: ["roleCode"],
|
|
13
12
|
handler: async (befly, ctx) => {
|
|
14
|
-
const
|
|
15
|
-
if (!isNonEmptyString(roleCode)) {
|
|
16
|
-
return befly.tool.No("参数不合法");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const apiPaths = await befly.cache.getRoleApis(roleCode);
|
|
13
|
+
const apiPaths = await befly.cache.getRoleApis(ctx.body.roleCode);
|
|
20
14
|
return befly.tool.Yes("操作成功", { apiPaths: apiPaths });
|
|
21
15
|
}
|
|
22
16
|
};
|
package/apis/role/delete.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getRoleById, systemRoleCodes } from "./_role.js";
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
name: "删除角色",
|
|
3
5
|
method: "POST",
|
|
@@ -8,42 +10,32 @@ export default {
|
|
|
8
10
|
},
|
|
9
11
|
required: ["id"],
|
|
10
12
|
handler: async (befly, ctx) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
table: "beflyAdmin",
|
|
29
|
-
where: { roleCode: role.data.code }
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
if (adminList.data.total > 0) {
|
|
33
|
-
return befly.tool.No("该角色已分配给用户,无法删除");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await befly.mysql.delData({
|
|
37
|
-
table: "beflyRole",
|
|
38
|
-
where: { id: ctx.body.id }
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
await befly.cache.deleteRoleApis(role.data.code);
|
|
42
|
-
|
|
43
|
-
return befly.tool.Yes("操作成功");
|
|
44
|
-
} catch (error) {
|
|
45
|
-
befly.logger.error("删除角色失败", error);
|
|
46
|
-
return befly.tool.No("操作失败");
|
|
13
|
+
const role = await getRoleById(befly, ctx.body.id, ["code"]);
|
|
14
|
+
|
|
15
|
+
if (!role.data?.code) {
|
|
16
|
+
return befly.tool.No("角色不存在");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (systemRoleCodes.includes(role.data.code)) {
|
|
20
|
+
return befly.tool.No(`系统角色 [${role.data.code}] 不允许删除`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const adminList = await befly.mysql.getList({
|
|
24
|
+
table: "beflyAdmin",
|
|
25
|
+
where: { roleCode: role.data.code }
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (adminList.data.total > 0) {
|
|
29
|
+
return befly.tool.No("该角色已分配给用户,无法删除");
|
|
47
30
|
}
|
|
31
|
+
|
|
32
|
+
await befly.mysql.delData({
|
|
33
|
+
table: "beflyRole",
|
|
34
|
+
where: { id: ctx.body.id }
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await befly.cache.deleteRoleApis(role.data.code);
|
|
38
|
+
|
|
39
|
+
return befly.tool.Yes("操作成功");
|
|
48
40
|
}
|
|
49
41
|
};
|
package/apis/role/detail.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import roleTable from "#root/tables/role.json";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { getRoleByCode } from "./_role.js";
|
|
3
4
|
|
|
4
5
|
export default {
|
|
5
6
|
name: "获取用户角色",
|
|
@@ -13,15 +14,8 @@ export default {
|
|
|
13
14
|
handler: async (befly, ctx) => {
|
|
14
15
|
let roleInfo = null;
|
|
15
16
|
if (ctx.body.id && ctx.roleType === "admin") {
|
|
16
|
-
const roleInfoResult = await befly.
|
|
17
|
-
|
|
18
|
-
where: { code: ctx.body.id }
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const roleId = roleInfoResult.data ? roleInfoResult.data.id : undefined;
|
|
22
|
-
if (isNumber(roleId)) {
|
|
23
|
-
roleInfo = roleInfoResult.data;
|
|
24
|
-
}
|
|
17
|
+
const roleInfoResult = await getRoleByCode(befly, ctx.body.id);
|
|
18
|
+
roleInfo = roleInfoResult.data || null;
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
return befly.tool.Yes("操作成功", {
|
package/apis/role/insert.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import roleTable from "#root/tables/role.json";
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
4
|
name: "创建角色",
|
|
@@ -6,15 +6,17 @@ export default {
|
|
|
6
6
|
body: "none",
|
|
7
7
|
auth: true,
|
|
8
8
|
fields: {
|
|
9
|
-
name:
|
|
10
|
-
code:
|
|
11
|
-
description:
|
|
12
|
-
menus:
|
|
13
|
-
apis:
|
|
14
|
-
sort:
|
|
9
|
+
name: roleTable.name,
|
|
10
|
+
code: roleTable.code,
|
|
11
|
+
description: roleTable.description,
|
|
12
|
+
menus: roleTable.menus,
|
|
13
|
+
apis: roleTable.apis,
|
|
14
|
+
sort: roleTable.sort
|
|
15
15
|
},
|
|
16
16
|
required: [],
|
|
17
17
|
handler: async (befly, ctx) => {
|
|
18
|
+
const menuPaths = ctx.body.menus || [];
|
|
19
|
+
const apiPaths = ctx.body.apis || [];
|
|
18
20
|
const existing = await befly.mysql.getOne({
|
|
19
21
|
table: "beflyRole",
|
|
20
22
|
where: { code: ctx.body.code }
|
|
@@ -30,13 +32,13 @@ export default {
|
|
|
30
32
|
name: ctx.body.name,
|
|
31
33
|
code: ctx.body.code,
|
|
32
34
|
description: ctx.body.description,
|
|
33
|
-
menus:
|
|
34
|
-
apis:
|
|
35
|
+
menus: menuPaths,
|
|
36
|
+
apis: apiPaths,
|
|
35
37
|
sort: ctx.body.sort
|
|
36
38
|
}
|
|
37
39
|
});
|
|
38
40
|
|
|
39
|
-
await befly.cache.refreshRoleApis(ctx.body.code,
|
|
41
|
+
await befly.cache.refreshRoleApis(ctx.body.code, apiPaths);
|
|
40
42
|
|
|
41
43
|
return befly.tool.Yes("操作成功", { id: roleId.data });
|
|
42
44
|
}
|
package/apis/role/menuSave.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import roleTable from "#root/tables/role.json";
|
|
2
|
+
|
|
3
|
+
import { getRoleByCode } from "./_role.js";
|
|
3
4
|
|
|
4
5
|
export default {
|
|
5
6
|
name: "保存角色菜单权限",
|
|
@@ -7,21 +8,14 @@ export default {
|
|
|
7
8
|
body: "none",
|
|
8
9
|
auth: true,
|
|
9
10
|
fields: {
|
|
10
|
-
roleCode:
|
|
11
|
-
menuPaths:
|
|
11
|
+
roleCode: roleTable.code,
|
|
12
|
+
menuPaths: roleTable.menus
|
|
12
13
|
},
|
|
13
|
-
required: [],
|
|
14
|
+
required: ["roleCode"],
|
|
14
15
|
handler: async (befly, ctx) => {
|
|
15
|
-
const roleCode = isNonEmptyString(ctx.body.roleCode) ? ctx.body.roleCode : "";
|
|
16
|
-
if (!isNonEmptyString(roleCode)) {
|
|
17
|
-
return befly.tool.No("参数不合法");
|
|
18
|
-
}
|
|
19
16
|
const menuPaths = ctx.body.menuPaths || [];
|
|
20
17
|
|
|
21
|
-
const role = await befly.
|
|
22
|
-
table: "beflyRole",
|
|
23
|
-
where: { code: roleCode }
|
|
24
|
-
});
|
|
18
|
+
const role = await getRoleByCode(befly, ctx.body.roleCode);
|
|
25
19
|
|
|
26
20
|
if (!role.data || !role.data.id) {
|
|
27
21
|
return befly.tool.No("角色不存在");
|
|
@@ -29,13 +23,13 @@ export default {
|
|
|
29
23
|
|
|
30
24
|
await befly.mysql.updData({
|
|
31
25
|
table: "beflyRole",
|
|
32
|
-
where: { code: roleCode },
|
|
26
|
+
where: { code: ctx.body.roleCode },
|
|
33
27
|
data: {
|
|
34
28
|
menus: menuPaths
|
|
35
29
|
}
|
|
36
30
|
});
|
|
37
31
|
|
|
38
|
-
await befly.cache.refreshRoleMenus(
|
|
32
|
+
await befly.cache.refreshRoleMenus(role.data.code, menuPaths);
|
|
39
33
|
|
|
40
34
|
return befly.tool.Yes("操作成功");
|
|
41
35
|
}
|
package/apis/role/menus.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isNonEmptyString } from "#root/utils/is.js";
|
|
1
|
+
import roleTable from "#root/tables/role.json";
|
|
3
2
|
|
|
4
3
|
export default {
|
|
5
4
|
name: "获取角色菜单权限",
|
|
@@ -7,16 +6,11 @@ export default {
|
|
|
7
6
|
body: "none",
|
|
8
7
|
auth: true,
|
|
9
8
|
fields: {
|
|
10
|
-
roleCode:
|
|
9
|
+
roleCode: roleTable.code
|
|
11
10
|
},
|
|
12
|
-
required: [],
|
|
11
|
+
required: ["roleCode"],
|
|
13
12
|
handler: async (befly, ctx) => {
|
|
14
|
-
const
|
|
15
|
-
if (!isNonEmptyString(roleCode)) {
|
|
16
|
-
return befly.tool.No("参数不合法");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const menuPaths = await befly.cache.getRoleMenus(roleCode);
|
|
13
|
+
const menuPaths = await befly.cache.getRoleMenus(ctx.body.roleCode);
|
|
20
14
|
return befly.tool.Yes("操作成功", menuPaths);
|
|
21
15
|
}
|
|
22
16
|
};
|
package/apis/role/save.js
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
|
+
import adminTable from "#root/tables/admin.json";
|
|
1
2
|
import roleTable from "#root/tables/role.json";
|
|
2
3
|
|
|
4
|
+
import { getRoleByCode } from "./_role.js";
|
|
5
|
+
|
|
3
6
|
export default {
|
|
4
7
|
name: "角色保存",
|
|
5
8
|
method: "POST",
|
|
6
9
|
body: "none",
|
|
7
10
|
auth: true,
|
|
8
11
|
fields: {
|
|
12
|
+
adminId: adminTable.id,
|
|
9
13
|
roleCode: roleTable.code
|
|
10
14
|
},
|
|
11
|
-
required: [],
|
|
15
|
+
required: ["adminId", "roleCode"],
|
|
12
16
|
handler: async (befly, ctx) => {
|
|
13
|
-
|
|
14
|
-
const role = await befly.mysql.getOne({
|
|
15
|
-
table: "beflyRole",
|
|
16
|
-
where: { code: ctx.body.roleCode }
|
|
17
|
-
});
|
|
17
|
+
const role = await getRoleByCode(befly, ctx.body.roleCode);
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
if (!role.data?.id) {
|
|
20
|
+
return befly.tool.No("角色不存在");
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const roleType = role.data.code === "dev" || role.data.code === "admin" ? "admin" : "user";
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
await befly.mysql.updData({
|
|
26
|
+
table: "beflyAdmin",
|
|
27
|
+
where: { id: ctx.body.adminId },
|
|
28
|
+
data: {
|
|
29
|
+
roleCode: role.data.code,
|
|
30
|
+
roleType: roleType
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
} catch (error) {
|
|
36
|
-
befly.logger.error("保存用户角色失败", error);
|
|
37
|
-
return befly.tool.No("操作失败");
|
|
38
|
-
}
|
|
34
|
+
return befly.tool.Yes("操作成功");
|
|
39
35
|
}
|
|
40
36
|
};
|
package/apis/role/select.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
|
+
import { queryFields } from "#root/apis/_apis.js";
|
|
2
|
+
import roleTable from "#root/tables/role.json";
|
|
3
|
+
|
|
1
4
|
export default {
|
|
2
5
|
name: "获取角色列表",
|
|
3
6
|
method: "POST",
|
|
4
7
|
body: "none",
|
|
5
8
|
auth: true,
|
|
6
9
|
fields: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
keyword: { name: "关键词", input: "string", min: 0, max: 50 },
|
|
10
|
-
state: { name: "状态", input: "integer", min: 0, max: 2 }
|
|
10
|
+
...queryFields,
|
|
11
|
+
state: roleTable.state
|
|
11
12
|
},
|
|
12
13
|
required: [],
|
|
13
|
-
handler: async (befly) => {
|
|
14
|
+
handler: async (befly, ctx) => {
|
|
14
15
|
const roles = await befly.mysql.getList({
|
|
15
|
-
limit: 30,
|
|
16
16
|
table: "beflyRole",
|
|
17
|
+
page: ctx.body.page,
|
|
18
|
+
limit: ctx.body.limit,
|
|
17
19
|
where: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
name$like$or: ctx.body.keyword,
|
|
21
|
+
code$like$or: ctx.body.keyword,
|
|
22
|
+
state: ctx.body.state,
|
|
23
|
+
code$not: "dev"
|
|
21
24
|
},
|
|
22
25
|
orderBy: ["sort#ASC", "id#ASC"]
|
|
23
26
|
});
|
package/apis/role/update.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import roleTable from "#root/tables/role.json";
|
|
2
|
+
|
|
3
|
+
import { getRoleById } from "./_role.js";
|
|
2
4
|
|
|
3
5
|
export default {
|
|
4
6
|
name: "更新角色",
|
|
@@ -6,20 +8,17 @@ export default {
|
|
|
6
8
|
body: "none",
|
|
7
9
|
auth: true,
|
|
8
10
|
fields: {
|
|
9
|
-
id:
|
|
10
|
-
name:
|
|
11
|
-
code:
|
|
12
|
-
description:
|
|
13
|
-
menus:
|
|
14
|
-
apis:
|
|
15
|
-
sort:
|
|
11
|
+
id: roleTable.id,
|
|
12
|
+
name: roleTable.name,
|
|
13
|
+
code: roleTable.code,
|
|
14
|
+
description: roleTable.description,
|
|
15
|
+
menus: roleTable.menus,
|
|
16
|
+
apis: roleTable.apis,
|
|
17
|
+
sort: roleTable.sort
|
|
16
18
|
},
|
|
17
19
|
required: ["id"],
|
|
18
20
|
handler: async (befly, ctx) => {
|
|
19
|
-
const role = await befly.
|
|
20
|
-
table: "beflyRole",
|
|
21
|
-
where: { id: ctx.body.id }
|
|
22
|
-
});
|
|
21
|
+
const role = await getRoleById(befly, ctx.body.id);
|
|
23
22
|
|
|
24
23
|
if (!role.data?.id) {
|
|
25
24
|
return befly.tool.No("角色不存在");
|
|
@@ -39,9 +38,9 @@ export default {
|
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
const roleCode = ctx.body.code
|
|
43
|
-
const apiPaths = ctx.body.apis
|
|
44
|
-
const menuPaths = ctx.body.menus
|
|
41
|
+
const roleCode = ctx.body.code === undefined ? role.data.code : ctx.body.code;
|
|
42
|
+
const apiPaths = ctx.body.apis === undefined ? role.data.apis || [] : ctx.body.apis;
|
|
43
|
+
const menuPaths = ctx.body.menus === undefined ? role.data.menus || [] : ctx.body.menus;
|
|
45
44
|
|
|
46
45
|
await befly.mysql.updData({
|
|
47
46
|
table: "beflyRole",
|
package/apis/source/imageList.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { queryFields } from "#root/apis/_apis.js";
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
name: "获取图库列表",
|
|
3
5
|
method: "POST",
|
|
4
6
|
body: "none",
|
|
5
7
|
auth: true,
|
|
6
8
|
fields: {
|
|
7
|
-
|
|
8
|
-
limit: { name: "每页数量", input: "integer", min: 1, max: 100 },
|
|
9
|
-
keyword: { name: "关键词", input: "string", min: 0, max: 100 }
|
|
9
|
+
...queryFields
|
|
10
10
|
},
|
|
11
11
|
required: [],
|
|
12
12
|
handler: async (befly, ctx) => {
|
package/apis/sysConfig/get.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import sysConfigTable from "#root/tables/sysConfig.json";
|
|
2
|
-
import { isString } from "#root/utils/is.js";
|
|
3
2
|
|
|
4
3
|
export default {
|
|
5
4
|
name: "根据代码获取配置值",
|
|
@@ -9,41 +8,30 @@ export default {
|
|
|
9
8
|
fields: {
|
|
10
9
|
code: sysConfigTable.code
|
|
11
10
|
},
|
|
12
|
-
required: [],
|
|
11
|
+
required: ["code"],
|
|
13
12
|
handler: async (befly, ctx) => {
|
|
14
13
|
const config = await befly.mysql.getOne({
|
|
15
14
|
table: "beflySysConfig",
|
|
16
15
|
where: { code: ctx.body.code }
|
|
17
16
|
});
|
|
18
17
|
|
|
19
|
-
if (!config.data
|
|
18
|
+
if (!config.data?.id) {
|
|
20
19
|
return befly.tool.No("配置不存在");
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const code = config.data.code;
|
|
30
|
-
if (!isString(code)) {
|
|
31
|
-
return befly.tool.No("配置数据不完整");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let value = rawValue;
|
|
35
|
-
if (valueType === "number") {
|
|
36
|
-
value = Number(rawValue);
|
|
37
|
-
} else if (valueType === "boolean") {
|
|
38
|
-
value = rawValue === "true" || rawValue === "1";
|
|
39
|
-
} else if (valueType === "json") {
|
|
22
|
+
let value = config.data.value;
|
|
23
|
+
if (config.data.valueType === "number") {
|
|
24
|
+
value = Number(config.data.value);
|
|
25
|
+
} else if (config.data.valueType === "boolean") {
|
|
26
|
+
value = config.data.value === "true" || config.data.value === "1";
|
|
27
|
+
} else if (config.data.valueType === "json") {
|
|
40
28
|
try {
|
|
41
|
-
value = JSON.parse(
|
|
29
|
+
value = JSON.parse(config.data.value);
|
|
42
30
|
} catch {
|
|
43
|
-
value =
|
|
31
|
+
value = config.data.value;
|
|
44
32
|
}
|
|
45
33
|
}
|
|
46
34
|
|
|
47
|
-
return befly.tool.Yes("操作成功", { code: code, value: value });
|
|
35
|
+
return befly.tool.Yes("操作成功", { code: config.data.code, value: value });
|
|
48
36
|
}
|
|
49
37
|
};
|