@steedos-widgets/amis-lib 1.3.22-beta.2 → 1.3.22-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
@@ -1626,6 +1626,7 @@ async function getQuickEditSchema(field, options){
1626
1626
  {
1627
1627
  "actionType": "custom",
1628
1628
  "script": `
1629
+
1629
1630
  var _display = _.cloneDeep(event.data._display);
1630
1631
  ${displayField}
1631
1632
  doAction({actionType: 'setValue', "args": {"value": {_display}},componentId: "${quickEditId}"});
@@ -2012,7 +2013,9 @@ async function getTableColumns(fields, options){
2012
2013
  if(!options.isLookup && !options.isInputTable){
2013
2014
  //将_display放入crud的columns中,可以通过setvalue修改行内数据域的_display,而不影响上层items的_display,用于批量编辑
2014
2015
  columns.push({name: '_display',type: 'static', width: 32, placeholder: "",id: "_display_${_index}", className: "hidden"});
2015
- columns.push({name: '_index',type: 'text', width: 32, placeholder: ""});
2016
+ if(!options.enable_tree){
2017
+ columns.push({name: '_index',type: 'text', width: 32, placeholder: ""});
2018
+ }
2016
2019
  }
2017
2020
  const allowEdit = options.permissions?.allowEdit && !options.isLookup && options.enable_inline_edit != false;
2018
2021
 
@@ -2863,7 +2866,21 @@ async function getTableApi(mainObject, fields, options){
2863
2866
 
2864
2867
  if(enable_tree){
2865
2868
  const records = payload.data.rows || [];
2866
- const getTreeOptions = SteedosUI.getTreeOptions
2869
+ const getTreeOptions = SteedosUI.getTreeOptions;
2870
+ const assignIndexToTreeRecords = function(tree, parentIndex) {
2871
+ tree.forEach(function (node, index) {
2872
+ // 构建当前节点的 _index
2873
+ var currentIndex = parentIndex ? parentIndex + '-' + (index + 1) : '' + (index + 1);
2874
+
2875
+ // 赋值给节点
2876
+ node._index = currentIndex;
2877
+
2878
+ // 如果有子节点,递归调用函数
2879
+ if (node.children && node.children.length > 0) {
2880
+ assignIndexToTreeRecords(node.children, currentIndex);
2881
+ }
2882
+ });
2883
+ };
2867
2884
  let isTreeOptionsComputed = false;
2868
2885
  if(records.length === 1 && records[0].children){
2869
2886
  isTreeOptionsComputed = true;
@@ -2871,6 +2888,7 @@ async function getTableApi(mainObject, fields, options){
2871
2888
  if(!isTreeOptionsComputed){
2872
2889
  // 如果api接口设置在缓存,缓存期间并不会重新请求接口,payload.data.rows是上次计算后的结果
2873
2890
  payload.data.rows = getTreeOptions(records,{"valueField":"_id"});
2891
+ assignIndexToTreeRecords(payload.data.rows, '');
2874
2892
  }
2875
2893
  try{
2876
2894
  setTimeout(() => {
@@ -8227,7 +8245,7 @@ async function getObjectCRUD(objectSchema, fields, options){
8227
8245
  let tableOptions = Object.assign({
8228
8246
  idFieldName: objectSchema.idFieldName, labelFieldName: labelFieldName,
8229
8247
  permissions:objectSchema.permissions,enable_inline_edit:objectSchema.enable_inline_edit,
8230
- crudId: listSchema.id || id
8248
+ crudId: listSchema.id || id, enable_tree: objectSchema.enable_tree
8231
8249
  }, options);
8232
8250
  tableOptions.amisData = createObject(options.amisData || {}, {});
8233
8251
  const table = await getTableSchema$1(fields, tableOptions);
@@ -12414,7 +12432,7 @@ async function getFormBody(permissionFields, formFields, ctx){
12414
12432
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12415
12433
  * @Date: 2023-11-15 09:50:22
12416
12434
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12417
- * @LastEditTime: 2023-12-23 22:13:22
12435
+ * @LastEditTime: 2023-12-25 13:13:56
12418
12436
  */
12419
12437
 
12420
12438
  /**
@@ -12661,7 +12679,7 @@ function getFormPagination(props, mode) {
12661
12679
  * @returns 带翻页容器的wrapper
12662
12680
  */
12663
12681
  function getFormPaginationWrapper(props, form, mode) {
12664
- console.log("==getFormPaginationWrapper===", props, mode);
12682
+ // console.log("==getFormPaginationWrapper===", props, mode);
12665
12683
  let serviceId = getComponentId("form_pagination", props.id);
12666
12684
  let tableServiceId = getComponentId("table_service", props.id);
12667
12685
  let innerForm = Object.assign({}, form, {
@@ -12701,8 +12719,26 @@ function getFormPaginationWrapper(props, form, mode) {
12701
12719
  let __wrapperServiceId = "${tableServiceId}";
12702
12720
  let wrapperService = scope.getComponentById(__wrapperServiceId);
12703
12721
  let wrapperServiceData = wrapperService.getData();
12704
- let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
12722
+ let lastestFieldValue = wrapperServiceData["${props.name}"] || [];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
12705
12723
  //不可以直接像event.data.__tableItems = lastestFieldValue; 这样整个赋值,否则作用域会断
12724
+ let mode = "${mode}";
12725
+ if(mode === "new"){
12726
+ // 点击子表组件底部新增按钮时新增一条空白行并自动翻页到新增行
12727
+ // 注意点击弹出的子表行详细表单中的新增按钮不会进此service init事件函数中
12728
+ let newItem = {};
12729
+ event.data.__tableItems.push(newItem);
12730
+ lastestFieldValue.push(newItem);
12731
+ event.data.index = lastestFieldValue.length - 1;
12732
+ event.data.__page = lastestFieldValue.length;
12733
+ // 这里新增空白行时要把值同步保存到子表组件中,如果不同步保存的话,用户点击弹出表单右上角的关闭窗口时不会自动删除这里自动增加的空白行,同步后可以让用户手动删除此行
12734
+ doAction({
12735
+ "componentId": "${props.id}",
12736
+ "actionType": "setValue",
12737
+ "args": {
12738
+ "value": lastestFieldValue
12739
+ }
12740
+ });
12741
+ }
12706
12742
  event.data.__tableItems.forEach(function(n,i){
12707
12743
  event.data.__tableItems[i] = lastestFieldValue[i];
12708
12744
  });
@@ -12766,7 +12802,8 @@ async function getForm(props, mode = "edit", formId) {
12766
12802
  "canAccessSuperData": false,
12767
12803
  "className": "steedos-object-form steedos-amis-form"
12768
12804
  };
12769
- if (mode === "edit") {
12805
+ if (mode === "edit" || mode === "new") {
12806
+ // 新增行弹出编辑行表单,在弹出之前已经不用先增加一行,因为在翻页service初始化的时候会判断mode为new时自动新增一行
12770
12807
  let onEditItemSubmitScript = `
12771
12808
  // let fieldValue = _.cloneDeep(event.data["${props.name}"]);
12772
12809
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
@@ -12805,66 +12842,66 @@ async function getForm(props, mode = "edit", formId) {
12805
12842
  }
12806
12843
  });
