@steedos-widgets/amis-lib 1.1.4-beta.1 → 1.1.4-beta.3

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.umd.js CHANGED
@@ -1046,7 +1046,7 @@
1046
1046
 
1047
1047
  async function getSource$1(field, ctx) {
1048
1048
  // data.query 最终格式 "{ \tleftOptions:organizations(filters: {__filters}){value:_id,label:name,children}, children:organizations(filters: {__filters}){ref:_id,children}, defaultValueOptions:space_users(filters: {__options_filters}){user,name} }"
1049
- const data = await getFindQuery({ name: refOrgsObjectName }, null, [{ name: "_id", alias: "value" }, { name: "name", alias: "label" }, { name: "children" }], {
1049
+ const data = await getFindQuery({ name: refOrgsObjectName }, null, [{ name: "_id", alias: "value" },{name: "parent"}, { name: "name", alias: "label" }, { name: "children" }], {
1050
1050
  alias: "leftOptions",
1051
1051
  filters: "{__filters}"
1052
1052
  });
@@ -1076,7 +1076,7 @@
1076
1076
  // data["&"] = "$$";
1077
1077
 
1078
1078
  const requestAdaptor = `
1079
- var filters = [['parent', '=', null]];
1079
+ var filters = [];
1080
1080
  api.data.query = api.data.query.replace(/{__filters}/g, JSON.stringify(filters));
1081
1081
  var defaultValue = api.data.$value;
1082
1082
  var optionsFiltersOp = "${field.multiple ? "in" : "="}";
@@ -1089,17 +1089,18 @@
1089
1089
  `;
1090
1090
  const adaptor = `
1091
1091
  const data = payload.data;
1092
+ const rows = data.leftOptions
1092
1093
  data.children = data.children.map(function (child) {
1093
1094
  // child.defer = !!(child.children && child.children.length);
1094
1095
  child.defer = true;
1095
1096
  delete child.children;
1096
1097
  return child;
1097
1098
  });
1098
- data.leftOptions = data.leftOptions.map(function (leftOption) {
1099
- leftOption.defer = !!(leftOption.children && leftOption.children.length);
1100
- delete leftOption.children;
1101
- return leftOption;
1102
- });
1099
+
1100
+ var getTreeOptions = SteedosUI.getTreeOptions
1101
+ data.leftOptions = getTreeOptions(rows);
1102
+
1103
+
1103
1104
  var defaultValueOptions = data.defaultValueOptions;
1104
1105
  data.children = _.union(data.children, defaultValueOptions);
1105
1106
  delete data.defaultValueOptions;
@@ -1572,8 +1573,8 @@
1572
1573
  /*
1573
1574
  * @Author: 殷亮辉 yinlianghui@hotoa.com
1574
1575
  * @Date: 2023-03-22 09:31:21
1575
- * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
1576
- * @LastEditTime: 2023-03-27 16:03:34
1576
+ * @LastEditors: Please set LastEditors
1577
+ * @LastEditTime: 2023-03-28 14:06:47
1577
1578
  */
1578
1579
  const getSchema$2 = (uiSchema)=>{
1579
1580
  return {
@@ -1634,7 +1635,7 @@
1634
1635
  "data": {
1635
1636
  "objectName": "${_master.objectName}"
1636
1637
  },
1637
- "expression": "${_master.objectName}"
1638
+ "expression": `\${_master.objectName != '${uiSchema.name}' && _master.objectName}`
1638
1639
  }
1639
1640
  ]
1640
1641
  }
@@ -2058,7 +2059,7 @@
2058
2059
  if(visible.trim().startsWith('function')){
2059
2060
  return `${visible}.apply({
2060
2061
  object: uiSchema
2061
- }, [objectName, _id, recordPermissions, data])`
2062
+ }, [objectName, _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`
2062
2063
  }
2063
2064
  return visible;
2064
2065
  }
@@ -3979,6 +3980,10 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
3979
3980
  }
3980
3981
  }
3981
3982
 
3983
+ const enable_tree = ${refObjectConfig.enable_tree};
3984
+ if(enable_tree){
3985
+ pageSize = 10000;
3986
+ }
3982
3987
  api.data.query = api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim());
3983
3988
  return api;
