@tuya-sat/micro-script 3.3.8 → 3.3.10
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/dist/apis/template.ts +30 -0
- package/dist/bin/cli.js +0 -0
- package/dist/template/main-app/index.tsx +8 -0
- package/dist/template/main-app/utils.ts +59 -0
- package/dist/template/micro-app/antdLang.ts +235 -0
- package/dist/template/micro-app/index.css +26 -0
- package/dist/template/micro-app/index.tsx +66 -0
- package/dist/template/micro-app/interfaces.ts +62 -0
- package/dist/template/micro-app/lang.ts +16 -0
- package/dist/template/micro-app/public-path.js +4 -0
- package/dist/template/multi-micro-app/index.css +25 -0
- package/dist/template/multi-micro-app/index.tsx +63 -0
- package/dist/template/multi-micro-app/interfaces.ts +61 -0
- package/dist/template/multi-micro-app/public-path.js +4 -0
- package/package.json +6 -7
- package/dist/utils/filterLoaderInRule.d.ts +0 -7
- package/dist/utils/filterLoaderInRule.js +0 -21
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosResponse, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { message } from 'antd';
|
|
3
|
+
|
|
4
|
+
const api = axios.create();
|
|
5
|
+
|
|
6
|
+
api.interceptors.request.use(
|
|
7
|
+
(config: AxiosRequestConfig) => {
|
|
8
|
+
config.headers = {
|
|
9
|
+
...config.headers,
|
|
10
|
+
'Content-Type': 'application/json;charset=utf-8',
|
|
11
|
+
};
|
|
12
|
+
return config;
|
|
13
|
+
},
|
|
14
|
+
(error: Error) => Promise.reject(error)
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
api.interceptors.response.use(
|
|
18
|
+
(response: AxiosResponse<any>) => {
|
|
19
|
+
const res = response.data;
|
|
20
|
+
if (!res.success) {
|
|
21
|
+
message.error(res.msg);
|
|
22
|
+
return Promise.reject(res);
|
|
23
|
+
}
|
|
24
|
+
return res;
|
|
25
|
+
},
|
|
26
|
+
(error: Error) => Promise.reject(error)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
//根据 manifest apis生产微应用可以直接使用的
|
|
30
|
+
export const apis = {};
|
package/dist/bin/cli.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '@tuya-sat/sdf-main-sdk/dist/main.css';
|
|
2
|
+
import 'react';
|
|
3
|
+
import { bootStrapSDF } from '@tuya-sat/sdf-main-sdk';
|
|
4
|
+
import { reWriteUI } from './utils';
|
|
5
|
+
import lang from '../../src/lang';
|
|
6
|
+
import hooks from '../../src/hooks';
|
|
7
|
+
|
|
8
|
+
bootStrapSDF({ lang, hooks, ui: reWriteUI() });
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { IUI } from '@tuya-sat/sdf-main-sdk';
|
|
2
|
+
|
|
3
|
+
const bindCmp = (result, cmp, name) => {
|
|
4
|
+
cmp.keys().forEach((key) => {
|
|
5
|
+
if (key.includes('index.tsx')) {
|
|
6
|
+
result[name] = cmp(key).default;
|
|
7
|
+
} else {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const reWriteUI = () => {
|
|
14
|
+
const result = { pages: {} };
|
|
15
|
+
const pages = (require as any).context(
|
|
16
|
+
'../../src/pages',
|
|
17
|
+
true,
|
|
18
|
+
/\.([tj]sx)|[tj]s$/
|
|
19
|
+
);
|
|
20
|
+
pages.keys().forEach((key) => {
|
|
21
|
+
if (key.includes('index.tsx')) {
|
|
22
|
+
const name = key.split('/')[1];
|
|
23
|
+
result.pages[name.charAt(0).toUpperCase() + name.slice(1)] =
|
|
24
|
+
pages(key).default;
|
|
25
|
+
} else {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const bdb = (require as any).context(
|
|
31
|
+
'../../src/bdb',
|
|
32
|
+
true,
|
|
33
|
+
/\.([tj]sx)|[tj]s$/
|
|
34
|
+
);
|
|
35
|
+
bindCmp(result, bdb, 'bdb');
|
|
36
|
+
|
|
37
|
+
const menu = (require as any).context(
|
|
38
|
+
'../../src/menu',
|
|
39
|
+
true,
|
|
40
|
+
/\.([tj]sx)|[tj]s$/
|
|
41
|
+
);
|
|
42
|
+
bindCmp(result, menu, 'menu');
|
|
43
|
+
|
|
44
|
+
const nav = (require as any).context(
|
|
45
|
+
'../../src/nav',
|
|
46
|
+
true,
|
|
47
|
+
/\.([tj]sx)|[tj]s$/
|
|
48
|
+
);
|
|
49
|
+
bindCmp(result, nav, 'nav');
|
|
50
|
+
|
|
51
|
+
const layout = (require as any).context(
|
|
52
|
+
'../../src',
|
|
53
|
+
true,
|
|
54
|
+
/\.\/layout\/.*\.([tj]sx?)$/
|
|
55
|
+
);
|
|
56
|
+
bindCmp(result, layout, 'layout');
|
|
57
|
+
|
|
58
|
+
return result as IUI;
|
|
59
|
+
};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import en_US from 'antd/lib/locale/en_US.js';
|
|
4
|
+
const ar_EG = () => import('antd/lib/locale/ar_EG.js');
|
|
5
|
+
const az_AZ = () => import('antd/lib/locale/az_AZ.js');
|
|
6
|
+
const bg_BG = () => import('antd/lib/locale/bg_BG.js');
|
|
7
|
+
const bn_BD = () => import('antd/lib/locale/bn_BD.js');
|
|
8
|
+
const by_BY = () => import('antd/lib/locale/by_BY.js');
|
|
9
|
+
const ca_ES = () => import('antd/lib/locale/ca_ES.js');
|
|
10
|
+
const cs_CZ = () => import('antd/lib/locale/cs_CZ.js');
|
|
11
|
+
const da_DK = () => import('antd/lib/locale/da_DK.js');
|
|
12
|
+
const de_DE = () => import('antd/lib/locale/de_DE.js');
|
|
13
|
+
//const default = () => import ('antd/lib/locale/default.js');
|
|
14
|
+
const el_GR = () => import('antd/lib/locale/el_GR.js');
|
|
15
|
+
const en_GB = () => import('antd/lib/locale/en_GB.js');
|
|
16
|
+
const es_ES = () => import('antd/lib/locale/es_ES.js');
|
|
17
|
+
const et_EE = () => import('antd/lib/locale/et_EE.js');
|
|
18
|
+
const fa_IR = () => import('antd/lib/locale/fa_IR.js');
|
|
19
|
+
const fi_FI = () => import('antd/lib/locale/fi_FI.js');
|
|
20
|
+
const fr_BE = () => import('antd/lib/locale/fr_BE.js');
|
|
21
|
+
const fr_CA = () => import('antd/lib/locale/fr_CA.js');
|
|
22
|
+
const fr_FR = () => import('antd/lib/locale/fr_FR.js');
|
|
23
|
+
const ga_IE = () => import('antd/lib/locale/ga_IE.js');
|
|
24
|
+
const gl_ES = () => import('antd/lib/locale/gl_ES.js');
|
|
25
|
+
const he_IL = () => import('antd/lib/locale/he_IL.js');
|
|
26
|
+
const hi_IN = () => import('antd/lib/locale/hi_IN.js');
|
|
27
|
+
const hr_HR = () => import('antd/lib/locale/hr_HR.js');
|
|
28
|
+
const hu_HU = () => import('antd/lib/locale/hu_HU.js');
|
|
29
|
+
const hy_AM = () => import('antd/lib/locale/hy_AM.js');
|
|
30
|
+
const id_ID = () => import('antd/lib/locale/id_ID.js');
|
|
31
|
+
const is_IS = () => import('antd/lib/locale/is_IS.js');
|
|
32
|
+
const it_IT = () => import('antd/lib/locale/it_IT.js');
|
|
33
|
+
const ja_JP = () => import('antd/lib/locale/ja_JP.js');
|
|
34
|
+
const ka_GE = () => import('antd/lib/locale/ka_GE.js');
|
|
35
|
+
const kk_KZ = () => import('antd/lib/locale/kk_KZ.js');
|
|
36
|
+
const km_KH = () => import('antd/lib/locale/km_KH.js');
|
|
37
|
+
const kmr_IQ = () => import('antd/lib/locale/kmr_IQ.js');
|
|
38
|
+
const kn_IN = () => import('antd/lib/locale/kn_IN.js');
|
|
39
|
+
const ko_KR = () => import('antd/lib/locale/ko_KR.js');
|
|
40
|
+
const ku_IQ = () => import('antd/lib/locale/ku_IQ.js');
|
|
41
|
+
const lt_LT = () => import('antd/lib/locale/lt_LT.js');
|
|
42
|
+
const lv_LV = () => import('antd/lib/locale/lv_LV.js');
|
|
43
|
+
const mk_MK = () => import('antd/lib/locale/mk_MK.js');
|
|
44
|
+
const ml_IN = () => import('antd/lib/locale/ml_IN.js');
|
|
45
|
+
const mn_MN = () => import('antd/lib/locale/mn_MN.js');
|
|
46
|
+
const ms_MY = () => import('antd/lib/locale/ms_MY.js');
|
|
47
|
+
const nb_NO = () => import('antd/lib/locale/nb_NO.js');
|
|
48
|
+
const ne_NP = () => import('antd/lib/locale/ne_NP.js');
|
|
49
|
+
const nl_BE = () => import('antd/lib/locale/nl_BE.js');
|
|
50
|
+
const nl_NL = () => import('antd/lib/locale/nl_NL.js');
|
|
51
|
+
const pl_PL = () => import('antd/lib/locale/pl_PL.js');
|
|
52
|
+
const pt_BR = () => import('antd/lib/locale/pt_BR.js');
|
|
53
|
+
const pt_PT = () => import('antd/lib/locale/pt_PT.js');
|
|
54
|
+
const ro_RO = () => import('antd/lib/locale/ro_RO.js');
|
|
55
|
+
const ru_RU = () => import('antd/lib/locale/ru_RU.js');
|
|
56
|
+
const sk_SK = () => import('antd/lib/locale/sk_SK.js');
|
|
57
|
+
const sl_SI = () => import('antd/lib/locale/sl_SI.js');
|
|
58
|
+
const sr_RS = () => import('antd/lib/locale/sr_RS.js');
|
|
59
|
+
const sv_SE = () => import('antd/lib/locale/sv_SE.js');
|
|
60
|
+
const ta_IN = () => import('antd/lib/locale/ta_IN.js');
|
|
61
|
+
const th_TH = () => import('antd/lib/locale/th_TH.js');
|
|
62
|
+
const tr_TR = () => import('antd/lib/locale/tr_TR.js');
|
|
63
|
+
const uk_UA = () => import('antd/lib/locale/uk_UA.js');
|
|
64
|
+
const ur_PK = () => import('antd/lib/locale/ur_PK.js');
|
|
65
|
+
const vi_VN = () => import('antd/lib/locale/vi_VN.js');
|
|
66
|
+
const zh_CN = () => import('antd/lib/locale/zh_CN.js');
|
|
67
|
+
const zh_HK = () => import('antd/lib/locale/zh_HK.js');
|
|
68
|
+
const zh_TW = () => import('antd/lib/locale/zh_TW.js');
|
|
69
|
+
|
|
70
|
+
const antdLang = {
|
|
71
|
+
"ar_EG": ar_EG,
|
|
72
|
+
"az_AZ": az_AZ,
|
|
73
|
+
"bg_BG": bg_BG,
|
|
74
|
+
"bn_BD": bn_BD,
|
|
75
|
+
"by_BY": by_BY,
|
|
76
|
+
"ca_ES": ca_ES,
|
|
77
|
+
"cs_CZ": cs_CZ,
|
|
78
|
+
"da_DK": da_DK,
|
|
79
|
+
"de_DE": de_DE,
|
|
80
|
+
//"default":default,
|
|
81
|
+
"el_GR": el_GR,
|
|
82
|
+
"en_GB": en_GB,
|
|
83
|
+
"en_US": en_US,
|
|
84
|
+
"es_ES": es_ES,
|
|
85
|
+
"et_EE": et_EE,
|
|
86
|
+
"fa_IR": fa_IR,
|
|
87
|
+
"fi_FI": fi_FI,
|
|
88
|
+
"fr_BE": fr_BE,
|
|
89
|
+
"fr_CA": fr_CA,
|
|
90
|
+
"fr_FR": fr_FR,
|
|
91
|
+
"ga_IE": ga_IE,
|
|
92
|
+
"gl_ES": gl_ES,
|
|
93
|
+
"he_IL": he_IL,
|
|
94
|
+
"hi_IN": hi_IN,
|
|
95
|
+
"hr_HR": hr_HR,
|
|
96
|
+
"hu_HU": hu_HU,
|
|
97
|
+
"hy_AM": hy_AM,
|
|
98
|
+
"id_ID": id_ID,
|
|
99
|
+
"is_IS": is_IS,
|
|
100
|
+
"it_IT": it_IT,
|
|
101
|
+
"ja_JP": ja_JP,
|
|
102
|
+
"ka_GE": ka_GE,
|
|
103
|
+
"kk_KZ": kk_KZ,
|
|
104
|
+
"km_KH": km_KH,
|
|
105
|
+
"kmr_IQ": kmr_IQ,
|
|
106
|
+
"kn_IN": kn_IN,
|
|
107
|
+
"ko_KR": ko_KR,
|
|
108
|
+
"ku_IQ": ku_IQ,
|
|
109
|
+
"lt_LT": lt_LT,
|
|
110
|
+
"lv_LV": lv_LV,
|
|
111
|
+
"mk_MK": mk_MK,
|
|
112
|
+
"ml_IN": ml_IN,
|
|
113
|
+
"mn_MN": mn_MN,
|
|
114
|
+
"ms_MY": ms_MY,
|
|
115
|
+
"nb_NO": nb_NO,
|
|
116
|
+
"ne_NP": ne_NP,
|
|
117
|
+
"nl_BE": nl_BE,
|
|
118
|
+
"nl_NL": nl_NL,
|
|
119
|
+
"pl_PL": pl_PL,
|
|
120
|
+
"pt_BR": pt_BR,
|
|
121
|
+
"pt_PT": pt_PT,
|
|
122
|
+
"ro_RO": ro_RO,
|
|
123
|
+
"ru_RU": ru_RU,
|
|
124
|
+
"sk_SK": sk_SK,
|
|
125
|
+
"sl_SI": sl_SI,
|
|
126
|
+
"sr_RS": sr_RS,
|
|
127
|
+
"sv_SE": sv_SE,
|
|
128
|
+
"ta_IN": ta_IN,
|
|
129
|
+
"th_TH": th_TH,
|
|
130
|
+
"tr_TR": tr_TR,
|
|
131
|
+
"uk_UA": uk_UA,
|
|
132
|
+
"ur_PK": ur_PK,
|
|
133
|
+
"vi_VN": vi_VN,
|
|
134
|
+
"zh_CN": zh_CN,
|
|
135
|
+
"zh_HK": zh_HK,
|
|
136
|
+
"zh_TW": zh_TW,
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
const localizeToPrincipleMap: Record<string, keyof typeof antdLang | ""> = {
|
|
140
|
+
"zh": "zh_CN",
|
|
141
|
+
"zh_tw": "zh_TW",
|
|
142
|
+
"en": "en_US",
|
|
143
|
+
"de": "de_DE",
|
|
144
|
+
"it": "it_IT",
|
|
145
|
+
"es": "es_ES",
|
|
146
|
+
"fr": "fr_FR",
|
|
147
|
+
"ja": "ja_JP",
|
|
148
|
+
"ko": "ko_KR",
|
|
149
|
+
"he": "he_IL",
|
|
150
|
+
"pt": "pt_PT",
|
|
151
|
+
"th": "th_TH",
|
|
152
|
+
"ru": "ru_RU",
|
|
153
|
+
"el": "el_GR",
|
|
154
|
+
"pl": "pl_PL",
|
|
155
|
+
"id": "id_ID",
|
|
156
|
+
"ms": "ms_MY",
|
|
157
|
+
"ar": "ar_EG",
|
|
158
|
+
"bg": "bg_BG",
|
|
159
|
+
"cs": "cs_CZ",
|
|
160
|
+
"nl": "nl_NL",
|
|
161
|
+
"tr": "tr_TR",
|
|
162
|
+
"hu": "hu_HU",
|
|
163
|
+
"vi": "vi_VN",
|
|
164
|
+
"kk": "kk_KZ",
|
|
165
|
+
"no": "nb_NO",
|
|
166
|
+
"da": "da_DK",
|
|
167
|
+
"fi": "fi_FI",
|
|
168
|
+
"sv": "sv_SE",
|
|
169
|
+
"ro": "ro_RO",
|
|
170
|
+
"hi": "hi_IN",
|
|
171
|
+
"uk": "uk_UA",
|
|
172
|
+
"sk": "sk_SK",
|
|
173
|
+
"bn": "bn_BD",
|
|
174
|
+
"ur": "ur_PK",
|
|
175
|
+
"uz": "",
|
|
176
|
+
"ug": "",
|
|
177
|
+
"mn": "mn_MN",
|
|
178
|
+
"mk": "mk_MK",
|
|
179
|
+
"tl": "",
|
|
180
|
+
"hr": "hr_HR",
|
|
181
|
+
"my": "",
|
|
182
|
+
"lt": "lt_LT",
|
|
183
|
+
"sr": "sr_RS",
|
|
184
|
+
"sl": "sl_SI",
|
|
185
|
+
"et": "et_EE",
|
|
186
|
+
"lv": "lv_LV",
|
|
187
|
+
"lo": "",
|
|
188
|
+
"ha": "",
|
|
189
|
+
"fa": "fa_IR",
|
|
190
|
+
"bs": "",
|
|
191
|
+
"ne": "ne_NP",
|
|
192
|
+
"la": "",
|
|
193
|
+
"sw": "",
|
|
194
|
+
"te": "",
|
|
195
|
+
"mr": "",
|
|
196
|
+
"be": "by_BY",
|
|
197
|
+
"rw": "",
|
|
198
|
+
"xh": "",
|
|
199
|
+
"az": "az_AZ",
|
|
200
|
+
"ks": "",
|
|
201
|
+
"jv": "",
|
|
202
|
+
"ta": "ta_IN",
|
|
203
|
+
"gu": "",
|
|
204
|
+
"en_GB": "en_GB",
|
|
205
|
+
"zh_Hant_HK": "zh_HK",
|
|
206
|
+
"pt_BR": "pt_BR",
|
|
207
|
+
"es_419": "",
|
|
208
|
+
"hy": "hy_AM"
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
type LangKey = keyof typeof localizeToPrincipleMap;
|
|
212
|
+
|
|
213
|
+
async function getThirdLang(key: LangKey) {
|
|
214
|
+
const keyOfAntd = localizeToPrincipleMap[key];
|
|
215
|
+
if (!keyOfAntd || keyOfAntd === 'en_US') {
|
|
216
|
+
return antdLang.en_US
|
|
217
|
+
}
|
|
218
|
+
return antdLang[keyOfAntd]().catch(() => antdLang.en_US);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function useAntdLang(langKey: string) {
|
|
222
|
+
const [antdLang, setAntdLang] = useState({
|
|
223
|
+
loading: true,
|
|
224
|
+
lang: {},
|
|
225
|
+
});
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
getThirdLang(langKey).then((lang: any) => {
|
|
228
|
+
setAntdLang({
|
|
229
|
+
lang: lang.default,
|
|
230
|
+
loading: false,
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}, []);
|
|
234
|
+
return antdLang as any;
|
|
235
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
body {
|
|
2
|
+
margin: 0;
|
|
3
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
|
|
4
|
+
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
|
|
5
|
+
-webkit-font-smoothing: antialiased;
|
|
6
|
+
-moz-osx-font-smoothing: grayscale;
|
|
7
|
+
background-color: transparent !important;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
code {
|
|
11
|
+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#root {
|
|
15
|
+
height: 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.layout {
|
|
19
|
+
margin-bottom: 20px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.square {
|
|
23
|
+
width: 20px;
|
|
24
|
+
height: 20px;
|
|
25
|
+
}
|
|
26
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import './public-path';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { BrowserRouter } from 'react-router-dom';
|
|
4
|
+
import { getI18n } from 'react-i18next';
|
|
5
|
+
import { message } from 'antd';
|
|
6
|
+
import { CaptureContext, Event, Severity } from '@sentry/types';
|
|
7
|
+
import { IQiankunProps } from './interfaces';
|
|
8
|
+
import App from './App';
|
|
9
|
+
import './lang';
|
|
10
|
+
import './index.css';
|
|
11
|
+
import './styles/global.less';
|
|
12
|
+
export * from './interfaces';
|
|
13
|
+
export * from './antdLang';
|
|
14
|
+
export * from './api';
|
|
15
|
+
export let microProps: IQiankunProps;
|
|
16
|
+
|
|
17
|
+
function render(props: IQiankunProps) {
|
|
18
|
+
const { base, container } = props as IQiankunProps;
|
|
19
|
+
const root = (
|
|
20
|
+
container
|
|
21
|
+
? container.querySelector('#root')
|
|
22
|
+
: document.querySelector('#root')
|
|
23
|
+
) as HTMLElement;
|
|
24
|
+
message.config({
|
|
25
|
+
getContainer: () => root,
|
|
26
|
+
});
|
|
27
|
+
ReactDOM.render(
|
|
28
|
+
<BrowserRouter basename={window.__POWERED_BY_QIANKUN__ ? base : '/'}>
|
|
29
|
+
<App {...props} />
|
|
30
|
+
</BrowserRouter>,
|
|
31
|
+
root
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!window.__POWERED_BY_QIANKUN__) {
|
|
36
|
+
render({} as IQiankunProps);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function bootstrap() {
|
|
40
|
+
console.log('子应用启动');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function mount(props: IQiankunProps) {
|
|
44
|
+
console.log('挂载子应用', props);
|
|
45
|
+
props.langResource && replaceLangResource(props.langResource);
|
|
46
|
+
getI18n().changeLanguage(props.tyLang);
|
|
47
|
+
microProps = props;
|
|
48
|
+
render(props);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function unmount(props: IQiankunProps) {
|
|
52
|
+
const { container } = props;
|
|
53
|
+
message.destroy();
|
|
54
|
+
const root = (
|
|
55
|
+
container
|
|
56
|
+
? container.querySelector('#root')
|
|
57
|
+
: document.querySelector('#root')
|
|
58
|
+
) as HTMLElement;
|
|
59
|
+
ReactDOM.unmountComponentAtNode(root);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function replaceLangResource(langResource: any) {
|
|
63
|
+
Object.keys(langResource).forEach((langkey) => {
|
|
64
|
+
getI18n().addResourceBundle(langkey, 'translation', langResource[langkey]);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CaptureContext, Event, Severity } from '@sentry/types';
|
|
2
|
+
|
|
3
|
+
type IState = { [k in string]: string | number | null };
|
|
4
|
+
interface mainHistory {
|
|
5
|
+
push: (path: string, state?: IState) => void;
|
|
6
|
+
replace: (path: string, state?: IState) => void;
|
|
7
|
+
go: (n: number) => void;
|
|
8
|
+
goBack: () => void;
|
|
9
|
+
goForward: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface DynamicProps {
|
|
13
|
+
setBreadcrumb: SetBreadcrumb;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface SetBreadcrumb {
|
|
18
|
+
(breadcrumbInfos?: BreadcrumbInfoInput[]): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type BreadcrumbInfoInput =
|
|
22
|
+
| {
|
|
23
|
+
type: 'auto' | 'root';
|
|
24
|
+
name?: never;
|
|
25
|
+
path?: never;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
type: 'menu';
|
|
29
|
+
name?: never;
|
|
30
|
+
path: string;
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
type: 'c';
|
|
34
|
+
name: string;
|
|
35
|
+
path: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export interface IQiankunProps {
|
|
39
|
+
base: string;
|
|
40
|
+
container: HTMLElement; // 子应用所在容器
|
|
41
|
+
dynamicProps: DynamicProps; // 面包屑
|
|
42
|
+
getOwnMenu: () => { entry_name: string }; // 获取当前选中菜单
|
|
43
|
+
hasPermission: (permissionCode: string) => boolean;
|
|
44
|
+
isSupportMobile: boolean; // 是否支持移动端
|
|
45
|
+
mainHistory: mainHistory; // 用于微应用间跳转
|
|
46
|
+
modifySelectedMenu: () => void; //
|
|
47
|
+
region: 'tx' | 'us' | 'eu' | 'in' | 'ueaz' | 'we' | 'sea';
|
|
48
|
+
resourcePrefix: string; // 静态资源地址
|
|
49
|
+
sentry: {
|
|
50
|
+
captureEvent: (event: Event) => string;
|
|
51
|
+
captureMessage: (
|
|
52
|
+
message: string,
|
|
53
|
+
captureContext?: CaptureContext | Severity
|
|
54
|
+
) => string;
|
|
55
|
+
captureException: (
|
|
56
|
+
exception: any,
|
|
57
|
+
captureContext?: CaptureContext
|
|
58
|
+
) => string;
|
|
59
|
+
};
|
|
60
|
+
tyLang: 'zh' | 'en'; // 当前语言
|
|
61
|
+
langResource: any;
|
|
62
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import i18n from 'i18next';
|
|
2
|
+
import { initReactI18next } from 'react-i18next';
|
|
3
|
+
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
4
|
+
import en from './en.json';
|
|
5
|
+
import zh from './zh.json';
|
|
6
|
+
|
|
7
|
+
i18n
|
|
8
|
+
.use(LanguageDetector)
|
|
9
|
+
.use(initReactI18next)
|
|
10
|
+
.init({
|
|
11
|
+
resources: { en: { translation: en }, zh: { translation: zh } },
|
|
12
|
+
fallbackLng: 'en',
|
|
13
|
+
interpolation: {
|
|
14
|
+
escapeValue: false,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
body {
|
|
2
|
+
margin: 0;
|
|
3
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
|
|
4
|
+
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
|
|
5
|
+
-webkit-font-smoothing: antialiased;
|
|
6
|
+
-moz-osx-font-smoothing: grayscale;
|
|
7
|
+
background-color: transparent !important;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
code {
|
|
11
|
+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#root {
|
|
15
|
+
height: 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.layout {
|
|
19
|
+
margin-bottom: 20px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.square {
|
|
23
|
+
width: 20px;
|
|
24
|
+
height: 20px;
|
|
25
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import './public-path';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { BrowserRouter } from 'react-router-dom';
|
|
4
|
+
import { getI18n } from 'react-i18next';
|
|
5
|
+
import { message } from 'antd';
|
|
6
|
+
import { IQiankunProps } from './interfaces';
|
|
7
|
+
import App from './App';
|
|
8
|
+
import './lang';
|
|
9
|
+
import './index.css';
|
|
10
|
+
import 'theme';
|
|
11
|
+
|
|
12
|
+
export let microProps: IQiankunProps;
|
|
13
|
+
|
|
14
|
+
function render(props: IQiankunProps) {
|
|
15
|
+
const { base, container } = props as IQiankunProps;
|
|
16
|
+
const root = (
|
|
17
|
+
container
|
|
18
|
+
? container.querySelector('#root')
|
|
19
|
+
: document.querySelector('#root')
|
|
20
|
+
) as HTMLElement;
|
|
21
|
+
message.config({
|
|
22
|
+
getContainer: () => root,
|
|
23
|
+
});
|
|
24
|
+
ReactDOM.render(
|
|
25
|
+
<BrowserRouter basename={window.__POWERED_BY_QIANKUN__ ? base : '/'}>
|
|
26
|
+
<App {...props} />
|
|
27
|
+
</BrowserRouter>,
|
|
28
|
+
root
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!window.__POWERED_BY_QIANKUN__) {
|
|
33
|
+
render({} as IQiankunProps);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function bootstrap() {
|
|
37
|
+
console.log('子应用启动');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function mount(props: IQiankunProps) {
|
|
41
|
+
console.log('挂载子应用', props);
|
|
42
|
+
props.langResource && replaceLangResource(props.langResource);
|
|
43
|
+
getI18n().changeLanguage(props.tyLang);
|
|
44
|
+
microProps = props;
|
|
45
|
+
render(props);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function unmount(props: IQiankunProps) {
|
|
49
|
+
const { container } = props;
|
|
50
|
+
message.destroy();
|
|
51
|
+
const root = (
|
|
52
|
+
container
|
|
53
|
+
? container.querySelector('#root')
|
|
54
|
+
: document.querySelector('#root')
|
|
55
|
+
) as HTMLElement;
|
|
56
|
+
ReactDOM.unmountComponentAtNode(root);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function replaceLangResource(langResource: any) {
|
|
60
|
+
Object.keys(langResource).forEach((langkey) => {
|
|
61
|
+
getI18n().addResourceBundle(langkey, 'translation', langResource[langkey]);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CaptureContext, Event, Severity } from '@sentry/types';
|
|
2
|
+
|
|
3
|
+
interface mainHistory {
|
|
4
|
+
push: (path, state?) => void;
|
|
5
|
+
replace: (path, state?) => void;
|
|
6
|
+
go: (n: number) => void;
|
|
7
|
+
goBack: () => void;
|
|
8
|
+
goForward: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface DynamicProps {
|
|
12
|
+
setBreadcrumb: SetBreadcrumb;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface SetBreadcrumb {
|
|
17
|
+
(breadcrumbInfos?: BreadcrumbInfoInput[]): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type BreadcrumbInfoInput =
|
|
21
|
+
| {
|
|
22
|
+
type: 'auto' | 'root';
|
|
23
|
+
name?: never;
|
|
24
|
+
path?: never;
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
type: 'menu';
|
|
28
|
+
name?: never;
|
|
29
|
+
path: string;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
type: 'c';
|
|
33
|
+
name: string;
|
|
34
|
+
path: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export interface IQiankunProps {
|
|
38
|
+
base: string;
|
|
39
|
+
container: HTMLElement; // 子应用所在容器
|
|
40
|
+
dynamicProps: DynamicProps; // 面包屑
|
|
41
|
+
getOwnMenu: () => { entry_name: string }; // 获取当前选中菜单
|
|
42
|
+
hasPermission: (permissionCode: string) => boolean;
|
|
43
|
+
isSupportMobile: boolean; // 是否支持移动端
|
|
44
|
+
mainHistory: mainHistory; // 用于微应用间跳转
|
|
45
|
+
modifySelectedMenu: () => void; //
|
|
46
|
+
region: 'tx' | 'us' | 'eu' | 'in' | 'ueaz' | 'we' | 'sea';
|
|
47
|
+
resourcePrefix: string; // 静态资源地址
|
|
48
|
+
sentry: {
|
|
49
|
+
captureEvent: (event: Event) => string;
|
|
50
|
+
captureMessage: (
|
|
51
|
+
message: string,
|
|
52
|
+
captureContext?: CaptureContext | Severity
|
|
53
|
+
) => string;
|
|
54
|
+
captureException: (
|
|
55
|
+
exception: any,
|
|
56
|
+
captureContext?: CaptureContext
|
|
57
|
+
) => string;
|
|
58
|
+
};
|
|
59
|
+
tyLang: 'zh' | 'en'; // 当前语言
|
|
60
|
+
langResource: any;
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.10",
|
|
4
4
|
"bin": "./dist/bin/cli.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"dev": "rm -rf dist/ && tsc --watch",
|
|
14
14
|
"build": "rm -rf dist/ && tsc && node ./scripts/copyTemplate.js",
|
|
15
|
-
"prepublish": "yarn build"
|
|
16
|
-
"ci:publish": "NPM_TOKEN=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 npm publish"
|
|
15
|
+
"prepublish": "yarn build"
|
|
17
16
|
},
|
|
18
17
|
"dependencies": {
|
|
19
18
|
"@babel/core": "7.17.8",
|
|
@@ -24,9 +23,9 @@
|
|
|
24
23
|
"@babel/preset-typescript": "7.16.7",
|
|
25
24
|
"@babel/traverse": "^7.20.13",
|
|
26
25
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
|
|
27
|
-
"@tuya-sat/micro-dev-loader": "
|
|
28
|
-
"@tuya-sat/micro-dev-proxy": "
|
|
29
|
-
"@tuya-sat/micro-utils": "
|
|
26
|
+
"@tuya-sat/micro-dev-loader": "3.3.10",
|
|
27
|
+
"@tuya-sat/micro-dev-proxy": "3.3.10",
|
|
28
|
+
"@tuya-sat/micro-utils": "3.3.10",
|
|
30
29
|
"@types/kill-port": "^2.0.0",
|
|
31
30
|
"babel-loader": "8.2.4",
|
|
32
31
|
"babel-plugin-import": "1.13.3",
|
|
@@ -94,4 +93,4 @@
|
|
|
94
93
|
"cloud",
|
|
95
94
|
"tuya"
|
|
96
95
|
]
|
|
97
|
-
}
|
|
96
|
+
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ModuleOptions } from "webpack";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param loaderName loader的名字
|
|
5
|
-
* @param ruleConfig webpack内的rule项的config
|
|
6
|
-
*/
|
|
7
|
-
export declare function filterRulesWithLoader(loaderName: string, ruleConfig: ModuleOptions["rules"]): (false | "" | 0 | import("webpack").RuleSetRule | "...")[];
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.filterRulesWithLoader = void 0;
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param loaderName loader的名字
|
|
7
|
-
* @param ruleConfig webpack内的rule项的config
|
|
8
|
-
*/
|
|
9
|
-
function filterRulesWithLoader(loaderName, ruleConfig) {
|
|
10
|
-
return ruleConfig.filter((rule) => {
|
|
11
|
-
if (rule !== "..." && rule.use instanceof Array) {
|
|
12
|
-
for (const useItem of rule.use) {
|
|
13
|
-
if (typeof useItem === "object" && useItem.loader === loaderName) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
exports.filterRulesWithLoader = filterRulesWithLoader;
|