@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.esm.js CHANGED
@@ -7973,7 +7973,8 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
7973
7973
  {
7974
7974
  "type": "pagination",
7975
7975
  "maxButtons": 5,
7976
- "showPageInput": false
7976
+ "showPageInput": true,
7977
+ "layout": "total,pager,go"
7977
7978
  }
7978
7979
  ]
7979
7980
  }
@@ -11562,7 +11563,16 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
11562
11563
  format:'YYYY-MM-DDT00:00:00.000[Z]',
11563
11564
  tpl: readonly ? getDateTpl(field) : null,
11564
11565
  // utc: true,
11565
- joinValues: false
11566
+ joinValues: false,
11567
+ "shortcuts": [
11568
+ "thismonth",
11569
+ "2monthsago",
11570
+ "3monthslater",
11571
+ "prevquarter",
11572
+ "thisquarter",
11573
+ "thisyear",
11574
+ "lastYear"
11575
+ ]
11566
11576
  };
11567
11577
  break;
11568
11578
  case 'date':
@@ -11973,6 +11983,8 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
11973
11983
  let subFieldName = subField.name.replace(`${field.name}.$.`, '').replace(`${field.name}.`, '');
11974
11984
  if(subField.type === 'grid'){
11975
11985
  subField = await getGridFieldSubFields(subField, ctx.__formFields);
11986
+ }else if(subField.type === 'table'){
11987
+ subField = await getTabledFieldSubFields(subField, ctx.__formFields);
11976
11988
  }else {
11977
11989
  if(readonly){
11978
11990
  subFieldName = `${field.name}.${subFieldName}`;
@@ -12089,7 +12101,8 @@ async function getFieldSearchable(perField, permissionFields, ctx){
12089
12101
  fieldNamePrefix = `${fieldNamePrefix}between__`;
12090
12102
  }
12091
12103
  if(_field.type === 'datetime'){
12092
- _field.type = 'input-datetime-range';
12104
+ // 特意改为日期范围而不是日期时间范围,因为搜索时一般精确到日期就足够了,需要精确到日期时间范围需要在字段上配置amis属性来实现
12105
+ _field.type = 'input-date-range';
12093
12106
  _field.is_wide = true;
12094
12107
  fieldNamePrefix = `${fieldNamePrefix}between__`;
12095
12108
  }
@@ -12401,7 +12414,7 @@ async function getFormBody(permissionFields, formFields, ctx){
12401
12414
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12402
12415
  * @Date: 2023-11-15 09:50:22
12403
12416
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12404
- * @LastEditTime: 2023-12-19 15:53:32
12417
+ * @LastEditTime: 2023-12-23 22:13:22
12405
12418
  */
12406
12419
 
12407
12420
  /**
@@ -12447,6 +12460,28 @@ function getInputTableCell(field, showAsInlineEditMode) {
12447
12460
  }
12448
12461
  }
12449
12462
 
12463
+ function getComponentId(name, tag) {
12464
+ let id = "";
12465
+ switch (name) {
12466
+ case "table_service":
12467
+ id = `service_wrapper__${tag}`;
12468
+ break;
12469
+ case "form_pagination":
12470
+ id = `service_popup_pagination_wrapper__${tag}`;
12471
+ break;
12472
+ case "form":
12473
+ id = `form_popup__${tag}`;
12474
+ break;
12475
+ case "dialog":
12476
+ id = `dialog_popup__${tag}`;
12477
+ break;
12478
+ default:
12479
+ id = `${name}__${tag}`;
12480
+ break;
12481
+ }
12482
+ return id;
12483
+ }
12484
+
12450
12485
  /**
12451
12486
  * @param {*} props
12452
12487
  * @param {*} mode edit/new/readonly
@@ -12494,17 +12529,35 @@ async function getInputTableColumns(props) {
12494
12529
  }
12495
12530
  }
12496
12531
 
12497
- function getFormPagination(props) {
12532
+ /**
12533
+ * @param {*} props input-table组件props
12534
+ * @param {*} mode edit/new/readonly
12535
+ * @returns 翻页组件
12536
+ */
12537
+ function getFormPagination(props, mode) {
12538
+ let showPagination = true;
12539
+ if(mode === "new" && !!!props.editable){
12540
+ //不允许编辑只允许新建时不应该让用户操作翻页
12541
+ showPagination = false;
12542
+ }
12543
+ let buttonPrevId = getComponentId("button_prev", props.id);
12544
+ let buttonNextId = getComponentId("button_next", props.id);
12545
+ let formId = getComponentId("form", props.id);
12546
+ let tableServiceId = getComponentId("table_service", props.id);
12547
+ let formPaginationId = getComponentId("form_pagination", props.id);
12498
12548
  let onPageChangeScript = `
12499
12549
  let scope = event.context.scoped;
12500
- let __paginationServiceId = event.data.__paginationServiceId;
12501
- let __wrapperServiceId = event.data.__wrapperServiceId;
12502
- let __formId = event.data.__formId;
12550
+ let __paginationServiceId = "${formPaginationId}";
12551
+ let __wrapperServiceId = "${tableServiceId}";
12552
+ let __formId = "${formId}";
12503
12553
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
12504
12554
  let pageChangeDirection = context.props.pageChangeDirection;
12555
+ // event.data中的index和__page分别表示当前要把表单数据提交到的行索引和用于标定下一页页码的当前页页码
12556
+ // 一般来说__page = index + 1,但是可以让event.data中传入__page和index值不是这种联系。
12557
+ // 比如__page设置为3,index设置为0表示把当前表单数据提交到第一页,但是跳转到第4页,弹出的表单中底下的新增和复制按钮依赖了此功能
12558
+ // let currentPage = currentIndex + 1;
12505
12559
  let currentPage = event.data.__page;
12506
12560
  let currentIndex = event.data.index;
12507
-
12508
12561
  // 翻页到下一页之前需要先把当前页改动的内容保存到中间变量__tableItems中
12509
12562
  let currentFormValues = scope.getComponentById(__formId).getValues();
12510
12563
  fieldValue[currentIndex] = currentFormValues;
@@ -12549,7 +12602,8 @@ function getFormPagination(props) {
12549
12602
  `;
12550
12603
  return {
12551
12604
  "type": "wrapper",
12552
- "className": "py-2",
12605
+ "size": "none",
12606
+ "className": "mr-1",
12553
12607
  "body": [
12554
12608
  {
12555
12609
  "type": "button",
@@ -12557,8 +12611,9 @@ function getFormPagination(props) {
12557
12611
  "icon": `fa fa-angle-left`,
12558
12612
  "level": "link",
12559
12613
  "pageChangeDirection": "prev",
12560
- "disabledOn": "${__page <= 1}",
12614
+ "disabledOn": showPagination ? "${__page <= 1}" : "true",
12561
12615
  "size": "sm",
12616
+ "id": buttonPrevId,
12562
12617
  "onEvent": {
12563
12618
  "click": {
12564
12619
  "actions": [
@@ -12572,7 +12627,7 @@ function getFormPagination(props) {
12572
12627
  },
12573
12628
  {
12574
12629
  "type": "tpl",
12575
- "tpl": "${__page}/${__total}"
12630
+ "tpl": "${__page}/${__tableItems.length}"
12576
12631
  },
12577
12632
  {
12578
12633
  "type": "button",
@@ -12580,8 +12635,9 @@ function getFormPagination(props) {
12580
12635
  "icon": `fa fa-angle-right`,
12581
12636
  "level": "link",
12582
12637
  "pageChangeDirection": "next",
12583
- "disabledOn": "${__page >= __total}",
12638
+ "disabledOn": showPagination ? "${__page >= __tableItems.length}" : "true",
12584
12639
  "size": "sm",
12640
+ "id": buttonNextId,
12585
12641
  "onEvent": {
12586
12642
  "click": {
12587
12643
  "actions": [
@@ -12601,11 +12657,13 @@ function getFormPagination(props) {
12601
12657
  * 传入formSchema输出带翻页容器的wrapper
12602
12658
  * @param {*} props input-table组件props
12603
12659
  * @param {*} form formSchema
12604
- * @param {*} mode edit/readonly
12660
+ * @param {*} mode edit/new/readonly
12605
12661
  * @returns 带翻页容器的wrapper
12606
12662
  */
12607
12663
  function getFormPaginationWrapper(props, form, mode) {
12608
- let serviceId = `service_popup_pagination_wrapper__${props.id}`;
12664
+ console.log("==getFormPaginationWrapper===", props, mode);
12665
+ let serviceId = getComponentId("form_pagination", props.id);
12666
+ let tableServiceId = getComponentId("table_service", props.id);
12609
12667
  let innerForm = Object.assign({}, form, {
12610
12668
  "data": {
12611
12669
  // 这里加__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
@@ -12617,9 +12675,9 @@ function getFormPaginationWrapper(props, form, mode) {
12617
12675
  {
12618
12676
  "type": "wrapper",
12619
12677
  "size": "none",
12620
- "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",
12678
+ "className": "flex justify-end sticky top-0 right-0 left-0 z-20 bg-white -mt-2",
12621
12679
  "body": [
12622
- getFormPagination(props)
12680
+ getFormPagination(props, mode)
12623
12681
  ]
12624
12682
  },
12625
12683
  {
@@ -12640,7 +12698,7 @@ function getFormPaginationWrapper(props, form, mode) {
12640
12698
  // 处理思路是每次弹出form之前先把其__tableItems同步更新为最新值,这样就能在弹出form中包含单元格中做的修改
12641
12699
  // 注意:service init事件只会在每次弹出窗口时才执行,在触发翻页时并不会触发service init事件
12642
12700
  let scope = event.context.scoped;
12643
- let __wrapperServiceId = event.data.__wrapperServiceId;
12701
+ let __wrapperServiceId = "${tableServiceId}";
12644
12702
  let wrapperService = scope.getComponentById(__wrapperServiceId);
12645
12703
  let wrapperServiceData = wrapperService.getData();
12646
12704
  let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
@@ -12669,9 +12727,9 @@ function getFormPaginationWrapper(props, form, mode) {
12669
12727
  "data": {
12670
12728
  "__page": "${index + 1}",
12671
12729
  // "__total": `\${${props.name}.length}`,
12672
- "__total": "${__tableItems.length}",
12673
- "__paginationServiceId": serviceId,
12674
- "__formId": form.id
12730
+ // "__total": "${__tableItems.length}",
12731
+ // "__paginationServiceId": serviceId,
12732
+ // "__formId": form.id
12675
12733
  },
12676
12734
  "onEvent": {
12677
12735
  "init": {
@@ -12694,8 +12752,8 @@ function getFormPaginationWrapper(props, form, mode) {
12694
12752
  async function getForm(props, mode = "edit", formId) {
12695
12753
  let formFields = getFormFields(props, mode);
12696
12754
  let body = await getFormBody(null, formFields);
12697
- if(!formId){
12698
- formId = `form_popup__${props.id}`;
12755
+ if (!formId) {
12756
+ formId = getComponentId("form", props.id);
12699
12757
  }
12700
12758
  let schema = {
12701
12759
  "type": "form",
@@ -12798,52 +12856,279 @@ async function getForm(props, mode = "edit", formId) {
12798
12856
  }
12799
12857
  });
12800
12858
  }
12801
- if (mode === "edit" || mode === "readonly") {
12802
- schema = getFormPaginationWrapper(props, schema);
12803
- }
12859
+ schema = getFormPaginationWrapper(props, schema, mode);
12804
12860
  return schema;
12805
12861
  }
12806
12862
 
12863
+
12864
+ /**
12865
+ * 编辑、新增和查看按钮actions
12866
+ * @param {*} props
12867
+ * @param {*} mode edit/new/readonly
12868
+ */
12869
+ async function getButtonActions(props, mode) {
12870
+ let actions = [];
12871
+ let formId = getComponentId("form", props.id);
12872
+ let dialogId = getComponentId("dialog", props.id);
12873
+ let buttonNextId = getComponentId("button_next", props.id);
12874
+ let formPaginationId = getComponentId("form_pagination", props.id);
12875
+ if (mode == "new" || mode == "edit") {
12876
+ // let actionShowNewDialog = {
12877
+ // "actionType": "dialog",
12878
+ // "dialog": {
12879
+ // "type": "dialog",
12880
+ // "title": "新增行",
12881
+ // "body": [
12882
+ // await getForm(props, "new", formId)
12883
+ // ],
12884
+ // "size": "lg",
12885
+ // "showCloseButton": true,
12886
+ // "showErrorMsg": true,
12887
+ // "showLoading": true,
12888
+ // "className": "app-popover",
12889
+ // "closeOnEsc": false,
12890
+ // "onEvent": {
12891
+ // "confirm": {
12892
+ // "actions": [
12893
+ // {
12894
+ // "actionType": "validate",
12895
+ // "componentId": formId
12896
+ // },
12897
+ // {
12898
+ // "preventDefault": true,
12899
+ // "expression": "${event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
12900
+ // }
12901
+ // ]
12902
+ // }
12903
+ // }
12904
+ // }
12905
+ // };
12906
+ let onSaveAndNewItemScript = `
12907
+ let scope = event.context.scoped;
12908
+ let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
12909
+ // 新建一条空白行并保存到子表组件
12910
+ fieldValue.push({});
12911
+ doAction({
12912
+ "componentId": "${props.id}",
12913
+ "actionType": "setValue",
12914
+ "args": {
12915
+ "value": fieldValue
12916
+ }
12917
+ });
12918
+ let buttonNextId = "${buttonNextId}";
12919
+ let __paginationServiceId = "${formPaginationId}";
12920
+ let __paginationData = scope.getComponentById(__paginationServiceId).getData();
12921
+ event.data.index = __paginationData.index;
12922
+ event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
12923
+ // 触发翻页按钮事件,实现保存当前页数据并跳转到最后一行
12924
+ scope.getComponentById(buttonNextId).props.dispatchEvent("click", event.data);
12925
+ `;
12926
+ let onSaveAndCopyItemScript = `
12927
+ let scope = event.context.scoped;
12928
+ let __formId = "${formId}";
12929
+ // let newItem = JSON.parse(JSON.stringify(event.data));
12930
+ let newItem = scope.getComponentById(__formId).getValues();//这里不可以用event.data,因为其拿到的是弹出表单时的初始值,不是用户实时填写的数据
12931
+ let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
12932
+ // 复制当前页数据到新建行并保存到子表组件
12933
+ fieldValue.push(newItem);
12934
+ doAction({
12935
+ "componentId": "${props.id}",
12936
+ "actionType": "setValue",
12937
+ "args": {
12938
+ "value": fieldValue
12939
+ }
12940
+ });
12941
+ let buttonNextId = "${buttonNextId}";
12942
+ let __paginationServiceId = "${formPaginationId}";
12943
+ let __paginationData = scope.getComponentById(__paginationServiceId).getData();
12944
+ event.data.index = __paginationData.index;
12945
+ event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
12946
+ // 触发翻页按钮事件,实现保存当前页数据并跳转到最后一行
12947
+ scope.getComponentById(buttonNextId).props.dispatchEvent("click", event.data);
12948
+ `;
12949
+ let dialogButtons = [
12950
+ {
12951
+ "type": "button",
12952
+ "label": "完成",
12953
+ "actionType": "confirm",
12954
+ "level": "primary"
12955
+ }
12956
+ ];
12957
+ if(props.addable){
12958
+ dialogButtons = [
12959
+ {
12960
+ "type": "button",
12961
+ "label": "新增",
12962
+ "tooltip": "保存并新增一行,即保存当前行数据并新增一条空白行",
12963
+ "onEvent": {
12964
+ "click": {
12965
+ "actions": [
12966
+ {
12967
+ "actionType": "custom",
12968
+ "script": onSaveAndNewItemScript
12969
+ }
12970
+ ]
12971
+ }
12972
+ }
12973
+ },
12974
+ {
12975
+ "type": "button",
12976
+ "label": "复制",
12977
+ "tooltip": "复制并新增一行,即保存当前行数据并复制当前行数据到新增行",
12978
+ "onEvent": {
12979
+ "click": {
12980
+ "actions": [
12981
+ {
12982
+ "actionType": "custom",
12983
+ "script": onSaveAndCopyItemScript
12984
+ }
12985
+ ]
12986
+ }
12987
+ }
12988
+ },
12989
+ dialogButtons[0]
12990
+ ];
12991
+ }
12992
+ let actionShowEditDialog = {
12993
+ "actionType": "dialog",
12994
+ "dialog": {
12995
+ "type": "dialog",
12996
+ "id": dialogId,
12997
+ "title": `\${uiSchema.fields.${props.name}.label} 明细`,
12998
+ "body": [
12999
+ await getForm(props, mode, formId)
13000
+ ],
13001
+ "size": "lg",
13002
+ "showCloseButton": true,
13003
+ "showErrorMsg": true,
13004
+ "showLoading": true,
13005
+ "className": "app-popover",
13006
+ "closeOnEsc": false,
13007
+ "data": {
13008
+ // 这里必须加data数据映射,否则翻页功能中取__tableItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
13009
+ // 额外把华炎魔方主表记录ObjectForm中的字段值从record变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
13010
+ // 额外把global、uiSchema也映射过去,有可能要用,后续需要用到其他变更可以这里加映射
13011
+ // "&": "${record || {}}",
13012
+ // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
13013
+ // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13014
+ // "__parentForm": "${__super.__super || {}}",
13015
+ "__parentForm": mode == "new" ? "$$" : "${__super.__super || {}}",
13016
+ "global": "${global}",
13017
+ "uiSchema": "${uiSchema}",
13018
+ "index": "${index}",
13019
+ // "__tableItems": `\${${props.name}}`
13020
+ // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13021
+ // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13022
+ "__tableItems": `\${${props.name}|json|toJson}`
13023
+ },
13024
+ "actions": dialogButtons,
13025
+ "onEvent": {
13026
+ "confirm": {
13027
+ "actions": [
13028
+ {
13029
+ "actionType": "validate",
13030
+ "componentId": formId
13031
+ },
13032
+ {
13033
+ "preventDefault": true,
13034
+ "expression": "${event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13035
+ }
13036
+ ]
13037
+ }
13038
+ }
13039
+ }
13040
+ };
13041
+ if (props.dialog) {
13042
+ Object.assign(actionShowEditDialog.dialog, props.dialog);
13043
+ }
13044
+ if (mode == "new") {
13045
+ let onNewLineScript = `
13046
+ let newItem = {};
13047
+ if(event.data["${props.name}"]){
13048
+ // let fieldValue = event.data.__tableItems;
13049
+ // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
13050
+ let fieldValue = event.data["${props.name}"];
13051
+ fieldValue.push(newItem);
13052
+ doAction({
13053
+ "componentId": "${props.id}",
13054
+ "actionType": "setValue",
13055
+ "args": {
13056
+ "value": fieldValue
13057
+ }
13058
+ });
13059
+ event.data.index = fieldValue.length - 1;
13060
+ }
13061
+ else{
13062
+ // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
13063
+ doAction({
13064
+ "componentId": "${props.id}",
13065
+ "actionType": "setValue",
13066
+ "args": {
13067
+ "value": [newItem]
13068
+ }
13069
+ });
13070
+ event.data.index = 1;
13071
+ }
13072
+ `;
13073
+ let actionNewLine = {
13074
+ "actionType": "custom",
13075
+ "script": onNewLineScript
13076
+ };
13077
+ actions = [actionNewLine, actionShowEditDialog];
13078
+ }
13079
+ else if (mode == "edit") {
13080
+ actions = [actionShowEditDialog];
13081
+ }
13082
+ }
13083
+ else if (mode == "readonly") {
13084
+ actions = [
13085
+ {
13086
+ "actionType": "dialog",
13087
+ "dialog": {
13088
+ "type": "dialog",
13089
+ "title": `\${uiSchema.fields.${props.name}.label} 明细`,
13090
+ "body": [
13091
+ await getForm(props, "readonly")
13092
+ ],
13093
+ "size": "lg",
13094
+ "showCloseButton": true,
13095
+ "showErrorMsg": true,
13096
+ "showLoading": true,
13097
+ "className": "app-popover",
13098
+ "closeOnEsc": false,
13099
+ "actions": [],
13100
+ "data": {
13101
+ // 这里必须加data数据映射,否则翻页功能中取__tableItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
13102
+ // 额外把华炎魔方主表记录ObjectForm中的字段值从record变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
13103
+ // 额外把global、uiSchema也映射过去,有可能要用,后续需要用到其他变更可以这里加映射
13104
+ // "&": "${record || {}}",
13105
+ // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
13106
+ // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13107
+ // "__parentForm": "${__super.__super || {}}",
13108
+ "__parentForm": "${__super.__super || {}}",
13109
+ "global": "${global}",
13110
+ "uiSchema": "${uiSchema}",
13111
+ "index": "${index}",
13112
+ // "__tableItems": `\${${props.name}}`
13113
+ // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13114
+ // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13115
+ "__tableItems": `\${${props.name}|json|toJson}`
13116
+ },
13117
+ }
13118
+ }
13119
+ ];
13120
+ }
13121
+ return actions;
13122
+ }
13123
+
12807
13124
  async function getButtonNew(props) {
12808
- let formId = `form_popup__${props.id}`;
12809
13125
  return {
12810
13126
  "label": "新增",
12811
13127
  "type": "button",
12812
13128
  "icon": "fa fa-plus",
12813
13129
  "onEvent": {
12814
13130
  "click": {
12815
- "actions": [
12816
- {
12817
- "actionType": "dialog",
12818
- "dialog": {
12819
- "type": "dialog",
12820
- "title": "新增行",
12821
- "body": [
12822
- await getForm(props, "new", formId)
12823
- ],
12824
- "size": "lg",
12825
- "showCloseButton": true,
12826
- "showErrorMsg": true,
12827
- "showLoading": true,
12828
- "className": "app-popover",
12829
- "closeOnEsc": false,
12830
- "onEvent": {
12831
- "confirm": {
12832
- "actions": [
12833
- {
12834
- "actionType": "validate",
12835
- "componentId": formId
12836
- },
12837
- {
12838
- "preventDefault": true,
12839
- "expression": "${event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
12840
- }
12841
- ]
12842
- }
12843
- }
12844
- }
12845
- }
12846
- ]
13131
+ "actions": await getButtonActions(props, "new")
12847
13132
  }
12848
13133
  },
12849
13134
  "level": "primary"
@@ -12851,60 +13136,14 @@ async function getButtonNew(props) {
12851
13136
  }
12852
13137
 
12853
13138
  async function getButtonEdit(props, showAsInlineEditMode) {
12854
- let formId = `form_popup__${props.id}`;
12855
13139
  return {
12856
13140
  "type": "button",
12857
13141
  "label": "",
12858
- "icon": `fa fa-${showAsInlineEditMode ? "expand" : "pencil"}`,//inline edit模式时显示为放开按钮,只读时显示为笔按钮
13142
+ "icon": `fa fa-${showAsInlineEditMode ? "expand-alt" : "pencil"}`,//inline edit模式时显示为放开按钮,只读时显示为笔按钮
12859
13143
  "level": "link",
12860
13144
  "onEvent": {
12861
13145
  "click": {
12862
- "actions": [
12863
- {
12864
- "actionType": "dialog",
12865
- "dialog": {
12866
- "type": "dialog",
12867
- "title": "编辑行",
12868
- "body": [
12869
- await getForm(props, "edit", formId)
12870
- ],
12871
- "size": "lg",
12872
- "showCloseButton": true,
12873
- "showErrorMsg": true,
12874
- "showLoading": true,
12875
- "className": "app-popover",
12876
- "closeOnEsc": false,
12877
- "data": {
12878
- // 这里必须加data数据映射,否则翻页功能中取__tableItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
12879
- // 额外把华炎魔方主表记录ObjectForm中的字段值从record变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
12880
- // 额外把global、uiSchema也映射过去,有可能要用,后续需要用到其他变更可以这里加映射
12881
- // "&": "${record || {}}",
12882
- // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
12883
- // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
12884
- "__parentForm": "${__super.__super || {}}",
12885
- "global": "${global}",
12886
- "uiSchema": "${uiSchema}",
12887
- "index": "${index}",
12888
- "__tableItems": `\${${props.name}}`,
12889
- "__wrapperServiceId": "${__wrapperServiceId}"
12890
- },
12891
- "onEvent": {
12892
- "confirm": {
12893
- "actions": [
12894
- {
12895
- "actionType": "validate",
12896
- "componentId": formId
12897
- },
12898
- {
12899
- "preventDefault": true,
12900
- "expression": "${event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
12901
- }
12902
- ]
12903
- }
12904
- }
12905
- }
12906
- }
12907
- ]
13146
+ "actions": await getButtonActions(props, "edit")
12908
13147
  }
12909
13148
  }
12910
13149
  };
@@ -12914,51 +13153,22 @@ async function getButtonView(props) {
12914
13153
  return {
12915
13154
  "type": "button",
12916
13155
  "label": "",
12917
- "icon": "fa fa-expand",//fa-external-link
13156
+ "icon": "fa fa-expand-alt",//fa-external-link
12918
13157
  "level": "link",
12919
13158
  "onEvent": {
12920
13159
  "click": {
12921
- "actions": [
12922
- {
12923
- "actionType": "dialog",
12924
- "dialog": {
12925
- "type": "dialog",
12926
- "title": "查看行",
12927
- "body": [
12928
- await getForm(props, "readonly")
12929
- ],
12930
- "size": "lg",
12931
- "showCloseButton": true,
12932
- "showErrorMsg": true,
12933
- "showLoading": true,
12934
- "className": "app-popover",
12935
- "closeOnEsc": false,
12936
- "actions": [],
12937
- "data": {
12938
- // 这里必须加data数据映射,否则翻页功能中取__tableItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
12939
- // 额外把华炎魔方主表记录ObjectForm中的字段值从formData变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
12940
- // global、uiSchema等常用变量本来就在formData变量已经存在了,无需另外映射
12941
- // "&": "${formData || {}}",
12942
- // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有formData变量
12943
- // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
12944
- "__parentForm": "${__super.__super || {}}",
12945
- "index": "${index}",
12946
- "__tableItems": `\${${props.name}}`,
12947
- "__wrapperServiceId": "${__wrapperServiceId}"
12948
- }
12949
- }
12950
- }
12951
- ]
13160
+ "actions": await getButtonActions(props, "readonly")
12952
13161
  }
12953
13162
  }
12954
13163
  };
12955
13164
  }
12956
13165
 
12957
13166
  function getButtonDelete(props) {
13167
+ let tableServiceId = getComponentId("table_service", props.id);
12958
13168
  let onDeleteItemScript = `
12959
13169
  // let fieldValue = event.data["${props.name}"];
12960
13170
  let scope = event.context.scoped;
12961
- let __wrapperServiceId = event.data.__wrapperServiceId;
13171
+ let __wrapperServiceId = "${tableServiceId}";
12962
13172
  let wrapperService = scope.getComponentById(__wrapperServiceId);
12963
13173
  let wrapperServiceData = wrapperService.getData();
12964
13174
  let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
@@ -12974,7 +13184,7 @@ function getButtonDelete(props) {
12974
13184
  return {
12975
13185
  "type": "button",
12976
13186
  "label": "",
12977
- "icon": "fa fa-minus",
13187
+ "icon": "fa fa-trash-alt",//不可以用fa-trash-o,因为设计字段布局界面中弹出的设置分组列表中显示不了这个图标
12978
13188
  "level": "link",
12979
13189
  "onEvent": {
12980
13190
  "click": {
@@ -13000,7 +13210,7 @@ const getAmisInputTableSchema = async (props) => {
13000
13210
  if (!props.id) {
13001
13211
  props.id = "steedos_input_table_" + props.name + "_" + Math.random().toString(36).substr(2, 9);
13002
13212
  }
13003
- let serviceId = `service_wrapper__${props.id}`;
13213
+ let serviceId = getComponentId("table_service", props.id);
13004
13214
  let buttonsForColumnOperations = [];
13005
13215
  let inlineEditMode = props.inlineEditMode;
13006
13216
  let showAsInlineEditMode = inlineEditMode && props.editable;
@@ -13091,24 +13301,22 @@ const getAmisInputTableSchema = async (props) => {
13091
13301
  "body": footerToolbar
13092
13302
  });
13093
13303
  }
13094
- // 不可以直接把headerToolbar unshift进schemaBody,因为它没有显示在label下面,而是显示在上面了,这没有意义
13304
+ // 直接把headerToolbar unshift进schemaBody,不会显示在label下面,而是显示在上面了,这个暂时没有解决办法,只能等amis 升级
13095
13305
  // 看起来amis官方后续会支持给input-table组件配置headerToolbar,见:https://github.com/baidu/amis/issues/7246
13096
- // let headerToolbar = clone(props.headerToolbar || []); //这里不clone的话,会造成死循环,应该是因为props属性变更会让组件重新渲染
13097
- // if (headerToolbar.length) {
13098
- // schemaBody.unshift({
13099
- // "type": "wrapper",
13100
- // "size": "none",
13101
- // "body": headerToolbar
13102
- // });
13103
- // }
13306
+ // 不过依然放开此功能的意义在于有的场景字段label本来就不需要显示出来,此时headerToolbar就有意义
13307
+ let headerToolbar = clone(props.headerToolbar || []); //这里不clone的话,会造成死循环,应该是因为props属性变更会让组件重新渲染
13308
+ if (headerToolbar.length) {
13309
+ schemaBody.unshift({
13310
+ "type": "wrapper",
13311
+ "size": "none",
13312
+ "body": headerToolbar
13313
+ });
13314
+ }
13104
13315
  let schema = {
13105
13316
  "type": "service",
13106
13317
  "body": schemaBody,
13107
13318
  "className": props.className,
13108
- "id": serviceId,
13109
- "data": {
13110
- "__wrapperServiceId": serviceId
13111
- }
13319
+ "id": serviceId
13112
13320
  };
13113
13321
  // console.log("===schema===", schema);
13114
13322
  return schema;