@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.cjs.js
CHANGED
|
@@ -1789,21 +1789,21 @@ async function getQuickEditSchema(field, options){
|
|
|
1789
1789
|
break;
|
|
1790
1790
|
case "avatar":
|
|
1791
1791
|
case "image":
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1792
|
+
quickEditSchema.body[0].receiver.adaptor = `
|
|
1793
|
+
const { context } = api.body;
|
|
1794
|
+
var rootUrl = context.rootUrl + "/api/files/${field.type}s/";
|
|
1795
|
+
payload = {
|
|
1796
|
+
status: response.status == 200 ? 0 : response.status,
|
|
1797
|
+
msg: response.statusText,
|
|
1798
|
+
data: {
|
|
1799
|
+
value: rootUrl + payload._id,//为了实现图片crud的回显,需要将value从id改为url,当保存数据数据时,再在发送适配器内重新将id提取出来
|
|
1800
|
+
name: payload.original.name,
|
|
1801
|
+
url: rootUrl + payload._id,
|
|
1802
|
+
}
|
|
1802
1803
|
}
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
break;
|
|
1804
|
+
return payload;
|
|
1805
|
+
`;
|
|
1806
|
+
break;
|
|
1807
1807
|
}
|
|
1808
1808
|
quickEditSchema.body[0].visibleOn = "${quickedit_record_permissions.allowEdit && quickedit_record_permissions_loading == false}";
|
|
1809
1809
|
quickEditSchema.body.push({
|
|
@@ -2010,6 +2010,11 @@ async function getQuickEditSchema(field, options){
|
|
|
2010
2010
|
if(field.type == "location"){
|
|
2011
2011
|
quickEditSchema = false;
|
|
2012
2012
|
}
|
|
2013
|
+
if(field.type == "color"){
|
|
2014
|
+
quickEditSchema = {
|
|
2015
|
+
type: "input-color"
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2013
2018
|
}
|
|
2014
2019
|
return quickEditSchema;
|
|
2015
2020
|
}
|
|
@@ -7995,7 +8000,8 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
|
|
|
7995
8000
|
{
|
|
7996
8001
|
"type": "pagination",
|
|
7997
8002
|
"maxButtons": 5,
|
|
7998
|
-
"showPageInput":
|
|
8003
|
+
"showPageInput": true,
|
|
8004
|
+
"layout": "total,pager,go"
|
|
7999
8005
|
}
|
|
8000
8006
|
]
|
|
8001
8007
|
}
|
|
@@ -11561,6 +11567,13 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
|
|
|
11561
11567
|
};
|
|
11562
11568
|
if(readonly){
|
|
11563
11569
|
convertData.defaultColor = null;
|
|
11570
|
+
}else {
|
|
11571
|
+
convertData.pipeIn = (value, data) => {
|
|
11572
|
+
if(value && value.indexOf('#')<0){
|
|
11573
|
+
return '#'+value;
|
|
11574
|
+
}
|
|
11575
|
+
return value;
|
|
11576
|
+
};
|
|
11564
11577
|
}
|
|
11565
11578
|
break;
|
|
11566
11579
|
case 'boolean':
|
|
@@ -11577,7 +11590,16 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
|
|
|
11577
11590
|
format:'YYYY-MM-DDT00:00:00.000[Z]',
|
|
11578
11591
|
tpl: readonly ? getDateTpl(field) : null,
|
|
11579
11592
|
// utc: true,
|
|
11580
|
-
joinValues: false
|
|
11593
|
+
joinValues: false,
|
|
11594
|
+
"shortcuts": [
|
|
11595
|
+
"thismonth",
|
|
11596
|
+
"2monthsago",
|
|
11597
|
+
"3monthslater",
|
|
11598
|
+
"prevquarter",
|
|
11599
|
+
"thisquarter",
|
|
11600
|
+
"thisyear",
|
|
11601
|
+
"lastYear"
|
|
11602
|
+
]
|
|
11581
11603
|
};
|
|
11582
11604
|
break;
|
|
11583
11605
|
case 'date':
|
|
@@ -11988,6 +12010,8 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
|
|
|
11988
12010
|
let subFieldName = subField.name.replace(`${field.name}.$.`, '').replace(`${field.name}.`, '');
|
|
11989
12011
|
if(subField.type === 'grid'){
|
|
11990
12012
|
subField = await getGridFieldSubFields(subField, ctx.__formFields);
|
|
12013
|
+
}else if(subField.type === 'table'){
|
|
12014
|
+
subField = await getTabledFieldSubFields(subField, ctx.__formFields);
|
|
11991
12015
|
}else {
|
|
11992
12016
|
if(readonly){
|
|
11993
12017
|
subFieldName = `${field.name}.${subFieldName}`;
|
|
@@ -12104,7 +12128,8 @@ async function getFieldSearchable(perField, permissionFields, ctx){
|
|
|
12104
12128
|
fieldNamePrefix = `${fieldNamePrefix}between__`;
|
|
12105
12129
|
}
|
|
12106
12130
|
if(_field.type === 'datetime'){
|
|
12107
|
-
|
|
12131
|
+
// 特意改为日期范围而不是日期时间范围,因为搜索时一般精确到日期就足够了,需要精确到日期时间范围需要在字段上配置amis属性来实现
|
|
12132
|
+
_field.type = 'input-date-range';
|
|
12108
12133
|
_field.is_wide = true;
|
|
12109
12134
|
fieldNamePrefix = `${fieldNamePrefix}between__`;
|
|
12110
12135
|
}
|
|
@@ -12416,7 +12441,7 @@ async function getFormBody(permissionFields, formFields, ctx){
|
|
|
12416
12441
|
* @Author: 殷亮辉 yinlianghui@hotoa.com
|
|
12417
12442
|
* @Date: 2023-11-15 09:50:22
|
|
12418
12443
|
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
|
|
12419
|
-
* @LastEditTime: 2023-12-
|
|
12444
|
+
* @LastEditTime: 2023-12-23 22:13:22
|
|
12420
12445
|
*/
|
|
12421
12446
|
|
|
12422
12447
|
/**
|
|
@@ -12462,6 +12487,28 @@ function getInputTableCell(field, showAsInlineEditMode) {
|
|
|
12462
12487
|
}
|
|
12463
12488
|
}
|
|
12464
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
|
+
|
|
12465
12512
|
/**
|
|
12466
12513
|
* @param {*} props
|
|
12467
12514
|
* @param {*} mode edit/new/readonly
|
|
@@ -12509,39 +12556,46 @@ async function getInputTableColumns(props) {
|
|
|
12509
12556
|
}
|
|
12510
12557
|
}
|
|
12511
12558
|
|
|
12512
|
-
|
|
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);
|
|
12513
12575
|
let onPageChangeScript = `
|
|
12514
12576
|
let scope = event.context.scoped;
|
|
12515
|
-
let __paginationServiceId =
|
|
12516
|
-
let __wrapperServiceId =
|
|
12517
|
-
let __formId =
|
|
12518
|
-
let fieldValue = event.data.
|
|
12577
|
+
let __paginationServiceId = "${formPaginationId}";
|
|
12578
|
+
let __wrapperServiceId = "${tableServiceId}";
|
|
12579
|
+
let __formId = "${formId}";
|
|
12580
|
+
let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
|
|
12519
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;
|
|
12520
12586
|
let currentPage = event.data.__page;
|
|
12521
12587
|
let currentIndex = event.data.index;
|
|
12522
|
-
|
|
12523
|
-
// 翻页到下一页之前需要先把当前页改动的内容保存到中间变量changedItems中
|
|
12588
|
+
// 翻页到下一页之前需要先把当前页改动的内容保存到中间变量__tableItems中
|
|
12524
12589
|
let currentFormValues = scope.getComponentById(__formId).getValues();
|
|
12525
12590
|
fieldValue[currentIndex] = currentFormValues;
|
|
12526
|
-
//
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
// }
|
|
12535
|
-
// });
|
|
12536
|
-
// 如果翻页到下一页前需要同时把改动的内容保存到最终正式的表单字段中,需要额外给正式表单字段执行一次setValue
|
|
12537
|
-
// 但是同时保存到正式表单字段中会造成翻页后点击取消无法取消翻页之前的改动内容
|
|
12538
|
-
// doAction({
|
|
12539
|
-
// "componentId": "${props.id}",
|
|
12540
|
-
// "actionType": "setValue",
|
|
12541
|
-
// "args": {
|
|
12542
|
-
// "value": fieldValue
|
|
12543
|
-
// }
|
|
12544
|
-
// });
|
|
12591
|
+
// 翻页到下一页前需要同时把改动的内容保存到最终正式的表单字段中,所以额外给正式表单字段执行一次setValue
|
|
12592
|
+
doAction({
|
|
12593
|
+
"componentId": "${props.id}",
|
|
12594
|
+
"actionType": "setValue",
|
|
12595
|
+
"args": {
|
|
12596
|
+
"value": fieldValue
|
|
12597
|
+
}
|
|
12598
|
+
});
|
|
12545
12599
|
|
|
12546
12600
|
// 以下是翻页逻辑,翻到下一页并把下一页内容显示到表单上
|
|
12547
12601
|
let targetPage;
|
|
@@ -12552,7 +12606,7 @@ function getFormPagination(props) {
|
|
|
12552
12606
|
targetPage = currentPage - 1;
|
|
12553
12607
|
}
|
|
12554
12608
|
let targetIndex = targetPage - 1;//input-table组件行索引,从0开始的索引
|
|
12555
|
-
// let targetFormData =
|
|
12609
|
+
// let targetFormData = __tableItems[targetIndex];
|
|
12556
12610
|
doAction({
|
|
12557
12611
|
"actionType": "setValue",
|
|
12558
12612
|
"componentId": __paginationServiceId,
|
|
@@ -12575,7 +12629,8 @@ function getFormPagination(props) {
|
|
|
12575
12629
|
`;
|
|
12576
12630
|
return {
|
|
12577
12631
|
"type": "wrapper",
|
|
12578
|
-
"
|
|
12632
|
+
"size": "none",
|
|
12633
|
+
"className": "mr-1",
|
|
12579
12634
|
"body": [
|
|
12580
12635
|
{
|
|
12581
12636
|
"type": "button",
|
|
@@ -12583,8 +12638,9 @@ function getFormPagination(props) {
|
|
|
12583
12638
|
"icon": `fa fa-angle-left`,
|
|
12584
12639
|
"level": "link",
|
|
12585
12640
|
"pageChangeDirection": "prev",
|
|
12586
|
-
"disabledOn": "${__page <= 1}",
|
|
12641
|
+
"disabledOn": showPagination ? "${__page <= 1}" : "true",
|
|
12587
12642
|
"size": "sm",
|
|
12643
|
+
"id": buttonPrevId,
|
|
12588
12644
|
"onEvent": {
|
|
12589
12645
|
"click": {
|
|
12590
12646
|
"actions": [
|
|
@@ -12598,7 +12654,7 @@ function getFormPagination(props) {
|
|
|
12598
12654
|
},
|
|
12599
12655
|
{
|
|
12600
12656
|
"type": "tpl",
|
|
12601
|
-
"tpl": "${__page}/${
|
|
12657
|
+
"tpl": "${__page}/${__tableItems.length}"
|
|
12602
12658
|
},
|
|
12603
12659
|
{
|
|
12604
12660
|
"type": "button",
|
|
@@ -12606,8 +12662,9 @@ function getFormPagination(props) {
|
|
|
12606
12662
|
"icon": `fa fa-angle-right`,
|
|
12607
12663
|
"level": "link",
|
|
12608
12664
|
"pageChangeDirection": "next",
|
|
12609
|
-
"disabledOn": "${__page >=
|
|
12665
|
+
"disabledOn": showPagination ? "${__page >= __tableItems.length}" : "true",
|
|
12610
12666
|
"size": "sm",
|
|
12667
|
+
"id": buttonNextId,
|
|
12611
12668
|
"onEvent": {
|
|
12612
12669
|
"click": {
|
|
12613
12670
|
"actions": [
|
|
@@ -12627,30 +12684,27 @@ function getFormPagination(props) {
|
|
|
12627
12684
|
* 传入formSchema输出带翻页容器的wrapper
|
|
12628
12685
|
* @param {*} props input-table组件props
|
|
12629
12686
|
* @param {*} form formSchema
|
|
12630
|
-
* @param {*} mode edit/readonly
|
|
12687
|
+
* @param {*} mode edit/new/readonly
|
|
12631
12688
|
* @returns 带翻页容器的wrapper
|
|
12632
12689
|
*/
|
|
12633
12690
|
function getFormPaginationWrapper(props, form, mode) {
|
|
12634
|
-
|
|
12635
|
-
|
|
12636
|
-
|
|
12637
|
-
// 只读的时候不可以走中间变量__changedItems,比如工作流规则详细页面修改了子表字段”时间触发器“值后,在只读界面点击查看按钮弹出的表单中__changedItems值是修改前的值
|
|
12638
|
-
let formValues = mode === "readonly" ? `\${${props.name}[__super.index]}` : "${__changedItems[__super.index]}";
|
|
12639
|
-
// 这时用__readonlyItemsLength是因为`\${${props.name}.length}`拿不到值
|
|
12640
|
-
let totalValue = mode === "readonly" ? "${__readonlyItemsLength}" : "${__changedItems.length}";
|
|
12691
|
+
console.log("==getFormPaginationWrapper===", props, mode);
|
|
12692
|
+
let serviceId = getComponentId("form_pagination", props.id);
|
|
12693
|
+
let tableServiceId = getComponentId("table_service", props.id);
|
|
12641
12694
|
let innerForm = Object.assign({}, form, {
|
|
12642
12695
|
"data": {
|
|
12643
|
-
//
|
|
12644
|
-
|
|
12696
|
+
// 这里加__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
|
|
12697
|
+
// 比如“对象字段”对象options字段是一个子表字段,但是主表(即“对象字段”对象)中正好有一个名为index的字段
|
|
12698
|
+
"&": "${__tableItems[__super.index]}"
|
|
12645
12699
|
}
|
|
12646
12700
|
});
|
|
12647
12701
|
let formBody = [
|
|
12648
12702
|
{
|
|
12649
12703
|
"type": "wrapper",
|
|
12650
12704
|
"size": "none",
|
|
12651
|
-
"className": "flex justify-end
|
|
12705
|
+
"className": "flex justify-end sticky top-0 right-0 left-0 z-20 bg-white -mt-2",
|
|
12652
12706
|
"body": [
|
|
12653
|
-
getFormPagination(props)
|
|
12707
|
+
getFormPagination(props, mode)
|
|
12654
12708
|
]
|
|
12655
12709
|
},
|
|
12656
12710
|
{
|
|
@@ -12664,49 +12718,45 @@ function getFormPaginationWrapper(props, form, mode) {
|
|
|
12664
12718
|
}
|
|
12665
12719
|
];
|
|
12666
12720
|
let onServiceInitedScript = `
|
|
12667
|
-
//
|
|
12668
|
-
// inlineEditMode模式时,用户在表格单元格中直接修改数据,然后弹出的表单form中并没有包含单元格中修改的内容
|
|
12669
|
-
//
|
|
12721
|
+
// 以下脚本是为了解决有时弹出编辑表单时,表单中的值比最后一次编辑保存的值会延迟一拍。
|
|
12722
|
+
// 比如:inlineEditMode模式时,用户在表格单元格中直接修改数据,然后弹出的表单form中并没有包含单元格中修改的内容
|
|
12723
|
+
// 另外有的地方在非inlineEditMode模式时也会有这种延迟一拍问题,比如对象字段中下拉框类型字段的”选择项“属性
|
|
12724
|
+
// 再比如工作流规则详细页面修改了子表字段”时间触发器“值后,在只读界面点击查看按钮弹出的表单中__tableItems值是修改前的值
|
|
12725
|
+
// 处理思路是每次弹出form之前先把其__tableItems同步更新为最新值,这样就能在弹出form中包含单元格中做的修改
|
|
12670
12726
|
// 注意:service init事件只会在每次弹出窗口时才执行,在触发翻页时并不会触发service init事件
|
|
12671
|
-
let inlineEditMode = ${props.inlineEditMode};
|
|
12672
|
-
if(!inlineEditMode){
|
|
12673
|
-
return;
|
|
12674
|
-
}
|
|
12675
12727
|
let scope = event.context.scoped;
|
|
12676
|
-
let __wrapperServiceId =
|
|
12728
|
+
let __wrapperServiceId = "${tableServiceId}";
|
|
12677
12729
|
let wrapperService = scope.getComponentById(__wrapperServiceId);
|
|
12678
12730
|
let wrapperServiceData = wrapperService.getData();
|
|
12679
12731
|
let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
|
|
12680
|
-
//不可以直接像event.data.
|
|
12681
|
-
event.data.
|
|
12682
|
-
event.data.
|
|
12732
|
+
//不可以直接像event.data.__tableItems = lastestFieldValue; 这样整个赋值,否则作用域会断
|
|
12733
|
+
event.data.__tableItems.forEach(function(n,i){
|
|
12734
|
+
event.data.__tableItems[i] = lastestFieldValue[i];
|
|
12683
12735
|
});
|
|
12684
12736
|
`;
|
|
12685
12737
|
let schema = {
|
|
12686
12738
|
"type": "service",
|
|
12687
12739
|
"id": serviceId,
|
|
12688
12740
|
"schemaApi": {
|
|
12689
|
-
"url": "${context.rootUrl}/graphql?rebuildOn=${index}",
|
|
12690
|
-
|
|
12691
|
-
"
|
|
12692
|
-
"
|
|
12693
|
-
"Authorization": "Bearer ${context.tenantId},${context.authToken}"
|
|
12694
|
-
},
|
|
12695
|
-
"requestAdaptor": "api.data={query: '{spaces__findOne(id: \"none\"){_id,name}}'};return api;",
|
|
12741
|
+
// "url": "${context.rootUrl}/graphql?rebuildOn=${index}",
|
|
12742
|
+
"url": "${context.rootUrl}/api/v1/spaces/none",
|
|
12743
|
+
"trackExpression": "${index}",
|
|
12744
|
+
"method": "get",
|
|
12696
12745
|
"adaptor": `
|
|
12697
12746
|
const formBody = ${JSON.stringify(formBody)};
|
|
12698
12747
|
return {
|
|
12699
12748
|
"body": formBody
|
|
12700
12749
|
}
|
|
12701
|
-
|
|
12750
|
+
`,
|
|
12751
|
+
"cache": 600000
|
|
12702
12752
|
},
|
|
12703
12753
|
// "body": formBody,
|
|
12704
12754
|
"data": {
|
|
12705
12755
|
"__page": "${index + 1}",
|
|
12706
12756
|
// "__total": `\${${props.name}.length}`,
|
|
12707
|
-
"__total":
|
|
12708
|
-
"__paginationServiceId": serviceId,
|
|
12709
|
-
"__formId": form.id
|
|
12757
|
+
// "__total": "${__tableItems.length}",
|
|
12758
|
+
// "__paginationServiceId": serviceId,
|
|
12759
|
+
// "__formId": form.id
|
|
12710
12760
|
},
|
|
12711
12761
|
"onEvent": {
|
|
12712
12762
|
"init": {
|
|
@@ -12726,13 +12776,15 @@ function getFormPaginationWrapper(props, form, mode) {
|
|
|
12726
12776
|
* @param {*} props
|
|
12727
12777
|
* @param {*} mode edit/new/readonly
|
|
12728
12778
|
*/
|
|
12729
|
-
async function getForm(props, mode = "edit") {
|
|
12779
|
+
async function getForm(props, mode = "edit", formId) {
|
|
12730
12780
|
let formFields = getFormFields(props, mode);
|
|
12731
12781
|
let body = await getFormBody(null, formFields);
|
|
12732
|
-
|
|
12782
|
+
if (!formId) {
|
|
12783
|
+
formId = getComponentId("form", props.id);
|
|
12784
|
+
}
|
|
12733
12785
|
let schema = {
|
|
12734
12786
|
"type": "form",
|
|
12735
|
-
"id":
|
|
12787
|
+
"id": formId,
|
|
12736
12788
|
"title": "表单",
|
|
12737
12789
|
"debug": false,
|
|
12738
12790
|
"mode": "normal",
|
|
@@ -12744,8 +12796,7 @@ async function getForm(props, mode = "edit") {
|
|
|
12744
12796
|
if (mode === "edit") {
|
|
12745
12797
|
let onEditItemSubmitScript = `
|
|
12746
12798
|
// let fieldValue = _.cloneDeep(event.data["${props.name}"]);
|
|
12747
|
-
let fieldValue = event.data.
|
|
12748
|
-
|
|
12799
|
+
let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
|
|
12749
12800
|
//这里加__super.__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
|
|
12750
12801
|
// 比如“对象字段”对象options字段是一个子表字段,但是主表(即“对象字段”对象)中正好有一个名为index的字段
|
|
12751
12802
|
fieldValue[event.data.__super.__super.index] = JSON.parse(JSON.stringify(event.data));
|
|
@@ -12756,16 +12807,6 @@ async function getForm(props, mode = "edit") {
|
|
|
12756
12807
|
"value": fieldValue
|
|
12757
12808
|
}
|
|
12758
12809
|
});
|
|
12759
|
-
// // 因为翻页form中用的是event.data.changedItems中的数据,所以不需要像下面这样doAction setValue变更中间变量changedItems值
|
|
12760
|
-
// doAction({
|
|
12761
|
-
// "componentId": event.data.__wrapperServiceId,
|
|
12762
|
-
// "actionType": "setValue",
|
|
12763
|
-
// "args": {
|
|
12764
|
-
// "value": {
|
|
12765
|
-
// "__changedItems": fieldValue
|
|
12766
|
-
// }
|
|
12767
|
-
// }
|
|
12768
|
-
// });
|
|
12769
12810
|
`;
|
|
12770
12811
|
Object.assign(schema, {
|
|
12771
12812
|
"onEvent": {
|
|
@@ -12793,29 +12834,30 @@ async function getForm(props, mode = "edit") {
|
|
|
12793
12834
|
}
|
|
12794
12835
|
else if (mode === "new") {
|
|
12795
12836
|
let onNewItemSubmitScript = `
|
|
12796
|
-
|
|
12797
|
-
if(
|
|
12798
|
-
event.data.
|
|
12837
|
+
let newItem = JSON.parse(JSON.stringify(event.data));
|
|
12838
|
+
if(event.data["${props.name}"]){
|
|
12839
|
+
// let fieldValue = event.data.__tableItems;
|
|
12840
|
+
// 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
|
|
12841
|
+
let fieldValue = event.data["${props.name}"];
|
|
12842
|
+
fieldValue.push(newItem);
|
|
12843
|
+
doAction({
|
|
12844
|
+
"componentId": "${props.id}",
|
|
12845
|
+
"actionType": "setValue",
|
|
12846
|
+
"args": {
|
|
12847
|
+
"value": fieldValue
|
|
12848
|
+
}
|
|
12849
|
+
});
|
|
12850
|
+
}
|
|
12851
|
+
else{
|
|
12852
|
+
// 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
|
|
12853
|
+
doAction({
|
|
12854
|
+
"componentId": "${props.id}",
|
|
12855
|
+
"actionType": "setValue",
|
|
12856
|
+
"args": {
|
|
12857
|
+
"value": [newItem]
|
|
12858
|
+
}
|
|
12859
|
+
});
|
|
12799
12860
|
}
|
|
12800
|
-
let fieldValue = event.data.__changedItems;
|
|
12801
|
-
fieldValue.push(JSON.parse(JSON.stringify(event.data)));
|
|
12802
|
-
doAction({
|
|
12803
|
-
"componentId": "${props.id}",
|
|
12804
|
-
"actionType": "setValue",
|
|
12805
|
-
"args": {
|
|
12806
|
-
"value": fieldValue
|
|
12807
|
-
}
|
|
12808
|
-
});
|
|
12809
|
-
// // 因为翻页form中用的是event.data.changedItems中的数据,所以不需要像下面这样doAction setValue变更中间变量changedItems值
|
|
12810
|
-
// doAction({
|
|
12811
|
-
// "componentId": event.data.__wrapperServiceId,
|
|
12812
|
-
// "actionType": "setValue",
|
|
12813
|
-
// "args": {
|
|
12814
|
-
// "value": {
|
|
12815
|
-
// "__changedItems": fieldValue
|
|
12816
|
-
// }
|
|
12817
|
-
// }
|
|
12818
|
-
// });
|
|
12819
12861
|
`;
|
|
12820
12862
|
Object.assign(schema, {
|
|
12821
12863
|
"onEvent": {
|
|
@@ -12841,12 +12883,271 @@ async function getForm(props, mode = "edit") {
|
|
|
12841
12883
|
}
|
|
12842
12884
|
});
|
|
12843
12885
|
}
|
|
12844
|
-
|
|
12845
|
-
schema = getFormPaginationWrapper(props, schema, mode);
|
|
12846
|
-
}
|
|
12886
|
+
schema = getFormPaginationWrapper(props, schema, mode);
|
|
12847
12887
|
return schema;
|
|
12848
12888
|
}
|
|
12849
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
|
+
|
|
12850
13151
|
async function getButtonNew(props) {
|
|
12851
13152
|
return {
|
|
12852
13153
|
"label": "新增",
|
|
@@ -12854,24 +13155,7 @@ async function getButtonNew(props) {
|
|
|
12854
13155
|
"icon": "fa fa-plus",
|
|
12855
13156
|
"onEvent": {
|
|
12856
13157
|
"click": {
|
|
12857
|
-
"actions":
|
|
12858
|
-
{
|
|
12859
|
-
"actionType": "dialog",
|
|
12860
|
-
"dialog": {
|
|
12861
|
-
"type": "dialog",
|
|
12862
|
-
"title": "新增行",
|
|
12863
|
-
"body": [
|
|
12864
|
-
await getForm(props, "new")
|
|
12865
|
-
],
|
|
12866
|
-
"size": "lg",
|
|
12867
|
-
"showCloseButton": true,
|
|
12868
|
-
"showErrorMsg": true,
|
|
12869
|
-
"showLoading": true,
|
|
12870
|
-
"className": "app-popover",
|
|
12871
|
-
"closeOnEsc": false
|
|
12872
|
-
}
|
|
12873
|
-
}
|
|
12874
|
-
]
|
|
13158
|
+
"actions": await getButtonActions(props, "new")
|
|
12875
13159
|
}
|
|
12876
13160
|
},
|
|
12877
13161
|
"level": "primary"
|
|
@@ -12879,76 +13163,14 @@ async function getButtonNew(props) {
|
|
|
12879
13163
|
}
|
|
12880
13164
|
|
|
12881
13165
|
async function getButtonEdit(props, showAsInlineEditMode) {
|
|
12882
|
-
let onCancelScript = `
|
|
12883
|
-
let scope = event.context.scoped;
|
|
12884
|
-
let __wrapperServiceId = event.data.__wrapperServiceId;
|
|
12885
|
-
let wrapperService = scope.getComponentById(__wrapperServiceId);
|
|
12886
|
-
let wrapperServiceData = wrapperService.getData();
|
|
12887
|
-
let originalFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
|
|
12888
|
-
//不可以直接像event.data.__changedItems = originalFieldValue; 这样整个赋值,否则作用域会断,造成无法还原
|
|
12889
|
-
event.data.__changedItems.forEach(function(n,i){
|
|
12890
|
-
event.data.__changedItems[i] = originalFieldValue[i];
|
|
12891
|
-
});
|
|
12892
|
-
// 因为翻页form中用的是event.data.changedItems中的数据,所以像下面这样doAction setValue无法实现还原
|
|
12893
|
-
// doAction({
|
|
12894
|
-
// "componentId": __wrapperServiceId,
|
|
12895
|
-
// "actionType": "setValue",
|
|
12896
|
-
// "args": {
|
|
12897
|
-
// "value": {
|
|
12898
|
-
// "__changedItems": originalFieldValue
|
|
12899
|
-
// }
|
|
12900
|
-
// }
|
|
12901
|
-
// });
|
|
12902
|
-
`;
|
|
12903
13166
|
return {
|
|
12904
13167
|
"type": "button",
|
|
12905
13168
|
"label": "",
|
|
12906
|
-
"icon": `fa fa-${showAsInlineEditMode ? "expand" : "pencil"}`,//inline edit模式时显示为放开按钮,只读时显示为笔按钮
|
|
13169
|
+
"icon": `fa fa-${showAsInlineEditMode ? "expand-alt" : "pencil"}`,//inline edit模式时显示为放开按钮,只读时显示为笔按钮
|
|
12907
13170
|
"level": "link",
|
|
12908
13171
|
"onEvent": {
|
|
12909
13172
|
"click": {
|
|
12910
|
-
"actions":
|
|
12911
|
-
{
|
|
12912
|
-
"actionType": "dialog",
|
|
12913
|
-
"dialog": {
|
|
12914
|
-
"type": "dialog",
|
|
12915
|
-
"title": "编辑行",
|
|
12916
|
-
"body": [
|
|
12917
|
-
await getForm(props, "edit")
|
|
12918
|
-
],
|
|
12919
|
-
"size": "lg",
|
|
12920
|
-
"showCloseButton": true,
|
|
12921
|
-
"showErrorMsg": true,
|
|
12922
|
-
"showLoading": true,
|
|
12923
|
-
"className": "app-popover",
|
|
12924
|
-
"closeOnEsc": false,
|
|
12925
|
-
"data": {
|
|
12926
|
-
// 这里必须加data数据映射,否则翻页功能中取changedItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
|
|
12927
|
-
// 额外把华炎魔方主表记录ObjectForm中的字段值从record变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
|
|
12928
|
-
// 额外把global、uiSchema也映射过去,有可能要用,后续需要用到其他变更可以这里加映射
|
|
12929
|
-
// "&": "${record || {}}",
|
|
12930
|
-
// 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
|
|
12931
|
-
// 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
|
|
12932
|
-
"__parentForm": "${__super.__super || {}}",
|
|
12933
|
-
"global": "${global}",
|
|
12934
|
-
"uiSchema": "${uiSchema}",
|
|
12935
|
-
"index": "${index}",
|
|
12936
|
-
"__changedItems": "${__changedItems}",
|
|
12937
|
-
"__wrapperServiceId": "${__wrapperServiceId}"
|
|
12938
|
-
},
|
|
12939
|
-
"onEvent": {
|
|
12940
|
-
"cancel": {
|
|
12941
|
-
"actions": [
|
|
12942
|
-
{
|
|
12943
|
-
"actionType": "custom",
|
|
12944
|
-
"script": onCancelScript
|
|
12945
|
-
}
|
|
12946
|
-
]
|
|
12947
|
-
}
|
|
12948
|
-
}
|
|
12949
|
-
}
|
|
12950
|
-
}
|
|
12951
|
-
]
|
|
13173
|
+
"actions": await getButtonActions(props, "edit")
|
|
12952
13174
|
}
|
|
12953
13175
|
}
|
|
12954
13176
|
};
|
|
@@ -12958,78 +13180,38 @@ async function getButtonView(props) {
|
|
|
12958
13180
|
return {
|
|
12959
13181
|
"type": "button",
|
|
12960
13182
|
"label": "",
|
|
12961
|
-
"icon": "fa fa-expand",//fa-external-link
|
|
13183
|
+
"icon": "fa fa-expand-alt",//fa-external-link
|
|
12962
13184
|
"level": "link",
|
|
12963
13185
|
"onEvent": {
|
|
12964
13186
|
"click": {
|
|
12965
|
-
"actions":
|
|
12966
|
-
{
|
|
12967
|
-
"actionType": "dialog",
|
|
12968
|
-
"dialog": {
|
|
12969
|
-
"type": "dialog",
|
|
12970
|
-
"title": "查看行",
|
|
12971
|
-
"body": [
|
|
12972
|
-
await getForm(props, "readonly")
|
|
12973
|
-
],
|
|
12974
|
-
"size": "lg",
|
|
12975
|
-
"showCloseButton": true,
|
|
12976
|
-
"showErrorMsg": true,
|
|
12977
|
-
"showLoading": true,
|
|
12978
|
-
"className": "app-popover",
|
|
12979
|
-
"closeOnEsc": false,
|
|
12980
|
-
"actions": [],
|
|
12981
|
-
"data": {
|
|
12982
|
-
// 这里必须加data数据映射,否则翻页功能中取changedItems值时会乱,比如翻页编辑后会把上一页中没改过的字段值带过去
|
|
12983
|
-
// 额外把华炎魔方主表记录ObjectForm中的字段值从formData变量中映射到子表form中,因为子表lookup字段filtersFunction中可能依赖了主表记录中的字段值,比如“工作流规则”对象“时间触发器”字段中的“日期字段”字段
|
|
12984
|
-
// global、uiSchema等常用变量本来就在formData变量已经存在了,无需另外映射
|
|
12985
|
-
// "&": "${formData || {}}",
|
|
12986
|
-
// 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有formData变量
|
|
12987
|
-
// 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
|
|
12988
|
-
"__parentForm": "${__super.__super || {}}",
|
|
12989
|
-
"index": "${index}",
|
|
12990
|
-
"__changedItems": "${__changedItems}",
|
|
12991
|
-
"__wrapperServiceId": "${__wrapperServiceId}",
|
|
12992
|
-
"__readonlyItemsLength": `\${${props.name}.length}`
|
|
12993
|
-
}
|
|
12994
|
-
}
|
|
12995
|
-
}
|
|
12996
|
-
]
|
|
13187
|
+
"actions": await getButtonActions(props, "readonly")
|
|
12997
13188
|
}
|
|
12998
13189
|
}
|
|
12999
13190
|
};
|
|
13000
13191
|
}
|
|
13001
13192
|
|
|
13002
13193
|
function getButtonDelete(props) {
|
|
13194
|
+
let tableServiceId = getComponentId("table_service", props.id);
|
|
13003
13195
|
let onDeleteItemScript = `
|
|
13004
|
-
// let fieldValue =
|
|
13005
|
-
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
let
|
|
13009
|
-
|
|
13010
|
-
|
|
13196
|
+
// let fieldValue = event.data["${props.name}"];
|
|
13197
|
+
let scope = event.context.scoped;
|
|
13198
|
+
let __wrapperServiceId = "${tableServiceId}";
|
|
13199
|
+
let wrapperService = scope.getComponentById(__wrapperServiceId);
|
|
13200
|
+
let wrapperServiceData = wrapperService.getData();
|
|
13201
|
+
let lastestFieldValue = wrapperServiceData["${props.name}"];//这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
|
|
13202
|
+
lastestFieldValue.splice(event.data.index, 1);
|
|
13011
13203
|
doAction({
|
|
13012
13204
|
"componentId": "${props.id}",
|
|
13013
13205
|
"actionType": "setValue",
|
|
13014
13206
|
"args": {
|
|
13015
|
-
"value":
|
|
13207
|
+
"value": lastestFieldValue
|
|
13016
13208
|
}
|
|
13017
13209
|
});
|
|
13018
|
-
// // 因为翻页form中用的是event.data.changedItems中的数据,所以不需要像下面这样doAction setValue变更中间变量changedItems值
|
|
13019
|
-
// doAction({
|
|
13020
|
-
// "componentId": event.data.__wrapperServiceId,
|
|
13021
|
-
// "actionType": "setValue",
|
|
13022
|
-
// "args": {
|
|
13023
|
-
// "value": {
|
|
13024
|
-
// "__changedItems": fieldValue
|
|
13025
|
-
// }
|
|
13026
|
-
// }
|
|
13027
|
-
// });
|
|
13028
13210
|
`;
|
|
13029
13211
|
return {
|
|
13030
13212
|
"type": "button",
|
|
13031
13213
|
"label": "",
|
|
13032
|
-
"icon": "fa fa-
|
|
13214
|
+
"icon": "fa fa-trash-alt",//不可以用fa-trash-o,因为设计字段布局界面中弹出的设置分组列表中显示不了这个图标
|
|
13033
13215
|
"level": "link",
|
|
13034
13216
|
"onEvent": {
|
|
13035
13217
|
"click": {
|
|
@@ -13055,20 +13237,22 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13055
13237
|
if (!props.id) {
|
|
13056
13238
|
props.id = "steedos_input_table_" + props.name + "_" + Math.random().toString(36).substr(2, 9);
|
|
13057
13239
|
}
|
|
13058
|
-
let serviceId =
|
|
13240
|
+
let serviceId = getComponentId("table_service", props.id);
|
|
13059
13241
|
let buttonsForColumnOperations = [];
|
|
13060
13242
|
let inlineEditMode = props.inlineEditMode;
|
|
13061
13243
|
let showAsInlineEditMode = inlineEditMode && props.editable;
|
|
13062
13244
|
if (props.editable) {
|
|
13063
13245
|
let showEditButton = true;
|
|
13064
13246
|
if (showAsInlineEditMode) {
|
|
13065
|
-
//
|
|
13066
|
-
|
|
13067
|
-
|
|
13068
|
-
|
|
13069
|
-
|
|
13070
|
-
|
|
13071
|
-
|
|
13247
|
+
// 始终显示弹出子表表单按钮,如果需要判断只在有列被隐藏时才需要显示弹出表单按钮放开下面的if逻辑就好
|
|
13248
|
+
showEditButton = true;
|
|
13249
|
+
// // inline edit模式下只在有列被隐藏时才需要显示编辑按钮
|
|
13250
|
+
// if (props.columns && props.columns.length > 0 && props.columns.length < props.fields.length) {
|
|
13251
|
+
// showEditButton = true;
|
|
13252
|
+
// }
|
|
13253
|
+
// else {
|
|
13254
|
+
// showEditButton = false;
|
|
13255
|
+
// }
|
|
13072
13256
|
}
|
|
13073
13257
|
// 编辑时显示编辑按钮
|
|
13074
13258
|
if (showEditButton) {
|
|
@@ -13078,11 +13262,9 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13078
13262
|
}
|
|
13079
13263
|
else {
|
|
13080
13264
|
// 只读时显示查看按钮
|
|
13081
|
-
if (props.columns && props.columns.length > 0 && props.columns.length < props.fields.length)
|
|
13082
|
-
|
|
13083
|
-
|
|
13084
|
-
buttonsForColumnOperations.push(buttonViewSchema);
|
|
13085
|
-
}
|
|
13265
|
+
// 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length < props.fields.length)
|
|
13266
|
+
let buttonViewSchema = await getButtonView(props);
|
|
13267
|
+
buttonsForColumnOperations.push(buttonViewSchema);
|
|
13086
13268
|
}
|
|
13087
13269
|
if (props.removable) {
|
|
13088
13270
|
let buttonDeleteSchema = getButtonDelete(props);
|
|
@@ -13118,85 +13300,51 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13118
13300
|
if (showAsInlineEditMode) {
|
|
13119
13301
|
inputTableSchema.needConfirm = false;
|
|
13120
13302
|
}
|
|
13121
|
-
let
|
|
13122
|
-
|
|
13123
|
-
|
|
13124
|
-
|
|
13125
|
-
|
|
13126
|
-
|
|
13127
|
-
|
|
13128
|
-
|
|
13129
|
-
|
|
13130
|
-
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
|
|
13134
|
-
"args": {
|
|
13135
|
-
"value": {
|
|
13136
|
-
"__changedItems": fieldValue
|
|
13137
|
-
}
|
|
13138
|
-
}
|
|
13303
|
+
let amis = props["input-table"] || props.amis;//额外支持"input-table"代替amis属性,是因为在字段yml文件中用amis作为key不好理解
|
|
13304
|
+
if (amis) {
|
|
13305
|
+
// 支持配置amis属性重写或添加最终生成的input-table中任何属性。
|
|
13306
|
+
delete amis.id;//如果steedos-input-table组件配置了amis.id属性,会造成新建编辑行功能不生效
|
|
13307
|
+
Object.assign(inputTableSchema, amis);
|
|
13308
|
+
}
|
|
13309
|
+
const isAnyFieldHasDependOn = (props.fields || []).find(function (item) {
|
|
13310
|
+
return item.depend_on;
|
|
13311
|
+
});
|
|
13312
|
+
if (isAnyFieldHasDependOn) {
|
|
13313
|
+
// 有任意一个子字段有depend_on属性时,强制设置禁用静态模式
|
|
13314
|
+
Object.assign(inputTableSchema, {
|
|
13315
|
+
strictMode: false
|
|
13139
13316
|
});
|
|
13140
|
-
|
|
13141
|
-
|
|
13142
|
-
// "componentId": "${props.id}",
|
|
13143
|
-
// "actionType": "setValue",
|
|
13144
|
-
// "args": {
|
|
13145
|
-
// "value": fieldValue
|
|
13146
|
-
// }
|
|
13147
|
-
// });
|
|
13148
|
-
`;
|
|
13149
|
-
let schema = {
|
|
13150
|
-
"type": "service",
|
|
13151
|
-
"body": [
|
|
13152
|
-
inputTableSchema
|
|
13153
|
-
],
|
|
13154
|
-
"className": props.className,
|
|
13155
|
-
"id": serviceId,
|
|
13156
|
-
"data": {
|
|
13157
|
-
"__wrapperServiceId": serviceId
|
|
13158
|
-
},
|
|
13159
|
-
"dataProvider": {
|
|
13160
|
-
"inited": dataProviderInited
|
|
13161
|
-
},
|
|
13162
|
-
"onEvent": {
|
|
13163
|
-
"init": {
|
|
13164
|
-
"actions": [
|
|
13165
|
-
{
|
|
13166
|
-
"actionType": "custom",
|
|
13167
|
-
"script": onInitScript
|
|
13168
|
-
}
|
|
13169
|
-
]
|
|
13170
|
-
}
|
|
13171
|
-
}
|
|
13172
|
-
};
|
|
13317
|
+
}
|
|
13318
|
+
let schemaBody = [inputTableSchema];
|
|
13173
13319
|
let footerToolbar = _$1.clone(props.footerToolbar || []); //这里不clone的话,会造成死循环,应该是因为props属性变更会让组件重新渲染
|
|
13174
13320
|
if (props.addable) {
|
|
13175
13321
|
let buttonNewSchema = await getButtonNew(props);
|
|
13176
13322
|
footerToolbar.unshift(buttonNewSchema);
|
|
13177
13323
|
}
|
|
13178
13324
|
if (footerToolbar.length) {
|
|
13179
|
-
|
|
13325
|
+
schemaBody.push({
|
|
13180
13326
|
"type": "wrapper",
|
|
13181
13327
|
"size": "none",
|
|
13182
13328
|
"body": footerToolbar
|
|
13183
13329
|
});
|
|
13184
13330
|
}
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
|
|
13194
|
-
if(isAnyFieldHasDependOn){
|
|
13195
|
-
// 有任意一个子字段有depend_on属性时,强制设置禁用静态模式
|
|
13196
|
-
Object.assign(schema.body[0], {
|
|
13197
|
-
strictMode: false
|
|
13331
|
+
// 直接把headerToolbar unshift进schemaBody,不会显示在label下面,而是显示在上面了,这个暂时没有解决办法,只能等amis 升级
|
|
13332
|
+
// 看起来amis官方后续会支持给input-table组件配置headerToolbar,见:https://github.com/baidu/amis/issues/7246
|
|
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
|
|
13198
13340
|
});
|
|
13199
13341
|
}
|
|
13342
|
+
let schema = {
|
|
13343
|
+
"type": "service",
|
|
13344
|
+
"body": schemaBody,
|
|
13345
|
+
"className": props.className,
|
|
13346
|
+
"id": serviceId
|
|
13347
|
+
};
|
|
13200
13348
|
// console.log("===schema===", schema);
|
|
13201
13349
|
return schema;
|
|
13202
13350
|
};
|