create-lumal-admin 0.0.5-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.
- package/CHANGELOG.md +13 -0
- package/README.md +39 -10
- package/dist/cli.d.ts +9 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +236 -19
- package/dist/cli.js.map +1 -1
- package/dist/create.d.ts +10 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +18 -5
- package/dist/create.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/presets.d.ts +29 -3
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js +38 -10
- package/dist/presets.js.map +1 -1
- package/dist/project-cli.d.ts +3 -0
- package/dist/project-cli.d.ts.map +1 -0
- package/dist/project-cli.js +13 -0
- package/dist/project-cli.js.map +1 -0
- package/dist/projects.d.ts +21 -0
- package/dist/projects.d.ts.map +1 -0
- package/dist/projects.js +124 -0
- package/dist/projects.js.map +1 -0
- package/dist/templates.d.ts +2 -0
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +42 -13
- package/dist/templates.js.map +1 -1
- package/dist/types.d.ts +39 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -3
- package/templates/base/API-CONTRACT.md +67 -20
- package/templates/base/README.md +20 -3
- package/templates/base/src/App.vue +71 -79
- package/templates/base/src/app/components/AppHeaderActions.vue +46 -0
- package/templates/base/src/{components/app → app/components}/AppSettingsDrawer.vue +15 -15
- package/templates/base/src/app/menu-policy.ts +163 -0
- package/templates/base/src/app/module.ts +46 -0
- package/templates/base/src/app/router/index.ts +107 -0
- package/templates/base/src/app/router/views.ts +12 -0
- package/templates/base/src/{services → app/services}/access.ts +1 -1
- package/templates/base/src/app/services/contracts.ts +54 -0
- package/templates/base/src/app/services/local-contracts.ts +18 -0
- package/templates/base/src/{services → app/services}/preferences.ts +8 -8
- package/templates/base/src/app/services/session-runtime.ts +186 -0
- package/templates/base/src/{services → app/services}/session.ts +4 -4
- package/templates/base/src/app/stored-menus.ts +72 -0
- package/templates/base/src/app/views/SafeIframeView.vue +34 -0
- package/templates/base/src/{views → app/views}/auth/LoginView.vue +29 -34
- package/templates/base/src/app/views/error/ForbiddenView.vue +20 -0
- package/templates/base/src/{views → app/views}/error/NotFoundView.vue +5 -7
- package/templates/base/src/main.ts +21 -22
- package/templates/base/src/modules/business/README.md +33 -0
- package/templates/base/src/{views → modules}/dashboard/DashboardView.vue +3 -3
- package/templates/base/src/modules/dashboard/module.ts +14 -0
- package/templates/base/src/shared/api.ts +53 -0
- package/templates/base/src/shared/components/BaseEntityDialog.vue +39 -0
- package/templates/base/src/shared/composables/use-async-data.ts +35 -0
- package/templates/base/src/shared/composables/use-entity-editor.ts +77 -0
- package/templates/base/src/shared/status.ts +4 -0
- package/templates/base/src/shared/tree.ts +41 -0
- package/templates/base/src/styles.scss +1 -6
- package/templates/base/tests/menu-policy.test.ts.template +89 -0
- package/templates/base/tests/session.test.ts.template +38 -27
- package/templates/base/vite.config.ts +4 -4
- package/templates/blank/README.md +6 -0
- package/templates/blank/src/App.vue +11 -0
- package/templates/common/AGENTS.md +13 -0
- package/templates/common/_editorconfig +15 -0
- package/templates/common/_gitattributes +6 -0
- package/templates/{base → common}/_gitignore +1 -0
- package/templates/common/_prettierignore +6 -0
- package/templates/common/docs/DEVELOPMENT.md +26 -0
- package/templates/common/eslint.config.mjs +60 -0
- package/templates/common/package.json +39 -0
- package/templates/common/prettier.config.mjs +8 -0
- package/templates/{base → common}/tsconfig.json +2 -5
- package/templates/common/vitest.config.ts +3 -0
- package/templates/features/examples/src/modules/examples/CrudExampleView.vue +51 -0
- package/templates/features/examples/src/{views → modules}/examples/FormExampleView.vue +15 -8
- package/templates/features/examples/src/modules/examples/module.ts +27 -0
- package/templates/features/system/src/modules/system/config/ConfigView.vue +104 -0
- package/templates/features/system/src/modules/system/config/api.ts +38 -0
- package/templates/features/system/src/modules/system/config/routes.ts +21 -0
- package/templates/features/system/src/modules/system/dictionary/DictionaryItemView.vue +141 -0
- package/templates/features/system/src/modules/system/dictionary/DictionaryTypeView.vue +107 -0
- package/templates/features/system/src/modules/system/dictionary/api.ts +61 -0
- package/templates/features/system/src/modules/system/dictionary/cache.ts +9 -0
- package/templates/features/system/src/modules/system/dictionary/routes.ts +32 -0
- package/templates/features/system/src/modules/system/dictionary/types.ts +22 -0
- package/templates/features/system/src/modules/system/local.ts +348 -0
- package/templates/features/system/src/modules/system/menu/MenuView.vue +133 -0
- package/templates/features/system/src/modules/system/menu/api.ts +73 -0
- package/templates/features/system/src/modules/system/menu/components/MenuEditorDialog.vue +106 -0
- package/templates/features/system/src/modules/system/menu/routes.ts +23 -0
- package/templates/features/system/src/modules/system/menu/types.ts +18 -0
- package/templates/features/system/src/modules/system/module.ts +22 -0
- package/templates/features/system/src/modules/system/organization/OrganizationView.vue +134 -0
- package/templates/features/system/src/modules/system/organization/api.ts +38 -0
- package/templates/features/system/src/modules/system/organization/routes.ts +23 -0
- package/templates/features/system/src/modules/system/organization/types.ts +17 -0
- package/templates/features/system/src/modules/system/role/RoleView.vue +90 -0
- package/templates/features/system/src/modules/system/role/api.ts +40 -0
- package/templates/features/system/src/modules/system/role/components/RoleAuthorizationDialog.vue +110 -0
- package/templates/features/system/src/modules/system/role/permission-tree.ts +31 -0
- package/templates/features/system/src/modules/system/role/routes.ts +24 -0
- package/templates/features/system/src/modules/system/role/types.ts +12 -0
- package/templates/features/system/src/modules/system/user/UserView.vue +297 -0
- package/templates/features/system/src/modules/system/user/api.ts +45 -0
- package/templates/features/system/src/modules/system/user/components/UserOrganizationFilter.vue +61 -0
- package/templates/features/system/src/modules/system/user/components/UserRoleDialog.vue +93 -0
- package/templates/features/system/src/modules/system/user/routes.ts +27 -0
- package/templates/features/system/src/modules/system/user/types.ts +28 -0
- package/templates/features/system/tests/system.test.ts.template +266 -0
- package/templates/modes/http/src/app/services/data-source.ts +124 -0
- package/templates/modes/http/src/app/services/http-adapter.ts +128 -0
- package/templates/modes/http/tests/http.test.ts.template +186 -133
- package/templates/modes/local/src/app/services/data-source.ts +113 -0
- package/templates/modes/local/src/app/services/local-database.ts +67 -0
- package/templates/modes/local/tests/local.test.ts.template +117 -77
- package/templates/presets/standard/src/modules/dashboard/DashboardView.vue +52 -0
- package/templates/presets/standard/src/modules/dashboard/components/DashboardSessionStatus.vue +41 -0
- package/templates/presets/standard/src/modules/dashboard/components/DashboardShortcuts.vue +51 -0
- package/templates/presets/standard/src/modules/profile/ProfileView.vue +109 -0
- package/templates/presets/standard/src/modules/profile/api.ts +49 -0
- package/templates/presets/standard/src/modules/profile/components/ProfilePasswordForm.vue +68 -0
- package/templates/presets/standard/src/modules/profile/local.ts +40 -0
- package/templates/presets/standard/src/modules/profile/module.ts +11 -0
- package/templates/presets/standard/tests/profile.test.ts.template +72 -0
- package/templates/screen/README.md +6 -0
- package/templates/screen/src/App.vue +7 -0
- package/templates/screen/src/screen/ScreenEntry.vue +18 -0
- package/templates/screen/src/screen/ScreenView.vue +48 -0
- package/templates/screen/src/screen/components/ScreenMetrics.vue +40 -0
- package/templates/screen-auth/src/screen/ScreenEntry.vue +52 -0
- package/templates/screen-auth/src/screen/components/ScreenLoginForm.vue +44 -0
- package/templates/screen-auth/src/services/session.ts +61 -0
- package/templates/screen-auth/tests/session.test.ts.template +54 -0
- package/templates/screen-auth-http/src/services/auth-adapter.ts +14 -0
- package/templates/screen-auth-http/tests/auth-adapter.test.ts.template +17 -0
- package/templates/screen-auth-local-demo/src/services/auth-adapter.ts +15 -0
- package/templates/screen-auth-local-demo/tests/auth-adapter.test.ts.template +18 -0
- package/templates/screen-data/src/screen/ScreenView.vue +69 -0
- package/templates/screen-data/src/services/metrics-types.ts +4 -0
- package/templates/screen-data-http/src/services/metrics.ts +20 -0
- package/templates/screen-data-http/src/services/request.ts +3 -0
- package/templates/screen-data-http/tests/metrics.test.ts.template +21 -0
- package/templates/screen-data-local/src/services/metrics.ts +11 -0
- package/templates/screen-data-local/tests/metrics.test.ts.template +9 -0
- package/templates/screen-http/API-CONTRACT.md +20 -0
- package/templates/screen-http/src/services/http.ts +17 -0
- package/templates/screen-request-auth/src/services/request.ts +15 -0
- package/templates/screen-router/src/App.vue +7 -0
- package/templates/screen-router/src/main.ts +13 -0
- package/templates/screen-router/src/router.ts +7 -0
- package/templates/screen-router/tests/app.test.ts.template +20 -0
- package/templates/screen-viewport/src/screen/ScreenViewport.vue +30 -0
- package/templates/screen-visualization-charts/src/screen/components/ScreenVisualization.vue +22 -0
- package/templates/screen-visualization-cockpit/src/screen/components/ScreenVisualization.vue +33 -0
- package/templates/screen-visualization-cockpit/src/screen/components/ScreenWidget.vue +10 -0
- package/templates/screen-visualization-datav/src/screen/components/ScreenVisualization.vue +11 -0
- package/templates/vben-compatible/MIGRATION.md +2 -0
- package/templates/vben-compatible/src/{views/migration → modules/vben-migration}/VbenFormView.vue +2 -1
- package/templates/vben-compatible/src/{views/migration → modules/vben-migration}/VbenUsersView.vue +3 -2
- package/templates/vben-compatible/src/modules/vben-migration/components/VbenFormExample.vue +64 -0
- package/templates/vben-compatible/src/{components/migration → modules/vben-migration/components}/VbenUsers.vue +73 -64
- package/templates/vben-compatible/src/modules/vben-migration/local.ts +68 -0
- package/templates/vben-compatible/src/modules/vben-migration/module.ts +42 -0
- package/templates/vue/index.html +12 -0
- package/templates/vue/src/main.ts +5 -0
- package/templates/vue/src/styles.css +19 -0
- package/templates/vue/tests/app.test.ts.template +10 -0
- package/templates/vue/vite.config.ts +9 -0
- package/templates/vue/vitest.config.ts +4 -0
- package/templates/base/eslint.config.mjs +0 -8
- package/templates/base/src/components/app/AppHeaderActions.vue +0 -34
- package/templates/base/src/router/index.ts +0 -86
- package/templates/base/src/router/views.ts +0 -16
- package/templates/base/src/services/contracts.ts +0 -29
- package/templates/base/src/services/session-runtime.ts +0 -137
- package/templates/base/src/views/error/ForbiddenView.vue +0 -25
- package/templates/base/vitest.config.ts +0 -3
- package/templates/features/examples/src/modules/examples.ts +0 -10
- package/templates/features/examples/src/views/examples/CrudExampleView.vue +0 -30
- package/templates/features/system/src/business/system/entities.ts +0 -93
- package/templates/features/system/src/modules/system.ts +0 -28
- package/templates/features/system/src/views/system/SystemEntityView.vue +0 -85
- package/templates/modes/http/src/services/data-source.ts +0 -120
- package/templates/modes/http/src/services/http-adapter.ts +0 -124
- package/templates/modes/local/src/services/data-source.ts +0 -176
- package/templates/vben-compatible/src/components/migration/VbenFormExample.vue +0 -34
- package/templates/vben-compatible/src/modules/vben.ts +0 -17
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequestClient } from '@lumal/core/request';
|
|
2
|
+
import { apiBaseURL, prepareRequest } from './http';
|
|
3
|
+
import { getSessionScope, getSessionSignal, getSessionToken, refreshSession, signOut } from './session';
|
|
4
|
+
|
|
5
|
+
export const request = createRequestClient({
|
|
6
|
+
baseURL: apiBaseURL,
|
|
7
|
+
getToken: getSessionToken,
|
|
8
|
+
getCacheScope: getSessionScope,
|
|
9
|
+
onRequest: ({ init }) => {
|
|
10
|
+
prepareRequest(init);
|
|
11
|
+
init.signal = AbortSignal.any([init.signal!, getSessionSignal()]);
|
|
12
|
+
},
|
|
13
|
+
authRefresh: { refresh: refreshSession },
|
|
14
|
+
onSessionExpired: () => signOut(),
|
|
15
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createApp } from 'vue';
|
|
2
|
+
import App from './App.vue';
|
|
3
|
+
import { router } from './router';
|
|
4
|
+
import './styles.css';
|
|
5
|
+
|
|
6
|
+
async function bootstrap() {
|
|
7
|
+
const app = createApp(App);
|
|
8
|
+
app.use(router);
|
|
9
|
+
await router.isReady();
|
|
10
|
+
app.mount('#app');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
void bootstrap();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createRouter, createWebHashHistory } from 'vue-router';
|
|
2
|
+
import ScreenEntry from './screen/ScreenEntry.vue';
|
|
3
|
+
|
|
4
|
+
export const router = createRouter({
|
|
5
|
+
history: createWebHashHistory(import.meta.env.BASE_URL),
|
|
6
|
+
routes: [{ path: '/', name: 'Screen', component: ScreenEntry }],
|
|
7
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createSSRApp } from 'vue';
|
|
3
|
+
import { createMemoryHistory, createRouter } from 'vue-router';
|
|
4
|
+
import { renderToString } from 'vue/server-renderer';
|
|
5
|
+
import App from '../src/App.vue';
|
|
6
|
+
import ScreenEntry from '../src/screen/ScreenEntry.vue';
|
|
7
|
+
|
|
8
|
+
describe('应用路由', () => {
|
|
9
|
+
it('可以渲染首页', async () => {
|
|
10
|
+
const router = createRouter({
|
|
11
|
+
history: createMemoryHistory(),
|
|
12
|
+
routes: [{ path: '/', component: ScreenEntry }],
|
|
13
|
+
});
|
|
14
|
+
const app = createSSRApp(App);
|
|
15
|
+
app.use(router);
|
|
16
|
+
await router.push('/');
|
|
17
|
+
await router.isReady();
|
|
18
|
+
expect(await renderToString(app)).toContain('<main');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { LumalViewport } from '@lumal/viewport';
|
|
3
|
+
|
|
4
|
+
/***********************只适配实际内容区,登录栏独立占位*********************/
|
|
5
|
+
const policy = {
|
|
6
|
+
mode: /* VIEWPORT_MODE */ 'contain',
|
|
7
|
+
designWidth: 1920,
|
|
8
|
+
designHeight: 1080,
|
|
9
|
+
minFontSize: 12,
|
|
10
|
+
} as const;
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<div class="screen-viewport">
|
|
15
|
+
<LumalViewport :policy="policy">
|
|
16
|
+
<slot />
|
|
17
|
+
</LumalViewport>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<style scoped>
|
|
22
|
+
.screen-viewport {
|
|
23
|
+
flex: 1;
|
|
24
|
+
min-width: 0;
|
|
25
|
+
min-height: 0;
|
|
26
|
+
}
|
|
27
|
+
.screen-viewport :deep([data-viewport-mode='vw'] .screen-view) {
|
|
28
|
+
padding: max(16px, calc(32 * var(--lumal-viewport-x-unit)));
|
|
29
|
+
}
|
|
30
|
+
</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { EChartsOption } from 'echarts';
|
|
3
|
+
import { LumalChart } from '@lumal/charts';
|
|
4
|
+
import { LineChart } from 'echarts/charts';
|
|
5
|
+
import { GridComponent, TooltipComponent } from 'echarts/components';
|
|
6
|
+
import { use } from 'echarts/core';
|
|
7
|
+
import { CanvasRenderer } from 'echarts/renderers';
|
|
8
|
+
import '@lumal/charts/style.css';
|
|
9
|
+
|
|
10
|
+
/***********************只注册示例实际使用的图表能力*********************/
|
|
11
|
+
use([LineChart, GridComponent, TooltipComponent, CanvasRenderer]);
|
|
12
|
+
const options: EChartsOption = {
|
|
13
|
+
grid: { top: 20, right: 20, left: 44, bottom: 24 },
|
|
14
|
+
xAxis: { type: 'category', data: ['A', 'B', 'C', 'D', 'E'] },
|
|
15
|
+
yAxis: { type: 'value' },
|
|
16
|
+
series: [{ type: 'line', data: [12, 24, 18, 36, 30] }],
|
|
17
|
+
};
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<template>
|
|
21
|
+
<LumalChart :options="options" height="240px" />
|
|
22
|
+
</template>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { createDefaultCockpitConfig, createWidgetInstance } from '@lumal/cockpit';
|
|
3
|
+
import { createCockpitRegistry } from '@lumal/cockpit/registry';
|
|
4
|
+
import { LumalCockpit } from '@lumal/cockpit/runtime';
|
|
5
|
+
import '@lumal/cockpit/style.css';
|
|
6
|
+
import 'element-plus/dist/index.css';
|
|
7
|
+
|
|
8
|
+
/***********************最小运行时编排,不加载 Designer*********************/
|
|
9
|
+
const registry = createCockpitRegistry();
|
|
10
|
+
registry.registerWidget({ type: 'metric', label: '指标', component: () => import('./ScreenWidget.vue') });
|
|
11
|
+
const config = createDefaultCockpitConfig('screen-demo');
|
|
12
|
+
const layout = config.layouts[0]!;
|
|
13
|
+
layout.left.width = layout.right.width = 200;
|
|
14
|
+
layout.left.columns[0]!.width = layout.right.columns[0]!.width = 200;
|
|
15
|
+
layout.left.rows[0]!.cells[0]!.widget = createWidgetInstance('metric', '任务指标');
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<div class="screen-cockpit">
|
|
20
|
+
<LumalCockpit :config="config" :registry="registry" viewport-mode="external">
|
|
21
|
+
<template #center><p>数据总览</p></template>
|
|
22
|
+
</LumalCockpit>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<style scoped>
|
|
27
|
+
.screen-cockpit {
|
|
28
|
+
width: 100%;
|
|
29
|
+
height: 360px;
|
|
30
|
+
min-width: 0;
|
|
31
|
+
overflow: auto;
|
|
32
|
+
}
|
|
33
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import LumalBorderBox from '@lumal/datav/border-box';
|
|
3
|
+
import LumalDigitalFlop from '@lumal/datav/digital-flop';
|
|
4
|
+
import '@lumal/datav/style.css';
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<template>
|
|
8
|
+
<LumalBorderBox :variant="8" style="height: 180px">
|
|
9
|
+
<LumalDigitalFlop :value="128" suffix=" 项" />
|
|
10
|
+
</LumalBorderBox>
|
|
11
|
+
</template>
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
6. 原 Vben Drawer/Modal 改为 Element Plus Dialog 或 Lumal CRUD 编辑器。
|
|
14
14
|
7. `@vben/access` 的高频用法可改为本入口的 AccessControl / useAccess;
|
|
15
15
|
路由数据先经 adaptVbenMenus,authority 按角色匹配。
|
|
16
|
+
8. `#toolbar-actions` 与 `#toolbar-tools` 用于具名工具栏插槽;当前不注入完整 VXE 工具栏上下文,
|
|
17
|
+
命令通过已获得的 `gridApi` 调用。兼容页面位于独立 `modules/vben-migration`,不混入系统管理。
|
|
16
18
|
|
|
17
19
|
本模板 `migration/form` 对应 web-ele/demos/form/basic 与共享 rules/dynamic
|
|
18
20
|
场景;`migration/users` 对应共享 vxe-table/form 和 system/user 的
|
package/templates/vben-compatible/src/{views/migration → modules/vben-migration}/VbenFormView.vue
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/***********************迁移表单场景装配*********************/
|
|
3
|
-
import VbenFormExample from '
|
|
3
|
+
import VbenFormExample from './components/VbenFormExample.vue';
|
|
4
|
+
import '@lumal/vben-compat/style.css';
|
|
4
5
|
</script>
|
|
5
6
|
|
|
6
7
|
<template>
|
package/templates/vben-compatible/src/{views/migration → modules/vben-migration}/VbenUsersView.vue
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { service } from '../../app/services/session';
|
|
2
3
|
/***********************迁移业务场景装配*********************/
|
|
3
|
-
import VbenUsers from '
|
|
4
|
-
import
|
|
4
|
+
import VbenUsers from './components/VbenUsers.vue';
|
|
5
|
+
import '@lumal/vben-compat/style.css';
|
|
5
6
|
</script>
|
|
6
7
|
|
|
7
8
|
<template>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useVbenForm } from '@lumal/vben-compat/v5';
|
|
3
|
+
import { shallowRef } from 'vue';
|
|
4
|
+
|
|
5
|
+
/***********************5.7.0 基础控件与动态依赖迁移*********************/
|
|
6
|
+
const submitted = shallowRef('');
|
|
7
|
+
const [Form, formApi] = useVbenForm({
|
|
8
|
+
layout: 'horizontal',
|
|
9
|
+
wrapperClass: 'grid-cols-2',
|
|
10
|
+
handleSubmit(values) {
|
|
11
|
+
submitted.value = JSON.stringify(values);
|
|
12
|
+
},
|
|
13
|
+
schema: [
|
|
14
|
+
{ component: 'Input', fieldName: 'name', label: '姓名', rules: 'required' },
|
|
15
|
+
{
|
|
16
|
+
component: 'Select',
|
|
17
|
+
fieldName: 'role',
|
|
18
|
+
label: '角色',
|
|
19
|
+
rules: 'selectRequired',
|
|
20
|
+
componentProps: {
|
|
21
|
+
options: [
|
|
22
|
+
{ label: '管理员', value: 'admin' },
|
|
23
|
+
{ label: '访客', value: 'guest' },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
component: 'DatePicker',
|
|
29
|
+
fieldName: 'date',
|
|
30
|
+
label: '日期',
|
|
31
|
+
rules: 'selectRequired',
|
|
32
|
+
componentProps: { valueFormat: 'YYYY-MM-DD' },
|
|
33
|
+
},
|
|
34
|
+
{ component: 'Switch', fieldName: 'enabled', label: '启用扩展', defaultValue: true },
|
|
35
|
+
{
|
|
36
|
+
component: 'Input',
|
|
37
|
+
fieldName: 'remark',
|
|
38
|
+
label: '备注',
|
|
39
|
+
dependencies: {
|
|
40
|
+
triggerFields: ['enabled', 'role'],
|
|
41
|
+
if: (values) => Boolean(values.enabled),
|
|
42
|
+
disabled: (values) => values.role === 'guest',
|
|
43
|
+
required: (values) => values.role === 'admin',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
component: 'Input',
|
|
48
|
+
fieldName: 'cssHidden',
|
|
49
|
+
label: '保留值字段',
|
|
50
|
+
defaultValue: 'retained',
|
|
51
|
+
dependencies: { triggerFields: ['enabled'], show: (values) => Boolean(values.enabled) },
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
defineExpose({ formApi });
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<template>
|
|
59
|
+
<section>
|
|
60
|
+
<h2>Vben 5 表单</h2>
|
|
61
|
+
<Form />
|
|
62
|
+
<output aria-label="提交结果">{{ submitted }}</output>
|
|
63
|
+
</section>
|
|
64
|
+
</template>
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import type { ApplicationService, DataRow } from '
|
|
3
|
-
import { AccessControl, useAccess, useVbenForm, useVbenVxeGrid } from '@lumal/vben-compat/v5'
|
|
4
|
-
import { ElButton, ElDialog, ElMessageBox } from 'element-plus'
|
|
5
|
-
import { nextTick, shallowRef } from 'vue'
|
|
2
|
+
import type { ApplicationService, DataRow } from '../../../app/services/contracts';
|
|
3
|
+
import { AccessControl, useAccess, useVbenForm, useVbenVxeGrid } from '@lumal/vben-compat/v5';
|
|
4
|
+
import { ElButton, ElDialog, ElMessageBox } from 'element-plus';
|
|
5
|
+
import { nextTick, shallowRef } from 'vue';
|
|
6
6
|
|
|
7
7
|
/***********************业务服务与权限边界*********************/
|
|
8
|
-
const props = defineProps<{ service: Pick<ApplicationService, 'list' | 'save' | 'remove'> }>()
|
|
9
|
-
const { hasAccessByCodes } = useAccess()
|
|
10
|
-
const visible = shallowRef(false)
|
|
11
|
-
const editingId = shallowRef<string>()
|
|
12
|
-
const failure = shallowRef('')
|
|
8
|
+
const props = defineProps<{ service: Pick<ApplicationService, 'list' | 'save' | 'remove'> }>();
|
|
9
|
+
const { hasAccessByCodes } = useAccess();
|
|
10
|
+
const visible = shallowRef(false);
|
|
11
|
+
const editingId = shallowRef<string>();
|
|
12
|
+
const failure = shallowRef('');
|
|
13
13
|
function rowId(row: DataRow): string {
|
|
14
|
-
if (typeof row.id !== 'string' && typeof row.id !== 'number')
|
|
15
|
-
|
|
16
|
-
return String(row.id)
|
|
14
|
+
if (typeof row.id !== 'string' && typeof row.id !== 'number') throw new Error('用户缺少 id');
|
|
15
|
+
return String(row.id);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
/***********************5.7.0 查询分页与列插槽迁移*********************/
|
|
@@ -33,16 +32,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|
|
33
32
|
pagerConfig: { pageSize: 10 },
|
|
34
33
|
proxyConfig: {
|
|
35
34
|
ajax: {
|
|
36
|
-
query: ({ page, sort }, formValues) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
query: ({ page, sort }, formValues) =>
|
|
36
|
+
props.service.list('users', {
|
|
37
|
+
page: page.currentPage,
|
|
38
|
+
pageSize: page.pageSize,
|
|
39
|
+
query: { ...formValues, sortField: sort.field, sortOrder: sort.order },
|
|
40
|
+
}),
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
toolbarConfig: { custom: true, refresh: true, search: true },
|
|
44
44
|
},
|
|
45
|
-
})
|
|
45
|
+
});
|
|
46
46
|
|
|
47
47
|
/***********************新增编辑弹窗与失败恢复*********************/
|
|
48
48
|
const [Form, formApi] = useVbenForm({
|
|
@@ -50,52 +50,69 @@ const [Form, formApi] = useVbenForm({
|
|
|
50
50
|
schema: [
|
|
51
51
|
{ component: 'Input', fieldName: 'username', label: '用户名', rules: 'required' },
|
|
52
52
|
{ component: 'Input', fieldName: 'nickname', label: '昵称', rules: 'required' },
|
|
53
|
-
{
|
|
54
|
-
|
|
53
|
+
{
|
|
54
|
+
component: 'Select',
|
|
55
|
+
fieldName: 'roles',
|
|
56
|
+
label: '角色',
|
|
57
|
+
defaultValue: ['guest'],
|
|
58
|
+
componentProps: {
|
|
59
|
+
multiple: true,
|
|
60
|
+
options: [
|
|
61
|
+
{ label: '访客', value: 'guest' },
|
|
62
|
+
{ label: '管理员', value: 'admin' },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
component: 'Select',
|
|
68
|
+
fieldName: 'status',
|
|
69
|
+
label: '状态',
|
|
70
|
+
defaultValue: 'enabled',
|
|
71
|
+
componentProps: {
|
|
72
|
+
options: [
|
|
73
|
+
{ label: '启用', value: 'enabled' },
|
|
74
|
+
{ label: '停用', value: 'disabled' },
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
55
78
|
],
|
|
56
|
-
})
|
|
57
|
-
const saving = shallowRef(false)
|
|
79
|
+
});
|
|
80
|
+
const saving = shallowRef(false);
|
|
58
81
|
async function open(row?: DataRow): Promise<void> {
|
|
59
|
-
editingId.value = row ? rowId(row) : undefined
|
|
60
|
-
failure.value = ''
|
|
61
|
-
visible.value = true
|
|
62
|
-
await nextTick()
|
|
63
|
-
await formApi.resetForm()
|
|
64
|
-
if (row)
|
|
65
|
-
await formApi.setValues(row)
|
|
82
|
+
editingId.value = row ? rowId(row) : undefined;
|
|
83
|
+
failure.value = '';
|
|
84
|
+
visible.value = true;
|
|
85
|
+
await nextTick();
|
|
86
|
+
await formApi.resetForm();
|
|
87
|
+
if (row) await formApi.setValues(row);
|
|
66
88
|
}
|
|
67
89
|
async function save(): Promise<void> {
|
|
68
|
-
if (saving.value || !(await formApi.validate()).valid)
|
|
69
|
-
|
|
70
|
-
saving.value = true
|
|
90
|
+
if (saving.value || !(await formApi.validate()).valid) return;
|
|
91
|
+
saving.value = true;
|
|
71
92
|
try {
|
|
72
|
-
await props.service.save('users', await formApi.getValues(), editingId.value)
|
|
73
|
-
visible.value = false
|
|
74
|
-
await gridApi.query()
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
finally {
|
|
80
|
-
saving.value = false
|
|
93
|
+
await props.service.save('users', await formApi.getValues(), editingId.value);
|
|
94
|
+
visible.value = false;
|
|
95
|
+
await gridApi.query();
|
|
96
|
+
} catch (error) {
|
|
97
|
+
failure.value = error instanceof Error ? error.message : String(error);
|
|
98
|
+
} finally {
|
|
99
|
+
saving.value = false;
|
|
81
100
|
}
|
|
82
101
|
}
|
|
83
102
|
async function remove(row: DataRow): Promise<void> {
|
|
84
103
|
try {
|
|
85
|
-
await ElMessageBox.confirm(`删除 ${String(row.username)}?`, '删除确认')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return // Element Plus 的取消和关闭都表示不执行删除。
|
|
104
|
+
await ElMessageBox.confirm(`删除 ${String(row.username)}?`, '删除确认');
|
|
105
|
+
} catch {
|
|
106
|
+
return; // Element Plus 的取消和关闭都表示不执行删除。
|
|
89
107
|
}
|
|
90
108
|
try {
|
|
91
|
-
await props.service.remove('users', rowId(row))
|
|
92
|
-
await gridApi.query()
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
failure.value = error instanceof Error ? error.message : String(error)
|
|
109
|
+
await props.service.remove('users', rowId(row));
|
|
110
|
+
await gridApi.query();
|
|
111
|
+
} catch (error) {
|
|
112
|
+
failure.value = error instanceof Error ? error.message : String(error);
|
|
96
113
|
}
|
|
97
114
|
}
|
|
98
|
-
defineExpose({ gridApi })
|
|
115
|
+
defineExpose({ gridApi });
|
|
99
116
|
</script>
|
|
100
117
|
|
|
101
118
|
<template>
|
|
@@ -104,17 +121,13 @@ defineExpose({ gridApi })
|
|
|
104
121
|
{{ failure }}
|
|
105
122
|
</p>
|
|
106
123
|
<Grid>
|
|
107
|
-
<template #toolbar-
|
|
124
|
+
<template #toolbar-actions>
|
|
108
125
|
<AccessControl type="code" :codes="['system:user:create']">
|
|
109
|
-
<ElButton type="primary" @click="open()">
|
|
110
|
-
新增用户
|
|
111
|
-
</ElButton>
|
|
126
|
+
<ElButton type="primary" @click="open()"> 新增用户 </ElButton>
|
|
112
127
|
</AccessControl>
|
|
113
128
|
</template>
|
|
114
129
|
<template #operation="{ row }">
|
|
115
|
-
<ElButton v-if="hasAccessByCodes(['system:user:update'])" link @click="open(row)">
|
|
116
|
-
编辑
|
|
117
|
-
</ElButton>
|
|
130
|
+
<ElButton v-if="hasAccessByCodes(['system:user:update'])" link @click="open(row)"> 编辑 </ElButton>
|
|
118
131
|
<ElButton v-if="hasAccessByCodes(['system:user:delete'])" link type="danger" @click="remove(row)">
|
|
119
132
|
删除
|
|
120
133
|
</ElButton>
|
|
@@ -123,12 +136,8 @@ defineExpose({ gridApi })
|
|
|
123
136
|
<ElDialog v-model="visible" :title="editingId ? '编辑用户' : '新增用户'" destroy-on-close width="min(640px, 92vw)">
|
|
124
137
|
<Form />
|
|
125
138
|
<template #footer>
|
|
126
|
-
<ElButton @click="visible = false">
|
|
127
|
-
|
|
128
|
-
</ElButton>
|
|
129
|
-
<ElButton type="primary" :loading="saving" @click="save">
|
|
130
|
-
保存
|
|
131
|
-
</ElButton>
|
|
139
|
+
<ElButton @click="visible = false"> 取消 </ElButton>
|
|
140
|
+
<ElButton type="primary" :loading="saving" @click="save"> 保存 </ElButton>
|
|
132
141
|
</template>
|
|
133
142
|
</ElDialog>
|
|
134
143
|
</section>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { LocalBusinessContext, LocalHandler } from '../../app/services/local-contracts';
|
|
2
|
+
import { appConfig } from '../../app.config';
|
|
3
|
+
import { object, stringArray } from '../../app/menu-policy';
|
|
4
|
+
import { status } from '../../shared/api';
|
|
5
|
+
|
|
6
|
+
// 仅迁移示例独立启用时使用,标准系统模块启用后由系统用户服务接管。
|
|
7
|
+
export function createLocalHandler({ db, user, assertPermission }: LocalBusinessContext): LocalHandler {
|
|
8
|
+
return {
|
|
9
|
+
handles: (path) => !appConfig.features.includes('system') && /^\/system\/users(?:\/[^/]+)?$/.test(path),
|
|
10
|
+
async request(method, path, input) {
|
|
11
|
+
user();
|
|
12
|
+
if (!['GET', 'POST', 'PUT', 'DELETE'].includes(method)) throw new Error('不支持的迁移用户操作');
|
|
13
|
+
const id = path.split('/')[3];
|
|
14
|
+
assertPermission(
|
|
15
|
+
`system:user:${method === 'GET' ? 'list' : method === 'POST' ? 'create' : method === 'DELETE' ? 'delete' : 'update'}`,
|
|
16
|
+
);
|
|
17
|
+
const rows = db.read('users');
|
|
18
|
+
if (method === 'GET') {
|
|
19
|
+
const query = input.query ?? {};
|
|
20
|
+
const filtered = rows.filter((row) => !query.keyword || String(row.username).includes(String(query.keyword)));
|
|
21
|
+
const page = Number(query.page ?? 1);
|
|
22
|
+
const size = Number(query.pageSize ?? 10);
|
|
23
|
+
if (!Number.isSafeInteger(page) || page < 1 || !Number.isSafeInteger(size) || size < 1 || size > 1000)
|
|
24
|
+
throw new Error('分页参数无效');
|
|
25
|
+
return {
|
|
26
|
+
items: filtered.slice((page - 1) * size, page * size).map(({ password: _password, ...row }) => row),
|
|
27
|
+
total: filtered.length,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (id === 'admin') throw new Error('不能修改或删除内置管理员');
|
|
31
|
+
const previous = rows.find((row) => row.id === id);
|
|
32
|
+
if (id && !previous) throw new Error('用户不存在');
|
|
33
|
+
if (method === 'DELETE') {
|
|
34
|
+
db.write(
|
|
35
|
+
'users',
|
|
36
|
+
rows.filter((row) => row.id !== id),
|
|
37
|
+
);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const body = object(input.body);
|
|
41
|
+
const roles = stringArray(body.roles);
|
|
42
|
+
if (
|
|
43
|
+
!body.username ||
|
|
44
|
+
!body.nickname ||
|
|
45
|
+
!roles.length ||
|
|
46
|
+
roles.some((code) => !db.read('roles').some((role) => role.code === code && role.status === 'enabled'))
|
|
47
|
+
)
|
|
48
|
+
throw new Error('用户资料或角色无效');
|
|
49
|
+
if (rows.some((row) => row.id !== id && row.username === body.username)) throw new Error('用户名重复');
|
|
50
|
+
// 只提取允许字段,不能由表单修改密码或注入用户 ID。
|
|
51
|
+
const next = {
|
|
52
|
+
organizationId: '',
|
|
53
|
+
phone: '',
|
|
54
|
+
createdAt: '',
|
|
55
|
+
password: 'lumal123',
|
|
56
|
+
...previous,
|
|
57
|
+
username: body.username,
|
|
58
|
+
nickname: body.nickname,
|
|
59
|
+
status: status(body.status ?? 'enabled'),
|
|
60
|
+
roles,
|
|
61
|
+
id: id ?? crypto.randomUUID(),
|
|
62
|
+
};
|
|
63
|
+
db.write('users', id ? rows.map((row) => (row.id === id ? next : row)) : [...rows, next]);
|
|
64
|
+
const { password: _password, ...result } = next;
|
|
65
|
+
return result;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AppModule } from '../../app/module';
|
|
2
|
+
import { adaptVbenMenus } from '@lumal/vben-compat/v5/router';
|
|
3
|
+
|
|
4
|
+
// Vben authority 是角色;按钮权限继续由应用 PermissionStore 管理。
|
|
5
|
+
export const menus = adaptVbenMenus([
|
|
6
|
+
{
|
|
7
|
+
path: '/migration',
|
|
8
|
+
name: 'VbenMigration',
|
|
9
|
+
meta: { title: 'Vben 迁移示例', icon: 'lumal:code', order: 30 },
|
|
10
|
+
children: [
|
|
11
|
+
{
|
|
12
|
+
path: '/migration/form',
|
|
13
|
+
name: 'VbenForm',
|
|
14
|
+
component: 'migration/form',
|
|
15
|
+
meta: { title: 'Vben 表单迁移', keepAlive: true },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
path: '/migration/users',
|
|
19
|
+
name: 'VbenUsers',
|
|
20
|
+
component: 'migration/users',
|
|
21
|
+
meta: { title: 'Vben 业务迁移', authority: ['admin'], keepAlive: true },
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
]);
|
|
26
|
+
export const views: AppModule['views'] = {
|
|
27
|
+
'migration/form': () => import('./VbenFormView.vue'),
|
|
28
|
+
'migration/users': () => import('./VbenUsersView.vue'),
|
|
29
|
+
};
|
|
30
|
+
// 独立生成迁移示例时仍使用明确的真实操作权限。
|
|
31
|
+
export const permissions: AppModule['permissions'] = [
|
|
32
|
+
{
|
|
33
|
+
id: 'migration-user',
|
|
34
|
+
label: '迁移用户服务',
|
|
35
|
+
children: [
|
|
36
|
+
{ id: 'migration-list', label: '查询用户', permission: 'system:user:list' },
|
|
37
|
+
{ id: 'migration-create', label: '创建用户', permission: 'system:user:create' },
|
|
38
|
+
{ id: 'migration-update', label: '编辑用户', permission: 'system:user:update' },
|
|
39
|
+
{ id: 'migration-delete', label: '删除用户', permission: 'system:user:delete' },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Vue Application</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/src/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createSSRApp } from 'vue';
|
|
3
|
+
import { renderToString } from 'vue/server-renderer';
|
|
4
|
+
import App from '../src/App.vue';
|
|
5
|
+
|
|
6
|
+
describe('应用入口', () => {
|
|
7
|
+
it('可以渲染首个页面', async () => {
|
|
8
|
+
expect(await renderToString(createSSRApp(App))).toMatch(/<main|data-viewport-mode/);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { fileURLToPath, URL } from 'node:url';
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
|
+
import { defineConfig } from 'vite';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [vue()],
|
|
7
|
+
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
|
|
8
|
+
build: { manifest: true },
|
|
9
|
+
});
|