@morningfast/create-ui 0.0.6 → 0.0.7

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/README.md CHANGED
@@ -26,7 +26,7 @@ packages/create-ui/dist/templates/workspace
26
26
  可以在任意希望放置新项目的目录执行:
27
27
 
28
28
  ```sh
29
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js
29
+ pnpm dlx @morningfast/create-ui
30
30
  ```
31
31
 
32
32
  脚手架会依次询问:
@@ -46,43 +46,43 @@ node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js
46
46
  生成默认子应用:
47
47
 
48
48
  ```sh
49
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js my-sub
49
+ pnpm dlx @morningfast/create-ui my-sub
50
50
  ```
51
51
 
52
52
  生成主应用:
53
53
 
54
54
  ```sh
55
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js my-main --template main-app
55
+ pnpm dlx @morningfast/create-ui my-main --template main-app
56
56
  ```
57
57
 
58
58
  生成主应用并移除 demo:
59
59
 
60
60
  ```sh
61
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js my-main --template main-app --no-demo
61
+ pnpm dlx @morningfast/create-ui my-main --template main-app --no-demo
62
62
  ```
63
63
 
64
64
  生成子应用:
65
65
 
66
66
  ```sh
67
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js my-sub --template sub-app
67
+ pnpm dlx @morningfast/create-ui my-sub --template sub-app
68
68
  ```
69
69
 
70
70
  生成业务 monorepo:
71
71
 
72
72
  ```sh
73
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js my-platform --template workspace
73
+ pnpm dlx @morningfast/create-ui my-platform --template workspace
74
74
  ```
75
75
 
76
76
  在已生成项目根目录更新:
77
77
 
78
78
  ```sh
79
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js --update
79
+ pnpm dlx @morningfast/create-ui --update
80
80
  ```
81
81
 
82
82
  也可以在项目外指定 workspace 根目录更新:
83
83
 
84
84
  ```sh
85
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js my-platform --update
85
+ pnpm dlx @morningfast/create-ui my-platform --update
86
86
  ```
87
87
 
88
88
  `--update` 必须在 workspace 根目录执行,或显式传入 workspace 根目录。它会读取根目录 `.morningfast-ui.json`,
@@ -91,19 +91,19 @@ node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js m
91
91
  默认更新整个 monorepo:
92
92
 
93
93
  ```sh
94
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js --update
94
+ pnpm dlx @morningfast/create-ui --update
95
95
  ```
96
96
 
97
97
  只更新主应用:
98
98
 
99
99
  ```sh
100
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js --update --update-target main
100
+ pnpm dlx @morningfast/create-ui --update --update-target main
101
101
  ```
102
102
 
103
103
  只更新所有子应用:
104
104
 
105
105
  ```sh
106
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js --update --update-target sub-apps
106
+ pnpm dlx @morningfast/create-ui --update --update-target sub-apps
107
107
  ```
108
108
 
109
109
  更新只覆盖 `.morningfast-ui.json` 里声明的 `managedRoots`。业务页面、业务接口模块和业务路由默认不覆盖;
@@ -139,7 +139,7 @@ hash 是按文件完整内容计算的,空格、换行和 CRLF/LF 变化都会
139
139
  指定系统初始名:
140
140
 
141
141
  ```sh
142
- node /Users/chenjie/Desktop/code/BFI-frontend/packages/create-ui/dist/index.js my-main --system-name "FMS 管理系统"
142
+ pnpm dlx @morningfast/create-ui my-main --system-name "FMS 管理系统"
143
143
  ```
144
144
 
145
145
  生成完成后进入新项目:
@@ -48,7 +48,7 @@ pnpm format
48
48
  主应用已预留 `qiankun` 微前端入口,默认有一个本地测试子应用配置:
49
49
 
50
50
  ```txt
51
- http://localhost:5174
51
+ http://localhost:8082
52
52
  ```
53
53
 
54
54
  本地联调时分别启动主应用和子应用:
@@ -67,14 +67,14 @@ pnpm --filter __MORNINGFAST_SUB_APP_DIR__ dev
67
67
 
68
68
  - `应用名称`:展示名。
