@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.cjs.js CHANGED
@@ -1653,6 +1653,7 @@ async function getQuickEditSchema(field, options){
1653
1653
  {
1654
1654
  "actionType": "custom",
1655
1655
  "script": `
1656
+
1656
1657
  var _display = _.cloneDeep(event.data._display);
1657
1658
  ${displayField}
1658
1659
  doAction({actionType: 'setValue', "args": {"value": {_display}},componentId: "${quickEditId}"});
@@ -2039,7 +2040,9 @@ async function getTableColumns(fields, options){
2039
2040
  if(!options.isLookup && !options.isInputTable){
2040
2041
  //将_display放入crud的columns中,可以通过setvalue修改行内数据域的_display,而不影响上层items的_display,用于批量编辑
2041
2042
  columns.push({name: '_display',type: 'static', width: 32, placeholder: "",id: "_display_${_index}", className: "hidden"});
2042
- columns.push({name: '_index',type: 'text', width: 32, placeholder: ""});
2043
+ if(!options.enable_tree){
2044
+ columns.push({name: '_index',type: 'text', width: 32, placeholder: ""});
2045
+ }
2043
2046
  }
2044
2047
  const allowEdit = options.permissions?.allowEdit && !options.isLookup && options.enable_inline_edit != false;
2045
2048
 
@@ -2890,7 +2893,21 @@ async function getTableApi(mainObject, fields, options){
2890
2893
 
2891
2894
  if(enable_tree){
2892
2895
  const records = payload.data.rows || [];
2893
- const getTreeOptions = SteedosUI.getTreeOptions
2896
+ const getTreeOptions = SteedosUI.getTreeOptions;
2897
+ const assignIndexToTreeRecords = function(tree, parentIndex) {
2898
+ tree.forEach(function (node, index) {
2899
+ // 构建当前节点的 _index
2900
+ var currentIndex = parentIndex ? parentIndex + '-' + (index + 1) : '' + (index + 1);
2901
+
2902
+ // 赋值给节点
2903
+ node._index = currentIndex;
2904
+
2905
+ // 如果有子节点,递归调用函数
2906
+ if (node.children && node.children.length > 0) {
2907
+ assignIndexToTreeRecords(node.children, currentIndex);
2908
+ }
2909
+ });
2910
+ };
2894
2911
  let isTreeOptionsComputed = false;
2895
2912
  if(records.length === 1 && records[0].children){
2896
2913
  isTreeOptionsComputed = true;
@@ -2898,6 +2915,7 @@ async function getTableApi(mainObject, fields, options){
2898
2915
  if(!isTreeOptionsComputed){
2899
2916
  // 如果api接口设置在缓存,缓存期间并不会重新请求接口,payload.data.rows是上次计算后的结果
2900
2917
  payload.data.rows = getTreeOptions(records,{"valueField":"_id"});
2918
+ assignIndexToTreeRecords(payload.data.rows, '');
2901
2919
  }
2902
2920
  try{
2903
2921
  setTimeout(() => {
@@ -8254,7 +8272,7 @@ async function getObjectCRUD(objectSchema, fields, options){
8254
8272
  let tableOptions = Object.assign({
8255
8273
  idFieldName: objectSchema.idFieldName, labelFieldName: labelFieldName,
8256
8274
  permissions:objectSchema.permissions,enable_inline_edit:objectSchema.enable_inline_edit,
8257
- crudId: listSchema.id || id
8275
+ crudId: listSchema.id || id, enable_tree: objectSchema.enable_tree
8258
8276
  }, options);
8259
8277
  tableOptions.amisData = createObject(options.amisData || {}, {});
8260
8278
  const table = await getTableSchema$1(fields, tableOptions);
@@ -12441,7 +12459,7 @@ async function getFormBody(permissionFields, formFields, ctx){
12441
12459
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12442
12460
  * @Date: 2023-11-15 09:50:22
12443
12461
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12444
- * @LastEditTime: 2023-12-23 22:13:22
12462
+ * @LastEditTime: 2023-12-25 13:13:56
12445
12463
  */
12446
12464
 
12447
12465
  /**
@@ -12688,7 +12706,7 @@ function getFormPagination(props, mode) {
12688
12706
  * @returns 带翻页容器的wrapper
12689
12707
  */
12690
12708
  function getFormPaginationWrapper(props, form, mode) {
12691
- console.log("==getFormPaginationWrapper===", props, mode);
12709
+ // console.log("==getFormPaginationWrapper===", props, mode);
12692
12710
  let serviceId = getComponentId("form_pagination", props.id);
12693
12711
  let tableServiceId = getComponentId("table_service", props.id);
12694
12712
  let innerForm = Object.assign({}, form, {
@@ -12728,8 +12746,26 @@ function getFormPaginationWrapper(props, form, mode) {
12728
12746
  let __wrapperServiceId = "${tableServiceId}";
12729
12747
  let wrapperService = scope.getComponentById(__wrapperServiceId);
12730
12748
  let wrapperServiceData = wrapperService.getData();
12731
- let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
12749
+ let lastestFieldValue = wrapperServiceData["${props.name}"] || [];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
12732
12750
  //不可以直接像event.data.__tableItems = lastestFieldValue; 这样整个赋值,否则作用域会断
12751
+ let mode = "${mode}";
12752
+ if(mode === "new"){
12753
+ // 点击子表组件底部新增按钮时新增一条空白行并自动翻页到新增行
12754
+ // 注意点击弹出的子表行详细表单中的新增按钮不会进此service init事件函数中
12755
+ let newItem = {};
12756
+ event.data.__tableItems.push(newItem);
12757
+ lastestFieldValue.push(newItem);
12758
+ event.data.index = lastestFieldValue.length - 1;
12759
+ event.data.__page = lastestFieldValue.length;
12760
+ // 这里新增空白行时要把值同步保存到子表组件中,如果不同步保存的话,用户点击弹出表单右上角的关闭窗口时不会自动删除这里自动增加的空白行,同步后可以让用户手动删除此行
12761
+ doAction({
12762
+ "componentId": "${props.id}",
12763
+ "actionType": "setValue",
12764
+ "args": {
12765
+ "value": lastestFieldValue
12766
+ }
12767
+ });
12768
+ }
12733
12769
  event.data.__tableItems.forEach(function(n,i){
12734
12770
  event.data.__tableItems[i] = lastestFieldValue[i];
12735
12771
  });
@@ -12793,7 +12829,8 @@ async function getForm(props, mode = "edit", formId) {
12793
12829
  "canAccessSuperData": false,
12794
12830
  "className": "steedos-object-form steedos-amis-form"
12795
12831
  };
12796
- if (mode === "edit") {
12832
+ if (mode === "edit" || mode === "new") {
12833
+ // 新增行弹出编辑行表单,在弹出之前已经不用先增加一行,因为在翻页service初始化的时候会判断mode为new时自动新增一行
12797
12834
  let onEditItemSubmitScript = `
12798
12835
  // let fieldValue = _.cloneDeep(event.data["${props.name}"]);
12799
12836
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
@@ -12832,66 +12869,66 @@ async function getForm(props, mode = "edit", formId) {
12832
12869
  }
12833
12870
  });
