create-lumal-admin 0.0.4-beta → 0.0.6-beta

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 (185) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +98 -12
  3. package/dist/cli.d.ts +18 -1
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +308 -28
  6. package/dist/cli.js.map +1 -1
  7. package/dist/create.d.ts +11 -1
  8. package/dist/create.d.ts.map +1 -1
  9. package/dist/create.js +98 -2
  10. package/dist/create.js.map +1 -1
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/presets.d.ts +41 -0
  16. package/dist/presets.d.ts.map +1 -0
  17. package/dist/presets.js +58 -0
  18. package/dist/presets.js.map +1 -0
  19. package/dist/project-cli.d.ts +3 -0
  20. package/dist/project-cli.d.ts.map +1 -0
  21. package/dist/project-cli.js +13 -0
  22. package/dist/project-cli.js.map +1 -0
  23. package/dist/projects.d.ts +21 -0
  24. package/dist/projects.d.ts.map +1 -0
  25. package/dist/projects.js +124 -0
  26. package/dist/projects.js.map +1 -0
  27. package/dist/scaffold.d.ts +2 -11
  28. package/dist/scaffold.d.ts.map +1 -1
  29. package/dist/scaffold.js +2 -1602
  30. package/dist/scaffold.js.map +1 -1
  31. package/dist/templates.d.ts +7 -0
  32. package/dist/templates.d.ts.map +1 -0
  33. package/dist/templates.js +91 -0
  34. package/dist/templates.js.map +1 -0
  35. package/dist/types.d.ts +64 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +2 -0
  38. package/dist/types.js.map +1 -0
  39. package/package.json +13 -4
  40. package/templates/base/.env.example +4 -0
  41. package/templates/base/API-CONTRACT.md +84 -0
  42. package/templates/base/README.md +59 -0
  43. package/templates/base/index.html +12 -0
  44. package/templates/base/package.json +38 -0
  45. package/templates/base/src/App.vue +206 -0
  46. package/templates/base/src/app/components/AppHeaderActions.vue +46 -0
  47. package/templates/base/src/app/components/AppSettingsDrawer.vue +37 -0
  48. package/templates/base/src/app/menu-policy.ts +163 -0
  49. package/templates/base/src/app/module.ts +46 -0
  50. package/templates/base/src/app/router/index.ts +107 -0
  51. package/templates/base/src/app/router/views.ts +12 -0
  52. package/templates/base/src/app/services/access.ts +2 -0
  53. package/templates/base/src/app/services/contracts.ts +54 -0
  54. package/templates/base/src/app/services/local-contracts.ts +18 -0
  55. package/templates/base/src/app/services/preferences.ts +41 -0
  56. package/templates/base/src/app/services/session-runtime.ts +186 -0
  57. package/templates/base/src/app/services/session.ts +14 -0
  58. package/templates/base/src/app/stored-menus.ts +72 -0
  59. package/templates/base/src/app/views/SafeIframeView.vue +34 -0
  60. package/templates/base/src/app/views/auth/LoginView.vue +75 -0
  61. package/templates/base/src/app/views/error/ForbiddenView.vue +20 -0
  62. package/templates/base/src/app/views/error/NotFoundView.vue +16 -0
  63. package/templates/base/src/main.ts +40 -0
  64. package/templates/base/src/modules/business/README.md +33 -0
  65. package/templates/base/src/modules/dashboard/DashboardView.vue +27 -0
  66. package/templates/base/src/modules/dashboard/module.ts +14 -0
  67. package/templates/base/src/shared/api.ts +53 -0
  68. package/templates/base/src/shared/components/BaseEntityDialog.vue +39 -0
  69. package/templates/base/src/shared/composables/use-async-data.ts +35 -0
  70. package/templates/base/src/shared/composables/use-entity-editor.ts +77 -0
  71. package/templates/base/src/shared/status.ts +4 -0
  72. package/templates/base/src/shared/tree.ts +41 -0
  73. package/templates/base/src/styles.scss +173 -0
  74. package/templates/base/tests/menu-policy.test.ts.template +89 -0
  75. package/templates/base/tests/session.test.ts.template +45 -0
  76. package/templates/base/vite.config.ts +54 -0
  77. package/templates/blank/README.md +6 -0
  78. package/templates/blank/src/App.vue +11 -0
  79. package/templates/common/AGENTS.md +13 -0
  80. package/templates/common/_editorconfig +15 -0
  81. package/templates/common/_gitattributes +6 -0
  82. package/templates/common/_gitignore +7 -0
  83. package/templates/common/_prettierignore +6 -0
  84. package/templates/common/docs/DEVELOPMENT.md +26 -0
  85. package/templates/common/eslint.config.mjs +60 -0
  86. package/templates/common/package.json +39 -0
  87. package/templates/common/prettier.config.mjs +8 -0
  88. package/templates/common/tsconfig.json +19 -0
  89. package/templates/common/vitest.config.ts +3 -0
  90. package/templates/features/examples/src/modules/examples/CrudExampleView.vue +51 -0
  91. package/templates/features/examples/src/modules/examples/FormExampleView.vue +32 -0
  92. package/templates/features/examples/src/modules/examples/module.ts +27 -0
  93. package/templates/features/system/src/modules/system/config/ConfigView.vue +104 -0
  94. package/templates/features/system/src/modules/system/config/api.ts +38 -0
  95. package/templates/features/system/src/modules/system/config/routes.ts +21 -0
  96. package/templates/features/system/src/modules/system/dictionary/DictionaryItemView.vue +141 -0
  97. package/templates/features/system/src/modules/system/dictionary/DictionaryTypeView.vue +107 -0
  98. package/templates/features/system/src/modules/system/dictionary/api.ts +61 -0
  99. package/templates/features/system/src/modules/system/dictionary/cache.ts +9 -0
  100. package/templates/features/system/src/modules/system/dictionary/routes.ts +32 -0
  101. package/templates/features/system/src/modules/system/dictionary/types.ts +22 -0
  102. package/templates/features/system/src/modules/system/local.ts +348 -0
  103. package/templates/features/system/src/modules/system/menu/MenuView.vue +133 -0
  104. package/templates/features/system/src/modules/system/menu/api.ts +73 -0
  105. package/templates/features/system/src/modules/system/menu/components/MenuEditorDialog.vue +106 -0
  106. package/templates/features/system/src/modules/system/menu/routes.ts +23 -0
  107. package/templates/features/system/src/modules/system/menu/types.ts +18 -0
  108. package/templates/features/system/src/modules/system/module.ts +22 -0
  109. package/templates/features/system/src/modules/system/organization/OrganizationView.vue +134 -0
  110. package/templates/features/system/src/modules/system/organization/api.ts +38 -0
  111. package/templates/features/system/src/modules/system/organization/routes.ts +23 -0
  112. package/templates/features/system/src/modules/system/organization/types.ts +17 -0
  113. package/templates/features/system/src/modules/system/role/RoleView.vue +90 -0
  114. package/templates/features/system/src/modules/system/role/api.ts +40 -0
  115. package/templates/features/system/src/modules/system/role/components/RoleAuthorizationDialog.vue +110 -0
  116. package/templates/features/system/src/modules/system/role/permission-tree.ts +31 -0
  117. package/templates/features/system/src/modules/system/role/routes.ts +24 -0
  118. package/templates/features/system/src/modules/system/role/types.ts +12 -0
  119. package/templates/features/system/src/modules/system/user/UserView.vue +297 -0
  120. package/templates/features/system/src/modules/system/user/api.ts +45 -0
  121. package/templates/features/system/src/modules/system/user/components/UserOrganizationFilter.vue +61 -0
  122. package/templates/features/system/src/modules/system/user/components/UserRoleDialog.vue +93 -0
  123. package/templates/features/system/src/modules/system/user/routes.ts +27 -0
  124. package/templates/features/system/src/modules/system/user/types.ts +28 -0
  125. package/templates/features/system/tests/system.test.ts.template +266 -0
  126. package/templates/modes/http/src/app/services/data-source.ts +124 -0
  127. package/templates/modes/http/src/app/services/http-adapter.ts +128 -0
  128. package/templates/modes/http/tests/http.test.ts.template +218 -0
  129. package/templates/modes/local/src/app/services/data-source.ts +113 -0
  130. package/templates/modes/local/src/app/services/local-database.ts +67 -0
  131. package/templates/modes/local/tests/local.test.ts.template +132 -0
  132. package/templates/presets/standard/src/modules/dashboard/DashboardView.vue +52 -0
  133. package/templates/presets/standard/src/modules/dashboard/components/DashboardSessionStatus.vue +41 -0
  134. package/templates/presets/standard/src/modules/dashboard/components/DashboardShortcuts.vue +51 -0
  135. package/templates/presets/standard/src/modules/profile/ProfileView.vue +109 -0
  136. package/templates/presets/standard/src/modules/profile/api.ts +49 -0
  137. package/templates/presets/standard/src/modules/profile/components/ProfilePasswordForm.vue +68 -0
  138. package/templates/presets/standard/src/modules/profile/local.ts +40 -0
  139. package/templates/presets/standard/src/modules/profile/module.ts +11 -0
  140. package/templates/presets/standard/tests/profile.test.ts.template +72 -0
  141. package/templates/screen/README.md +6 -0
  142. package/templates/screen/src/App.vue +7 -0
  143. package/templates/screen/src/screen/ScreenEntry.vue +18 -0
  144. package/templates/screen/src/screen/ScreenView.vue +48 -0
  145. package/templates/screen/src/screen/components/ScreenMetrics.vue +40 -0
  146. package/templates/screen-auth/src/screen/ScreenEntry.vue +52 -0
  147. package/templates/screen-auth/src/screen/components/ScreenLoginForm.vue +44 -0
  148. package/templates/screen-auth/src/services/session.ts +61 -0
  149. package/templates/screen-auth/tests/session.test.ts.template +54 -0
  150. package/templates/screen-auth-http/src/services/auth-adapter.ts +14 -0
  151. package/templates/screen-auth-http/tests/auth-adapter.test.ts.template +17 -0
  152. package/templates/screen-auth-local-demo/src/services/auth-adapter.ts +15 -0
  153. package/templates/screen-auth-local-demo/tests/auth-adapter.test.ts.template +18 -0
  154. package/templates/screen-data/src/screen/ScreenView.vue +69 -0
  155. package/templates/screen-data/src/services/metrics-types.ts +4 -0
  156. package/templates/screen-data-http/src/services/metrics.ts +20 -0
  157. package/templates/screen-data-http/src/services/request.ts +3 -0
  158. package/templates/screen-data-http/tests/metrics.test.ts.template +21 -0
  159. package/templates/screen-data-local/src/services/metrics.ts +11 -0
  160. package/templates/screen-data-local/tests/metrics.test.ts.template +9 -0
  161. package/templates/screen-http/API-CONTRACT.md +20 -0
  162. package/templates/screen-http/src/services/http.ts +17 -0
  163. package/templates/screen-request-auth/src/services/request.ts +15 -0
  164. package/templates/screen-router/src/App.vue +7 -0
  165. package/templates/screen-router/src/main.ts +13 -0
  166. package/templates/screen-router/src/router.ts +7 -0
  167. package/templates/screen-router/tests/app.test.ts.template +20 -0
  168. package/templates/screen-viewport/src/screen/ScreenViewport.vue +30 -0
  169. package/templates/screen-visualization-charts/src/screen/components/ScreenVisualization.vue +22 -0
  170. package/templates/screen-visualization-cockpit/src/screen/components/ScreenVisualization.vue +33 -0
  171. package/templates/screen-visualization-cockpit/src/screen/components/ScreenWidget.vue +10 -0
  172. package/templates/screen-visualization-datav/src/screen/components/ScreenVisualization.vue +11 -0
  173. package/templates/vben-compatible/MIGRATION.md +30 -0
  174. package/templates/vben-compatible/src/modules/vben-migration/VbenFormView.vue +11 -0
  175. package/templates/vben-compatible/src/modules/vben-migration/VbenUsersView.vue +12 -0
  176. package/templates/vben-compatible/src/modules/vben-migration/components/VbenFormExample.vue +64 -0
  177. package/templates/vben-compatible/src/modules/vben-migration/components/VbenUsers.vue +144 -0
  178. package/templates/vben-compatible/src/modules/vben-migration/local.ts +68 -0
  179. package/templates/vben-compatible/src/modules/vben-migration/module.ts +42 -0
  180. package/templates/vue/index.html +12 -0
  181. package/templates/vue/src/main.ts +5 -0
  182. package/templates/vue/src/styles.css +19 -0
  183. package/templates/vue/tests/app.test.ts.template +10 -0
  184. package/templates/vue/vite.config.ts +9 -0
  185. package/templates/vue/vitest.config.ts +4 -0