69
69
  - `路由前缀`:qiankun `activeRule`,例如 `/micro/__MORNINGFAST_SUB_APP_DIR__`。
70
- - `入口地址`:qiankun `entry`,例如 `http://localhost:5174`。每个子应用单独维护自己的入口地址。
70
+ - `入口地址`:qiankun `entry`,例如 `http://localhost:8082`。每个子应用单独维护自己的入口地址。
71
71
  - `应用说明`:仅用于配置页展示。
72
72
 
73
73
  应用配置当前先存在浏览器 `localStorage`,key 是 `system:apps`。保存后刷新主应用,qiankun 会重新读取本地配置并注册子应用。
74
74
 
75
75
  ## 配置一个子应用
76
76
 
77
- 1. 启动子应用,确认能直接打开它的本地地址,例如 `http://localhost:5174`。
77
+ 1. 启动子应用,确认能直接打开它的本地地址,例如 `http://localhost:8082`。
78
78
  2. 打开主应用“系统 / 应用配置”。
79
79
  3. 点击新增应用,填写应用名称、路由前缀、入口地址和应用说明。
80
80
  4. 保存后刷新主应用。
@@ -97,7 +97,6 @@ pnpm --filter __MORNINGFAST_SUB_APP_DIR__ dev
97
97
  {
98
98
  basePath,
99
99
  app,
100
- auth,
101
100
  runtime,
102
101
  theme,
103
102
  }
@@ -107,18 +106,17 @@ pnpm --filter __MORNINGFAST_SUB_APP_DIR__ dev
107
106
 
108
107
  - `basePath`:子应用路由基座,来自子应用配置的路由前缀。
109
108
  - `app`:当前子应用信息,包含 `id`、`name`、`title`、`entry`、`activeRule`。
110
- - `auth`:主应用登录上下文,包含 `token`、`user`、`roles`、`permissions`。
111
109
  - `runtime`:运行时配置,当前包含 `env` 和 `apiBaseUrl`。
112
110
  - `theme`:主应用当前 Element Plus 主题变量和明暗模式。
113
111
 
114
112
  子应用业务页面不直接读主应用 store,也不自己重新维护一套登录态。主应用只负责把必要上下文传进去,子应用通过自己的
115
- `useSubAppContext()` 读取。
113
+ `useSubAppContext()` 读取。登录 token、用户和权限通过 `@morningfast/platform/auth` 共享包读取。
116
114
 
117
115
  后续接菜单、权限时,继续沿用这个边界:
118
116
 
119
117
  - 菜单树属于某个应用,先在应用配置中选应用,再维护该应用菜单。
120
118
  - 权限点属于某个应用,接口按应用维度返回。
121
- - 主应用负责下发当前登录用户的权限集合,子应用负责按自己的菜单和权限点渲染页面。
119
+ - 主应用负责维护当前登录用户的权限集合,子应用通过共享认证包读取权限后按自己的菜单和权限点渲染页面。
122
120
 
123
121
  子应用通过 `morningfast-plus/components` 使用 `MpSearchForm`、`MpTable` 等公共组件。
124
122
 
@@ -152,12 +150,14 @@ const apiBaseUrl = runtime.apiBaseUrl;
152
150
 
153
151
  ### 子应用怎么取用户信息?
154
152
 
155
- 主应用会在 `auth` 里传登录上下文:
153
+ 主应用登录后会把 token 持久化到 `localStorage`,并把用户、角色和权限写入共享认证包的内存缓存。子应用从共享认证包读取:
156
154
 
157
155
  ```ts
158
- const { auth } = useSubAppContext();
159
- const token = auth?.token;
160
- const permissions = auth?.permissions ?? [];
156
+ import { getAccessToken, getAuthProfile } from '@morningfast/platform/auth';
157
+
158
+ const token = getAccessToken();
159
+ const profile = getAuthProfile();
160
+ const permissions = profile?.permissions ?? [];
161
161
  ```
162
162
 
163
163
  ### 子应用之间怎么通信?
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@element-plus/icons-vue": "^2.3.2",
21
- "@morningfast/platform": "^0.0.6",
21
+ "@morningfast/platform": "^0.0.7",
22
22
  "axios": "^1.16.0",
