generator-mico-cli 0.2.18 → 0.2.20
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/generators/micro-react/index.js +10 -0
- package/generators/micro-react/templates/.eslintrc.js +24 -1
- package/generators/micro-react/templates/CICD/start_dev.sh +1 -1
- package/generators/micro-react/templates/apps/layout/config/config.dev.ts +3 -3
- package/generators/micro-react/templates/apps/layout/config/config.prod.development.ts +2 -2
- package/generators/micro-react/templates/apps/layout/config/config.prod.testing.ts +1 -1
- package/generators/micro-react/templates/apps/layout/config/config.prod.ts +1 -1
- package/generators/micro-react/templates/apps/layout/docs/common-intl.md +15 -15
- 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 +1 -1
- 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 +1 -1
- package/generators/micro-react/templates/apps/layout/package.json +0 -1
- package/generators/micro-react/templates/apps/layout/src/app.tsx +2 -4
- package/generators/micro-react/templates/apps/layout/src/common/locale.ts +21 -68
- package/generators/micro-react/templates/apps/layout/src/common/menu/parser.ts +5 -4
- package/generators/micro-react/templates/apps/layout/src/common/request/url-resolver.ts +1 -1
- package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/index.tsx +4 -4
- package/generators/micro-react/templates/apps/layout/src/components/RightContent/AvatarDropdown.tsx +4 -5
- package/generators/micro-react/templates/apps/layout/src/global.less +1 -1
- package/generators/micro-react/templates/apps/layout/src/layouts/index.less +1 -1
- package/generators/micro-react/templates/apps/layout/src/locales/en-US.ts +3 -0
- package/generators/micro-react/templates/apps/layout/src/locales/zh-CN.ts +3 -0
- package/generators/micro-react/templates/apps/layout/src/pages/Home/index.tsx +7 -1
- package/generators/micro-react/templates/apps/layout/src/services/config/type.ts +2 -4
- package/generators/micro-react/templates/package.json +3 -1
- package/generators/micro-react/templates/packages/common-intl/README.md +8 -8
- package/generators/micro-react/templates/packages/common-intl/src/intl.ts +13 -5678
- package/generators/micro-react/templates/packages/common-intl/src/utils.ts +22 -21
- package/package.json +1 -1
- package/generators/micro-react/templates/packages/common-intl/.turbo/turbo-build.log +0 -13
- package/generators/micro-react/templates/packages/common-intl/dist/index.d.ts +0 -3
- package/generators/micro-react/templates/packages/common-intl/dist/index.js +0 -4388
- package/generators/micro-react/templates/packages/common-intl/dist/indexedDBUtils.d.ts +0 -13
- package/generators/micro-react/templates/packages/common-intl/dist/intl.d.ts +0 -1022
- package/generators/micro-react/templates/packages/common-intl/dist/utils.d.ts +0 -122
|
@@ -210,6 +210,16 @@ module.exports = class extends Generator {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
install() {
|
|
213
|
+
// 检查并初始化 git
|
|
214
|
+
const gitDir = path.join(this.destDir, '.git');
|
|
215
|
+
if (!fs.existsSync(gitDir)) {
|
|
216
|
+
this.log('');
|
|
217
|
+
this.log('🔧 初始化 Git 仓库...');
|
|
218
|
+
this.spawnCommandSync('git', ['init'], {
|
|
219
|
+
cwd: this.destDir,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
213
223
|
this.log('');
|
|
214
224
|
this.log('📦 正在安装依赖...');
|
|
215
225
|
this.spawnCommandSync('pnpm', ['install'], {
|
|
@@ -19,7 +19,30 @@ module.exports = {
|
|
|
19
19
|
},
|
|
20
20
|
],
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
// TypeScript 文件使用专门的 parser
|
|
23
|
+
overrides: [
|
|
24
|
+
{
|
|
25
|
+
files: ["*.ts", "*.tsx"],
|
|
26
|
+
parser: "@typescript-eslint/parser",
|
|
27
|
+
plugins: ["@typescript-eslint"],
|
|
28
|
+
extends: [
|
|
29
|
+
"eslint:recommended",
|
|
30
|
+
"plugin:@typescript-eslint/recommended",
|
|
31
|
+
],
|
|
32
|
+
rules: {
|
|
33
|
+
// 使用 TS 版本的 no-unused-vars
|
|
34
|
+
"no-unused-vars": "off",
|
|
35
|
+
"@typescript-eslint/no-unused-vars": [
|
|
36
|
+
"warn",
|
|
37
|
+
{
|
|
38
|
+
argsIgnorePattern: "^_",
|
|
39
|
+
varsIgnorePattern: "^_",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
// 忽略 apps/ 子包和 scripts/,apps由内部的eslint规则处理
|
|
23
46
|
ignorePatterns: [
|
|
24
47
|
'node_modules/',
|
|
25
48
|
'dist/',
|
|
@@ -48,7 +48,7 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
48
48
|
// 依赖 origin 的功能可能需要这个,比如 cookie
|
|
49
49
|
changeOrigin: true,
|
|
50
50
|
},
|
|
51
|
-
'/proxy
|
|
51
|
+
'/proxy/<%= projectName %>_svr': {
|
|
52
52
|
// 要代理的地址
|
|
53
53
|
target: 'https://dashboard-api-test.micoplatform.com',
|
|
54
54
|
// 配置了这个可以从 http 代理到 https
|
|
@@ -59,8 +59,8 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
59
59
|
define: {
|
|
60
60
|
'process.env.NODE_ENV': 'development',
|
|
61
61
|
'process.env.APP_ID': '<%= projectName %>',
|
|
62
|
-
'process.env.API_BASE_URL': '
|
|
63
|
-
'process.env.PROXY_SUFFIX': '/proxy
|
|
62
|
+
'process.env.API_BASE_URL': '',
|
|
63
|
+
'process.env.PROXY_SUFFIX': '/proxy/<%= projectName %>_svr',
|
|
64
64
|
'process.env.LOGIN_ENDPOINT':
|
|
65
65
|
'https://dashboard-api-test.micoplatform.com/api/yufu_login/',
|
|
66
66
|
'process.env.REFRESH_ENDPOINT':
|
|
@@ -6,8 +6,8 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
6
6
|
define: {
|
|
7
7
|
'process.env.NODE_ENV': 'development',
|
|
8
8
|
'process.env.APP_ID': '<%= projectName %>',
|
|
9
|
-
'process.env.API_BASE_URL': '',
|
|
10
|
-
'process.env.PROXY_SUFFIX': '/proxy
|
|
9
|
+
'process.env.API_BASE_URL': 'https://dashboard-api-test.micoplatform.com',
|
|
10
|
+
'process.env.PROXY_SUFFIX': '/proxy/<%= projectName %>_svr',
|
|
11
11
|
'process.env.LOGIN_ENDPOINT':
|
|
12
12
|
'https://dashboard-api-test.micoplatform.com/api/yufu_login/',
|
|
13
13
|
'process.env.REFRESH_ENDPOINT':
|
|
@@ -7,7 +7,7 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
7
7
|
'process.env.NODE_ENV': 'testing',
|
|
8
8
|
'process.env.APP_ID': '<%= projectName %>',
|
|
9
9
|
'process.env.API_BASE_URL': 'https://dashboard-api-test.micoplatform.com',
|
|
10
|
-
'process.env.PROXY_SUFFIX': '/proxy
|
|
10
|
+
'process.env.PROXY_SUFFIX': '/proxy/<%= projectName %>_svr',
|
|
11
11
|
'process.env.LOGIN_ENDPOINT':
|
|
12
12
|
'https://dashboard-api-test.micoplatform.com/api/yufu_login/',
|
|
13
13
|
'process.env.REFRESH_ENDPOINT':
|
|
@@ -12,7 +12,7 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
12
12
|
'process.env.NODE_ENV': 'production',
|
|
13
13
|
'process.env.APP_ID': '<%= projectName %>',
|
|
14
14
|
'process.env.API_BASE_URL': 'https://dashboard-api.micoplatform.com',
|
|
15
|
-
'process.env.PROXY_SUFFIX': '/proxy
|
|
15
|
+
'process.env.PROXY_SUFFIX': '/proxy/<%= projectName %>_svr',
|
|
16
16
|
'process.env.LOGIN_ENDPOINT':
|
|
17
17
|
'https://dashboard-api.micoplatform.com/api/yufu_login/',
|
|
18
18
|
'process.env.REFRESH_ENDPOINT':
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## 概述
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`<%= packageScope %>/common-intl` 是 Portal 项目的通用国际化(i18n)库,用于管理多语言文案,支持从多语言中台拉取翻译数据。
|
|
6
6
|
|
|
7
7
|
## 适用场景
|
|
8
8
|
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
## 两种使用模式
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
根据应用架构的不同,`<%= packageScope %>/common-intl` 支持两种使用模式:
|
|
26
26
|
|
|
27
27
|
| 模式 | 适用场景 | 示例应用 |
|
|
28
28
|
| ------------ | ------------------------------------------------ | ------------------------------------------------------------ |
|
|
@@ -64,7 +64,7 @@ import {
|
|
|
64
64
|
getCurrentLocale,
|
|
65
65
|
initIntl,
|
|
66
66
|
type ILang,
|
|
67
|
-
} from "
|
|
67
|
+
} from "<%= packageScope %>/common-intl";
|
|
68
68
|
import { Message } from "@mico-platform/ui";
|
|
69
69
|
import { request } from "@umijs/max";
|
|
70
70
|
|
|
@@ -100,7 +100,7 @@ export function render(oldRender: () => void): void {
|
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
102
102
|
// apps/conversation-v2、apps/session、apps/workorder 等子应用
|
|
103
|
-
import { intl } from "
|
|
103
|
+
import { intl } from "<%= packageScope %>/common-intl";
|
|
104
104
|
|
|
105
105
|
// 直接使用,文案来自主应用
|
|
106
106
|
<h1>{intl.cs_web_workbench_conversation_record()}</h1>;
|
|
@@ -113,7 +113,7 @@ import { intl } from "@portal-web/common-intl";
|
|
|
113
113
|
**独立应用配置(apps/mico-cs-mobile/src/app.ts)**:
|
|
114
114
|
|
|
115
115
|
```typescript
|
|
116
|
-
import { initIntl } from "
|
|
116
|
+
import { initIntl } from "<%= packageScope %>/common-intl";
|
|
117
117
|
import { Toast } from "@arco-design/mobile-react";
|
|
118
118
|
import { request } from "@umijs/max";
|
|
119
119
|
import { convertLocaleToLangParam } from "./locales/utils";
|
|
@@ -149,7 +149,7 @@ export function render(oldRender: () => void): void {
|
|
|
149
149
|
**独立应用的文案文件(apps/mico-cs-mobile/src/locales/index.ts)**:
|
|
150
150
|
|
|
151
151
|
```typescript
|
|
152
|
-
import { i18n } from "
|
|
152
|
+
import { i18n } from "<%= packageScope %>/common-intl";
|
|
153
153
|
|
|
154
154
|
const intl = {
|
|
155
155
|
sdk_h5_ticket_record: () =>
|
|
@@ -173,7 +173,7 @@ import intl from "@/locales";
|
|
|
173
173
|
|
|
174
174
|
## 导出 API
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
`<%= packageScope %>/common-intl` 提供以下导出:
|
|
177
177
|
|
|
178
178
|
| 导出 | 类型 | 说明 |
|
|
179
179
|
| -------------------- | ---- | --------------------------------------------------------- |
|
|
@@ -192,18 +192,18 @@ import intl from "@/locales";
|
|
|
192
192
|
|
|
193
193
|
```typescript
|
|
194
194
|
// 微前端子应用 - 直接使用共享的 intl 对象
|
|
195
|
-
import { intl } from "
|
|
195
|
+
import { intl } from "<%= packageScope %>/common-intl";
|
|
196
196
|
intl.cs_web_common_request_failed();
|
|
197
197
|
|
|
198
198
|
// 独立应用 - 使用 i18n 函数构建自己的文案对象
|
|
199
|
-
import { i18n, initIntl, LANG } from "
|
|
199
|
+
import { i18n, initIntl, LANG } from "<%= packageScope %>/common-intl";
|
|
200
200
|
|
|
201
201
|
// 获取当前语言环境
|
|
202
|
-
import { getCurrentLocale } from "
|
|
202
|
+
import { getCurrentLocale } from "<%= packageScope %>/common-intl";
|
|
203
203
|
const currentLang = getCurrentLocale(); // 'zh_CN' | 'en' | 'ar' | 'tr'
|
|
204
204
|
|
|
205
205
|
// 获取支持的语言列表
|
|
206
|
-
import { SUPPORTED_LOCALES } from "
|
|
206
|
+
import { SUPPORTED_LOCALES } from "<%= packageScope %>/common-intl";
|
|
207
207
|
console.log(SUPPORTED_LOCALES); // ['zh_CN', 'en', 'ar', 'tr']
|
|
208
208
|
```
|
|
209
209
|
|
|
@@ -212,7 +212,7 @@ console.log(SUPPORTED_LOCALES); // ['zh_CN', 'en', 'ar', 'tr']
|
|
|
212
212
|
### PC 端主子应用
|
|
213
213
|
|
|
214
214
|
- **文案位置**:[packages/common-intl/src/intl.ts](../packages/common-intl/src/intl.ts)
|
|
215
|
-
- **使用方式**:`import { intl } from '
|
|
215
|
+
- **使用方式**:`import { intl } from '<%= packageScope %>/common-intl'`
|
|
216
216
|
- **适用应用**:
|
|
217
217
|
- apps/layout(主应用)
|
|
218
218
|
- apps/conversation-v2(工作台子应用)
|
|
@@ -242,7 +242,7 @@ console.log(SUPPORTED_LOCALES); // ['zh_CN', 'en', 'ar', 'tr']
|
|
|
242
242
|
// apps/your-app/package.json
|
|
243
243
|
{
|
|
244
244
|
"dependencies": {
|
|
245
|
-
"
|
|
245
|
+
"<%= packageScope %>/common-intl": "workspace:*"
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
```
|
|
@@ -252,7 +252,7 @@ console.log(SUPPORTED_LOCALES); // ['zh_CN', 'en', 'ar', 'tr']
|
|
|
252
252
|
**如果是 layout 的子应用**:
|
|
253
253
|
|
|
254
254
|
- 无需调用 `initIntl()`
|
|
255
|
-
- 直接使用 `import { intl } from '
|
|
255
|
+
- 直接使用 `import { intl } from '<%= packageScope %>/common-intl'`
|
|
256
256
|
|
|
257
257
|
**如果是独立应用**:
|
|
258
258
|
|
|
@@ -321,7 +321,7 @@ console.log(SUPPORTED_LOCALES); // ['zh_CN', 'en', 'ar', 'tr']
|
|
|
321
321
|
### Q: 如何在代码中获取当前语言?
|
|
322
322
|
|
|
323
323
|
```typescript
|
|
324
|
-
import { getCurrentLocale } from "
|
|
324
|
+
import { getCurrentLocale } from "<%= packageScope %>/common-intl";
|
|
325
325
|
|
|
326
326
|
const currentLang = getCurrentLocale();
|
|
327
327
|
if (currentLang === "ar") {
|
|
@@ -201,7 +201,7 @@ wc -c apps/[子应用]/dist/umi.css
|
|
|
201
201
|
1. 主应用加载 @mico-platform/ui 并暴露到 `window.micoUI`
|
|
202
202
|
2. 主应用的样式包含 `arco-theme` 属性选择器(基于 Arco)
|
|
203
203
|
3. 主应用切换主题时设置 `body[arco-theme="dark"]`
|
|
204
|
-
4. 子应用的 UI 组件(来自 window.
|
|
204
|
+
4. 子应用的 UI 组件(来自 window.micoUI)自动应用暗色样式
|
|
205
205
|
|
|
206
206
|
#### 子应用使用 @mico-platform/ui
|
|
207
207
|
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
import { initTheme } from './common/theme';
|
|
23
23
|
import MicroAppLoader from './components/MicroAppLoader';
|
|
24
24
|
import { isNoAuthRoute } from '@/constants';
|
|
25
|
-
import {
|
|
25
|
+
import { getCurrentLocale } from '@/common/locale';
|
|
26
26
|
import './global.less';
|
|
27
27
|
|
|
28
28
|
// ==================== qiankun 全局错误处理 ====================
|
|
@@ -93,16 +93,14 @@ if (typeof window !== 'undefined') {
|
|
|
93
93
|
initTheme();
|
|
94
94
|
|
|
95
95
|
// ==================== 国际化运行时配置 ====================
|
|
96
|
-
// 使用 umi 本地文案,通过映射转换保持 localStorage 与 common-intl 统一
|
|
97
96
|
|
|
98
97
|
/**
|
|
99
98
|
* 运行时国际化配置
|
|
100
|
-
* 自定义 getLocale 函数,将 common-intl 格式 (zh_CN, en) 转换为 umi 格式 (zh-CN, en-US)
|
|
101
99
|
* @see https://umijs.org/docs/max/i18n#%E8%BF%90%E8%A1%8C%E6%97%B6%E9%85%8D%E7%BD%AE
|
|
102
100
|
*/
|
|
103
101
|
export const locale = {
|
|
104
102
|
getLocale() {
|
|
105
|
-
return
|
|
103
|
+
return getCurrentLocale();
|
|
106
104
|
},
|
|
107
105
|
};
|
|
108
106
|
|
|
@@ -12,39 +12,23 @@ const LOCALE_STORAGE_KEY = 'umi_locale';
|
|
|
12
12
|
const URL_PARAM_KEY = 'lang';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* 支持的语言列表(umi 格式)
|
|
16
16
|
*/
|
|
17
|
-
export const SUPPORTED_LOCALES = ['
|
|
17
|
+
export const SUPPORTED_LOCALES = ['zh-CN', 'en-US'] as const;
|
|
18
18
|
export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* 语言枚举常量
|
|
22
22
|
*/
|
|
23
|
-
export
|
|
23
|
+
export const LOCALE = {
|
|
24
|
+
ZH_CN: 'zh-CN',
|
|
25
|
+
EN_US: 'en-US',
|
|
26
|
+
} as const;
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
|
-
*
|
|
27
|
-
* localStorage 存储值 → umi 本地文案文件名
|
|
29
|
+
* 默认语言
|
|
28
30
|
*/
|
|
29
|
-
const
|
|
30
|
-
zh_CN: 'zh-CN',
|
|
31
|
-
en: 'en-US',
|
|
32
|
-
ar: 'en-US', // 阿拉伯语暂无本地文案,回退到英文
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 语言映射:umi → common-intl
|
|
37
|
-
* umi 本地文案文件名 → localStorage 存储值
|
|
38
|
-
*/
|
|
39
|
-
const UMI_TO_LOCALE: Record<UmiLocale, SupportedLocale> = {
|
|
40
|
-
'zh-CN': 'zh_CN',
|
|
41
|
-
'en-US': 'en',
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 默认语言(common-intl 格式)
|
|
46
|
-
*/
|
|
47
|
-
const DEFAULT_LOCALE: SupportedLocale = 'en';
|
|
31
|
+
const DEFAULT_LOCALE: SupportedLocale = 'en-US';
|
|
48
32
|
|
|
49
33
|
/**
|
|
50
34
|
* 从 URL 参数获取语言
|
|
@@ -74,20 +58,19 @@ function getLocaleFromStorage(): string | null {
|
|
|
74
58
|
/**
|
|
75
59
|
* 获取浏览器默认语言
|
|
76
60
|
*/
|
|
77
|
-
function getBrowserLocale():
|
|
61
|
+
function getBrowserLocale(): SupportedLocale {
|
|
78
62
|
if (typeof window === 'undefined') {
|
|
79
63
|
return DEFAULT_LOCALE;
|
|
80
64
|
}
|
|
81
65
|
const browserLang = navigator.language || (navigator as any).userLanguage;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
66
|
+
const locales = [...SUPPORTED_LOCALES];
|
|
67
|
+
// 检查是否直接支持该语言
|
|
68
|
+
if (locales.includes(browserLang as SupportedLocale)) {
|
|
69
|
+
return browserLang as SupportedLocale;
|
|
85
70
|
}
|
|
86
|
-
// 检查语言前缀(如 zh-TW -> zh-CN)
|
|
71
|
+
// 检查语言前缀(如 zh-TW -> zh-CN, en-GB -> en-US)
|
|
87
72
|
const langPrefix = browserLang.split('-')[0];
|
|
88
|
-
const matchedLocale =
|
|
89
|
-
locale.startsWith(langPrefix),
|
|
90
|
-
);
|
|
73
|
+
const matchedLocale = locales.find((locale) => locale.startsWith(langPrefix));
|
|
91
74
|
return matchedLocale || DEFAULT_LOCALE;
|
|
92
75
|
}
|
|
93
76
|
|
|
@@ -98,7 +81,7 @@ function isValidLocale(locale: string | null): locale is SupportedLocale {
|
|
|
98
81
|
if (!locale) {
|
|
99
82
|
return false;
|
|
100
83
|
}
|
|
101
|
-
return SUPPORTED_LOCALES.includes(locale
|
|
84
|
+
return ([...SUPPORTED_LOCALES] as string[]).includes(locale);
|
|
102
85
|
}
|
|
103
86
|
|
|
104
87
|
/**
|
|
@@ -119,7 +102,7 @@ export function getCurrentLocale(): SupportedLocale {
|
|
|
119
102
|
}
|
|
120
103
|
|
|
121
104
|
// 3. 使用浏览器默认语言
|
|
122
|
-
return getBrowserLocale()
|
|
105
|
+
return getBrowserLocale();
|
|
123
106
|
}
|
|
124
107
|
|
|
125
108
|
/**
|
|
@@ -139,37 +122,7 @@ export function setLocaleToStorage(locale: SupportedLocale): void {
|
|
|
139
122
|
/**
|
|
140
123
|
* 根据语言获取图标库路径
|
|
141
124
|
*/
|
|
142
|
-
export function getIconFontPath(locale: SupportedLocale): string {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
return withPublicPath('/font/default.js');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// ==================== 语言类型转换函数 ====================
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* 将 common-intl 语言标识符转换为 umi 格式
|
|
153
|
-
* @param locale common-intl 格式的语言标识符 (zh_CN, en, ar)
|
|
154
|
-
* @returns umi 格式的语言标识符 (zh-CN, en-US)
|
|
155
|
-
*/
|
|
156
|
-
export function toUmiLocale(locale: SupportedLocale): UmiLocale {
|
|
157
|
-
return LOCALE_TO_UMI[locale] ?? 'en-US';
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* 将 umi 语言标识符转换为 common-intl 格式
|
|
162
|
-
* @param umiLocale umi 格式的语言标识符 (zh-CN, en-US)
|
|
163
|
-
* @returns common-intl 格式的语言标识符 (zh_CN, en)
|
|
164
|
-
*/
|
|
165
|
-
export function fromUmiLocale(umiLocale: UmiLocale): SupportedLocale {
|
|
166
|
-
return UMI_TO_LOCALE[umiLocale] ?? 'en';
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* 获取当前语言的 umi 格式(供 umi locale 运行时配置使用)
|
|
171
|
-
* @returns umi 格式的语言标识符
|
|
172
|
-
*/
|
|
173
|
-
export function getUmiLocale(): UmiLocale {
|
|
174
|
-
return toUmiLocale(getCurrentLocale());
|
|
125
|
+
export function getIconFontPath(/* locale: SupportedLocale */): string {
|
|
126
|
+
// 如果后续需要支持 RTL 语言(如阿拉伯语),可在此扩展
|
|
127
|
+
return withPublicPath("/font/default.js");
|
|
175
128
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getIntl } from '@umijs/max';
|
|
2
2
|
import { isAuthDisabled, isNoPermissionRoute } from '@/constants';
|
|
3
3
|
import type { MenuItem, ParsedMenuItem, ParsedRoute } from './types';
|
|
4
|
-
import { getCurrentLocale } from '@/common/locale';
|
|
4
|
+
import { getCurrentLocale, LOCALE } from '@/common/locale';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 获取 window 上挂载的菜单数据
|
|
@@ -35,7 +35,7 @@ export const buildMenuPath = (parentPath: string, name: string): string => {
|
|
|
35
35
|
*/
|
|
36
36
|
export const isChineseLocale = (): boolean => {
|
|
37
37
|
const locale = getCurrentLocale();
|
|
38
|
-
return locale ===
|
|
38
|
+
return locale === LOCALE.ZH_CN;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -241,7 +241,8 @@ export const extractRoutes = (
|
|
|
241
241
|
* @returns 翻译后的菜单名称
|
|
242
242
|
*/
|
|
243
243
|
export const getMenuLabel = (key: string, fallbackName?: string): string => {
|
|
244
|
-
|
|
244
|
+
const intl = getIntl();
|
|
245
|
+
return intl.formatMessage({ id: key, defaultMessage: fallbackName ?? key });
|
|
245
246
|
};
|
|
246
247
|
|
|
247
248
|
/**
|
|
@@ -37,7 +37,7 @@ const joinProxyAndPath = (proxySuffix: string, path: string): string => {
|
|
|
37
37
|
* 4. 其他情况 → 拼接 apiBaseUrl + proxySuffix + url
|
|
38
38
|
*
|
|
39
39
|
* 示例(testing 环境,apiBaseUrl = https://dashboard-api-test.micoplatform.com):
|
|
40
|
-
* - 默认: /api/user/info → https://dashboard-api-test.micoplatform.com/proxy/
|
|
40
|
+
* - 默认: /api/user/info → https://dashboard-api-test.micoplatform.com/proxy/<%= projectName %>_svr/api/user/info
|
|
41
41
|
* - skipProxy: /api/user/info → https://dashboard-api-test.micoplatform.com/api/user/info
|
|
42
42
|
*/
|
|
43
43
|
export const resolveRequestUrl = (
|
package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getAuthInfo } from '@/common/auth/auth-manager';
|
|
2
2
|
import { EEnv, getEnv } from '@/common/env';
|
|
3
|
-
import {
|
|
3
|
+
import { getCurrentLocale } from '@/common/locale';
|
|
4
4
|
import { request } from '@/common/request';
|
|
5
5
|
import { isAuthDisabled, isNoPermissionRoute } from '@/constants';
|
|
6
6
|
import { Spin } from '@mico-platform/ui';
|
|
@@ -70,7 +70,7 @@ const MicroAppLoader: React.FC<MicroAppLoaderProps> = ({
|
|
|
70
70
|
const buildProps = useCallback(() => {
|
|
71
71
|
const authInfo = getAuthInfo();
|
|
72
72
|
return {
|
|
73
|
-
mainApp: '
|
|
73
|
+
mainApp: '<%= projectName %>',
|
|
74
74
|
env,
|
|
75
75
|
authToken: authInfo.token,
|
|
76
76
|
uid: authInfo.uid,
|
|
@@ -80,8 +80,8 @@ const MicroAppLoader: React.FC<MicroAppLoaderProps> = ({
|
|
|
80
80
|
routePath,
|
|
81
81
|
// 传递主应用的 request 实例,子应用可直接使用
|
|
82
82
|
request,
|
|
83
|
-
// 传递当前多语言类型给子应用(
|
|
84
|
-
locale:
|
|
83
|
+
// 传递当前多语言类型给子应用(zh-CN, en-US)
|
|
84
|
+
locale: getCurrentLocale(),
|
|
85
85
|
};
|
|
86
86
|
}, [env, routePath]);
|
|
87
87
|
|
package/generators/micro-react/templates/apps/layout/src/components/RightContent/AvatarDropdown.tsx
CHANGED
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
getCurrentLocale,
|
|
11
11
|
LOCALE,
|
|
12
12
|
setLocaleToStorage,
|
|
13
|
-
type
|
|
14
|
-
} from '
|
|
13
|
+
type SupportedLocale,
|
|
14
|
+
} from '@/common/locale';
|
|
15
15
|
import IconFont from '@/components/IconFont';
|
|
16
16
|
import { useTheme } from '@/hooks/useTheme';
|
|
17
17
|
import { getTimezoneList, type ITimezone } from '@/services/config';
|
|
@@ -173,12 +173,11 @@ export const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu }) => {
|
|
|
173
173
|
|
|
174
174
|
// 处理语言切换
|
|
175
175
|
if (key.startsWith('language-')) {
|
|
176
|
-
const newLocale = key.replace('language-', '') as
|
|
176
|
+
const newLocale = key.replace('language-', '') as SupportedLocale;
|
|
177
177
|
const currentLocale = getCurrentLocale();
|
|
178
178
|
if (newLocale === currentLocale) {
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
181
|
-
// 存储 common-intl 格式的语言标识符,刷新后 umi 会通过映射转换
|
|
182
181
|
setLocaleToStorage(newLocale);
|
|
183
182
|
window.location.reload();
|
|
184
183
|
return;
|
|
@@ -313,7 +312,7 @@ export const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu }) => {
|
|
|
313
312
|
|
|
314
313
|
// 语言菜单项选中状态
|
|
315
314
|
if (item.key.startsWith('language-')) {
|
|
316
|
-
const locale = item.key.replace('language-', '') as
|
|
315
|
+
const locale = item.key.replace('language-', '') as SupportedLocale;
|
|
317
316
|
const currentLocale = getCurrentLocale();
|
|
318
317
|
if (locale === currentLocale) {
|
|
319
318
|
displayLabel = (
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { useIntl } from '@umijs/max';
|
|
1
2
|
import styles from './index.less';
|
|
2
3
|
|
|
3
4
|
const HomePage: React.FC = () => {
|
|
4
|
-
|
|
5
|
+
const intl = useIntl();
|
|
6
|
+
return (
|
|
7
|
+
<div className={styles.container}>
|
|
8
|
+
{intl.formatMessage({ id: 'page.home.title' })}
|
|
9
|
+
</div>
|
|
10
|
+
);
|
|
5
11
|
};
|
|
6
12
|
|
|
7
13
|
export default HomePage;
|
|
@@ -24,13 +24,15 @@
|
|
|
24
24
|
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix && turbo run lint:fix",
|
|
25
25
|
"check-types": "turbo run check-types",
|
|
26
26
|
"lint-staged": "pnpm exec lint-staged --quiet",
|
|
27
|
-
"prepare": "husky
|
|
27
|
+
"prepare": "husky",
|
|
28
28
|
"test": "dotenv -e .env -e .env.local -- turbo run test",
|
|
29
29
|
"create:umi-app": "./scripts/create-umi-app.sh"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@commitlint/cli": "^19.5.0",
|
|
33
33
|
"@commitlint/config-conventional": "^19.5.0",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
35
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
34
36
|
"dotenv-cli": "^7.4.1",
|
|
35
37
|
"eslint": "^8.57.0",
|
|
36
38
|
"husky": "^9.1.7",
|