befly 3.23.7 → 3.24.0
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/admin/{del.js → delete.js} +3 -6
- package/apis/admin/{ins.js → insert.js} +6 -13
- package/apis/admin/update.js +92 -0
- package/apis/dict/{del.js → delete.js} +3 -1
- package/apis/dict/{ins.js → insert.js} +2 -2
- package/apis/dict/{upd.js → update.js} +16 -25
- package/apis/dictType/{del.js → delete.js} +8 -8
- package/apis/dictType/{ins.js → insert.js} +1 -1
- package/apis/dictType/{upd.js → update.js} +11 -9
- package/apis/role/{del.js → delete.js} +3 -3
- package/apis/role/{ins.js → insert.js} +4 -7
- package/apis/role/update.js +67 -0
- package/apis/sysConfig/{del.js → delete.js} +1 -1
- package/apis/sysConfig/{ins.js → insert.js} +1 -1
- package/apis/sysConfig/{upd.js → update.js} +1 -1
- package/package.json +2 -2
- package/apis/admin/upd.js +0 -95
- package/apis/role/upd.js +0 -50
|
@@ -8,22 +8,19 @@ export default {
|
|
|
8
8
|
},
|
|
9
9
|
required: ["id"],
|
|
10
10
|
handler: async (befly, ctx) => {
|
|
11
|
-
|
|
12
|
-
const adminData = await befly.mysql.getOne({
|
|
11
|
+
const admin = await befly.mysql.getOne({
|
|
13
12
|
table: "beflyAdmin",
|
|
14
13
|
where: { id: ctx.body.id }
|
|
15
14
|
});
|
|
16
15
|
|
|
17
|
-
if (!
|
|
16
|
+
if (!admin.data?.id) {
|
|
18
17
|
return befly.tool.No("管理员不存在");
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
if (adminData.data.roleCode === "dev") {
|
|
20
|
+
if (admin.data.roleCode === "dev") {
|
|
23
21
|
return befly.tool.No("不能删除开发管理员");
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
// 删除管理员
|
|
27
24
|
await befly.mysql.delData({
|
|
28
25
|
table: "beflyAdmin",
|
|
29
26
|
where: { id: ctx.body.id }
|
|
@@ -14,7 +14,6 @@ export default {
|
|
|
14
14
|
},
|
|
15
15
|
required: ["username", "password", "roleCode"],
|
|
16
16
|
handler: async (befly, ctx) => {
|
|
17
|
-
// 检查用户名是否已存在
|
|
18
17
|
const existingByUsername = await befly.mysql.getOne({
|
|
19
18
|
table: "beflyAdmin",
|
|
20
19
|
where: { username: ctx.body.username }
|
|
@@ -24,7 +23,6 @@ export default {
|
|
|
24
23
|
return befly.tool.No("用户名已被使用");
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
// 检查昵称是否已存在
|
|
28
26
|
if (ctx.body.nickname) {
|
|
29
27
|
const existingByNickname = await befly.mysql.getOne({
|
|
30
28
|
table: "beflyAdmin",
|
|
@@ -36,22 +34,19 @@ export default {
|
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
const roleData = await befly.mysql.getOne({
|
|
37
|
+
const role = await befly.mysql.getOne({
|
|
41
38
|
table: "beflyRole",
|
|
42
39
|
where: { code: ctx.body.roleCode }
|
|
43
40
|
});
|
|
44
41
|
|
|
45
|
-
if (!
|
|
42
|
+
if (!role.data?.id) {
|
|
46
43
|
return befly.tool.No("角色不存在");
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const hashedPassword = isSha256Hex ? befly.tool.sha256(incoming) : befly.tool.sha256(befly.tool.sha256(ctx.body.password));
|
|
46
|
+
const passwordSource = isString(ctx.body.password) ? ctx.body.password.toLowerCase() : "";
|
|
47
|
+
const isSha256Hex = /^[a-f0-9]{64}$/.test(passwordSource);
|
|
48
|
+
const hashedPassword = isSha256Hex ? befly.tool.sha256(passwordSource) : befly.tool.sha256(befly.tool.sha256(ctx.body.password));
|
|
53
49
|
|
|
54
|
-
// 创建管理员
|
|
55
50
|
const adminId = await befly.mysql.insData({
|
|
56
51
|
table: "beflyAdmin",
|
|
57
52
|
data: {
|
|
@@ -62,8 +57,6 @@ export default {
|
|
|
62
57
|
}
|
|
63
58
|
});
|
|
64
59
|
|
|
65
|
-
return befly.tool.Yes("添加成功", {
|
|
66
|
-
id: adminId.data
|
|
67
|
-
});
|
|
60
|
+
return befly.tool.Yes("添加成功", { id: adminId.data });
|
|
68
61
|
}
|
|
69
62
|
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import adminTable from "../../tables/admin.json";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: "更新管理员",
|
|
5
|
+
method: "POST",
|
|
6
|
+
body: "none",
|
|
7
|
+
auth: true,
|
|
8
|
+
fields: {
|
|
9
|
+
id: { name: "ID", input: "integer", min: 1, max: null },
|
|
10
|
+
username: adminTable.username,
|
|
11
|
+
nickname: adminTable.nickname,
|
|
12
|
+
roleCode: adminTable.roleCode,
|
|
13
|
+
avatar: adminTable.avatar,
|
|
14
|
+
email: adminTable.email,
|
|
15
|
+
lastLoginIp: adminTable.lastLoginIp,
|
|
16
|
+
lastLoginTime: adminTable.lastLoginTime,
|
|
17
|
+
password: adminTable.password,
|
|
18
|
+
phone: adminTable.phone,
|
|
19
|
+
roleType: adminTable.roleType
|
|
20
|
+
},
|
|
21
|
+
required: ["id"],
|
|
22
|
+
handler: async (befly, ctx) => {
|
|
23
|
+
const admin = await befly.mysql.getOne({
|
|
24
|
+
table: "beflyAdmin",
|
|
25
|
+
where: { id: ctx.body.id }
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (!admin.data?.id) {
|
|
29
|
+
return befly.tool.No("管理员不存在");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (ctx.body.username && ctx.body.username !== admin.data.username) {
|
|
33
|
+
const existingUsername = await befly.mysql.getOne({
|
|
34
|
+
table: "beflyAdmin",
|
|
35
|
+
where: {
|
|
36
|
+
username: ctx.body.username,
|
|
37
|
+
id: { $not: ctx.body.id }
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (existingUsername.data?.id) {
|
|
42
|
+
return befly.tool.No("用户名已被使用");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (ctx.body.nickname && ctx.body.nickname !== admin.data.nickname) {
|
|
47
|
+
const existingNickname = await befly.mysql.getOne({
|
|
48
|
+
table: "beflyAdmin",
|
|
49
|
+
where: {
|
|
50
|
+
nickname: ctx.body.nickname,
|
|
51
|
+
id: { $not: ctx.body.id }
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (existingNickname.data?.id) {
|
|
56
|
+
return befly.tool.No("昵称已被使用");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (ctx.body.roleCode && ctx.body.roleCode !== admin.data.roleCode) {
|
|
61
|
+
const role = await befly.mysql.getOne({
|
|
62
|
+
table: "beflyRole",
|
|
63
|
+
where: { code: ctx.body.roleCode }
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (!role.data?.id) {
|
|
67
|
+
return befly.tool.No("角色不存在");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const updateData = {};
|
|
72
|
+
|
|
73
|
+
if (ctx.body.avatar !== undefined) updateData.avatar = ctx.body.avatar;
|
|
74
|
+
if (ctx.body.email !== undefined) updateData.email = ctx.body.email;
|
|
75
|
+
if (ctx.body.lastLoginIp !== undefined) updateData.lastLoginIp = ctx.body.lastLoginIp;
|
|
76
|
+
if (ctx.body.lastLoginTime !== undefined) updateData.lastLoginTime = ctx.body.lastLoginTime;
|
|
77
|
+
if (ctx.body.password !== undefined) updateData.password = ctx.body.password;
|
|
78
|
+
if (ctx.body.phone !== undefined) updateData.phone = ctx.body.phone;
|
|
79
|
+
if (ctx.body.roleType !== undefined) updateData.roleType = ctx.body.roleType;
|
|
80
|
+
if (ctx.body.username !== undefined) updateData.username = ctx.body.username;
|
|
81
|
+
if (ctx.body.nickname !== undefined) updateData.nickname = ctx.body.nickname;
|
|
82
|
+
if (ctx.body.roleCode !== undefined) updateData.roleCode = ctx.body.roleCode;
|
|
83
|
+
|
|
84
|
+
await befly.mysql.updData({
|
|
85
|
+
table: "beflyAdmin",
|
|
86
|
+
data: updateData,
|
|
87
|
+
where: { id: ctx.body.id }
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return befly.tool.Yes("更新成功");
|
|
91
|
+
}
|
|
92
|
+
};
|
|
@@ -3,7 +3,9 @@ export default {
|
|
|
3
3
|
method: "POST",
|
|
4
4
|
body: "none",
|
|
5
5
|
auth: true,
|
|
6
|
-
fields: {
|
|
6
|
+
fields: {
|
|
7
|
+
id: { name: "ID", input: "integer", min: 1, max: null }
|
|
8
|
+
},
|
|
7
9
|
required: ["id"],
|
|
8
10
|
handler: async (befly, ctx) => {
|
|
9
11
|
await befly.mysql.delData({
|
|
@@ -19,7 +19,7 @@ export default {
|
|
|
19
19
|
where: { code: ctx.body.typeCode }
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
if (!dictType.data
|
|
22
|
+
if (!dictType.data?.id) {
|
|
23
23
|
return befly.tool.No("字典类型不存在");
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -31,7 +31,7 @@ export default {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
if (existing.data
|
|
34
|
+
if (existing.data?.id) {
|
|
35
35
|
return befly.tool.No("该类型下已存在相同的键名");
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -15,58 +15,49 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
required: ["id"],
|
|
17
17
|
handler: async (befly, ctx) => {
|
|
18
|
-
|
|
19
|
-
const typeCode = ctx.body.typeCode;
|
|
20
|
-
const key = ctx.body.key;
|
|
21
|
-
const label = ctx.body.label;
|
|
22
|
-
const sort = ctx.body.sort;
|
|
23
|
-
const remark = ctx.body.remark;
|
|
24
|
-
|
|
25
|
-
if (typeCode) {
|
|
18
|
+
if (ctx.body.typeCode !== undefined) {
|
|
26
19
|
const dictType = await befly.mysql.getOne({
|
|
27
20
|
table: "beflyDictType",
|
|
28
|
-
where: { code: typeCode }
|
|
21
|
+
where: { code: ctx.body.typeCode }
|
|
29
22
|
});
|
|
30
23
|
|
|
31
|
-
if (!dictType.data
|
|
24
|
+
if (!dictType.data?.id) {
|
|
32
25
|
return befly.tool.No("字典类型不存在");
|
|
33
26
|
}
|
|
34
27
|
}
|
|
35
28
|
|
|
36
|
-
if (typeCode || key) {
|
|
29
|
+
if (ctx.body.typeCode !== undefined || ctx.body.key !== undefined) {
|
|
37
30
|
const current = await befly.mysql.getOne({
|
|
38
31
|
table: "beflyDict",
|
|
39
|
-
where: { id: id }
|
|
32
|
+
where: { id: ctx.body.id }
|
|
40
33
|
});
|
|
41
34
|
|
|
42
|
-
const checkTypeCode = typeCode || (current.data ? current.data.typeCode : undefined);
|
|
43
|
-
const checkKey = key || (current.data ? current.data.key : undefined);
|
|
44
|
-
|
|
45
35
|
const existing = await befly.mysql.getOne({
|
|
46
36
|
table: "beflyDict",
|
|
47
37
|
where: {
|
|
48
|
-
typeCode:
|
|
49
|
-
key:
|
|
50
|
-
id$not: id
|
|
38
|
+
typeCode: ctx.body.typeCode !== undefined ? ctx.body.typeCode : current.data?.typeCode,
|
|
39
|
+
key: ctx.body.key !== undefined ? ctx.body.key : current.data?.key,
|
|
40
|
+
id$not: ctx.body.id
|
|
51
41
|
}
|
|
52
42
|
});
|
|
53
43
|
|
|
54
|
-
if (existing.data
|
|
44
|
+
if (existing.data?.id) {
|
|
55
45
|
return befly.tool.No("该类型下已存在相同的键名");
|
|
56
46
|
}
|
|
57
47
|
}
|
|
58
48
|
|
|
59
49
|
const updateData = {};
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
if (
|
|
63
|
-
if (
|
|
64
|
-
if (
|
|
50
|
+
|
|
51
|
+
if (ctx.body.typeCode !== undefined) updateData.typeCode = ctx.body.typeCode;
|
|
52
|
+
if (ctx.body.key !== undefined) updateData.key = ctx.body.key;
|
|
53
|
+
if (ctx.body.label !== undefined) updateData.label = ctx.body.label;
|
|
54
|
+
if (ctx.body.sort !== undefined) updateData.sort = ctx.body.sort;
|
|
55
|
+
if (ctx.body.remark !== undefined) updateData.remark = ctx.body.remark;
|
|
65
56
|
|
|
66
57
|
await befly.mysql.updData({
|
|
67
58
|
table: "beflyDict",
|
|
68
59
|
data: updateData,
|
|
69
|
-
where: { id: id }
|
|
60
|
+
where: { id: ctx.body.id }
|
|
70
61
|
});
|
|
71
62
|
|
|
72
63
|
return befly.tool.Yes("更新成功");
|
|
@@ -3,34 +3,34 @@ export default {
|
|
|
3
3
|
method: "POST",
|
|
4
4
|
body: "none",
|
|
5
5
|
auth: true,
|
|
6
|
-
fields: {
|
|
6
|
+
fields: {
|
|
7
|
+
id: { name: "ID", input: "integer", min: 1, max: null }
|
|
8
|
+
},
|
|
7
9
|
required: ["id"],
|
|
8
10
|
handler: async (befly, ctx) => {
|
|
9
|
-
const id = ctx.body.id;
|
|
10
|
-
|
|
11
11
|
const dictType = await befly.mysql.getOne({
|
|
12
12
|
table: "beflyDictType",
|
|
13
|
-
where: { id: id }
|
|
13
|
+
where: { id: ctx.body.id }
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
if (!dictType.data
|
|
16
|
+
if (!dictType.data?.code) {
|
|
17
17
|
return befly.tool.No("字典类型不存在");
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const
|
|
20
|
+
const dictItem = await befly.mysql.getOne({
|
|
21
21
|
table: "beflyDict",
|
|
22
22
|
where: {
|
|
23
23
|
typeCode: dictType.data.code
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
if (
|
|
27
|
+
if (dictItem.data?.id) {
|
|
28
28
|
return befly.tool.No("该类型下存在字典项,无法删除");
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
await befly.mysql.delData({
|
|
32
32
|
table: "beflyDictType",
|
|
33
|
-
where: { id: id }
|
|
33
|
+
where: { id: ctx.body.id }
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
return befly.tool.Yes("删除成功");
|
|
@@ -15,16 +15,18 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
required: ["id"],
|
|
17
17
|
handler: async (befly, ctx) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
if (ctx.body.code !== undefined) {
|
|
19
|
+
const existing = await befly.mysql.getOne({
|
|
20
|
+
table: "beflyDictType",
|
|
21
|
+
where: {
|
|
22
|
+
code: ctx.body.code,
|
|
23
|
+
id$not: ctx.body.id
|
|
24
|
+
}
|
|
25
|
+
});
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
if (existing.data?.id) {
|
|
28
|
+
return befly.tool.No("类型代码已被使用");
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
await befly.mysql.updData({
|
|
@@ -15,12 +15,12 @@ export default {
|
|
|
15
15
|
fields: ["code"]
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
if (!role.data
|
|
18
|
+
if (!role.data?.code) {
|
|
19
19
|
return befly.tool.No("角色不存在");
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
22
|
+
const systemRoleCodes = ["dev", "user", "admin", "guest"];
|
|
23
|
+
if (systemRoleCodes.includes(role.data.code)) {
|
|
24
24
|
return befly.tool.No(`系统角色 [${role.data.code}] 不允许删除`);
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -15,15 +15,12 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
required: [],
|
|
17
17
|
handler: async (befly, ctx) => {
|
|
18
|
-
const apiPaths = ctx.body.apis || [];
|
|
19
|
-
const menuPaths = ctx.body.menus || [];
|
|
20
|
-
|
|
21
18
|
const existing = await befly.mysql.getOne({
|
|
22
19
|
table: "beflyRole",
|
|
23
20
|
where: { code: ctx.body.code }
|
|
24
21
|
});
|
|
25
22
|
|
|
26
|
-
if (existing.data
|
|
23
|
+
if (existing.data?.id) {
|
|
27
24
|
return befly.tool.No("角色代码已存在");
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -33,13 +30,13 @@ export default {
|
|
|
33
30
|
name: ctx.body.name,
|
|
34
31
|
code: ctx.body.code,
|
|
35
32
|
description: ctx.body.description,
|
|
36
|
-
menus:
|
|
37
|
-
apis:
|
|
33
|
+
menus: ctx.body.menus || [],
|
|
34
|
+
apis: ctx.body.apis || [],
|
|
38
35
|
sort: ctx.body.sort
|
|
39
36
|
}
|
|
40
37
|
});
|
|
41
38
|
|
|
42
|
-
await befly.cache.refreshRoleApis(ctx.body.code,
|
|
39
|
+
await befly.cache.refreshRoleApis(ctx.body.code, ctx.body.apis || []);
|
|
43
40
|
|
|
44
41
|
return befly.tool.Yes("操作成功", { id: roleId.data });
|
|
45
42
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import adminRoleTable from "../../tables/role.json";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: "更新角色",
|
|
5
|
+
method: "POST",
|
|
6
|
+
body: "none",
|
|
7
|
+
auth: true,
|
|
8
|
+
fields: {
|
|
9
|
+
id: { name: "ID", input: "integer", min: 1, max: null },
|
|
10
|
+
name: adminRoleTable.name,
|
|
11
|
+
code: adminRoleTable.code,
|
|
12
|
+
description: adminRoleTable.description,
|
|
13
|
+
menus: adminRoleTable.menus,
|
|
14
|
+
apis: adminRoleTable.apis,
|
|
15
|
+
sort: adminRoleTable.sort
|
|
16
|
+
},
|
|
17
|
+
required: ["id"],
|
|
18
|
+
handler: async (befly, ctx) => {
|
|
19
|
+
const role = await befly.mysql.getOne({
|
|
20
|
+
table: "beflyRole",
|
|
21
|
+
where: { id: ctx.body.id }
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (!role.data?.id) {
|
|
25
|
+
return befly.tool.No("角色不存在");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (ctx.body.code !== undefined) {
|
|
29
|
+
const existing = await befly.mysql.getOne({
|
|
30
|
+
table: "beflyRole",
|
|
31
|
+
where: {
|
|
32
|
+
code: ctx.body.code,
|
|
33
|
+
id$not: ctx.body.id
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (existing.data?.id) {
|
|
38
|
+
return befly.tool.No("角色代码已被其他角色使用");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const roleCode = ctx.body.code !== undefined ? ctx.body.code : role.data.code;
|
|
43
|
+
const apiPaths = ctx.body.apis !== undefined ? ctx.body.apis : role.data.apis || [];
|
|
44
|
+
const menuPaths = ctx.body.menus !== undefined ? ctx.body.menus : role.data.menus || [];
|
|
45
|
+
|
|
46
|
+
await befly.mysql.updData({
|
|
47
|
+
table: "beflyRole",
|
|
48
|
+
where: { id: ctx.body.id },
|
|
49
|
+
data: {
|
|
50
|
+
name: ctx.body.name,
|
|
51
|
+
code: roleCode,
|
|
52
|
+
description: ctx.body.description,
|
|
53
|
+
menus: menuPaths,
|
|
54
|
+
apis: apiPaths,
|
|
55
|
+
sort: ctx.body.sort
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (role.data.code !== roleCode) {
|
|
60
|
+
await befly.cache.deleteRoleApis(role.data.code);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
await befly.cache.refreshRoleApis(roleCode, apiPaths);
|
|
64
|
+
|
|
65
|
+
return befly.tool.Yes("操作成功");
|
|
66
|
+
}
|
|
67
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.24.0",
|
|
4
|
+
"gitHead": "976e70ee1f6f959e9def8189bd43ad4c0d454b7f",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|
package/apis/admin/upd.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import adminTable from "../../tables/admin.json";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
name: "更新管理员",
|
|
5
|
-
method: "POST",
|
|
6
|
-
body: "none",
|
|
7
|
-
auth: true,
|
|
8
|
-
fields: {
|
|
9
|
-
id: { name: "ID", input: "integer", min: 1, max: null },
|
|
10
|
-
username: adminTable.username,
|
|
11
|
-
nickname: adminTable.nickname,
|
|
12
|
-
roleCode: adminTable.roleCode,
|
|
13
|
-
avatar: adminTable.avatar,
|
|
14
|
-
email: adminTable.email,
|
|
15
|
-
lastLoginIp: adminTable.lastLoginIp,
|
|
16
|
-
lastLoginTime: adminTable.lastLoginTime,
|
|
17
|
-
password: adminTable.password,
|
|
18
|
-
phone: adminTable.phone,
|
|
19
|
-
roleType: adminTable.roleType
|
|
20
|
-
},
|
|
21
|
-
required: ["id"],
|
|
22
|
-
handler: async (befly, ctx) => {
|
|
23
|
-
const id = ctx.body.id;
|
|
24
|
-
const username = ctx.body.username;
|
|
25
|
-
const nickname = ctx.body.nickname;
|
|
26
|
-
const roleCode = ctx.body.roleCode;
|
|
27
|
-
|
|
28
|
-
// 检查管理员是否存在
|
|
29
|
-
const admin = await befly.mysql.getOne({
|
|
30
|
-
table: "beflyAdmin",
|
|
31
|
-
where: { id: id }
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (!admin.data?.id) {
|
|
35
|
-
return befly.tool.No("管理员不存在");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 检查用户名是否已被其他管理员使用
|
|
39
|
-
if (username && username !== admin.data.username) {
|
|
40
|
-
const existingUsername = await befly.mysql.getOne({
|
|
41
|
-
table: "beflyAdmin",
|
|
42
|
-
where: { username: username, id: { $not: id } }
|
|
43
|
-
});
|
|
44
|
-
if (existingUsername.data?.id) {
|
|
45
|
-
return befly.tool.No("用户名已被使用");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 检查昵称是否已被其他管理员使用
|
|
50
|
-
if (nickname && nickname !== admin.data.nickname) {
|
|
51
|
-
const existingNickname = await befly.mysql.getOne({
|
|
52
|
-
table: "beflyAdmin",
|
|
53
|
-
where: { nickname: nickname, id: { $not: id } }
|
|
54
|
-
});
|
|
55
|
-
if (existingNickname.data?.id) {
|
|
56
|
-
return befly.tool.No("昵称已被使用");
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 检查角色是否存在
|
|
61
|
-
if (roleCode && roleCode !== admin.data.roleCode) {
|
|
62
|
-
const role = await befly.mysql.getOne({
|
|
63
|
-
table: "beflyRole",
|
|
64
|
-
where: { code: roleCode }
|
|
65
|
-
});
|
|
66
|
-
if (!role.data?.id) {
|
|
67
|
-
return befly.tool.No("角色不存在");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 构建更新数据
|
|
72
|
-
const dataToUpdate = {};
|
|
73
|
-
|
|
74
|
-
if (ctx.body.avatar !== undefined) dataToUpdate["avatar"] = ctx.body.avatar;
|
|
75
|
-
if (ctx.body.email !== undefined) dataToUpdate["email"] = ctx.body.email;
|
|
76
|
-
if (ctx.body.lastLoginIp !== undefined) dataToUpdate["lastLoginIp"] = ctx.body.lastLoginIp;
|
|
77
|
-
if (ctx.body.lastLoginTime !== undefined) dataToUpdate["lastLoginTime"] = ctx.body.lastLoginTime;
|
|
78
|
-
if (ctx.body.password !== undefined) dataToUpdate["password"] = ctx.body.password;
|
|
79
|
-
if (ctx.body.phone !== undefined) dataToUpdate["phone"] = ctx.body.phone;
|
|
80
|
-
if (ctx.body.roleType !== undefined) dataToUpdate["roleType"] = ctx.body.roleType;
|
|
81
|
-
|
|
82
|
-
if (username !== undefined) dataToUpdate["username"] = username;
|
|
83
|
-
if (nickname !== undefined) dataToUpdate["nickname"] = nickname;
|
|
84
|
-
if (roleCode !== undefined) dataToUpdate["roleCode"] = roleCode;
|
|
85
|
-
|
|
86
|
-
// 更新管理员信息
|
|
87
|
-
await befly.mysql.updData({
|
|
88
|
-
table: "beflyAdmin",
|
|
89
|
-
data: dataToUpdate,
|
|
90
|
-
where: { id: id }
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return befly.tool.Yes("更新成功");
|
|
94
|
-
}
|
|
95
|
-
};
|
package/apis/role/upd.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import adminRoleTable from "../../tables/role.json";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
name: "更新角色",
|
|
5
|
-
method: "POST",
|
|
6
|
-
body: "none",
|
|
7
|
-
auth: true,
|
|
8
|
-
fields: {
|
|
9
|
-
name: adminRoleTable.name,
|
|
10
|
-
code: adminRoleTable.code,
|
|
11
|
-
description: adminRoleTable.description,
|
|
12
|
-
menus: adminRoleTable.menus,
|
|
13
|
-
apis: adminRoleTable.apis,
|
|
14
|
-
sort: adminRoleTable.sort
|
|
15
|
-
},
|
|
16
|
-
required: [],
|
|
17
|
-
handler: async (befly, ctx) => {
|
|
18
|
-
const apiPaths = ctx.body.apis || [];
|
|
19
|
-
const menuPaths = ctx.body.menus || [];
|
|
20
|
-
|
|
21
|
-
const existing = await befly.mysql.getList({
|
|
22
|
-
table: "beflyRole",
|
|
23
|
-
where: {
|
|
24
|
-
code: ctx.body.code,
|
|
25
|
-
id$not: ctx.body.id
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
if (existing.data.total > 0) {
|
|
30
|
-
return befly.tool.No("角色代码已被其他角色使用");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
await befly.mysql.updData({
|
|
34
|
-
table: "beflyRole",
|
|
35
|
-
where: { id: ctx.body.id },
|
|
36
|
-
data: {
|
|
37
|
-
name: ctx.body.name,
|
|
38
|
-
code: ctx.body.code,
|
|
39
|
-
description: ctx.body.description,
|
|
40
|
-
menus: menuPaths,
|
|
41
|
-
apis: apiPaths,
|
|
42
|
-
sort: ctx.body.sort
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
await befly.cache.refreshRoleApis(ctx.body.code, apiPaths);
|
|
47
|
-
|
|
48
|
-
return befly.tool.Yes("操作成功");
|
|
49
|
-
}
|
|
50
|
-
};
|