@steedos-widgets/amis-lib 1.1.3-beta.9 → 1.1.4-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.esm.js CHANGED
@@ -806,7 +806,7 @@ function getSaveDataTpl(fields){
806
806
  ${getScriptForSimplifiedValueForFileFields(fields)}
807
807
  let query = \`mutation{record: \${objectName}__insert(doc: {__saveData}){_id}}\`;
808
808
  if(formData.recordId && formData.recordId !='new'){
809
- query = \`mutation{record: \${objectName}__update(id: "\${formData._id}", doc: {__saveData}){_id}}\`;
809
+ query = \`mutation{record: \${objectName}__update(id: "\${formData.recordId}", doc: {__saveData}){_id}}\`;
810
810
  };
811
811
  delete formData._id;
812
812
  let __saveData = JSON.stringify(JSON.stringify(formData));
@@ -5402,6 +5402,21 @@ async function getEditFormInitApi(object, recordId, fields){
5402
5402
  }
5403
5403
  else{
5404
5404
  var uiSchema = api.body.uiSchema;
5405
+ if(uiSchema.form){
5406
+ try{
5407
+ var objectFormConfig = JSON.parse(uiSchema.form);
5408
+ initialValues = objectFormConfig.initialValues;
5409
+ if(initialValues){
5410
+ initialValues = new Function("return " + initialValues)();
5411
+ }
5412
+ if(typeof initialValues === "function"){
5413
+ initialValues = initialValues();
5414
+ }
5415
+ }
5416
+ catch(ex){
5417
+ console.warn(ex);
5418
+ }
5419
+ }
5405
5420
  var defaultData = api.body.defaultData;
5406
5421
  var defaultValues = {};
5407
5422
  _.each(uiSchema?.fields, function(field){
@@ -5413,7 +5428,13 @@ async function getEditFormInitApi(object, recordId, fields){
5413
5428
  if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){
5414
5429
  defaultValues = Object.assign({}, defaultValues, defaultData)
5415
5430
  }
5416
- initialValues = defaultValues;
5431
+ if(_.isObject(initialValues)){
5432
+ // uiSchema.form.initialValues为函数且执行后为json,则优先取initialValues中的默认值
5433
+ initialValues = Object.assign({}, defaultValues, initialValues);
5434
+ }
5435
+ else{
5436
+ initialValues = defaultValues;
5437
+ }
5417
5438
  }
5418
5439
  // data下的变量需要在保存接口(getSaveApi)中被删除。
5419
5440
  payload.data = {