@steedos-widgets/amis-lib 1.1.7 → 1.2.0-beta.1

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.cjs.js CHANGED
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _$1 = require('lodash');
6
- var isPlainObject = require('lodash/isPlainObject');
7
6
  var amisLib = require('@steedos-widgets/amis-lib');
7
+ var isPlainObject = require('lodash/isPlainObject');
8
8
 
9
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
10
 
@@ -679,11 +679,7 @@ function getRecordPermissionsTemplate(){
679
679
  }
680
680
 
681
681
  async function getFindOneQuery$1(object, recordId, fields, options){
682
- let queryOptions = "";
683
-
684
- if(recordId){
685
- queryOptions = `(filters:["${object.idFieldName}", "=", "${recordId}"])`;
686
- }
682
+ let queryOptions = `(filters:["${object.idFieldName}", "=", "\${recordId}"])`;
687
683
  let alias = "data";
688
684
  if(options){
689
685
  if(options.alias){
@@ -1392,8 +1388,8 @@ var config = {
1392
1388
  /*
1393
1389
  * @Author: baozhoutao@steedos.com
1394
1390
  * @Date: 2022-11-01 15:51:00
1395
- * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
1396
- * @LastEditTime: 2023-03-27 15:42:24
1391
+ * @LastEditors: Please set LastEditors
1392
+ * @LastEditTime: 2023-04-08 12:05:19
1397
1393
  * @Description:
1398
1394
  */
1399
1395
 
@@ -1411,6 +1407,32 @@ const getSchema$4 = async (uiSchema, ctx) => {
1411
1407
  if (payload && payload.schema) {
1412
1408
  formSchema = _.isString(payload.schema) ? JSON.parse(payload.schema) : payload.schema;
1413
1409
  }
1410
+
1411
+ const _master = api.body._master;
1412
+ if(_master && _master._isRelated){
1413
+ const relatedKey = _master.relatedKey;
1414
+ const masterObjectName = _master.objectName;
1415
+ const recordId = _master.recordId;
1416
+ const fields = ${JSON.stringify(uiSchema.fields)};
1417
+ const relatedField = fields[relatedKey];
1418
+ let defaultData = {};
1419
+ let relatedKeyValue;
1420
+ if(!_.isString(relatedField.reference_to)){
1421
+ relatedKeyValue = { o: masterObjectName, ids: [recordId] };
1422
+ }else if (relatedField.multiple) {
1423
+ relatedKeyValue = [recordId];
1424
+ } else {
1425
+ relatedKeyValue = recordId;
1426
+ }
1427
+ defaultData[relatedKey]=relatedKeyValue;
1428
+ if(payload.schema){
1429
+ // 表单微页面第一层要求是page
1430
+ formSchema.data.defaultData = defaultData;
1431
+ }else{
1432
+ formSchema.defaultData = defaultData;
1433
+ }
1434
+ }
1435
+
1414
1436
  return {
1415
1437
  data: formSchema
1416
1438
  };
@@ -1434,6 +1456,8 @@ const getSchema$4 = async (uiSchema, ctx) => {
1434
1456
  "data": {
1435
1457
  "$master": "$$",
1436
1458
  "_master": "${_master}",
1459
+ "_master._isRelated": "${_isRelated}",
1460
+ "_master.relatedKey": "${relatedKey}",
1437
1461
  "defaultData": "${defaultData}",
1438
1462
  "appId": "${appId}",
1439
1463
  "objectName": "${objectName}",
@@ -1452,7 +1476,8 @@ const getSchema$4 = async (uiSchema, ctx) => {
1452
1476
  "messages": {},
1453
1477
  "schemaApi": {
1454
1478
  "data": {
1455
- "isLookup": "${isLookup}"
1479
+ "isLookup": "${isLookup}",
1480
+ "_master": "${_master}"
1456
1481
  },
1457
1482
  "url": "${context.rootUrl}/api/pageSchema/form?app=${appId}&objectApiName=${objectName}&formFactor=${formFactor}",
1458
1483
  "method": "get",
@@ -1973,7 +1998,7 @@ const StandardButtons = {
1973
1998
  getStandardNew: async (uiSchema, ctx)=>{
1974
1999
  return {
1975
2000
  type: 'amis_button',
1976
- amis_schema: await getSchema$4()
2001
+ amis_schema: await getSchema$4(uiSchema)
1977
2002
  }
1978
2003
  },
1979
2004
  getStandardEdit: async (uiSchema, ctx)=>{
@@ -2057,7 +2082,7 @@ function getButtonVisibleOn$1(button){
2057
2082
  if(visible.trim().startsWith('function')){
2058
2083
  return `${visible}.apply({
2059
2084
  object: uiSchema
2060
- }, [objectName, _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`
2085
+ }, [objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`
2061
2086
  }
2062
2087
  return visible;
2063
2088
  }
@@ -3187,9 +3212,8 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3187
3212
 
3188
3213
  let body = [
3189
3214
  {
3190
- "type": "service",
3191
- "id": `page_readonly_${name}_header`,
3192
- data: { "&":"$$", objectName: name, _id: recordId, recordPermissions: "${record.recordPermissions}", uiSchema: objectSchema},
3215
+ "type": "wrapper",
3216
+ "className": "p-0",
3193
3217
  "body": [
3194
3218
  {
3195
3219
  "type": "grid",
@@ -3197,14 +3221,14 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3197
3221
  "className": "flex justify-between"
3198
3222
  }
3199
3223
  ],
3200
- "messages": {},
3201
3224
  "hiddenOn": "${recordLoaded != true}"
3202
3225
  }
3203
3226
  ];
3204
3227
 
3205
3228
  if(showRecordTitle){
3206
3229
  body.push({
3207
- "type": "service",
3230
+ "type": "wrapper",
3231
+ "className": "p-0",
3208
3232
  "body": [
3209
3233
  {
3210
3234
  "type": "grid",
@@ -3212,16 +3236,15 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3212
3236
  "className": "flex justify-between"
3213
3237
  }
3214
3238
  ],
3215
- "messages": {},
3216
3239
  "hiddenOn": "${recordLoaded == true}"
3217
3240
  });
3218
3241
  }
3219
3242
 
3220
3243
  return {
3221
3244
  type: 'service',
3222
- bodyClassName: '',
3245
+ id: `page_readonly_${name}_header`,
3223
3246
  name: `page`,
3224
- data: { "&":"$$", objectName: name, _id: recordId, recordPermissions: objectSchema.permissions, uiSchema: objectSchema, record: "${record}"},
3247
+ data: { objectName: name, _id: recordId, recordPermissions: objectSchema.permissions, uiSchema: objectSchema, record: "${record}" },
3225
3248
  body: body,
3226
3249
  className: ''
3227
3250
  }
@@ -3276,7 +3299,7 @@ async function getObjectRecordDetailRelatedListHeader(relatedObjectSchema, relat
3276
3299
  "body": [
3277
3300
  {
3278
3301
  "type": "tpl",
3279
- "tpl": `<a class="text-black text-base font-bold" href="/app/\${appId}/\${masterObjectName}/\${masterRecordId}/\${objectName}/grid?related_field_name=\${relatedKey}">${relatedLabel}(\${$count})</a>`,
3302
+ "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>`,
3280
3303
  "inline": false,
3281
3304
  "wrapperComponent": "",
3282
3305
  "className": "",
@@ -3317,17 +3340,22 @@ async function getObjectRecordDetailRelatedListHeader(relatedObjectSchema, relat
3317
3340
  async function getObjectRelatedListHeader(objectSchema, recordId, relatedObjectName) {
3318
3341
  }
3319
3342
 
3320
- const getDisplayAsButton = function(showDisplayAs){
3343
+ const getDisplayAsButton = function(objectName, showDisplayAs){
3344
+ let displayAs = amisLib.Router.getTabDisplayAs(objectName);
3321
3345
  let buttons = [
3322
3346
  {
3323
3347
  "type": "button",
3324
3348
  "label": "表格",
3325
- "onClick": "const url = document.location.pathname + '?display=grid'; props.env.jumpTo(url);"
3349
+ "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');",
3350
+ "rightIcon": displayAs != 'split' ? "fa fa-check" : null,
3351
+ "rightIconClassName": "m-l-sm"
3326
3352
  },
3327
3353
  {
3328
3354
  "type": "button",
3329
3355
  "label": "分栏视图",
3330
- "onClick": "const url = document.location.pathname + '?display=split'; props.env.jumpTo(url);"
3356
+ "onClick": "const url = document.location.pathname + '?display=split'; props.env.jumpTo(url);",
3357
+ "rightIcon": displayAs === 'split' ? "fa fa-check" : null,
3358
+ "rightIconClassName": "m-l-sm"
3331
3359
  }
3332
3360
  ];
3333
3361
  return {
@@ -3469,7 +3497,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3469
3497
  }
3470
3498
  }
3471
3499
  },
3472
- showDisplayAs? getDisplayAsButton() : {}
3500
+ showDisplayAs? getDisplayAsButton(mainObject?.name) : {}
3473
3501
  ]
3474
3502
  }else {
3475
3503
  return [
@@ -3550,7 +3578,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3550
3578
  }
3551
3579
  }
3552
3580
  },
3553
- showDisplayAs? getDisplayAsButton() : {}
3581
+ showDisplayAs? getDisplayAsButton(showDisplayAs) : {}
3554
3582
  // {
3555
3583
  // "type": "search-box",
3556
3584
  // "align": "right",
@@ -3829,6 +3857,90 @@ const getReferenceTo = async (field)=>{
3829
3857
  }
3830
3858
  };
3831
3859
 
3860
+ function getLookupSapceUserTreeSchema(){
3861
+ const tree = [{
3862
+ "type": "input-tree",
3863
+ "className": "",
3864
+ "id": "u:7fd77b7915b0",
3865
+ "source": {
3866
+ "method": "post",
3867
+ "url": "${context.rootUrl}/graphql",
3868
+ "headers": {
3869
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
3870
+ },
3871
+ "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 ",
3872
+ "requestAdaptor": "\n ",
3873
+ "data": {
3874
+ "query": "{options:organizations(filters:[\"hidden\", \"!=\", true],sort:\"sort_no desc\"){value:_id label:name,parent,children}}"
3875
+ },
3876
+ "messages": {
3877
+ },
3878
+ "cache": 300000
3879
+ },
3880
+ "onEvent": {
3881
+ "change": {
3882
+ "actions": [
3883
+ {
3884
+ "actionType": "custom",
3885
+ "script": `
3886
+ debugger;
3887
+ const scope = event.context.scoped;
3888
+ //TODO: 将form中的value一同加入筛选内
3889
+ // var filterForm = scope.parent.parent.getComponents().find(function(n){
3890
+ // return n.props.type === "form";
3891
+ // });
3892
+ // var filterFormValues = filterForm.getValues();
3893
+ filterFormValues={
3894
+ "__searchable__organizations_parents":event.data.value.value
3895
+ }
3896
+ var listView = scope.parent.getComponents().find(function(n){
3897
+ return n.props.type === "crud";
3898
+ });
3899
+ const removedValues = {};
3900
+ // for(var k in filterFormValues){
3901
+ // if(filterFormValues[k] === "" && !filterFormValues.hasOwnProperty(k)){
3902
+ // removedValues[k] = "";
3903
+ // }
3904
+ // }
3905
+ listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
3906
+ `
3907
+ }
3908
+ ]
3909
+ }
3910
+ },
3911
+ "label": "",
3912
+ "name": "organizations",
3913
+ "multiple": false,
3914
+ "joinValues": false,
3915
+ "clearValueOnHidden": false,
3916
+ "fieldName": "organizations",
3917
+ "hideRoot": true,
3918
+ "initiallyOpen": false,
3919
+ "extractValue": true,
3920
+ "onlyChildren": true,
3921
+ "treeContainerClassName": "no-border",
3922
+ "showIcon": false,
3923
+ "enableNodePath": false,
3924
+ "autoCheckChildren": false,
3925
+ "searchable": true,
3926
+ "searchConfig": {
3927
+ "sticky": true
3928
+ },
3929
+ "unfoldedLevel": 2,
3930
+ "style": {
3931
+ "max-height": "100%",
3932
+ "position": "absolute",
3933
+ "left": "-190px",
3934
+ "width": "190px",
3935
+ "bottom": 0,
3936
+ "top": "0",
3937
+ "overflow": "auto",
3938
+ "min-height":"300px"
3939
+ },
3940
+ "originPosition": "left-top"
3941
+ }];
3942
+ return tree;
3943
+ }
3832
3944
 
3833
3945
  async function lookupToAmisPicker(field, readonly, ctx){
3834
3946
  let referenceTo = await getReferenceTo(field);
@@ -4071,7 +4183,16 @@ async function lookupToAmisPicker(field, readonly, ctx){
4071
4183
  ...ctx
4072
4184
  });
4073
4185
 
4074
- pickerSchema.headerToolbar = getObjectHeaderToolbar(refObjectConfig, ctx.formFactor);
4186
+ var headerToolbarItems = [];
4187
+ const isMobile = window.innerWidth < 768;
4188
+ if(referenceTo.objectName === "space_users" && field.reference_to_field === "user" && !isMobile){
4189
+ headerToolbarItems = getLookupSapceUserTreeSchema();
4190
+ pickerSchema["style"] = {
4191
+ "margin-left":"200px",
4192
+ "min-height": "300px"
4193
+ };
4194
+ }
4195
+ pickerSchema.headerToolbar = getObjectHeaderToolbar(refObjectConfig, ctx.formFactor, { headerToolbarItems });
4075
4196
  const isAllowCreate = refObjectConfig.permissions.allowCreate;
4076
4197
  if (isAllowCreate) {
4077
4198
  const new_button = await getSchema$4(refObjectConfig, { appId: ctx.appId, objectName: refObjectConfig.name, formFactor: ctx.formFactor });
@@ -4079,15 +4200,18 @@ async function lookupToAmisPicker(field, readonly, ctx){
4079
4200
  pickerSchema.headerToolbar.push(new_button);
4080
4201
  }
4081
4202
  pickerSchema.footerToolbar = refObjectConfig.enable_tree ? [] : getObjectFooterToolbar();
4082
- if(ctx.filterVisible !== false){
4083
- let filterLoopCount = ctx.filterLoopCount || 0;
4084
- filterLoopCount++;
4085
- // 可以传入filterVisible为false防止死循环
4086
- pickerSchema.filter = await getObjectFilter(refObjectConfig, fields, {
4087
- isLookup: true,
4088
- ...ctx,
4089
- filterLoopCount,
4090
- });
4203
+ //TODO: 等待放大镜bug修复,if会去掉,始终显示放大镜
4204
+ if(referenceTo.objectName != "space_users" || field.reference_to_field != "user"){
4205
+ if (ctx.filterVisible !== false) {
4206
+ let filterLoopCount = ctx.filterLoopCount || 0;
4207
+ filterLoopCount++;
4208
+ // 可以传入filterVisible为false防止死循环
4209
+ pickerSchema.filter = await getObjectFilter(refObjectConfig, fields, {
4210
+ isLookup: true,
4211
+ ...ctx,
4212
+ filterLoopCount,
4213
+ });
4214
+ }
4091
4215
  }
4092
4216
  pickerSchema.data = Object.assign({}, pickerSchema.data, {
4093
4217
  "&": "$$",
@@ -4335,7 +4459,7 @@ async function lookupToAmis(field, readonly, ctx){
4335
4459
  if(ctx.idsDependOn || field.amis){
4336
4460
  return await lookupToAmisIdsPicker(field, readonly, ctx);
4337
4461
  }
4338
- return await lookupToAmisSelectUser(field, readonly, ctx);
4462
+ // return await lookupToAmisSelectUser(field, readonly, ctx);
4339
4463
  }
4340
4464
 
4341
4465
  const refObject = await getUISchema(referenceTo.objectName);
@@ -5316,8 +5440,9 @@ function getReadonlyFormAdaptor(fields){
5316
5440
  async function getReadonlyFormInitApi(object, recordId, fields, options){
5317
5441
  return {
5318
5442
  method: "post",
5319
- url: getApi$2()+"?rf="+ (new Date()).getTime(),
5443
+ url: getApi$2()+"&recordId=${recordId}",
5320
5444
  cache: API_CACHE,
5445
+ // requestAdaptor: "console.log('getReadonlyFormInitApi requestAdaptor', api);return api;",
5321
5446
  adaptor: getReadonlyFormAdaptor(fields),
5322
5447
  data: await getFindOneQuery$1(object, recordId, fields, options),
5323
5448
  headers: {
@@ -5424,6 +5549,7 @@ async function getEditFormInitApi(object, recordId, fields, options){
5424
5549
  data.global = "${global}";
5425
5550
  data.context = "${context}";
5426
5551
  data.defaultData = "${defaultData}";
5552
+
5427
5553
  return {
5428
5554
  method: "post",
5429
5555
  url: getApi$2(),
@@ -5792,7 +5918,7 @@ async function getObjectCRUD(objectSchema, fields, options){
5792
5918
  keepItemSelectionOnPageChange: true,
5793
5919
  api: await getTableApi(objectSchema, fields, options),
5794
5920
  hiddenOn: options.tableHiddenOn,
5795
- autoFillHeight: true,
5921
+ autoFillHeight: options.isRelated ? false : true,
5796
5922
  className: `flex-auto ${crudClassName || ""}`,
5797
5923
  crudClassName: crudClassName,
5798
5924
  },
@@ -5835,11 +5961,11 @@ async function getObjectCRUD(objectSchema, fields, options){
5835
5961
  id: `service_${id}`,
5836
5962
  name: `page`,
5837
5963
  data: {
5838
- objectName: objectSchema.name,
5839
- _id: null,
5964
+ // objectName: objectSchema.name,
5965
+ // _id: null,
5840
5966
  recordPermissions: objectSchema.permissions,
5841
5967
  uiSchema: objectSchema,
5842
- loaded: false //crud接收适配器中设置为true,否则就是刷新浏览器第一次加载
5968
+ // loaded: false //crud接收适配器中设置为true,否则就是刷新浏览器第一次加载
5843
5969
  },
5844
5970
  body: body
5845
5971
  }
@@ -5952,6 +6078,10 @@ async function getObjectForm(objectSchema, ctx){
5952
6078
  "objectName": "${_master.objectName}"
5953
6079
  },
5954
6080
  "expression": `\${_master.objectName != '${objectSchema.name}' && _master.objectName}`
6081
+ },
6082
+ {
6083
+ "args": {},
6084
+ "actionType": "closeDialog"
5955
6085
  }
5956
6086
  ]
5957
6087
  }
@@ -6298,7 +6428,7 @@ function getButtonVisibleOn(button){
6298
6428
  // return 'false';
6299
6429
  // }
6300
6430
  if(visible.trim().startsWith('function')){
6301
- return `${visible}(objectName, _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
6431
+ return `${visible}(objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
6302
6432
  }
6303
6433
  return visible;
6304
6434
  }
@@ -6463,6 +6593,11 @@ async function getTableApi(mainObject, fields, options){
6463
6593
 
6464
6594
  let valueField = mainObject.key_field || '_id';
6465
6595
  const api = await getApi(mainObject, null, fields, {count: options.queryCount, alias: 'rows', limit: top, queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
6596
+
6597
+ if(options.isRelated){
6598
+ api.url += "&recordId=${recordId}";
6599
+ }
6600
+
6466
6601
  api.data.$term = "$term";
6467
6602
  api.data.$self = "$$";
6468
6603
  api.data.filter = "$filter";
@@ -6582,11 +6717,36 @@ async function getTableApi(mainObject, fields, options){
6582
6717
  if(!_.isEmpty(systemFilters)){
6583
6718
  filters = systemFilters;
6584
6719
  };
6585
-
6586
6720
  if(api.data.$self.additionalFilters){
6587
6721
  userFilters.push(api.data.$self.additionalFilters)
6588
6722
  }
6589
6723
 
6724
+ if(api.data.$self._isRelated){
6725
+ const self = api.data.$self;
6726
+ const relatedKey = self.relatedKey;
6727
+ const recordId = self.recordId;
6728
+ const refField = self.uiSchema.fields[relatedKey];
6729
+ const masterRecord = self._master.record;
6730
+ const masterObjectName = self._master.objectName;
6731
+ let relatedValue = recordId;
6732
+ if(refField.reference_to_field && refField.reference_to_field != '_id'){
6733
+ relatedValue = masterRecord[refField.reference_to_field]
6734
+ }
6735
+ let relatedFilters;
6736
+ if (
6737
+ refField._reference_to ||
6738
+ (refField.reference_to && !_.isString(refField.reference_to))
6739
+ ) {
6740
+ relatedFilters = [
6741
+ [relatedKey + "/o", "=", masterObjectName],
6742
+ [relatedKey + "/ids", "=", relatedValue],
6743
+ ];
6744
+ } else {
6745
+ relatedFilters = [relatedKey, "=", relatedValue];
6746
+ }
6747
+ userFilters.push(relatedFilters)
6748
+ }
6749
+
6590
6750
  if(!_.isEmpty(userFilters)){
6591
6751
  if(_.isEmpty(filters)){
6592
6752
  filters = userFilters;
@@ -6709,7 +6869,7 @@ async function getApi(object, recordId, fields, options){
6709
6869
  const data = await getFindQuery(object, recordId, fields, options);
6710
6870
  return {
6711
6871
  method: "post",
6712
- url: getApi$2(),
6872
+ url: getApi$2(), // + "&recordId=${recordId}"
6713
6873
  data: data,
6714
6874
  headers: {
6715
6875
  Authorization: "Bearer ${context.tenantId},${context.authToken}"
@@ -7343,8 +7503,8 @@ const getRecordPermissions = async (objectName, recordId)=>{
7343
7503
  /*
7344
7504
  * @Author: baozhoutao@steedos.com
7345
7505
  * @Date: 2022-07-05 15:55:39
7346
- * @LastEditors: Please set LastEditors
7347
- * @LastEditTime: 2023-03-30 17:44:53
7506
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
7507
+ * @LastEditTime: 2023-04-08 18:14:55
7348
7508
  * @Description:
7349
7509
  */
7350
7510
 
@@ -7416,7 +7576,7 @@ async function getObjectRelatedList(
7416
7576
 
7417
7577
  // 获取单个相关表
7418
7578
  async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObjectName, relatedKey, ctx){
7419
- let { top, perPage, hiddenEmptyTable, appId, relatedLabel, className, columns, sort, filters, visible_on } = ctx;
7579
+ let { top, perPage, appId, relatedLabel, className, columns, sort, filters, visible_on } = ctx;
7420
7580
  // console.log('getRecordDetailRelatedListSchema==>',objectName,recordId,relatedObjectName)
7421
7581
  const relatedObjectUiSchema = await getUISchema(relatedObjectName);
7422
7582
  if(!relatedObjectUiSchema){
@@ -7451,6 +7611,7 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
7451
7611
  relatedKey = mainRelated[relatedObjectName];
7452
7612
  }
7453
7613
  let globalFilter = null;
7614
+ // TODO: refField变量去掉,写到amis运行时脚本中,uiSchema.fields[relatedKey];可以取到
7454
7615
  const refField = await getField(relatedObjectName, relatedKey);
7455
7616
 
7456
7617
  if(!refField){
@@ -7466,23 +7627,23 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
7466
7627
  }
7467
7628
  }
7468
7629
 
7469
- let relatedValue = recordId;
7470
- if(refField.reference_to_field && refField.reference_to_field != '_id'){
7471
- const masterRecord = await getRecord(objectName, recordId, [refField.reference_to_field]);
7472
- relatedValue = masterRecord[refField.reference_to_field];
7473
- }
7630
+ let relatedValue = "${recordId}";
7631
+ // if(refField.reference_to_field && refField.reference_to_field != '_id'){
7632
+ // const masterRecord = await getRecord(objectName, recordId, [refField.reference_to_field]);
7633
+ // relatedValue = masterRecord[refField.reference_to_field]
7634
+ // }
7474
7635
 
7475
- if (
7476
- refField._reference_to ||
7477
- (refField.reference_to && !_$1.isString(refField.reference_to))
7478
- ) {
7479
- globalFilter = [
7480
- [`${relatedKey}/o`, "=", objectName],
7481
- [`${relatedKey}/ids`, "=", relatedValue],
7482
- ];
7483
- } else {
7484
- globalFilter = [`${relatedKey}`, "=", relatedValue];
7485
- }
7636
+ // if (
7637
+ // refField._reference_to ||
7638
+ // (refField.reference_to && !isString(refField.reference_to))
7639
+ // ) {
7640
+ // globalFilter = [
7641
+ // [`${relatedKey}/o`, "=", objectName],
7642
+ // [`${relatedKey}/ids`, "=", relatedValue],
7643
+ // ];
7644
+ // } else {
7645
+ // globalFilter = [`${relatedKey}`, "=", relatedValue];
7646
+ // }
7486
7647
  const recordRelatedListHeader = await getObjectRecordDetailRelatedListHeader(relatedObjectUiSchema, relatedLabel);
7487
7648
  const componentId = `steedos-record-related-list-${relatedObjectName}`;
7488
7649
  const options = {
@@ -7507,9 +7668,9 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
7507
7668
  top: top,
7508
7669
  perPage: perPage,
7509
7670
  setDataToComponentId: componentId,
7510
- tableHiddenOn: hiddenEmptyTable ? "this.$count === 0" : null,
7671
+ // tableHiddenOn: hiddenEmptyTable ? "this.$count === 0" : null,
7511
7672
  appId: appId,
7512
- crudClassName: 'border-t border-slate-300',
7673
+ crudClassName: 'border-t border-slate-300 hidden',
7513
7674
  ...ctx
7514
7675
  };
7515
7676
  const amisSchema= (await getRelatedListSchema(relatedObjectName, 'all', options)).amisSchema;
@@ -7521,15 +7682,9 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
7521
7682
  amisSchema: {
7522
7683
  type: "service",
7523
7684
  id: componentId,
7524
- className: `steedos-record-related-list rounded border border-slate-300 bg-gray-100 mb-4 ${className}`,
7685
+ className: `steedos-record-related-list ${componentId} rounded border border-slate-300 bg-gray-100 mb-4 ${className}`,
7525
7686
  data: {
7526
- "&": "$$",
7527
- appId: "${appId}",
7528
- app_id: "${appId}",
7529
- masterObjectName: objectName,
7530
- masterRecordId: "${recordId}",
7531
7687
  relatedKey: relatedKey,
7532
- objectName: relatedObjectName,
7533
7688
  listViewId: `amis-\${appId}-${relatedObjectName}-listview`,
7534
7689
  _isRelated: true
7535
7690
  },
@@ -7537,12 +7692,6 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
7537
7692
  {
7538
7693
  ...amisSchema,
7539
7694
  data: {
7540
- "&": "$$",
7541
- appId: "${appId}",
7542
- app_id: "${appId}",
7543
- relatedKey: relatedKey,
7544
- objectName: "${objectName}",
7545
- recordId: "${masterRecordId}",
7546
7695
  defaultData: {
7547
7696
  ...{[relatedKey]: getRelatedFieldValue(objectName, relatedValue, relatedObjectUiSchema, relatedKey)}
7548
7697
  }
@@ -7586,13 +7735,13 @@ function getDefaultRelatedListProps(uiSchema, listName, ctx) {
7586
7735
  columns = getListViewColumns(listView, ctx.formFactor);
7587
7736
  sort = getListViewSort(listView);
7588
7737
  filter = getListViewFilter(listView);
7589
- if(_$1.isArray(ctx.globalFilter) && ctx.globalFilter.length && _$1.isArray(filter) && filter.length){
7590
- // 都有值
7591
- filter = [ctx.globalFilter, 'and', filter];
7592
- }else if(ctx.globalFilter && (!filter || !filter.length)){
7593
- // globalFilter有值,filter无值
7594
- filter = ctx.globalFilter;
7595
- }
7738
+ // if(isArray(ctx.globalFilter) && ctx.globalFilter.length && isArray(filter) && filter.length){
7739
+ // // 都有值
7740
+ // filter = [ctx.globalFilter, 'and', filter]
7741
+ // }else if(ctx.globalFilter && (!filter || !filter.length)){
7742
+ // // globalFilter有值,filter无值
7743
+ // filter = ctx.globalFilter;
7744
+ // }
7596
7745
  filtersFunction = listView && listView._filters;
7597
7746
  }else {
7598
7747
  const isNameField = _$1.find(
@@ -7602,9 +7751,9 @@ function getDefaultRelatedListProps(uiSchema, listName, ctx) {
7602
7751
  }
7603
7752
  );
7604
7753
  columns = isNameField ? [isNameField.name] : ['name'];
7605
- if(ctx.globalFilter){
7606
- filter = ctx.globalFilter;
7607
- }
7754
+ // if(ctx.globalFilter){
7755
+ // filter = ctx.globalFilter;
7756
+ // }
7608
7757
  }
7609
7758
 
7610
7759
  return {
@@ -7628,7 +7777,7 @@ function getRelatedListProps(uiSchema, listViewName, ctx) {
7628
7777
  return {
7629
7778
  columns: ctx.columns,
7630
7779
  sort,
7631
- filter: ctx.globalFilter,
7780
+ // filter: ctx.globalFilter,
7632
7781
  filtersFunction: filtersFunction
7633
7782
  }
7634
7783
  } else {
@@ -7667,6 +7816,16 @@ async function getRelatedListSchema(
7667
7816
  delete ctx.filters;
7668
7817
 
7669
7818
  delete ctx.globalFilter;
7819
+
7820
+ const adaptor = `
7821
+ if(setDataToComponentId){
7822
+ if(payload.data.count){
7823
+ setTimeout(function(){
7824
+ window.$("." + setDataToComponentId + " .antd-Crud").removeClass("hidden");
7825
+ }, 10);
7826
+ }
7827
+ };
7828
+ `;
7670
7829
  const amisSchema = {
7671
7830
  "type": "steedos-object-table",
7672
7831
  "objectApiName": objectName,
@@ -7675,6 +7834,8 @@ async function getRelatedListSchema(
7675
7834
  "filters": listviewFilter,
7676
7835
  "filtersFunction": filtersFunction,
7677
7836
  "sort": listViewSort,
7837
+ "filterVisible": false,
7838
+ adaptor,
7678
7839
  "ctx": ctx
7679
7840
  };
7680
7841
  // console.log(`getRelatedListSchema amisSchema`, amisSchema);
@@ -7687,8 +7848,8 @@ async function getRelatedListSchema(
7687
7848
  /*
7688
7849
  * @Author: baozhoutao@steedos.com
7689
7850
  * @Date: 2022-07-05 15:55:39
7690
- * @LastEditors: baozhoutao@steedos.com
7691
- * @LastEditTime: 2023-03-11 17:02:30
7851
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
7852
+ * @LastEditTime: 2023-04-08 17:31:57
7692
7853
  * @Description:
7693
7854
  */
7694
7855
 
@@ -7860,14 +8021,14 @@ async function getField(objectName, fieldName) {
7860
8021
  async function getFormSchema(objectName, ctx) {
7861
8022
  const uiSchema = await getUISchema(objectName);
7862
8023
  const amisSchema = await getObjectForm(uiSchema, ctx);
7863
- // console.log(`getFormSchema====>`, amisSchema)
8024
+ console.log(`getFormSchema====>`, amisSchema);
7864
8025
  return {
7865
8026
  uiSchema,
7866
8027
  amisSchema,
7867
8028
  };
7868
8029
  }
7869
8030
 
7870
- // 获取只读页面
8031
+ // 获取只读页面 recordId 已废弃, 函数签名保持不变, 但recordId变量不可再使用, 请使用运行时的${recordId}
7871
8032
  async function getViewSchema(objectName, recordId, ctx) {
7872
8033
  const uiSchema = await getUISchema(objectName);
7873
8034
  const amisSchema = await getObjectDetail(uiSchema, recordId, ctx);
@@ -8052,6 +8213,7 @@ async function getTableSchema(
8052
8213
  headerToolbarItems: ctx.headerToolbarItems,
8053
8214
  buttons: await getListViewItemButtons(uiSchema, ctx)
8054
8215
  });
8216
+ // console.log('getTableSchema====>amisSchema', amisSchema)
8055
8217
  return {
8056
8218
  uiSchema,
8057
8219
  amisSchema,
@@ -8150,15 +8312,8 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
8150
8312
  "data": {
8151
8313
  "name": `\${event.data.record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
8152
8314
  "record": `\${event.data.record}`,
8153
- "recordLoaded": true,
8154
- }
8155
- },
8156
- {
8157
- "actionType": "reload",
8158
- "componentId": `page_readonly_${objectName}_header`, //刷新标题, 详细页面header service 嵌套太多, 导致仅刷新第一层service无法更新recordName
8159
- "data": {
8160
- "name": `\${event.data.record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
8161
- "record": `\${event.data.record}`,
8315
+ "_id": "\${event.data.record._id}",
8316
+ "recordId": "\${event.data.record._id}",
8162
8317
  "recordLoaded": true,
8163
8318
  }
8164
8319
  }
@@ -8168,10 +8323,10 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
8168
8323
  },
8169
8324
  content
8170
8325
  ],
8171
- data: {
8172
- "_master.objectName": "${objectName}",
8173
- "_master.recordId": "${recordId}"
8174
- },
8326
+ // data: {
8327
+ // "_master.objectName": "${objectName}",
8328
+ // "_master.recordId": "${recordId}"
8329
+ // },
8175
8330
  onEvent: {
8176
8331
  "recordLoaded": {
8177
8332
  "actions": [
@@ -8179,10 +8334,10 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
8179
8334
  "actionType": "reload",
8180
8335
  "data": {
8181
8336
  "name": `\${record.${uiSchema.NAME_FIELD_KEY || 'name'}}`,
8182
- "_master.record": `\${record}`,
8183
- // 不清楚reload 如何给对象下的某个key复制, 所以此处重复设置_master的objectName、recordId
8184
- "_master.objectName": "${objectName}",
8185
- "_master.recordId": "${recordId}"
8337
+ // "_master.record": `\${record}`,
8338
+ // // 不清楚reload 如何给对象下的某个key复制, 所以此处重复设置_master的objectName、recordId
8339
+ // "_master.objectName": "${objectName}",
8340
+ // "_master.recordId": "${recordId}"
8186
8341
  }
8187
8342
  }
8188
8343
  ]
@@ -8193,51 +8348,6 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
8193
8348
  }
8194
8349
  }
8195
8350
 
8196
- // export async function getRecordDetailRelatedListSchema(objectName,recordId,relatedObjectName){
8197
- // // console.log('b==>',objectName,recordId,relatedObjectName)
8198
- // const relatedObjectUiSchema = await getUISchema(relatedObjectName);
8199
- // const { list_views, label , icon, fields } = relatedObjectUiSchema;
8200
- // const firstListViewName = keys(list_views)[0];
8201
- // const relatedKey = findKey(fields, function(field) {
8202
- // return ["lookup","master_detail"].indexOf(field.type) > -1 && field.reference_to === objectName;
8203
- // });
8204
- // const globalFilter = [relatedKey,'=',recordId];
8205
- // const recordRelatedListHeader = await getObjectRecordDetailRelatedListHeader(relatedObjectUiSchema);
8206
- // const options = {
8207
- // globalFilter,
8208
- // defaults: {
8209
- // listSchema: { headerToolbar:[],columnsTogglable:false },
8210
- // headerSchema: recordRelatedListHeader
8211
- // },
8212
- // showHeader: true
8213
- // }
8214
- // const amisSchema= (await getListSchema(null, relatedObjectName, firstListViewName, options)).amisSchema;
8215
- // return {
8216
- // uiSchema: relatedObjectUiSchema,
8217
- // amisSchema: {
8218
- // type: "service",
8219
- // data: {
8220
- // masterObjectName: objectName,
8221
- // masterRecordId: "${recordId}",
8222
- // relatedKey: relatedKey,
8223
- // objectName: relatedObjectName,
8224
- // listViewId: `amis-\${appId}-${relatedObjectName}-listview`,
8225
- // },
8226
- // body:[
8227
- // {
8228
- // ...amisSchema,
8229
- // data: {
8230
- // filter: ["${relatedKey}", "=", "${masterRecordId}"],
8231
- // objectName: "${objectName}",
8232
- // recordId: "${masterRecordId}",
8233
- // ...{[relatedKey]: getRelatedFieldValue(objectName, "${recordId}", relatedSchema.uiSchema, relatedKey)}
8234
- // }
8235
- // }
8236
- // ]
8237
- // }
8238
- // };
8239
- // }
8240
-
8241
8351
 
8242
8352
  // 获取单个相关表
8243
8353
  async function getObjectRelated(
@@ -11131,6 +11241,7 @@ exports.getListViewFilter = getListViewFilter;
11131
11241
  exports.getListViewItemButtons = getListViewItemButtons;
11132
11242
  exports.getListViewSort = getListViewSort;
11133
11243
  exports.getListviewInitSchema = getListviewInitSchema;
11244
+ exports.getLookupSapceUserTreeSchema = getLookupSapceUserTreeSchema;
11134
11245
  exports.getNotifications = getNotifications;
11135
11246
  exports.getObjectDetailButtons = getObjectDetailButtons;
11136
11247
  exports.getObjectDetailMoreButtons = getObjectDetailMoreButtons;