23
23
  "element-plus": "^2.14.0",
24
24
  "localforage": "^1.10.0",
@@ -34,48 +34,8 @@ export const mockRouteItems: MockRouteItem[] = [
34
34
  name: 'demo',
35
35
  title: '示例模块',
36
36
  icon: 'Setting',
37
- redirect: '/demo/menu/one',
37
+ redirect: '/demo/user-management',
38
38
  children: [
39
- {
40
- path: 'menu',
41
- name: 'demo-menu',
42
- title: '示例分组一',
43
- redirect: '/demo/menu/one',
44
- children: [
45
- {
46
- path: 'one',
47
- name: 'demo-menu-one',
48
- title: '菜单示例一',
49
- componentKey: 'demo-menu-one',
50
- },
51
- {
52
- path: 'two',
53
- name: 'demo-menu-two',
54
- title: '菜单示例二',
55
- componentKey: 'demo-menu-two',
56
- },
57
- ],
58
- },
59
- {
60
- path: 'another',
61
- name: 'demo-another',
62
- title: '示例分组二',
63
- redirect: '/demo/another/leaf',
64
- children: [
65
- {
66
- path: 'leaf',
67
- name: 'demo-another-leaf',
68
- title: '菜单示例三',
69
- componentKey: 'demo-another-leaf',
70
- },
71
- ],
72
- },
73
- {
74
- path: 'standalone',
75
- name: 'demo-standalone',
76
- title: '独立菜单示例',
77
- componentKey: 'demo-standalone',
78
- },
79
39
  {
80
40
  path: 'user-management',
81
41
  name: 'demo-user-management',
@@ -107,10 +67,6 @@ export const mockRouteItems: MockRouteItem[] = [
107
67
 
108
68
  const componentMap: Record<string, RouteRecordRaw['component']> = {
109
69
  dashboard: () => import('@/pages/dashboard/Workplace.vue'),
110
- 'demo-menu-one': () => import('@/pages/demo/MenuLevelOne.vue'),
111
- 'demo-menu-two': () => import('@/pages/demo/MenuLevelTwo.vue'),
112
- 'demo-another-leaf': () => import('@/pages/demo/MenuLeaf.vue'),
113
- 'demo-standalone': () => import('@/pages/demo/StandaloneMenu.vue'),
114
70
  'demo-user-management': () => import('@/pages/demo/user-management/index.vue'),
115
71
  'demo-mapping-config': () => import('@/pages/demo/mapping-config/index.vue'),
116
72
  'demo-table-page': () => import('@/pages/demo/table-page-demo/index.vue'),
@@ -38,10 +38,9 @@ export default defineConfig((configEnv) => {
38
38
  },
39
39
  ],
40
40
  },
41
- server: Object.keys(proxy).length
42
- ? {
43
- proxy,
44
- }
45
- : undefined,
41
+ server: {
42
+ port: Number(env.VITE_MAIN_APP_PORT || 8081),
43
+ ...(Object.keys(proxy).length ? { proxy } : {}),
44
+ },
46
45
  }, defineBusinessViteConfig(configEnv))
47
46
  })
@@ -12,7 +12,7 @@ Morningfast UI 微前端子应用模板。
12
12
  pnpm dev
13
13
  ```
14
14
 
15
- 作为主应用子应用联调时,默认端口是 `5174`,主应用默认入口也是 `http://localhost:5174`。
15
+ 作为主应用子应用联调时,默认端口是 `8082`,主应用默认入口也是 `http://localhost:8082`。
16
16
 
17
17
  如果需要开启 `vite-plugin-qiankun` 的 dev 子应用调试模式:
18
18
 
@@ -37,7 +37,7 @@ VITE_QIANKUN_DEV_MODE=true pnpm dev
37
37
 
38
38
  - 子应用名:`morningfast-__MORNINGFAST_SUB_APP_DIR__`。
39
39
  - 主应用默认挂载路径:`/micro/__MORNINGFAST_SUB_APP_DIR__`。
