@steedos-widgets/amis-lib 1.3.21 → 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/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/index.cjs.js +483 -335
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +483 -335
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +137 -76
- package/dist/index.umd.js.map +1 -1
- package/dist/types/lib/converter/amis/toolbar.d.ts +6 -1
- package/dist/types/lib/input_table.d.ts +0 -14
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -1762,21 +1762,21 @@ async function getQuickEditSchema(field, options){
|
|
|
1762
1762
|
break;
|
|
1763
1763
|
case "avatar":
|
|
1764
1764
|
case "image":
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1765
|
+
quickEditSchema.body[0].receiver.adaptor = `
|
|
1766
|
+
const { context } = api.body;
|
|
1767
|
+
var rootUrl = context.rootUrl + "/api/files/${field.type}s/";
|
|
1768
|
+
payload = {
|
|
1769
|
+
status: response.status == 200 ? 0 : response.status,
|
|
1770
|
+
msg: response.statusText,
|
|
1771
|
+
data: {
|
|
1772
|
+
value: rootUrl + payload._id,//为了实现图片crud的回显,需要将value从id改为url,当保存数据数据时,再在发送适配器内重新将id提取出来
|
|
1773
|
+
name: payload.original.name,
|
|
1774
|
+
url: rootUrl + payload._id,
|
|
1775
|
+
}
|
|
1775
1776
|
}
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
break;
|
|
1777
|
+
return payload;
|
|
1778
|
+
`;
|
|
1779
|
+
break;
|
|
1780
1780
|
}
|
|
1781
1781
|
quickEditSchema.body[0].visibleOn = "${quickedit_record_permissions.allowEdit && quickedit_record_permissions_loading == false}";
|
|
1782
1782
|
quickEditSchema.body.push({
|
|
@@ -1983,6 +1983,11 @@ async function getQuickEditSchema(field, options){
|
|
|
1983
1983
|
if(field.type == "location"){
|
|
1984
1984
|
quickEditSchema = false;
|
|
1985
1985
|
}
|
|
1986
|
+
if(field.type == "color"){
|
|
1987
|
+
quickEditSchema = {
|
|
1988
|
+
type: "input-color"
|
|
1989
|
+
};
|
|
1990
|
+
}
|
|
1986
1991
|
}
|
|
1987
1992
|
return quickEditSchema;
|
|
1988
1993
|
}
|
|
@@ -7968,7 +7973,8 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
|
|
|
7968
7973
|
{
|
|
7969
7974
|
"type": "pagination",
|
|
7970
7975
|
"maxButtons": 5,
|
|
7971
|
-
"showPageInput":
|
|
7976
|
+
"showPageInput": true,
|
|
7977
|
+
"layout": "total,pager,go"
|
|
7972
7978
|
}
|
|
7973
7979
|
]
|
|
7974
7980
|
}
|
|
@@ -11534,6 +11540,13 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
|
|
|
11534
11540
|
};
|
|
11535
11541
|
if(readonly){
|
|
11536
11542
|
convertData.defaultColor = null;
|
|
11543
|
+
}else {
|
|
11544
|
+
convertData.pipeIn = (value, data) => {
|
|
11545
|
+
if(value && value.indexOf('#')<0){
|
|
11546
|
+
return '#'+value;
|
|
11547
|
+
}
|
|
11548
|
+
return value;
|
|
11549
|
+
};
|
|
11537
11550
|
}
|
|
11538
11551
|
break;
|
|
11539
11552
|
case 'boolean':
|
|
@@ -11550,7 +11563,16 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
|
|
|
11550
11563
|
format:'YYYY-MM-DDT00:00:00.000[Z]',
|
|
11551
11564
|
tpl: readonly ? getDateTpl(field) : null,
|
|
11552
11565
|
// utc: true,
|
|
11553
|
-
joinValues: false
|
|
11566
|
+
joinValues: false,
|
|
11567
|
+
"shortcuts": [
|
|
11568
|
+
"thismonth",
|
|
11569
|
+
"2monthsago",
|
|
11570
|
+
"3monthslater",
|
|
11571
|
+
"prevquarter",
|
|
11572
|
+
"thisquarter",
|
|
11573
|
+
"thisyear",
|
|
11574
|
+
"lastYear"
|
|
11575
|
+
]
|
|
11554
11576
|
};
|
|
11555
11577
|
break;
|
|
11556
11578
|
case 'date':
|
|
@@ -11961,6 +11983,8 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
|
|
|
11961
11983
|
let subFieldName = subField.name.replace(`${field.name}.$.`, '').replace(`${field.name}.`, '');
|
|
11962
11984
|
if(subField.type === 'grid'){
|
|
11963
11985
|
subField = await getGridFieldSubFields(subField, ctx.__formFields);
|
|
11986
|
+
}else if(subField.type === 'table'){
|
|
11987
|
+
subField = await getTabledFieldSubFields(subField, ctx.__formFields);
|
|
11964
11988
|
}else {
|
|
11965
11989
|
if(readonly){
|
|
11966
11990
|
subFieldName = `${field.name}.${subFieldName}`;
|
|
@@ -12077,7 +12101,8 @@ async function getFieldSearchable(perField, permissionFields, ctx){
|
|
|
12077
12101
|
fieldNamePrefix = `${fieldNamePrefix}between__`;
|
|
12078
12102
|
}
|
|
12079
12103
|
if(_field.type === 'datetime'){
|
|
12080
|
-
|
|
12104
|
+
// 特意改为日期范围而不是日期时间范围,因为搜索时一般精确到日期就足够了,需要精确到日期时间范围需要在字段上配置amis属性来实现
|
|
12105
|
+
_field.type = 'input-date-range';
|
|
12081
12106
|
_field.is_wide = true;
|
|
12082
12107
|
fieldNamePrefix = `${fieldNamePrefix}between__`;
|
|
12083
12108
|
}
|
|
@@ -12389,7 +12414,7 @@ async function getFormBody(permissionFields, formFields, ctx){
|
|
|
12389
12414
|
* @Author: 殷亮辉 yinlianghui@hotoa.com
|
|
12390
12415
|
* @Date: 2023-11-15 09:50:22
|
|
12391
12416
|
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
|
|
12392
|
-
* @LastEditTime: 2023-12-
|
|
12417
|
+
* @LastEditTime: 2023-12-23 22:13:22
|
|
12393
12418
|
*/
|
|
12394
12419
|
|
|
12395
12420
|
/**
|
|
@@ -12435,6 +12460,28 @@ function getInputTableCell(field, showAsInlineEditMode) {
|
|
|
12435
12460
|
}
|
|
12436
12461
|
}
|
|
12437
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
|
+
|
|
12438
12485
|
/**
|
|
12439
12486
|
* @param {*} props
|
|
12440
12487
|
* @param {*} mode edit/new/readonly
|
|
@@ -12482,39 +12529,46 @@ async function getInputTableColumns(props) {
|
|
|
12482
12529
|
}
|
|
12483
12530
|
}
|
|
12484
12531
|
|
|
12485
|
-
|
|
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);
|
|
12486
12548
|
let onPageChangeScript = `
|
|
12487
12549
|
let scope = event.context.scoped;
|
|
12488
|
-
let __paginationServiceId =
|
|
12489
|
-
let __wrapperServiceId =
|
|
12490
|
-
let __formId =
|
|
12491
|
-
let fieldValue = event.data.
|
|
12550
|
+
let __paginationServiceId = "${formPaginationId}";
|
|
12551
|
+
let __wrapperServiceId = "${tableServiceId}";
|
|
12552
|
+
let __formId = "${formId}";
|
|
12553
|
+
let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
|
|
12492
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;
|
|
12493
12559
|
let currentPage = event.data.__page;
|
|
12494
12560
|
let currentIndex = event.data.index;
|
|
12495
|
-
|
|
12496
|
-
// 翻页到下一页之前需要先把当前页改动的内容保存到中间变量changedItems中
|
|
12561
|
+
// 翻页到下一页之前需要先把当前页改动的内容保存到中间变量__tableItems中
|
|
12497
12562
|
let currentFormValues = scope.getComponentById(__formId).getValues();
|
|
12498
12563
|
fieldValue[currentIndex] = currentFormValues;
|
|
12499
|
-
//
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
// }
|
|
12508
|
-
// });
|
|
12509
|
-
// 如果翻页到下一页前需要同时把改动的内容保存到最终正式的表单字段中,需要额外给正式表单字段执行一次setValue
|
|
12510
|
-
// 但是同时保存到正式表单字段中会造成翻页后点击取消无法取消翻页之前的改动内容
|
|
12511
|
-
// doAction({
|
|
12512
|
-
// "componentId": "${props.id}",
|
|
12513
|
-
// "actionType": "setValue",
|
|
12514
|
-
// "args": {
|
|
12515
|
-
// "value": fieldValue
|
|
12516
|
-
// }
|
|
12517
|
-
// });
|
|
12564
|
+
// 翻页到下一页前需要同时把改动的内容保存到最终正式的表单字段中,所以额外给正式表单字段执行一次setValue
|
|
12565
|
+
doAction({
|
|
12566
|
+
"componentId": "${props.id}",
|
|
12567
|
+
"actionType": "setValue",
|
|
12568
|
+
"args": {
|
|
12569
|
+
"value": fieldValue
|
|
12570
|
+
}
|
|
12571
|
+
});
|
|
12518
12572
|
|
|
12519
12573
|
// 以下是翻页逻辑,翻到下一页并把下一页内容显示到表单上
|
|
12520
12574
|
let targetPage;
|
|
@@ -12525,7 +12579,7 @@ function getFormPagination(props) {
|
|
|
12525
12579
|
targetPage = currentPage - 1;
|
|
12526
12580
|
}
|
|
12527
12581
|
let targetIndex = targetPage - 1;//input-table组件行索引,从0开始的索引
|
|
12528
|
-
// let targetFormData =
|
|
12582
|
+
// let targetFormData = __tableItems[targetIndex];
|
|
12529
12583
|
doAction({
|
|
12530
12584
|
"actionType": "setValue",
|
|
12531
12585
|
"componentId": __paginationServiceId,
|
|
@@ -12548,7 +12602,8 @@ function getFormPagination(props) {
|
|
|
12548
12602
|
`;
|
|
12549
12603
|
return {
|
|
12550
12604
|
"type": "wrapper",
|
|
12551
|
-
"
|
|
12605
|
+
"size": "none",
|
|
12606
|
+
"className": "mr-1",
|
|
12552
12607
|
"body": [
|
|
12553
12608
|
{
|
|
12554
12609
|
"type": "button",
|
|
@@ -12556,8 +12611,9 @@ function getFormPagination(props) {
|
|
|
12556
12611
|
"icon": `fa fa-angle-left`,
|
|
12557
12612
|
"level": "link",
|
|
12558
12613
|
"pageChangeDirection": "prev",
|
|
12559
|
-
"disabledOn": "${__page <= 1}",
|
|
12614
|
+
"disabledOn": showPagination ? "${__page <= 1}" : "true",
|
|
12560
12615
|
"size": "sm",
|
|
12616
|
+
"id": buttonPrevId,
|
|
12561
12617
|
"onEvent": {
|
|
12562
12618
|
"click": {
|
|
12563
12619
|
"actions": [
|
|
@@ -12571,7 +12627,7 @@ function getFormPagination(props) {
|
|
|
12571
12627
|
},
|
|
12572
12628
|
{
|
|
12573
12629
|
"type": "tpl",
|
|
12574
|
-
"tpl": "${__page}/${
|
|
12630
|
+
"tpl": "${__page}/${__tableItems.length}"
|
|
12575
12631
|
},
|
|
12576
12632
|
{
|
|
12577
12633
|
"type": "button",
|
|
@@ -12579,8 +12635,9 @@ function getFormPagination(props) {
|
|
|
12579
12635
|
"icon": `fa fa-angle-right`,
|
|
12580
12636
|
"level": "link",
|
|
12581
12637
|
"pageChangeDirection": "next",
|
|
12582
|
-
"disabledOn": "${__page >=
|
|
12638
|
+
"disabledOn": showPagination ? "${__page >= __tableItems.length}" : "true",
|
|
12583
12639
|
"size": "sm",
|
|
12640
|
+
"id": buttonNextId,
|
|
12584
12641
|
"onEvent": {
|
|
12585
12642
|
"click": {
|
|
12586
12643
|
"actions": [
|
|
@@ -12600,30 +12657,27 @@ function getFormPagination(props) {
|
|
|
12600
12657
|
* 传入formSchema输出带翻页容器的wrapper
|
|
12601
12658
|
* @param {*} props input-table组件props
|
|
12602
12659
|
* @param {*} form formSchema
|
|
12603
|
-
* @param {*} mode edit/readonly
|
|
12660
|
+
* @param {*} mode edit/new/readonly
|
|
12604
12661
|
* @returns 带翻页容器的wrapper
|
|
12605
12662
|
*/
|
|
12606
12663
|
function getFormPaginationWrapper(props, form, mode) {
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
|
|
12610
|
-
// 只读的时候不可以走中间变量__changedItems,比如工作流规则详细页面修改了子表字段”时间触发器“值后,在只读界面点击查看按钮弹出的表单中__changedItems值是修改前的值
|
|
12611
|
-
let formValues = mode === "readonly" ? `\${${props.name}[__super.index]}` : "${__changedItems[__super.index]}";
|
|
12612
|
-
// 这时用__readonlyItemsLength是因为`\${${props.name}.length}`拿不到值
|
|
12613
|
-
let totalValue = mode === "readonly" ? "${__readonlyItemsLength}" : "${__changedItems.length}";
|
|
12664
|
+
console.log("==getFormPaginationWrapper===", props, mode);
|
|
12665
|
+
let serviceId = getComponentId("form_pagination", props.id);
|
|
12666
|
+
let tableServiceId = getComponentId("table_service", props.id);
|
|
12614
12667
|
let innerForm = Object.assign({}, form, {
|
|
12615
12668
|
"data": {
|
|
12616
|
-
//
|
|
12617
|
-
|
|
12669
|
+
// 这里加__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
|
|
12670
|
+
// 比如“对象字段”对象options字段是一个子表字段,但是主表(即“对象字段”对象)中正好有一个名为index的字段
|
|
12671
|
+
"&": "${__tableItems[__super.index]}"
|
|
12618
12672
|
}
|
|
12619
12673
|
});
|
|
12620
12674
|
let formBody = [
|
|
12621
12675
|
{
|
|
12622
12676
|
"type": "wrapper",
|
|
12623
12677
|
"size": "none",
|
|
12624
|
-
"className": "flex justify-end
|
|
12678
|
+
"className": "flex justify-end sticky top-0 right-0 left-0 z-20 bg-white -mt-2",
|
|
12625
12679
|
"body": [
|
|
12626
|
-
getFormPagination(props)
|
|
12680
|
+
getFormPagination(props, mode)
|
|
12627
12681
|
]
|
|
12628
12682
|
},
|
|
12629
12683
|
{
|
|
@@ -12637,49 +12691,45 @@ function getFormPaginationWrapper(props, form, mode) {
|
|
|
12637
12691
|
}
|
|
12638
12692
|
];
|
|
12639
12693
|
let onServiceInitedScript = `
|
|
12640
|
-
//
|
|
12641
|
-
// inlineEditMode模式时,用户在表格单元格中直接修改数据,然后弹出的表单form中并没有包含单元格中修改的内容
|
|
12642
|
-
//
|
|
12694
|
+
// 以下脚本是为了解决有时弹出编辑表单时,表单中的值比最后一次编辑保存的值会延迟一拍。
|
|
12695
|
+
// 比如:inlineEditMode模式时,用户在表格单元格中直接修改数据,然后弹出的表单form中并没有包含单元格中修改的内容
|
|
12696
|
+
// 另外有的地方在非inlineEditMode模式时也会有这种延迟一拍问题,比如对象字段中下拉框类型字段的”选择项“属性
|
|
12697
|
+
// 再比如工作流规则详细页面修改了子表字段”时间触发器“值后,在只读界面点击查看按钮弹出的表单中__tableItems值是修改前的值
|
|
12698
|
+
// 处理思路是每次弹出form之前先把其__tableItems同步更新为最新值,这样就能在弹出form中包含单元格中做的修改
|
|
12643
12699
|
// 注意:service init事件只会在每次弹出窗口时才执行,在触发翻页时并不会触发service init事件
|
|
12644
|
-
let inlineEditMode = ${props.inlineEditMode};
|
|
12645
|
-
if(!inlineEditMode){
|
|
12646
|
-
return;
|
|
12647
|
-
}
|
|
12648
12700
|
let scope = event.context.scoped;
|
|
12649
|
-
let __wrapperServiceId =
|
|
12701
|
+
let __wrapperServiceId = "${tableServiceId}";
|
|
12650
12702
|
let wrapperService = scope.getComponentById(__wrapperServiceId);
|
|
12651
12703
|
let wrapperServiceData = wrapperService.getData();
|
|
12652
12704
|
let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
|
|
12653
|
-
//不可以直接像event.data.
|
|
12654
|
-
event.data.
|
|
12655
|
-
event.data.
|
|
12705
|
+
//不可以直接像event.data.__tableItems = lastestFieldValue; 这样整个赋值,否则作用域会断
|
|
12706
|
+
event.data.__tableItems.forEach(function(n,i){
|
|
12707
|
+
event.data.__tableItems[i] = lastestFieldValue[i];
|
|
12656
12708
|
});
|
|
12657
12709
|
`;
|
|
12658
12710
|
let schema = {
|
|
12659
12711
|
"type": "service",
|
|
12660
12712
|
"id": serviceId,
|
|
12661
12713
|
"schemaApi": {
|
|
12662
|
-
"url": "${context.rootUrl}/graphql?rebuildOn=${index}",
|
|
12663
|
-
|
|
12664
|
-
"
|
|
12665
|
-
"
|
|
12666
|
-
"Authorization": "Bearer ${context.tenantId},${context.authToken}"
|
|
12667
|
-
},
|
|
12668
|
-
"requestAdaptor": "api.data={query: '{spaces__findOne(id: \"none\"){_id,name}}'};return api;",
|
|
12714
|
+
// "url": "${context.rootUrl}/graphql?rebuildOn=${index}",
|
|
12715
|
+
"url": "${context.rootUrl}/api/v1/spaces/none",
|
|
12716
|
+
"trackExpression": "${index}",
|
|
12717
|
+
"method": "get",
|
|
12669
12718
|
"adaptor": `
|
|
12670
12719
|
const formBody = ${JSON.stringify(formBody)};
|
|
12671
12720
|
return {
|
|
12672
12721
|
"body": formBody
|
|
12673
12722
|
}
|
|
12674
|
-
|
|
12723
|
+
`,
|
|
12724
|
+
"cache": 600000
|
|
12675
12725
|
},
|
|
12676
12726
|
// "body": formBody,
|
|
12677
12727
|
"data": {
|
|
12678
12728
|
"__page": "${index + 1}",
|
|
12679
12729
|
// "__total": `\${${props.name}.length}`,
|
|
12680
|
-
"__total":
|
|
12681
|
-
"__paginationServiceId": serviceId,
|
|
12682
|
-
"__formId": form.id
|
|
12730
|
+
// "__total": "${__tableItems.length}",
|
|
12731
|
+
// "__paginationServiceId": serviceId,
|
|
12732
|
+
// "__formId": form.id
|
|
12683
12733
|
},
|
|
12684
12734
|
"onEvent": {
|
|
12685
12735
|
"init": {
|
|
@@ -12699,13 +12749,15 @@ function getFormPaginationWrapper(props, form, mode) {
|
|
|
12699
12749
|
* @param {*} props
|
|
12700
12750
|
* @param {*} mode edit/new/readonly
|
|
12701
12751
|
*/
|
|
12702
|
-
async function getForm(props, mode = "edit") {
|
|
12752
|
+
async function getForm(props, mode = "edit", formId) {
|
|
12703
12753
|
let formFields = getFormFields(props, mode);
|
|
12704
12754
|
let body = await getFormBody(null, formFields);
|
|
12705
|
-
|
|
12755
|
+
if (!formId) {
|
|
12756
|
+
formId = getComponentId("form", props.id);
|
|
12757
|
+
}
|
|
12706
12758
|
let schema = {
|
|
12707
12759
|
"type": "form",
|
|
12708
|
-
"id":
|
|
12760
|
+
"id": formId,
|
|
12709
12761
|
"title": "表单",
|
|
12710
12762
|
"debug": false,
|
|
12711
12763
|
"mode": "normal",
|
|
@@ -12717,8 +12769,7 @@ async function getForm(props, mode = "edit") {
|
|
|
12717
12769
|
if (mode === "edit") {
|
|
12718
12770
|
let onEditItemSubmitScript = `
|
|
12719
12771
|
// let fieldValue = _.cloneDeep(event.data["${props.name}"]);
|
|
12720
|
-
let fieldValue = event.data.
|
|
12721
|
-
|
|
12772
|
+
let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
|
|
12722
12773
|
//这里加__super.__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
|
|
12723
12774
|
// 比如“对象字段”对象options字段是一个子表字段,但是主表(即“对象字段”对象)中正好有一个名为index的字段
|
|
12724
12775
|
fieldValue[event.data.__super.__super.index] = JSON.parse(JSON.stringify(event.data));
|
|
@@ -12729,16 +12780,6 @@ async function getForm(props, mode = "edit") {
|
|
|
12729
12780
|
"value": fieldValue
|
|
12730
12781
|
}
|
|
12731
12782
|
});
|
|
12732
|
-
// // 因为翻页form中用的是event.data.changedItems中的数据,所以不需要像下面这样doAction setValue变更中间变量changedItems值
|
|
12733
|
-
// doAction({
|
|
12734
|
-
// "componentId": event.data.__wrapperServiceId,
|
|
12735
|
-
// "actionType": "setValue",
|
|
12736
|
-
// "args": {
|
|
12737
|
-
// "value": {
|
|
12738
|
-
// "__changedItems": fieldValue
|
|
12739
|
-
// }
|
|
12740
|
-
// }
|
|
12741
|
-
// });
|
|
12742
12783
|
`;
|
|
12743
12784
|
Object.assign(schema, {
|
|
12744
12785
|
"onEvent": {
|
|
@@ -12766,29 +12807,30 @@ async function getForm(props, mode = "edit") {
|
|
|
12766
12807
|
}
|
|
12767
12808
|
else if (mode === "new") {
|
|
12768
12809
|
let onNewItemSubmitScript = `
|
|
12769
|
-
|
|
12770
|
-
if(
|
|
12771
|
-
event.data.
|
|
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
|
+
});
|
|
12772
12833
|
}
|
|
12773
|
-
let fieldValue = event.data.__changedItems;
|
|
12774
|
-
fieldValue.push(JSON.parse(JSON.stringify(event.data)));
|
|
12775
|
-
doAction({
|
|
12776
|
-
"componentId": "${props.id}",
|
|
12777
|
-
"actionType": "setValue",
|
|
12778
|
-
"args": {
|
|
12779
|
-
"value": fieldValue
|
|
12780
|
-
}
|
|
12781
|
-
});
|
|
12782
|
-
// // 因为翻页form中用的是event.data.changedItems中的数据,所以不需要像下面这样doAction setValue变更中间变量changedItems值
|
|
12783
|
-
// doAction({
|
|
12784
|
-
// "componentId": event.data.__wrapperServiceId,
|
|
12785
|
-
// "actionType": "setValue",
|
|
12786
|
-
// "args": {
|
|
12787
|
-
// "value": {
|
|
12788
|
-
// "__changedItems": fieldValue
|
|
12789
|
-
// }
|
|
12790
|
-
// }
|
|
12791
|
-
// });
|
|
12792
12834
|
`;
|
|
12793
12835
|
Object.assign(schema, {
|
|
12794
12836
|
"onEvent": {
|
|
@@ -12814,12 +12856,271 @@ async function getForm(props, mode = "edit") {
|
|
|
12814
12856
|
}
|
|
12815
12857
|
});
|
|
12816
12858
|
}
|
|
12817
|
-
|
|
12818
|
-
schema = getFormPaginationWrapper(props, schema, mode);
|
|
12819
|
-
}
|
|
12859
|
+
schema = getFormPaginationWrapper(props, schema, mode);
|
|
12820
12860
|
return schema;
|
|
12821
12861
|
}
|
|
12822
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
|
+
|
|
12823
13124
|
async function getButtonNew(props) {
|
|
12824
13125
|
return {
|
|
12825
13126
|
"label": "新增",
|
|
@@ -12827,24 +13128,7 @@ async function getButtonNew(props) {
|
|
|
12827
13128
|
"icon": "fa fa-plus",
|
|
12828
13129
|
"onEvent": {
|
|
12829
13130
|
"click": {
|
|
12830
|
-
"actions":
|
|
12831
|
-
{
|
|
12832
|
-
"actionType": "dialog",
|
|
12833
|
-
"dialog": {
|
|
12834
|
-
"type": "dialog",
|
|
12835
|
-
"title": "新增行",
|
|
12836
|
-
"body": [
|
|
12837
|
-
await getForm(props, "new")
|
|
12838
|
-
],
|
|
12839
|
-
"size": "lg",
|
|
12840
|
-
"showCloseButton": true,
|
|
12841
|
-
"showErrorMsg": true,
|
|
12842
|
-
"showLoading": true,
|
|
12843
|
-
"className": "app-popover",
|
|
12844
|
-
"closeOnEsc": false
|
|
12845
|
-
}
|
|
12846
|
-
}
|
|
12847
|
-
]
|
|
13131
|
+
"actions": await getButtonActions(props, "new")
|
|
12848
13132
|
}
|
|
12849
13133
|
},
|
|
12850
13134
|
"level": "primary"
|
|
@@ -12852,76 +13136,14 @@ async function getButtonNew(props) {
|
|
|
12852
13136
|
}
|
|
12853
13137
|
|
|
12854
13138
|
async function getButtonEdit(props, showAsInlineEditMode) {
|
|
12855
|
-
let onCancelScript = `
|
|
12856
|
-
let scope = event.context.scoped;
|
|
12857
|
-
let __wrapperServiceId = event.data.__wrapperServiceId;
|
|
12858
|
-
let wrapperService = scope.getComponentById(__wrapperServiceId);
|
|
12859
|
-
let wrapperServiceData = wrapperService.getData();
|
|
12860
|
-
let originalFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
|
|
12861
|
-
//不可以直接像event.data.__changedItems = originalFieldValue; 这样整个赋值,否则作用域会断,造成无法还原
|
|
12862
|
-
event.data.__changedItems.forEach(function(n,i){
|
|
12863
|
-
event.data.__changedItems[i] = originalFieldValue[i];
|
|
12864
|
-
});
|
|
12865
|
-
// 因为翻页form中用的是event.data.changedItems中的数据,所以像下面这样doAction setValue无法实现还原
|
|
12866
|
-
// doAction({
|
|
12867
|
-
// "componentId": __wrapperServiceId,
|
|
12868
|
-
// "actionType": "setValue",
|
|
12869
|
-
// "args": {
|
|
12870
|
-
// "value": {
|
|
12871
|
-
// "__changedItems": originalFieldValue
|
|
12872
|
-
// }
|
|
12873
|
-
// }
|
|
12874
|
-
// });
|
|
12875
|
-
`;
|
|
12876
13139
|
return {
|
|
12877
13140
|
"type": "button",
|
|
12878
13141
|
"label": "",
|
|
12879
|
-
"icon": `fa fa-${showAsInlineEditMode ? "expand" : "pencil"}`,//inline edit模式时显示为放开按钮,只读时显示为笔按钮
|
|
13142
|
+
"icon": `fa fa-${showAsInlineEditMode ? "expand-alt" : "pencil"}`,//inline edit模式时显示为放开按钮,只读时显示为笔按钮
|
|
12880
13143
|
"level": "link",
|
|
12881
13144
|
"onEvent": {
|
|
12882
13145
|
"click": {
|
|
12883
|
-
"actions":
|
|
12884
|
-
{
|
|
12885
|
-
"actionType": "dialog",
|
|
12886
|
-
"dialog": {
|
|
12887
|
-
"type": "dialog",
|
|
12888
|
-
"title": "编辑行",
|
|
12889
|
-
"body": [
|
|
12890
|
-
await getForm(props, "edit")
|
|
12891
|
-
],
|
|
12892
|
-
"size": "lg",
|
|
12893
|
-
"showCloseButton": true,
|
|
12894
|
-
"showErrorMsg": true,
|
|
12895
|
-
"showLoading": true,
|
|
12896
|
-
"className": "app-popover",
|
|
12897
|
-
"closeOnEsc": false,
|
|
12898
|
-
"data": {
|
|
12899
|
-
// 这里必须加data数据映射,否则翻页功能中取changedItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
|
|
12900
|
-
// 额外把华炎魔方主表记录ObjectForm中的字段值从record变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
|
|
12901
|
-
// 额外把global、uiSchema也映射过去,有可能要用,后续需要用到其他变更可以这里加映射
|
|
12902
|
-
// "&": "${record || {}}",
|
|
12903
|
-
// 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
|
|
12904
|
-
// 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
|
|
12905
|
-
"__parentForm": "${__super.__super || {}}",
|
|
12906
|
-
"global": "${global}",
|
|
12907
|
-
"uiSchema": "${uiSchema}",
|
|
12908
|
-
"index": "${index}",
|
|
12909
|
-
"__changedItems": "${__changedItems}",
|
|
12910
|
-
"__wrapperServiceId": "${__wrapperServiceId}"
|
|
12911
|
-
},
|
|
12912
|
-
"onEvent": {
|
|
12913
|
-
"cancel": {
|
|
12914
|
-
"actions": [
|
|
12915
|
-
{
|
|
12916
|
-
"actionType": "custom",
|
|
12917
|
-
"script": onCancelScript
|
|
12918
|
-
}
|
|
12919
|
-
]
|
|
12920
|
-
}
|
|
12921
|
-
}
|
|
12922
|
-
}
|
|
12923
|
-
}
|
|
12924
|
-
]
|
|
13146
|
+
"actions": await getButtonActions(props, "edit")
|
|
12925
13147
|
}
|
|
12926
13148
|
}
|
|
12927
13149
|
};
|
|
@@ -12931,78 +13153,38 @@ async function getButtonView(props) {
|
|
|
12931
13153
|
return {
|
|
12932
13154
|
"type": "button",
|
|
12933
13155
|
"label": "",
|
|
12934
|
-
"icon": "fa fa-expand",//fa-external-link
|
|
13156
|
+
"icon": "fa fa-expand-alt",//fa-external-link
|
|
12935
13157
|
"level": "link",
|
|
12936
13158
|
"onEvent": {
|
|
12937
13159
|
"click": {
|
|
12938
|
-
"actions":
|
|
12939
|
-
{
|
|
12940
|
-
"actionType": "dialog",
|
|
12941
|
-
"dialog": {
|
|
12942
|
-
"type": "dialog",
|
|
12943
|
-
"title": "查看行",
|
|
12944
|
-
"body": [
|
|
12945
|
-
await getForm(props, "readonly")
|
|
12946
|
-
],
|
|
12947
|
-
"size": "lg",
|
|
12948
|
-
"showCloseButton": true,
|
|
12949
|
-
"showErrorMsg": true,
|
|
12950
|
-
"showLoading": true,
|
|
12951
|
-
"className": "app-popover",
|
|
12952
|
-
"closeOnEsc": false,
|
|
12953
|
-
"actions": [],
|
|
12954
|
-
"data": {
|
|
12955
|
-
// 这里必须加data数据映射,否则翻页功能中取changedItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
|
|
12956
|
-
// 额外把华炎魔方主表记录ObjectForm中的字段值从formData变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
|
|
12957
|
-
// global、uiSchema等常用变量本来就在formData变量已经存在了,无需另外映射
|
|
12958
|
-
// "&": "${formData || {}}",
|
|
12959
|
-
// 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有formData变量
|
|
12960
|
-
// 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
|
|
12961
|
-
"__parentForm": "${__super.__super || {}}",
|
|
12962
|
-
"index": "${index}",
|
|
12963
|
-
"__changedItems": "${__changedItems}",
|
|
12964
|
-
"__wrapperServiceId": "${__wrapperServiceId}",
|
|
12965
|
-
"__readonlyItemsLength": `\${${props.name}.length}`
|
|
12966
|
-
}
|
|
12967
|
-
}
|
|
12968
|
-
}
|
|
12969
|
-
]
|
|
13160
|
+
"actions": await getButtonActions(props, "readonly")
|
|
12970
13161
|
}
|
|
12971
13162
|
}
|
|
12972
13163
|
};
|
|
12973
13164
|
}
|
|
12974
13165
|
|
|
12975
13166
|
function getButtonDelete(props) {
|
|
13167
|
+
let tableServiceId = getComponentId("table_service", props.id);
|
|
12976
13168
|
let onDeleteItemScript = `
|
|
12977
|
-
// let fieldValue =
|
|
12978
|
-
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
let
|
|
12982
|
-
|
|
12983
|
-
|
|
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);
|
|
12984
13176
|
doAction({
|
|
12985
13177
|
"componentId": "${props.id}",
|
|
12986
13178
|
"actionType": "setValue",
|
|
12987
13179
|
"args": {
|
|
12988
|
-
"value":
|
|
13180
|
+
"value": lastestFieldValue
|
|
12989
13181
|
}
|
|
12990
13182
|
});
|
|
12991
|
-
// // 因为翻页form中用的是event.data.changedItems中的数据,所以不需要像下面这样doAction setValue变更中间变量changedItems值
|
|
12992
|
-
// doAction({
|
|
12993
|
-
// "componentId": event.data.__wrapperServiceId,
|
|
12994
|
-
// "actionType": "setValue",
|
|
12995
|
-
// "args": {
|
|
12996
|
-
// "value": {
|
|
12997
|
-
// "__changedItems": fieldValue
|
|
12998
|
-
// }
|
|
12999
|
-
// }
|
|
13000
|
-
// });
|
|
13001
13183
|
`;
|
|
13002
13184
|
return {
|
|
13003
13185
|
"type": "button",
|
|
13004
13186
|
"label": "",
|
|
13005
|
-
"icon": "fa fa-
|
|
13187
|
+
"icon": "fa fa-trash-alt",//不可以用fa-trash-o,因为设计字段布局界面中弹出的设置分组列表中显示不了这个图标
|
|
13006
13188
|
"level": "link",
|
|
13007
13189
|
"onEvent": {
|
|
13008
13190
|
"click": {
|
|
@@ -13028,20 +13210,22 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13028
13210
|
if (!props.id) {
|
|
13029
13211
|
props.id = "steedos_input_table_" + props.name + "_" + Math.random().toString(36).substr(2, 9);
|
|
13030
13212
|
}
|
|
13031
|
-
let serviceId =
|
|
13213
|
+
let serviceId = getComponentId("table_service", props.id);
|
|
13032
13214
|
let buttonsForColumnOperations = [];
|
|
13033
13215
|
let inlineEditMode = props.inlineEditMode;
|
|
13034
13216
|
let showAsInlineEditMode = inlineEditMode && props.editable;
|
|
13035
13217
|
if (props.editable) {
|
|
13036
13218
|
let showEditButton = true;
|
|
13037
13219
|
if (showAsInlineEditMode) {
|
|
13038
|
-
//
|
|
13039
|
-
|
|
13040
|
-
|
|
13041
|
-
|
|
13042
|
-
|
|
13043
|
-
|
|
13044
|
-
|
|
13220
|
+
// 始终显示弹出子表表单按钮,如果需要判断只在有列被隐藏时才需要显示弹出表单按钮放开下面的if逻辑就好
|
|
13221
|
+
showEditButton = true;
|
|
13222
|
+
// // inline edit模式下只在有列被隐藏时才需要显示编辑按钮
|
|
13223
|
+
// if (props.columns && props.columns.length > 0 && props.columns.length < props.fields.length) {
|
|
13224
|
+
// showEditButton = true;
|
|
13225
|
+
// }
|
|
13226
|
+
// else {
|
|
13227
|
+
// showEditButton = false;
|
|
13228
|
+
// }
|
|
13045
13229
|
}
|
|
13046
13230
|
// 编辑时显示编辑按钮
|
|
13047
13231
|
if (showEditButton) {
|
|
@@ -13051,11 +13235,9 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13051
13235
|
}
|
|
13052
13236
|
else {
|
|
13053
13237
|
// 只读时显示查看按钮
|
|
13054
|
-
if (props.columns && props.columns.length > 0 && props.columns.length < props.fields.length)
|
|
13055
|
-
|
|
13056
|
-
|
|
13057
|
-
buttonsForColumnOperations.push(buttonViewSchema);
|
|
13058
|
-
}
|
|
13238
|
+
// 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length < props.fields.length)
|
|
13239
|
+
let buttonViewSchema = await getButtonView(props);
|
|
13240
|
+
buttonsForColumnOperations.push(buttonViewSchema);
|
|
13059
13241
|
}
|
|
13060
13242
|
if (props.removable) {
|
|
13061
13243
|
let buttonDeleteSchema = getButtonDelete(props);
|
|
@@ -13091,85 +13273,51 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13091
13273
|
if (showAsInlineEditMode) {
|
|
13092
13274
|
inputTableSchema.needConfirm = false;
|
|
13093
13275
|
}
|
|
13094
|
-
let
|
|
13095
|
-
|
|
13096
|
-
|
|
13097
|
-
|
|
13098
|
-
|
|
13099
|
-
|
|
13100
|
-
|
|
13101
|
-
|
|
13102
|
-
|
|
13103
|
-
|
|
13104
|
-
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
"args": {
|
|
13108
|
-
"value": {
|
|
13109
|
-
"__changedItems": fieldValue
|
|
13110
|
-
}
|
|
13111
|
-
}
|
|
13276
|
+
let amis = props["input-table"] || props.amis;//额外支持"input-table"代替amis属性,是因为在字段yml文件中用amis作为key不好理解
|
|
13277
|
+
if (amis) {
|
|
13278
|
+
// 支持配置amis属性重写或添加最终生成的input-table中任何属性。
|
|
13279
|
+
delete amis.id;//如果steedos-input-table组件配置了amis.id属性,会造成新建编辑行功能不生效
|
|
13280
|
+
Object.assign(inputTableSchema, amis);
|
|
13281
|
+
}
|
|
13282
|
+
const isAnyFieldHasDependOn = (props.fields || []).find(function (item) {
|
|
13283
|
+
return item.depend_on;
|
|
13284
|
+
});
|
|
13285
|
+
if (isAnyFieldHasDependOn) {
|
|
13286
|
+
// 有任意一个子字段有depend_on属性时,强制设置禁用静态模式
|
|
13287
|
+
Object.assign(inputTableSchema, {
|
|
13288
|
+
strictMode: false
|
|
13112
13289
|
});
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
// "componentId": "${props.id}",
|
|
13116
|
-
// "actionType": "setValue",
|
|
13117
|
-
// "args": {
|
|
13118
|
-
// "value": fieldValue
|
|
13119
|
-
// }
|
|
13120
|
-
// });
|
|
13121
|
-
`;
|
|
13122
|
-
let schema = {
|
|
13123
|
-
"type": "service",
|
|
13124
|
-
"body": [
|
|
13125
|
-
inputTableSchema
|
|
13126
|
-
],
|
|
13127
|
-
"className": props.className,
|
|
13128
|
-
"id": serviceId,
|
|
13129
|
-
"data": {
|
|
13130
|
-
"__wrapperServiceId": serviceId
|
|
13131
|
-
},
|
|
13132
|
-
"dataProvider": {
|
|
13133
|
-
"inited": dataProviderInited
|
|
13134
|
-
},
|
|
13135
|
-
"onEvent": {
|
|
13136
|
-
"init": {
|
|
13137
|
-
"actions": [
|
|
13138
|
-
{
|
|
13139
|
-
"actionType": "custom",
|
|
13140
|
-
"script": onInitScript
|
|
13141
|
-
}
|
|
13142
|
-
]
|
|
13143
|
-
}
|
|
13144
|
-
}
|
|
13145
|
-
};
|
|
13290
|
+
}
|
|
13291
|
+
let schemaBody = [inputTableSchema];
|
|
13146
13292
|
let footerToolbar = clone(props.footerToolbar || []); //这里不clone的话,会造成死循环,应该是因为props属性变更会让组件重新渲染
|
|
13147
13293
|
if (props.addable) {
|
|
13148
13294
|
let buttonNewSchema = await getButtonNew(props);
|
|
13149
13295
|
footerToolbar.unshift(buttonNewSchema);
|
|
13150
13296
|
}
|
|
13151
13297
|
if (footerToolbar.length) {
|
|
13152
|
-
|
|
13298
|
+
schemaBody.push({
|
|
13153
13299
|
"type": "wrapper",
|
|
13154
13300
|
"size": "none",
|
|
13155
13301
|
"body": footerToolbar
|
|
13156
13302
|
});
|
|
13157
13303
|
}
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
if(isAnyFieldHasDependOn){
|
|
13168
|
-
// 有任意一个子字段有depend_on属性时,强制设置禁用静态模式
|
|
13169
|
-
Object.assign(schema.body[0], {
|
|
13170
|
-
strictMode: false
|
|
13304
|
+
// 直接把headerToolbar unshift进schemaBody,不会显示在label下面,而是显示在上面了,这个暂时没有解决办法,只能等amis 升级
|
|
13305
|
+
// 看起来amis官方后续会支持给input-table组件配置headerToolbar,见:https://github.com/baidu/amis/issues/7246
|
|
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
|
|
13171
13313
|
});
|
|
13172
13314
|
}
|
|
13315
|
+
let schema = {
|
|
13316
|
+
"type": "service",
|
|
13317
|
+
"body": schemaBody,
|
|
13318
|
+
"className": props.className,
|
|
13319
|
+
"id": serviceId
|
|
13320
|
+
};
|
|
13173
13321
|
// console.log("===schema===", schema);
|
|
13174
13322
|
return schema;
|
|
13175
13323
|
};
|