@steedos/service-plugin-amis 3.0.0-beta.113 → 3.0.0-beta.116
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.
|
@@ -33,386 +33,4 @@
|
|
|
33
33
|
console.error(error)
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
const getAmisLng = ()=>{
|
|
37
|
-
var locale = Builder.settings.context.user ? Builder.settings.context.user.language : null;
|
|
38
|
-
if(locale){
|
|
39
|
-
locale = locale.replace('_', '-');
|
|
40
|
-
locale = locale === 'en' ? 'en-US' : locale;
|
|
41
|
-
locale = locale === 'zh' ? 'zh-CN' : locale;
|
|
42
|
-
locale = locale === 'cn' ? 'zh-CN' : locale;
|
|
43
|
-
return locale
|
|
44
|
-
}
|
|
45
|
-
return 'zh-CN'
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 此处不能使用import, client js 编译时会将import 转为require, 导致加载失败
|
|
49
|
-
// import('/unpkg.com/@steedos-ui/amis/dist/amis-sdk.umd.min.js').then(() => {
|
|
50
|
-
Promise.all([
|
|
51
|
-
waitForThing(window, 'assetsLoaded'),
|
|
52
|
-
waitForThing(window, 'amis'),
|
|
53
|
-
]).then(()=>{
|
|
54
|
-
// window.React = window.__React;
|
|
55
|
-
// window.ReactDOM = window.__ReactDOM;
|
|
56
|
-
const AmisRenderers = [];
|
|
57
|
-
let amis = (window.amisRequire && window.amisRequire('amis')) || window.Amis;
|
|
58
|
-
let amisVersion = amis && amis.version;
|
|
59
|
-
if(amisVersion){
|
|
60
|
-
const amisVersionClassName = "amis-" + amisVersion.split(".")[0] + "-" + amisVersion.split(".")[1];
|
|
61
|
-
document.getElementsByTagName('body')[0].className += " " + amisVersionClassName;
|
|
62
|
-
}
|
|
63
|
-
let amisLib = amisRequire('amis');
|
|
64
|
-
amisLib.registerFilter('t', function (key,param) {
|
|
65
|
-
return typeof key === 'string' ? window.t(key,param) : key;
|
|
66
|
-
});
|
|
67
|
-
const registerMap = {
|
|
68
|
-
renderer: amisLib.Renderer,
|
|
69
|
-
formitem: amisLib.FormItem,
|
|
70
|
-
options: amisLib.OptionsControl,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const amisComps = lodash.filter(Builder.registry['meta-components'], function(item){ return item.componentName && item.amis && item.amis.render});
|
|
74
|
-
|
|
75
|
-
lodash.each(amisComps,(comp)=>{
|
|
76
|
-
const Component = Builder.components.find(item => item.name === comp.componentName);
|
|
77
|
-
var type = null;
|
|
78
|
-
if(comp.amis){
|
|
79
|
-
type = comp.amis.render.type
|
|
80
|
-
}
|
|
81
|
-
if (Component && !AmisRenderers.includes(type)){
|
|
82
|
-
try {
|
|
83
|
-
let AmisWrapper = Component.class
|
|
84
|
-
AmisRenderers.push(type);
|
|
85
|
-
if(comp.componentType === 'amisSchema'){
|
|
86
|
-
let amisReact = amisRequire('react');
|
|
87
|
-
AmisWrapper = function(props){
|
|
88
|
-
// console.log(`AmisWrapper===>`, props)
|
|
89
|
-
const { $schema, body, render } = props
|
|
90
|
-
const [schema, setSchema] = amisReact.useState(null);
|
|
91
|
-
amisReact.useEffect(()=>{
|
|
92
|
-
// console.log("AmisWrapper===>==useEffect==", comp.amis.render.type, JSON.stringify(props.data?.recordId))
|
|
93
|
-
const result = Component.class(props);
|
|
94
|
-
if(result.then && typeof result.then === 'function'){
|
|
95
|
-
result.then((data)=>{
|
|
96
|
-
// console.log("AmisWrapper===>==useEffect==setSchema", data)
|
|
97
|
-
setSchema(data);
|
|
98
|
-
})
|
|
99
|
-
}else{
|
|
100
|
-
// console.log("AmisWrapper===>==useEffect==result", result)
|
|
101
|
-
setSchema(result)
|
|
102
|
-
}
|
|
103
|
-
}, [JSON.stringify($schema)]) //, JSON.stringify(props.data)
|
|
104
|
-
|
|
105
|
-
if (!schema)
|
|
106
|
-
return;
|
|
107
|
-
// return render('body', {
|
|
108
|
-
// "type": "wrapper",
|
|
109
|
-
// "className": "h-full flex items-center justify-center",
|
|
110
|
-
// "body": {
|
|
111
|
-
// "type": "spinner",
|
|
112
|
-
// "show": true
|
|
113
|
-
// }
|
|
114
|
-
// })
|
|
115
|
-
|
|
116
|
-
if (props.env.enableAMISDebug && schema) {
|
|
117
|
-
console.groupCollapsed(`[steedos render ${type}]`);
|
|
118
|
-
console.trace('Component: ', props, 'Generated Amis Schema: ', schema);
|
|
119
|
-
console.groupEnd();
|
|
120
|
-
}
|
|
121
|
-
return amisReact.createElement(amisReact.Fragment, null, amisReact.createElement(amisReact.Fragment, null, schema && render ? render('body', schema) : ''));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// 注册amis渲染器
|
|
125
|
-
let asset = comp.amis.render;
|
|
126
|
-
if (!registerMap[asset.usage]) {
|
|
127
|
-
console.error(
|
|
128
|
-
`自定义组件注册失败,不存在${asset.usage}自定义组件类型。`, comp
|
|
129
|
-
);
|
|
130
|
-
} else {
|
|
131
|
-
registerMap[asset.usage]({
|
|
132
|
-
test: new RegExp(`(^|\/)${asset.type}`),
|
|
133
|
-
type: asset.type,
|
|
134
|
-
weight: asset.weight,
|
|
135
|
-
autoVar: true,
|
|
136
|
-
})(AmisWrapper);
|
|
137
|
-
// 记录当前创建的amis自定义组件
|
|
138
|
-
console.debug('注册了一个自定义amis组件:', {
|
|
139
|
-
type: asset.type,
|
|
140
|
-
weight: asset.weight,
|
|
141
|
-
component: AmisWrapper,
|
|
142
|
-
framework: asset.framework,
|
|
143
|
-
usage: asset.usage,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
// amisRequire("amis").Renderer(
|
|
147
|
-
// {
|
|
148
|
-
// type: comp.amis?.render.type,
|
|
149
|
-
// weight: comp.amis?.render.weight,
|
|
150
|
-
// autoVar: true,
|
|
151
|
-
// }
|
|
152
|
-
// )(AmisWrapper);
|
|
153
|
-
} catch(e){console.error(e)}
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
const normalizeLink = (to, location = window.location) => {
|
|
158
|
-
to = to || '';
|
|
159
|
-
|
|
160
|
-
if (to && to[0] === '#') {
|
|
161
|
-
to = location.pathname + location.search + to;
|
|
162
|
-
} else if (to && to[0] === '?') {
|
|
163
|
-
to = location.pathname + to;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const idx = to.indexOf('?');
|
|
167
|
-
const idx2 = to.indexOf('#');
|
|
168
|
-
let pathname = ~idx
|
|
169
|
-
? to.substring(0, idx)
|
|
170
|
-
: ~idx2
|
|
171
|
-
? to.substring(0, idx2)
|
|
172
|
-
: to;
|
|
173
|
-
let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
|
|
174
|
-
let hash = ~idx2 ? to.substring(idx2) : location.hash;
|
|
175
|
-
|
|
176
|
-
if (!pathname) {
|
|
177
|
-
pathname = location.pathname;
|
|
178
|
-
} else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
|
|
179
|
-
let relativeBase = location.pathname;
|
|
180
|
-
const paths = relativeBase.split('/');
|
|
181
|
-
paths.pop();
|
|
182
|
-
let m;
|
|
183
|
-
while ((m = /^\.\.?\//.exec(pathname))) {
|
|
184
|
-
if (m[0] === '../') {
|
|
185
|
-
paths.pop();
|
|
186
|
-
}
|
|
187
|
-
pathname = pathname.substring(m[0].length);
|
|
188
|
-
}
|
|
189
|
-
pathname = paths.concat(pathname).join('/');
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return pathname + search + hash;
|
|
193
|
-
};
|
|
194
|
-
const isCurrentUrl = (to, ctx)=>{
|
|
195
|
-
try {
|
|
196
|
-
if (!to) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
const pathname = window.location.pathname;
|
|
200
|
-
const link = normalizeLink(to, {
|
|
201
|
-
...location,
|
|
202
|
-
pathname,
|
|
203
|
-
hash: ''
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
if (!~link.indexOf('http') && ~link.indexOf(':')) {
|
|
207
|
-
let strict = ctx && ctx.strict;
|
|
208
|
-
return match(link, {
|
|
209
|
-
decode: decodeURIComponent,
|
|
210
|
-
strict: typeof strict !== 'undefined' ? strict : true
|
|
211
|
-
})(pathname);
|
|
212
|
-
}
|
|
213
|
-
return decodeURI(pathname) === link || decodeURI(pathname).startsWith(`${link}/`);
|
|
214
|
-
} catch (error) {
|
|
215
|
-
console.error(`error`, error)
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
AmisEnv = {
|
|
219
|
-
// getModalContainer: (props)=>{
|
|
220
|
-
// let div = document.querySelector("#amisModalContainer");
|
|
221
|
-
// if(!div){
|
|
222
|
-
// div = document.createElement('div');
|
|
223
|
-
// div.className="amis-scope";
|
|
224
|
-
// div.style.height='0px';
|
|
225
|
-
// div.id="amisModalContainer";
|
|
226
|
-
// document.body.appendChild(div)
|
|
227
|
-
// }
|
|
228
|
-
// return div;
|
|
229
|
-
// },
|
|
230
|
-
// 如果这里不配置env.notify,那么会走amis 默认的env.notify,它会造成随机把toast组件dom插入到不同的scope容器内(应该是插入到最后一个加载的scope),这在苹果手机上可能会造成弹出的通知z-index不生效的情况,出现通知被档住的问题
|
|
231
|
-
notify: (type, msg)=>{
|
|
232
|
-
var tpl = msg.props && msg.props.schema.tpl;
|
|
233
|
-
if(tpl){
|
|
234
|
-
SteedosUI.message[type](tpl)
|
|
235
|
-
}else if(typeof msg == 'string'){
|
|
236
|
-
SteedosUI.message[type](msg)
|
|
237
|
-
}else{
|
|
238
|
-
console.warn('notify', type, msg)
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
jumpTo: (to, action) => {
|
|
242
|
-
if (to === 'goBack') {
|
|
243
|
-
return window.history.back();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
to = normalizeLink(to);
|
|
247
|
-
|
|
248
|
-
if (action && action.actionType === 'url') {
|
|
249
|
-
action.blank === false ? (window.location.href = to) : window.open(to);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// 主要是支持 nav 中的跳转
|
|
254
|
-
if (action && to && action.target) {
|
|
255
|
-
window.open(to, action.target);
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (/^https?:\/\//.test(to)) {
|
|
260
|
-
window.location.replace(to);
|
|
261
|
-
} else {
|
|
262
|
-
FlowRouter.go(to);
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
theme: 'antd',
|
|
266
|
-
isCurrentUrl: isCurrentUrl,
|
|
267
|
-
requestAdaptor: (config)=>{
|
|
268
|
-
if(config.allowCredentials == false){
|
|
269
|
-
config.withCredentials = false;
|
|
270
|
-
delete config.allowCredentials
|
|
271
|
-
}
|
|
272
|
-
// url是相对路径
|
|
273
|
-
if(config.url && (!/^http[s]?:\/\//i.test(config.url))){
|
|
274
|
-
if(!config.headers){
|
|
275
|
-
config.headers = {}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if(!config.headers.Authorization && Builder.settings.context && Builder.settings.context.tenantId && Builder.settings.context.authToken){
|
|
279
|
-
config.headers.Authorization = `Bearer ${Builder.settings.context.tenantId},${Builder.settings.context.authToken}`;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
return config;
|
|
283
|
-
},
|
|
284
|
-
responseAdaptor: function(api, payload, query, request, response){
|
|
285
|
-
if(payload.statusCode === 500 && payload.message){
|
|
286
|
-
payload = {
|
|
287
|
-
"status": payload.statusCode,
|
|
288
|
-
"msg": payload.message
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return payload;
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
// 已弃用
|
|
295
|
-
const AmisRender = function (props) {
|
|
296
|
-
let env = props.env;
|
|
297
|
-
const schema = props.schema;
|
|
298
|
-
const data = props.data;
|
|
299
|
-
const name = props.name;
|
|
300
|
-
const refName = schema.name || schema.id;
|
|
301
|
-
if(SteedosUI.refs[refName]){
|
|
302
|
-
if(SteedosUI.refs[refName].unmount){
|
|
303
|
-
try {
|
|
304
|
-
SteedosUI.refs[refName].unmount()
|
|
305
|
-
} catch (Exception) {
|
|
306
|
-
}
|
|
307
|
-
}else{
|
|
308
|
-
console.log(`not find amis scope unmount`)
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
if(props.pageType === 'form'){
|
|
313
|
-
env = Object.assign({
|
|
314
|
-
getModalContainer: ()=>{
|
|
315
|
-
return document.querySelector('.amis-scope');
|
|
316
|
-
}
|
|
317
|
-
}, env);
|
|
318
|
-
}
|
|
319
|
-
schema.scopeRef = (ref) => {
|
|
320
|
-
try {
|
|
321
|
-
if(!window.amisScopes){
|
|
322
|
-
window.amisScopes = {};
|
|
323
|
-
}
|
|
324
|
-
if(name){
|
|
325
|
-
window.amisScopes[name] = ref;
|
|
326
|
-
}
|
|
327
|
-
} catch (error) {
|
|
328
|
-
console.error('error', error)
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return scoped = ref
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
let amisReact = amisRequire('react');
|
|
336
|
-
|
|
337
|
-
amisReact.useEffect(()=>{
|
|
338
|
-
const amisScope = amisRequire('amis/embed').embed(`.steedos-amis-render-scope-${name}`,schema, {data, name, locale: getAmisLng()}, Object.assign({}, AmisEnv, env))
|
|
339
|
-
const refName = schema.name || schema.id;
|
|
340
|
-
if(window.SteedosUI && refName){
|
|
341
|
-
SteedosUI.refs[refName] = amisScope;
|
|
342
|
-
}
|
|
343
|
-
}, [])
|
|
344
|
-
return amisReact.createElement("div", {
|
|
345
|
-
className: "amis-scope"
|
|
346
|
-
}, amisReact.createElement("div", {
|
|
347
|
-
className: `steedos-amis-render-scope-${name}`
|
|
348
|
-
}));
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
window.renderAmis = function (root, schema, data, env) {
|
|
352
|
-
// console.log("===window.renderAmis===root, env===", root, env);
|
|
353
|
-
// console.log("===window.renderAmis===data===", data);
|
|
354
|
-
const refName = schema.name || schema.id;
|
|
355
|
-
if(SteedosUI.refs[refName]){
|
|
356
|
-
if(SteedosUI.refs[refName].unmount){
|
|
357
|
-
try {
|
|
358
|
-
SteedosUI.refs[refName].unmount()
|
|
359
|
-
} catch (Exception) {
|
|
360
|
-
}
|
|
361
|
-
}else{
|
|
362
|
-
console.log(`not find amis scope unmount`)
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// if(props.pageType === 'form'){
|
|
367
|
-
// env = Object.assign({
|
|
368
|
-
// getModalContainer: ()=>{
|
|
369
|
-
// return document.querySelector('.amis-scope');
|
|
370
|
-
// }
|
|
371
|
-
// }, env);
|
|
372
|
-
// }
|
|
373
|
-
schema.scopeRef = (ref) => {
|
|
374
|
-
try {
|
|
375
|
-
if(!window.amisScopes){
|
|
376
|
-
window.amisScopes = {};
|
|
377
|
-
}
|
|
378
|
-
if(name){
|
|
379
|
-
window.amisScopes[name] = ref;
|
|
380
|
-
}
|
|
381
|
-
} catch (error) {
|
|
382
|
-
console.error('error', error)
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
return scoped = ref
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const amisScope = amisRequire('amis/embed').embed(root, schema, {data, name, locale: getAmisLng()}, Object.assign({getModalContainer: ()=>{ return document.querySelector('body');}}, AmisEnv, env))
|
|
389
|
-
if(window.SteedosUI && refName){
|
|
390
|
-
SteedosUI.refs[refName] = amisScope;
|
|
391
|
-
SteedosUI.refs[refName].__$schema = schema;
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
const initMonaco = ()=>{
|
|
396
|
-
return Promise.resolve(true)
|
|
397
|
-
}
|
|
398
|
-
//Amis SDK 中已清理了monaco, 所以这里需要提前注册,否则会导致amis code类型报错
|
|
399
|
-
initMonaco().catch((err)=>{
|
|
400
|
-
console.error(`Builder.initMonaco error: ${err}`);
|
|
401
|
-
}).finally(()=>{
|
|
402
|
-
const language = getAmisLng()
|
|
403
|
-
axios.get(`/translations/amis/${language}.json`).then((res)=>{
|
|
404
|
-
amisRequire("amis").registerLocale(`${language}`, res.data)
|
|
405
|
-
Builder.registerComponent(AmisRender, {
|
|
406
|
-
name: 'Amis',
|
|
407
|
-
inputs: [
|
|
408
|
-
{ name: 'schema', type: 'object' },
|
|
409
|
-
{ name: 'data', type: 'object' },
|
|
410
|
-
{ name: 'name', type: 'string' }
|
|
411
|
-
]
|
|
412
|
-
});
|
|
413
|
-
})
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
// });
|
|
417
|
-
|
|
418
36
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-plugin-amis",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.116",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "yarn build:tailwind-base && yarn build:tailwind",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "5faa4fd9601e2316a5fa428fcb945e3ecc8d1160",
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"tailwindcss": "^3.4.17"
|
|
18
18
|
}
|