12834
12871
  }
12835
- else if (mode === "new") {
12836
- let onNewItemSubmitScript = `
12837
- let newItem = JSON.parse(JSON.stringify(event.data));
12838
- if(event.data["${props.name}"]){
12839
- // let fieldValue = event.data.__tableItems;
12840
- // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
12841
- let fieldValue = event.data["${props.name}"];
12842
- fieldValue.push(newItem);
12843
- doAction({
12844
- "componentId": "${props.id}",
12845
- "actionType": "setValue",
12846
- "args": {
12847
- "value": fieldValue
12848
- }
12849
- });
12850
- }
12851
- else{
12852
- // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
12853
- doAction({
12854
- "componentId": "${props.id}",
12855
- "actionType": "setValue",
12856
- "args": {
12857
- "value": [newItem]
12858
- }
12859
- });
12860
- }
12861
- `;
12862
- Object.assign(schema, {
12863
- "onEvent": {
12864
- "submit": {
12865
- "weight": 0,
12866
- "actions": [
12867
- {
12868
- "actionType": "custom",
12869
- "script": onNewItemSubmitScript
12870
- },
12871
- // {
12872
- // "componentId": props.id,
12873
- // "actionType": "addItem",//input-table组件的needConfirm属性为true时,addItem动作会把新加的行显示为编辑状态,所以只能使用上面的custom script来setValue实现添加行
12874
- // "args": {
12875
- // "index": `\${${props.name}.length || 9000}`,//这里加9000是因为字段如果没放在form组件内,props.name.length拿不到值
12876
- // "item": {
12877
- // "&": "$$"
12878
- // }
12879
- // }
12880
- // }
12881
- ]
12882
- }
12883
- }
12884
- });
12885
- }
12872
+ // else if (mode === "new") {
12873
+ // let onNewItemSubmitScript = `
12874
+ // let newItem = JSON.parse(JSON.stringify(event.data));
12875
+ // if(event.data["${props.name}"]){
12876
+ // // let fieldValue = event.data.__tableItems;
12877
+ // // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
12878
+ // let fieldValue = event.data["${props.name}"];
12879
+ // fieldValue.push(newItem);
12880
+ // doAction({
12881
+ // "componentId": "${props.id}",
12882
+ // "actionType": "setValue",
12883
+ // "args": {
12884
+ // "value": fieldValue
12885
+ // }
12886
+ // });
12887
+ // }
12888
+ // else{
12889
+ // // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
12890
+ // doAction({
12891
+ // "componentId": "${props.id}",
12892
+ // "actionType": "setValue",
12893
+ // "args": {
12894
+ // "value": [newItem]
12895
+ // }
12896
+ // });
12897
+ // }
12898
+ // `;
12899
+ // Object.assign(schema, {
12900
+ // "onEvent": {
12901
+ // "submit": {
12902
+ // "weight": 0,
12903
+ // "actions": [
12904
+ // {
12905
+ // "actionType": "custom",
12906
+ // "script": onNewItemSubmitScript
12907
+ // },
12908
+ // // {
12909
+ // // "componentId": props.id,
12910
+ // // "actionType": "addItem",//input-table组件的needConfirm属性为true时,addItem动作会把新加的行显示为编辑状态,所以只能使用上面的custom script来setValue实现添加行
12911
+ // // "args": {
12912
+ // // "index": `\${${props.name}.length || 9000}`,//这里加9000是因为字段如果没放在form组件内,props.name.length拿不到值
12913
+ // // "item": {
12914
+ // // "&": "$$"
12915
+ // // }
12916
+ // // }
12917
+ // // }
12918
+ // ]
12919
+ // }
12920
+ // }
12921
+ // });
12922
+ // }
12886
12923
  schema = getFormPaginationWrapper(props, schema, mode);
