befly-admin 3.0.1

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 (57) hide show
  1. package/.env.development +4 -0
  2. package/.env.production +4 -0
  3. package/LICENSE +201 -0
  4. package/README.md +143 -0
  5. package/index.html +13 -0
  6. package/libs/auto-routes-template.js +104 -0
  7. package/libs/autoRouter.ts +67 -0
  8. package/libs/icons.ts +543 -0
  9. package/package.json +42 -0
  10. package/public/logo.svg +106 -0
  11. package/src/App.vue +17 -0
  12. package/src/api/auth.ts +60 -0
  13. package/src/components/Icon.vue +41 -0
  14. package/src/env.d.ts +9 -0
  15. package/src/layouts/0.vue +207 -0
  16. package/src/layouts/1.vue +22 -0
  17. package/src/layouts/2.vue +166 -0
  18. package/src/main.ts +19 -0
  19. package/src/plugins/http.ts +94 -0
  20. package/src/plugins/router.ts +47 -0
  21. package/src/plugins/store.ts +19 -0
  22. package/src/styles/index.scss +198 -0
  23. package/src/styles/mixins.scss +98 -0
  24. package/src/styles/variables.scss +75 -0
  25. package/src/types/env.d.ts +23 -0
  26. package/src/util.ts +28 -0
  27. package/src/views/403/403.vue +33 -0
  28. package/src/views/admin/components/edit.vue +147 -0
  29. package/src/views/admin/components/role.vue +135 -0
  30. package/src/views/admin/index.vue +169 -0
  31. package/src/views/dict/components/edit.vue +156 -0
  32. package/src/views/dict/index.vue +159 -0
  33. package/src/views/index/components/AddonList.vue +125 -0
  34. package/src/views/index/components/EnvironmentInfo.vue +97 -0
  35. package/src/views/index/components/OperationLogs.vue +112 -0
  36. package/src/views/index/components/PerformanceMetrics.vue +148 -0
  37. package/src/views/index/components/QuickActions.vue +27 -0
  38. package/src/views/index/components/ServiceStatus.vue +193 -0
  39. package/src/views/index/components/SystemNotifications.vue +136 -0
  40. package/src/views/index/components/SystemOverview.vue +188 -0
  41. package/src/views/index/components/SystemResources.vue +104 -0
  42. package/src/views/index/components/UserInfo.vue +136 -0
  43. package/src/views/index/index.vue +62 -0
  44. package/src/views/login/index_1.vue +694 -0
  45. package/src/views/menu/components/edit.vue +150 -0
  46. package/src/views/menu/index.vue +168 -0
  47. package/src/views/news/detail/detail_2.vue +26 -0
  48. package/src/views/news/detail/index.vue +26 -0
  49. package/src/views/news/news.vue +26 -0
  50. package/src/views/role/components/api.vue +280 -0
  51. package/src/views/role/components/edit.vue +129 -0
  52. package/src/views/role/components/menu.vue +143 -0
  53. package/src/views/role/index.vue +179 -0
  54. package/src/views/user/user.vue +320 -0
  55. package/temp/router.js +71 -0
  56. package/tsconfig.json +34 -0
  57. package/vite.config.ts +100 -0
