@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.cjs.js CHANGED
@@ -10699,7 +10699,22 @@ async function getSelectUserSchema(field, readonly, ctx) {
10699
10699
  async function getSource(field, ctx) {
10700
10700
  // 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} }"
10701
10701
  const refObjectName = ctx.objectName;
10702
- const data = await getFindQuery({ name: refObjectName }, null, [{ name: ctx.valueField, alias: "value" }, { name: ctx.labelField, alias: "label" }, { name: "children" }], {
10702
+ let optionQueryFields = [{ name: ctx.valueField, alias: "value" }, { name: ctx.labelField, alias: "label" }, { name: "children" }];
10703
+ let defaultOptionQueryFields = optionQueryFields.filter(function (f) { return f.name !== "children" });
10704
+
10705
+ // 把自动填充规则中依赖的字段也加到api请求中
10706
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
10707
+ if (autoFillMapping && autoFillMapping.length) {
10708
+ autoFillMapping.forEach(function (item) {
10709
+ if(item.from !== "children"){
10710
+ optionQueryFields.push({ name: item.from });
10711
+ }
10712
+ defaultOptionQueryFields.push({ name: item.from });
10713
+ });
10714
+ }
10715
+
10716
+ const data = await getFindQuery({ name: refObjectName }, null, optionQueryFields, {
10717
+ expand: false,
10703
10718
  alias: "options",
10704
10719
  filters: "{__filters}"
10705
10720
  });
@@ -10710,7 +10725,8 @@ async function getSource(field, ctx) {
10710
10725
  // });
10711
10726
  // childrenData.query = childrenData.query.replace(/,count\:.+/, "}");
10712
10727
  // data.query = data.query.replace(/}$/, "," + childrenData.query.replace(/{(.+)}/, "$1}"));
10713
- const defaultValueOptionsData = await getFindQuery({ name: refObjectName }, null, [{ name: ctx.valueField, alias: "value" }, { name: ctx.labelField, alias: "label" }], {
10728
+ const defaultValueOptionsData = await getFindQuery({ name: refObjectName }, null, defaultOptionQueryFields, {
10729
+ expand: false,
10714
10730
  alias: "defaultValueOptions",
10715
10731
  filters: "{__options_filters}"
10716
10732
  });
@@ -10777,7 +10793,20 @@ async function getSource(field, ctx) {
10777
10793
  async function getDeferApi(field, ctx) {
10778
10794
  // data.query 最终格式 "{ \toptions:{__object_name}(filters:{__filters}){{__fields}} }"
10779
10795
  const refObjectName = ctx.objectName;
10780
- const data = await getFindQuery({ name: "{__object_name}" }, null, [], {
10796
+ let optionQueryFields = [{ name: ctx.valueField, alias: "value" }, { name: ctx.labelField, alias: "label" }, { name: "children" }];
10797
+
10798
+ // 把自动填充规则中依赖的字段也加到api请求中
10799
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
10800
+ if (autoFillMapping && autoFillMapping.length) {
10801
+ autoFillMapping.forEach(function (item) {
10802
+ if(item.from !== "children"){
10803
+ optionQueryFields.push({ name: item.from });
10804
+ }
10805
+ });
10806
+ }
10807
+
10808
+ const data = await getFindQuery({ name: "{__object_name}" }, null, optionQueryFields, {
10809
+ expand: false,
10781
10810
  alias: "options",
10782
10811
  // filters: "{__filters}",
10783
10812
  queryOptions: `filters: {__filters}, sort: "{__sort}"`
@@ -10792,8 +10821,6 @@ async function getDeferApi(field, ctx) {
10792
10821
  filters = filters(field);
10793
10822
  }
10794
10823
  data.query = data.query.replace(/,count\:.+/, "}");
10795
- // 字段要根据请求参数动态生成,写死为__fields后续在发送适配器中替换
10796
- data.query = data.query.replace("{_id}", "{{__fields}}");
10797
10824
  const requestAdaptor = `
10798
10825
  var dep = api.query.dep;
10799
10826
  var term = api.query.term;
@@ -10803,11 +10830,10 @@ async function getDeferApi(field, ctx) {
10803
10830
  var sort = "";
10804
10831
  if (dep) {
10805
10832
  objectName = "${refObjectName}";
10806
- fields = "_id,value:${ctx.valueField},label:${ctx.labelField},children";
10807
10833
  filters = [['parent', '=', dep]];
10808
10834
  sort = "${ctx.sort}";
10809
10835
  }
10810
- 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());
10836
+ api.data.query = api.data.query.replace(/{__object_name}/g, objectName).replace(/{__filters}/g, JSON.stringify(filters)).replace('{__sort}', sort.trim());
10811
10837
  return api;
10812
10838
  `;
10813
10839
  const adaptor = `
@@ -11161,6 +11187,18 @@ async function lookupToAmisPicker(field, readonly, ctx){
11161
11187
  }
11162
11188
  });
11163
11189
 
11190
+ // 把自动填充规则中依赖的字段也加到api请求中
11191
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
11192
+ if (autoFillMapping && autoFillMapping.length) {
11193
+ autoFillMapping.forEach(function (item) {
11194
+ if(!___namespace.find(tableFields, function(f){
11195
+ return f.name === item.from
11196
+ })){
11197
+ tableFields.push(refObjectConfig.fields[item.from]);
11198
+ }
11199
+ });
11200
+ }
11201
+
11164
11202
  ___namespace.each(refObjectConfig.fields, function (field) {
11165
11203
  if(isFieldQuickSearchable(field, refObjectConfig.NAME_FIELD_KEY)){
11166
11204
  searchableFields.push(field.name);
@@ -11592,22 +11630,31 @@ async function lookupToAmisSelect(field, readonly, ctx){
11592
11630
 
11593
11631
  let apiInfo;
11594
11632
  let defaultValueOptionsQueryData;
11633
+ const refObjectConfig = referenceTo && await getUISchema(referenceTo.objectName);
11595
11634
  if(referenceTo){
11596
- // 字段值单独走一个请求合并到source的同一个GraphQL接口中
11597
- defaultValueOptionsQueryData = await getFindQuery({ name: referenceTo.objectName }, null, [
11635
+ let queryFields = [
11598
11636
  Object.assign({}, referenceTo.labelField, {alias: 'label'}),
11599
11637
  Object.assign({}, referenceTo.valueField, {alias: 'value'})
11600
- ], {
11638
+ ];
11639
+
11640
+ // 把自动填充规则中依赖的字段也加到api请求中
11641
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
11642
+ if (autoFillMapping && autoFillMapping.length) {
11643
+ autoFillMapping.forEach(function (item) {
11644
+ queryFields.push(refObjectConfig.fields[item.from]);
11645
+ });
11646
+ }
11647
+
11648
+ // 字段值单独走一个请求合并到source的同一个GraphQL接口中
11649
+ defaultValueOptionsQueryData = await getFindQuery({ name: referenceTo.objectName }, null, queryFields, {
11650
+ expand: false,
11601
11651
  alias: "defaultValueOptions",
11602
11652
  filters: "{__options_filters}",
11603
11653
  count: false
11604
11654
  });
11605
11655
  apiInfo = await getApi({
11606
11656
  name: referenceTo.objectName
11607
- }, null, [
11608
- Object.assign({}, referenceTo.labelField, {alias: 'label'}),
11609
- Object.assign({}, referenceTo.valueField, {alias: 'value'})
11610
- ], {expand: false, alias: 'options', queryOptions: `filters: {__filters}, top: {__top}, sort: "{__sort}"`});
11657
+ }, null, queryFields, {expand: false, alias: 'options', queryOptions: `filters: {__filters}, top: {__top}, sort: "{__sort}"`});
11611
11658
 
11612
11659
  apiInfo.adaptor = `
11613
11660
  const data = payload.data;
@@ -11631,7 +11678,6 @@ async function lookupToAmisSelect(field, readonly, ctx){
11631
11678
  };
11632
11679
  }
11633
11680
 
11634
- const refObjectConfig = referenceTo && await getUISchema(referenceTo.objectName);
11635
11681
  let listView = getLookupListView(refObjectConfig);
11636
11682
 
11637
11683
  let listviewFilter = getListViewFilter(listView);
@@ -11817,13 +11863,13 @@ async function getApi(object, recordId, fields, options){
11817
11863
  }
11818
11864
 
11819
11865
  async function getAutoFill(field, refObject) {
11820
- let autoFillMapping = field.auto_fill_mapping;
11866
+ let autoFillMapping = !field.multiple && field.auto_fill_mapping;
11821
11867
  if (autoFillMapping && autoFillMapping.length) {
11822
11868
  let fillMapping = {};
11823
- let fieldsForApi = [];
11869
+ // let fieldsForApi = [];
11824
11870
  autoFillMapping.forEach(function (item) {
11825
11871
  fillMapping[item.to] = `\${${item.from}}`;
11826
- fieldsForApi.push(item.from);
11872
+ // fieldsForApi.push(item.from);
11827
11873
  });
11828
11874
  // let api = {
11829
11875
  // // "url": "/amis/api/mock2/form/autoUpdate?browser=${browser}&version=${version}",
@@ -14158,6 +14204,7 @@ async function getForm(props, mode = "edit", formId) {
14158
14204
  async function getButtonActions(props, mode) {
14159
14205
  let actions = [];
14160
14206
  let primaryKey = getTablePrimaryKey(props);
14207
+ let tableServiceId = getComponentId("table_service", props.id);
14161
14208
  let formId = getComponentId("form", props.id);
14162
14209
  let dialogId = getComponentId("dialog", props.id);
14163
14210
  let buttonNextId = getComponentId("button_next", props.id);
@@ -14474,7 +14521,30 @@ async function getButtonActions(props, mode) {
14474
14521
  // };
14475
14522
  // 新增行时不需要在弹出编辑表单前先加一行,因为会在编辑表单所在service初始化时判断到是新增就自动增加一行,因为这里拿不到event.data.__tableItems,也无法变更其值
14476
14523
  // actions = [actionNewLine, actionShowEditDialog];
14477
- actions = [actionShowEditDialog];
14524
+ if (props.enableDialog === false) {
14525
+ actions = [
14526
+ {
14527
+ "actionType": "custom",
14528
+ "script": `
14529
+ let scope = event.context.scoped;
14530
+ let __wrapperServiceId = "${tableServiceId}";
14531
+ let wrapperService = scope.getComponentById(__wrapperServiceId);
14532
+ let wrapperServiceData = wrapperService.getData();
14533
+ let lastestFieldValue = _.clone(wrapperServiceData["${props.name}"] || []);
14534
+ lastestFieldValue.push({})
14535
+ doAction({
14536
+ "componentId": "${props.id}",
14537
+ "actionType": "setValue",
14538
+ "args": {
14539
+ "value": lastestFieldValue
14540
+ }
14541
+ });
14542
+ `
14543
+ }
14544
+ ];
14545
+ }else {
14546
+ actions = [actionShowEditDialog];
14547
+ }
14478
14548
  }
14479
14549
  else if (mode == "edit") {
14480
14550
  actions = [actionShowEditDialog];
@@ -14706,31 +14776,34 @@ const getAmisInputTableSchema = async (props) => {
14706
14776
  let inlineEditMode = props.inlineEditMode;
14707
14777
  let showAsInlineEditMode = inlineEditMode && props.editable;
14708
14778
  if (showOperation) {
14709
- if (props.editable) {
14710
- let showEditButton = true;
14711
- if (showAsInlineEditMode) {
14712
- // 始终显示弹出子表表单按钮,如果需要判断只在有列被隐藏时才需要显示弹出表单按钮放开下面的if逻辑就好
14713
- showEditButton = true;
14714
- // // inline edit模式下只在有列被隐藏时才需要显示编辑按钮
14715
- // if (props.columns && props.columns.length > 0 && props.columns.length < fields.length) {
14716
- // showEditButton = true;
14717
- // }
14718
- // else {
14719
- // showEditButton = false;
14720
- // }
14779
+ if (props.enableDialog !== false) {
14780
+ if (props.editable) {
14781
+ let showEditButton = true;
14782
+ if (showAsInlineEditMode) {
14783
+ // 始终显示弹出子表表单按钮,如果需要判断只在有列被隐藏时才需要显示弹出表单按钮放开下面的if逻辑就好
14784
+ showEditButton = true;
14785
+ // // inline edit模式下只在有列被隐藏时才需要显示编辑按钮
14786
+ // if (props.columns && props.columns.length > 0 && props.columns.length < fields.length) {
14787
+ // showEditButton = true;
14788
+ // }
14789
+ // else {
14790
+ // showEditButton = false;
14791
+ // }
14792
+ }
14793
+ // 编辑时显示编辑按钮
14794
+ if (showEditButton) {
14795
+ let buttonEditSchema = await getButtonEdit(props, showAsInlineEditMode);
14796
+ buttonsForColumnOperations.push(buttonEditSchema);
14797
+ }
14721
14798
  }
14722
- // 编辑时显示编辑按钮
14723
- if (showEditButton) {
14724
- let buttonEditSchema = await getButtonEdit(props, showAsInlineEditMode);
14725
- buttonsForColumnOperations.push(buttonEditSchema);
14799
+ else {
14800
+ // 只读时显示查看按钮
14801
+ // 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length < fields.length)
14802
+ let buttonViewSchema = await getButtonView(props);
14803
+ buttonsForColumnOperations.push(buttonViewSchema);
14726
14804
  }
14727
14805
  }
14728
- else {
14729
- // 只读时显示查看按钮
14730
- // 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length < fields.length)
14731
- let buttonViewSchema = await getButtonView(props);
14732
- buttonsForColumnOperations.push(buttonViewSchema);
14733
- }
14806
+
14734
14807
  if (props.removable) {
14735
14808
  let buttonDeleteSchema = await getButtonDelete(props);
14736
14809
  buttonsForColumnOperations.push(buttonDeleteSchema);