@steedos-widgets/amis-lib 1.2.0-beta.0 → 1.2.0-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.
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _$1 from 'lodash';
2
2
  import ___default, { isEmpty, isArray, each, find, endsWith, cloneDeep, includes, get, map, keys, sortBy, compact, toArray, mergeWith, isBoolean, omitBy, isNil, isString, slice, defaultsDeep as defaultsDeep$1, isObject as isObject$1, has, filter, startsWith } from 'lodash';
3
- import isPlainObject from 'lodash/isPlainObject';
4
3
  import { Router as Router$1, getSteedosAuth as getSteedosAuth$1, lookupToAmis as lookupToAmis$1, fetchAPI as fetchAPI$1 } from '@steedos-widgets/amis-lib';
4
+ import isPlainObject from 'lodash/isPlainObject';
5
5
 
6
6
  /*
7
7
  * @Author: baozhoutao@steedos.com
@@ -334,7 +334,7 @@ const getSteedosAuth = () => {
334
334
  * @Author: baozhoutao@steedos.com
335
335
  * @Date: 2022-08-16 17:02:08
336
336
  * @LastEditors: baozhoutao@steedos.com
337
- * @LastEditTime: 2023-03-03 14:52:18
337
+ * @LastEditTime: 2023-04-11 09:57:37
338
338
  * @Description:
339
339
  */
340
340
 
@@ -361,10 +361,11 @@ const Router = {
361
361
  },
