@steedos/service-plugin-amis 2.4.14 → 2.4.15-beta.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.
@@ -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
  })();
@@ -161,13 +161,24 @@
161
161
  },
162
162
  {
163
163
  "name": "showSidebar",
164
- "label": "菜单显示在左侧",
164
+ "label": "显示左侧导航",
165
165
  "type": "checkbox",
166
166
  "tpl": null,
167
167
  "className": "m-0",
168
168
  "labelClassName": "text-left",
169
169
  "id": "u:07a8a4c5f877"
170
170
  },
171
+ {
172
+ "name": "enable_nav_schema",
173
+ "label": "启用自定义导航",
174
+ "required": false,
175
+ "type": "checkbox",
176
+ "tpl": null,
177
+ "className": "m-0",
178
+ "labelClassName": "text-left",
179
+ "clearValueOnHidden": true,
180
+ "fieldName": "enable_nav_schema"
181
+ },
171
182
  {
172
183
  "name": "description",
173
184
  "label": "描述",
@@ -31,7 +31,7 @@
31
31
  "method": "post",
32
32
  "url": "${context.rootUrl}/graphql?rf=1653731141728",
33
33
  "cache": 100,
34
- "adaptor": "const recordId = api.body.recordId;\nvar data;\nif (recordId) {\n console.log('recordId==>', recordId)\n data = payload.data.data[0] || { _filters_type_controller: 'conditions' };\n //数据格式转换\n if (data) {\n data.columns = lodash.map(data.columns, 'field');\n data.sort = lodash.map(data.sort, (item) => {\n return `${item.field_name}:${item.order || 'asc'}`\n });\n data.mobile_columns = lodash.map(data.mobile_columns, 'field');\n data.searchable_fields = lodash.map(data.searchable_fields, 'field');\n\n if (data.filters && lodash.isString(data.filters)) {\n try {\n data.filters = JSON.parse(data.filters);\n } catch (e) { }\n }\n\n if (data.filters && lodash.isString(data.filters)) {\n data._filters_type_controller = 'function';\n } else {\n data._filters_type_controller = 'conditions'\n }\n\n if (data._filters_type_controller === 'conditions') {\n data._filters_conditions = window.amisConvert.filtersToConditions(data.filters || []);\n } else {\n data._filters_function = data.filters;\n }\n }\n} else {\n const defaultData = api.body.defaultData;\n let defaultValues = {};\n // TODO:字段默认值后期添加\n if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){\n data = Object.assign({}, defaultValues, defaultData)\n }\n}\nfor (key in data) {\n if (data[key] === null) {\n delete data[key];\n }\n}\npayload.data = data;\ndelete payload.extensions;\nreturn payload;",
34
+ "adaptor": "const recordId = api.body.recordId;\nvar data;\nif (recordId) {\n data = payload.data.data[0] || { _filters_type_controller: 'conditions' };\n //数据格式转换\n if (data) {\n data.columns = lodash.map(data.columns, 'field');\n data.sort = lodash.map(data.sort, (item) => {\n return `${item.field_name}:${item.order || 'asc'}`\n });\n data.mobile_columns = lodash.map(data.mobile_columns, 'field');\n data.searchable_fields = lodash.map(data.searchable_fields, 'field');\n\n if (data.filters && lodash.isString(data.filters)) {\n try {\n data.filters = JSON.parse(data.filters);\n } catch (e) { }\n }\n\n if (data.filters && lodash.isString(data.filters)) {\n data._filters_type_controller = 'function';\n } else {\n data._filters_type_controller = 'conditions'\n }\n\n if (data._filters_type_controller === 'conditions') {\n data._filters_conditions = window.amisConvert.filtersToConditions(data.filters || []);\n } else {\n data._filters_function = data.filters;\n }\n }\n} else {\n const defaultData = api.body.defaultData;\n let defaultValues = {};\n // TODO:字段默认值后期添加\n if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){\n data = Object.assign({}, defaultValues, defaultData)\n }\n}\nfor (key in data) {\n if (data[key] === null) {\n delete data[key];\n }\n}\npayload.data = data;\ndelete payload.extensions;\nreturn payload;",
35
35
  "data": {
36
36
  "recordId": "${recordId}",
37
37
  "defaultData": "${defaultData}",
@@ -197,6 +197,7 @@
197
197
  "headers": {
198
198
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
199
199
  },
200
+ "cache": 10000,
200
201
  "data": null,
201
202
  "requestAdaptor": "",
202
203
  "adaptor": "",
@@ -233,6 +234,7 @@
233
234
  "headers": {
234
235
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
235
236
  },
237
+ "cache": 10000,
236
238
  "data": null,
237
239
  "requestAdaptor": "",
238
240
  "adaptor": "",
@@ -380,6 +382,7 @@
380
382
  "headers": {
381
383
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
382
384
  },
385
+ "cache": 10000,
383
386
  "data": null,
384
387
  "requestAdaptor": "",
385
388
  "adaptor": "",
@@ -424,6 +427,7 @@
424
427
  "headers": {
425
428
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
426
429
  },
430
+ "cache": 10000,
427
431
  "data": null,
428
432
  "requestAdaptor": "",
429
433
  "adaptor": "",
@@ -34,7 +34,7 @@
34
34
  "data": {
35
35
  "recordId": "${recordId}",
36
36
  "defaultData": "${defaultData}",
37
- "query": "{data:object_layouts(filters:[\"_id\", \"=\", \"${recordId}\"]){_id,name,label,object_name,profiles,buttons,fields,related_lists,is_system,created,created_by,modified,modified_by,instances,instance_state,_display:_ui{object_name,profiles,buttons,fields,related_lists,is_system,created,created_by,modified,modified_by,instances,instance_state}}}",
37
+ "query": "{data:object_layouts(filters:[\"_id\", \"=\", \"${recordId}\"]){_id,name,label,object_name,profiles,buttons,fields,related_lists,field_groups,is_system,created,created_by,modified,modified_by,instances,instance_state,_display:_ui{object_name,profiles,buttons,fields,related_lists,is_system,created,created_by,modified,modified_by,instances,instance_state}}}",
38
38
  "uiSchema": "${uiSchema}",
39
39
  "objectName": "${objectName}"
40
40
  },
@@ -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.10",
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": "c04650f172e77e9d719f2f6c6b23cf1a9a199b92",
17
17
  "devDependencies": {
18
18
  "tailwindcss": "3.2.4"
19
19
  }
@@ -87,3 +87,7 @@
87
87
  .ant-message{
88
88
  z-index: 2600;
89
89
  }
90
+
91
+ .antd-Form-item.p-0{
92
+ padding: 0;
93
+ }
@@ -46,37 +46,6 @@
46
46
  position: static
47
47
  }
48
48
 
49
- .fixed {
50
- position: fixed
51
- }
52
-
53
- .absolute {
54
- position: absolute
55
- }
56
-
57
- .sticky {
58
- position: sticky
59
- }
60
-
61
- .inset-0 {
62
- top: 0px;
63
- right: 0px;
64
- bottom: 0px;
65
- left: 0px
66
- }
67
-
68
- .top-0 {
69
- top: 0px
70
- }
71
-
72
- .z-40 {
73
- z-index: 40
74
- }
75
-
76
- .z-20 {
77
- z-index: 20
78
- }
79
-
80
49
  .col-span-2 {
81
50
  grid-column: span 2 / span 2
82
51
  }
@@ -108,18 +77,6 @@
108
77
  margin-right: -2.75rem
109
78
  }
