@befly-addon/admin 1.0.7 → 1.0.8
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/cacheRefresh.ts +100 -0
- package/apis/auth/login.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 刷新全部缓存接口
|
|
3
|
+
*
|
|
4
|
+
* 功能:
|
|
5
|
+
* 1. 刷新接口缓存(apis:all)
|
|
6
|
+
* 2. 刷新菜单缓存(menus:all)
|
|
7
|
+
* 3. 刷新角色权限缓存(role:{code})
|
|
8
|
+
*
|
|
9
|
+
* 使用场景:
|
|
10
|
+
* - 执行数据库同步后
|
|
11
|
+
* - 手动修改配置需要立即生效
|
|
12
|
+
* - 缓存出现异常需要重建
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { Yes, No } from 'befly';
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
name: '刷新全部缓存',
|
|
19
|
+
handler: async (befly, ctx) => {
|
|
20
|
+
try {
|
|
21
|
+
const results: Record<string, any> = {
|
|
22
|
+
apis: { success: false, count: 0 },
|
|
23
|
+
menus: { success: false, count: 0 },
|
|
24
|
+
roles: { success: false, count: 0 }
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 1. 刷新接口缓存
|
|
28
|
+
try {
|
|
29
|
+
const apis = await befly.db.getAll({
|
|
30
|
+
table: 'addon_admin_api',
|
|
31
|
+
fields: ['id', 'name', 'path', 'method', 'description', 'addonName', 'addonTitle'],
|
|
32
|
+
orderBy: ['addonName#ASC', 'path#ASC']
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await befly.redis.setObject('apis:all', apis);
|
|
36
|
+
results.apis = { success: true, count: apis.length };
|
|
37
|
+
} catch (error: any) {
|
|
38
|
+
befly.logger.error('刷新接口缓存失败:', error);
|
|
39
|
+
results.apis = { success: false, error: error.message };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 2. 刷新菜单缓存
|
|
43
|
+
try {
|
|
44
|
+
const menus = await befly.db.getAll({
|
|
45
|
+
table: 'addon_admin_menu',
|
|
46
|
+
fields: ['id', 'pid', 'name', 'path', 'icon', 'type', 'sort'],
|
|
47
|
+
orderBy: ['sort#ASC', 'id#ASC']
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await befly.redis.setObject('menus:all', menus);
|
|
51
|
+
|
|
52
|
+
const parentCount = menus.filter((m: any) => m.pid === 0).length;
|
|
53
|
+
const childCount = menus.filter((m: any) => m.pid !== 0).length;
|
|
54
|
+
|
|
55
|
+
results.menus = {
|
|
56
|
+
success: true,
|
|
57
|
+
count: menus.length,
|
|
58
|
+
parentCount: parentCount,
|
|
59
|
+
childCount: childCount
|
|
60
|
+
};
|
|
61
|
+
} catch (error: any) {
|
|
62
|
+
befly.logger.error('刷新菜单缓存失败:', error);
|
|
63
|
+
results.menus = { success: false, error: error.message };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 3. 刷新角色权限缓存
|
|
67
|
+
try {
|
|
68
|
+
const roles = await befly.db.getAll({
|
|
69
|
+
table: 'addon_admin_role',
|
|
70
|
+
fields: ['id', 'name', 'code', 'apis', 'menus'],
|
|
71
|
+
orderBy: ['id#ASC']
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// 为每个角色单独缓存
|
|
75
|
+
let cachedCount = 0;
|
|
76
|
+
for (const role of roles) {
|
|
77
|
+
await befly.redis.setObject(`role:${role.code}`, role);
|
|
78
|
+
cachedCount++;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
results.roles = { success: true, count: cachedCount };
|
|
82
|
+
} catch (error: any) {
|
|
83
|
+
befly.logger.error('刷新角色缓存失败:', error);
|
|
84
|
+
results.roles = { success: false, error: error.message };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 检查是否全部成功
|
|
88
|
+
const allSuccess = results.apis.success && results.menus.success && results.roles.success;
|
|
89
|
+
|
|
90
|
+
if (allSuccess) {
|
|
91
|
+
return Yes('全部缓存刷新成功', results);
|
|
92
|
+
} else {
|
|
93
|
+
return No('部分缓存刷新失败', results);
|
|
94
|
+
}
|
|
95
|
+
} catch (error: any) {
|
|
96
|
+
befly.logger.error('刷新全部缓存失败:', error);
|
|
97
|
+
return No('刷新全部缓存失败', { error: error.message });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
package/apis/auth/login.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@befly-addon/admin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Befly Admin Addon - 管理后台功能组件",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"befly": "^3.0.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "c9933a45ed268f79ee3428d8c9179fbe885cb888"
|
|
39
39
|
}
|