generator-mico-cli 0.2.18 → 0.2.19
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/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/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 +19 -66
- 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 +3 -3
- package/generators/micro-react/templates/apps/layout/src/components/RightContent/AvatarDropdown.tsx +4 -5
- 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/package.json +1 -1
|
@@ -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':
|
|
@@ -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
|
/**
|
|
@@ -140,36 +123,6 @@ export function setLocaleToStorage(locale: SupportedLocale): void {
|
|
|
140
123
|
* 根据语言获取图标库路径
|
|
141
124
|
*/
|
|
142
125
|
export function getIconFontPath(locale: SupportedLocale): string {
|
|
143
|
-
|
|
144
|
-
return withPublicPath('/font/ar-SA.js');
|
|
145
|
-
}
|
|
126
|
+
// 如果后续需要支持 RTL 语言(如阿拉伯语),可在此扩展
|
|
146
127
|
return withPublicPath('/font/default.js');
|
|
147
128
|
}
|
|
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());
|
|
175
|
-
}
|
|
@@ -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';
|
|
@@ -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;
|