@befly-addon/admin 1.0.10 → 1.0.12

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.
Files changed (38) hide show
  1. package/apis/api/all.ts +6 -11
  2. package/apis/menu/all.ts +9 -15
  3. package/apis/menu/list.ts +1 -1
  4. package/apis/menu/upd.ts +1 -2
  5. package/package.json +15 -4
  6. package/tables/menu.json +0 -13
  7. package/util.ts +1 -150
  8. package/views/403/index.vue +68 -0
  9. package/views/admin/components/edit.vue +150 -0
  10. package/views/admin/components/role.vue +138 -0
  11. package/views/admin/index.vue +179 -0
  12. package/views/dict/components/edit.vue +159 -0
  13. package/views/dict/index.vue +162 -0
  14. package/views/index/components/addonList.vue +127 -0
  15. package/views/index/components/environmentInfo.vue +99 -0
  16. package/views/index/components/operationLogs.vue +114 -0
  17. package/views/index/components/performanceMetrics.vue +150 -0
  18. package/views/index/components/quickActions.vue +27 -0
  19. package/views/index/components/serviceStatus.vue +183 -0
  20. package/views/index/components/systemNotifications.vue +132 -0
  21. package/views/index/components/systemOverview.vue +190 -0
  22. package/views/index/components/systemResources.vue +106 -0
  23. package/views/index/components/userInfo.vue +206 -0
  24. package/views/index/index.vue +29 -0
  25. package/views/login/components/emailLoginForm.vue +167 -0
  26. package/views/login/components/registerForm.vue +170 -0
  27. package/views/login/components/welcomePanel.vue +61 -0
  28. package/views/login/index.vue +191 -0
  29. package/views/menu/components/edit.vue +144 -0
  30. package/views/menu/index.vue +171 -0
  31. package/views/news/detail/index.vue +26 -0
  32. package/views/news/index.vue +26 -0
  33. package/views/role/components/api.vue +283 -0
  34. package/views/role/components/edit.vue +132 -0
  35. package/views/role/components/menu.vue +146 -0
  36. package/views/role/index.vue +179 -0
  37. package/views/user/index.vue +322 -0
  38. package/apis/dashboard/addonList.ts +0 -47