110
79
 
111
- .mr-4 {
112
- margin-right: 1rem
113
- }
114
-
115
- .mb-\[-3px\] {
116
- margin-bottom: -3px
117
- }
118
-
119
- .mt-\[50px\] {
120
- margin-top: 50px
121
- }
122
-
123
80
  .mt-0\.5 {
124
81
  margin-top: 0.125rem
125
82
  }
@@ -140,6 +97,14 @@
140
97
  margin-top: 0.75rem
141
98
  }
142
99
 
100
+ .mb-0 {
101
+ margin-bottom: 0px
102
+ }
103
+
104
+ .ml-2 {
105
+ margin-left: 0.5rem
106
+ }
107
+
143
108
  .block {
144
109
  display: block
145
110
  }
@@ -172,26 +137,6 @@
172
137
  height: 100%
173
138
  }
174
139
 
175
- .h-\[50px\] {
176
- height: 50px
177
- }
178
-
179
- .h-10 {
180
- height: 2.5rem
181
- }
182
-
183
- .w-full {
184
- width: 100%
185
- }
186
-
187
- .w-auto {
188
- width: auto
189
- }
190
-
191
- .w-64 {
192
- width: 16rem
193
- }
194
-
195
140
  .w-10 {
196
141
  width: 2.5rem
197
142
  }
@@ -200,36 +145,23 @@
200
145
  width: 50%
201
146
  }
202
147
 
148
+ .w-full {
149
+ width: 100%
150
+ }
151
+
203
152
  .min-w-max {
204
153
  min-width: -moz-max-content;
205
154
  min-width: max-content
206
155
  }
207
156
 
208
- .flex-none {
209
- flex: none
210
- }
211
-
212
157
  .flex-1 {
213
158
  flex: 1 1 0%
214
159
  }
215
160
 
216
- .-translate-x-0 {
217
- --tw-translate-x: -0px;
218
- transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))
219
- }
220
-
221
161
  .flex-row {
222
162
  flex-direction: row
223
163
  }
224
164
 
225
- .flex-col {
226
- flex-direction: column
227
- }
228
-
229
- .flex-nowrap {
230
- flex-wrap: nowrap
231
- }
232
-
233
165
  .items-center {
234
166
  align-items: center
235
167
  }
@@ -238,53 +170,14 @@
238
170
  justify-content: center
239
171
  }
