generator-mico-cli 0.2.1 → 0.2.2-8.beta.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 (159) hide show
  1. package/README.md +199 -15
  2. package/bin/mico.js +232 -27
  3. package/generators/micro-react/index.js +200 -18
  4. package/generators/micro-react/meta.json +13 -0
  5. package/generators/micro-react/templates/.commitlintrc.js +1 -0
  6. package/generators/micro-react/templates/.cursor/rules/always-read-docs.mdc +14 -4
  7. package/generators/micro-react/templates/.cursor/rules/cicd-deploy.mdc +10 -8
  8. package/generators/micro-react/templates/.cursor/rules/coding-conventions.mdc +1 -1
  9. package/generators/micro-react/templates/.cursor/rules/development-guide.mdc +3 -4
  10. package/generators/micro-react/templates/.cursor/rules/layout-app.mdc +38 -31
  11. package/generators/micro-react/templates/.cursor/rules/project-overview.mdc +7 -4
  12. package/generators/micro-react/templates/.cursor/rules/theme-system.mdc +10 -12
  13. package/generators/micro-react/templates/.eslintrc.js +25 -1
  14. package/generators/micro-react/templates/AGENTS.md +5 -2
  15. package/generators/micro-react/templates/CICD/before_build.sh +76 -0
  16. package/generators/micro-react/templates/CICD/start_dev.sh +27 -3
  17. package/generators/micro-react/templates/CICD/start_prod.sh +26 -3
  18. package/generators/micro-react/templates/CICD/start_test.sh +28 -3
  19. package/generators/micro-react/templates/CICD/wangsu_fresh_dev.sh +4 -4
  20. package/generators/micro-react/templates/CICD/wangsu_fresh_prod.sh +4 -4
  21. package/generators/micro-react/templates/CICD/wangsu_fresh_test.sh +4 -4
  22. package/generators/micro-react/templates/CLAUDE.md +16 -9
  23. package/generators/micro-react/templates/README.md +42 -4
  24. package/generators/micro-react/templates/_gitignore +4 -0
  25. package/generators/micro-react/templates/_npmrc +4 -0
  26. package/generators/micro-react/templates/apps/layout/config/config.dev.ts +32 -16
  27. package/generators/micro-react/templates/apps/layout/config/config.prod.development.ts +24 -29
  28. package/generators/micro-react/templates/apps/layout/config/config.prod.testing.ts +25 -6
  29. package/generators/micro-react/templates/apps/layout/config/config.prod.ts +16 -7
  30. package/generators/micro-react/templates/apps/layout/config/config.ts +27 -4
  31. package/generators/micro-react/templates/apps/layout/config/routes.ts +5 -5
  32. package/generators/micro-react/templates/apps/layout/docs/arch-/346/227/245/345/277/227/344/270/216/345/270/270/351/207/217.md +2 -2
  33. package/generators/micro-react/templates/apps/layout/docs/common-intl.md +372 -0
  34. package/generators/micro-react/templates/apps/layout/docs/feat-/346/236/204/345/273/272define/344/270/216/345/205/215/350/256/244/350/257/201/345/210/235/345/247/213/346/200/201.md +44 -0
  35. package/generators/micro-react/templates/apps/layout/docs/feature-404/351/241/265/351/235/242.md +103 -0
  36. package/generators/micro-react/templates/apps/layout/docs/feature-/344/270/273/351/242/230/350/211/262/345/210/207/346/215/242.md +22 -26
  37. package/generators/micro-react/templates/apps/layout/docs/feature-/345/276/256/345/211/215/347/253/257/346/250/241/345/274/217.md +185 -28
  38. package/generators/micro-react/templates/apps/layout/docs/feature-/350/217/234/345/215/225/346/235/203/351/231/220/346/216/247/345/210/266.md +308 -63
  39. package/generators/micro-react/templates/apps/layout/docs/feature-/350/267/257/347/224/261/344/270/216/350/217/234/345/215/225/350/247/243/350/200/246.md +179 -0
  40. package/generators/micro-react/templates/apps/layout/docs/fix-SSO/346/227/240/351/231/220/351/207/215/345/256/232/345/220/221.md +88 -0
  41. package/generators/micro-react/templates/apps/layout/docs/utils-timezone.md +324 -0
  42. package/generators/micro-react/templates/apps/layout/mock/api.mock.ts +81 -61
  43. package/generators/micro-react/templates/apps/layout/mock/menus.ts +114 -4
  44. package/generators/micro-react/templates/apps/layout/mock/pages.ts +86 -0
  45. package/generators/micro-react/templates/apps/layout/package.json +7 -4
  46. package/generators/micro-react/templates/apps/layout/src/app.tsx +111 -76
  47. package/generators/micro-react/templates/apps/layout/src/common/auth/index.ts +3 -0
  48. package/generators/micro-react/templates/apps/layout/src/common/helpers.ts +177 -0
  49. package/generators/micro-react/templates/apps/layout/src/common/locale.ts +22 -17
  50. package/generators/micro-react/templates/apps/layout/src/common/menu/parser.ts +192 -42
  51. package/generators/micro-react/templates/apps/layout/src/common/menu/types.ts +69 -5
  52. package/generators/micro-react/templates/apps/layout/src/common/micro/index.ts +34 -0
  53. package/generators/micro-react/templates/apps/layout/src/common/micro-prefetch.ts +109 -0
  54. package/generators/micro-react/templates/apps/layout/src/common/portal-data.ts +45 -0
  55. package/generators/micro-react/templates/apps/layout/src/common/request/config.ts +72 -10
  56. package/generators/micro-react/templates/apps/layout/src/common/request/index.ts +2 -2
  57. package/generators/micro-react/templates/apps/layout/src/common/request/interceptors.ts +31 -3
  58. package/generators/micro-react/templates/apps/layout/src/common/request/sso.ts +29 -11
  59. package/generators/micro-react/templates/apps/layout/src/common/request/url-resolver.ts +1 -1
  60. package/generators/micro-react/templates/apps/layout/src/common/route-guard.ts +345 -0
  61. package/generators/micro-react/templates/apps/layout/src/common/theme.ts +2 -4
  62. package/generators/micro-react/templates/apps/layout/src/common/upload/oss.ts +3 -4
  63. package/generators/micro-react/templates/apps/layout/src/common/upload/types.ts +1 -1
  64. package/generators/micro-react/templates/apps/layout/src/common/uploadFiles.ts +1 -1
  65. package/generators/micro-react/templates/apps/layout/src/components/AppTabs/index.less +8 -3
  66. package/generators/micro-react/templates/apps/layout/src/components/AppTabs/index.tsx +25 -8
  67. package/generators/micro-react/templates/apps/layout/src/components/HeaderDropdown/index.tsx +20 -0
  68. package/generators/micro-react/templates/apps/layout/src/components/IconFont/index.tsx +5 -6
  69. package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/index.less +21 -6
  70. package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/index.tsx +83 -149
  71. package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/micro-app-manager.ts +569 -0
  72. package/generators/micro-react/templates/apps/layout/src/components/RightContent/AvatarDropdown.tsx +383 -0
  73. package/generators/micro-react/templates/apps/layout/src/components/RightContent/avatar-dropdown.less +35 -0
  74. package/generators/micro-react/templates/apps/layout/src/components/RightContent/index.ts +2 -0
  75. package/generators/micro-react/templates/apps/layout/src/constants/index.ts +170 -6
  76. package/generators/micro-react/templates/apps/layout/src/global.less +18 -9
  77. package/generators/micro-react/templates/apps/layout/src/hooks/useMenu.ts +3 -2
  78. package/generators/micro-react/templates/apps/layout/src/hooks/useRoutePermissionRefresh.ts +72 -0
  79. package/generators/micro-react/templates/apps/layout/src/layouts/components/header/index.less +3 -1
  80. package/generators/micro-react/templates/apps/layout/src/layouts/components/header/index.tsx +10 -55
  81. package/generators/micro-react/templates/apps/layout/src/layouts/components/menu/index.less +34 -4
  82. package/generators/micro-react/templates/apps/layout/src/layouts/components/menu/index.tsx +24 -8
  83. package/generators/micro-react/templates/apps/layout/src/layouts/index.less +84 -13
  84. package/generators/micro-react/templates/apps/layout/src/layouts/index.tsx +156 -69
  85. package/generators/micro-react/templates/apps/layout/src/locales/en-US.ts +12 -0
  86. package/generators/micro-react/templates/apps/layout/src/locales/zh-CN.ts +12 -0
  87. package/generators/micro-react/templates/apps/layout/src/pages/403/index.tsx +8 -2
  88. package/generators/micro-react/templates/apps/layout/src/pages/404/index.tsx +78 -0
  89. package/generators/micro-react/templates/apps/layout/src/pages/Home/index.less +3 -0
  90. package/generators/micro-react/templates/apps/layout/src/pages/Home/index.tsx +7 -1
  91. package/generators/micro-react/templates/apps/layout/src/pages/User/Login/index.less +1 -1
  92. package/generators/micro-react/templates/apps/layout/src/pages/User/Login/index.tsx +3 -3
  93. package/generators/micro-react/templates/apps/layout/src/requestErrorConfig.ts +1 -1
  94. package/generators/micro-react/templates/apps/layout/src/services/config/index.ts +63 -0
  95. package/generators/micro-react/templates/apps/layout/src/services/config/type.ts +30 -0
  96. package/generators/micro-react/templates/apps/layout/src/services/user.ts +29 -2
  97. package/generators/micro-react/templates/apps/layout/tailwind.config.js +3 -0
  98. package/generators/micro-react/templates/deployDesc.md +3 -3
  99. package/generators/micro-react/templates/dev.preset.json +14 -0
  100. package/generators/micro-react/templates/docs/dev-preset.md +130 -0
  101. package/generators/micro-react/templates/package.json +21 -6
  102. package/generators/micro-react/templates/packages/common-intl/README.md +427 -0
  103. package/generators/micro-react/templates/packages/common-intl/package.json +34 -0
  104. package/generators/micro-react/templates/packages/common-intl/src/index.ts +7 -0
  105. package/generators/micro-react/templates/packages/common-intl/src/indexedDBUtils.ts +51 -0
  106. package/generators/micro-react/templates/packages/common-intl/src/intl.ts +50 -0
  107. package/generators/micro-react/templates/packages/common-intl/src/utils.ts +482 -0
  108. package/generators/micro-react/templates/packages/common-intl/tsconfig.json +22 -0
  109. package/generators/micro-react/templates/packages/common-intl/vite.config.ts +25 -0
  110. package/generators/micro-react/templates/scripts/apply-sentry-plugin.ts +45 -0
  111. package/generators/micro-react/templates/scripts/collect-dist.js +10 -0
  112. package/generators/micro-react/templates/scripts/dev-preset.js +265 -0
  113. package/generators/micro-react/templates/scripts/dev-preset.schema.json +39 -0
  114. package/generators/micro-react/templates/turbo.json +4 -1
  115. package/generators/subapp-react/index.js +326 -40
  116. package/generators/subapp-react/meta.json +10 -0
  117. package/generators/subapp-react/templates/homepage/.env +2 -1
  118. package/generators/subapp-react/templates/homepage/README.md +3 -3
  119. package/generators/subapp-react/templates/homepage/config/config.dev.ts +14 -7
  120. package/generators/subapp-react/templates/homepage/config/config.prod.development.ts +16 -5
  121. package/generators/subapp-react/templates/homepage/config/config.prod.testing.ts +16 -5
  122. package/generators/subapp-react/templates/homepage/config/config.prod.ts +14 -5
  123. package/generators/subapp-react/templates/homepage/config/config.ts +21 -0
  124. package/generators/subapp-react/templates/homepage/config/routes.ts +2 -2
  125. package/generators/subapp-react/templates/homepage/mock/api.mock.ts +2 -2
  126. package/generators/subapp-react/templates/homepage/package.json +7 -4
  127. package/generators/subapp-react/templates/homepage/src/app.tsx +18 -27
  128. package/generators/subapp-react/templates/homepage/src/common/request.ts +29 -2
  129. package/generators/subapp-react/templates/homepage/src/global.less +6 -5
  130. package/generators/subapp-react/templates/homepage/src/pages/index.less +3 -3
  131. package/generators/subapp-react/templates/homepage/src/pages/index.tsx +99 -60
  132. package/generators/subapp-react/templates/homepage/src/styles/theme.less +1 -1
  133. package/generators/subapp-umd/ignore-list.json +5 -0
  134. package/generators/subapp-umd/index.js +309 -0
  135. package/generators/subapp-umd/meta.json +11 -0
  136. package/generators/subapp-umd/templates/README.md +94 -0
  137. package/generators/subapp-umd/templates/package.json +35 -0
  138. package/generators/subapp-umd/templates/public/index.html +34 -0
  139. package/generators/subapp-umd/templates/src/App.less +15 -0
  140. package/generators/subapp-umd/templates/src/App.tsx +13 -0
  141. package/generators/subapp-umd/templates/src/index.ts +2 -0
  142. package/generators/subapp-umd/templates/tsconfig.json +27 -0
  143. package/generators/subapp-umd/templates/webpack.config.js +70 -0
  144. package/lib/utils.js +332 -2
  145. package/package.json +15 -2
  146. package/generators/micro-react/templates/apps/layout/mock/menus.json +0 -100
  147. package/generators/micro-react/templates/apps/layout/src/common/constants.ts +0 -38
  148. package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/container-manager.ts +0 -202
  149. package/generators/micro-react/templates/packages/shared-styles/README.md +0 -124
  150. package/generators/micro-react/templates/packages/shared-styles/arco-design-mobile-override.less +0 -91
  151. package/generators/micro-react/templates/packages/shared-styles/arco-override.less +0 -119
  152. package/generators/micro-react/templates/packages/shared-styles/index.d.ts +0 -44
  153. package/generators/micro-react/templates/packages/shared-styles/index.less +0 -13
  154. package/generators/micro-react/templates/packages/shared-styles/package.json +0 -30
  155. package/generators/micro-react/templates/packages/shared-styles/theme-inject.less +0 -10
  156. package/generators/micro-react/templates/packages/shared-styles/themes/dark/custom-var.less +0 -290
  157. package/generators/micro-react/templates/packages/shared-styles/themes/normal/custom-var.less +0 -269
  158. package/generators/micro-react/templates/packages/shared-styles/variables-only.less +0 -433
  159. package/generators/micro-react/templates/packages/shared-styles/variables.less +0 -452
