@steedos-widgets/amis-lib 3.6.4-beta.2 → 3.6.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
@@ -10672,7 +10672,22 @@ async function getSelectUserSchema(field, readonly, ctx) {
10672
10672
  async function getSource(field, ctx) {
10673
10673
  // 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} }"
10674
10674
  const refObjectName = ctx.objectName;
10675
- const data = await getFindQuery({ name: refObjectName }, null, [{ name: ctx.valueField, alias: "value" }, { name: ctx.labelField, alias: "label" }, { name: "children" }], {
10675
+ let optionQueryFields = [{ name: ctx.valueField, alias: "value" }, { name: ctx.labelField, alias: "label" }, { name: "children" }];
10676
+ let defaultOptionQueryFields = optionQueryFields.filter(function (f) { return f.name !== "children" });
10677
+
10678
+ // 把自动填充规则中依赖的字段也加到api请求中
10679
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
10680
+ if (autoFillMapping && autoFillMapping.length) {
10681
+ autoFillMapping.forEach(function (item) {
10682
+ if(item.from !== "children"){
10683
+ optionQueryFields.push({ name: item.from });
10684
+ }
10685
+ defaultOptionQueryFields.push({ name: item.from });
10686
+ });
10687
+ }
10688
+
10689
+ const data = await getFindQuery({ name: refObjectName }, null, optionQueryFields, {
10690
+ expand: false,
10676
10691
  alias: "options",
10677
10692
  filters: "{__filters}"
10678
10693
  });
@@ -10683,7 +10698,8 @@ async function getSource(field, ctx) {
10683
10698
  // });
10684
10699
  // childrenData.query = childrenData.query.replace(/,count\:.+/, "}");
10685
10700
  // data.query = data.query.replace(/}$/, "," + childrenData.query.replace(/{(.+)}/, "$1}"));
10686
- const defaultValueOptionsData = await getFindQuery({ name: refObjectName }, null, [{ name: ctx.valueField, alias: "value" }, { name: ctx.labelField, alias: "label" }], {
10701
+ const defaultValueOptionsData = await getFindQuery({ name: refObjectName }, null, defaultOptionQueryFields, {
10702
+ expand: false,
10687
10703
  alias: "defaultValueOptions",
10688
10704
  filters: "{__options_filters}"
10689
10705
  });
@@ -10750,7 +10766,20 @@ async function getSource(field, ctx) {
10750
10766
  async function getDeferApi(field, ctx) {
10751
10767
  // data.query 最终格式 "{ \toptions:{__object_name}(filters:{__filters}){{__fields}} }"
10752
10768
  const refObjectName = ctx.objectName;
10753
- const data = await getFindQuery({ name: "{__object_name}" }, null, [], {
10769
+ let optionQueryFields = [{ name: ctx.valueField, alias: "value" }, { name: ctx.labelField, alias: "label" }, { name: "children" }];
10770
+
10771
+ // 把自动填充规则中依赖的字段也加到api请求中
10772
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
10773
+ if (autoFillMapping && autoFillMapping.length) {
10774
+ autoFillMapping.forEach(function (item) {
10775
+ if(item.from !== "children"){
10776
+ optionQueryFields.push({ name: item.from });
10777
+ }
10778
+ });
10779
+ }
10780
+
10781
+ const data = await getFindQuery({ name: "{__object_name}" }, null, optionQueryFields, {
10782
+ expand: false,
10754
10783
  alias: "options",
10755
10784
  // filters: "{__filters}",
10756
10785
  queryOptions: `filters: {__filters}, sort: "{__sort}"`
@@ -10765,8 +10794,6 @@ async function getDeferApi(field, ctx) {
10765
10794
  filters = filters(field);
10766
10795
  }
10767
10796
  data.query = data.query.replace(/,count\:.+/, "}");
10768
- // 字段要根据请求参数动态生成,写死为__fields后续在发送适配器中替换
10769
- data.query = data.query.replace("{_id}", "{{__fields}}");
10770
10797
  const requestAdaptor = `
10771
10798
  var dep = api.query.dep;
10772
10799
  var term = api.query.term;
@@ -10776,11 +10803,10 @@ async function getDeferApi(field, ctx) {
10776
10803
  var sort = "";
10777
10804
  if (dep) {
10778
10805
  objectName = "${refObjectName}";
10779
- fields = "_id,value:${ctx.valueField},label:${ctx.labelField},children";
10780
10806
  filters = [['parent', '=', dep]];
10781
10807
  sort = "${ctx.sort}";
10782
10808
  }
10783
- api.data.query = api.data.query.replace(/{__object_name}/g, objectName).replace(/{__fields}/g, fields).replace(/{__filters}/g, JSON.stringify(filters)).replace('{__sort}', sort.trim());
10809
+ api.data.query = api.data.query.replace(/{__object_name}/g, objectName).replace(/{__filters}/g, JSON.stringify(filters)).replace('{__sort}', sort.trim());
10784
10810
  return api;
10785
10811
  `;
10786
10812
  const adaptor = `
@@ -11134,6 +11160,18 @@ async function lookupToAmisPicker(field, readonly, ctx){
11134
11160
  }
11135
11161
  });
11136
11162
 
11163
+ // 把自动填充规则中依赖的字段也加到api请求中
11164
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
11165
+ if (autoFillMapping && autoFillMapping.length) {
11166
+ autoFillMapping.forEach(function (item) {
11167
+ if(!_$1.find(tableFields, function(f){
11168
+ return f.name === item.from
11169
+ })){
11170
+ tableFields.push(refObjectConfig.fields[item.from]);
11171
+ }
11172
+ });
11173
+ }
11174
+
11137
11175
  _$1.each(refObjectConfig.fields, function (field) {
11138
11176
  if(isFieldQuickSearchable(field, refObjectConfig.NAME_FIELD_KEY)){
11139
11177
  searchableFields.push(field.name);
@@ -11565,22 +11603,31 @@ async function lookupToAmisSelect(field, readonly, ctx){
11565
11603
 
11566
11604
  let apiInfo;
11567
11605
  let defaultValueOptionsQueryData;
11606
+ const refObjectConfig = referenceTo && await getUISchema(referenceTo.objectName);
11568
11607
  if(referenceTo){
11569
- // 字段值单独走一个请求合并到source的同一个GraphQL接口中
11570
- defaultValueOptionsQueryData = await getFindQuery({ name: referenceTo.objectName }, null, [
11608
+ let queryFields = [
11571
11609
  Object.assign({}, referenceTo.labelField, {alias: 'label'}),
11572
11610
  Object.assign({}, referenceTo.valueField, {alias: 'value'})
11573
- ], {
11611
+ ];
11612
+
11613
+ // 把自动填充规则中依赖的字段也加到api请求中
11614
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
11615
+ if (autoFillMapping && autoFillMapping.length) {
11616
+ autoFillMapping.forEach(function (item) {
11617
+ queryFields.push(refObjectConfig.fields[item.from]);
11618
+ });
11619
+ }
11620
+
11621
+ // 字段值单独走一个请求合并到source的同一个GraphQL接口中
11622
+ defaultValueOptionsQueryData = await getFindQuery({ name: referenceTo.objectName }, null, queryFields, {
11623
+ expand: false,
11574
11624
  alias: "defaultValueOptions",
11575
11625
  filters: "{__options_filters}",
11576
11626
  count: false
11577
11627
  });
11578
11628
  apiInfo = await getApi({
11579
11629
  name: referenceTo.objectName
11580
- }, null, [
11581
- Object.assign({}, referenceTo.labelField, {alias: 'label'}),
11582
- Object.assign({}, referenceTo.valueField, {alias: 'value'})
11583
- ], {expand: false, alias: 'options', queryOptions: `filters: {__filters}, top: {__top}, sort: "{__sort}"`});
11630
+ }, null, queryFields, {expand: false, alias: 'options', queryOptions: `filters: {__filters}, top: {__top}, sort: "{__sort}"`});
11584
11631
 
11585
11632
  apiInfo.adaptor = `
11586
11633
  const data = payload.data;
@@ -11604,7 +11651,6 @@ async function lookupToAmisSelect(field, readonly, ctx){
11604
11651
  };
11605
11652
  }
11606
11653
 
11607
- const refObjectConfig = referenceTo && await getUISchema(referenceTo.objectName);
11608
11654
  let listView = getLookupListView(refObjectConfig);
11609
11655
 
11610
11656
  let listviewFilter = getListViewFilter(listView);
@@ -11790,13 +11836,13 @@ async function getApi(object, recordId, fields, options){
11790
11836
  }
11791
11837
 
11792
11838
  async function getAutoFill(field, refObject) {
11793
- let autoFillMapping = field.auto_fill_mapping;
11839
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
11794
11840
  if (autoFillMapping && autoFillMapping.length) {
11795
11841
  let fillMapping = {};
11796
- let fieldsForApi = [];
11842
+ // let fieldsForApi = [];
11797
11843
  autoFillMapping.forEach(function (item) {
11798
11844
  fillMapping[item.to] = `\${${item.from}}`;
11799
- fieldsForApi.push(item.from);
11845
+ // fieldsForApi.push(item.from);
11800
11846
  });
11801
11847
  // let api = {
11802
11848
  // // "url": "/amis/api/mock2/form/autoUpdate?browser=${browser}&version=${version}",
@@ -14131,6 +14177,7 @@ async function getForm(props, mode = "edit", formId) {
14131
14177
  async function getButtonActions(props, mode) {
14132
14178
  let actions = [];
14133
14179
  let primaryKey = getTablePrimaryKey(props);
14180
+ let tableServiceId = getComponentId("table_service", props.id);
14134
14181
  let formId = getComponentId("form", props.id);
14135
14182
  let dialogId = getComponentId("dialog", props.id);
14136
14183
  let buttonNextId = getComponentId("button_next", props.id);
@@ -14447,7 +14494,30 @@ async function getButtonActions(props, mode) {
14447
14494
  // };
14448
14495
  // 新增行时不需要在弹出编辑表单前先加一行,因为会在编辑表单所在service初始化时判断到是新增就自动增加一行,因为这里拿不到event.data.__tableItems,也无法变更其值
14449
14496
  // actions = [actionNewLine, actionShowEditDialog];
14450
- actions = [actionShowEditDialog];
14497
+ if (props.enableDialog === false) {
14498
+ actions = [
14499
+ {
14500
+ "actionType": "custom",
14501
+ "script": `
14502
+ let scope = event.context.scoped;
14503
+ let __wrapperServiceId = "${tableServiceId}";
14504
+ let wrapperService = scope.getComponentById(__wrapperServiceId);
14505
+ let wrapperServiceData = wrapperService.getData();
14506
+ let lastestFieldValue = _.clone(wrapperServiceData["${props.name}"] || []);
14507
+ lastestFieldValue.push({})
14508
+ doAction({
14509
+ "componentId": "${props.id}",
14510
+ "actionType": "setValue",
14511
+ "args": {
14512
+ "value": lastestFieldValue
14513
+ }
14514
+ });
14515
+ `
14516
+ }
14517
+ ];
14518
+ }else {
14519
+ actions = [actionShowEditDialog];
14520
+ }
14451
14521
  }
14452
14522
  else if (mode == "edit") {
14453
14523
  actions = [actionShowEditDialog];
@@ -14679,31 +14749,34 @@ const getAmisInputTableSchema = async (props) => {
14679
14749
  let inlineEditMode = props.inlineEditMode;
14680
14750
  let showAsInlineEditMode = inlineEditMode && props.editable;
14681
14751
  if (showOperation) {
14682
- if (props.editable) {
14683
- let showEditButton = true;
14684
- if (showAsInlineEditMode) {
14685
- // 始终显示弹出子表表单按钮,如果需要判断只在有列被隐藏时才需要显示弹出表单按钮放开下面的if逻辑就好
14686
- showEditButton = true;
14687
- // // inline edit模式下只在有列被隐藏时才需要显示编辑按钮
14688
- // if (props.columns && props.columns.length > 0 && props.columns.length < fields.length) {
14689
- // showEditButton = true;
14690
- // }
14691
- // else {
14692
- // showEditButton = false;
14693
- // }
14752
+ if (props.enableDialog !== false) {
14753
+ if (props.editable) {
14754
+ let showEditButton = true;
14755
+ if (showAsInlineEditMode) {
14756
+ // 始终显示弹出子表表单按钮,如果需要判断只在有列被隐藏时才需要显示弹出表单按钮放开下面的if逻辑就好
14757
+ showEditButton = true;
14758
+ // // inline edit模式下只在有列被隐藏时才需要显示编辑按钮
14759
+ // if (props.columns && props.columns.length > 0 && props.columns.length < fields.length) {
14760
+ // showEditButton = true;
14761
+ // }
14762
+ // else {
14763
+ // showEditButton = false;
14764
+ // }
14765
+ }
14766
+ // 编辑时显示编辑按钮
14767
+ if (showEditButton) {
14768
+ let buttonEditSchema = await getButtonEdit(props, showAsInlineEditMode);
14769
+ buttonsForColumnOperations.push(buttonEditSchema);
14770
+ }
14694
14771
  }
14695
- // 编辑时显示编辑按钮
14696
- if (showEditButton) {
14697
- let buttonEditSchema = await getButtonEdit(props, showAsInlineEditMode);
14698
- buttonsForColumnOperations.push(buttonEditSchema);
14772
+ else {
14773
+ // 只读时显示查看按钮
14774
+ // 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length < fields.length)
14775
+ let buttonViewSchema = await getButtonView(props);
14776
+ buttonsForColumnOperations.push(buttonViewSchema);
14699
14777
  }
14700
14778
  }
14701
- else {
14702
- // 只读时显示查看按钮
14703
- // 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length < fields.length)
14704
- let buttonViewSchema = await getButtonView(props);
14705
- buttonsForColumnOperations.push(buttonViewSchema);
14706
- }
14779
+
14707
14780
  if (props.removable) {
14708
14781
  let buttonDeleteSchema = await getButtonDelete(props);
14709
14782
  buttonsForColumnOperations.push(buttonDeleteSchema);