240
172
 
241
- .justify-between {
242
- justify-content: space-between
243
- }
244
-
245
- .gap-x-3 {
246
- -moz-column-gap: 0.75rem;
247
- column-gap: 0.75rem
248
- }
249
-
250
173
  .overflow-auto {
251
174
  overflow: auto
252
175
  }
253
176
 
254
- .overflow-hidden {
255
- overflow: hidden
256
- }
257
-
258
- .overflow-y-auto {
259
- overflow-y: auto
260
- }
261
-
262
- .border-b-\[3px\] {
263
- border-bottom-width: 3px
264
- }
265
-
266
- .border-r {
267
- border-right-width: 1px
268
- }
269
-
270
177
  .border-b {
271
178
  border-bottom-width: 1px
272
179
  }
273
180
 
274
- .border-solid {
275
- border-style: solid
276
- }
277
-
278
- .border-sky-500 {
279
- --tw-border-opacity: 1;
280
- border-color: rgb(14 165 233 / var(--tw-border-opacity))
281
- }
282
-
283
- .border-slate-200 {
284
- --tw-border-opacity: 1;
285
- border-color: rgb(226 232 240 / var(--tw-border-opacity))
286
- }
287
-
288
181
  .border-slate-300 {
289
182
  --tw-border-opacity: 1;
290
183
  border-color: rgb(203 213 225 / var(--tw-border-opacity))
@@ -303,16 +196,6 @@
303
196
  padding: 1rem
304
197
  }
305
198
 
306
- .px-4 {
307
- padding-left: 1rem;
308
- padding-right: 1rem
309
- }
310
-
311
- .px-0 {
312
- padding-left: 0px;
313
- padding-right: 0px
314
- }
315
-
316
199
  .px-1 {
317
200
  padding-left: 0.25rem;
318
201
  padding-right: 0.25rem
@@ -333,28 +216,19 @@
333
216
  padding-bottom: 0.5rem
334
217
  }
335
218
 
336
- .pr-4 {
337
- padding-right: 1rem
338
- }
339
-
340
- .pl-4 {
341
- padding-left: 1rem
342
- }
343
-
344
- .pb-0 {
345
- padding-bottom: 0px
219
+ .py-5 {
220
+ padding-top: 1.25rem;
221
+ padding-bottom: 1.25rem
346
222
  }
347
223
 
348
- .pt-4 {
349
- padding-top: 1rem
224
+ .py-1 {
225
+ padding-top: 0.25rem;
226
+ padding-bottom: 0.25rem
350
227
  }
351
228
 
352
- .pb-24 {
353
- padding-bottom: 6rem
354
- }
355
-
356
- .pb-4 {
357
- padding-bottom: 1rem
229
+ .px-0 {
230
+ padding-left: 0px;
231
+ padding-right: 0px
358
232
  }
359
233
 
360
234
  .pl-1\.5 {
@@ -373,6 +247,18 @@
373
247
  text-align: center
374
248
  }
375
249
 
250
+ .text-lg {
251
+ font-size: 16px
252
+ }
253
+
254
+ .text-xl {
255
+ font-size: 18px
256
+ }
257
+
258
+ .font-bold {
259
+ font-weight: 700
260
+ }
261
+
376
262
  .lowercase {
377
263
  text-transform: lowercase
378
264
  }
@@ -381,10 +267,6 @@
381
267
  font-style: italic
382
268
  }
383
269
 
384
- .leading-5 {
385
- line-height: 1.25rem
386
- }
387
-
388
270
  .leading-none {
389
271
  line-height: 1
390
272
  }
@@ -408,43 +290,11 @@
408
290
  filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)
409
291
  }
410
292
 
411
- .backdrop-blur {
412
- --tw-backdrop-blur: blur(8px);
413
- -webkit-backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);
414
- backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)
415
- }
416
-
417
- .transition-colors {
418
- transition-property: color, background-color, border-color, text-decoration-color, fill, stroke;
419
- transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
420
- transition-duration: 150ms
421
- }
422
-
423
- .duration-500 {
424
- transition-duration: 500ms
425
- }
426
-
427
- .duration-300 {
428
- transition-duration: 300ms
429
- }
430
-
431
- .ease-in-out {
432
- transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1)
433
- }
434
-
435
293
  @media (min-width: 640px) {
436
- .sm\:mt-\[90px\] {
437
- margin-top: 90px
438
- }
439
-
440
294
  .sm\:mt-3 {
441
295
  margin-top: 0.75rem
442
296
  }
443
297
 
444
- .sm\:w-\[220px\] {
445
- width: 220px
446
- }
447
-
448
298
  .sm\:rounded-lg {
449
299
  border-radius: 0.5rem
450
300
  }
@@ -468,9 +318,3 @@
468
318
  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)
469
319
  }
470
320
  }
471
-
472
- @media (min-width: 1024px) {
473
- .lg\:z-50 {
474
- z-index: 50
475
- }
476
- }