12807
12844
  }
12808
- else if (mode === "new") {
12809
- let onNewItemSubmitScript = `
12810
- let newItem = JSON.parse(JSON.stringify(event.data));
12811
- if(event.data["${props.name}"]){
12812
- // let fieldValue = event.data.__tableItems;
12813
- // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
12814
- let fieldValue = event.data["${props.name}"];
12815
- fieldValue.push(newItem);
12816
- doAction({
12817
- "componentId": "${props.id}",
12818
- "actionType": "setValue",
12819
- "args": {
12820
- "value": fieldValue
12821
- }
12822
- });
12823
- }
12824
- else{
12825
- // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
12826
- doAction({
12827
- "componentId": "${props.id}",
12828
- "actionType": "setValue",
12829
- "args": {
12830
- "value": [newItem]
12831
- }
12832
- });
12833
- }
12834
- `;
12835
- Object.assign(schema, {
12836
- "onEvent": {
12837
- "submit": {
12838
- "weight": 0,
12839
- "actions": [
12840
- {
12841
- "actionType": "custom",
12842
- "script": onNewItemSubmitScript
12843
- },
12844
- // {
12845
- // "componentId": props.id,
12846
- // "actionType": "addItem",//input-table组件的needConfirm属性为true时,addItem动作会把新加的行显示为编辑状态,所以只能使用上面的custom script来setValue实现添加行
12847
- // "args": {
12848
- // "index": `\${${props.name}.length || 9000}`,//这里加9000是因为字段如果没放在form组件内,props.name.length拿不到值
12849
- // "item": {
12850
- // "&": "$$"
12851
- // }
12852
- // }
12853
- // }
12854
- ]
12855
- }
12856
- }
12857
- });
12858
- }
12845
+ // else if (mode === "new") {
12846
+ // let onNewItemSubmitScript = `
12847
+ // let newItem = JSON.parse(JSON.stringify(event.data));
12848
+ // if(event.data["${props.name}"]){
12849
+ // // let fieldValue = event.data.__tableItems;
12850
+ // // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
12851
+ // let fieldValue = event.data["${props.name}"];
12852
+ // fieldValue.push(newItem);
12853
+ // doAction({
12854
+ // "componentId": "${props.id}",
12855
+ // "actionType": "setValue",
12856
+ // "args": {
12857
+ // "value": fieldValue
12858
+ // }
12859
+ // });
12860
+ // }
12861
+ // else{
12862
+ // // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
12863
+ // doAction({
12864
+ // "componentId": "${props.id}",
12865
+ // "actionType": "setValue",
12866
+ // "args": {
12867
+ // "value": [newItem]
12868
+ // }
12869
+ // });
12870
+ // }
12871
+ // `;
12872
+ // Object.assign(schema, {
12873
+ // "onEvent": {
12874
+ // "submit": {
12875
+ // "weight": 0,
12876
+ // "actions": [
12877
+ // {
12878
+ // "actionType": "custom",
12879
+ // "script": onNewItemSubmitScript
12880
+ // },
12881
+ // // {
12882
+ // // "componentId": props.id,
12883
+ // // "actionType": "addItem",//input-table组件的needConfirm属性为true时,addItem动作会把新加的行显示为编辑状态,所以只能使用上面的custom script来setValue实现添加行
12884
+ // // "args": {
12885
+ // // "index": `\${${props.name}.length || 9000}`,//这里加9000是因为字段如果没放在form组件内,props.name.length拿不到值
12886
+ // // "item": {
12887
+ // // "&": "$$"
12888
+ // // }
12889
+ // // }
12890
+ // // }
12891
+ // ]
12892
+ // }
12893
+ // }
12894
+ // });
12895
+ // }
12859
12896
  schema = getFormPaginationWrapper(props, schema, mode);
