@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.esm.js CHANGED
@@ -1020,7 +1020,7 @@ const refOrgsObjectName = "organizations";
1020
1020
 
1021
1021
  async function getSource$1(field, ctx) {
1022
1022
  // 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} }"
1023
- const data = await getFindQuery({ name: refOrgsObjectName }, null, [{ name: "_id", alias: "value" }, { name: "name", alias: "label" }, { name: "children" }], {
1023
+ const data = await getFindQuery({ name: refOrgsObjectName }, null, [{ name: "_id", alias: "value" },{name: "parent"}, { name: "name", alias: "label" }, { name: "children" }], {
1024
1024
  alias: "leftOptions",
1025
1025
  filters: "{__filters}"
1026
1026
  });
@@ -1050,7 +1050,7 @@ async function getSource$1(field, ctx) {
1050
1050
  // data["&"] = "$$";
1051
1051
 
1052
1052
  const requestAdaptor = `
1053
- var filters = [['parent', '=', null]];
1053
+ var filters = [];
1054
1054
  api.data.query = api.data.query.replace(/{__filters}/g, JSON.stringify(filters));
1055
1055
  var defaultValue = api.data.$value;
1056
1056
  var optionsFiltersOp = "${field.multiple ? "in" : "="}";
@@ -1063,17 +1063,18 @@ async function getSource$1(field, ctx) {
1063
1063
  `;
1064
1064
  const adaptor = `
1065
1065
  const data = payload.data;
1066
+ const rows = data.leftOptions
1066
1067
  data.children = data.children.map(function (child) {
1067
1068
  // child.defer = !!(child.children && child.children.length);
1068
1069
  child.defer = true;
1069
1070
  delete child.children;
1070
1071
  return child;
1071
1072
  });
1072
- data.leftOptions = data.leftOptions.map(function (leftOption) {
1073
- leftOption.defer = !!(leftOption.children && leftOption.children.length);
1074
- delete leftOption.children;
1075
- return leftOption;
1076
- });
1073
+
1074
+ var getTreeOptions = SteedosUI.getTreeOptions
1075
+ data.leftOptions = getTreeOptions(rows);
1076
+
1077
+
1077
1078
  var defaultValueOptions = data.defaultValueOptions;
1078
1079
  data.children = _.union(data.children, defaultValueOptions);
1079
1080
  delete data.defaultValueOptions;
@@ -1546,8 +1547,8 @@ const getSchema$3 = async (uiSchema, ctx) => {
1546
1547
  /*
1547
1548
  * @Author: 殷亮辉 yinlianghui@hotoa.com
1548
1549
  * @Date: 2023-03-22 09:31:21
1549
- * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
1550
- * @LastEditTime: 2023-03-27 16:03:34
1550
+ * @LastEditors: Please set LastEditors
1551
+ * @LastEditTime: 2023-03-28 14:06:47
1551
1552
  */
1552
1553
  const getSchema$2 = (uiSchema)=>{
1553
1554
  return {
@@ -1608,7 +1609,7 @@ const getSchema$2 = (uiSchema)=>{
1608
1609
  "data": {
1609
1610
  "objectName": "${_master.objectName}"
1610
1611
  },
1611
- "expression": "${_master.objectName}"
1612
+ "expression": `\${_master.objectName != '${uiSchema.name}' && _master.objectName}`
1612
1613
  }
1613
1614
  ]
1614
1615
  }
@@ -2032,7 +2033,7 @@ function getButtonVisibleOn$1(button){
2032
2033
  if(visible.trim().startsWith('function')){
2033
2034
  return `${visible}.apply({
2034
2035
  object: uiSchema
2035
- }, [objectName, _id, recordPermissions, data])`
2036
+ }, [objectName, _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`
2036
2037
  }
2037
2038
  return visible;
2038
2039
  }
@@ -3953,6 +3954,10 @@ async function lookupToAmisPicker(field, readonly, ctx){
3953
3954
  }
3954
3955
  }
3955
3956
 
3957
+ const enable_tree = ${refObjectConfig.enable_tree};
3958
+ if(enable_tree){
3959
+ pageSize = 10000;
3960
+ }
3956
3961
  api.data.query = api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim());
3957
3962
  return api;