@@ -0,0 +1,320 @@
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
+ <add-icon />
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
+ <search-icon />
20
+ </template>
21
+ 搜索
22
+ </t-button>
23
+ <t-button theme="default" @click="$Method.handleReset">
24
+ <template #icon>
25
+ <refresh-icon />
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
+ <t-tag v-if="row.state === 1" theme="success">正常</t-tag>
38
+ <t-tag v-else-if="row.state === 2" theme="warning">禁用</t-tag>
39
+ <t-tag v-else theme="danger">已删除</t-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
+ <t-tag theme="primary">{{ $Data.currentUser.username }}</t-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
+ // 响应式数据
78
+ const $Data = $ref({
79
+ loading: false,
80
+ userList: [],
81
+ pagination: {
82
+ current: 1,
83
+ pageSize: 10,
84
+ total: 0
85
+ },
86
+ searchKeyword: '',
87
+ searchState: undefined,
88
+ stateOptions: [
89
+ { label: '正常', value: 1 },
90
+ { label: '禁用', value: 2 },
91
+ { label: '已删除', value: 0 }
92
+ ],
93
+ roleVisible: false,
94
+ currentUser: {},
95
+ columns: [
96
+ { colKey: 'username', title: '用户名', width: 150 },
97
+ { colKey: 'email', title: '邮箱', width: 200 },
98
+ { colKey: 'nickname', title: '昵称', width: 150 },
99
+ { colKey: 'state', title: '状态', width: 100 },
100
+ { colKey: 'roleCode', title: '角色', width: 120 },
101
+ { colKey: 'lastLoginTime', title: '最后登录', width: 180 },
102
+ { colKey: 'operation', title: '操作', width: 200, fixed: 'right' }
103
+ ],
104
+ roleOptions: [],
105
+ checkedRoleCode: ''
106
+ });
107
+
108
+ // 方法集合
109
+ const $Method = {
110
+ // 加载用户列表
111
+ async loadUserList() {
112
+ $Data.loading = true;
113
+ try {
114
+ const res = await $Http('/addon/admin/adminList', {
115
+ page: $Data.pagination.current,
116
+ limit: $Data.pagination.pageSize
117
+ });
118
+ if (res.code === 0 && res.data) {
119
+ // getList 返回分页对象 { list, total, page, limit, pages }
120
+ $Data.userList = res.data.list || [];
121
+ $Data.pagination.total = res.data.total || 0;
122
+ }
123
+ } catch (error) {
124
+ MessagePlugin.error('加载用户列表失败');
125
+ console.error(error);
126
+ } finally {
127
+ $Data.loading = false;
128
+ }
129
+ },
130
+
131
+ // 分页变化
132
+ onPageChange(pageInfo) {
133
+ $Data.pagination.current = pageInfo.current;
134
+ $Data.pagination.pageSize = pageInfo.pageSize;
135
+ $Method.loadUserList();
136
+ },
137
+
138
+ // 搜索
139
+ handleSearch() {
140
+ $Data.pagination.current = 1;
141
+ $Method.loadUserList();
142
+ },
143
+
144
+ // 重置
145
+ handleReset() {
146
+ $Data.searchKeyword = '';
147
+ $Data.searchState = undefined;
148
+ $Data.pagination.current = 1;
149
+ $Method.loadUserList();
150
+ },
151
+
152
+ // 添加管理员
153
+ handleAdd() {
154
+ MessagePlugin.info('添加管理员功能待开发');
155
+ },
156
+
157
+ // 编辑管理员
158
+ handleEdit(row) {
159
+ MessagePlugin.info(`编辑管理员:${row.username}`);
160
+ },
161
+
162
+ // 删除管理员
163
+ handleDelete(row) {
164
+ DialogPlugin.confirm({
165
+ header: '确认删除',
166
+ body: `确定要删除管理员 "${row.username}" 吗?`,
167
+ onConfirm: async () => {
168
+ try {
169
+ // TODO: 调用删除接口
170
+ MessagePlugin.success('删除成功');
171
+ await $Method.loadUserList();
172
+ } catch (error) {
173
+ MessagePlugin.error('删除失败');
174
+ console.error(error);
175
+ }
176
+ }
177
+ });
178
+ },
179
+
180
+ // 加载角色列表
181
+ async loadRoleList() {
182
+ try {
183
+ const res = await $Http('/addon/admin/roleList', {});
184
+ if (res.code === 0 && res.data) {
185
+ // getList 返回分页对象
186
+ const roleList = res.data.list || res.data || [];
187
+ $Data.roleOptions = roleList
188
+ .filter((role) => role.state === 1)
189
+ .map((role) => ({
190
+ label: role.name,
191
+ value: role.code
192
+ }));
193
+ }
194
+ } catch (error) {
195
+ MessagePlugin.error('加载角色列表失败');
196
+ console.error(error);
197
+ }
198
+ },
199
+
200
+ // 打开角色分配对话框
201
+ async handleRole(row) {
202
+ $Data.currentUser = row;
203
+ $Data.roleVisible = true;
204
+
205
+ // 加载角色列表
206
+ await $Method.loadRoleList();
207
+
208
+ // 加载该用户已有的角色
209
+ try {
210
+ const res = await $Http('/addon/admin/adminRoleDetail', { adminId: row.id });
211
+ if (res.code === 0 && res.data) {
212
+ $Data.checkedRoleCode = res.data.roleCode || '';
213
+ }
214
+ } catch (error) {
215
+ MessagePlugin.error('加载用户角色失败');
216
+ console.error(error);
217
+ }
218
+ },
219
+
220
+ // 提交角色分配
221
+ async handleRoleSubmit() {
222
+ if (!$Data.checkedRoleCode) {
223
+ MessagePlugin.warning('请选择角色');
224
+ return false;
225
+ }
226
+
227
+ try {
228
+ const res = await $Http('/addon/admin/adminRoleSave', {
229
+ adminId: $Data.currentUser.id,
230
+ roleCode: $Data.checkedRoleCode
231
+ });
232
+
233
+ if (res.code === 0) {
234
+ MessagePlugin.success('角色分配成功');
235
+ $Data.roleVisible = false;
236
+ await $Method.loadUserList();
237
+ return true;
238
+ } else {
239
+ MessagePlugin.error(res.msg || '分配失败');
240
+ return false;
241
+ }
242
+ } catch (error) {
243
+ MessagePlugin.error('分配失败');
244
+ console.error(error);
245
+ return false;
246
+ }
247
+ }
248
+ };
249
+
250
+ // 初始化加载
251
+ $Method.loadUserList();
252
+ </script>
253
+
254
+ <style scoped lang="scss">
255
+ .user-manage {
256
+ height: 100%;
257
+ display: flex;
258
+ flex-direction: column;
259
+ gap: 16px;
260
+ padding: 16px;
261
+ overflow: hidden; // 防止外层滚动
262
+ }
263
+
264
+ // 上:工具栏
265
+ .toolbar {
266
+ flex-shrink: 0; // 不允许收缩
267
+ display: flex;
268
+ justify-content: space-between;
269
+ align-items: center;
270
+ padding: 16px;
271
+ background: $bg-color-container;
272
+ border-radius: $border-radius;
273
+ box-shadow: $shadow-card;
274
+
275
+ .toolbar-left {
276
+ display: flex;
277
+ gap: 12px;
278
+ }
279
+
280
+ .toolbar-right {
281
+ display: flex;
282
+ gap: 12px;
283
+ }
284
+ }
285
+
286
+ // 中:表格区域(撑满剩余空间并支持滚动)
287
+ .table-wrapper {
288
+ flex: 1; // 占据剩余空间
289
+ overflow: hidden; // 隐藏超出部分
290
+ display: flex;
291
+ flex-direction: column;
292
+ background: $bg-color-container;
293
+ border-radius: $border-radius;
294
+ box-shadow: $shadow-card;
295
+ }
296
+
297
+ // 下:分页栏
298
+ .pagination-wrapper {
299
+ flex-shrink: 0; // 不允许收缩
300
+ display: flex;
301
+ justify-content: flex-end;
302
+ padding: 16px;
303
+ background: $bg-color-container;
304
+ border-radius: $border-radius;
305
+ box-shadow: $shadow-card;
306
+ }
307
+
308
+ .role-dialog {
309
+ .user-info {
310
+ display: flex;
311
+ align-items: center;
312
+ gap: 12px;
313
+ margin-bottom: 16px;
314
+
315
+ .user-email {
316
+ color: $text-secondary;
317
+ }
318
+ }
319
+ }
320
+ </style>
package/temp/router.js ADDED
@@ -0,0 +1,71 @@
1
+ export const yiteRouter = (options) => {
2
+ let config = {};
3
+ const virtualModuleId = `virtual:yite-router`;
4
+ const resolvedVirtualModuleId = '\0' + virtualModuleId;
5
+
6
+ return {
7
+ name: 'yite-router',
8
+ enforce: 'pre',
9
+ options(options) {},
10
+ buildStart(options) {},
11
+ configResolved(resolvedConfig) {
12
+ config = resolvedConfig;
13
+ },
14
+ resolveId(id) {
15
+ if (id === virtualModuleId) {
16
+ return resolvedVirtualModuleId;
17
+ }
18
+ },
19
+ load(id) {
20
+ if (id === resolvedVirtualModuleId) {
21
+ return `
22
+ const pageFiles = import.meta.glob('@/pages/**/*.vue');
23
+ const layoutFiles = import.meta.glob('@/layouts/*.vue');
24
+
25
+ const layouts = {};
26
+ const routes = [];
27
+
28
+
29
+
30
+ const getRouteData = (file) => {
31
+ const path = file //
32
+ .replace(/[\\\\\/]+/g, '/')
33
+ .replace(/.*\\/pages\\//, '')
34
+ .replace(/(\\!\\d)?\\.vue/, '')
35
+ .replace(/#\\d+/g, '')
36
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
37
+ .replace(/-$/g, '')
38
+ .toLowerCase()
39
+ .replace(/[\\s_-]+/g, '-');
40
+ const index = file.indexOf('!');
41
+ const layout = index !== -1 ? file.substring(index + 1, file.length - 4) : 1;
42
+
43
+ return {
44
+ path: path,
45
+ layout: Number(layout)
46
+ };
47
+ };
48
+
49
+ for (let file in pageFiles) {
50
+ if (file.indexOf('components') !== -1) continue;
51
+
52
+ const routeData = getRouteData(file);
53
+ routes.push({
54
+ path: routeData.path === 'index' ? '/' : '/' + routeData.path,
55
+ component: layoutFiles['/src/layouts/' + routeData.layout + '.vue'],
56
+ children: [
57
+ {
58
+ path: '',
59
+ component: pageFiles[file]
60
+ }
61
+ ]
62
+ });
63
+ }
64
+
65
+
66
+ export { routes };
67
+ `;
68
+ }
69
+ }
70
+ };
71
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "isolatedModules": true,
13
+ "moduleDetection": "force",
14
+ "noEmit": true,
15
+
16
+ /* Linting */
17
+ "strict": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedSideEffectImports": true,
22
+
23
+ /* Path mapping */
24
+ "baseUrl": ".",
25
+ "paths": {
26
+ "@/*": ["./src/*"]
27
+ },
28
+
29
+ /* Type definitions */
30
+ "types": ["vite/client", "node"]
31
+ },
32
+ "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
33
+ "exclude": ["node_modules", "dist"]
34
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,100 @@
1
+ import { fileURLToPath, URL } from 'node:url';
2
+ import { defineConfig } from 'vite';
3
+ import vue from '@vitejs/plugin-vue';
4
+ import ReactivityTransform from '@vue-macros/reactivity-transform/vite';
5
+ import AutoImport from 'unplugin-auto-import/vite';
6
+ import Components from 'unplugin-vue-components/vite';
7
+ import { TinyVueSingleResolver } from '@opentiny/unplugin-tiny-vue';
8
+ import autoRouter from './libs/autoRouter';
9
+
10
+ // https://vite.dev/config/
11
+ export default defineConfig({
12
+ plugins: [
13
+ vue(),
14
+ // Vue 响应式语法糖
15
+ ReactivityTransform(),
16
+ // 自动路由插件
17
+ autoRouter(),
18
+ // 自动导入 Vue3 API 和组合式函数
19
+ AutoImport({
20
+ imports: [
21
+ 'vue',
22
+ 'vue-router',
23
+ 'pinia',
24
+ {
25
+ '@opentiny/vue': ['Modal', 'Notify', 'Loading', 'Message']
26
+ }
27
+ ],
28
+ resolvers: [TinyVueSingleResolver],
29
+ // 自动导入 plugins 目录下的所有导出
30
+ dirs: ['./src/plugins'],
31
+ dts: 'src/types/auto-imports.d.ts',
32
+ eslintrc: {
33
+ enabled: false
34
+ }
35
+ }),
36
+ // 自动导入 OpenTiny 组件
37
+ Components({
38
+ resolvers: [TinyVueSingleResolver],
39
+ dirs: ['src/components'],
40
+ dts: 'src/types/components.d.ts'
41
+ })
42
+ ],
43
+ resolve: {
44
+ alias: {
45
+ '@': fileURLToPath(new URL('./src', import.meta.url))
46
+ }
47
+ },
48
+ define: {
49
+ 'process.env': { TINY_MODE: 'pc' } // OpenTiny 需要的环境变量
50
+ },
51
+ css: {
52
+ preprocessorOptions: {
53
+ scss: {
54
+ api: 'modern-compiler',
55
+ additionalData: `@use "@/styles/variables.scss" as *;`
56
+ }
57
+ }
58
+ },
59
+ server: {
60
+ port: 5173,
61
+ host: true,
62
+ open: false
63
+ },
64
+ logLevel: 'info',
65
+ customLogger: {
66
+ info: (msg) => {
67
+ // 过滤掉频繁的依赖优化信息
68
+ if (msg.includes('new dependencies optimized')) {
69
+ return;
70
+ }
71
+ console.info(msg);
72
+ },
73
+ warn: console.warn,
74
+ error: console.error
75
+ },
76
+ optimizeDeps: {
77
+ include: ['vue', 'vue-router', 'pinia', 'lucide-vue-next', 'axios', '@opentiny/vue'],
78
+ exclude: [],
79
+ // 禁用自动发现,减少频繁优化提示
80
+ noDiscovery: true,
81
+ // 增加缓存时间,避免重复优化
82
+ force: false,
83
+ esbuildOptions: {
84
+ target: 'esnext'
85
+ }
86
+ },
87
+ build: {
88
+ outDir: 'dist',
89
+ sourcemap: false,
90
+ chunkSizeWarningLimit: 1500,
91
+ rollupOptions: {
92
+ output: {
93
+ manualChunks: {
94
+ 'vue-vendor': ['vue', 'vue-router', 'pinia'],
95
+ 'opentiny-vendor': ['@opentiny/vue']
96
+ }
97
+ }
98
+ }
99
+ }
100
+ });