@@ -0,0 +1,322 @@
1
+ <template>
2
+ <div class="user-manage">
3
+ <!-- 上:过滤和操作栏 -->
4
+ <div class="toolbar">
5
+ <div class="toolbar-left">
6
+ <t-button theme="primary" @click="$Method.handleAdd">
7
+ <template #icon>
8
+ <i-lucide:plus style="width: 16px; height: 16px" />
9
+ </template>
10
+ 添加管理员
11
+ </t-button>
12
+ </div>
13
+ <div class="toolbar-right">
14
+ <t-space>
15
+ <t-input v-model="$Data.searchKeyword" placeholder="搜索用户名/邮箱" clearable style="width: 200px" @enter="$Method.handleSearch" />
16
+ <t-select v-model="$Data.searchState" placeholder="状态" clearable style="width: 120px" :options="$Data.stateOptions" @change="$Method.handleSearch" />
17
+ <t-button theme="default" @click="$Method.handleSearch">
18
+ <template #icon>
19
+ <i-lucide:search style="width: 16px; height: 16px" />
20
+ </template>
21
+ 搜索
22
+ </t-button>
23
+ <t-button theme="default" @click="$Method.handleReset">
24
+ <template #icon>
25
+ <i-lucide:rotate-cw style="width: 16px; height: 16px" />
26
+ </template>
27
+ 重置
28
+ </t-button>
29
+ </t-space>
30
+ </div>
31
+ </div>
32
+
33
+ <!-- 中:数据表格 -->
34
+ <div class="table-wrapper">
35
+ <t-table :data="$Data.userList" :columns="$Data.columns" row-key="id" :loading="$Data.loading" bordered stripe hover max-height="100%">
36
+ <template #state="{ row }">
37
+ <tiny-tag v-if="row.state === 1" type="success">正常</tiny-tag>
38
+ <tiny-tag v-else-if="row.state === 2" type="warning">禁用</tiny-tag>
39
+ <tiny-tag v-else type="danger">已删除</tiny-tag>
40
+ </template>
41
+
42
+ <template #lastLoginTime="{ row }">
43
+ <span v-if="row.lastLoginTime">{{ new Date(Number(row.lastLoginTime)).toLocaleString() }}</span>
44
+ <span v-else>-</span>
45
+ </template>
46
+
47
+ <template #operation="{ row }">
48
+ <t-space>
49
+ <t-link theme="primary" @click="$Method.handleRole(row)">分配角色</t-link>
50
+ <t-link theme="warning" @click="$Method.handleEdit(row)">编辑</t-link>
51
+ <t-link theme="danger" @click="$Method.handleDelete(row)">删除</t-link>
52
+ </t-space>
53
+ </template>
54
+ </t-table>
55
+ </div>
56
+
57
+ <!-- 下:分页栏 -->
58
+ <div class="pagination-wrapper">
59
+ <t-pagination v-model="$Data.pagination.current" v-model:page-size="$Data.pagination.pageSize" :total="$Data.pagination.total" :page-size-options="[10, 20, 50, 100]" show-jumper show-page-size @change="$Method.onPageChange" />
60
+ </div>
61
+
62
+ <!-- 角色分配对话框 -->
63
+ <t-dialog v-model:visible="$Data.roleVisible" header="分配角色" width="600px" :on-confirm="$Method.handleRoleSubmit">
64
+ <div class="role-dialog">
65
+ <div class="user-info">
66
+ <tiny-tag type="primary">{{ $Data.currentUser.username }}</tiny-tag>
67
+ <span class="user-email">{{ $Data.currentUser.email }}</span>
68
+ </div>
69
+ <t-divider />
70
+ <t-select v-model="$Data.checkedRoleCode" :options="$Data.roleOptions" placeholder="请选择角色" />
71
+ </div>
72
+ </t-dialog>
73
+ </div>
74
+ </template>
75
+
76
+ <script setup>
77
+ import { ref } from 'vue';
78
+
79
+ // 响应式数据
80
+ const $Data = $ref({
81
+ loading: false,
82
+ userList: [],
83
+ pagination: {
84
+ current: 1,
85
+ pageSize: 10,
86
+ total: 0
87
+ },
88
+ searchKeyword: '',
89
+ searchState: undefined,
90
+ stateOptions: [
91
+ { label: '正常', value: 1 },
92
+ { label: '禁用', value: 2 },
93
+ { label: '已删除', value: 0 }
94
+ ],
95
+ roleVisible: false,
96
+ currentUser: {},
97
+ columns: [
98
+ { colKey: 'username', title: '用户名', width: 150 },
99
+ { colKey: 'email', title: '邮箱', width: 200 },
100
+ { colKey: 'nickname', title: '昵称', width: 150 },
101
+ { colKey: 'state', title: '状态', width: 100 },
102
+ { colKey: 'roleCode', title: '角色', width: 120 },
103
+ { colKey: 'lastLoginTime', title: '最后登录', width: 180 },
104
+ { colKey: 'operation', title: '操作', width: 200, fixed: 'right' }
105
+ ],
106
+ roleOptions: [],
107
+ checkedRoleCode: ''
108
+ });
109
+
110
+ // 方法集合
111
+ const $Method = {
112
+ // 加载用户列表
113
+ async loadUserList() {
114
+ $Data.loading = true;
115
+ try {
116
+ const res = await $Http('/addon/admin/list', {
117
+ page: $Data.pagination.current,
118
+ limit: $Data.pagination.pageSize
119
+ });
120
+ if (res.code === 0 && res.data) {
121
+ // getList 返回分页对象 { list, total, page, limit, pages }
122
+ $Data.userList = res.data.list || [];
123
+ $Data.pagination.total = res.data.total || 0;
124
+ }
125
+ } catch (error) {
126
+ MessagePlugin.error('加载用户列表失败');
127
+ console.error(error);
128
+ } finally {
129
+ $Data.loading = false;
130
+ }
131
+ },
132
+
133
+ // 分页变化
134
+ onPageChange(pageInfo) {
135
+ $Data.pagination.current = pageInfo.current;
136
+ $Data.pagination.pageSize = pageInfo.pageSize;
137
+ $Method.loadUserList();
138
+ },
139
+
140
+ // 搜索
141
+ handleSearch() {
142
+ $Data.pagination.current = 1;
143
+ $Method.loadUserList();
144
+ },
145
+
146
+ // 重置
147
+ handleReset() {
148
+ $Data.searchKeyword = '';
149
+ $Data.searchState = undefined;
150
+ $Data.pagination.current = 1;
151
+ $Method.loadUserList();
152
+ },
153
+
154
+ // 添加管理员
155
+ handleAdd() {
156
+ MessagePlugin.info('添加管理员功能待开发');
157
+ },
158
+
159
+ // 编辑管理员
160
+ handleEdit(row) {
161
+ MessagePlugin.info(`编辑管理员:${row.username}`);
162
+ },
163
+
164
+ // 删除管理员
165
+ handleDelete(row) {
166
+ DialogPlugin.confirm({
167
+ header: '确认删除',
168
+ body: `确定要删除管理员 "${row.username}" 吗?`,
169
+ onConfirm: async () => {
170
+ try {
171
+ // TODO: 调用删除接口
172
+ MessagePlugin.success('删除成功');
173
+ await $Method.loadUserList();
174
+ } catch (error) {
175
+ MessagePlugin.error('删除失败');
176
+ console.error(error);
177
+ }
178
+ }
179
+ });
180
+ },
181
+
182
+ // 加载角色列表
183
+ async loadRoleList() {
184
+ try {
185
+ const res = await $Http('/addon/admin/role/list', {});
186
+ if (res.code === 0 && res.data) {
187
+ // getList 返回分页对象
188
+ const roleList = res.data.list || res.data || [];
189
+ $Data.roleOptions = roleList
190
+ .filter((role) => role.state === 1)
191
+ .map((role) => ({
192
+ label: role.name,
193
+ value: role.code
194
+ }));
195
+ }
196
+ } catch (error) {
197
+ MessagePlugin.error('加载角色列表失败');
198
+ console.error(error);
199
+ }
200
+ },
201
+
202
+ // 打开角色分配对话框
203
+ async handleRole(row) {
204
+ $Data.currentUser = row;
205
+ $Data.roleVisible = true;
206
+
207
+ // 加载角色列表
208
+ await $Method.loadRoleList();
209
+
210
+ // 加载该用户已有的角色
211
+ try {
212
+ const res = await $Http('/addon/admin/roleDetail', { adminId: row.id });
213
+ if (res.code === 0 && res.data) {
214
+ $Data.checkedRoleCode = res.data.roleCode || '';
215
+ }
216
+ } catch (error) {
217
+ MessagePlugin.error('加载用户角色失败');
218
+ console.error(error);
219
+ }
220
+ },
221
+
222
+ // 提交角色分配
223
+ async handleRoleSubmit() {
224
+ if (!$Data.checkedRoleCode) {
225
+ MessagePlugin.warning('请选择角色');
226
+ return false;
227
+ }
228
+
229
+ try {
230
+ const res = await $Http('/addon/admin/roleSave', {
231
+ adminId: $Data.currentUser.id,
232
+ roleCode: $Data.checkedRoleCode
233
+ });
234
+
235
+ if (res.code === 0) {
236
+ MessagePlugin.success('角色分配成功');
237
+ $Data.roleVisible = false;
238
+ await $Method.loadUserList();
239
+ return true;
240
+ } else {
241
+ MessagePlugin.error(res.msg || '分配失败');
242
+ return false;
243
+ }
244
+ } catch (error) {
245
+ MessagePlugin.error('分配失败');
246
+ console.error(error);
247
+ return false;
248
+ }
249
+ }
250
+ };
251
+
252
+ // 初始化加载
253
+ $Method.loadUserList();
254
+ </script>
255
+
256
+ <style scoped lang="scss">
257
+ .user-manage {
258
+ height: 100%;
259
+ display: flex;
260
+ flex-direction: column;
261
+ gap: 16px;
262
+ padding: 16px;
263
+ overflow: hidden; // 防止外层滚动
264
+ }
265
+
266
+ // 上:工具栏
267
+ .toolbar {
268
+ flex-shrink: 0; // 不允许收缩
269
+ display: flex;
270
+ justify-content: space-between;
271
+ align-items: center;
272
+ padding: 16px;
273
+ background: $bg-color-container;
274
+ border-radius: $border-radius;
275
+ box-shadow: $shadow-card;
276
+
277
+ .toolbar-left {
278
+ display: flex;
279
+ gap: 12px;
280
+ }
281
+
282
+ .toolbar-right {
283
+ display: flex;
284
+ gap: 12px;
285
+ }
286
+ }
287
+
288
+ // 中:表格区域(撑满剩余空间并支持滚动)
289
+ .table-wrapper {
290
+ flex: 1; // 占据剩余空间
291
+ overflow: hidden; // 隐藏超出部分
292
+ display: flex;
293
+ flex-direction: column;
294
+ background: $bg-color-container;
295
+ border-radius: $border-radius;
296
+ box-shadow: $shadow-card;
297
+ }
298
+
299
+ // 下:分页栏
300
+ .pagination-wrapper {
301
+ flex-shrink: 0; // 不允许收缩
302
+ display: flex;
303
+ justify-content: flex-end;
304
+ padding: 16px;
305
+ background: $bg-color-container;
306
+ border-radius: $border-radius;
307
+ box-shadow: $shadow-card;
308
+ }
309
+
310
+ .role-dialog {
311
+ .user-info {
312
+ display: flex;
313
+ align-items: center;
314
+ gap: 12px;
315
+ margin-bottom: 16px;
316
+
317
+ .user-email {
318
+ color: $text-secondary;
319
+ }
320
+ }
321
+ }
322
+ </style>
@@ -1,47 +0,0 @@
1
- /**
2
- * 获取插件列表
3
- */
4
-
5
- import { Yes, Addon } from 'befly';
6
- import { readFileSync } from 'node:fs';
7
-
8
- export default {
9
- name: '获取插件列表',
10
- handler: async (befly, ctx) => {
11
- const addonList: Array<{ name: string; title: string; version: string; description: string; enabled: boolean }> = [];
12
-
13
- // 使用 Addon.scan() 扫描所有 addon
14
- const addonNames = Addon.scan();
15
-
16
- for (const addonName of addonNames) {
17
- // addonName 格式: admin, demo 等
18
-
19
- // 读取插件配置文件
20
- const configPath = Addon.getDir(addonName, 'addon.config.json');
21
-
22
- try {
23
- const configContent = readFileSync(configPath, 'utf-8');
24
- const config = JSON.parse(configContent);
25
-
26
- addonList.push({
27
- name: config.name || addonName,
28
- title: config.title || addonName,
29
- version: config.version || '1.0.0',
30
- description: config.description || '',
31
- enabled: true
32
- });
33
- } catch (error) {
34
- // 配置文件不存在或解析失败,使用默认值
35
- addonList.push({
36
- name: addonName,
37
- title: addonName,
38
- version: '1.0.0',
39
- description: '',
40
- enabled: true
41
- });
42
- }
43
- }
44
-
45
- return Yes('获取成功', addonList);
46
- }
47
- };