3958
3963
  `;
@@ -3970,6 +3975,19 @@ async function lookupToAmisPicker(field, readonly, ctx){
3970
3975
  if(enable_tree){
3971
3976
  const records = payload.data.rows;
3972
3977
  const treeRecords = [];
3978
+
3979
+ const getParentIds = (records)=>{
3980
+ const ids = _.map(records, (item)=>{
3981
+ return item._id;
3982
+ });
3983
+ const parents = _.filter(records,(record)=>{
3984
+ return !record.parent || !_.includes(ids,record.parent);
3985
+ })
3986
+ const parentsIds = _.map(parents,(item)=>{
3987
+ return item._id;
3988
+ })
3989
+ return parentsIds;
3990
+ }
3973
3991
  const getChildren = (records, childrenIds)=>{
3974
3992
  if(!childrenIds){
3975
3993
  return;
@@ -3985,8 +4003,9 @@ async function lookupToAmisPicker(field, readonly, ctx){
3985
4003
  return children;
3986
4004
  }
3987
4005
 
4006
+ const parentIds = getParentIds(records);
3988
4007
  _.each(records, (record)=>{
3989
- if(!record.parent){
4008
+ if(!record.parent || _.includes(parentIds, record._id)){
3990
4009
  treeRecords.push(Object.assign({}, record, {children: getChildren(records, record.children)}));
3991
4010
  }
3992
4011
  });
@@ -4026,7 +4045,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
4026
4045
  new_button.align = "right";
4027
4046
  pickerSchema.headerToolbar.push(new_button);
4028
4047
  }
4029
- pickerSchema.footerToolbar = getObjectFooterToolbar();
4048
+ pickerSchema.footerToolbar = refObjectConfig.enable_tree ? [] : getObjectFooterToolbar();
4030
4049
  if(ctx.filterVisible !== false){
4031
4050
  let filterLoopCount = ctx.filterLoopCount || 0;
4032
4051
  filterLoopCount++;
@@ -4120,7 +4139,10 @@ async function lookupToAmisSelect(field, readonly, ctx){
4120
4139
  apiInfo = {
4121
4140
  method: "post",
4122
4141
  url: getApi$2(),
4123
- data: {query: '{objects(filters: ["_id", "=", "-1"]){_id}}', $: "$$"}
4142
+ data: {query: '{objects(filters: ["_id", "=", "-1"]){_id}}', $: "$$"},
4143
+ "headers": {
4144
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
4145
+ }
4124
4146
  };
4125
4147
  }
4126
4148
 
@@ -5402,6 +5424,17 @@ async function getEditFormInitApi(object, recordId, fields){
5402
5424
  }
5403
5425
  else{
5404
5426
  var uiSchema = api.body.uiSchema;
5427
+ var defaultData = api.body.defaultData;
5428
+ var defaultValues = {};
5429
+ _.each(uiSchema?.fields, function(field){
5430
+ var value = SteedosUI.getFieldDefaultValue(field, api.body.global);
5431
+ if(value){
5432
+ defaultValues[field.name] = value;
5433
+ }
5434
+ });
5435
+ if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){
5436
+ defaultValues = Object.assign({}, defaultValues, defaultData)
5437
+ }
5405
5438
  if(uiSchema.form){
5406
5439
  try{
5407
5440
  var objectFormConfig = JSON.parse(uiSchema.form);
@@ -5410,24 +5443,13 @@ async function getEditFormInitApi(object, recordId, fields){
5410
5443
  initialValues = new Function("return " + initialValues)();
5411
5444
  }
5412
5445
  if(typeof initialValues === "function"){
5413
- initialValues = initialValues();
5446
+ initialValues = initialValues.apply({doc: defaultValues || {} })
5414
5447
  }
5415
5448
  }
5416
5449
  catch(ex){
5417
5450
  console.warn(ex);
5418
5451
  }
5419
5452
  }
5420
- var defaultData = api.body.defaultData;
5421
- var defaultValues = {};
5422
- _.each(uiSchema?.fields, function(field){
5423
- var value = SteedosUI.getFieldDefaultValue(field, api.body.global);
5424
- if(value){
5425
- defaultValues[field.name] = value;
5426
- }
5427
- });
5428
- if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){
5429
- defaultValues = Object.assign({}, defaultValues, defaultData)
5430
- }
5431
5453
  if(_.isObject(initialValues)){
5432
5454
  // uiSchema.form.initialValues为函数且执行后为json,则优先取initialValues中的默认值
5433
5455
  initialValues = Object.assign({}, defaultValues, initialValues);
@@ -5657,7 +5679,7 @@ async function getObjectCRUD(objectSchema, fields, options){
5657
5679
  footerToolbar: getObjectFooterToolbar(objectSchema, options.formFactor, {
5658
5680
  disableStatistics: options.queryCount === false
5659
5681
  }),
5660
- filter: !!options.filterVisible && await getObjectFilter(objectSchema, fields, options),
5682
+ filter: options.filterVisible !== false && await getObjectFilter(objectSchema, fields, options),
5661
5683
  };
5662
5684
  if(options.formFactor !== 'SMALL'){
5663
5685
  Object.assign(bodyProps, {
@@ -5873,7 +5895,7 @@ async function getObjectForm(objectSchema, ctx){
5873
5895
  "data": {
5874
5896
  "objectName": "${_master.objectName}"
5875
5897
  },
5876
- "expression": "${_master.objectName}"
5898
+ "expression": `\${_master.objectName != '${objectSchema.name}' && _master.objectName}`
5877
5899
  }
5878
5900
  ]
5879
5901
  }
@@ -5890,7 +5912,7 @@ async function getObjectDetail(objectSchema, recordId, ctx){
5890
5912
  const { formFactor, layout = formFactor === 'SMALL' ? 'normal' : "normal", labelAlign, formInitProps } = ctx;
5891
5913
  const fields = ___default.values(objectSchema.fields);
5892
5914
  const formFields = getFormFields(objectSchema, ctx);
5893
- const serviceId = `detail_${recordId}`;
5915
+ const serviceId = `service_detail_page`;
5894
5916
  return {
5895
5917
  type: 'service',
5896
5918
  name: `page_readonly_${recordId}`,
@@ -6220,7 +6242,7 @@ function getButtonVisibleOn(button){
6220
6242
  // return 'false';
6221
6243
  // }
6222
6244
  if(visible.trim().startsWith('function')){
6223
- return `${visible}(objectName, _id, recordPermissions, data)`
6245
+ return `${visible}(objectName, _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
6224
6246
  }
6225
6247
  return visible;
6226
6248
  }
@@ -6289,14 +6311,15 @@ async function getTableOperation(ctx){
6289
6311
  formFactor: "${formFactor}",
6290
6312
  context: `\${context}`
6291
6313
  },
6292
- "responseData": {
6293
- "recordPermissions": "$$"
6294
- },
6295
6314
  headers: {
6296
6315
  Authorization: "Bearer ${context.tenantId},${context.authToken}"
6297
6316
  },
6298
6317
  adaptor: `
6299
- payload.recordPermissions = payload;
6318
+ payload = {
6319
+ record: {
6320
+ recordPermissions: payload
6321
+ }
6322
+ };
6300
6323
  return payload;
6301
6324
  `,
6302
6325
  }