@@ -1,43 +1,38 @@
1
1
  // https://umijs.org/config/
2
2
 
3
3
  import { defineConfig } from '@umijs/max';
4
- import fs from 'fs';
5
- import path from 'path';
4
+ // 开发环境,不上传 sourcemap。调试时如有需要再解开
5
+ // import { applySentryPlugin } from "../../../scripts/apply-sentry-plugin";
6
+ const { CDN_PUBLIC_PATH } = process.env;
6
7
 
7
- // 使用 fs 读取 JSON 避免成为配置依赖,修改 menus.json 不会触发服务器重启
8
- const mockMenus = JSON.parse(
9
- fs.readFileSync(path.join(__dirname, '../mock/menus.json'), 'utf-8'),
10
- );
8
+ const PUBLIC_PATH: string = CDN_PUBLIC_PATH
9
+ ? `${CDN_PUBLIC_PATH.replace(/\/?$/, '/')}layout/`
10
+ : '/layout/';
11
11
 
12
12
  const config: ReturnType<typeof defineConfig> = {
13
- publicPath: '/',
14
- /**
15
- * @name 注入到 HTML head 的脚本
16
- * @description 开发环境注入 mock 菜单数据
17
- * @doc https://umijs.org/docs/api/config#headscripts
18
- */
19
- headScripts: [
20
- {
21
- content: `
22
- window.__MICO_MENUS__ = ${JSON.stringify(mockMenus)};
23
- window.__MICO_CONFIG__ = {
24
- appName: 'Mico Center',
25
- apiBaseUrl: '',
26
- };
27
- `,
28
- },
29
- ],
13
+ // 开发环境,不上传 sourcemap。调试时如有需要再解开
14
+ // devtool: 'hidden-source-map',
15
+
16
+ // chainWebpack(memo) {
17
+ // // 开发环境,不上传 sourcemap。调试时如有需要再解开
18
+ // applySentryPlugin({ memo, appName: 'layout' });
19
+ // return memo;
20
+ // },
21
+
22
+ externals: {
23
+ react: 'React',
24
+ 'react-dom': 'ReactDOM',
25
+ '@common-web/sentry': 'CommonWebSentry',
26
+ },
27
+ publicPath: PUBLIC_PATH,
28
+ cssPublicPath: PUBLIC_PATH,
30
29
  define: {
31
30
  'process.env.NODE_ENV': 'development',
32
- 'process.env.APP_ID': 'mibot_dev',
33
31
  'process.env.API_BASE_URL': 'https://dashboard-api-test.micoplatform.com',
34
- 'process.env.PROXY_SUFFIX': '/',
35
32
  'process.env.LOGIN_ENDPOINT':
36
- '',
33
+ 'https://dashboard-api-test.micoplatform.com/api/yufu_login/',
37
34
  'process.env.REFRESH_ENDPOINT':
38
- '',
39
- 'process.env.EXTERNAL_LOGIN_PATH':
40
- '',
35
+ 'https://dashboard-api-test.micoplatform.com/api/yufu_login/refresh/',
41
36
  },
42
37
  };
