@steedos/service-plugin-amis 2.4.14 → 2.4.15-beta.2

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.
@@ -6,216 +6,219 @@
6
6
 
7
7
  ; (function () {
8
8
 
9
- try {
10
- window['attrAccept'] = function (file, acceptedFiles) {
11
- if (file && acceptedFiles) {
12
- var acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(',');
13
- var fileName = file.name || '';
14
- var mimeType = (file.type || '').toLowerCase();
15
- var baseMimeType = mimeType.replace(/\/.*$/, '');
16
- return acceptedFilesArray.some(function (type) {
17
- var validType = type.trim().toLowerCase();
18
-
19
- if (validType.charAt(0) === '.') {
20
- return fileName.toLowerCase().endsWith(validType);
21
- } else if (validType.endsWith('/*')) {
22
- // This is something like a image/* mime type
23
- return baseMimeType === validType.replace(/\/.*$/, '');
24
- }
25
-
26
- return mimeType === validType;
27
- });
28
- }
29
-
30
- return true;
9
+ try {
10
+ window['attrAccept'] = function (file, acceptedFiles) {
11
+ if (file && acceptedFiles) {
12
+ var acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(',');
13
+ var fileName = file.name || '';
14
+ var mimeType = (file.type || '').toLowerCase();
15
+ var baseMimeType = mimeType.replace(/\/.*$/, '');
16
+ return acceptedFilesArray.some(function (type) {
17
+ var validType = type.trim().toLowerCase();
18
+
19
+ if (validType.charAt(0) === '.') {
20
+ return fileName.toLowerCase().endsWith(validType);
21
+ } else if (validType.endsWith('/*')) {
22
+ // This is something like a image/* mime type
23
+ return baseMimeType === validType.replace(/\/.*$/, '');
24
+ }
25
+
26
+ return mimeType === validType;
27
+ });
31
28
  }
32
-
33
- // 加载Amis SDK: 如果直接放到body中会导致 meteor 编译后的 cordova.js 加载报错
34
- // let amisSDKScript = document.createElement("script");
35
- // amisSDKScript.setAttribute("src", Steedos.absoluteUrl('/unpkg.com/amis/sdk/sdk.js'));
36
- // document.getElementsByTagName("head")[0].appendChild(amisSDKScript);
37
- } catch (error) {
38
- console.error(error)
39
- };
40
-
41
- const getAmisLng = ()=>{
42
- var locale = Creator.USER_CONTEXT ? Creator.USER_CONTEXT.user.language : null;
43
- if(locale){
44
- locale = locale.replace('_', '-');
45
- locale = locale === 'en' ? 'en-US' : locale;
46
- locale = locale === 'zh' ? 'zh-CN' : locale;
47
- locale = locale === 'cn' ? 'zh-CN' : locale;
48
- return locale
29
+
30
+ return true;
49
31
  }
50
- return 'zh-CN'
51
- }
52
32
 
53
- // 此处不能使用import, client js 编译时会将import 转为require, 导致加载失败
54
- // import('/unpkg.com/@steedos-ui/amis/dist/amis-sdk.umd.min.js').then(() => {
55
- Promise.all([
56
- waitForThing(window, 'assetsLoaded'),
57
- waitForThing(window, 'amis'),
58
- ]).then(()=>{
59
- // window.React = window.__React;
60
- // window.ReactDOM = window.__ReactDOM;
61
- const AmisRenderers = [];
62
- let amisLib = amisRequire('amis');
63
- const registerMap = {
64
- renderer: amisLib.Renderer,
65
- formitem: amisLib.FormItem,
66
- options: amisLib.OptionsControl,
67
- };
33
+ // 加载Amis SDK: 如果直接放到body中会导致 meteor 编译后的 cordova.js 加载报错
34
+ // let amisSDKScript = document.createElement("script");
35
+ // amisSDKScript.setAttribute("src", Steedos.absoluteUrl('/unpkg.com/amis/sdk/sdk.js'));
36
+ // document.getElementsByTagName("head")[0].appendChild(amisSDKScript);
37
+ } catch (error) {
38
+ console.error(error)
39
+ };
68
40
 
69
- const amisComps = lodash.filter(Builder.registry['meta-components'], function(item){ return item.componentName && item.amis?.render});
70
-
71
- lodash.each(amisComps,(comp)=>{
72
- const Component = Builder.components.find(item => item.name === comp.componentName);
73
- if (Component && !AmisRenderers.includes(comp.amis?.render.type)){
74
- try {
75
- let AmisWrapper = Component.class
76
- AmisRenderers.push(comp.amis?.render.type);
77
- if(comp.componentType === 'amisSchema'){
78
- let amisReact = amisRequire('react');
79
- AmisWrapper = function(props){
80
- const { $schema, body, render } = props
81
- const [schema, setSchema] = amisReact.useState(null);
82
- amisReact.useEffect(()=>{
83
- const result = Component.class(props);
84
- if(result.then && typeof result.then === 'function'){
85
- result.then((data)=>{
86
- setSchema(data);
87
- })
88
- }else{
89
- setSchema(result)
90
- }
91
- }, [JSON.stringify($schema)]) //, JSON.stringify(props.data)
41
+ const getAmisLng = ()=>{
42
+ var locale = Creator.USER_CONTEXT ? Creator.USER_CONTEXT.user.language : null;
43
+ if(locale){
44
+ locale = locale.replace('_', '-');
45
+ locale = locale === 'en' ? 'en-US' : locale;
46
+ locale = locale === 'zh' ? 'zh-CN' : locale;
47
+ locale = locale === 'cn' ? 'zh-CN' : locale;
48
+ return locale
49
+ }
50
+ return 'zh-CN'
51
+ }
52
+
53
+ // 此处不能使用import, client js 编译时会将import 转为require, 导致加载失败
54
+ // import('/unpkg.com/@steedos-ui/amis/dist/amis-sdk.umd.min.js').then(() => {
55
+ Promise.all([
56
+ waitForThing(window, 'assetsLoaded'),
57
+ waitForThing(window, 'amis'),
58
+ ]).then(()=>{
59
+ // window.React = window.__React;
60
+ // window.ReactDOM = window.__ReactDOM;
61
+ const AmisRenderers = [];
62
+ let amisLib = amisRequire('amis');
63
+ const registerMap = {
64
+ renderer: amisLib.Renderer,
65
+ formitem: amisLib.FormItem,
66
+ options: amisLib.OptionsControl,
67
+ };
92
68
 
93
- if (!schema)
94
- return render('body', {
95
- "type": "wrapper",
96
- "className": "h-full flex items-center justify-center",
97
- "body": {
98
- "type": "spinner",
99
- "show": true
100
- }
101
- })
69
+ const amisComps = lodash.filter(Builder.registry['meta-components'], function(item){ return item.componentName && item.amis?.render});
70
+
71
+ lodash.each(amisComps,(comp)=>{
72
+ const Component = Builder.components.find(item => item.name === comp.componentName);
73
+ if (Component && !AmisRenderers.includes(comp.amis?.render.type)){
74
+ try {
75
+ let AmisWrapper = Component.class
76
+ AmisRenderers.push(comp.amis?.render.type);
77
+ if(comp.componentType === 'amisSchema'){
78
+ let amisReact = amisRequire('react');
79
+ AmisWrapper = function(props){
80
+ // console.log(`AmisWrapper===>`, props)
81
+ const { $schema, body, render } = props
82
+ const [schema, setSchema] = amisReact.useState(null);
83
+ amisReact.useEffect(()=>{
84
+ // console.log("AmisWrapper===>==useEffect==", comp.amis.render.type, JSON.stringify(props.data?.recordId))
85
+ const result = Component.class(props);
86
+ if(result.then && typeof result.then === 'function'){
87
+ result.then((data)=>{
88
+ // console.log("AmisWrapper===>==useEffect==setSchema", data)
89
+ setSchema(data);
90
+ })
91
+ }else{
92
+ // console.log("AmisWrapper===>==useEffect==result", result)
93
+ setSchema(result)
94
+ }
95
+ }, [JSON.stringify($schema)]) //, JSON.stringify(props.data)
102
96
 
103
- if (props.env.enableAMISDebug && schema) {
104
- console.groupCollapsed(`[steedos render ${comp.amis?.render.type}]`);
105
- console.trace('Component: ', props, 'Generated Amis Schema: ', schema);
106
- console.groupEnd();
97
+ if (!schema)
98
+ return render('body', {
99
+ "type": "wrapper",
100
+ "className": "h-full flex items-center justify-center",
101
+ "body": {
102
+ "type": "spinner",
103
+ "show": true
107
104
  }
105
+ })
108
106
 
109
- return amisReact.createElement(amisReact.Fragment, null, amisReact.createElement(amisReact.Fragment, null, schema && render ? render('body', schema) : ''), amisReact.createElement(amisReact.Fragment, null, render ? render('body', body) : ''));
107
+ if (props.env.enableAMISDebug && schema) {
108
+ console.groupCollapsed(`[steedos render ${comp.amis?.render.type}]`);
109
+ console.trace('Component: ', props, 'Generated Amis Schema: ', schema);
110
+ console.groupEnd();
110
111
  }
112
+ return amisReact.createElement(amisReact.Fragment, null, amisReact.createElement(amisReact.Fragment, null, schema && render ? render('body', schema) : ''));
111
113
  }
112
- // 注册amis渲染器
113
- let asset = comp.amis.render;
114
- if (!registerMap[asset.usage]) {
115
- console.error(
116
- `自定义组件注册失败,不存在${asset.usage}自定义组件类型。`, comp
117
- );
118
- } else {
119
- registerMap[asset.usage]({
120
- test: new RegExp(`(^|\/)${asset.type}`),
121
- type: asset.type,
122
- weight: asset.weight,
123
- autoVar: true,
124
- })(AmisWrapper);
125
- // 记录当前创建的amis自定义组件
126
- console.info('注册了一个自定义amis组件:', {
127
- type: asset.type,
128
- weight: asset.weight,
129
- component: AmisWrapper,
130
- framework: asset.framework,
131
- usage: asset.usage,
132
- });
133
114
  }
134
- // amisRequire("amis").Renderer(
135
- // {
136
- // type: comp.amis?.render.type,
137
- // weight: comp.amis?.render.weight,
138
- // autoVar: true,
139
- // }
140
- // )(AmisWrapper);
141
- } catch(e){console.error(e)}
142
- }
143
- });
115
+ // 注册amis渲染器
116
+ let asset = comp.amis.render;
117
+ if (!registerMap[asset.usage]) {
118
+ console.error(
119
+ `自定义组件注册失败,不存在${asset.usage}自定义组件类型。`, comp
120
+ );
121
+ } else {
122
+ registerMap[asset.usage]({
123
+ test: new RegExp(`(^|\/)${asset.type}`),
124
+ type: asset.type,
125
+ weight: asset.weight,
126
+ autoVar: true,
127
+ })(AmisWrapper);
128
+ // 记录当前创建的amis自定义组件
129
+ console.info('注册了一个自定义amis组件:', {
130
+ type: asset.type,
131
+ weight: asset.weight,
132
+ component: AmisWrapper,
133
+ framework: asset.framework,
134
+ usage: asset.usage,
135
+ });
136
+ }
137
+ // amisRequire("amis").Renderer(
138
+ // {
139
+ // type: comp.amis?.render.type,
140
+ // weight: comp.amis?.render.weight,
141
+ // autoVar: true,
142
+ // }
143
+ // )(AmisWrapper);
144
+ } catch(e){console.error(e)}
145
+ }
146
+ });
144
147
 
145
- const normalizeLink = (to, location = window.location) => {
146
- to = to || '';
147
-
148
- if (to && to[0] === '#') {
149
- to = location.pathname + location.search + to;
150
- } else if (to && to[0] === '?') {
151
- to = location.pathname + to;
152
- }
153
-
154
- const idx = to.indexOf('?');
155
- const idx2 = to.indexOf('#');
156
- let pathname = ~idx
157
- ? to.substring(0, idx)
158
- : ~idx2
159
- ? to.substring(0, idx2)
160
- : to;
161
- let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
162
- let hash = ~idx2 ? to.substring(idx2) : location.hash;
163
-
164
- if (!pathname) {
165
- pathname = location.pathname;
166
- } else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
167
- let relativeBase = location.pathname;
168
- const paths = relativeBase.split('/');
169
- paths.pop();
170
- let m;
171
- while ((m = /^\.\.?\//.exec(pathname))) {
172
- if (m[0] === '../') {
173
- paths.pop();
174
- }
175
- pathname = pathname.substring(m[0].length);
148
+ const normalizeLink = (to, location = window.location) => {
149
+ to = to || '';
150
+
151
+ if (to && to[0] === '#') {
152
+ to = location.pathname + location.search + to;
153
+ } else if (to && to[0] === '?') {
154
+ to = location.pathname + to;
155
+ }
156
+
157
+ const idx = to.indexOf('?');
158
+ const idx2 = to.indexOf('#');
159
+ let pathname = ~idx
160
+ ? to.substring(0, idx)
161
+ : ~idx2
162
+ ? to.substring(0, idx2)
163
+ : to;
164
+ let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
165
+ let hash = ~idx2 ? to.substring(idx2) : location.hash;
166
+
167
+ if (!pathname) {
168
+ pathname = location.pathname;
169
+ } else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
170
+ let relativeBase = location.pathname;
171
+ const paths = relativeBase.split('/');
172
+ paths.pop();
173
+ let m;
174
+ while ((m = /^\.\.?\//.exec(pathname))) {
175
+ if (m[0] === '../') {
176
+ paths.pop();
176
177
  }
177
- pathname = paths.concat(pathname).join('/');
178
- }
179
-
180
- return pathname + search + hash;
181
- };
182
- const isCurrentUrl = (to, ctx)=>{
183
- try {
184
- if (!to) {
185
- return false;
186
- }
187
- const pathname = window.location.pathname;
188
- const link = normalizeLink(to, {
189
- ...location,
190
- pathname,
191
- hash: ''
192
- });
193
-
194
- if (!~link.indexOf('http') && ~link.indexOf(':')) {
195
- let strict = ctx && ctx.strict;
196
- return match(link, {
197
- decode: decodeURIComponent,
198
- strict: typeof strict !== 'undefined' ? strict : true
199
- })(pathname);
178
+ pathname = pathname.substring(m[0].length);
200
179
  }
201
- return decodeURI(pathname) === link || decodeURI(pathname).startsWith(`${link}/`);
202
- } catch (error) {
203
- console.error(`error`, error)
180
+ pathname = paths.concat(pathname).join('/');
181
+ }
182
+
183
+ return pathname + search + hash;
184
+ };
185
+ const isCurrentUrl = (to, ctx)=>{
186
+ try {
187
+ if (!to) {
188
+ return false;
204
189
  }
190
+ const pathname = window.location.pathname;
191
+ const link = normalizeLink(to, {
192
+ ...location,
193
+ pathname,
194
+ hash: ''
195
+ });
196
+
197
+ if (!~link.indexOf('http') && ~link.indexOf(':')) {
198
+ let strict = ctx && ctx.strict;
199
+ return match(link, {
200
+ decode: decodeURIComponent,
201
+ strict: typeof strict !== 'undefined' ? strict : true
202
+ })(pathname);
203
+ }
204
+ return decodeURI(pathname) === link || decodeURI(pathname).startsWith(`${link}/`);
205
+ } catch (error) {
206
+ console.error(`error`, error)
205
207
  }
206
- AmisEnv = {
207
- // getModalContainer: (props)=>{
208
- // let div = document.querySelector("#amisModalContainer");
209
- // if(!div){
210
- // div = document.createElement('div');
211
- // div.className="amis-scope";
212
- // div.style.height='0px';
213
- // div.id="amisModalContainer";
214
- // document.body.appendChild(div)
215
- // }
216
- // return div;
217
- // },
218
- jumpTo: (to, action) => {
208
+ }
209
+ AmisEnv = {
210
+ // getModalContainer: (props)=>{
211
+ // let div = document.querySelector("#amisModalContainer");
212
+ // if(!div){
213
+ // div = document.createElement('div');
214
+ // div.className="amis-scope";
215
+ // div.style.height='0px';
216
+ // div.id="amisModalContainer";
217
+ // document.body.appendChild(div)
218
+ // }
219
+ // return div;
220
+ // },
221
+ jumpTo: (to, action) => {
219
222
  if (to === 'goBack') {
220
223
  return window.history.back();
221
224
  }
@@ -238,68 +241,16 @@
238
241
  } else {
239
242
  FlowRouter.go(to);
240
243
  }
241
- },
242
- theme: 'antd',
243
- isCurrentUrl: isCurrentUrl,
244
- };
245
-
246
- const AmisRender = function (props) {
247
- let env = props.env;
248
- const schema = props.schema;
249
- const data = props.data;
250
- const name = props.name;
251
- const refName = schema.name || schema.id;
252
- if(SteedosUI.refs[refName]){
253
- if(SteedosUI.refs[refName].unmount){
254
- try {
255
- SteedosUI.refs[refName].unmount()
256
- } catch (Exception) {
257
- }
258
- }else{
259
- console.log(`not find amis scope unmount`)
260
- }
261
- }
262
-
263
- if(props.pageType === 'form'){
264
- env = Object.assign({
265
- getModalContainer: ()=>{
266
- return document.querySelector('.amis-scope');
267
- }
268
- }, env);
269
- }
270
- schema.scopeRef = (ref) => {
271
- try {
272
- if(!window.amisScopes){
273
- window.amisScopes = {};
274
- }
275
- if(name){
276
- window.amisScopes[name] = ref;
277
- }
278
- } catch (error) {
279
- console.error('error', error)
280
- }
281
-
282
- return scoped = ref
283
- }
284
-
285
-
286
- let amisReact = amisRequire('react');
287
-
288
- amisReact.useEffect(()=>{
289
- const amisScope = amisRequire('amis/embed').embed(`.steedos-amis-render-scope-${name}`,schema, {data, name, locale: getAmisLng()}, Object.assign({}, AmisEnv, env))
290
- const refName = schema.name || schema.id;
291
- if(window.SteedosUI && refName){
292
- SteedosUI.refs[refName] = amisScope;
293
- }
294
- }, [])
295
- return amisReact.createElement("div", {
296
- className: "amis-scope"
297
- }, amisReact.createElement("div", {
298
- className: `steedos-amis-render-scope-${name}`
299
- }));
300
- };
301
-
302
- window.renderAmis = function (root, schema, data, env) {
244
+ },
245
+ theme: 'antd',
246
+ isCurrentUrl: isCurrentUrl,
247
+ };
248
+ // 已弃用
249
+ const AmisRender = function (props) {
250
+ let env = props.env;
251
+ const schema = props.schema;
252
+ const data = props.data;
253
+ const name = props.name;
303
254
  const refName = schema.name || schema.id;
304
255
  if(SteedosUI.refs[refName]){
305
256
  if(SteedosUI.refs[refName].unmount){
@@ -312,13 +263,13 @@
312
263
  }
313
264
  }
314
265
 
315
- // if(props.pageType === 'form'){
316
- // env = Object.assign({
317
- // getModalContainer: ()=>{
318
- // return document.querySelector('.amis-scope');
319
- // }
320
- // }, env);
321
- // }
266
+ if(props.pageType === 'form'){
267
+ env = Object.assign({
268
+ getModalContainer: ()=>{
269
+ return document.querySelector('.amis-scope');
270
+ }
271
+ }, env);
272
+ }
322
273
  schema.scopeRef = (ref) => {
323
274
  try {
324
275
  if(!window.amisScopes){
@@ -335,50 +286,102 @@
335
286
  }
336
287
 
337
288
 
338
- const amisScope = amisRequire('amis/embed').embed(root, schema, {data, name, locale: getAmisLng()}, Object.assign({}, AmisEnv, env))
339
- if(window.SteedosUI && refName){
340
- SteedosUI.refs[refName] = amisScope;
289
+ let amisReact = amisRequire('react');
290
+
291
+ amisReact.useEffect(()=>{
292
+ const amisScope = amisRequire('amis/embed').embed(`.steedos-amis-render-scope-${name}`,schema, {data, name, locale: getAmisLng()}, Object.assign({}, AmisEnv, env))
293
+ const refName = schema.name || schema.id;
294
+ if(window.SteedosUI && refName){
295
+ SteedosUI.refs[refName] = amisScope;
296
+ }
297
+ }, [])
298
+ return amisReact.createElement("div", {
299
+ className: "amis-scope"
300
+ }, amisReact.createElement("div", {
301
+ className: `steedos-amis-render-scope-${name}`
302
+ }));
303
+ };
304
+
305
+ window.renderAmis = function (root, schema, data, env) {
306
+ const refName = schema.name || schema.id;
307
+ if(SteedosUI.refs[refName]){
308
+ if(SteedosUI.refs[refName].unmount){
309
+ try {
310
+ SteedosUI.refs[refName].unmount()
311
+ } catch (Exception) {
341
312
  }
342
- };
313
+ }else{
314
+ console.log(`not find amis scope unmount`)
315
+ }
316
+ }
317
+
318
+ // if(props.pageType === 'form'){
319
+ // env = Object.assign({
320
+ // getModalContainer: ()=>{
321
+ // return document.querySelector('.amis-scope');
322
+ // }
323
+ // }, env);
324
+ // }
325
+ schema.scopeRef = (ref) => {
326
+ try {
327
+ if(!window.amisScopes){
328
+ window.amisScopes = {};
329
+ }
330
+ if(name){
331
+ window.amisScopes[name] = ref;
332
+ }
333
+ } catch (error) {
334
+ console.error('error', error)
335
+ }
336
+
337
+ return scoped = ref
338
+ }
339
+
340
+ const amisScope = amisRequire('amis/embed').embed(root, schema, {data, name, locale: getAmisLng()}, Object.assign({}, AmisEnv, env))
341
+ if(window.SteedosUI && refName){
342
+ SteedosUI.refs[refName] = amisScope;
343
+ SteedosUI.refs[refName].__$schema = schema;
344
+ }
345
+ };
343
346
 
344
- const initMonaco = ()=>{
347
+ const initMonaco = ()=>{
345
348
 
346
- // const { detect } = require('detect-browser');
349
+ // const { detect } = require('detect-browser');
347
350
 
348
- // const browser = detect();
351
+ // const browser = detect();
349
352
 
350
- // // 低于86版的chrome 不支持code类型字段及功能
351
- // if (browser && browser.name === 'chrome' && Number(browser.version.split(".")[0]) < 86) {
352
- // return Promise.resolve(true)
353
- // }
353
+ // // 低于86版的chrome 不支持code类型字段及功能
354
+ // if (browser && browser.name === 'chrome' && Number(browser.version.split(".")[0]) < 86) {
355
+ // return Promise.resolve(true)
356
+ // }
354
357
 
355
- // // 手机版暂不支持code类型字段.
356
- // if(Meteor.isCordova){
357
- // return Promise.resolve(true)
358
- // }else{
359
- // return Builder.initMonaco()
360
- // }
358
+ // // 手机版暂不支持code类型字段.
359
+ // if(Meteor.isCordova){
360
+ // return Promise.resolve(true)
361
+ // }else{
362
+ // return Builder.initMonaco()
363
+ // }
361
364
 
362
- return Promise.resolve(true)
363
- }
364
- //Amis SDK 中已清理了monaco, 所以这里需要提前注册,否则会导致amis code类型报错
365
- initMonaco().catch((err)=>{
366
- console.error(`Builder.initMonaco error: ${err}`);
367
- }).finally(()=>{
368
- const language = getAmisLng()
369
- axios.get(`/translations/amis/${language}.json`).then((res)=>{
370
- amisRequire("amis").registerLocale(`${language}`, res.data)
371
- Builder.registerComponent(AmisRender, {
372
- name: 'Amis',
373
- inputs: [
374
- { name: 'schema', type: 'object' },
375
- { name: 'data', type: 'object' },
376
- { name: 'name', type: 'string' }
377
- ]
378
- });
379
- })
380
- });
381
- });
382
- // });
365
+ return Promise.resolve(true)
366
+ }
367
+ //Amis SDK 中已清理了monaco, 所以这里需要提前注册,否则会导致amis code类型报错
368
+ initMonaco().catch((err)=>{
369
+ console.error(`Builder.initMonaco error: ${err}`);
370
+ }).finally(()=>{
371
+ const language = getAmisLng()
372
+ axios.get(`/translations/amis/${language}.json`).then((res)=>{
373
+ amisRequire("amis").registerLocale(`${language}`, res.data)
374
+ Builder.registerComponent(AmisRender, {
375
+ name: 'Amis',
376
+ inputs: [
377
+ { name: 'schema', type: 'object' },
378
+ { name: 'data', type: 'object' },
379
+ { name: 'name', type: 'string' }
380
+ ]
381
+ });
382
+ })
383
+ });
384
+ });
385
+ // });
383
386
 
384
387
  })();
@@ -234,15 +234,15 @@ module.exports = {
234
234
  */
235
235
  const relatedListObjects = [];
236
236
  const relationsInfo = await object.getRelationsInfo();
237
- const details = relationsInfo && relationsInfo.details;
238
- // const lookupDetails = relationsInfo && relationsInfo.lookup_details;
239
- // const relatedLists = _.union(details, lookupDetails);
237
+ let details = relationsInfo && relationsInfo.details;
238
+ const lookupDetails = relationsInfo && relationsInfo.lookup_details;
239
+ details = _.union(details, lookupDetails);
240
240
 
241
241
  _.each(details, function(related){
242
242
  /*related可能是一个lookup_details,它是对象而不是字符串,从中取出key值*/
243
- // if(typeof related !== "string"){
244
- // relatedListObjects.push(related.objectName)
245
- // }
243
+ if(typeof related !== "string"){
244
+ relatedListObjects.push(related.objectName)
245
+ }
246
246
  let foo = related.split('.');
247
247
  let rObjectName = foo[0];
248
248
  relatedListObjects.push(rObjectName);
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * @Author: baozhoutao@steedos.com
3
3
  * @Date: 2022-05-19 11:38:30
4
- * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
5
- * @LastEditTime: 2023-03-15 17:37:05
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2023-04-19 13:20:20
6
6
  * @Description:
7
7
  */
8
8
  const PageSchema = require('./utils/page-schema');
@@ -100,67 +100,22 @@ const getRecordPageInitSchema = async function (objectApiName, userSession) {
100
100
  if (hasRelatedLists) {
101
101
  content.tabs.push(related)
102
102
  }
103
- const amisSchema = {
104
- "type": "service",
105
- "body": [
106
- {
107
- "type": "steedos-record-detail-header",
108
- "label": "标题面板",
109
- "objectApiName": "${objectName}",
110
- "recordId": "${recordId}",
111
- onEvent: {
112
- "recordLoaded": {
113
- "actions": [
114
- {
115
- "actionType": "reload",
116
- "data": {
117
- "name": `\${event.data.record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
118
- "record": `\${event.data.record}`,
119
- "recordLoaded": true,
120
- }
121
- },
122
- {
123
- "actionType": "reload",
124
- "componentId": `page_readonly_${objectApiName}_header`, //刷新标题, 详细页面header service 嵌套太多, 导致仅刷新第一层service无法更新recordName
125
- "data": {
126
- "name": `\${event.data.record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
127
- "record": `\${event.data.record}`,
128
- "recordLoaded": true,
129
- }
130
- }
131
- ]
132
- }
133
- },
134
- },
135
- content
136
- ],
137
- data: {
138
- "_master.objectName": "${objectName}",
139
- "_master.recordId": "${recordId}"
140
- },
141
- onEvent: {
142
- "recordLoaded": {
143
- "actions": [
144
- {
145
- "actionType": "reload",
146
- "data": {
147
- "name": `\${record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
148
- "_master.record": `\${record}`,
149
- // 不清楚reload 如何给对象下的某个key复制, 所以此处重复设置_master的objectName、recordId
150
- "_master.objectName": "${objectName}",
151
- "_master.recordId": "${recordId}"
152
- }
153
- }
154
- ]
155
- }
103
+ body = [
104
+ {
105
+ "type": "steedos-record-detail-header",
106
+ "label": "标题面板",
107
+ "objectApiName": "${objectName}",
108
+ "recordId": "${recordId}"
156
109
  },
157
- }
158
- body.push(amisSchema);
110
+ content
111
+ ];
159
112
  return {
160
- type: 'page',
113
+ type: 'steedos-record-service',
161
114
  id: `page_${objectApiName}_record_detail`,
162
115
  name: getScopeId(objectApiName, "record_detail"),
116
+ objectApiName: "${objectName}",
163
117
  bodyClassName: '',
118
+ className: "object-detail-page",
164
119
  regions: [
165
120
  "body"
166
121
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-plugin-amis",
3
- "version": "2.4.14",
3
+ "version": "2.4.15-beta.2",
4
4
  "main": "package.service.js",
5
5
  "scripts": {
6
6
  "build": "yarn build:tailwind-base && yarn build:tailwind",
@@ -13,7 +13,7 @@
13
13
  "publishConfig": {
14
14
  "access": "public"
15
15
  },
16
- "gitHead": "4a6e702d9416a27901ebd6af26d0d5a399ea49b1",
16
+ "gitHead": "12a38495b498f270c96d571e9fb4216d3df64d49",
17
17
  "devDependencies": {
18
18
  "tailwindcss": "3.2.4"
19
19
  }