362
362
  getObjectDetailPath(props){
363
363
  const {formFactor, appId, objectName, recordId, listViewName, _templateType} = props;
364
+ // var urlParams = new URLSearchParams(window.location.search);
364
365
  // if(objectName === 'instances'){
365
366
  // return `/workflow/space/\${context.tenantId}/\${listName}/${recordId}`;
366
367
  // }
367
- const displayAs = Router.getTabDisplayAs(objectName);
368
+ const displayAs = Router.getTabDisplayAs(objectName); //urlParams.get("display") ||
368
369
  if(_templateType === 'JavaScript'){
369
370
  return `/app/${appId}/${objectName}/view/${recordId}?display=${displayAs}&side_object=<%=item.objectName%>&side_listview_id=<%=item.listName%>`;
370
371
  }
@@ -380,7 +381,7 @@ const Router = {
380
381
  * @Author: baozhoutao@steedos.com
381
382
  * @Date: 2022-05-23 09:53:08
382
383
  * @LastEditors: baozhoutao@steedos.com
383
- * @LastEditTime: 2023-03-09 10:00:44
384
+ * @LastEditTime: 2023-04-10 11:22:54
384
385
  * @Description:
385
386
  */
386
387
 
@@ -575,6 +576,7 @@ async function getFieldTpl (field, options){
575
576
  case 'number':
576
577
  case 'currency':
577
578
  return await getNumberTpl(field);
579
+ case 'percent':
578
580
  case 'formula':
579
581
  case 'summary':
580
582
  return getUiFieldTpl(field)
@@ -607,7 +609,7 @@ async function getFieldsTemplate(fields, expand){
607
609
  if(includes(['time','date','datetime','boolean','number','currency'], field.type)){
608
610
  fieldsName.push(`${field.name}`);
609
611
  }
610
- if(includes(['time','filesize','date','datetime','boolean','number','currency', 'select', 'file', 'image', 'avatar', 'formula', 'summary', 'object', 'grid'], field.type)){
612
+ if(includes(['percent','time','filesize','date','datetime','boolean','number','currency', 'select', 'file', 'image', 'avatar', 'formula', 'summary', 'object', 'grid'], field.type)){
611
613
  displayFields.push(`${field.name}`);
612
614
  }
613
615
  }
@@ -652,11 +654,7 @@ function getRecordPermissionsTemplate(){
652
654
  }
653
655
 
654
656
  async function getFindOneQuery$1(object, recordId, fields, options){
655
- let queryOptions = "";
656
-
657
- if(recordId){
658
- queryOptions = `(filters:["${object.idFieldName}", "=", "${recordId}"])`;
659
- }
657
+ let queryOptions = `(filters:["${object.idFieldName}", "=", "\${recordId}"])`;
660
658
  let alias = "data";
661
659
  if(options){
662
660
  if(options.alias){
@@ -1365,8 +1363,8 @@ var config = {
1365
1363
  /*
1366
1364
  * @Author: baozhoutao@steedos.com
1367
1365
  * @Date: 2022-11-01 15:51:00
1368
- * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
1369
- * @LastEditTime: 2023-03-27 15:42:24
1366
+ * @LastEditors: Please set LastEditors
1367
+ * @LastEditTime: 2023-04-11 13:58:24
1370
1368
  * @Description:
1371
1369
  */
1372
1370
 
@@ -1384,6 +1382,36 @@ const getSchema$4 = async (uiSchema, ctx) => {
1384
1382
  if (payload && payload.schema) {
1385
1383
  formSchema = _.isString(payload.schema) ? JSON.parse(payload.schema) : payload.schema;
1386
1384
  }
1385
+
1386
+ const _master = api.body._master;
1387
+ if(_master && _master._isRelated){
1388
+ const relatedKey = _master.relatedKey;
1389
+ const masterObjectName = _master.objectName;
1390
+ const recordId = _master.recordId;
1391
+ let relatedKeySaveValue = recordId;
1392
+ const fields = ${JSON.stringify(uiSchema.fields)};
1393
+ const relatedField = fields[relatedKey];
1394
+ if(relatedField.reference_to_field && relatedField.reference_to_field !== '_id'){
1395
+ relatedKeySaveValue = _master.record[relatedField.reference_to_field];
1396
+ }
1397
+ let defaultData = {};
1398
+ let relatedKeyValue;
1399
+ if(!_.isString(relatedField.reference_to)){
1400
+ relatedKeyValue = { o: masterObjectName, ids: [relatedKeySaveValue] };
1401
+ }else if (relatedField.multiple) {
1402
+ relatedKeyValue = [relatedKeySaveValue];
1403
+ } else {
1404
+ relatedKeyValue = relatedKeySaveValue;
1405
+ }
1406
+ defaultData[relatedKey]=relatedKeyValue;
1407
+ if(payload.schema){
1408
+ // 表单微页面第一层要求是page
1409
+ formSchema.data.defaultData = defaultData;
1410
+ }else{
1411
+ formSchema.defaultData = defaultData;
1412
+ }
1413
+ }
1414
+
1387
1415
  return {
1388
1416
  data: formSchema
1389
1417
  };
@@ -1407,7 +1435,8 @@ const getSchema$4 = async (uiSchema, ctx) => {
1407
1435
  "data": {
1408
1436
  "$master": "$$",
1409
1437
  "_master": "${_master}",
1410
- "defaultData": "${defaultData}",
1438
+ "_master._isRelated": "${_isRelated}",
1439
+ "_master.relatedKey": "${relatedKey}",
1411
1440
  "appId": "${appId}",
1412
1441
  "objectName": "${objectName}",
1413
1442
  "context": "${context}",
@@ -1425,7 +1454,8 @@ const getSchema$4 = async (uiSchema, ctx) => {
1425
1454
  "messages": {},
1426
1455
  "schemaApi": {
1427
1456
  "data": {
1428
- "isLookup": "${isLookup}"
1457
+ "isLookup": "${isLookup}",
1458
+ "_master": "${_master}"
1429
1459
  },
1430
1460
  "url": "${context.rootUrl}/api/pageSchema/form?app=${appId}&objectApiName=${objectName}&formFactor=${formFactor}",
1431
1461
  "method": "get",
@@ -1463,7 +1493,7 @@ const getSchema$4 = async (uiSchema, ctx) => {
1463
1493
  * @Author: baozhoutao@steedos.com
1464
1494
  * @Date: 2022-07-13 15:18:03
1465
1495
  * @LastEditors: baozhoutao@steedos.com
1466
- * @LastEditTime: 2022-11-08 09:35:03
1496
+ * @LastEditTime: 2023-04-11 10:34:26
1467
1497
  * @Description:
1468
1498
  */
1469
1499
 
@@ -1471,6 +1501,13 @@ async function getPage({type, pageId = '', appId, objectName = '', recordId = ''
1471
1501
  const api = `/api/pageSchema/${type}?app=${appId}&objectApiName=${objectName}&recordId=${recordId}&pageId=${pageId}&formFactor=${formFactor}`;
1472
1502
  const page = await fetchAPI(api);
1473
1503
  if (page && page.schema) {
1504
+ page.schema = JSON.parse(page.schema);
1505
+ if(page.schema.data){
1506
+ delete page.schema.data.recordId;
1507
+ delete page.schema.data.objectName;
1508
+ delete page.schema.data.context;
1509
+ delete page.schema.data.global;
1510
+ }
1474
1511
  return page;
1475
1512
  }
1476
1513
  }
@@ -1548,8 +1585,8 @@ const getSchema$3 = async (uiSchema, ctx) => {
1548
1585
  /*
1549
1586
  * @Author: 殷亮辉 yinlianghui@hotoa.com
1550
1587
  * @Date: 2023-03-22 09:31:21
1551
- * @LastEditors: Please set LastEditors
1552
- * @LastEditTime: 2023-03-28 14:06:47
1588
+ * @LastEditors: baozhoutao@steedos.com
1589
+ * @LastEditTime: 2023-04-06 16:04:20
1553
1590
  */
1554
1591
  const getSchema$2 = (uiSchema)=>{
1555
1592
  return {
@@ -1579,15 +1616,11 @@ const getSchema$2 = (uiSchema)=>{
1579
1616
  },
1580
1617
  "adaptor": `
1581
1618
  if(payload.errors){
1582
- payload.status = 2;
1583
- payload.msg = payload.errors[0].message;
1619
+ payload.status = 2;
1620
+ payload.msg = window.t ? window.t(payload.errors[0].message) : payload.errors[0].message;
1584
1621
  }
1585
1622
  return payload;
1586
1623
  `,
1587
- },
1588
- "messages": {
1589
- "success": "删除成功",
1590
- "failed": "删除失败"
1591
1624
  }
1592
1625
  },
1593
1626
  "actionType": "ajax"
@@ -1950,7 +1983,7 @@ const StandardButtons = {
1950
1983
  getStandardNew: async (uiSchema, ctx)=>{
1951
1984
  return {
1952
1985
  type: 'amis_button',
1953
- amis_schema: await getSchema$4()
1986
+ amis_schema: await getSchema$4(uiSchema)
1954
1987
  }
1955
1988
  },
1956
1989
  getStandardEdit: async (uiSchema, ctx)=>{
@@ -2034,7 +2067,7 @@ function getButtonVisibleOn$1(button){
2034
2067
  if(visible.trim().startsWith('function')){
2035
2068
  return `${visible}.apply({
2036
2069
  object: uiSchema
2037
- }, [objectName, _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`
2070
+ }, [objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`
2038
2071
  }
2039
2072
  return visible;
2040
2073
  }
@@ -3164,9 +3197,8 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3164
3197
 
3165
3198
  let body = [
3166
3199
  {
3167
- "type": "service",
3168
- "id": `page_readonly_${name}_header`,
3169
- data: { "&":"$$", objectName: name, _id: recordId, recordPermissions: "${record.recordPermissions}", uiSchema: objectSchema},
3200
+ "type": "wrapper",
3201
+ "className": "p-0",
3170
3202
  "body": [
3171
3203
  {
3172
3204
  "type": "grid",
@@ -3174,14 +3206,14 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3174
3206
  "className": "flex justify-between"
3175
3207
  }
3176
3208
  ],
3177
- "messages": {},
3178
3209
  "hiddenOn": "${recordLoaded != true}"
3179
3210
  }
3180
3211
  ];
3181
3212
 
3182
3213
  if(showRecordTitle){
3183
3214
  body.push({
3184
- "type": "service",
3215
+ "type": "wrapper",
3216
+ "className": "p-0",
3185
3217
  "body": [
3186
3218
  {
3187
3219
  "type": "grid",
@@ -3189,16 +3221,15 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3189
3221
  "className": "flex justify-between"
3190
3222
  }
3191
3223
  ],
3192
- "messages": {},
3193
3224
  "hiddenOn": "${recordLoaded == true}"
3194
3225
  });
3195
3226
  }
3196
3227
 
3197
3228
  return {
3198
3229
  type: 'service',
3199
- bodyClassName: '',
3230
+ id: `page_readonly_${name}_header`,
3200
3231
  name: `page`,
3201
- data: { "&":"$$", objectName: name, _id: recordId, recordPermissions: objectSchema.permissions, uiSchema: objectSchema, record: "${record}"},
3232
+ data: { objectName: name, _id: recordId, recordPermissions: objectSchema.permissions, uiSchema: objectSchema, record: "${record}" },
3202
3233
  body: body,
3203
3234
  className: ''
3204
3235
  }
@@ -3253,7 +3284,7 @@ async function getObjectRecordDetailRelatedListHeader(relatedObjectSchema, relat
3253
3284
  "body": [
3254
3285
  {
3255
3286
  "type": "tpl",
3256
- "tpl": `<a class="text-black text-base font-bold" href="/app/\${appId}/\${masterObjectName}/\${masterRecordId}/\${objectName}/grid?related_field_name=\${relatedKey}">${relatedLabel}(\${$count})</a>`,
3287
+ "tpl": `<a class="text-black text-base font-bold" href="/app/\${appId}/\${_master.objectName}/\${_master.recordId}/\${objectName}/grid?related_field_name=\${relatedKey}">${relatedLabel}(\${$count})</a>`,
3257
3288
  "inline": false,
3258
3289
  "wrapperComponent": "",
3259
3290
  "className": "",
@@ -3294,17 +3325,22 @@ async function getObjectRecordDetailRelatedListHeader(relatedObjectSchema, relat
3294
3325
  async function getObjectRelatedListHeader(objectSchema, recordId, relatedObjectName) {
3295
3326
  }
3296
3327
 
3297
- const getDisplayAsButton = function(showDisplayAs){
3328
+ const getDisplayAsButton = function(objectName, showDisplayAs){
3329
+ let displayAs = Router$1.getTabDisplayAs(objectName);
3298
3330
  let buttons = [
3299
3331
  {
3300
3332
  "type": "button",
3301
3333
  "label": "表格",
3302
- "onClick": "const url = document.location.pathname + '?display=grid'; props.env.jumpTo(url);"
3334
+ "onClick": "let url = document.location.pathname; var urlSearch = new URLSearchParams(document.location.search); if(urlSearch.get(\"side_object\") && urlSearch.get(\"side_listview_id\")){url=`/app/${props.data.appId}/${urlSearch.get(\"side_object\")}/grid/${urlSearch.get(\"side_listview_id\")}`;}; props.env.jumpTo(url + '?display=grid');",
3335
+ "rightIcon": displayAs != 'split' ? "fa fa-check" : null,
3336
+ "rightIconClassName": "m-l-sm"
3303
3337
  },
3304
3338
  {
3305
3339
  "type": "button",
3306
3340
  "label": "分栏视图",
3307
- "onClick": "const url = document.location.pathname + '?display=split'; props.env.jumpTo(url);"
3341
+ "onClick": "const url = document.location.pathname + '?display=split'; props.env.jumpTo(url);",
3342
+ "rightIcon": displayAs === 'split' ? "fa fa-check" : null,
3343
+ "rightIconClassName": "m-l-sm"
3308
3344
  }
3309
3345
  ];
3310
3346
  return {
@@ -3446,7 +3482,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3446
3482
  }
3447
3483
  }
3448
3484
  },
3449
- showDisplayAs? getDisplayAsButton() : {}
3485
+ showDisplayAs? getDisplayAsButton(mainObject?.name) : {}
3450
3486
  ]
3451
3487
  }else {
3452
3488
  return [
@@ -3527,7 +3563,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3527
3563
  }
3528
3564
  }
3529
3565
  },
3530
- showDisplayAs? getDisplayAsButton() : {}
3566
+ showDisplayAs? getDisplayAsButton(showDisplayAs) : {}
3531
3567
  // {
3532
3568
  // "type": "search-box",
3533
3569
  // "align": "right",
@@ -3817,13 +3853,14 @@ function getLookupSapceUserTreeSchema(){
3817
3853
  "headers": {
3818
3854
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
3819
3855
  },
3820
- "adaptor": " const records = payload.data.options;\n const treeRecords = [];\n const getChildren = (records, childrenIds) => {\n if (!childrenIds) {\n return;\n }\n const children = _.filter(records, (record) => {\n return _.includes(childrenIds, record.value)\n });\n _.each(children, (item) => {\n if (item.children) {\n item.children = getChildren(records, item.children)\n }\n })\n return children;\n }\n\n const getRoot = (records) => {\n for (var i = 0; i < records.length; i++){\n records[i].noParent = 0;\n if (!!records[i].parent) {\n biaozhi = 1\n for (var j = 0; j < records.length; j++){\n if (records[i].parent == records[j].value)\n biaozhi = 0;\n }\n if (biaozhi == 1) records[i].noParent = 1;\n } else records[i].noParent = 1;\n }\n }\n getRoot(records);\n console.log(records)\n\n _.each(records, (record) => {\n if (record.noParent ==1) {\n treeRecords.push(Object.assign({}, record, { children: getChildren(records, record.children) }));\n }\n });\n console.log(treeRecords)\n\n payload.data.options = treeRecords;\n return payload;\n ",
3856
+ "adaptor": "if (payload.data.treeCache == true) {\n return payload;\n }\n const records = payload.data.options;\n const treeRecords = [];\n const getChildren = (records, childrenIds) => {\n if (!childrenIds) {\n return;\n }\n const children = _.filter(records, (record) => {\n return _.includes(childrenIds, record.value)\n });\n _.each(children, (item) => {\n if (item.children) {\n item.children = getChildren(records, item.children)\n }\n })\n return children;\n }\n\n const getRoot = (records) => {\n for (var i = 0; i < records.length; i++){\n records[i].noParent = 0;\n if (!!records[i].parent) {\n biaozhi = 1\n for (var j = 0; j < records.length; j++){\n if (records[i].parent == records[j].value)\n biaozhi = 0;\n }\n if (biaozhi == 1) records[i].noParent = 1;\n } else records[i].noParent = 1;\n }\n }\n getRoot(records);\n console.log(records)\n\n _.each(records, (record) => {\n if (record.noParent ==1) {\n treeRecords.push(Object.assign({}, record, { children: getChildren(records, record.children) }));\n }\n });\n console.log(treeRecords)\n\n payload.data.options = treeRecords;\n payload.data.treeCache = true;\n return payload;\n ",
3821
3857
  "requestAdaptor": "\n ",
3822
3858
  "data": {
3823
3859
  "query": "{options:organizations(filters:[\"hidden\", \"!=\", true],sort:\"sort_no desc\"){value:_id label:name,parent,children}}"
3824
3860
  },
3825
3861
  "messages": {
3826
- }
3862
+ },
3863
+ "cache": 300000
3827
3864
  },
3828
3865
  "onEvent": {
3829
3866
  "change": {
@@ -4214,20 +4251,20 @@ async function lookupToAmisSelect(field, readonly, ctx){
4214
4251
 
4215
4252
  if(referenceTo){
4216
4253
  // 字段值单独走一个请求合并到source的同一个GraphQL接口中
4217
- const defaultValueOptionsQueryData = await getFindQuery({ name: referenceTo.objectName }, null, {
4218
- [referenceTo.labelField.name]: Object.assign({}, referenceTo.labelField, {alias: 'label'}),
4219
- [referenceTo.valueField.name]: Object.assign({}, referenceTo.valueField, {alias: 'value'})
4220
- }, {
4254
+ const defaultValueOptionsQueryData = await getFindQuery({ name: referenceTo.objectName }, null, [
4255
+ Object.assign({}, referenceTo.labelField, {alias: 'label'}),
4256
+ Object.assign({}, referenceTo.valueField, {alias: 'value'})
4257
+ ], {
4221
4258
  alias: "defaultValueOptions",
4222
4259
  filters: "{__options_filters}",
4223
4260
  count: false
4224
4261
  });
4225
4262
  apiInfo = await getApi$1({
4226
4263
  name: referenceTo.objectName
4227
- }, null, {
4228
- [referenceTo.labelField.name]: Object.assign({}, referenceTo.labelField, {alias: 'label'}),
4229
- [referenceTo.valueField.name]: Object.assign({}, referenceTo.valueField, {alias: 'value'})
4230
- }, {expand: false, alias: 'options', queryOptions: `filters: {__filters}, top: {__top}, sort: "{__sort}"`, moreQueries: [defaultValueOptionsQueryData.query]});
4264
+ }, null, [
4265
+ Object.assign({}, referenceTo.labelField, {alias: 'label'}),
4266
+ Object.assign({}, referenceTo.valueField, {alias: 'value'})
4267
+ ], {expand: false, alias: 'options', queryOptions: `filters: {__filters}, top: {__top}, sort: "{__sort}"`, moreQueries: [defaultValueOptionsQueryData.query]});
4231
4268
 
4232
4269
  apiInfo.adaptor = `
4233
4270
  const data = payload.data;
@@ -5388,8 +5425,9 @@ function getReadonlyFormAdaptor(fields){
5388
5425
  async function getReadonlyFormInitApi(object, recordId, fields, options){
5389
5426
  return {
5390
5427
  method: "post",
5391
- url: getApi$2()+"?rf="+ (new Date()).getTime(),
5428
+ url: getApi$2()+"&recordId=${recordId}",
5392
5429
  cache: API_CACHE,
5430
+ // requestAdaptor: "console.log('getReadonlyFormInitApi requestAdaptor', api);return api;",
5393
5431
  adaptor: getReadonlyFormAdaptor(fields),
5394
5432
  data: await getFindOneQuery$1(object, recordId, fields, options),
5395
5433
  headers: {
@@ -5496,6 +5534,7 @@ async function getEditFormInitApi(object, recordId, fields, options){
5496
5534
  data.global = "${global}";
5497
5535
  data.context = "${context}";
5498
5536
  data.defaultData = "${defaultData}";
5537
+
5499
5538
  return {
5500
5539
  method: "post",
5501
5540
  url: getApi$2(),
@@ -5864,7 +5903,7 @@ async function getObjectCRUD(objectSchema, fields, options){
5864
5903
  keepItemSelectionOnPageChange: true,
5865
5904
  api: await getTableApi(objectSchema, fields, options),
5866
5905
  hiddenOn: options.tableHiddenOn,
5867
- autoFillHeight: true,
5906
+ autoFillHeight: options.isRelated ? false : true,
5868
5907
  className: `flex-auto ${crudClassName || ""}`,
5869
5908
  crudClassName: crudClassName,
5870
5909
  },
@@ -5907,11 +5946,11 @@ async function getObjectCRUD(objectSchema, fields, options){
5907
5946
  id: `service_${id}`,
5908
5947
  name: `page`,
5909
5948
  data: {
5910
- objectName: objectSchema.name,
5911
- _id: null,
5949
+ // objectName: objectSchema.name,
5950
+ // _id: null,
5912
5951
  recordPermissions: objectSchema.permissions,
5913
5952
  uiSchema: objectSchema,
5914
- loaded: false //crud接收适配器中设置为true,否则就是刷新浏览器第一次加载
5953
+ // loaded: false //crud接收适配器中设置为true,否则就是刷新浏览器第一次加载
5915
5954
  },
5916
5955
  body: body
5917
5956
  }
@@ -6024,6 +6063,10 @@ async function getObjectForm(objectSchema, ctx){
6024
6063
  "objectName": "${_master.objectName}"
6025
6064
  },
6026
6065
  "expression": `\${_master.objectName != '${objectSchema.name}' && _master.objectName}`
6066
+ },
6067
+ {
6068
+ "args": {},
6069
+ "actionType": "closeDialog"
6027
6070
  }
6028
6071
  ]
6029
6072
  }
@@ -6370,7 +6413,7 @@ function getButtonVisibleOn(button){
6370
6413
  // return 'false';
6371
6414
  // }
6372
6415
  if(visible.trim().startsWith('function')){
6373
- return `${visible}(objectName, _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
6416
+ return `${visible}(objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
6374
6417
  }
6375
6418
  return visible;
6376
6419
  }
@@ -6535,6 +6578,11 @@ async function getTableApi(mainObject, fields, options){
6535
6578
 
6536
6579
  let valueField = mainObject.key_field || '_id';
6537
6580
  const api = await getApi(mainObject, null, fields, {count: options.queryCount, alias: 'rows', limit: top, queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
6581
+
6582
+ if(options.isRelated){
6583
+ api.url += "&recordId=${recordId}";
6584
+ }
6585
+
6538
6586
  api.data.$term = "$term";
6539
6587
  api.data.$self = "$$";
6540
6588
  api.data.filter = "$filter";
@@ -6654,11 +6702,36 @@ async function getTableApi(mainObject, fields, options){
6654
6702
  if(!_.isEmpty(systemFilters)){
6655
6703
  filters = systemFilters;
6656
6704
  };
6657
-
6658
6705
  if(api.data.$self.additionalFilters){
6659
6706
  userFilters.push(api.data.$self.additionalFilters)
6660
6707
  }
6661
6708
 
6709
+ if(api.data.$self._isRelated){
6710
+ const self = api.data.$self;
6711
+ const relatedKey = self.relatedKey;
6712
+ const recordId = self.recordId;
6713
+ const refField = self.uiSchema.fields[relatedKey];
6714
+ const masterRecord = self._master.record;
6715
+ const masterObjectName = self._master.objectName;
6716
+ let relatedValue = recordId;
6717
+ if(refField.reference_to_field && refField.reference_to_field != '_id'){
6718
+ relatedValue = masterRecord[refField.reference_to_field]
6719
+ }
6720
+ let relatedFilters;
6721
+ if (
6722
+ refField._reference_to ||
6723
+ (refField.reference_to && !_.isString(refField.reference_to))
6724
+ ) {
6725
+ relatedFilters = [
6726
+ [relatedKey + "/o", "=", masterObjectName],
6727
+ [relatedKey + "/ids", "=", relatedValue],
6728
+ ];
6729
+ } else {
6730
+ relatedFilters = [relatedKey, "=", relatedValue];
6731
+ }
6732
+ userFilters.push(relatedFilters)
6733
+ }
6734
+
6662
6735
  if(!_.isEmpty(userFilters)){
6663
6736
  if(_.isEmpty(filters)){
6664
6737
  filters = userFilters;
@@ -6781,7 +6854,7 @@ async function getApi(object, recordId, fields, options){
6781
6854
  const data = await getFindQuery(object, recordId, fields, options);
6782
6855
  return {
6783
6856
  method: "post",
6784
- url: getApi$2(),
6857
+ url: getApi$2(), // + "&recordId=${recordId}"
6785
6858
  data: data,
6786
6859
  headers: {
6787
6860
  Authorization: "Bearer ${context.tenantId},${context.authToken}"
@@ -7416,7 +7489,7 @@ const getRecordPermissions = async (objectName, recordId)=>{
7416
7489
  * @Author: baozhoutao@steedos.com
7417
7490
  * @Date: 2022-07-05 15:55:39
7418
7491
  * @LastEditors: Please set LastEditors
7419
- * @LastEditTime: 2023-03-30 17:44:53
7492
+ * @LastEditTime: 2023-04-11 13:13:00
7420
7493
  * @Description:
7421
7494
  */
7422
7495
 
@@ -7488,7 +7561,7 @@ async function getObjectRelatedList(
7488
7561
 
7489
7562
  // 获取单个相关表
7490
7563
  async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObjectName, relatedKey, ctx){
7491
- let { top, perPage, hiddenEmptyTable, appId, relatedLabel, className, columns, sort, filters, visible_on } = ctx;
7564
+ let { top, perPage, appId, relatedLabel, className, columns, sort, filters, visible_on } = ctx;
7492
7565
  // console.log('getRecordDetailRelatedListSchema==>',objectName,recordId,relatedObjectName)
7493
7566
  const relatedObjectUiSchema = await getUISchema(relatedObjectName);
7494
7567
  if(!relatedObjectUiSchema){
@@ -7523,6 +7596,7 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
7523
7596
  relatedKey = mainRelated[relatedObjectName];
7524
7597
  }
7525
7598
  let globalFilter = null;
7599
+ // TODO: refField变量去掉,写到amis运行时脚本中,uiSchema.fields[relatedKey];可以取到
7526
7600
  const refField = await getField(relatedObjectName, relatedKey);
7527
7601
 
7528
7602
  if(!refField){
@@ -7537,24 +7611,22 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
7537
7611
  }
7538
7612
  }
7539
7613
  }
7540
-
7541
- let relatedValue = recordId;
7542
- if(refField.reference_to_field && refField.reference_to_field != '_id'){
7543
- const masterRecord = await getRecord(objectName, recordId, [refField.reference_to_field]);
7544
- relatedValue = masterRecord[refField.reference_to_field];
7545
- }
7614
+ // if(refField.reference_to_field && refField.reference_to_field != '_id'){
7615
+ // const masterRecord = await getRecord(objectName, recordId, [refField.reference_to_field]);
7616
+ // relatedValue = masterRecord[refField.reference_to_field]
7617
+ // }
7546
7618
 
7547
- if (
7548
- refField._reference_to ||
7549
- (refField.reference_to && !isString(refField.reference_to))
7550
- ) {
7551
- globalFilter = [
7552
- [`${relatedKey}/o`, "=", objectName],
7553
- [`${relatedKey}/ids`, "=", relatedValue],
7554
- ];
7555
- } else {
7556
- globalFilter = [`${relatedKey}`, "=", relatedValue];
7557
- }
7619
+ // if (
7620
+ // refField._reference_to ||
7621
+ // (refField.reference_to && !isString(refField.reference_to))
7622
+ // ) {
7623
+ // globalFilter = [
7624
+ // [`${relatedKey}/o`, "=", objectName],
7625
+ // [`${relatedKey}/ids`, "=", relatedValue],
7626
+ // ];
7627
+ // } else {
7628
+ // globalFilter = [`${relatedKey}`, "=", relatedValue];
7629
+ // }
7558
7630
  const recordRelatedListHeader = await getObjectRecordDetailRelatedListHeader(relatedObjectUiSchema, relatedLabel);
7559
7631
  const componentId = `steedos-record-related-list-${relatedObjectName}`;
7560
7632
  const options = {
@@ -7579,9 +7651,9 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
7579
7651
  top: top,
7580
7652
  perPage: perPage,
7581
7653
  setDataToComponentId: componentId,
7582
- tableHiddenOn: hiddenEmptyTable ? "this.$count === 0" : null,
7654
+ // tableHiddenOn: hiddenEmptyTable ? "this.$count === 0" : null,
7583
7655
  appId: appId,
7584
- crudClassName: 'border-t border-slate-300',
7656
+ crudClassName: 'border-t border-slate-300 hidden',
7585
7657
  ...ctx
7586
7658
  };
7587
7659
  const amisSchema= (await getRelatedListSchema(relatedObjectName, 'all', options)).amisSchema;
@@ -7593,33 +7665,14 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
7593
7665
  amisSchema: {
7594
7666
  type: "service",
7595
7667
  id: componentId,
7596
- className: `steedos-record-related-list rounded border border-slate-300 bg-gray-100 mb-4 ${className}`,
7668
+ className: `steedos-record-related-list ${componentId} rounded border border-slate-300 bg-gray-100 mb-4 ${className}`,
7597
7669
  data: {
7598
- "&": "$$",
7599
- appId: "${appId}",
7600
- app_id: "${appId}",
7601
- masterObjectName: objectName,
7602
- masterRecordId: "${recordId}",
7603
7670
  relatedKey: relatedKey,
7604
- objectName: relatedObjectName,
7605
7671
  listViewId: `amis-\${appId}-${relatedObjectName}-listview`,
7606
7672
  _isRelated: true
7607
7673
  },
7608
7674
  body:[
7609
- {
7610
- ...amisSchema,
7611
- data: {
7612
- "&": "$$",
7613
- appId: "${appId}",
7614
- app_id: "${appId}",
7615
- relatedKey: relatedKey,
7616
- objectName: "${objectName}",
7617
- recordId: "${masterRecordId}",
7618
- defaultData: {
7619
- ...{[relatedKey]: getRelatedFieldValue(objectName, relatedValue, relatedObjectUiSchema, relatedKey)}
7620
- }
7621
- }
7622
- }
7675
+ amisSchema
7623
7676
  ]
7624
7677
  }
7625
7678
  };
@@ -7658,13 +7711,13 @@ function getDefaultRelatedListProps(uiSchema, listName, ctx) {
7658
7711
  columns = getListViewColumns(listView, ctx.formFactor);
7659
7712
  sort = getListViewSort(listView);
7660
7713
  filter = getListViewFilter(listView);
7661
- if(isArray(ctx.globalFilter) && ctx.globalFilter.length && isArray(filter) && filter.length){
7662
- // 都有值
7663
- filter = [ctx.globalFilter, 'and', filter];
7664
- }else if(ctx.globalFilter && (!filter || !filter.length)){
7665
- // globalFilter有值,filter无值
7666
- filter = ctx.globalFilter;
7667
- }
7714
+ // if(isArray(ctx.globalFilter) && ctx.globalFilter.length && isArray(filter) && filter.length){
7715
+ // // 都有值
7716
+ // filter = [ctx.globalFilter, 'and', filter]
7717
+ // }else if(ctx.globalFilter && (!filter || !filter.length)){
7718
+ // // globalFilter有值,filter无值
7719
+ // filter = ctx.globalFilter;
7720
+ // }
7668
7721
  filtersFunction = listView && listView._filters;
7669
7722
  }else {
7670
7723
  const isNameField = find(
@@ -7674,9 +7727,9 @@ function getDefaultRelatedListProps(uiSchema, listName, ctx) {
7674
7727
  }
7675
7728
  );
7676
7729
  columns = isNameField ? [isNameField.name] : ['name'];
7677
- if(ctx.globalFilter){
7678
- filter = ctx.globalFilter;
7679
- }
7730
+ // if(ctx.globalFilter){
7731
+ // filter = ctx.globalFilter;
7732
+ // }
7680
7733
  }
7681
7734
 
7682
7735
  return {
@@ -7700,7 +7753,7 @@ function getRelatedListProps(uiSchema, listViewName, ctx) {
7700
7753
  return {
7701
7754
  columns: ctx.columns,
7702
7755
  sort,
7703
- filter: ctx.globalFilter,
7756
+ // filter: ctx.globalFilter,
7704
7757
  filtersFunction: filtersFunction
7705
7758
  }
7706
7759
  } else {
@@ -7739,6 +7792,16 @@ async function getRelatedListSchema(
7739
7792
  delete ctx.filters;
7740
7793
 
7741
7794
  delete ctx.globalFilter;
7795
+
7796
+ const adaptor = `
7797
+ if(setDataToComponentId){
7798
+ if(payload.data.count){
7799
+ setTimeout(function(){
7800
+ window.$("." + setDataToComponentId + " .antd-Crud").removeClass("hidden");
7801
+ }, 10);
7802
+ }
7803
+ };
7804
+ `;
7742
7805
  const amisSchema = {
7743
7806
  "type": "steedos-object-table",
7744
7807
  "objectApiName": objectName,
@@ -7747,6 +7810,8 @@ async function getRelatedListSchema(
7747
7810
  "filters": listviewFilter,
7748
7811
  "filtersFunction": filtersFunction,
7749
7812
  "sort": listViewSort,
7813
+ "filterVisible": false,
7814
+ adaptor,
7750
7815
  "ctx": ctx
7751
7816
  };
7752
7817
  // console.log(`getRelatedListSchema amisSchema`, amisSchema);
@@ -7759,8 +7824,8 @@ async function getRelatedListSchema(
7759
7824
  /*
7760
7825
  * @Author: baozhoutao@steedos.com
7761
7826
  * @Date: 2022-07-05 15:55:39
7762
- * @LastEditors: baozhoutao@steedos.com
7763
- * @LastEditTime: 2023-03-11 17:02:30
7827
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
7828
+ * @LastEditTime: 2023-04-11 11:28:11
7764
7829
  * @Description:
7765
7830
  */
7766
7831
 
@@ -7932,14 +7997,14 @@ async function getField(objectName, fieldName) {
7932
7997
  async function getFormSchema(objectName, ctx) {
7933
7998
  const uiSchema = await getUISchema(objectName);
7934
7999
  const amisSchema = await getObjectForm(uiSchema, ctx);
7935
- // console.log(`getFormSchema====>`, amisSchema)
8000
+ console.log(`getFormSchema====>`, amisSchema);
7936
8001
  return {
7937
8002
  uiSchema,
7938
8003
  amisSchema,
7939
8004
  };
7940
8005
  }
7941
8006
 
7942
- // 获取只读页面
8007
+ // 获取只读页面 recordId 已废弃, 函数签名保持不变, 但recordId变量不可再使用, 请使用运行时的${recordId}
7943
8008
  async function getViewSchema(objectName, recordId, ctx) {
7944
8009
  const uiSchema = await getUISchema(objectName);
7945
8010
  const amisSchema = await getObjectDetail(uiSchema, recordId, ctx);
@@ -8124,6 +8189,7 @@ async function getTableSchema(
8124
8189
  headerToolbarItems: ctx.headerToolbarItems,
8125
8190
  buttons: await getListViewItemButtons(uiSchema, ctx)
8126
8191
  });
8192
+ // console.log('getTableSchema====>amisSchema', amisSchema)
8127
8193
  return {
8128
8194
  uiSchema,
8129
8195
  amisSchema,
@@ -8208,37 +8274,14 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
8208
8274
  amisSchema: {
8209
8275
  "type": "service",
8210
8276
  "body": [
8211
- {
8212
- "type": "steedos-record-detail-header",
8213
- "label": "标题面板",
8214
- "objectApiName": "${objectName}",
8215
- "recordId": "${recordId}",
8216
- "id": "u:48d2c28eb755",
8217
- onEvent: {
8218
- "recordLoaded": {
8219
- "actions": [
8220
- {
8221
- "actionType": "reload",
8222
- "data": {
8223
- "name": `\${event.data.record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
8224
- "record": `\${event.data.record}`,
8225
- "recordLoaded": true,
8226
- }
8227
- },
8228
- {
8229
- "actionType": "reload",
8230
- "componentId": `page_readonly_${objectName}_header`, //刷新标题, 详细页面header service 嵌套太多, 导致仅刷新第一层service无法更新recordName
8231
- "data": {
8232
- "name": `\${event.data.record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
8233
- "record": `\${event.data.record}`,
8234
- "recordLoaded": true,
8235
- }
8236
- }
8237
- ]
8238
- }
8277
+ {
8278
+ "type": "steedos-record-detail-header",
8279
+ "label": "标题面板",
8280
+ "objectApiName": "${objectName}",
8281
+ "recordId": "${recordId}",
8282
+ "id": "u:48d2c28eb755"
8239
8283
  },
8240
- },
8241
- content
8284
+ content
8242
8285
  ],
8243
8286
  data: {
8244
8287
  "_master.objectName": "${objectName}",
@@ -8265,51 +8308,6 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
8265
8308
  }
8266
8309
  }
8267
8310
 
8268
- // export async function getRecordDetailRelatedListSchema(objectName,recordId,relatedObjectName){
8269
- // // console.log('b==>',objectName,recordId,relatedObjectName)
8270
- // const relatedObjectUiSchema = await getUISchema(relatedObjectName);
8271
- // const { list_views, label , icon, fields } = relatedObjectUiSchema;
8272
- // const firstListViewName = keys(list_views)[0];
8273
- // const relatedKey = findKey(fields, function(field) {
8274
- // return ["lookup","master_detail"].indexOf(field.type) > -1 && field.reference_to === objectName;
8275
- // });
8276
- // const globalFilter = [relatedKey,'=',recordId];
8277
- // const recordRelatedListHeader = await getObjectRecordDetailRelatedListHeader(relatedObjectUiSchema);
8278
- // const options = {
8279
- // globalFilter,
8280
- // defaults: {
8281
- // listSchema: { headerToolbar:[],columnsTogglable:false },
8282
- // headerSchema: recordRelatedListHeader
8283
- // },
8284
- // showHeader: true
8285
- // }
8286
- // const amisSchema= (await getListSchema(null, relatedObjectName, firstListViewName, options)).amisSchema;
8287
- // return {
8288
- // uiSchema: relatedObjectUiSchema,
8289
- // amisSchema: {
8290
- // type: "service",
8291
- // data: {
8292
- // masterObjectName: objectName,
8293
- // masterRecordId: "${recordId}",
8294
- // relatedKey: relatedKey,
8295
- // objectName: relatedObjectName,
8296
- // listViewId: `amis-\${appId}-${relatedObjectName}-listview`,
8297
- // },
8298
- // body:[
8299
- // {
8300
- // ...amisSchema,
8301
- // data: {
8302
- // filter: ["${relatedKey}", "=", "${masterRecordId}"],
8303
- // objectName: "${objectName}",
8304
- // recordId: "${masterRecordId}",
8305
- // ...{[relatedKey]: getRelatedFieldValue(objectName, "${recordId}", relatedSchema.uiSchema, relatedKey)}
8306
- // }
8307
- // }
8308
- // ]
8309
- // }
8310
- // };
8311
- // }
8312
-
8313
8311
 
8314
8312
  // 获取单个相关表
8315
8313
  async function getObjectRelated(