@steedos-widgets/amis-lib 3.6.2-beta.2 → 3.6.2-beta.4

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
@@ -3399,6 +3399,18 @@ function getBatchDelete(objectName){
3399
3399
  return {
3400
3400
  method: 'post',
3401
3401
  url: getApi$2(),
3402
+ adaptor: `
3403
+ if(payload.errors){
3404
+ payload.data.deleteErrorMessage = [];
3405
+ payload.errors.forEach(function(error){
3406
+ let errorRecord = error.path.map(function (item) {
3407
+ return item.split('delete__')[1].to_float() + 1;
3408
+ }).toString();
3409
+ payload.data.deleteErrorMessage.push("第" + errorRecord + "条记录删除出现异常,报错信息为(" + (window.t ? window.t(error.message) : error.message) + ")");
3410
+ })
3411
+ }
3412
+ return payload;
3413
+ `,
3402
3414
  requestAdaptor: `
3403
3415
  var ids = api.data.ids.split(",");
3404
3416
  var deleteArray = [];
@@ -8095,7 +8107,10 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
8095
8107
  // ]
8096
8108
  if(options.displayAs === 'split'){
8097
8109
  return [
8098
- "switch-per-page",
8110
+ {
8111
+ "type": "switch-per-page",
8112
+ "visibleOn": "${count >= 20}"
8113
+ },
8099
8114
  {
8100
8115
  "type": "pagination",
8101
8116
  "maxButtons": 5,
@@ -8117,7 +8132,6 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
8117
8132
  else {
8118
8133
  if(options && options.isRelated){
8119
8134
  return [
8120
- "statistics",
8121
8135
  {
8122
8136
  "type": "pagination",
8123
8137
  "maxButtons": 10,
@@ -8130,7 +8144,6 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
8130
8144
  const no_pagination = mainObject.paging && (mainObject.paging.enabled === false);
8131
8145
  const is_lookup = options.isLookup;
8132
8146
  const commonConfig = [
8133
- "statistics",
8134
8147
  {
8135
8148
  "type": "pagination",
8136
8149
  "maxButtons": 10,
@@ -8141,7 +8154,10 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
8141
8154
  if (no_pagination && is_lookup) {
8142
8155
  return commonConfig;
8143
8156
  } else {
8144
- return ["switch-per-page", ...commonConfig];
8157
+ return [{
8158
+ "type": "switch-per-page",
8159
+ "visibleOn": "${count >= 20}"
8160
+ }, ...commonConfig];
8145
8161
  }
8146
8162
  }
8147
8163
  }
@@ -8249,6 +8265,29 @@ function getBulkActions(objectSchema){
8249
8265
  "className": "hidden",
8250
8266
  "id": "batchDelete",
8251
8267
  "api": getBatchDelete(objectSchema.name),
8268
+ "feedback": {
8269
+ "title": "删除警告",
8270
+ "visibleOn": "${deleteErrorMessage}",
8271
+ "body": [
8272
+ {
8273
+ "type": "each",
8274
+ "name": "deleteErrorMessage",
8275
+ "items": {
8276
+ "type": "alert",
8277
+ "body": "${item}",
8278
+ "level": "danger",
8279
+ "className": "mb-3"
8280
+ }
8281
+ }
8282
+ ],
8283
+ "actions": [
8284
+ {
8285
+ "type": "button",
8286
+ "actionType": "close",
8287
+ "label": "关闭"
8288
+ }
8289
+ ]
8290
+ }
8252
8291
  }
8253
8292
  // {
8254
8293
  // "label": "批量修改",
@@ -12701,8 +12740,8 @@ async function getFormBody(permissionFields, formFields, ctx){
12701
12740
  /*
12702
12741
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12703
12742
  * @Date: 2023-11-15 09:50:22
12704
- * @LastEditors: liaodaxue
12705
- * @LastEditTime: 2024-01-09 18:12:28
12743
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12744
+ * @LastEditTime: 2024-01-14 21:08:32
12706
12745
  */
12707
12746
 
12708
12747
  /**
@@ -12851,7 +12890,12 @@ function getFormPagination(props, mode) {
12851
12890
  let currentIndex = event.data.index;
12852
12891
  // 翻页到下一页之前需要先把当前页改动的内容保存到中间变量__tableItems中
12853
12892
  let currentFormValues = scope.getComponentById(__formId).getValues();
12854
- fieldValue[currentIndex] = currentFormValues;
12893
+ if(event.data.parent){
12894
+ fieldValue[event.data.__parentIndex].children[currentIndex] = currentFormValues;
12895
+ }
12896
+ else{
12897
+ fieldValue[currentIndex] = currentFormValues;
12898
+ }
12855
12899
  // 翻页到下一页前需要同时把改动的内容保存到最终正式的表单字段中,所以额外给正式表单字段执行一次setValue
12856
12900
  doAction({
12857
12901
  "componentId": "${props.id}",
@@ -12918,7 +12962,8 @@ function getFormPagination(props, mode) {
12918
12962
  },
12919
12963
  {
12920
12964
  "type": "tpl",
12921
- "tpl": "${__page}/${__tableItems.length}"
12965
+ // 这里用__super.parent,加__super是为了防止当前记录有字段名为parent的重名变量
12966
+ "tpl": "${__page}/${__super.parent ? __tableItems[__parentIndex]['children'].length : __tableItems.length}"
12922
12967
  },
12923
12968
  {
12924
12969
  "type": "button",
@@ -12926,7 +12971,9 @@ function getFormPagination(props, mode) {
12926
12971
  "icon": `fa fa-angle-right`,
12927
12972
  "level": "link",
12928
12973
  "pageChangeDirection": "next",
12929
- "disabledOn": showPagination ? "${__page >= __tableItems.length}" : "true",
12974
+ // "disabledOn": showPagination ? "${__page >= __tableItems.length}" : "true",
12975
+ // 这里用__super.parent,加__super是为了防止当前记录有字段名为parent的重名变量
12976
+ "disabledOn": showPagination ? "${__page >= (__super.parent ? __tableItems[__parentIndex]['children'].length : __tableItems.length)}" : "true",
12930
12977
  "size": "sm",
12931
12978
  "id": buttonNextId,
12932
12979
  "onEvent": {
@@ -12959,7 +13006,7 @@ function getFormPaginationWrapper(props, form, mode) {
12959
13006
  "data": {
12960
13007
  // 这里加__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
12961
13008
  // 比如“对象字段”对象options字段是一个子表字段,但是主表(即“对象字段”对象)中正好有一个名为index的字段
12962
- "&": "${__tableItems[__super.index]}"
13009
+ "&": "${__super.parent ? __tableItems[__parentIndex]['children'][__super.index] : __tableItems[__super.index]}"
12963
13010
  }
12964
13011
  });
12965
13012
  let formBody = [
@@ -12982,6 +13029,10 @@ function getFormPaginationWrapper(props, form, mode) {
12982
13029
  }
12983
13030
  ];
12984
13031
  let onServiceInitedScript = `
13032
+ if(event.data.parent){
13033
+ // 如果是子行,即在节点嵌套情况下,当前节点如果是children属性下的子节点时,则算出其所属父行的索引值
13034
+ event.data.__parentIndex = _.findIndex(event.data.__tableItems, {_id: event.data.parent._id});
13035
+ }
12985
13036
  // 以下脚本是为了解决有时弹出编辑表单时,表单中的值比最后一次编辑保存的值会延迟一拍。
12986
13037
  // 比如:inlineEditMode模式时,用户在表格单元格中直接修改数据,然后弹出的表单form中并没有包含单元格中修改的内容
12987
13038
  // 另外有的地方在非inlineEditMode模式时也会有这种延迟一拍问题,比如对象字段中下拉框类型字段的”选择项“属性
@@ -13037,6 +13088,7 @@ function getFormPaginationWrapper(props, form, mode) {
13037
13088
  // "body": formBody,
13038
13089
  "data": {
13039
13090
  "__page": "${index + 1}",
13091
+ "__parentIndex": null,//兼容节点嵌套情况,即节点中有children属性时,这里记录当前节点所属上层节点index,只支持向上找一层,不支持多层
13040
13092
  // "__total": `\${${props.name}.length}`,
13041
13093
  // "__total": "${__tableItems.length}",
13042
13094
  // "__paginationServiceId": serviceId,
@@ -13084,7 +13136,17 @@ async function getForm(props, mode = "edit", formId) {
13084
13136
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
13085
13137
  //这里加__super.__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
13086
13138
  // 比如“对象字段”对象options字段是一个子表字段,但是主表(即“对象字段”对象)中正好有一个名为index的字段
13087
- fieldValue[event.data.__super.__super.index] = JSON.parse(JSON.stringify(event.data));
13139
+ // fieldValue[event.data.__super.__super.index] = JSON.parse(JSON.stringify(event.data));
13140
+ var currentIndex = event.data.__super.__super.index;
13141
+ var currentFormValues = JSON.parse(JSON.stringify(event.data));
13142
+ var parent = event.data.__super.__super.parent;
13143
+ var __parentIndex = event.data.__super.__super.__parentIndex;
13144
+ if(parent){
13145
+ fieldValue[__parentIndex].children[currentIndex] = currentFormValues;
13146
+ }
13147
+ else{
13148
+ fieldValue[currentIndex] = currentFormValues;
13149
+ }
13088
13150
  doAction({
13089
13151
  "componentId": "${props.id}",
13090
13152
  "actionType": "setValue",
@@ -13224,7 +13286,14 @@ async function getButtonActions(props, mode) {
13224
13286
  let scope = event.context.scoped;
13225
13287
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
13226
13288
  // 新建一条空白行并保存到子表组件
13227
- fieldValue.push({});
13289
+ var parent = event.data.__super.parent;
13290
+ var __parentIndex = parent && _.findIndex(fieldValue, {_id: parent._id});
13291
+ if(parent){
13292
+ fieldValue[__parentIndex].children.push({});
13293
+ }
13294
+ else{
13295
+ fieldValue.push({});
13296
+ }
13228
13297
  doAction({
13229
13298
  "componentId": "${props.id}",
13230
13299
  "actionType": "setValue",
@@ -13236,7 +13305,13 @@ async function getButtonActions(props, mode) {
13236
13305
  let __paginationServiceId = "${formPaginationId}";
13237
13306
  let __paginationData = scope.getComponentById(__paginationServiceId).getData();
13238
13307
  event.data.index = __paginationData.index;
13239
- event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13308
+ if(parent){
13309
+ event.data.__page = fieldValue[__parentIndex].children.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13310
+ event.data.__parentIndex = __parentIndex; //执行下面的翻页按钮事件中依赖了__parentIndex值
13311
+ }
13312
+ else{
13313
+ event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13314
+ }
13240
13315
  // 触发翻页按钮事件,实现保存当前页数据并跳转到最后一行
13241
13316
  scope.getComponentById(buttonNextId).props.dispatchEvent("click", event.data);
13242
13317
  `;
@@ -13247,7 +13322,15 @@ async function getButtonActions(props, mode) {
13247
13322
  let newItem = scope.getComponentById(__formId).getValues();//这里不可以用event.data,因为其拿到的是弹出表单时的初始值,不是用户实时填写的数据
13248
13323
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
13249
13324
  // 复制当前页数据到新建行并保存到子表组件
13250
- fieldValue.push(newItem);
13325
+ // fieldValue.push(newItem);
13326
+ var parent = event.data.__super.parent;
13327
+ var __parentIndex = parent && _.findIndex(fieldValue, {_id: parent._id});
13328
+ if(parent){
13329
+ fieldValue[__parentIndex].children.push(newItem);
13330
+ }
13331
+ else{
13332
+ fieldValue.push(newItem);
13333
+ }
13251
13334
  doAction({
13252
13335
  "componentId": "${props.id}",
13253
13336
  "actionType": "setValue",
@@ -13259,7 +13342,14 @@ async function getButtonActions(props, mode) {
13259
13342
  let __paginationServiceId = "${formPaginationId}";
13260
13343
  let __paginationData = scope.getComponentById(__paginationServiceId).getData();
13261
13344
  event.data.index = __paginationData.index;
13262
- event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13345
+ // event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13346
+ if(parent){
13347
+ event.data.__page = fieldValue[__parentIndex].children.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13348
+ event.data.__parentIndex = __parentIndex; //执行下面的翻页按钮事件中依赖了__parentIndex值
13349
+ }
13350
+ else{
13351
+ event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13352
+ }
13263
13353
  // 触发翻页按钮事件,实现保存当前页数据并跳转到最后一行
13264
13354
  scope.getComponentById(buttonNextId).props.dispatchEvent("click", event.data);
13265
13355
  `;
@@ -13335,13 +13425,15 @@ async function getButtonActions(props, mode) {
13335
13425
  "_master": "${_master}",
13336
13426
  "global": "${global}",
13337
13427
  "uiSchema": "${uiSchema}",
13338
- "index": "${index}",
13428
+ "index": "${index}",//amis组件自带行索引,在节点嵌套情况下,当前节点如果是children属性下的子节点时,这里的index是当前节点在children中的索引,而不是外层父节点的index
13429
+ "parent": "${__super.parent}",//amis组件自带父节点数据域数据,即节点嵌套情况下,当前节点为某个节点(比如A节点)的children属性下的子节点时,当前节点的父节点(即A节点)的数据域数据
13339
13430
  // "__tableItems": `\${${props.name}}`
13340
13431
  // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13341
13432
  // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13342
13433
  // "__tableItems": `\${${props.name}|json|toJson}`
13343
- "__tableItems": `\${(${props.name} || [])|json|toJson}`
13344
- },
13434
+ // 这里加__super.__super是因为要让映射到准确的作用域层,如果不加,在节点嵌套情况下,当前节点正好是带children属性的节点的话,这里弹出的dialog映射到的会是children数组
13435
+ "__tableItems": `\${((__super.parent ? __super.__super.${props.name} : __super.${props.name}) || [])|json|toJson}`
13436
+ },
13345
13437
  "actions": dialogButtons,
13346
13438
  "onEvent": {
13347
13439
  "confirm": {
@@ -13363,35 +13455,39 @@ async function getButtonActions(props, mode) {
13363
13455
  Object.assign(actionShowEditDialog.dialog, props.dialog);
13364
13456
  }
13365
13457
  if (mode == "new") {
13366
- `
13367
- let newItem = {};
13368
- if(event.data["${props.name}"]){
13369
- // let fieldValue = event.data.__tableItems;
13370
- // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
13371
- // let fieldValue = _.clone(event.data["${props.name}"]);
13372
- let fieldValue = event.data["${props.name}"];
13373
- fieldValue.push(newItem);
13374
- doAction({
13375
- "componentId": "${props.id}",
13376
- "actionType": "setValue",
13377
- "args": {
13378
- "value": fieldValue
13379
- }
13380
- });
13381
- event.data.index = fieldValue.length - 1;
13382
- }
13383
- else{
13384
- // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
13385
- doAction({
13386
- "componentId": "${props.id}",
13387
- "actionType": "setValue",
13388
- "args": {
13389
- "value": [newItem]
13390
- }
13391
- });
13392
- event.data.index = 1;
13393
- }
13394
- `;
13458
+ // let onNewLineScript = `
13459
+ // let newItem = {};
13460
+ // if(event.data["${props.name}"]){
13461
+ // // let fieldValue = event.data.__tableItems;
13462
+ // // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
13463
+ // // let fieldValue = _.clone(event.data["${props.name}"]);
13464
+ // let fieldValue = event.data["${props.name}"];
13465
+ // fieldValue.push(newItem);
13466
+ // doAction({
13467
+ // "componentId": "${props.id}",
13468
+ // "actionType": "setValue",
13469
+ // "args": {
13470
+ // "value": fieldValue
13471
+ // }
13472
+ // });
13473
+ // event.data.index = fieldValue.length - 1;
13474
+ // }
13475
+ // else{
13476
+ // // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
13477
+ // doAction({
13478
+ // "componentId": "${props.id}",
13479
+ // "actionType": "setValue",
13480
+ // "args": {
13481
+ // "value": [newItem]
13482
+ // }
13483
+ // });
13484
+ // event.data.index = 1;
13485
+ // }
13486
+ // `;
13487
+ // let actionNewLine = {
13488
+ // "actionType": "custom",
13489
+ // "script": onNewLineScript
13490
+ // };
13395
13491
  // 新增行时不需要在弹出编辑表单前先加一行,因为会在编辑表单所在service初始化时判断到是新增就自动增加一行,因为这里拿不到event.data.__tableItems,也无法变更其值
13396
13492
  // actions = [actionNewLine, actionShowEditDialog];
13397
13493
  actions = [actionShowEditDialog];
@@ -13426,15 +13522,17 @@ async function getButtonActions(props, mode) {
13426
13522
  // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13427
13523
  // "__parentForm": "${__super.__super || {}}",
13428
13524
  "__parentForm": parentFormData,
13525
+ "_master": "${_master}",
13429
13526
  "global": "${global}",
13430
13527
  "uiSchema": "${uiSchema}",
13431
13528
  "index": "${index}",
13529
+ "parent": "${__super.parent}",//amis组件自带父节点数据域数据,即节点嵌套情况下,当前节点为某个节点(比如A节点)的children属性下的子节点时,当前节点的父节点(即A节点)的数据域数据
13432
13530
  // "__tableItems": `\${${props.name}}`
13433
13531
  // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13434
13532
  // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13435
13533
  // "__tableItems": `\${${props.name}|json|toJson}`
13436
- "__tableItems": `\${(${props.name} || [])|json|toJson}`
13437
- },
13534
+ "__tableItems": `\${((__super.parent ? __super.__super.${props.name} : __super.${props.name}) || [])|json|toJson}`
13535
+ },
13438
13536
  }
13439
13537
  }
13440
13538
  ];
@@ -13450,7 +13548,15 @@ async function getButtonActions(props, mode) {
13450
13548
  // 这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
13451
13549
  // 这里_.clone是因为字段设计布局设置分组这种弹出窗口中的子表组件,直接删除后,点取消无法还原
13452
13550
  let lastestFieldValue = _.clone(wrapperServiceData["${props.name}"]);
13453
- lastestFieldValue.splice(event.data.index, 1);
13551
+ var currentIndex = event.data.index;
13552
+ var parent = event.data.__super.parent;
13553
+ var __parentIndex = parent && _.findIndex(lastestFieldValue, {_id: parent._id});
13554
+ if(parent){
13555
+ lastestFieldValue[__parentIndex].children.splice(currentIndex, 1);
13556
+ }
13557
+ else{
13558
+ lastestFieldValue.splice(currentIndex, 1);
13559
+ }
13454
13560
  doAction({
13455
13561
  "componentId": "${props.id}",
13456
13562
  "actionType": "setValue",