43
38
 
@@ -1,19 +1,38 @@
1
1
  // https://umijs.org/config/
2
2
 
3
3
  import { defineConfig } from '@umijs/max';
4
+ // 测试环境,不上传 sourcemap。调试时如有需要再解开
5
+ // import { applySentryPlugin } from "../../../scripts/apply-sentry-plugin";
6
+ const { CDN_PUBLIC_PATH } = process.env;
7
+
8
+ const PUBLIC_PATH: string = CDN_PUBLIC_PATH
9
+ ? `${CDN_PUBLIC_PATH.replace(/\/?$/, '/')}layout/`
10
+ : '/layout/';
4
11
 
5
12
  const config: ReturnType<typeof defineConfig> = {
13
+ // 测试环境,不上传 sourcemap。调试时如有需要再解开
14
+ // devtool: 'hidden-source-map',
15
+
16
+ // chainWebpack(memo) {
17
+ // // 测试环境,不上传 sourcemap。调试时如有需要再解开
18
+ // applySentryPlugin({ memo, appName: 'layout' });
19
+ // return memo;
20
+ // },
21
+
22
+ externals: {
23
+ react: 'React',
24
+ 'react-dom': 'ReactDOM',
25
+ '@common-web/sentry': 'CommonWebSentry',
26
+ },
27
+ publicPath: PUBLIC_PATH,
28
+ cssPublicPath: PUBLIC_PATH,
6
29
  define: {
7
30
  'process.env.NODE_ENV': 'testing',
8
- 'process.env.APP_ID': 'mibot',
9
31
  'process.env.API_BASE_URL': 'https://dashboard-api-test.micoplatform.com',
10
- 'process.env.PROXY_SUFFIX': '/',
11
32
  'process.env.LOGIN_ENDPOINT':
12
- '',
33
+ 'https://dashboard-api-test.micoplatform.com/api/yufu_login/',
13
34
  'process.env.REFRESH_ENDPOINT':
14
- '',
15
- 'process.env.EXTERNAL_LOGIN_PATH':
16
- '',
35
+ 'https://dashboard-api-test.micoplatform.com/api/yufu_login/refresh/',
17
36
  },
18
37
  };
