quick-platform 1.0.46

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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -0
  3. package/dist/application/constants.d.ts +4 -0
  4. package/dist/application/index.d.ts +29 -0
  5. package/dist/application/manage.d.ts +31 -0
  6. package/dist/business/index.d.ts +72 -0
  7. package/dist/business/version.d.ts +7 -0
  8. package/dist/components/IconFont.d.ts +4 -0
  9. package/dist/components/LocalDebug.d.ts +6 -0
  10. package/dist/components/MicroApp.d.ts +14 -0
  11. package/dist/components/Permission.d.ts +6 -0
  12. package/dist/components/context.d.ts +3 -0
  13. package/dist/components/i18n.d.ts +2 -0
  14. package/dist/config.d.ts +2 -0
  15. package/dist/config.js +2 -0
  16. package/dist/config.js.map +1 -0
  17. package/dist/event.d.ts +13 -0
  18. package/dist/index-543d110b.js +547 -0
  19. package/dist/index-543d110b.js.map +1 -0
  20. package/dist/index-be61d86b.js +2 -0
  21. package/dist/index-be61d86b.js.map +1 -0
  22. package/dist/index.d.ts +12 -0
  23. package/dist/index.js +2 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/theme/define/color.d.ts +9 -0
  26. package/dist/theme/define/font.d.ts +50 -0
  27. package/dist/theme/define/index.d.ts +5 -0
  28. package/dist/theme/define/size.d.ts +24 -0
  29. package/dist/theme/define/style.d.ts +21 -0
  30. package/dist/theme/doc.d.ts +2 -0
  31. package/dist/theme/index.d.ts +3 -0
  32. package/dist/theme/lib/index.d.ts +1 -0
  33. package/dist/theme/react/hook.d.ts +5 -0
  34. package/dist/theme/react/index.d.ts +3 -0
  35. package/dist/theme/uno.d.ts +19 -0
  36. package/dist/utils/i18n.d.ts +6 -0
  37. package/dist/utils/image.d.ts +2 -0
  38. package/dist/utils/index.d.ts +5 -0
  39. package/dist/utils/localstorage.d.ts +6 -0
  40. package/dist/utils/request.d.ts +37 -0
  41. package/dist/utils/utils.d.ts +3 -0
  42. package/package.json +67 -0
  43. package/src/application/constants.ts +7 -0
  44. package/src/application/index.ts +82 -0
  45. package/src/application/manage.ts +119 -0
  46. package/src/business/declare.d.ts +39 -0
  47. package/src/business/index.ts +130 -0
  48. package/src/business/version.ts +58 -0
  49. package/src/components/IconFont.ts +11 -0
  50. package/src/components/LocalDebug.ts +244 -0
  51. package/src/components/MicroApp.ts +97 -0
  52. package/src/components/Permission.ts +13 -0
  53. package/src/components/context.ts +31 -0
  54. package/src/components/i18n.ts +17 -0
  55. package/src/config.ts +3 -0
  56. package/src/event.ts +24 -0
  57. package/src/index.ts +38 -0
  58. package/src/theme/define/color.ts +53 -0
  59. package/src/theme/define/font.ts +29 -0
  60. package/src/theme/define/index.ts +8 -0
  61. package/src/theme/define/size.ts +31 -0
  62. package/src/theme/define/style.ts +41 -0
  63. package/src/theme/doc.tsx +438 -0
  64. package/src/theme/index.ts +5 -0
  65. package/src/theme/lib/index.ts +15 -0
  66. package/src/theme/react/hook.ts +42 -0
  67. package/src/theme/react/index.ts +14 -0
  68. package/src/theme/uno.ts +218 -0
  69. package/src/utils/i18n.ts +84 -0
  70. package/src/utils/image.ts +52 -0
  71. package/src/utils/index.ts +9 -0
  72. package/src/utils/localstorage.ts +32 -0
  73. package/src/utils/request.ts +173 -0
  74. package/src/utils/utils.ts +15 -0
