@steedos-widgets/amis-lib 1.3.22-beta.1 → 1.3.22-beta.2

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
@@ -8000,7 +8000,8 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
8000
8000
  {
8001
8001
  "type": "pagination",
8002
8002
  "maxButtons": 5,
8003
- "showPageInput": false
8003
+ "showPageInput": true,
8004
+ "layout": "total,pager,go"
8004
8005
  }
8005
8006
  ]
8006
8007
  }
@@ -11589,7 +11590,16 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
11589
11590
  format:'YYYY-MM-DDT00:00:00.000[Z]',
11590
11591
  tpl: readonly ? getDateTpl(field) : null,
11591
11592
  // utc: true,
11592
- joinValues: false
11593
+ joinValues: false,
11594
+ "shortcuts": [
11595
+ "thismonth",
11596
+ "2monthsago",
11597
+ "3monthslater",
11598
+ "prevquarter",
11599
+ "thisquarter",
11600
+ "thisyear",
11601
+ "lastYear"
11602
+ ]
11593
11603
  };
11594
11604
  break;
11595
11605
  case 'date':
@@ -12000,6 +12010,8 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
12000
12010
  let subFieldName = subField.name.replace(`${field.name}.$.`, '').replace(`${field.name}.`, '');
12001
12011
  if(subField.type === 'grid'){
12002
12012
  subField = await getGridFieldSubFields(subField, ctx.__formFields);
12013
+ }else if(subField.type === 'table'){
12014
+ subField = await getTabledFieldSubFields(subField, ctx.__formFields);
12003
12015
  }else {
12004
12016
  if(readonly){
12005
12017
  subFieldName = `${field.name}.${subFieldName}`;
@@ -12116,7 +12128,8 @@ async function getFieldSearchable(perField, permissionFields, ctx){
12116
12128
  fieldNamePrefix = `${fieldNamePrefix}between__`;
12117
12129
  }
12118
12130
  if(_field.type === 'datetime'){
12119
- _field.type = 'input-datetime-range';
12131
+ // 特意改为日期范围而不是日期时间范围,因为搜索时一般精确到日期就足够了,需要精确到日期时间范围需要在字段上配置amis属性来实现
12132
+ _field.type = 'input-date-range';
12120
12133
  _field.is_wide = true;
12121
12134
  fieldNamePrefix = `${fieldNamePrefix}between__`;
12122
12135
  }
@@ -12428,7 +12441,7 @@ async function getFormBody(permissionFields, formFields, ctx){
12428
12441
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12429
12442
  * @Date: 2023-11-15 09:50:22
12430
12443
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12431
- * @LastEditTime: 2023-12-19 15:53:32
12444
+ * @LastEditTime: 2023-12-23 22:13:22
12432
12445
  */
12433
12446
 
12434
12447
  /**
@@ -12474,6 +12487,28 @@ function getInputTableCell(field, showAsInlineEditMode) {
12474
12487
  }
12475
12488
  }
12476
12489
 
12490
+ function getComponentId(name, tag) {
12491
+ let id = "";
12492
+ switch (name) {
12493
+ case "table_service":
12494
+ id = `service_wrapper__${tag}`;
12495
+ break;
12496
+ case "form_pagination":
12497
+ id = `service_popup_pagination_wrapper__${tag}`;
12498
+ break;
12499
+ case "form":
12500
+ id = `form_popup__${tag}`;
12501
+ break;
12502
+ case "dialog":
12503
+ id = `dialog_popup__${tag}`;
12504
+ break;
12505
+ default:
12506
+ id = `${name}__${tag}`;
12507
+ break;
12508
+ }
12509
+ return id;
12510
+ }
12511
+
12477
12512
  /**
12478
12513
  * @param {*} props
12479
12514
  * @param {*} mode edit/new/readonly
@@ -12521,17 +12556,35 @@ async function getInputTableColumns(props) {
12521
12556
  }
12522
12557
  }
12523
12558
 
12524
- function getFormPagination(props) {
12559
+ /**
12560
+ * @param {*} props input-table组件props
12561
+ * @param {*} mode edit/new/readonly
12562
+ * @returns 翻页组件
12563
+ */
12564
+ function getFormPagination(props, mode) {
12565
+ let showPagination = true;
12566
+ if(mode === "new" && !!!props.editable){
12567
+ //不允许编辑只允许新建时不应该让用户操作翻页
12568
+ showPagination = false;
12569
+ }
12570
+ let buttonPrevId = getComponentId("button_prev", props.id);
12571
+ let buttonNextId = getComponentId("button_next", props.id);
12572
+ let formId = getComponentId("form", props.id);
12573
+ let tableServiceId = getComponentId("table_service", props.id);
12574
+ let formPaginationId = getComponentId("form_pagination", props.id);
12525
12575
  let onPageChangeScript = `
12526
12576
  let scope = event.context.scoped;
12527
- let __paginationServiceId = event.data.__paginationServiceId;
12528
- let __wrapperServiceId = event.data.__wrapperServiceId;
12529
- let __formId = event.data.__formId;
12577
+ let __paginationServiceId = "${formPaginationId}";
12578
+ let __wrapperServiceId = "${tableServiceId}";
12579
+ let __formId = "${formId}";
12530
12580
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
12531
12581
  let pageChangeDirection = context.props.pageChangeDirection;
12582
+ // event.data中的index和__page分别表示当前要把表单数据提交到的行索引和用于标定下一页页码的当前页页码
12583
+ // 一般来说__page = index + 1,但是可以让event.data中传入__page和index值不是这种联系。
12584
+ // 比如__page设置为3,index设置为0表示把当前表单数据提交到第一页,但是跳转到第4页,弹出的表单中底下的新增和复制按钮依赖了此功能
12585
+ // let currentPage = currentIndex + 1;
12532
12586
  let currentPage = event.data.__page;
12533
12587
  let currentIndex = event.data.index;
12534
-
12535
12588
  // 翻页到下一页之前需要先把当前页改动的内容保存到中间变量__tableItems中
12536
12589
  let currentFormValues = scope.getComponentById(__formId).getValues();
12537
12590
  fieldValue[currentIndex] = currentFormValues;
@@ -12576,7 +12629,8 @@ function getFormPagination(props) {
12576
12629
  `;
12577
12630
  return {
12578
12631
  "type": "wrapper",
12579
- "className": "py-2",
12632
+ "size": "none",
12633
+ "className": "mr-1",
12580
12634
  "body": [
12581
12635
  {
12582
12636
  "type": "button",
@@ -12584,8 +12638,9 @@ function getFormPagination(props) {
12584
12638
  "icon": `fa fa-angle-left`,
12585
12639
  "level": "link",
12586
12640
  "pageChangeDirection": "prev",
12587
- "disabledOn": "${__page <= 1}",
12641
+ "disabledOn": showPagination ? "${__page <= 1}" : "true",
12588
12642
  "size": "sm",
12643
+ "id": buttonPrevId,
12589
12644
  "onEvent": {
12590
12645
  "click": {
12591
12646
  "actions": [
@@ -12599,7 +12654,7 @@ function getFormPagination(props) {
12599
12654
  },
12600
12655
  {
12601
12656
  "type": "tpl",
12602
- "tpl": "${__page}/${__total}"
12657
+ "tpl": "${__page}/${__tableItems.length}"
12603
12658
  },
12604
12659
  {
12605
12660
  "type": "button",
@@ -12607,8 +12662,9 @@ function getFormPagination(props) {
12607
12662
  "icon": `fa fa-angle-right`,
12608
12663
  "level": "link",
12609
12664
  "pageChangeDirection": "next",
12610
- "disabledOn": "${__page >= __total}",
12665
+ "disabledOn": showPagination ? "${__page >= __tableItems.length}" : "true",
12611
12666
  "size": "sm",
12667
+ "id": buttonNextId,
12612
12668
  "onEvent": {
12613
12669
  "click": {
12614
12670
  "actions": [
@@ -12628,11 +12684,13 @@ function getFormPagination(props) {
12628
12684
  * 传入formSchema输出带翻页容器的wrapper
12629
12685
  * @param {*} props input-table组件props
12630
12686
  * @param {*} form formSchema
12631
- * @param {*} mode edit/readonly
12687
+ * @param {*} mode edit/new/readonly
12632
12688
  * @returns 带翻页容器的wrapper
12633
12689
  */
12634
12690
  function getFormPaginationWrapper(props, form, mode) {
12635
- let serviceId = `service_popup_pagination_wrapper__${props.id}`;
12691
+ console.log("==getFormPaginationWrapper===", props, mode);
12692
+ let serviceId = getComponentId("form_pagination", props.id);
12693
+ let tableServiceId = getComponentId("table_service", props.id);
12636
12694
  let innerForm = Object.assign({}, form, {
12637
12695
  "data": {
12638
12696
  // 这里加__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
@@ -12644,9 +12702,9 @@ function getFormPaginationWrapper(props, form, mode) {
12644
12702
  {
12645
12703
  "type": "wrapper",
12646
12704
  "size": "none",
12647
- "className": "flex justify-end border-y border-gray-200 -mx-6 shadow-inner sticky top-0 right-0 left-0 z-20 bg-white mb-4",
12705
+ "className": "flex justify-end sticky top-0 right-0 left-0 z-20 bg-white -mt-2",
12648
12706
  "body": [
12649
- getFormPagination(props)
12707
+ getFormPagination(props, mode)
12650
12708
  ]
12651
12709
  },
12652
12710
  {
@@ -12667,7 +12725,7 @@ function getFormPaginationWrapper(props, form, mode) {
12667
12725
  // 处理思路是每次弹出form之前先把其__tableItems同步更新为最新值,这样就能在弹出form中包含单元格中做的修改
12668
12726
  // 注意:service init事件只会在每次弹出窗口时才执行,在触发翻页时并不会触发service init事件
12669
12727
  let scope = event.context.scoped;
12670
- let __wrapperServiceId = event.data.__wrapperServiceId;
12728
+ let __wrapperServiceId = "${tableServiceId}";
12671
12729
  let wrapperService = scope.getComponentById(__wrapperServiceId);
12672
12730
  let wrapperServiceData = wrapperService.getData();
12673
12731
  let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
@@ -12696,9 +12754,9 @@ function getFormPaginationWrapper(props, form, mode) {
12696
12754
  "data": {
12697
12755
  "__page": "${index + 1}",
12698
12756
  // "__total": `\${${props.name}.length}`,
12699
- "__total": "${__tableItems.length}",
12700
- "__paginationServiceId": serviceId,
12701
- "__formId": form.id
12757
+ // "__total": "${__tableItems.length}",
12758
+ // "__paginationServiceId": serviceId,
12759
+ // "__formId": form.id
12702
12760
  },
12703
12761
  "onEvent": {
12704
12762
  "init": {
@@ -12721,8 +12779,8 @@ function getFormPaginationWrapper(props, form, mode) {
12721
12779
  async function getForm(props, mode = "edit", formId) {
12722
12780
  let formFields = getFormFields(props, mode);
12723
12781
  let body = await getFormBody(null, formFields);
12724
- if(!formId){
12725
- formId = `form_popup__${props.id}`;
12782
+ if (!formId) {
12783
+ formId = getComponentId("form", props.id);
12726
12784
  }
12727
12785
  let schema = {
12728
12786
  "type": "form",
@@ -12825,52 +12883,279 @@ async function getForm(props, mode = "edit", formId) {
12825
12883
  }
12826
12884
  });
12827
12885
  }
12828
- if (mode === "edit" || mode === "readonly") {
12829
- schema = getFormPaginationWrapper(props, schema);
12830
- }
12886
+ schema = getFormPaginationWrapper(props, schema, mode);
12831
12887
  return schema;
12832
12888
  }
12833
12889
 
12890
+
12891
+ /**
12892
+ * 编辑、新增和查看按钮actions
12893
+ * @param {*} props
12894
+ * @param {*} mode edit/new/readonly
12895
+ */
12896
+ async function getButtonActions(props, mode) {
12897
+ let actions = [];
12898
+ let formId = getComponentId("form", props.id);
12899
+ let dialogId = getComponentId("dialog", props.id);
12900
+ let buttonNextId = getComponentId("button_next", props.id);
12901
+ let formPaginationId = getComponentId("form_pagination", props.id);
12902
+ if (mode == "new" || mode == "edit") {
12903
+ // let actionShowNewDialog = {
12904
+ // "actionType": "dialog",
12905
+ // "dialog": {
12906
+ // "type": "dialog",
12907
+ // "title": "新增行",
12908
+ // "body": [
12909
+ // await getForm(props, "new", formId)
12910
+ // ],
12911
+ // "size": "lg",
12912
+ // "showCloseButton": true,
12913
+ // "showErrorMsg": true,
12914
+ // "showLoading": true,
12915
+ // "className": "app-popover",
12916
+ // "closeOnEsc": false,
12917
+ // "onEvent": {
12918
+ // "confirm": {
12919
+ // "actions": [
12920
+ // {
12921
+ // "actionType": "validate",
12922
+ // "componentId": formId
12923
+ // },
12924
+ // {
12925
+ // "preventDefault": true,
12926
+ // "expression": "${event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
12927
+ // }
12928
+ // ]
12929
+ // }
12930
+ // }
12931
+ // }
12932
+ // };
12933
+ let onSaveAndNewItemScript = `
12934
+ let scope = event.context.scoped;
12935
+ let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
12936
+ // 新建一条空白行并保存到子表组件
12937
+ fieldValue.push({});
12938
+ doAction({
12939
+ "componentId": "${props.id}",
12940
+ "actionType": "setValue",
12941
+ "args": {
12942
+ "value": fieldValue
12943
+ }
12944
+ });
12945
+ let buttonNextId = "${buttonNextId}";
12946
+ let __paginationServiceId = "${formPaginationId}";
12947
+ let __paginationData = scope.getComponentById(__paginationServiceId).getData();
12948
+ event.data.index = __paginationData.index;
12949
+ event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
12950
+ // 触发翻页按钮事件,实现保存当前页数据并跳转到最后一行
12951
+ scope.getComponentById(buttonNextId).props.dispatchEvent("click", event.data);
12952
+ `;
12953
+ let onSaveAndCopyItemScript = `
12954
+ let scope = event.context.scoped;
12955
+ let __formId = "${formId}";
12956
+ // let newItem = JSON.parse(JSON.stringify(event.data));
12957
+ let newItem = scope.getComponentById(__formId).getValues();//这里不可以用event.data,因为其拿到的是弹出表单时的初始值,不是用户实时填写的数据
12958
+ let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
12959
+ // 复制当前页数据到新建行并保存到子表组件
12960
+ fieldValue.push(newItem);
12961
+ doAction({
12962
+ "componentId": "${props.id}",
12963
+ "actionType": "setValue",
12964
+ "args": {
12965
+ "value": fieldValue
12966
+ }
12967
+ });
12968
+ let buttonNextId = "${buttonNextId}";
12969
+ let __paginationServiceId = "${formPaginationId}";
12970
+ let __paginationData = scope.getComponentById(__paginationServiceId).getData();
12971
+ event.data.index = __paginationData.index;
12972
+ event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
12973
+ // 触发翻页按钮事件,实现保存当前页数据并跳转到最后一行
12974
+ scope.getComponentById(buttonNextId).props.dispatchEvent("click", event.data);
12975
+ `;
12976
+ let dialogButtons = [
12977
+ {
12978
+ "type": "button",
12979
+ "label": "完成",
12980
+ "actionType": "confirm",
12981
+ "level": "primary"
12982
+ }
12983
+ ];
12984
+ if(props.addable){
12985
+ dialogButtons = [
12986
+ {
12987
+ "type": "button",
12988
+ "label": "新增",
12989
+ "tooltip": "保存并新增一行,即保存当前行数据并新增一条空白行",
12990
+ "onEvent": {
12991
+ "click": {
12992
+ "actions": [
12993
+ {
12994
+ "actionType": "custom",
12995
+ "script": onSaveAndNewItemScript
12996
+ }
12997
+ ]
12998
+ }
12999
+ }
13000
+ },
13001
+ {
13002
+ "type": "button",
13003
+ "label": "复制",
13004
+ "tooltip": "复制并新增一行,即保存当前行数据并复制当前行数据到新增行",
13005
+ "onEvent": {
13006
+ "click": {
13007
+ "actions": [
13008
+ {
13009
+ "actionType": "custom",
13010
+ "script": onSaveAndCopyItemScript
13011
+ }
13012
+ ]
13013
+ }
13014
+ }
13015
+ },
13016
+ dialogButtons[0]
13017
+ ];
13018
+ }
13019
+ let actionShowEditDialog = {
13020
+ "actionType": "dialog",
13021
+ "dialog": {
13022
+ "type": "dialog",
13023
+ "id": dialogId,
13024
+ "title": `\${uiSchema.fields.${props.name}.label} 明细`,
13025
+ "body": [
13026
+ await getForm(props, mode, formId)
13027
+ ],
13028
+ "size": "lg",
13029
+ "showCloseButton": true,
13030
+ "showErrorMsg": true,
13031
+ "showLoading": true,
13032
+ "className": "app-popover",
13033
+ "closeOnEsc": false,
13034
+ "data": {
13035
+ // 这里必须加data数据映射,否则翻页功能中取__tableItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
13036
+ // 额外把华炎魔方主表记录ObjectForm中的字段值从record变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
13037
+ // 额外把global、uiSchema也映射过去,有可能要用,后续需要用到其他变更可以这里加映射
13038
+ // "&": "${record || {}}",
13039
+ // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
13040
+ // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13041
+ // "__parentForm": "${__super.__super || {}}",
13042
+ "__parentForm": mode == "new" ? "$$" : "${__super.__super || {}}",
13043
+ "global": "${global}",
13044
+ "uiSchema": "${uiSchema}",
13045
+ "index": "${index}",
13046
+ // "__tableItems": `\${${props.name}}`
13047
+ // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13048
+ // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13049
+ "__tableItems": `\${${props.name}|json|toJson}`
13050
+ },
13051
+ "actions": dialogButtons,
13052
+ "onEvent": {
13053
+ "confirm": {
13054
+ "actions": [
13055
+ {
13056
+ "actionType": "validate",
13057
+ "componentId": formId
13058
+ },
13059
+ {
13060
+ "preventDefault": true,
13061
+ "expression": "${event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13062
+ }
13063
+ ]
13064
+ }
13065
+ }
13066
+ }
13067
+ };
13068
+ if (props.dialog) {
13069
+ Object.assign(actionShowEditDialog.dialog, props.dialog);
13070
+ }
13071
+ if (mode == "new") {
13072
+ let onNewLineScript = `
13073
+ let newItem = {};
13074
+ if(event.data["${props.name}"]){
13075
+ // let fieldValue = event.data.__tableItems;
13076
+ // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
13077
+ let fieldValue = event.data["${props.name}"];
13078
+ fieldValue.push(newItem);
13079
+ doAction({
13080
+ "componentId": "${props.id}",
13081
+ "actionType": "setValue",
13082
+ "args": {
13083
+ "value": fieldValue
13084
+ }
13085
+ });
13086
+ event.data.index = fieldValue.length - 1;
13087
+ }
13088
+ else{
13089
+ // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
13090
+ doAction({
13091
+ "componentId": "${props.id}",
13092
+ "actionType": "setValue",
13093
+ "args": {
13094
+ "value": [newItem]
13095
+ }
13096
+ });
13097
+ event.data.index = 1;
13098
+ }
13099
+ `;
13100
+ let actionNewLine = {
13101
+ "actionType": "custom",
13102
+ "script": onNewLineScript
13103
+ };
13104
+ actions = [actionNewLine, actionShowEditDialog];
13105
+ }
13106
+ else if (mode == "edit") {
13107
+ actions = [actionShowEditDialog];
13108
+ }
13109
+ }
13110
+ else if (mode == "readonly") {
13111
+ actions = [
13112
+ {
13113
+ "actionType": "dialog",
13114
+ "dialog": {
13115
+ "type": "dialog",
13116
+ "title": `\${uiSchema.fields.${props.name}.label} 明细`,
13117
+ "body": [
13118
+ await getForm(props, "readonly")
13119
+ ],
13120
+ "size": "lg",
13121
+ "showCloseButton": true,
13122
+ "showErrorMsg": true,
13123
+ "showLoading": true,
13124
+ "className": "app-popover",
13125
+ "closeOnEsc": false,
13126
+ "actions": [],
13127
+ "data": {
13128
+ // 这里必须加data数据映射,否则翻页功能中取__tableItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
13129
+ // 额外把华炎魔方主表记录ObjectForm中的字段值从record变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
13130
+ // 额外把global、uiSchema也映射过去,有可能要用,后续需要用到其他变更可以这里加映射
13131
+ // "&": "${record || {}}",
13132
+ // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
13133
+ // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13134
+ // "__parentForm": "${__super.__super || {}}",
13135
+ "__parentForm": "${__super.__super || {}}",
13136
+ "global": "${global}",
13137
+ "uiSchema": "${uiSchema}",
13138
+ "index": "${index}",
13139
+ // "__tableItems": `\${${props.name}}`
13140
+ // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13141
+ // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13142
+ "__tableItems": `\${${props.name}|json|toJson}`
13143
+ },
13144
+ }
13145
+ }
13146
+ ];
13147
+ }
13148
+ return actions;
13149
+ }
13150
+
12834
13151
  async function getButtonNew(props) {
12835
- let formId = `form_popup__${props.id}`;
12836
13152
  return {
12837
13153
  "label": "新增",
12838
13154
  "type": "button",
12839
13155
  "icon": "fa fa-plus",
12840
13156
  "onEvent": {
12841
13157
  "click": {
12842
- "actions": [
12843
- {
12844
- "actionType": "dialog",
12845
- "dialog": {
12846
- "type": "dialog",
12847
- "title": "新增行",
12848
- "body": [
12849
- await getForm(props, "new", formId)
12850
- ],
12851
- "size": "lg",
12852
- "showCloseButton": true,
12853
- "showErrorMsg": true,
12854
- "showLoading": true,
12855
- "className": "app-popover",
12856
- "closeOnEsc": false,
12857
- "onEvent": {
12858
- "confirm": {
12859
- "actions": [
12860
- {
12861
- "actionType": "validate",
12862
- "componentId": formId
12863
- },
12864
- {
12865
- "preventDefault": true,
12866
- "expression": "${event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
12867
- }
12868
- ]
12869
- }
12870
- }
12871
- }
12872
- }
12873
- ]
13158
+ "actions": await getButtonActions(props, "new")
12874
13159
  }
12875
13160
  },
12876
13161
  "level": "primary"
@@ -12878,60 +13163,14 @@ async function getButtonNew(props) {
12878
13163
  }
12879
13164
 
12880
13165
  async function getButtonEdit(props, showAsInlineEditMode) {
12881
- let formId = `form_popup__${props.id}`;
12882
13166
  return {
12883
13167
  "type": "button",
12884
13168
  "label": "",
12885
- "icon": `fa fa-${showAsInlineEditMode ? "expand" : "pencil"}`,//inline edit模式时显示为放开按钮,只读时显示为笔按钮
13169
+ "icon": `fa fa-${showAsInlineEditMode ? "expand-alt" : "pencil"}`,//inline edit模式时显示为放开按钮,只读时显示为笔按钮
12886
13170
  "level": "link",
12887
13171
  "onEvent": {
12888
13172
  "click": {
12889
- "actions": [
12890
- {
12891
- "actionType": "dialog",
12892
- "dialog": {
12893
- "type": "dialog",
12894
- "title": "编辑行",
12895
- "body": [
12896
- await getForm(props, "edit", formId)
12897
- ],
12898
- "size": "lg",
12899
- "showCloseButton": true,
12900
- "showErrorMsg": true,
12901
- "showLoading": true,
12902
- "className": "app-popover",
12903
- "closeOnEsc": false,
12904
- "data": {
12905
- // 这里必须加data数据映射,否则翻页功能中取__tableItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
12906
- // 额外把华炎魔方主表记录ObjectForm中的字段值从record变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
12907
- // 额外把global、uiSchema也映射过去,有可能要用,后续需要用到其他变更可以这里加映射
12908
- // "&": "${record || {}}",
12909
- // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
12910
- // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
12911
- "__parentForm": "${__super.__super || {}}",
12912
- "global": "${global}",
12913
- "uiSchema": "${uiSchema}",
12914
- "index": "${index}",
12915
- "__tableItems": `\${${props.name}}`,
12916
- "__wrapperServiceId": "${__wrapperServiceId}"
12917
- },
12918
- "onEvent": {
12919
- "confirm": {
12920
- "actions": [
12921
- {
12922
- "actionType": "validate",
12923
- "componentId": formId
12924
- },
12925
- {
12926
- "preventDefault": true,
12927
- "expression": "${event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
12928
- }
12929
- ]
12930
- }
12931
- }
12932
- }
12933
- }
12934
- ]
13173
+ "actions": await getButtonActions(props, "edit")
12935
13174
  }
12936
13175
  }
12937
13176
  };
@@ -12941,51 +13180,22 @@ async function getButtonView(props) {
12941
13180
  return {
12942
13181
  "type": "button",
12943
13182
  "label": "",
12944
- "icon": "fa fa-expand",//fa-external-link
13183
+ "icon": "fa fa-expand-alt",//fa-external-link
12945
13184
  "level": "link",
12946
13185
  "onEvent": {
12947
13186
  "click": {
12948
- "actions": [
12949
- {
12950
- "actionType": "dialog",
12951
- "dialog": {
12952
- "type": "dialog",
12953
- "title": "查看行",
12954
- "body": [
12955
- await getForm(props, "readonly")
12956
- ],
12957
- "size": "lg",
12958
- "showCloseButton": true,
12959
- "showErrorMsg": true,
12960
- "showLoading": true,
12961
- "className": "app-popover",
12962
- "closeOnEsc": false,
12963
- "actions": [],
12964
- "data": {
12965
- // 这里必须加data数据映射,否则翻页功能中取__tableItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
12966
- // 额外把华炎魔方主表记录ObjectForm中的字段值从formData变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
12967
- // global、uiSchema等常用变量本来就在formData变量已经存在了,无需另外映射
12968
- // "&": "${formData || {}}",
12969
- // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有formData变量
12970
- // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
12971
- "__parentForm": "${__super.__super || {}}",
12972
- "index": "${index}",
12973
- "__tableItems": `\${${props.name}}`,
12974
- "__wrapperServiceId": "${__wrapperServiceId}"
12975
- }
12976
- }
12977
- }
12978
- ]
13187
+ "actions": await getButtonActions(props, "readonly")
12979
13188
  }
12980
13189
  }
12981
13190
  };
12982
13191
  }
12983
13192
 
12984
13193
  function getButtonDelete(props) {
13194
+ let tableServiceId = getComponentId("table_service", props.id);
12985
13195
  let onDeleteItemScript = `
12986
13196
  // let fieldValue = event.data["${props.name}"];
12987
13197
  let scope = event.context.scoped;
12988
- let __wrapperServiceId = event.data.__wrapperServiceId;
13198
+ let __wrapperServiceId = "${tableServiceId}";
12989
13199
  let wrapperService = scope.getComponentById(__wrapperServiceId);
12990
13200
  let wrapperServiceData = wrapperService.getData();
12991
13201
  let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
@@ -13001,7 +13211,7 @@ function getButtonDelete(props) {
13001
13211
  return {
13002
13212
  "type": "button",
13003
13213
  "label": "",
13004
- "icon": "fa fa-minus",
13214
+ "icon": "fa fa-trash-alt",//不可以用fa-trash-o,因为设计字段布局界面中弹出的设置分组列表中显示不了这个图标
13005
13215
  "level": "link",
13006
13216
  "onEvent": {
13007
13217
  "click": {
@@ -13027,7 +13237,7 @@ const getAmisInputTableSchema = async (props) => {
13027
13237
  if (!props.id) {
13028
13238
  props.id = "steedos_input_table_" + props.name + "_" + Math.random().toString(36).substr(2, 9);
13029
13239
  }
13030
- let serviceId = `service_wrapper__${props.id}`;
13240
+ let serviceId = getComponentId("table_service", props.id);
13031
13241
  let buttonsForColumnOperations = [];
13032
13242
  let inlineEditMode = props.inlineEditMode;
13033
13243
  let showAsInlineEditMode = inlineEditMode && props.editable;
@@ -13118,24 +13328,22 @@ const getAmisInputTableSchema = async (props) => {
13118
13328
  "body": footerToolbar
13119
13329
  });
13120
13330
  }
13121
- // 不可以直接把headerToolbar unshift进schemaBody,因为它没有显示在label下面,而是显示在上面了,这没有意义
13331
+ // 直接把headerToolbar unshift进schemaBody,不会显示在label下面,而是显示在上面了,这个暂时没有解决办法,只能等amis 升级
13122
13332
  // 看起来amis官方后续会支持给input-table组件配置headerToolbar,见:https://github.com/baidu/amis/issues/7246
13123
- // let headerToolbar = clone(props.headerToolbar || []); //这里不clone的话,会造成死循环,应该是因为props属性变更会让组件重新渲染
13124
- // if (headerToolbar.length) {
13125
- // schemaBody.unshift({
13126
- // "type": "wrapper",
13127
- // "size": "none",
13128
- // "body": headerToolbar
13129
- // });
13130
- // }
13333
+ // 不过依然放开此功能的意义在于有的场景字段label本来就不需要显示出来,此时headerToolbar就有意义
13334
+ let headerToolbar = _$1.clone(props.headerToolbar || []); //这里不clone的话,会造成死循环,应该是因为props属性变更会让组件重新渲染
13335
+ if (headerToolbar.length) {
13336
+ schemaBody.unshift({
13337
+ "type": "wrapper",
13338
+ "size": "none",
13339
+ "body": headerToolbar
13340
+ });
13341
+ }
13131
13342
  let schema = {
13132
13343
  "type": "service",
13133
13344
  "body": schemaBody,
13134
13345
  "className": props.className,
13135
- "id": serviceId,
13136
- "data": {
13137
- "__wrapperServiceId": serviceId
13138
- }
13346
+ "id": serviceId
13139
13347
  };
13140
13348
  // console.log("===schema===", schema);
13141
13349
  return schema;