@@ -0,0 +1,73 @@
1
+ import type { SchemaFormModel } from '@lumal/core/components';
2
+ import type { BusinessTransport } from '../../../app/services/contracts';
3
+ import type { Menu, MenuInput, MenuType } from './types';
4
+ import { assertRoutePath, resolveView, safeExternalUrl } from '../../../app/menu-policy';
5
+ import { viewComponents } from '../../../app/router/views';
6
+ import { integer, object, rows, stringArray, text } from '../../../shared/api';
7
+
8
+ export function menuInput(model: SchemaFormModel): MenuInput {
9
+ const type = text(model.type, '菜单类型', true) as MenuType;
10
+ if (!['directory', 'menu', 'button', 'external', 'embedded'].includes(type)) throw new Error('菜单类型无效');
11
+ const path = type === 'button' ? '' : text(model.path, '路径', true);
12
+ if (type !== 'button') assertRoutePath(path);
13
+ const component = type === 'menu' ? text(model.component, '组件', true) : type === 'embedded' ? 'app/iframe' : '';
14
+ if (component && !resolveView(viewComponents, component)) throw new Error('菜单组件不在白名单中');
15
+ const externalLink = ['external', 'embedded'].includes(type) ? safeExternalUrl(model.externalLink) : '';
16
+ if (type === 'embedded') {
17
+ const origins = String(import.meta.env.VITE_IFRAME_ORIGINS ?? '')
18
+ .split(',')
19
+ .map((item) => item.trim());
20
+ if (!origins.includes(new URL(externalLink).origin)) throw new Error('iframe 来源不在独立白名单中');
21
+ }
22
+ const permissions =
23
+ typeof model.permissions === 'string'
24
+ ? stringArray(
25
+ model.permissions
26
+ .split(',')
27
+ .map((item) => item.trim())
28
+ .filter(Boolean),
29
+ )
30
+ : stringArray(model.permissions ?? []);
31
+ if (type === 'button' && !permissions.length) throw new Error('按钮必须配置权限标识');
32
+ return {
33
+ type,
34
+ path,
35
+ component,
36
+ externalLink,
37
+ permissions,
38
+ name: type === 'button' ? '' : text(model.name, '路由名', true),
39
+ parentId: text(model.parentId, '父节点'),
40
+ title: text(model.title, '标题', true),
41
+ icon: text(model.icon, '图标'),
42
+ order: integer(model.order ?? 0),
43
+ hidden: model.hidden === true,
44
+ };
45
+ }
46
+ export function parseMenu(value: unknown): Menu {
47
+ const raw = object(value);
48
+ // 远端业务菜单包含未生成页面时,仍允许管理其资料;路由下发另经严格白名单验证。
49
+ return {
50
+ id: text(raw.id, '菜单 ID', true),
51
+ title: text(raw.title, '标题', true),
52
+ parentId: text(raw.parentId, '父节点'),
53
+ type: raw.type as MenuType,
54
+ path: text(raw.path, '路径'),
55
+ name: text(raw.name, '路由名'),
56
+ component: text(raw.component, '组件'),
57
+ icon: text(raw.icon, '图标'),
58
+ order: integer(raw.order ?? 0),
59
+ hidden: raw.hidden === true,
60
+ permissions: stringArray(raw.permissions ?? (raw.permission ? [raw.permission] : [])),
61
+ externalLink: text(raw.externalLink, '外链'),
62
+ children: raw.children === undefined ? undefined : rows(raw.children, parseMenu),
63
+ };
64
+ }
65
+ export function createMenuService(transport: BusinessTransport) {
66
+ return {
67
+ list: async () => rows(await transport.request('GET', '/system/menus'), parseMenu),
68
+ create: async (input: MenuInput) => parseMenu(await transport.request('POST', '/system/menus', { body: input })),
69
+ update: async (id: string, input: MenuInput) =>
70
+ parseMenu(await transport.request('PUT', `/system/menus/${encodeURIComponent(id)}`, { body: input })),
71
+ remove: (id: string) => transport.request<void>('DELETE', `/system/menus/${encodeURIComponent(id)}`),
72
+ };
73
+ }
@@ -0,0 +1,106 @@
1
+ <script setup lang="ts">
2
+ import type { SchemaFormItem, SchemaFormModel } from '@lumal/core/components';
3
+ import type { Menu } from '../types';
4
+ import { LumalIconPicker } from '@lumal/icons-vue';
5
+ import { computed } from 'vue';
6
+ import { viewComponents } from '../../../../app/router/views';
7
+ import BaseEntityDialog from '../../../../shared/components/BaseEntityDialog.vue';
8
+ import { excludedDescendants } from '../../../../shared/tree';
9
+
10
+ /***********************节点类型约束与父级选择*********************/
11
+ const props = defineProps<{ records: Menu[]; editingId?: string; saving: boolean; error: string }>();
12
+ defineEmits<{ submit: [model: SchemaFormModel] }>();
13
+ const visible = defineModel<boolean>('visible', { required: true });
14
+ const model = defineModel<SchemaFormModel>('model', { required: true });
15
+ const schemas = computed<SchemaFormItem[]>(() => {
16
+ const excluded = excludedDescendants(props.records, props.editingId);
17
+ const parents = props.records.filter(
18
+ (item) =>
19
+ !excluded.has(item.id) &&
20
+ (model.value.type === 'button' ? ['menu', 'directory'].includes(item.type) : item.type === 'directory'),
21
+ );
22
+ return [
23
+ {
24
+ field: 'type',
25
+ label: '节点类型',
26
+ component: 'select',
27
+ required: true,
28
+ defaultValue: 'menu',
29
+ options: [
30
+ { label: '目录', value: 'directory' },
31
+ { label: '菜单', value: 'menu' },
32
+ { label: '按钮', value: 'button' },
33
+ { label: '外链', value: 'external' },
34
+ { label: '内嵌页面', value: 'embedded' },
35
+ ],
36
+ },
37
+ {
38
+ field: 'parentId',
39
+ label: '父节点',
40
+ component: 'select',
41
+ options: [{ label: '无', value: '' }, ...parents.map((item) => ({ label: item.title, value: item.id }))],
42
+ },
43
+ { field: 'title', label: '标题', required: true },
44
+ { field: 'name', label: '路由名', required: true, hidden: ({ model }) => model.type === 'button' },
45
+ { field: 'path', label: '路径', required: true, hidden: ({ model }) => model.type === 'button' },
46
+ {
47
+ field: 'component',
48
+ label: '页面组件',
49
+ component: 'select',
50
+ required: true,
51
+ options: Object.keys(viewComponents)
52
+ .filter((key) => key !== 'app/iframe')
53
+ .map((key) => ({ label: key, value: key })),
54
+ hidden: ({ model }) => model.type !== 'menu',
55
+ },
56
+ {
57
+ field: 'externalLink',
58
+ label: 'HTTP(S) 地址',
59
+ required: true,
60
+ hidden: ({ model }) => !['external', 'embedded'].includes(String(model.type)),
61
+ },
62
+ {
63
+ field: 'permissions',
64
+ label: '权限标识',
65
+ component: 'input',
66
+ placeholder: '多个权限以英文逗号分隔',
67
+ required: ({ model }) => model.type === 'button',
68
+ },
69
+ { field: 'icon', label: '图标', hidden: ({ model }) => model.type === 'button' },
70
+ { field: 'order', label: '排序', component: 'number', defaultValue: 0 },
71
+ {
72
+ field: 'hidden',
73
+ label: '隐藏',
74
+ component: 'switch',
75
+ defaultValue: false,
76
+ hidden: ({ model }) => model.type === 'button',
77
+ },
78
+ ];
79
+ });
80
+ const formModel = computed<SchemaFormModel>({
81
+ get: () => ({
82
+ ...model.value,
83
+ permissions: Array.isArray(model.value.permissions) ? model.value.permissions.join(',') : model.value.permissions,
84
+ }),
85
+ set: (value) => {
86
+ model.value = value;
87
+ },
88
+ });
89
+ </script>
90
+
91
+ <template>
92
+ <BaseEntityDialog
93
+ v-model:visible="visible"
94
+ v-model:model="formModel"
95
+ :title="editingId ? '编辑节点' : '新增节点'"
96
+ :schemas="schemas"
97
+ :editing="!!editingId"
98
+ :saving="saving"
99
+ :error="error"
100
+ @submit="$emit('submit', $event)"
101
+ >
102
+ <template #field-icon="{ value }">
103
+ <LumalIconPicker :model-value="String(value ?? '')" @update:model-value="model = { ...model, icon: $event }" />
104
+ </template>
105
+ </BaseEntityDialog>
106
+ </template>
@@ -0,0 +1,23 @@
1
+ import type { AppModule } from '../../../app/module';
2
+
3
+ export const menus: AppModule['menus'] = [
4
+ {
5
+ path: '/system/menus',
6
+ name: 'SystemMenus',
7
+ component: 'system/menus',
8
+ meta: { title: '菜单管理', authority: ['system:menu:list'], keepAlive: true, order: 3 },
9
+ },
10
+ ];
11
+ export const views: AppModule['views'] = { 'system/menus': () => import('./MenuView.vue') };
12
+ export const permissions: AppModule['permissions'] = [
13
+ {
14
+ id: 'system-menu',
15
+ label: '菜单管理',
16
+ children: [
17
+ { id: 'system:menu:list', label: '查询菜单', permission: 'system:menu:list' },
18
+ { id: 'system:menu:create', label: '新增节点', permission: 'system:menu:create' },
19
+ { id: 'system:menu:update', label: '修改节点', permission: 'system:menu:update' },
20
+ { id: 'system:menu:delete', label: '删除节点', permission: 'system:menu:delete' },
21
+ ],
22
+ },
23
+ ];
@@ -0,0 +1,18 @@
1
+ export type MenuType = 'directory' | 'menu' | 'button' | 'external' | 'embedded';
2
+ export interface MenuInput {
3
+ parentId: string;
4
+ type: MenuType;
5
+ title: string;
6
+ path: string;
7
+ name: string;
8
+ component: string;
9
+ icon: string;
10
+ order: number;
11
+ hidden: boolean;
12
+ permissions: string[];
13
+ externalLink: string;
14
+ }
15
+ export interface Menu extends MenuInput {
16
+ id: string;
17
+ children?: Menu[];
18
+ }
@@ -0,0 +1,22 @@
1
+ import type { AppModule } from '../../app/module';
2
+ import { assembleModules } from '../../app/module';
3
+ import * as config from './config/routes';
4
+ import * as dictionary from './dictionary/routes';
5
+ import * as menu from './menu/routes';
6
+ import * as organization from './organization/routes';
7
+ import * as role from './role/routes';
8
+ import * as user from './user/routes';
9
+
10
+ const children = assembleModules([user, role, menu, organization, dictionary, config]);
11
+ export const menus: AppModule['menus'] = [
12
+ {
13
+ path: '/system',
14
+ name: 'System',
15
+ meta: { title: '系统管理', icon: 'lumal:settings', order: 20 },
16
+ children: children.menus,
17
+ },
18
+ ];
19
+ export const views = children.views;
20
+ export const permissions: AppModule['permissions'] = [
21
+ { id: 'system', label: '系统管理', children: children.permissions },
22
+ ];
@@ -0,0 +1,134 @@
1
+ <script setup lang="ts">
2
+ import type { SchemaFormItem, SchemaTableColumn } from '@lumal/core/components';
3
+ import type { Organization } from './types';
4
+ import { LumalPage, LumalSchemaTable } from '@lumal/core/components';
5
+ import { LumalIcon } from '@lumal/icons-vue';
6
+ import { ElAlert, ElButton, ElInput } from 'element-plus';
7
+ import { computed, shallowRef } from 'vue';
8
+ import { permissionStore, service } from '../../../app/services/session';
9
+ import BaseEntityDialog from '../../../shared/components/BaseEntityDialog.vue';
10
+ import { useAsyncData } from '../../../shared/composables/use-async-data';
11
+ import { useEntityEditor } from '../../../shared/composables/use-entity-editor';
12
+ import { statusOptions } from '../../../shared/status';
13
+ import { excludedDescendants, flattenTree } from '../../../shared/tree';
14
+ import { createOrganizationService, organizationInput, parseOrganization } from './api';
15
+
16
+ /***********************机构树、关联限制与筛选*********************/
17
+ const api = createOrganizationService(service);
18
+ const state = useAsyncData(api.list, [] as Organization[]);
19
+ const keyword = shallowRef('');
20
+ const can = (action: string) => permissionStore.hasPermission(`system:organization:${action}`);
21
+ const editor = useEntityEditor<Organization, ReturnType<typeof organizationInput>>({
22
+ create: api.create,
23
+ update: api.update,
24
+ remove: api.remove,
25
+ toInput: organizationInput,
26
+ reload: state.load,
27
+ });
28
+ function filter(items: Organization[]): Organization[] {
29
+ return items.flatMap((item) => {
30
+ const children = filter(item.children ?? []);
31
+ return !keyword.value || `${item.name} ${item.code}`.includes(keyword.value) || children.length
32
+ ? [{ ...item, children }]
33
+ : [];
34
+ });
35
+ }
36
+ const displayed = computed(() => filter(state.data.value));
37
+ const columns: SchemaTableColumn<Organization>[] = [
38
+ { field: 'name', label: '机构名称', minWidth: 220 },
39
+ { field: 'code', label: '编码', minWidth: 130 },
40
+ { field: 'leader', label: '负责人', minWidth: 100 },
41
+ { field: 'phone', label: '联系电话', minWidth: 140 },
42
+ { field: 'status', label: '状态', options: statusOptions, width: 90 },
43
+ { field: 'userCount', label: '关联用户', width: 100, formatter: (value) => value ?? '-' },
44
+ { field: 'order', label: '排序', width: 80 },
45
+ ];
46
+ const schemas = computed<SchemaFormItem[]>(() => {
47
+ const all = flattenTree(state.data.value);
48
+ const excluded = excludedDescendants(all, editor.editing.value?.id);
49
+ return [
50
+ { field: 'name', label: '机构名称', required: true },
51
+ { field: 'code', label: '机构编码', required: true },
52
+ {
53
+ field: 'parentId',
54
+ label: '上级机构',
55
+ component: 'select',
56
+ options: [
57
+ { label: '无', value: '' },
58
+ ...all.filter((row) => !excluded.has(row.id)).map((row) => ({ label: row.name, value: row.id })),
59
+ ],
60
+ },
61
+ { field: 'leader', label: '负责人' },
62
+ { field: 'phone', label: '联系电话' },
63
+ { field: 'email', label: '邮箱', rules: [{ type: 'email', message: '邮箱格式错误' }] },
64
+ { field: 'order', label: '排序', component: 'number', defaultValue: 0 },
65
+ { field: 'status', label: '状态', component: 'select', options: statusOptions, defaultValue: 'enabled' },
66
+ ];
67
+ });
68
+ </script>
69
+
70
+ <template>
71
+ <LumalPage class="lumal-admin-page" title="机构管理" no-padding>
72
+ <ElAlert v-if="editor.error.value" :title="editor.error.value" type="error" :closable="false" />
73
+ <LumalSchemaTable
74
+ :columns="columns"
75
+ :rows="displayed"
76
+ :loading="state.loading.value"
77
+ :error="state.error.value"
78
+ default-expand-all
79
+ :action-width="240"
80
+ @retry="state.reload"
81
+ >
82
+ <template #toolbar>
83
+ <ElInput
84
+ v-model="keyword"
85
+ clearable
86
+ placeholder="搜索机构名称或编码"
87
+ aria-label="搜索机构"
88
+ style="max-width: 260px"
89
+ />
90
+ <ElButton
91
+ v-if="can('create')"
92
+ type="primary"
93
+ @click="editor.openCreate({ parentId: '', status: 'enabled', order: 0 })"
94
+ >
95
+ 新增机构
96
+ </ElButton>
97
+ </template>
98
+ <template #toolbar-tools>
99
+ <ElButton title="重新加载" aria-label="重新加载" @click="state.reload">
100
+ <LumalIcon name="lumal:refresh" />
101
+ </ElButton>
102
+ </template>
103
+ <template #actions="{ row }">
104
+ <ElButton
105
+ v-if="can('create')"
106
+ link
107
+ @click="editor.openCreate({ parentId: row.id, status: 'enabled', order: 0 })"
108
+ >
109
+ 新增子机构
110
+ </ElButton>
111
+ <ElButton v-if="can('update')" link @click="editor.openEdit(parseOrganization(row))"> 编辑 </ElButton>
112
+ <ElButton
113
+ v-if="can('delete')"
114
+ link
115
+ type="danger"
116
+ :disabled="editor.saving.value"
117
+ @click="editor.remove(parseOrganization(row))"
118
+ >
119
+ 删除
120
+ </ElButton>
121
+ </template>
122
+ </LumalSchemaTable>
123
+ <BaseEntityDialog
124
+ v-model:visible="editor.visible.value"
125
+ v-model:model="editor.model.value"
126
+ :title="editor.editing.value ? '编辑机构' : '新增机构'"
127
+ :schemas="schemas"
128
+ :editing="!!editor.editing.value"
129
+ :saving="editor.saving.value"
130
+ :error="editor.error.value"
131
+ @submit="editor.submit"
132
+ />
133
+ </LumalPage>
134
+ </template>
@@ -0,0 +1,38 @@
1
+ import type { SchemaFormModel } from '@lumal/core/components';
2
+ import type { BusinessTransport } from '../../../app/services/contracts';
3
+ import type { Organization, OrganizationInput } from './types';
4
+ import { formStatus, integer, object, rows, text } from '../../../shared/api';
5
+
6
+ export function organizationInput(model: SchemaFormModel): OrganizationInput {
7
+ return {
8
+ name: text(model.name, '机构名称', true),
9
+ code: text(model.code, '机构编码', true),
10
+ parentId: text(model.parentId, '父机构'),
11
+ leader: text(model.leader, '负责人'),
12
+ phone: text(model.phone, '联系电话'),
13
+ email: text(model.email, '邮箱'),
14
+ order: integer(model.order ?? 0),
15
+ status: formStatus(model),
16
+ };
17
+ }
18
+ export function parseOrganization(value: unknown): Organization {
19
+ const raw = object(value);
20
+ return {
21
+ ...organizationInput(raw),
22
+ id: text(raw.id, '机构 ID', true),
23
+ children: raw.children === undefined ? undefined : rows(raw.children, parseOrganization),
24
+ userCount: typeof raw.userCount === 'number' ? raw.userCount : undefined,
25
+ };
26
+ }
27
+ export function createOrganizationService(transport: BusinessTransport) {
28
+ return {
29
+ list: async () => rows(await transport.request('GET', '/system/organizations'), parseOrganization),
30
+ create: async (input: OrganizationInput) =>
31
+ parseOrganization(await transport.request('POST', '/system/organizations', { body: input })),
32
+ update: async (id: string, input: OrganizationInput) =>
33
+ parseOrganization(
34
+ await transport.request('PUT', `/system/organizations/${encodeURIComponent(id)}`, { body: input }),
35
+ ),
36
+ remove: (id: string) => transport.request<void>('DELETE', `/system/organizations/${encodeURIComponent(id)}`),
37
+ };
38
+ }
@@ -0,0 +1,23 @@
1
+ import type { AppModule } from '../../../app/module';
2
+
3
+ export const menus: AppModule['menus'] = [
4
+ {
5
+ path: '/system/organizations',
6
+ name: 'SystemOrganizations',
7
+ component: 'system/organizations',
8
+ meta: { title: '机构管理', authority: ['system:organization:list'], keepAlive: true, order: 4 },
9
+ },
10
+ ];
11
+ export const views: AppModule['views'] = { 'system/organizations': () => import('./OrganizationView.vue') };
12
+ export const permissions: AppModule['permissions'] = [
13
+ {
14
+ id: 'system-organization',
15
+ label: '机构管理',
16
+ children: [
17
+ { id: 'system:organization:list', label: '查询机构', permission: 'system:organization:list' },
18
+ { id: 'system:organization:create', label: '新增机构', permission: 'system:organization:create' },
19
+ { id: 'system:organization:update', label: '修改机构', permission: 'system:organization:update' },
20
+ { id: 'system:organization:delete', label: '删除机构', permission: 'system:organization:delete' },
21
+ ],
22
+ },
23
+ ];
@@ -0,0 +1,17 @@
1
+ import type { Status } from '../../../shared/api';
2
+
3
+ export interface OrganizationInput {
4
+ name: string;
5
+ code: string;
6
+ parentId: string;
7
+ leader: string;
8
+ phone: string;
9
+ email: string;
10
+ order: number;
11
+ status: Status;
12
+ }
13
+ export interface Organization extends OrganizationInput {
14
+ id: string;
15
+ children?: Organization[];
16
+ userCount?: number;
17
+ }
@@ -0,0 +1,90 @@
1
+ <script setup lang="ts">
2
+ import type { CrudDataSource, SchemaFormItem, SchemaTableColumn } from '@lumal/core/components';
3
+ import type { Role } from './types';
4
+ import { LumalCrudTable, LumalPage } from '@lumal/core/components';
5
+ import { ElAlert, ElButton } from 'element-plus';
6
+ import { shallowRef, useTemplateRef } from 'vue';
7
+ import { permissionStore, service } from '../../../app/services/session';
8
+ import { statusOptions } from '../../../shared/status';
9
+ import { createRoleService, parseRole, roleInput } from './api';
10
+ import RoleAuthorizationDialog from './components/RoleAuthorizationDialog.vue';
11
+
12
+ /***********************角色资料与授权分离*********************/
13
+ const api = createRoleService(service);
14
+ const table = useTemplateRef<InstanceType<typeof LumalCrudTable>>('table');
15
+ const authorizing = shallowRef<Role>();
16
+ const authorizationVisible = shallowRef(false);
17
+ const failure = shallowRef('');
18
+ const can = (action: string) => permissionStore.hasPermission(`system:role:${action}`);
19
+ const dataSource: CrudDataSource = {
20
+ fetch: (input) => api.list(input),
21
+ create: (model) => api.create(roleInput(model)),
22
+ update: (row, model) => api.update(parseRole(row).id, roleInput(model)),
23
+ remove: (row) => api.remove(parseRole(row).id),
24
+ };
25
+ const columns: SchemaTableColumn[] = [
26
+ { field: 'name', label: '角色名称', minWidth: 160 },
27
+ { field: 'code', label: '角色编码', minWidth: 140 },
28
+ { field: 'status', label: '状态', options: statusOptions, width: 100 },
29
+ { field: 'description', label: '说明', minWidth: 200 },
30
+ ];
31
+ const schemas: SchemaFormItem[] = [
32
+ { field: 'name', label: '角色名称', required: true },
33
+ {
34
+ field: 'code',
35
+ label: '角色编码',
36
+ required: true,
37
+ editDisabled: true,
38
+ rules: [{ pattern: /^[a-z][\w-]*$/, message: '使用小写字母开头的编码' }],
39
+ },
40
+ {
41
+ field: 'status',
42
+ label: '状态',
43
+ component: 'select',
44
+ options: statusOptions,
45
+ defaultValue: 'enabled',
46
+ disabled: ({ model }) => model.builtIn === true,
47
+ },
48
+ { field: 'description', label: '说明', component: 'textarea', span: 24 },
49
+ ];
50
+ const querySchemas: SchemaFormItem[] = [
51
+ { field: 'keyword', label: '关键词' },
52
+ { field: 'status', label: '状态', component: 'select', options: statusOptions },
53
+ ];
54
+ function authorize(role: Role): void {
55
+ authorizing.value = role;
56
+ authorizationVisible.value = true;
57
+ }
58
+ </script>
59
+
60
+ <template>
61
+ <LumalPage class="lumal-admin-page" title="角色管理" no-padding>
62
+ <ElAlert v-if="failure" :title="failure" type="error" :closable="false" />
63
+ <LumalCrudTable
64
+ ref="table"
65
+ :data-source="dataSource"
66
+ :form-schemas="schemas"
67
+ :table="{ columns, rowKey: 'id', actionWidth: 260 }"
68
+ :query="{ schemas: querySchemas, columns: 2, collapsible: true }"
69
+ :toolbar="{ create: can('create'), batchDelete: false }"
70
+ :actions="{ view: false, edit: false, remove: false }"
71
+ @operation-error="failure = $event instanceof Error ? $event.message : String($event)"
72
+ >
73
+ <template #row-actions="{ row }">
74
+ <ElButton link @click="table?.openView(row)"> 查看 </ElButton>
75
+ <ElButton v-if="can('update')" link @click="table?.openEdit(row)"> 编辑 </ElButton>
76
+ <ElButton v-if="can('authorize')" link @click="authorize(parseRole(row))"> 授权 </ElButton>
77
+ <ElButton
78
+ v-if="can('delete')"
79
+ link
80
+ type="danger"
81
+ :disabled="row.builtIn === true"
82
+ @click="table?.removeRow(row)"
83
+ >
84
+ 删除
85
+ </ElButton>
86
+ </template>
87
+ </LumalCrudTable>
88
+ <RoleAuthorizationDialog v-if="authorizing" v-model="authorizationVisible" :role="authorizing" />
89
+ </LumalPage>
90
+ </template>
@@ -0,0 +1,40 @@
1
+ import type { SchemaFormModel } from '@lumal/core/components';
2
+ import type { ApplicationService } from '../../../app/services/contracts';
3
+ import type { PageInput } from '../../../shared/api';
4
+ import type { Role, RoleInput } from './types';
5
+ import { formStatus, object, stringArray, text } from '../../../shared/api';
6
+ import { parsePermissionTree } from './permission-tree';
7
+
8
+ export function roleInput(model: SchemaFormModel): RoleInput {
9
+ return {
10
+ code: text(model.code, '角色编码', true),
11
+ name: text(model.name, '角色名称', true),
12
+ description: text(model.description, '说明'),
13
+ status: formStatus(model),
14
+ };
15
+ }
16
+ export function parseRole(value: unknown): Role {
17
+ const raw = object(value);
18
+ return { ...roleInput(raw), id: text(raw.id, '角色 ID', true), builtIn: raw.builtIn === true };
19
+ }
20
+ export function createRoleService(transport: Pick<ApplicationService, 'list' | 'request'>) {
21
+ return {
22
+ async list(input: PageInput) {
23
+ const page = await transport.list('roles', { ...input, query: { ...input.query } });
24
+ return { items: page.items.map(parseRole), total: page.total };
25
+ },
26
+ create: async (input: RoleInput) => parseRole(await transport.request('POST', '/system/roles', { body: input })),
27
+ update: async (id: string, input: RoleInput) =>
28
+ parseRole(await transport.request('PUT', `/system/roles/${encodeURIComponent(id)}`, { body: input })),
29
+ remove: (id: string) => transport.request<void>('DELETE', `/system/roles/${encodeURIComponent(id)}`),
30
+ tree: async () => parsePermissionTree(await transport.request('GET', '/system/permissions/tree')),
31
+ permissions: async (code: string) =>
32
+ stringArray(await transport.request('GET', `/system/roles/${encodeURIComponent(code)}/permissions`)),
33
+ authorize: async (code: string, permissions: string[]) =>
34
+ stringArray(
35
+ await transport.request('PUT', `/system/roles/${encodeURIComponent(code)}/permissions`, {
36
+ body: { permissions },
37
+ }),
38
+ ),
39
+ };
40
+ }