40
- - 主应用应用配置里的 `入口地址` 要指向子应用访问地址,例如 `http://localhost:5174`。
40
+ - 主应用应用配置里的 `入口地址` 要指向子应用访问地址,例如 `http://localhost:8082`。
41
41
  - 主应用应用配置里的 `路由前缀` 要和子应用挂载路径一致,例如 `/micro/__MORNINGFAST_SUB_APP_DIR__`。
42
42
  - 子应用默认保留一个基础 `home` 页面,业务示例放在 `src/pages/demo/orders`,对应路由是 `/demo/orders`。
43
43
  - 子应用独立运行时,`html`、`body`、`#sub-app` 必须形成 `height: 100%; min-height: 0;` 的闭合高度链,否则
@@ -66,7 +66,6 @@ import { MpSearchForm, MpTable } from 'morningfast-plus/components';
66
66
  {
67
67
  basePath,
68
68
  app,
69
- auth,
70
69
  runtime,
71
70
  theme,
72
71
  }
@@ -81,14 +80,12 @@ import { useSubAppContext } from '@/composables/useSubAppContext';
81
80
 
82
81
  const subAppContext = useSubAppContext();
83
82
  const apiBaseUrl = subAppContext.runtime.apiBaseUrl;
84
- const token = subAppContext.auth?.token;
85
83
  ```
86
84
 
87
85
  常用字段:
88
86
 
89
87
  - `basePath`:子应用路由基座,独立运行时默认 `/`,被主应用挂载时例如 `/micro/sub-app/`。
90
88
  - `app`:当前子应用配置,包含应用 id、名称、入口地址和激活路由前缀。
91
- - `auth`:主应用登录态,包含 token、用户、角色和权限。
92
89
  - `runtime`:运行时配置,当前包含 `env` 和 `apiBaseUrl`。请求封装应优先从这里拿接口前缀。
93
90
  - `theme`:当前主题快照。
94
91
 
@@ -103,9 +100,9 @@ runtime: {
103
100
 
104
101
  后续真实接菜单和权限时,建议保持边界:
105
102
 
106
- - 主应用只传当前应用运行时上下文,不通过 qiankun props 传 token 或权限快照。
103
+ - 主应用只通过 qiankun props 传当前应用运行时上下文,不通过 props 传 token 或权限快照。
107
104
  - 子应用维护自己的路由、菜单和权限点定义。
108
- - 子应用通过 profile 接口获取权限集合,并根据自身菜单配置决定展示内容。
105
+ - 子应用通过 `@morningfast/platform/auth` 共享认证包读取 token、用户和权限,并根据自身菜单配置决定展示内容。
109
106
 
110
107
  ## 子应用接收主应用消息
111
108
 
@@ -172,13 +169,15 @@ fetch(`${runtime.apiBaseUrl}/orders`, {
172
169
  ### 子应用怎么取当前用户和权限?
173
170
 
174
171
  ```ts
175
- const { auth } = useSubAppContext();
172
+ import { getAccessToken, getAuthProfile } from '@morningfast/platform/auth';
176
173
 
177
- const user = auth?.user;
178
- const permissions = auth?.permissions ?? [];
174
+ const token = getAccessToken();
175
+ const profile = getAuthProfile();
176
+ const user = profile?.user;
177
+ const permissions = profile?.permissions ?? [];
179
178
  ```
180
179
 
181
- 业务页面用 `permissions` 控制按钮和功能入口。不要在子应用里重新维护一套登录态。
180
+ 业务页面用 `permissions` 控制按钮和功能入口。token 保存在 `localStorage`,刷新后仍可读取;用户和权限在共享包内存中,主应用刷新初始化后会重新写入。
182
181
 
183
182
  ### 子应用怎么知道自己挂在哪个路径?
184
183
 
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@element-plus/icons-vue": "^2.3.2",
17
- "@morningfast/platform": "^0.0.6",
17
+ "@morningfast/platform": "^0.0.7",
18
18
  "@types/sortablejs": "^1.15.9",
19
19
  "@vitejs/plugin-vue": "^6.0.6",
20
20
  "element-plus": "^2.14.0",
@@ -27,7 +27,7 @@ export default defineConfig((configEnv) => {
27
27
  ],
28
28
  },
29
29
  server: {
30
- port: Number(env.VITE_SUB_APP_PORT || 5174),
30
+ port: Number(env.VITE_SUB_APP_PORT || 8082),
31
31
  cors: true,
32
32
  headers: {
33
33
  'Access-Control-Allow-Origin': '*',
@@ -14,16 +14,70 @@ packages/
14
14
  micro-contract/
15
15
  ```