12860
12897
  return schema;
12861
12898
  }
12862
12899
 
12863
12900
 
12864
12901
  /**
12865
- * 编辑、新增和查看按钮actions
12902
+ * 编辑、新增、删除、查看按钮actions
12866
12903
  * @param {*} props
12867
- * @param {*} mode edit/new/readonly
12904
+ * @param {*} mode edit/new/readonly/delete
12868
12905
  */
12869
12906
  async function getButtonActions(props, mode) {
12870
12907
  let actions = [];
@@ -12955,6 +12992,7 @@ async function getButtonActions(props, mode) {
12955
12992
  }
12956
12993
  ];
12957
12994
  if(props.addable){
12995
+ // 有新增行权限时额外添加新增和复制按钮
12958
12996
  dialogButtons = [
12959
12997
  {
12960
12998
  "type": "button",
@@ -13019,7 +13057,8 @@ async function getButtonActions(props, mode) {
13019
13057
  // "__tableItems": `\${${props.name}}`
13020
13058
  // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13021
13059
  // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13022
- "__tableItems": `\${${props.name}|json|toJson}`
13060
+ // "__tableItems": `\${${props.name}|json|toJson}`
13061
+ "__tableItems": `\${(${props.name} || [])|json|toJson}`
13023
13062
  },
13024
13063
  "actions": dialogButtons,
13025
13064
  "onEvent": {
@@ -13042,11 +13081,12 @@ async function getButtonActions(props, mode) {
13042
13081
  Object.assign(actionShowEditDialog.dialog, props.dialog);
13043
13082
  }
13044
13083
  if (mode == "new") {
13045
- let onNewLineScript = `
13084
+ `
13046
13085
  let newItem = {};
13047
13086
  if(event.data["${props.name}"]){
13048
13087
  // let fieldValue = event.data.__tableItems;
13049
13088
  // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
13089
+ // let fieldValue = _.clone(event.data["${props.name}"]);
13050
13090
  let fieldValue = event.data["${props.name}"];
13051
13091
  fieldValue.push(newItem);
13052
13092
  doAction({
@@ -13070,11 +13110,9 @@ async function getButtonActions(props, mode) {
13070
13110
  event.data.index = 1;
13071
13111
  }
13072
13112
  `;
13073
- let actionNewLine = {
13074
- "actionType": "custom",
13075
- "script": onNewLineScript
13076
- };
13077
- actions = [actionNewLine, actionShowEditDialog];
13113
+ // 新增行时不需要在弹出编辑表单前先加一行,因为会在编辑表单所在service初始化时判断到是新增就自动增加一行,因为这里拿不到event.data.__tableItems,也无法变更其值
13114
+ // actions = [actionNewLine, actionShowEditDialog];
13115
+ actions = [actionShowEditDialog];
13078
13116
  }
13079
13117
  else if (mode == "edit") {
13080
13118
  actions = [actionShowEditDialog];
@@ -13112,12 +13150,47 @@ async function getButtonActions(props, mode) {
13112
13150
  // "__tableItems": `\${${props.name}}`
13113
13151
  // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13114
13152
  // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13115
- "__tableItems": `\${${props.name}|json|toJson}`
13116
- },
13153
+ // "__tableItems": `\${${props.name}|json|toJson}`
13154
+ "__tableItems": `\${(${props.name} || [])|json|toJson}`
13155
+ },
13117
13156
  }
13118
13157
  }
13119
13158
  ];
13120
13159
  }
13160
+ else if (mode == "delete") {
13161
+ let tableServiceId = getComponentId("table_service", props.id);
13162
+ let onDeleteItemScript = `
13163
+ // let fieldValue = event.data["${props.name}"];
13164
+ let scope = event.context.scoped;
13165
+ let __wrapperServiceId = "${tableServiceId}";
13166
+ let wrapperService = scope.getComponentById(__wrapperServiceId);
13167
+ let wrapperServiceData = wrapperService.getData();
13168
+ // 这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
13169
+ // 这里_.clone是因为字段设计布局设置分组这种弹出窗口中的子表组件,直接删除后,点取消无法还原
13170
+ let lastestFieldValue = _.clone(wrapperServiceData["${props.name}"]);
13171
+ lastestFieldValue.splice(event.data.index, 1);
13172
+ doAction({
13173
+ "componentId": "${props.id}",
13174
+ "actionType": "setValue",
13175
+ "args": {
13176
+ "value": lastestFieldValue
13177
+ }
13178
+ });
13179
+ `;
13180
+ actions = [
13181
+ // {
13182
+ // "actionType": "deleteItem",
13183
+ // "args": {
13184
+ // "index": "${index+','}" //这里不加逗号后续会报错,语法是逗号分隔可以删除多行
13185
+ // },
13186
+ // "componentId": props.id
13187
+ // },
13188
+ {
13189
+ "actionType": "custom",
13190
+ "script": onDeleteItemScript
13191
+ }
13192
+ ];
13193
+ }
13121
13194
  return actions;
13122
13195
  }
13123
13196
 
@@ -13163,24 +13236,7 @@ async function getButtonView(props) {
13163
13236
  };
13164
13237
  }
13165
13238
 
13166
- function getButtonDelete(props) {
13167
- let tableServiceId = getComponentId("table_service", props.id);
13168
- let onDeleteItemScript = `
13169
- // let fieldValue = event.data["${props.name}"];
13170
- let scope = event.context.scoped;
13171
- let __wrapperServiceId = "${tableServiceId}";
13172
- let wrapperService = scope.getComponentById(__wrapperServiceId);
13173
- let wrapperServiceData = wrapperService.getData();
13174
- let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
13175
- lastestFieldValue.splice(event.data.index, 1);
13176
- doAction({
13177
- "componentId": "${props.id}",
13178
- "actionType": "setValue",
13179
- "args": {
13180
- "value": lastestFieldValue
13181
- }
13182
- });
13183
- `;
13239
+ async function getButtonDelete(props) {
13184
13240
  return {
13185
13241
  "type": "button",
13186
13242
  "label": "",
@@ -13188,19 +13244,7 @@ function getButtonDelete(props) {
13188
13244
  "level": "link",
13189
13245
  "onEvent": {
13190
13246
  "click": {
13191
- "actions": [
13192
- // {
13193
- // "actionType": "deleteItem",
13194
- // "args": {
13195
- // "index": "${index+','}" //这里不加逗号后续会报错,语法是逗号分隔可以删除多行
13196
- // },
13197
- // "componentId": props.id
13198
- // },
13199
- {
13200
- "actionType": "custom",
13201
- "script": onDeleteItemScript
13202
- }
13203
- ]
13247
+ "actions": await getButtonActions(props, "delete")
13204
13248
  }
13205
13249
  }
13206
13250
  };
@@ -13240,7 +13284,7 @@ const getAmisInputTableSchema = async (props) => {
13240
13284
  buttonsForColumnOperations.push(buttonViewSchema);
13241
13285
  }
13242
13286
  if (props.removable) {
13243
- let buttonDeleteSchema = getButtonDelete(props);
13287
+ let buttonDeleteSchema = await getButtonDelete(props);
13244
13288
  buttonsForColumnOperations.push(buttonDeleteSchema);
13245
13289
  }
13246
13290
  let inputTableSchema = {