3984
3989
  `;
@@ -3996,6 +4001,19 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
3996
4001
  if(enable_tree){
3997
4002
  const records = payload.data.rows;
3998
4003
  const treeRecords = [];
4004
+
4005
+ const getParentIds = (records)=>{
4006
+ const ids = _.map(records, (item)=>{
4007
+ return item._id;
4008
+ });
4009
+ const parents = _.filter(records,(record)=>{
4010
+ return !record.parent || !_.includes(ids,record.parent);
4011
+ })
4012
+ const parentsIds = _.map(parents,(item)=>{
4013
+ return item._id;
4014
+ })
4015
+ return parentsIds;
4016
+ }
3999
4017
  const getChildren = (records, childrenIds)=>{
4000
4018
  if(!childrenIds){
4001
4019
  return;
@@ -4011,8 +4029,9 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
4011
4029
  return children;
4012
4030
  }
4013
4031
 
4032
+ const parentIds = getParentIds(records);
4014
4033
  _.each(records, (record)=>{
4015
- if(!record.parent){
4034
+ if(!record.parent || _.includes(parentIds, record._id)){
4016
4035
  treeRecords.push(Object.assign({}, record, {children: getChildren(records, record.children)}));
4017
4036
  }
4018
4037
  });
@@ -4052,7 +4071,7 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
4052
4071
  new_button.align = "right";
4053
4072
  pickerSchema.headerToolbar.push(new_button);
4054
4073
  }
4055
- pickerSchema.footerToolbar = getObjectFooterToolbar();
4074
+ pickerSchema.footerToolbar = refObjectConfig.enable_tree ? [] : getObjectFooterToolbar();
4056
4075
  if(ctx.filterVisible !== false){
4057
4076
  let filterLoopCount = ctx.filterLoopCount || 0;
4058
4077
  filterLoopCount++;
@@ -4146,7 +4165,10 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
4146
4165
  apiInfo = {
4147
4166
  method: "post",
4148
4167
  url: getApi$2(),
4149
- data: {query: '{objects(filters: ["_id", "=", "-1"]){_id}}', $: "$$"}
4168
+ data: {query: '{objects(filters: ["_id", "=", "-1"]){_id}}', $: "$$"},
4169
+ "headers": {
4170
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
4171
+ }
4150
4172
  };
4151
4173
  }
4152
4174
 
@@ -5428,6 +5450,17 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
5428
5450
  }
5429
5451
  else{
5430
5452
  var uiSchema = api.body.uiSchema;
5453
+ var defaultData = api.body.defaultData;
5454
+ var defaultValues = {};
5455
+ _.each(uiSchema?.fields, function(field){
5456
+ var value = SteedosUI.getFieldDefaultValue(field, api.body.global);
5457
+ if(value){
5458
+ defaultValues[field.name] = value;
5459
+ }
5460
+ });
5461
+ if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){
5462
+ defaultValues = Object.assign({}, defaultValues, defaultData)
5463
+ }
5431
5464
  if(uiSchema.form){
5432
5465
  try{
5433
5466
  var objectFormConfig = JSON.parse(uiSchema.form);
@@ -5436,24 +5469,13 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
5436
5469
  initialValues = new Function("return " + initialValues)();
5437
5470
  }
5438
5471
  if(typeof initialValues === "function"){
5439
- initialValues = initialValues();
5472
+ initialValues = initialValues.apply({doc: defaultValues || {} })
5440
5473
  }
5441
5474
  }
5442
5475
  catch(ex){
5443
5476
  console.warn(ex);
5444
5477
  }
5445
5478
  }
5446
- var defaultData = api.body.defaultData;
5447
- var defaultValues = {};
5448
- _.each(uiSchema?.fields, function(field){
5449
- var value = SteedosUI.getFieldDefaultValue(field, api.body.global);
5450
- if(value){
5451
- defaultValues[field.name] = value;
5452
- }
5453
- });
5454
- if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){
5455
- defaultValues = Object.assign({}, defaultValues, defaultData)
5456
- }
5457
5479
  if(_.isObject(initialValues)){
5458
5480
  // uiSchema.form.initialValues为函数且执行后为json,则优先取initialValues中的默认值
5459
5481
  initialValues = Object.assign({}, defaultValues, initialValues);
@@ -5683,7 +5705,7 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
5683
5705
  footerToolbar: getObjectFooterToolbar(objectSchema, options.formFactor, {
5684
5706
  disableStatistics: options.queryCount === false
5685
5707
  }),
5686
- filter: !!options.filterVisible && await getObjectFilter(objectSchema, fields, options),
5708
+ filter: options.filterVisible !== false && await getObjectFilter(objectSchema, fields, options),
5687
5709
  };
5688
5710
  if(options.formFactor !== 'SMALL'){
5689
5711
  Object.assign(bodyProps, {
@@ -5899,7 +5921,7 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
5899
5921
  "data": {
5900
5922
  "objectName": "${_master.objectName}"
5901
5923
  },
5902
- "expression": "${_master.objectName}"
5924
+ "expression": `\${_master.objectName != '${objectSchema.name}' && _master.objectName}`
5903
5925
  }
5904
5926
  ]
5905
5927
  }
@@ -5916,7 +5938,7 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
5916
5938
  const { formFactor, layout = formFactor === 'SMALL' ? 'normal' : "normal", labelAlign, formInitProps } = ctx;
5917
5939
  const fields = ___default["default"].values(objectSchema.fields);
5918
5940
  const formFields = getFormFields(objectSchema, ctx);
5919
- const serviceId = `detail_${recordId}`;
5941
+ const serviceId = `service_detail_page`;
5920
5942
  return {
5921
5943
  type: 'service',
5922
5944
  name: `page_readonly_${recordId}`,
@@ -6246,7 +6268,7 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
6246
6268
  // return 'false';
6247
6269
  // }
6248
6270
  if(visible.trim().startsWith('function')){
6249
- return `${visible}(objectName, _id, recordPermissions, data)`
6271
+ return `${visible}(objectName, _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
6250
6272
  }
6251
6273
  return visible;
6252
6274
  }
@@ -6315,14 +6337,15 @@ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsF
6315
6337
  formFactor: "${formFactor}",
6316
6338
  context: `\${context}`
6317
6339
  },
6318
- "responseData": {
6319
- "recordPermissions": "$$"
6320
- },
6321
6340
  headers: {
6322
6341
  Authorization: "Bearer ${context.tenantId},${context.authToken}"
6323
6342
  },
6324
6343
  adaptor: `
6325
- payload.recordPermissions = payload;
6344
+ payload = {
6345
+ record: {
6346
+ recordPermissions: payload
6347
+ }
6348
+ };
6326
6349
  return payload;
6327
6350
  `,
6328
6351
  }