12887
12924
  return schema;
12888
12925
  }
12889
12926
 
12890
12927
 
12891
12928
  /**
12892
- * 编辑、新增和查看按钮actions
12929
+ * 编辑、新增、删除、查看按钮actions
12893
12930
  * @param {*} props
12894
- * @param {*} mode edit/new/readonly
12931
+ * @param {*} mode edit/new/readonly/delete
12895
12932
  */
12896
12933
  async function getButtonActions(props, mode) {
12897
12934
  let actions = [];
@@ -12982,6 +13019,7 @@ async function getButtonActions(props, mode) {
12982
13019
  }
12983
13020
  ];
12984
13021
  if(props.addable){
13022
+ // 有新增行权限时额外添加新增和复制按钮
12985
13023
  dialogButtons = [
12986
13024
  {
12987
13025
  "type": "button",
@@ -13046,7 +13084,8 @@ async function getButtonActions(props, mode) {
13046
13084
  // "__tableItems": `\${${props.name}}`
13047
13085
  // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13048
13086
  // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13049
- "__tableItems": `\${${props.name}|json|toJson}`
13087
+ // "__tableItems": `\${${props.name}|json|toJson}`
13088
+ "__tableItems": `\${(${props.name} || [])|json|toJson}`
13050
13089
  },
13051
13090
  "actions": dialogButtons,
13052
13091
  "onEvent": {
@@ -13069,11 +13108,12 @@ async function getButtonActions(props, mode) {
13069
13108
  Object.assign(actionShowEditDialog.dialog, props.dialog);
13070
13109
  }
13071
13110
  if (mode == "new") {
13072
- let onNewLineScript = `
13111
+ `
13073
13112
  let newItem = {};
13074
13113
  if(event.data["${props.name}"]){
13075
13114
  // let fieldValue = event.data.__tableItems;
13076
13115
  // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
13116
+ // let fieldValue = _.clone(event.data["${props.name}"]);
13077
13117
  let fieldValue = event.data["${props.name}"];
13078
13118
  fieldValue.push(newItem);
13079
13119
  doAction({
@@ -13097,11 +13137,9 @@ async function getButtonActions(props, mode) {
13097
13137
  event.data.index = 1;
13098
13138
  }
13099
13139
  `;
13100
- let actionNewLine = {
13101
- "actionType": "custom",
13102
- "script": onNewLineScript
13103
- };
13104
- actions = [actionNewLine, actionShowEditDialog];
13140
+ // 新增行时不需要在弹出编辑表单前先加一行,因为会在编辑表单所在service初始化时判断到是新增就自动增加一行,因为这里拿不到event.data.__tableItems,也无法变更其值
13141
+ // actions = [actionNewLine, actionShowEditDialog];
13142
+ actions = [actionShowEditDialog];
13105
13143
  }
13106
13144
  else if (mode == "edit") {
13107
13145
  actions = [actionShowEditDialog];
@@ -13139,12 +13177,47 @@ async function getButtonActions(props, mode) {
13139
13177
  // "__tableItems": `\${${props.name}}`
13140
13178
  // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13141
13179
  // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13142
- "__tableItems": `\${${props.name}|json|toJson}`
13143
- },
13180
+ // "__tableItems": `\${${props.name}|json|toJson}`
13181
+ "__tableItems": `\${(${props.name} || [])|json|toJson}`
13182
+ },
13144
13183
  }
13145
13184
  }
13146
13185
  ];
13147
13186
  }
13187
+ else if (mode == "delete") {
13188
+ let tableServiceId = getComponentId("table_service", props.id);
13189
+ let onDeleteItemScript = `
13190
+ // let fieldValue = event.data["${props.name}"];
13191
+ let scope = event.context.scoped;
13192
+ let __wrapperServiceId = "${tableServiceId}";
13193
+ let wrapperService = scope.getComponentById(__wrapperServiceId);
13194
+ let wrapperServiceData = wrapperService.getData();
13195
+ // 这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
13196
+ // 这里_.clone是因为字段设计布局设置分组这种弹出窗口中的子表组件,直接删除后,点取消无法还原
13197
+ let lastestFieldValue = _.clone(wrapperServiceData["${props.name}"]);
13198
+ lastestFieldValue.splice(event.data.index, 1);
13199
+ doAction({
13200
+ "componentId": "${props.id}",
13201
+ "actionType": "setValue",
13202
+ "args": {
13203
+ "value": lastestFieldValue
13204
+ }
13205
+ });
13206
+ `;
13207
+ actions = [
13208
+ // {
13209
+ // "actionType": "deleteItem",
13210
+ // "args": {
13211
+ // "index": "${index+','}" //这里不加逗号后续会报错,语法是逗号分隔可以删除多行
13212
+ // },
13213
+ // "componentId": props.id
13214
+ // },
13215
+ {
13216
+ "actionType": "custom",
13217
+ "script": onDeleteItemScript
13218
+ }
13219
+ ];
13220
+ }
13148
13221
  return actions;
13149
13222
  }
13150
13223
 
@@ -13190,24 +13263,7 @@ async function getButtonView(props) {
13190
13263
  };
13191
13264
  }
13192
13265
 
13193
- function getButtonDelete(props) {
13194
- let tableServiceId = getComponentId("table_service", props.id);
13195
- let onDeleteItemScript = `
13196
- // let fieldValue = event.data["${props.name}"];
13197
- let scope = event.context.scoped;
13198
- let __wrapperServiceId = "${tableServiceId}";
13199
- let wrapperService = scope.getComponentById(__wrapperServiceId);
13200
- let wrapperServiceData = wrapperService.getData();
13201
- let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
13202
- lastestFieldValue.splice(event.data.index, 1);
13203
- doAction({
13204
- "componentId": "${props.id}",
13205
- "actionType": "setValue",
13206
- "args": {
13207
- "value": lastestFieldValue
13208
- }
13209
- });
13210
- `;
13266
+ async function getButtonDelete(props) {
13211
13267
  return {
13212
13268
  "type": "button",
13213
13269
  "label": "",
@@ -13215,19 +13271,7 @@ function getButtonDelete(props) {
13215
13271
  "level": "link",
13216
13272
  "onEvent": {
13217
13273
  "click": {
13218
- "actions": [
13219
- // {
13220
- // "actionType": "deleteItem",
13221
- // "args": {
13222
- // "index": "${index+','}" //这里不加逗号后续会报错,语法是逗号分隔可以删除多行
13223
- // },
13224
- // "componentId": props.id
13225
- // },
13226
- {
13227
- "actionType": "custom",
13228
- "script": onDeleteItemScript
13229
- }
13230
- ]
13274
+ "actions": await getButtonActions(props, "delete")
13231
13275
  }
13232
13276
  }
13233
13277
  };
@@ -13267,7 +13311,7 @@ const getAmisInputTableSchema = async (props) => {
13267
13311
  buttonsForColumnOperations.push(buttonViewSchema);
13268
13312
  }
13269
13313
  if (props.removable) {
13270
- let buttonDeleteSchema = getButtonDelete(props);
13314
+ let buttonDeleteSchema = await getButtonDelete(props);
13271
13315
  buttonsForColumnOperations.push(buttonDeleteSchema);
13272
13316
  }
13273
13317
  let inputTableSchema = {