@@ -0,0 +1,39 @@
1
+ export interface UserInfo {
2
+ rightList: string[];
3
+ staffInfo: {
4
+ email: string;
5
+ firstName: string;
6
+ id: string;
7
+ name: string;
8
+ role: string;
9
+ roleList: string[];
10
+ storeId: number;
11
+ userId: string;
12
+ [key: string]: any;
13
+ };
14
+ storeInfo: {
15
+ [key: string]: any;
16
+ city: string;
17
+ id: number;
18
+ platform: string;
19
+ productCategory: string;
20
+ storeName: string;
21
+ timezone: string;
22
+ };
23
+ storeLicenceInfo: {
24
+ storeId: number;
25
+ name: string;
26
+ enName: string;
27
+ expireTime: string;
28
+ daysToRemain: number;
29
+ remainExpire: boolean;
30
+ licenceId: number;
31
+ productCategory: string;
32
+ validInviteCode: any;
33
+ unLimitedLicence: boolean;
34
+ ultimate: boolean;
35
+ licenceType: string;
36
+ useBalance: number;
37
+ };
38
+ userId: string;
39
+ }
@@ -0,0 +1,130 @@
1
+ import { getCurrentApp } from '../application/manage';
2
+ import ls from '../utils/localstorage';
3
+ import { UserInfo } from './declare';
4
+ import {
5
+ isCredits,
6
+ isEnterprise,
7
+ isFree,
8
+ isPLG,
9
+ isProfessional,
10
+ isSLG,
11
+ } from './version';
12
+
13
+ interface Env {
14
+ AIBOT_URL: string;
15
+ APP_URL: string;
16
+ CHAT_URL: string;
17
+ MOPOWER: string;
18
+ MOPOWER_MICRO: string;
19
+ Shoplazza_URL: string;
20
+ Shopify_URL: string;
21
+ Shopline_URL: string;
22
+ Shopyy_URL: string;
23
+ PRODUCT_URL: string;
24
+ PRODUCT_TYPE_URL: string;
25
+ COLLECTION_URL: string;
26
+ appId: number;
27
+ isProd?: boolean;
28
+ isDev?: boolean;
29
+ isTest?: boolean;
30
+ socketUrl: string;
31
+ }
32
+
33
+ let GlobalUserInfo: UserInfo = {} as any;
34
+
35
+ export const login = (userInfo: UserInfo) => {
36
+ const root = getCurrentApp()?.root;
37
+ if (!getCurrentApp()?.isRoot) {
38
+ console.warn(
39
+ 'quick platform login warn:current App is not Root App. Invalid login!',
40
+ getCurrentApp()
41
+ );
42
+ }
43
+ GlobalUserInfo = userInfo;
44
+ if (root) {
45
+ root?.cache('userinfo', userInfo);
46
+ }
47
+ };
48
+
49
+ const buildSystemGetter = <T>(
50
+ fn: (data: UserInfo) => T
51
+ ): (() => Partial<T>) => {
52
+ return () => {
53
+ const root = getCurrentApp()?.root;
54
+ if (!root) {
55
+ console.warn('quick platform warn:root App not found!!!');
56
+ }
57
+ const userinfo = root?.cache('userinfo');
58
+ if (!userinfo?.userId) {
59
+ console.error('quick platform warn:root App not logged in yet');
60
+ }
61
+ return fn(userinfo || {});
62
+ };
63
+ };
64
+
65
+ const authFunction = buildSystemGetter(userInfo => {
66
+ return userInfo.rightList || [];
67
+ });
68
+
69
+ export const getUserInfo = buildSystemGetter(userInfo => {
70
+ return userInfo.statffInfo || {};
71
+ });
72
+
73
+ export const getStaffInfo = buildSystemGetter(userInfo => {
74
+ return userInfo.staffInfo || {};
75
+ });
76
+
77
+ export const getStoreInfo = buildSystemGetter(userInfo => {
78
+ return userInfo.storeInfo || {};
79
+ });
80
+
81
+ export const getStoreLicense = buildSystemGetter(
82
+ userInfo => userInfo.storeLicenceInfo || {}
83
+ );
84
+
85
+ export const hasAuth = (code: string) => {
86
+ return authFunction().includes(code);
87
+ };
88
+
89
+ export const getSystem = () => {
90
+ const oem = process.env.OEM_NAME;
91
+ const defaultLang = oem ? 'zh-CN' : 'en-US';
92
+ return {
93
+ oem: oem,
94
+ env: process.env.REACT_APP_ENVKEY,
95
+ lang: (ls.getData('qs_lang') || defaultLang) as
96
+ | 'zh-CN'
97
+ | 'en-US'
98
+ | 'ko'
99
+ | 'ja'
100
+ | 'zh-TW',
101
+ token: sessionStorage.getItem('quick-token') || '',
102
+ requestTokenKey: 'quick-token',
103
+ storeId: sessionStorage.getItem('quick-im-storeId') || '',
104
+ };
105
+ };
106
+
107
+ export const getOEMName = () => {
108
+ return (window as any).QUICK_CEP?.oem?.name;
109
+ };
110
+
111
+ const LicenseCreator = (
112
+ fn: (licence: Partial<UserInfo['storeLicenceInfo']>) => boolean
113
+ ) => {
114
+ return () => {
115
+ return fn(getStoreLicense());
116
+ };
117
+ };
118
+
119
+ export const License = {
120
+ isPLG: LicenseCreator(isPLG),
121
+ isSLG: LicenseCreator(isSLG),
122
+ isEnterprise: LicenseCreator(isEnterprise),
123
+ isFree: LicenseCreator(isFree),
124
+ isProfessional: LicenseCreator(isProfessional),
125
+ isCredits: LicenseCreator(isCredits),
126
+ getLicense: getStoreLicense,
127
+ isOEM() {
128
+ return !!getOEMName();
129
+ },
130
+ };
@@ -0,0 +1,58 @@
1
+ import { UserInfo } from './declare';
2
+
3
+ enum ReleaseMap {
4
+ 'Trial' = 1,
5
+ 'Free' = 2,
6
+ 'Basic' = 3,
7
+ 'Professional' = 4,
8
+ 'Ultimate' = 5,
9
+ 'FreeCode' = 13,
10
+ 'Starter' = 14,
11
+ 'Growth' = 15,
12
+ 'Enterprise' = 6,
13
+ }
14
+ //@mark LicenseTypeMap对应storeInfo里面的licenceType
15
+ // storeInfo 里的licenceType与licenceId没有对应关系,不能复用上文ReleaseMap的处理
16
+ enum LicenseTypeMap {
17
+ Enterprise = 'ENTERPRISE', //企业版本
18
+ PLG = 'PLG', // (, "PLG版本"),
19
+ }
20
+
21
+ const PLGList: number[] = [
22
+ ReleaseMap.Free,
23
+ ReleaseMap.FreeCode,
24
+ ReleaseMap.Starter,
25
+ ReleaseMap.Growth,
26
+ ];
27
+
28
+ export const isPLG = (licence: Partial<UserInfo['storeLicenceInfo']>) => {
29
+ if (typeof licence.licenceId === 'undefined') return false;
30
+ return PLGList.includes(licence.licenceId);
31
+ };
32
+
33
+ export const isSLG = (licence: Partial<UserInfo['storeLicenceInfo']>) => {
34
+ return !isPLG(licence);
35
+ };
36
+
37
+ export const isEnterprise = (
38
+ licence: Partial<UserInfo['storeLicenceInfo']>
39
+ ) => {
40
+ return ReleaseMap.Enterprise === licence.licenceId;
41
+ };
42
+
43
+ export const isFree = (licence: Partial<UserInfo['storeLicenceInfo']>) => {
44
+ return ReleaseMap.Free === licence.licenceId;
45
+ };
46
+
47
+ export const isProfessional = (
48
+ licence: Partial<UserInfo['storeLicenceInfo']>
49
+ ) => {
50
+ return ReleaseMap.Professional === licence.licenceId;
51
+ };
52
+
53
+ export const isCredits = (licence: Partial<UserInfo['storeLicenceInfo']>) => {
54
+ return !(
55
+ LicenseTypeMap.Enterprise === licence.licenceType &&
56
+ licence.useBalance === 1
57
+ );
58
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { createFromIconfontCN } from '@ant-design/icons';
3
+ import { IconFontProps } from '@ant-design/icons/lib/components/IconFont';
4
+ const hasInstalled = !!document.getElementById('_CD_ICON_1633');
5
+ const IconFont: React.FC<IconFontProps> = createFromIconfontCN({
6
+ scriptUrl: hasInstalled
7
+ ? ''
8
+ : 'https://front-assets.obs.ap-southeast-3.myhuaweicloud.com/library/icon/icon.js', //https://front-assets.quickcep.com/library/icon/icon.js
9
+ });
10
+
11
+ export default IconFont;
@@ -0,0 +1,244 @@
1
+ import React, { PropsWithChildren, useEffect, useState } from 'react';
2
+ const URls = {
3
+ UserInfoUrl: '/store/user/getUserInfo',
4
+ Login: '/store/user/login',
5
+ StoreList: '/store/store/list',
6
+ ChangeStore: '/store/store/switch',
7
+ };
8
+ import * as Authentication from '../business';
9
+
10
+ const useRequest = (
11
+ http: (...args: any[]) => Promise<any>,
12
+ url: string,
13
+ ...params: any[]
14
+ ) => {
15
+ const [data, setData] = useState<any>();
16
+ const [loading, setLoading] = useState(true);
17
+ const request = () => {
18
+ setLoading(true);
19
+ return http(url, ...params)
20
+ .then(user => {
21
+ setData(user);
22
+ })
23
+ .finally(() => {
24
+ setLoading(false);
25
+ });
26
+ };
27
+ useEffect(() => {
28
+ request();
29
+ }, []);
30
+
31
+ return {
32
+ data,
33
+ loading,
34
+ request,
35
+ setData,
36
+ };
37
+ };
38
+
39
+ const Spining = React.createElement(
40
+ 'div',
41
+ {
42
+ style: {
43
+ width: '100%',
44
+ height: '100&',
45
+ textAlign: 'center',
46
+ fontSize: 40,
47
+ },
48
+ },
49
+ ['微应用本地调试模式初始化中...']
50
+ );
51
+
52
+ const valueById = (id: string) => (document.getElementById(id) as any)!.value;
53
+
54
+ const Login: React.FC<{ onLogin(data: any): void }> = props => {
55
+ const login = () => {
56
+ props.onLogin({
57
+ email: valueById('local_debug_account'),
58
+ loginStatus: 2,
59
+ password: valueById('local_debug_password'),
60
+ });
61
+ };
62
+ return React.createElement(
63
+ 'div',
64
+ {
65
+ style: {
66
+ fontSize: 20,
67
+ display: 'flex',
68
+ alignItems: 'center',
69
+ justifyContent: 'center',
70
+ flexDirection: 'column',
71
+ height: '100%',
72
+ },
73
+ },
74
+ [
75
+ React.createElement('div', {}),
76
+ [
77
+ '请先登录:',
78
+ React.createElement('table', {}, [
79
+ React.createElement('tr', {}, [
80
+ React.createElement('td', {}, [
81
+ '帐号:',
82
+ React.createElement('input', {
83
+ id: 'local_debug_account',
84
+ style: { fontSize: 20, width: 400 },
85
+ }),
86
+ ]),
87
+ ]),
88
+ React.createElement('tr', {}, [
89
+ React.createElement('td', {}, [
90
+ '密码:',
91
+ React.createElement('input', {
92
+ id: 'local_debug_password',
93
+ type: 'password',
94
+ style: { fontSize: 20, width: 400 },
95
+ }),
96
+ ]),
97
+ ]),
98
+ React.createElement('tr', {}, [
99
+ React.createElement(
100
+ 'td',
101
+ {
102
+ colSpan: 2,
103
+ },
104
+ [
105
+ React.createElement(
106
+ 'button',
107
+ {
108
+ style: { fontSize: 20, width: '100%' },
109
+ onClickCapture: login,
110
+ },
111
+ ['登录']
112
+ ),
113
+ ]
114
+ ),
115
+ ]),
116
+ ]),
117
+ ],
118
+ ]
119
+ );
120
+ };
121
+
122
+ const Info: React.FC<{
123
+ onLogout(): void;
124
+ post(...args: any[]): Promise<any>;
125
+ }> = ({ post, ...props }) => {
126
+ const store = Authentication.getStoreInfo();
127
+ const staff = Authentication.getStaffInfo();
128
+ const lang = window.localStorage.getItem('quick_local_debug_lang') || 'zh-CN';
129
+ const { data } = useRequest(post, URls.StoreList);
130
+ return React.createElement(
131
+ 'div',
132
+ {
133
+ style: { position: 'fixed', right: 10, bottom: 10, zIndex: 10000 },
134
+ },
135
+ [
136
+ 'quick-platform子应用调试工具:',
137
+ React.createElement('div', { key: 'store' }, [
138
+ React.createElement('span', { style: { float: 'left' } }, [
139
+ `当前店铺:`,
140
+ ]),
141
+ React.createElement(
142
+ 'select',
143
+ {
144
+ style: { fontSize: 16 },
145
+ value: store.id,
146
+ onChange: (e: any) => {
147
+ post(URls.ChangeStore, { storeId: e.target.value })
148
+ .then(data => {
149
+ sessionStorage.setItem('quick-storeId', data.storeId);
150
+ sessionStorage.setItem('quick-token', data.jwt);
151
+ sessionStorage.removeItem('quick-qyWechat');
152
+ console.log(
153
+ '%c [ halvee>]-133',
154
+ 'font-size:13px; background:pink; color:#bf2c9f;',
155
+ data.jwt
156
+ );
157
+ window.location.reload();
158
+ })
159
+ .catch(() => {
160
+ alert('切换店铺失败');
161
+ });
162
+ },
163
+ },
164
+ (data || []).map((item: any) => {
165
+ return React.createElement(
166
+ 'option',
167
+ { value: item.id, key: item.id },
168
+ [item.storeName]
169
+ );
170
+ })
171
+ ),
172
+ ]),
173
+ React.createElement('div', {}, [
174
+ React.createElement('span', { style: { float: 'left' } }, [
175
+ `当前语言:`,
176
+ ]),
177
+ React.createElement(
178
+ 'select',
179
+ {
180
+ style: { fontSize: 16 },
181
+ value: lang,
182
+ onChange(e: any) {
183
+ localStorage.setItem('quick_local_debug_lang', e.target.value);
184
+ window.location.reload();
185
+ },
186
+ },
187
+ ['zh-CN', 'en-US', 'ko', 'ja', 'zh-TW'].map(key => {
188
+ return React.createElement('option', { value: key, key: key }, [
189
+ key,
190
+ ]);
191
+ })
192
+ ),
193
+ ]),
194
+ React.createElement('div', { key: 'user' }, [`当前用户:${staff.email}`]),
195
+ React.createElement(
196
+ 'button',
197
+ {
198
+ onClick() {
199
+ sessionStorage.clear();
200
+ props.onLogout();
201
+ },
202
+ },
203
+ ['退出登录']
204
+ ),
205
+ ]
206
+ );
207
+ };
208
+
209
+ const LocalDebug: React.FC<PropsWithChildren<{
210
+ hideInfo: boolean;
211
+ post(...args: any[]): Promise<any>;
212
+ }>> = ({ post, ...props }) => {
213
+ const { loading, data, setData } = useRequest(post, URls.UserInfoUrl);
214
+ if (loading) return Spining;
215
+ if (!data)
216
+ return React.createElement(Login, {
217
+ onLogin: info => {
218
+ post(URls.Login, info)
219
+ .then(data => {
220
+ Authentication.login(data);
221
+ setData(data);
222
+ })
223
+ .catch(e => {
224
+ alert(e.data.message || '登录失败');
225
+ });
226
+ },
227
+ });
228
+ sessionStorage.setItem('quick-token', data.jwt);
229
+ Authentication.login(data);
230
+ if (props.hideInfo)
231
+ return React.createElement(React.Fragment, {}, props.children);
232
+ return React.createElement(React.Fragment, {}, [
233
+ React.createElement(Info, {
234
+ key: 'info-wrapper',
235
+ post,
236
+ onLogout() {
237
+ setData(null);
238
+ },
239
+ }),
240
+ props.children,
241
+ ]);
242
+ };
243
+
244
+ export default LocalDebug;
@@ -0,0 +1,97 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { getCurrentApp, loadApp } from '../application';
3
+ import { assign } from '../utils/utils';
4
+ import { getSystem } from '../business';
5
+ import events from '../event';
6
+
7
+ const MicroApp: React.FC<{
8
+ name: string;
9
+ extra?: any;
10
+ base?: string;
11
+ env?: string;
12
+ host?: string;
13
+ data?: any;
14
+ className?: string;
15
+ loading?: React.ReactNode;
16
+ entry?: string;
17
+ onMounted?(): void;
18
+ }> = props => {
19
+ const app = useRef<any>();
20
+ const [loading, setLoading] = useState(true);
21
+
22
+ useEffect(() => {
23
+ return () => {
24
+ if (app.current) {
25
+ console.log(props.name, '应用卸载');
26
+ app.current.unmount();
27
+ console.log(props.name, '应用卸载完成');
28
+ }
29
+ };
30
+ }, []);
31
+ useState(() => {
32
+ if (props.data) {
33
+ getCurrentApp().cache(`${props.name}-data`, props.data);
34
+ }
35
+ });
36
+
37
+ useEffect(() => {
38
+ if (props.data) {
39
+ getCurrentApp().cache(`${props.name}-data`, props.data);
40
+ events.broadcast(`${props.name}-data-change`, props.data);
41
+ }
42
+ }, [props.data, props.name]);
43
+
44
+ return React.createElement(
45
+ 'div',
46
+ {
47
+ style: {
48
+ width: '100%',
49
+ height: '100%',
50
+ position: 'relative',
51
+ },
52
+ },
53
+ [
54
+ React.createElement('div', {
55
+ style: { width: '100%', height: '100%' },
56
+ className: props.className,
57
+ ref(instance: any) {
58
+ if (!instance || app.current) return;
59
+ const system = getSystem();
60
+ app.current = loadApp(
61
+ props.name,
62
+ instance,
63
+ Object.assign(
64
+ {},
65
+ props.extra,
66
+ assign('base', props.base),
67
+ assign('host', props.host),
68
+ assign('env', props.env || system.env),
69
+ assign('entry', props.entry)
70
+ )
71
+ );
72
+ app.current.mountPromise.then(() => {
73
+ setLoading(false);
74
+ props.onMounted?.();
75
+ });
76
+ },
77
+ }),
78
+ loading
79
+ ? React.createElement(
80
+ 'div',
81
+ {
82
+ style: {
83
+ width: '100%',
84
+ height: '100%',
85
+ position: 'absolute',
86
+ top: 0,
87
+ left: 0,
88
+ },
89
+ },
90
+ [props.loading]
91
+ )
92
+ : null,
93
+ ]
94
+ );
95
+ };
96
+
97
+ export default MicroApp;
@@ -0,0 +1,13 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+
3
+ import { hasAuth } from '../business';
4
+
5
+ const Permission: React.FC<PropsWithChildren<{
6
+ code: string; // 权限码
7
+ auth?: () => boolean; // 自定义权限检验
8
+ }>> = ({ auth = () => true, ...props }) => {
9
+ if (hasAuth(props.code) && auth()) return props.children as any;
10
+ return null;
11
+ };
12
+
13
+ export default Permission;
@@ -0,0 +1,31 @@
1
+ import React, { useMemo, useState, useEffect } from 'react';
2
+ import { getCurrentApp } from '../application';
3
+ import events from '../event';
4
+
5
+ const AppContext = React.createContext({ data: null as any });
6
+
7
+ export const useAppData = () => React.useContext(AppContext).data;
8
+
9
+ export const App: React.FC<any> = props => {
10
+ const app = getCurrentApp();
11
+ const [data, setData] = useState(app.parent?.cache(`${app.name}-data`));
12
+ useEffect(() => {
13
+ const update = (data: any) => {
14
+ setData(data);
15
+ };
16
+ events.on(`${app.name}-data-change`, update);
17
+ return () => {
18
+ events.off(`${app.name}-data-change`, update);
19
+ };
20
+ }, [app.name]);
21
+ const value = useMemo(() => {
22
+ return { data };
23
+ }, [data]);
24
+ return React.createElement(
25
+ AppContext.Provider,
26
+ {
27
+ value,
28
+ },
29
+ [props.children]
30
+ );
31
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ const I18nFC = (text: string, data?: Record<string, any>) => {
3
+ if (!data) return text;
4
+ const list: React.ReactNode[] = [];
5
+ let prev = 0;
6
+ text.replace(/\{[a-zA-Z_0-9]*\}/g, (match, index) => {
7
+ const prevText = text.slice(prev, index);
8
+ list.push(prevText);
9
+ list.push(data[match.slice(1, -1)]);
10
+ prev = index + match.length;
11
+ return '';
12
+ });
13
+ list.push(text.slice(prev, text.length));
14
+ return React.createElement(React.Fragment, {}, list as any);
15
+ };
16
+
17
+ export default I18nFC;
package/src/config.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { UnoConfig } from './theme/uno';
2
+
3
+ export { UnoConfig };
package/src/event.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { getCurrentApp } from './application/manage';
2
+
3
+ const events = {
4
+ /**
5
+ *向父级发送事件
6
+ */
7
+ trigger(name: string, data: any) {
8
+ getCurrentApp()?.trigger(name, data);
9
+ },
10
+ /**
11
+ *向子级发送事件
12
+ */
13
+ broadcast(name: string, data: any) {
14
+ getCurrentApp()?.broadcast(name, data);
15
+ },
16
+ on(name: string, handler: (...args: any[]) => void) {
17
+ getCurrentApp()?.on(name, handler);
18
+ },
19
+ off(name: string, handler: (...args: any[]) => void) {
20
+ getCurrentApp()?.off(name, handler);
21
+ },
22
+ };
23
+
24
+ export default events;