16
16
 
17
- ## 命令
17
+ ## 快速启动
18
+
19
+ 进入生成后的项目根目录,先安装依赖:
18
20
 
19
21
  ```sh
20
22
  pnpm install
23
+ ```
24
+
25
+ 只运行主应用:
26
+
27
+ ```sh
21
28
  pnpm dev:main
29
+ ```
30
+
31
+ 只运行子应用:
32
+
33
+ ```sh
22
34
  pnpm dev:sub
35
+ ```
36
+
37
+ 主子应用本地联调时,需要开两个终端同时运行:
38
+
39
+ ```sh
40
+ pnpm dev:main
41
+ ```
42
+
43
+ ```sh
44
+ pnpm dev:sub
45
+ ```
46
+
47
+ 默认主应用使用 Vite 默认端口,通常是 `http://localhost:8081`。
48
+ 默认子应用端口是 `http://localhost:8082`,主应用内置的子应用入口也指向这个地址。
49
+
50
+ 启动后先访问主应用地址,再从主应用菜单进入“微前端 / 子应用示例”。如果子应用端口或部署地址不同,在主应用“系统 / 应用配置”里维护子应用入口地址。
51
+
52
+ ## 检查和构建
53
+
54
+ 检查主应用:
55
+
56
+ ```sh
23
57
  pnpm check:main
58
+ ```
59
+
60
+ 检查子应用:
61
+
62
+ ```sh
24
63
  pnpm check:sub
64
+ ```
65
+
66
+ 构建主应用:
67
+
68
+ ```sh
25
69
  pnpm build:main
70
+ ```
71
+
72
+ 构建子应用:
73
+
74
+ ```sh
26
75
  pnpm build:sub
76
+ ```
77
+
78
+ 构建全部应用:
79
+
80
+ ```sh
27
81
  pnpm build:all
28
82
  ```
29
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morningfast/create-ui",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Morningfast UI internal system scaffold CLI.",
5
5
  "bin": {
6
6
  "create-morningfast-ui": "dist/index.js"
@@ -1,12 +0,0 @@
1
- <template>
2
- <div class="page">
3
- <div class="page__header">
4
- <div>
5
- <h2 class="page__title">菜单示例三</h2>
6
- <p class="page__subtitle">用于演示另一条三级菜单链路。</p>
7
- </div>
8
- </div>
9
-
10
- <el-card shadow="never">示例分组二 / 菜单示例三</el-card>
11
- </div>
12
- </template>
@@ -1,12 +0,0 @@
1
- <template>
2
- <div class="page">
3
- <div class="page__header">
4
- <div>
5
- <h2 class="page__title">菜单示例一</h2>
6
- <p class="page__subtitle">用于演示二三级菜单、面包屑和页签联动效果。</p>
7
- </div>
8
- </div>
9
-
10
- <el-card shadow="never">示例分组一 / 菜单示例一</el-card>
11
- </div>
12
- </template>
@@ -1,12 +0,0 @@
1
- <template>
2
- <div class="page">
3
- <div class="page__header">
4
- <div>
5
- <h2 class="page__title">菜单示例二</h2>
6
- <p class="page__subtitle">用于演示同级菜单切换和面包屑展示。</p>
7
- </div>
8
- </div>
9
-
10
- <el-card shadow="never">示例分组一 / 菜单示例二</el-card>
11
- </div>
12
- </template>
@@ -1,12 +0,0 @@
1
- <template>
2
- <div class="page">
3
- <div class="page__header">
4
- <div>
5
- <h2 class="page__title">独立菜单示例</h2>
6
- <p class="page__subtitle">这是一个直接挂在示例模块下的叶子菜单页面。</p>
7
- </div>
8
- </div>
9
-
10
- <el-card shadow="never">示例模块 / 独立菜单示例</el-card>
11
- </div>
12
- </template>