19
38
 
@@ -1,6 +1,7 @@
1
1
  // https://umijs.org/config/
2
2
 
3
3
  import { defineConfig } from '@umijs/max';
4
+ import { applySentryPlugin } from '../../../scripts/apply-sentry-plugin';
4
5
  const { CDN_PUBLIC_PATH } = process.env;
5
6
 
6
7
  const PUBLIC_PATH: string = CDN_PUBLIC_PATH
@@ -8,30 +9,38 @@ const PUBLIC_PATH: string = CDN_PUBLIC_PATH
8
9
  : '/layout/';
9
10
 
10
11
  const config: ReturnType<typeof defineConfig> = {
12
+ /**
13
+ * 启用 Source Map(用于 Sentry 错误追踪)
14
+ * hidden-source-map 会生成 .map 文件但不在 JS 中添加 sourcemap 注释
15
+ */
16
+ devtool: 'hidden-source-map',
11
17
  define: {
12
18
  'process.env.NODE_ENV': 'production',
13
- 'process.env.APP_ID': 'mibot',
14
19
  'process.env.API_BASE_URL': 'https://dashboard-api.micoplatform.com',
15
- 'process.env.PROXY_SUFFIX': '/',
16
20
  'process.env.LOGIN_ENDPOINT':
17
- '',
21
+ 'https://dashboard-api.micoplatform.com/api/yufu_login/',
18
22
  'process.env.REFRESH_ENDPOINT':
19
- '',
20
- 'process.env.EXTERNAL_LOGIN_PATH':
21
- '',
23
+ 'https://dashboard-api.micoplatform.com/api/yufu_login/refresh/',
24
+ },
25
+ externals: {
26
+ react: 'React',
27
+ 'react-dom': 'ReactDOM',
28
+ '@common-web/sentry': 'CommonWebSentry',
22
29
  },
23
30
  // 生产环境:将所有代码打包到一个文件
24
31
  extraBabelPlugins: ['babel-plugin-dynamic-import-node'],
25
32
 
26
33
  // 禁用代码分割,只输出一个 JS 和一个 CSS
27
- chainWebpack(memo) {
34
+ chainWebpack(memo: any) {
28
35
  // 禁用 splitChunks
29
36
  memo.optimization.splitChunks(false);
30
37
  // 禁用 runtimeChunk
31
38
  memo.optimization.runtimeChunk(false);
39
+ applySentryPlugin({ memo, appName: 'layout' });
32
40
  return memo;
33
41
  },
34
42
  publicPath: PUBLIC_PATH,
43
+ cssPublicPath: PUBLIC_PATH,
35
44
  };
36
45
 
37
46
  export default defineConfig(config);
@@ -16,7 +16,7 @@ const config: ReturnType<typeof defineConfig> = {
16
16
  * @description React 应用挂载的 DOM 元素 id
17
17
  * @doc https://umijs.org/docs/api/config#mountelementid
18
18
  */
19
- mountElementId: '<%= projectName %>',
19
+ mountElementId: 'root',
20
20
 
21
21
  /**
22
22
  * @name 开启 hash 模式
@@ -36,7 +36,7 @@ const config: ReturnType<typeof defineConfig> = {
36
36
 
37
37
  /**
38
38
  * @name Less 配置
39
- * @description 全局导入 Arco Design 主题变量
39
+ * @description 主题变量由 @mico-platform/theme 提供,在 global.less 中导入
40
40
  */
41
41
  lessLoader: {
42
42
  modifyVars: {},
@@ -77,7 +77,7 @@ const config: ReturnType<typeof defineConfig> = {
77
77
 
78
78
  /**
79
79
  * @name layout 插件
80
- * @description 禁用内置 layout,使用自定义 Arco Design 布局
80
+ * @description 禁用内置 layout,使用自定义 @mico-platform/ui 布局
81
81
  * @doc https://umijs.org/docs/max/layout-menu
82
82
  */
83
83
  layout: false,
@@ -89,7 +89,8 @@ const config: ReturnType<typeof defineConfig> = {
89
89
  locale: {
90
90
  default: 'zh-CN',
91
91
  antd: false,
92
- baseNavigator: true,
92
+ // 禁用浏览器语言自动检测,由运行时 getLocale 统一处理
93
+ baseNavigator: false,
93
94
  },
94
95
 
95
96
  /**
@@ -98,6 +99,7 @@ const config: ReturnType<typeof defineConfig> = {
98
99
  */
99
100
  mock: {
100
101
  include: ['mock/**/_mock.ts', 'mock/**/*.mock.ts', 'src/pages/**/_mock.ts'],
102
+ exclude: ['mock/**/menus.ts'],
101
103
  },
102
104
 
103
105
  /**
@@ -116,6 +118,27 @@ const config: ReturnType<typeof defineConfig> = {
116
118
  */
117
119
  tailwindcss: {},
118
120
 
121
+ /**
122
+ * @name 额外 Babel Presets
123
+ * @description 使用 @mico-platform/ui 的 babel preset,实现组件与图标的按需加载
124
+ */
125
+ extraBabelPresets: ['@mico-platform/ui/babel-preset'],
126
+
127
+ /**
128
+ * @name MFSU 配置
129
+ * @description
130
+ * - exclude: theme 子路径解析;ui 尽量与主应用一起编译
131
+ * - shared: React 单例,确保 MFSU 预打包里的组件(如 Layout)与主应用共用同一份 React,否则 useContext 报 null
132
+ * @doc https://umijs.org/docs/guides/mfsu
133
+ */
134
+ mfsu: {
135
+ exclude: ['@mico-platform/theme', '@mico-platform/ui'],
136
+ shared: {
137
+ react: { singleton: true },
138
+ 'react-dom': { singleton: true },
139
+ },
140
+ },
141
+
119
142
  /**
120
143
  * @name qiankun 微前端配置
121
144
  * @description 作为主应用,动态加载子应用
@@ -5,11 +5,6 @@
5
5
  * @note Umi Max 会自动使用 src/layouts/index.tsx 作为全局布局,无需显式配置
6
6
  */
7
7
  export default [
8
- {
9
- path: '/user/login',
10
- component: './User/Login',
11
- name: '登录',
12
- },
13
8
  {
14
9
  path: '/',
15
10
  component: './Home',
@@ -20,4 +15,9 @@ export default [
20
15
  component: './403',
21
16
  name: '无权限',
22
17
  },
18
+ {
19
+ path: '/*',
20
+ component: './404',
21
+ name: '页面不存在',
22
+ },
23
23
  ];
@@ -37,7 +37,7 @@ const createLogger = (prefix: string) => ({
37
37
 
38
38
  ## 常量定义
39
39
 
40
- 集中管理魔法字符串,位于 `src/common/constants.ts`。
40
+ 集中管理魔法字符串,位于 `src/constants/index.ts`。
41
41
 
42
42
  ### ROUTES
43
43
 
@@ -95,7 +95,7 @@ export const STORAGE_KEYS = {
95
95
  | 文件 | 说明 |
96
96
  | ------------------------------------ | ------------- |
97
97
  | `src/common/logger.ts` | Logger 工具 |
98
- | `src/common/constants.ts` | 常量定义 |
98
+ | `src/constants/index.ts` | 常量定义 |
99
99
  | `apps/homepage/src/common/logger.ts` | 子应用 Logger |
100
100
 
101
101
  ## 注意事项
@@ -0,0 +1,372 @@
1
+ # 通用国际化库使用指南
2
+
3
+ ## 概述
4
+
5
+ `<%= packageScope %>/common-intl` 是 Portal 项目的通用国际化(i18n)库,用于管理多语言文案,支持从多语言中台拉取翻译数据。
6
+
7
+ ## 适用场景
8
+
9
+ - 应用需要支持多语言切换(中文、英文、阿拉伯语、土耳其语等)
10
+ - 需要从多语言中台动态获取翻译文案
11
+ - 希望统一管理国际化逻辑,减少重复代码
12
+
13
+ > **注意**:本文档描述的是 `@payment-portal/common-intl` 包的完整使用方式,涵盖了所有使用该包的应用(包括本仓库外的应用如 conversation-v2、session、workorder 等)。当前仓库仅包含 `layout` 和 `basis` 两个应用。
14
+
15
+ ## 核心特性
16
+
17
+ | 特性 | 说明 |
18
+ | ---------- | ------------------------------------------------ |
19
+ | 跨端兼容 | 通过外部注入 `messageInstance`,适配不同 UI 框架 |
20
+ | 离线缓存 | 支持 IndexedDB + 内存双重缓存 |
21
+ | 插值替换 | 支持 `%AA%`、`%BB%` 等动态占位符 |
22
+ | 降级兜底 | 翻译缺失时自动返回默认文案 |
23
+ | 微前端共享 | 主应用获取文案后,子应用可直接使用 |
24
+
25
+ ## 两种使用模式
26
+
27
+ 根据应用架构的不同,`<%= packageScope %>/common-intl` 支持两种使用模式:
28
+
29
+ | 模式 | 适用场景 | 示例应用 |
30
+ | ------------ | ------------------------------------------------ | ------------------------------------------------------------ |
31
+ | 微前端模式 | qiankun 主子应用架构,主应用获取文案后子应用共享 | layout、conversation-v2、session、workorder、faq、permission |
32
+ | 独立应用模式 | 独立运行的应用,自己获取和管理文案 | mico-cs-mobile |
33
+
34
+ ### 微前端模式
35
+
36
+ 在 qiankun 微前端架构中,**主应用负责获取文案**,子应用直接使用共享的文案对象,无需重复初始化。
37
+
38
+ **工作原理**:
39
+
40
+ - 主应用调用 `initIntl()` 获取远程文案
41
+ - 文案数据存储到 `window.__MICO_COMMON_INTL_TRANSLATIONS__`
42
+ - 子应用直接使用 `intl` 对象,自动从 window 读取共享数据
43
+
44
+ ```
45
+ ┌─────────────────────────────────────────────────────────────┐
46
+ │ apps/layout(主应用) │
47
+ │ ┌─────────────────────────────────────────────────────────┐│
48
+ │ │ initIntl() → 请求远程文案 → 存储到 window 对象 ││
49
+ │ └─────────────────────────────────────────────────────────┘│
50
+ └─────────────────────────────────────────────────────────────┘
51
+
52
+ ┌─────────────────────┼─────────────────────┐
53
+ ↓ ↓ ↓
54
+ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐
55
+ │ conversation │ │ session │ │ workorder │
56
+ │ 子应用 │ │ 子应用 │ │ 子应用 │
57
+ │ import {intl} │ │ import {intl} │ │ import {intl} │
58
+ │ 直接使用 │ │ 直接使用 │ │ 直接使用 │
59
+ └───────────────┘ └───────────────┘ └───────────────┘
60
+ ```
61
+
62
+ **主应用配置(apps/layout/src/app.tsx)**:
63
+
64
+ ```typescript
65
+ import {
66
+ getCurrentLocale,
67
+ initIntl,
68
+ type ILang,
69
+ } from "<%= packageScope %>/common-intl";
70
+ import { Message } from "@mico-platform/ui";
71
+ import { request } from "@umijs/max";
72
+
73
+ // 初始化国际化模块
74
+ const fetchMultilingualData = initIntl({
75
+ requestInstance: request,
76
+ messageInstance: {
77
+ error: (msg: string) => Message.error(msg),
78
+ warning: (msg: string) => Message.warning(msg),
79
+ },
80
+ fetchMultilingualDataParams: {
81
+ tag: "cs_fe_pc",
82
+ lang: getCurrentLocale() as ILang,
83
+ app_name: "middle",
84
+ },
85
+ indexedDBParams: {
86
+ dbName: "mico_cs_web_i18n_db",
87
+ },
88
+ });
89
+
90
+ // 在应用渲染前加载多语言数据
91
+ export function render(oldRender: () => void): void {
92
+ fetchMultilingualData()
93
+ .then(oldRender)
94
+ .catch((error: Error) => {
95
+ console.error("获取多语言文案失败", error);
96
+ oldRender(); // 失败时继续渲染,使用兜底文案
97
+ });
98
+ }
99
+ ```
100
+
101
+ **子应用使用(无需初始化)**:
102
+
103
+ ```typescript
104
+ // apps/conversation-v2、apps/session、apps/workorder 等子应用
105
+ import { intl } from "<%= packageScope %>/common-intl";
106
+
107
+ // 直接使用,文案来自主应用
108
+ <h1>{intl.cs_web_workbench_conversation_record()}</h1>;
109
+ ```
110
+
111
+ ### 独立应用模式
112
+
113
+ 对于非 qiankun 架构的独立应用(如 H5 应用),需要自己调用 `initIntl()` 获取文案,并维护独立的文案文件。
114
+
115
+ **独立应用配置(apps/mico-cs-mobile/src/app.ts)**:
116
+
117
+ ```typescript
118
+ import { initIntl } from "<%= packageScope %>/common-intl";
119
+ import { Toast } from "@arco-design/mobile-react";
120
+ import { request } from "@umijs/max";
121
+ import { convertLocaleToLangParam } from "./locales/utils";
122
+ import { getSearchParams } from "@/common/jsbridge/jsbridge";
123
+
124
+ // 初始化国际化模块
125
+ const fetchMultilingualData = initIntl({
126
+ requestInstance: request,
127
+ messageInstance: {
128
+ error: (msg: string) => Toast.error(msg),
129
+ warning: (msg: string) => Toast.warn(msg),
130
+ },
131
+ fetchMultilingualDataParams: {
132
+ tag: "cs_fe_mobile", // 独立应用使用不同的 tag
133
+ lang: convertLocaleToLangParam(getSearchParams().language as string),
134
+ app_name: "middle",
135
+ },
136
+ indexedDBParams: {
137
+ dbName: "mico_cs_mobile_i18n_db",
138
+ },
139
+ });
140
+
141
+ export function render(oldRender: () => void): void {
142
+ fetchMultilingualData()
143
+ .then(oldRender)
144
+ .catch((error: Error) => {
145
+ console.error("获取多语言文案失败", error);
146
+ oldRender();
147
+ });
148
+ }
149
+ ```
150
+
151
+ **独立应用的文案文件(apps/mico-cs-mobile/src/locales/index.ts)**:
152
+
153
+ ```typescript
154
+ import { i18n } from "<%= packageScope %>/common-intl";
155
+
156
+ const intl = {
157
+ sdk_h5_ticket_record: () =>
158
+ i18n({
159
+ key: "sdk_h5_ticket_record",
160
+ defaultMessage: "工单记录",
161
+ }),
162
+ // ... 其他文案
163
+ };
164
+
165
+ export default intl;
166
+ ```
167
+
168
+ **在组件中使用**:
169
+
170
+ ```typescript
171
+ import intl from "@/locales";
172
+
173
+ <h1>{intl.sdk_h5_ticket_record()}</h1>;
174
+ ```
175
+
176
+ ## 导出 API
177
+
178
+ `<%= packageScope %>/common-intl` 提供以下导出:
179
+
180
+ | 导出 | 类型 | 说明 |
181
+ | -------------------- | ---- | --------------------------------------------------------- |
182
+ | `initIntl` | 函数 | 初始化国际化模块,返回 `fetchMultilingualData` 函数 |
183
+ | `i18n` | 函数 | 翻译函数,用于获取单条翻译文案 |
184
+ | `intl` | 对象 | PC 端主子应用共享的文案对象(仅供 layout 及其子应用使用) |
185
+ | `LANG` | 常量 | 支持的语言常量:`ZH_CN`、`EN`、`AR`、`TR` |
186
+ | `LOCALE` | 常量 | `LANG` 的别名,用于兼容 |
187
+ | `SUPPORTED_LOCALES` | 常量 | 支持的语言列表数组 |
188
+ | `getCurrentLocale` | 函数 | 获取当前语言环境(按优先级:URL > localStorage > 浏览器) |
189
+ | `setLocaleToStorage` | 函数 | 设置语言到 localStorage |
190
+ | `ILang` | 类型 | 语言类型定义 |
191
+ | `TLocale` | 类型 | `ILang` 的别名,用于兼容 |
192
+
193
+ ### 导入示例
194
+
195
+ ```typescript
196
+ // 微前端子应用 - 直接使用共享的 intl 对象
197
+ import { intl } from "<%= packageScope %>/common-intl";
198
+ intl.cs_web_common_request_failed();
199
+
200
+ // 独立应用 - 使用 i18n 函数构建自己的文案对象
201
+ import { i18n, initIntl, LANG } from "<%= packageScope %>/common-intl";
202
+
203
+ // 获取当前语言环境
204
+ import { getCurrentLocale } from "<%= packageScope %>/common-intl";
205
+ const currentLang = getCurrentLocale(); // 'zh_CN' | 'en' | 'ar' | 'tr'
206
+
207
+ // 获取支持的语言列表
208
+ import { SUPPORTED_LOCALES } from "<%= packageScope %>/common-intl";
209
+ console.log(SUPPORTED_LOCALES); // ['zh_CN', 'en', 'ar', 'tr']
210
+ ```
211
+
212
+ ## 文案管理规则
213
+
214
+ ### PC 端主子应用
215
+
216
+ - **文案位置**:[packages/common-intl/src/intl.ts](../packages/common-intl/src/intl.ts)
217
+ - **使用方式**:`import { intl } from '<%= packageScope %>/common-intl'`
218
+ - **适用应用**:
219
+ - apps/layout(主应用)
220
+ - apps/conversation-v2(工作台子应用)
221
+ - apps/session(服务记录子应用)
222
+ - apps/workorder(工单子应用)
223
+ - apps/faq(FAQ 子应用)
224
+ - apps/permission(权限管理子应用)
225
+ - packages/shared(公共包)
226
+
227
+ ### 独立应用(如 mico-cs-mobile)
228
+
229
+ - **文案位置**:各应用自己的 `src/locales/index.ts`
230
+ - **使用方式**:`import intl from '@/locales'`
231
+ - **原因**:独立应用有自己的多语言标签(tag),文案独立管理
232
+
233
+ ### layout-crm 应用
234
+
235
+ - **角色**:另一个主应用(类似 layout)
236
+ - **使用方式**:使用 `getCurrentLocale`、`LOCALE` 等工具函数
237
+ - **说明**:layout-crm 是独立的布局应用,可按需配置国际化初始化
238
+
239
+ ## 快速接入
240
+
241
+ ### 1. 添加依赖
242
+
243
+ ```json
244
+ // apps/your-app/package.json
245
+ {
246
+ "dependencies": {
247
+ "<%= packageScope %>/common-intl": "workspace:*"
248
+ }
249
+ }
250
+ ```
251
+
252
+ ### 2. 根据模式选择接入方式
253
+
254
+ **如果是 layout 的子应用**:
255
+
256
+ - 无需调用 `initIntl()`
257
+ - 直接使用 `import { intl } from '<%= packageScope %>/common-intl'`
258
+
259
+ **如果是独立应用**:
260
+
261
+ - 在 `app.ts` 中调用 `initIntl()` 并配置
262
+ - 创建自己的国际化文案集中管理文件,如 `src/locales/index.ts`
263
+ - 使用 `import intl from '@/locales'`
264
+
265
+ ## 语言优先级
266
+
267
+ `getCurrentLocale()` 函数按以下优先级确定当前语言:
268
+
269
+ 1. **URL 参数**:`?lang=zh_CN`
270
+ 2. **localStorage**:`umi_locale` 键
271
+ 3. **浏览器默认语言**:`navigator.language`
272
+
273
+ ## 详细文档
274
+
275
+ 完整的 API 参考、类型定义和占位符规则,请参阅:
276
+
277
+ - **[packages/common-intl/README.md](../packages/common-intl/README.md)**
278
+
279
+ ## 常见问题
280
+
281
+ ### Q: 微前端子应用需要调用 initIntl 吗?
282
+
283
+ 不需要。主应用(layout)负责初始化和获取文案,子应用直接使用共享的 `intl` 对象即可。
284
+
285
+ ### Q: 如何获取多语言中台的 `tag` 和 `app_name`?
286
+
287
+ 请联系多语言中台管理员,根据你的应用申请对应的配置参数。
288
+
289
+ ### Q: 翻译数据什么时候加载?
290
+
291
+ 推荐在 UmiJS 的 `render` 钩子中调用 `fetchMultilingualData()`,确保在应用渲染前完成加载。
292
+
293
+ ### Q: 如何添加新的翻译文案?
294
+
295
+ 1. 在多语言中台添加新的翻译 key 和对应的各语言翻译
296
+ 2. PC 端:在 `packages/common-intl/src/intl.ts` 中添加对应的函数
297
+ 3. 独立应用:在应用自己的 `src/locales/index.ts` 中添加
298
+ 4. 在代码中通过 `intl.xxx()` 调用
299
+
300
+ ### Q: IndexedDB 不可用怎么办?
301
+
302
+ 库会自动降级到内存缓存模式,不影响正常使用,但页面刷新后需要重新拉取数据。
303
+
304
+ ### Q: 主应用获取文案失败,子应用会怎样?
305
+
306
+ 会显示兜底文案(`defaultMessage`)。建议在定义文案时始终提供有意义的兜底文案。
307
+
308
+ ### Q: 如何切换语言?
309
+
310
+ 语言切换由主应用(layout)的 AvatarDropdown 组件处理,切换后会刷新页面重新加载对应语言的文案。
311
+
312
+ ### Q: 支持哪些语言?
313
+
314
+ 目前支持以下语言:
315
+
316
+ | 语言常量 | 值 | 说明 |
317
+ | ------------- | ------- | -------- |
318
+ | `LANG.ZH_CN` | `zh_CN` | 简体中文 |
319
+ | `LANG.EN_US` | `en` | 英语 |
320
+ | `LANG.AR_SA` | `ar` | 阿拉伯语 |
321
+ | `LANG.TR_TR` | `tr` | 土耳其语 |
322
+
323
+ ### Q: 如何在代码中获取当前语言?
324
+
325
+ ```typescript
326
+ import { getCurrentLocale } from "<%= packageScope %>/common-intl";
327
+
328
+ const currentLang = getCurrentLocale();
329
+ if (currentLang === "ar") {
330
+ // 处理阿拉伯语的 RTL 布局
331
+ }
332
+ ```
333
+
334
+ ### Q: 模块级常量中使用 intl 时,为什么文案显示不正确?
335
+
336
+ 当在模块顶层定义常量时,`intl.xxx()` 会在模块加载时立即执行,此时多语言文案可能还未加载完成,导致显示兜底文案或空值。
337
+
338
+ **错误示例**:
339
+
340
+ ```typescript
341
+ // ❌ 模块加载时立即执行,此时文案可能未加载
342
+ export const STATUS_TEXT = {
343
+ pending: intl.cs_web_status_pending(),
344
+ completed: intl.cs_web_status_completed(),
345
+ };
346
+ ```
347
+
348
+ **正确做法**:用函数包裹,延迟到运行时获取文案。
349
+
350
+ ```typescript
351
+ // ✅ 函数形式,运行时调用才获取文案
352
+ export const getStatusText = (status: TStatus): string => {
353
+ const map: Record<TStatus, string> = {
354
+ pending: intl.cs_web_status_pending(),
355
+ completed: intl.cs_web_status_completed(),
356
+ };
357
+ return map[status];
358
+ };
359
+ ```
360
+
361
+ **在组件中使用时**,如果需要构建选项列表,可用 `useMemo`:
362
+
363
+ ```tsx
364
+ const options = useMemo(
365
+ () =>
366
+ Object.values(Status).map((status) => ({
367
+ value: status,
368
+ label: getStatusText(status),
369
+ })),
370
+ [],
371
+ );
372
+ ```