@steedos-widgets/amis-lib 3.6.2-beta.10 → 3.6.2-beta.11
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 +238 -39
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +238 -39
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +55 -27
- package/dist/index.umd.js.map +1 -1
- package/dist/types/lib/input_table.d.ts +1 -0
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1308,6 +1308,7 @@ var frontend_notifications$1 = "Notifications";
|
|
|
1308
1308
|
var frontend_notifications_allread$1 = "Mark all as read";
|
|
1309
1309
|
var frontend_notifications_allread_message$1 = "All marked as read";
|
|
1310
1310
|
var frontend_profile$1 = "Profile";
|
|
1311
|
+
var switch_space$1 = "Switch Space";
|
|
1311
1312
|
var frontend_about$1 = "About";
|
|
1312
1313
|
var frontend_log_out$1 = "Log out";
|
|
1313
1314
|
var frontend_listview_warning_start$1 = "The current ";
|
|
@@ -1395,6 +1396,7 @@ var en_us = {
|
|
|
1395
1396
|
frontend_notifications_allread: frontend_notifications_allread$1,
|
|
1396
1397
|
frontend_notifications_allread_message: frontend_notifications_allread_message$1,
|
|
1397
1398
|
frontend_profile: frontend_profile$1,
|
|
1399
|
+
switch_space: switch_space$1,
|
|
1398
1400
|
frontend_about: frontend_about$1,
|
|
1399
1401
|
frontend_log_out: frontend_log_out$1,
|
|
1400
1402
|
frontend_listview_warning_start: frontend_listview_warning_start$1,
|
|
@@ -1484,6 +1486,7 @@ var frontend_notifications = "通知";
|
|
|
1484
1486
|
var frontend_notifications_allread = "全部标记为已读";
|
|
1485
1487
|
var frontend_notifications_allread_message = "已全部标记为已读";
|
|
1486
1488
|
var frontend_profile = "个人资料";
|
|
1489
|
+
var switch_space = "切换工作区";
|
|
1487
1490
|
var frontend_about = "关于";
|
|
1488
1491
|
var frontend_log_out = "注销";
|
|
1489
1492
|
var frontend_listview_warning_start = "当前";
|
|
@@ -1572,6 +1575,7 @@ var zh_cn = {
|
|
|
1572
1575
|
frontend_notifications_allread: frontend_notifications_allread,
|
|
1573
1576
|
frontend_notifications_allread_message: frontend_notifications_allread_message,
|
|
1574
1577
|
frontend_profile: frontend_profile,
|
|
1578
|
+
switch_space: switch_space,
|
|
1575
1579
|
frontend_about: frontend_about,
|
|
1576
1580
|
frontend_log_out: frontend_log_out,
|
|
1577
1581
|
frontend_listview_warning_start: frontend_listview_warning_start,
|
|
@@ -12950,13 +12954,83 @@ async function getFormBody(permissionFields, formFields, ctx){
|
|
|
12950
12954
|
return await getSections(permissionFields, formFields, ctx);
|
|
12951
12955
|
}
|
|
12952
12956
|
|
|
12957
|
+
/*
|
|
12958
|
+
* @Author: 殷亮辉 yinlianghui@hotoa.com
|
|
12959
|
+
* @Date: 2024-01-18 15:12:41
|
|
12960
|
+
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
|
|
12961
|
+
* @LastEditTime: 2024-01-18 15:12:49
|
|
12962
|
+
*/
|
|
12963
|
+
/**
|
|
12964
|
+
* 生成符合标准uuid格式的36位满足唯一性的随机串
|
|
12965
|
+
* @returns uuid
|
|
12966
|
+
*/
|
|
12967
|
+
function uuidv4() {
|
|
12968
|
+
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
|
|
12969
|
+
(c ^ window.crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
|
12970
|
+
);
|
|
12971
|
+
}
|
|
12972
|
+
|
|
12953
12973
|
/*
|
|
12954
12974
|
* @Author: 殷亮辉 yinlianghui@hotoa.com
|
|
12955
12975
|
* @Date: 2023-11-15 09:50:22
|
|
12956
12976
|
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
|
|
12957
|
-
* @LastEditTime: 2024-01-
|
|
12977
|
+
* @LastEditTime: 2024-01-21 23:40:13
|
|
12958
12978
|
*/
|
|
12959
12979
|
|
|
12980
|
+
function getTablePrimaryKey(props){
|
|
12981
|
+
return props.primaryKey || "_id";
|
|
12982
|
+
}
|
|
12983
|
+
|
|
12984
|
+
/**
|
|
12985
|
+
* 子表组件字段值中每行数据的补上唯一标识字段值,其值为随机uuid
|
|
12986
|
+
* @param {*} value 子表组件字段值,数组
|
|
12987
|
+
* @param {*} primaryKey 主键字段名,一般为_id
|
|
12988
|
+
* @returns 转换后的子表组件字段值
|
|
12989
|
+
*/
|
|
12990
|
+
function getTableValueWithPrimaryKeyValue(value, primaryKey){
|
|
12991
|
+
if(!primaryKey){
|
|
12992
|
+
return value;
|
|
12993
|
+
}
|
|
12994
|
+
return (value || []).map((itemValue)=>{
|
|
12995
|
+
//这里不clone的话,会造成在pipeIn函数执行该函数后像pipeOut一样最终输出到表单项中,即库里把primaryKey字段值保存了
|
|
12996
|
+
const newItemValue = _$1.clone(itemValue);
|
|
12997
|
+
if(newItemValue[primaryKey]){
|
|
12998
|
+
if(newItemValue.children){
|
|
12999
|
+
newItemValue.children = getTableValueWithPrimaryKeyValue(newItemValue.children, primaryKey);
|
|
13000
|
+
}
|
|
13001
|
+
return newItemValue;
|
|
13002
|
+
}
|
|
13003
|
+
else {
|
|
13004
|
+
newItemValue[primaryKey] = uuidv4();
|
|
13005
|
+
if(newItemValue.children){
|
|
13006
|
+
newItemValue.children = getTableValueWithPrimaryKeyValue(newItemValue.children, primaryKey);
|
|
13007
|
+
}
|
|
13008
|
+
return newItemValue;
|
|
13009
|
+
}
|
|
13010
|
+
});
|
|
13011
|
+
}
|
|
13012
|
+
|
|
13013
|
+
/**
|
|
13014
|
+
* 子表组件字段值中每行数据的移除唯一标识字段值,因为该字段值一般只作临时标记,不存库
|
|
13015
|
+
* @param {*} value 子表组件字段值,数组
|
|
13016
|
+
* @param {*} primaryKey 主键字段名,一般为_id
|
|
13017
|
+
* @returns 转换后的子表组件字段值
|
|
13018
|
+
*/
|
|
13019
|
+
function getTableValueWithoutPrimaryKeyValue(value, primaryKey){
|
|
13020
|
+
if(!primaryKey){
|
|
13021
|
+
return value;
|
|
13022
|
+
}
|
|
13023
|
+
return (value || []).map((itemValue)=>{
|
|
13024
|
+
//这里clone只是为了保险,不是必须的,每次修改子表数据是否都会生成新的primaryKey字段值是由pipeOut中识别autoGeneratePrimaryKeyValue决定的,跟这里没关系
|
|
13025
|
+
const newItemValue = _$1.clone(itemValue);
|
|
13026
|
+
if(newItemValue.children){
|
|
13027
|
+
newItemValue.children = getTableValueWithoutPrimaryKeyValue(newItemValue.children, primaryKey);
|
|
13028
|
+
}
|
|
13029
|
+
delete newItemValue[primaryKey];
|
|
13030
|
+
return newItemValue;
|
|
13031
|
+
});
|
|
13032
|
+
}
|
|
13033
|
+
|
|
12960
13034
|
/**
|
|
12961
13035
|
* 子表组件字段值中每行数据的键值key移除指定前缀
|
|
12962
13036
|
* @param {*} value 子表组件字段值,数组
|
|
@@ -12968,7 +13042,9 @@ function getTableValueWithoutFieldPrefix(value, fieldPrefix){
|
|
|
12968
13042
|
(value || []).forEach((itemValue)=>{
|
|
12969
13043
|
var newItemValue = {};
|
|
12970
13044
|
for(let n in itemValue){
|
|
12971
|
-
|
|
13045
|
+
if(itemValue.hasOwnProperty(n)){
|
|
13046
|
+
newItemValue[n.replace(new RegExp(`^${fieldPrefix}`), "")] = itemValue[n];
|
|
13047
|
+
}
|
|
12972
13048
|
}
|
|
12973
13049
|
convertedValue.push(newItemValue);
|
|
12974
13050
|
});
|
|
@@ -12981,15 +13057,18 @@ function getTableValueWithoutFieldPrefix(value, fieldPrefix){
|
|
|
12981
13057
|
* @param {*} fieldPrefix 字段前缀
|
|
12982
13058
|
* @returns 转换后的子表组件字段值
|
|
12983
13059
|
*/
|
|
12984
|
-
function getTableValuePrependFieldPrefix(value, fieldPrefix){
|
|
13060
|
+
function getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey){
|
|
12985
13061
|
let convertedValue = [];
|
|
12986
13062
|
(value || []).forEach((itemValue)=>{
|
|
12987
13063
|
var newItemValue = {};
|
|
12988
13064
|
for(let n in itemValue){
|
|
12989
|
-
if(typeof itemValue[n] !== undefined){
|
|
13065
|
+
if(itemValue.hasOwnProperty(n) && typeof itemValue[n] !== undefined && n !== primaryKey){
|
|
12990
13066
|
newItemValue[`${fieldPrefix}${n}`] = itemValue[n];
|
|
12991
13067
|
}
|
|
12992
13068
|
}
|
|
13069
|
+
if(primaryKey && itemValue[primaryKey]){
|
|
13070
|
+
newItemValue[primaryKey] = itemValue[primaryKey];
|
|
13071
|
+
}
|
|
12993
13072
|
convertedValue.push(newItemValue);
|
|
12994
13073
|
});
|
|
12995
13074
|
return convertedValue;
|
|
@@ -13014,7 +13093,12 @@ function getTableFieldsWithoutFieldPrefix(fields, fieldPrefix){
|
|
|
13014
13093
|
* @param {*} mode edit/new/readonly
|
|
13015
13094
|
*/
|
|
13016
13095
|
function getFormFields(props, mode = "edit") {
|
|
13017
|
-
|
|
13096
|
+
let fieldPrefix = props.fieldPrefix;
|
|
13097
|
+
let fields = props.fields || [];
|
|
13098
|
+
if (fieldPrefix) {
|
|
13099
|
+
fields = getTableFieldsWithoutFieldPrefix(fields, fieldPrefix);
|
|
13100
|
+
}
|
|
13101
|
+
return (fields || []).map(function (item) {
|
|
13018
13102
|
let formItem = {
|
|
13019
13103
|
"type": "steedos-field",
|
|
13020
13104
|
"name": item.name,
|
|
@@ -13086,7 +13170,12 @@ async function getInputTableColumns(props) {
|
|
|
13086
13170
|
let inlineEditMode = props.inlineEditMode;
|
|
13087
13171
|
let showAsInlineEditMode = inlineEditMode && props.editable;
|
|
13088
13172
|
// 实测过,直接不生成对应的隐藏column并不会对input-table值造成丢失问题,隐藏的列字段值能正常维护
|
|
13089
|
-
|
|
13173
|
+
|
|
13174
|
+
let fieldPrefix = props.fieldPrefix;
|
|
13175
|
+
let fields = props.fields || [];
|
|
13176
|
+
if (fieldPrefix) {
|
|
13177
|
+
fields = getTableFieldsWithoutFieldPrefix(fields, fieldPrefix);
|
|
13178
|
+
}
|
|
13090
13179
|
if (columns && columns.length) {
|
|
13091
13180
|
return columns.map(function (column) {
|
|
13092
13181
|
let field, extendColumnProps = {};
|
|
@@ -13155,6 +13244,8 @@ function getFormPagination(props, mode) {
|
|
|
13155
13244
|
let currentIndex = event.data.index;
|
|
13156
13245
|
// 翻页到下一页之前需要先把当前页改动的内容保存到中间变量__tableItems中
|
|
13157
13246
|
let currentFormValues = scope.getComponentById(__formId).getValues();
|
|
13247
|
+
// 这里不clone的话,其值会带上__super属性
|
|
13248
|
+
currentFormValues = _.clone(currentFormValues);
|
|
13158
13249
|
var parent = event.data.parent;
|
|
13159
13250
|
var __parentIndex = event.data.__parentIndex;
|
|
13160
13251
|
if(parent){
|
|
@@ -13274,6 +13365,7 @@ function getFormPaginationWrapper(props, form, mode) {
|
|
|
13274
13365
|
// console.log("==getFormPaginationWrapper===", props, mode);
|
|
13275
13366
|
let serviceId = getComponentId("form_pagination", props.id);
|
|
13276
13367
|
let tableServiceId = getComponentId("table_service", props.id);
|
|
13368
|
+
let primaryKey = getTablePrimaryKey(props);
|
|
13277
13369
|
let innerForm = Object.assign({}, form, {
|
|
13278
13370
|
"data": {
|
|
13279
13371
|
// 这里加__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
|
|
@@ -13301,7 +13393,6 @@ function getFormPaginationWrapper(props, form, mode) {
|
|
|
13301
13393
|
}
|
|
13302
13394
|
];
|
|
13303
13395
|
let onServiceInitedScript = `
|
|
13304
|
-
|
|
13305
13396
|
// 以下脚本解决了有时弹出编辑表单时,表单中的值比最后一次编辑保存的值会延迟一拍。
|
|
13306
13397
|
// 比如:inlineEditMode模式时,用户在表格单元格中直接修改数据,然后弹出的表单form中并没有包含单元格中修改的内容
|
|
13307
13398
|
// 另外有的地方在非inlineEditMode模式时也会有这种延迟一拍问题,比如对象字段中下拉框类型字段的”选择项“属性
|
|
@@ -13315,13 +13406,13 @@ function getFormPaginationWrapper(props, form, mode) {
|
|
|
13315
13406
|
// 这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
|
|
13316
13407
|
// 这里如果不.clone的话,在弹出窗口中显示的子表组件,添加行后点窗口的取消按钮关闭窗口后无法把之前的操作还原,即把之前添加的行自动移除
|
|
13317
13408
|
let lastestFieldValue = _.clone(wrapperServiceData["${props.name}"] || []);
|
|
13318
|
-
let fieldPrefix = "${props.fieldPrefix}";
|
|
13409
|
+
let fieldPrefix = "${props.fieldPrefix || ''}";
|
|
13319
13410
|
if(fieldPrefix){
|
|
13320
13411
|
let getTableValueWithoutFieldPrefix = new Function('v', 'f', "return (" + ${getTableValueWithoutFieldPrefix.toString()} + ")(v, f)");
|
|
13321
13412
|
lastestFieldValue = getTableValueWithoutFieldPrefix(lastestFieldValue, fieldPrefix);
|
|
13322
13413
|
}
|
|
13323
13414
|
//不可以直接像event.data.__tableItems = lastestFieldValue; 这样整个赋值,否则作用域会断
|
|
13324
|
-
let mode = "${mode}";
|
|
13415
|
+
let mode = "${mode || ''}";
|
|
13325
13416
|
if(mode === "new"){
|
|
13326
13417
|
// 点击子表组件底部新增按钮时新增一条空白行并自动翻页到新增行
|
|
13327
13418
|
// 注意点击弹出的子表行详细表单中的新增按钮不会进此service init事件函数中
|
|
@@ -13347,10 +13438,20 @@ function getFormPaginationWrapper(props, form, mode) {
|
|
|
13347
13438
|
var fieldValue = event.data.__tableItems;
|
|
13348
13439
|
if(parent){
|
|
13349
13440
|
// 如果是子行,即在节点嵌套情况下,当前节点如果是children属性下的子节点时,则算出其所属父行的索引值
|
|
13350
|
-
var primaryKey = "${
|
|
13441
|
+
var primaryKey = "${primaryKey}";
|
|
13351
13442
|
event.data.__parentIndex = _.findIndex(fieldValue, function(item){
|
|
13352
13443
|
return item[primaryKey] == parent[primaryKey];
|
|
13353
13444
|
});
|
|
13445
|
+
if(event.data.__parentIndex < 0){
|
|
13446
|
+
let tableId = "${props.id}";
|
|
13447
|
+
let table = scope.getComponentById(tableId)
|
|
13448
|
+
// autoGeneratePrimaryKeyValue不为true的情况下,即子表组件input-table的pipeOut函数中会移除表单了子表字段的primaryKey字段值,
|
|
13449
|
+
// 此时行primaryKey字段值为空,但是pipeIn函数中已经为input-table自动生成过primaryKey字段值了,只是没有输出到表单字段值中而已
|
|
13450
|
+
// 所以上面从表单字段值中没找到__parentIndex,是因为此时行primaryKey字段值只经过pipeIn保存到table组件内而没有保存到tableService
|
|
13451
|
+
event.data.__parentIndex = _.findIndex(table.props.value, function(item){
|
|
13452
|
+
return item[primaryKey] == parent[primaryKey];
|
|
13453
|
+
});
|
|
13454
|
+
}
|
|
13354
13455
|
}
|
|
13355
13456
|
`;
|
|
13356
13457
|
let schema = {
|
|
@@ -13399,6 +13500,7 @@ function getFormPaginationWrapper(props, form, mode) {
|
|
|
13399
13500
|
async function getForm(props, mode = "edit", formId) {
|
|
13400
13501
|
let formFields = getFormFields(props, mode);
|
|
13401
13502
|
let body = await getFormBody(null, formFields);
|
|
13503
|
+
let primaryKey = getTablePrimaryKey(props);
|
|
13402
13504
|
if (!formId) {
|
|
13403
13505
|
formId = getComponentId("form", props.id);
|
|
13404
13506
|
}
|
|
@@ -13417,6 +13519,18 @@ async function getForm(props, mode = "edit", formId) {
|
|
|
13417
13519
|
// 新增行弹出编辑行表单,在弹出之前已经不用先增加一行,因为在翻页service初始化的时候会判断mode为new时自动新增一行
|
|
13418
13520
|
let onEditItemSubmitScript = `
|
|
13419
13521
|
// let fieldValue = _.cloneDeep(event.data["${props.name}"]);
|
|
13522
|
+
let removeEmptyItems = function(items){
|
|
13523
|
+
let i = _.findIndex(items, function(item){
|
|
13524
|
+
return item === undefined
|
|
13525
|
+
});
|
|
13526
|
+
if(i > -1){
|
|
13527
|
+
items.splice(i, 1);
|
|
13528
|
+
removeEmptyItems(items);
|
|
13529
|
+
}
|
|
13530
|
+
}
|
|
13531
|
+
// 因为删除时只是把input-table组件中的行数据删除了,并没有把父层service中的行删除,所以__tableItems会有值为undefined的数据,需要移除掉
|
|
13532
|
+
// 不用event.data.__tableItems = _.compact(event.data.__tableItems)是因为会把__tableItems变量保存到表单中
|
|
13533
|
+
removeEmptyItems(event.data.__tableItems);
|
|
13420
13534
|
let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
|
|
13421
13535
|
//这里加__super.__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
|
|
13422
13536
|
// 比如“对象字段”对象options字段是一个子表字段,但是主表(即“对象字段”对象)中正好有一个名为index的字段
|
|
@@ -13425,6 +13539,8 @@ async function getForm(props, mode = "edit", formId) {
|
|
|
13425
13539
|
var currentFormValues = JSON.parse(JSON.stringify(event.data));
|
|
13426
13540
|
var parent = event.data.__super.__super.parent;
|
|
13427
13541
|
var __parentIndex = event.data.__super.__super.__parentIndex;
|
|
13542
|
+
let uuidv4 = new Function("return (" + ${uuidv4.toString()} + ")()");
|
|
13543
|
+
var primaryKey = "${primaryKey}";
|
|
13428
13544
|
if(parent){
|
|
13429
13545
|
fieldValue[__parentIndex].children[currentIndex] = currentFormValues;
|
|
13430
13546
|
// 重写父节点,并且改变其某个属性以让子节点修改的内容回显到界面上
|
|
@@ -13434,6 +13550,8 @@ async function getForm(props, mode = "edit", formId) {
|
|
|
13434
13550
|
});
|
|
13435
13551
|
}
|
|
13436
13552
|
else{
|
|
13553
|
+
// 这里currentFormValues中如果没有primaryKey字段值不用处理,因为组件的pipeIn/pipeOut中会为每行自动生成
|
|
13554
|
+
// 也不用担心复制行时_id会重复,因为点击复制按钮时已经处理过了
|
|
13437
13555
|
fieldValue[currentIndex] = currentFormValues;
|
|
13438
13556
|
}
|
|
13439
13557
|
doAction({
|
|
@@ -13531,6 +13649,7 @@ async function getForm(props, mode = "edit", formId) {
|
|
|
13531
13649
|
*/
|
|
13532
13650
|
async function getButtonActions(props, mode) {
|
|
13533
13651
|
let actions = [];
|
|
13652
|
+
let primaryKey = getTablePrimaryKey(props);
|
|
13534
13653
|
let formId = getComponentId("form", props.id);
|
|
13535
13654
|
let dialogId = getComponentId("dialog", props.id);
|
|
13536
13655
|
let buttonNextId = getComponentId("button_next", props.id);
|
|
@@ -13573,13 +13692,35 @@ async function getButtonActions(props, mode) {
|
|
|
13573
13692
|
// };
|
|
13574
13693
|
let onSaveAndNewItemScript = `
|
|
13575
13694
|
let scope = event.context.scoped;
|
|
13695
|
+
let removeEmptyItems = function(items){
|
|
13696
|
+
let i = _.findIndex(items, function(item){
|
|
13697
|
+
return item === undefined
|
|
13698
|
+
});
|
|
13699
|
+
if(i > -1){
|
|
13700
|
+
items.splice(i, 1);
|
|
13701
|
+
removeEmptyItems(items);
|
|
13702
|
+
}
|
|
13703
|
+
}
|
|
13704
|
+
// 因为删除时只是把input-table组件中的行数据删除了,并没有把父层service中的行删除,所以__tableItems会有值为undefined的数据,需要移除掉
|
|
13705
|
+
// 不用event.data.__tableItems = _.compact(event.data.__tableItems)是因为会把__tableItems变量保存到表单中
|
|
13706
|
+
removeEmptyItems(event.data.__tableItems);
|
|
13576
13707
|
let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
|
|
13577
13708
|
// 新建一条空白行并保存到子表组件
|
|
13578
13709
|
var parent = event.data.__super.parent;
|
|
13579
|
-
var primaryKey = "${
|
|
13710
|
+
var primaryKey = "${primaryKey}";
|
|
13580
13711
|
var __parentIndex = parent && _.findIndex(fieldValue, function(item){
|
|
13581
13712
|
return item[primaryKey] == parent[primaryKey];
|
|
13582
13713
|
});
|
|
13714
|
+
if(parent && __parentIndex < 0){
|
|
13715
|
+
let tableId = "${props.id}";
|
|
13716
|
+
let table = scope.getComponentById(tableId)
|
|
13717
|
+
// autoGeneratePrimaryKeyValue不为true的情况下,即子表组件input-table的pipeOut函数中会移除表单了子表字段的primaryKey字段值,
|
|
13718
|
+
// 此时行primaryKey字段值为空,但是pipeIn函数中已经为input-table自动生成过primaryKey字段值了,只是没有输出到表单字段值中而已
|
|
13719
|
+
// 所以上面从表单字段值中没找到__parentIndex,是因为此时行primaryKey字段值只经过pipeIn保存到table组件内而没有保存到tableService
|
|
13720
|
+
__parentIndex = _.findIndex(table.props.value, function(item){
|
|
13721
|
+
return item[primaryKey] == parent[primaryKey];
|
|
13722
|
+
});
|
|
13723
|
+
}
|
|
13583
13724
|
if(parent){
|
|
13584
13725
|
fieldValue[__parentIndex].children.push({});
|
|
13585
13726
|
// 这里实测不需要fieldValue[__parentIndex] = ... 来重写整个父行让子表回显,所以没加相关代码
|
|
@@ -13613,14 +13754,42 @@ async function getButtonActions(props, mode) {
|
|
|
13613
13754
|
let __formId = "${formId}";
|
|
13614
13755
|
// let newItem = JSON.parse(JSON.stringify(event.data));
|
|
13615
13756
|
let newItem = scope.getComponentById(__formId).getValues();//这里不可以用event.data,因为其拿到的是弹出表单时的初始值,不是用户实时填写的数据
|
|
13757
|
+
newItem = _.clone(newItem);
|
|
13758
|
+
let removeEmptyItems = function(items){
|
|
13759
|
+
let i = _.findIndex(items, function(item){
|
|
13760
|
+
return item === undefined
|
|
13761
|
+
});
|
|
13762
|
+
if(i > -1){
|
|
13763
|
+
items.splice(i, 1);
|
|
13764
|
+
removeEmptyItems(items);
|
|
13765
|
+
}
|
|
13766
|
+
}
|
|
13767
|
+
// 因为删除时只是把input-table组件中的行数据删除了,并没有把父层service中的行删除,所以__tableItems会有值为undefined的数据,需要移除掉
|
|
13768
|
+
// 不用event.data.__tableItems = _.compact(event.data.__tableItems)是因为会把__tableItems变量保存到表单中
|
|
13769
|
+
removeEmptyItems(event.data.__tableItems);
|
|
13616
13770
|
let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
|
|
13617
13771
|
// 复制当前页数据到新建行并保存到子表组件
|
|
13618
13772
|
// fieldValue.push(newItem);
|
|
13619
13773
|
var parent = event.data.__super.parent;
|
|
13620
|
-
var primaryKey = "${
|
|
13774
|
+
var primaryKey = "${primaryKey}";
|
|
13621
13775
|
var __parentIndex = parent && _.findIndex(fieldValue, function(item){
|
|
13622
13776
|
return item[primaryKey] == parent[primaryKey];
|
|
13623
13777
|
});
|
|
13778
|
+
if(parent && __parentIndex < 0){
|
|
13779
|
+
let tableId = "${props.id}";
|
|
13780
|
+
let table = scope.getComponentById(tableId)
|
|
13781
|
+
// autoGeneratePrimaryKeyValue不为true的情况下,即子表组件input-table的pipeOut函数中会移除表单了子表字段的primaryKey字段值,
|
|
13782
|
+
// 此时行primaryKey字段值为空,但是pipeIn函数中已经为input-table自动生成过primaryKey字段值了,只是没有输出到表单字段值中而已
|
|
13783
|
+
// 所以上面从表单字段值中没找到__parentIndex,是因为此时行primaryKey字段值只经过pipeIn保存到table组件内而没有保存到tableService
|
|
13784
|
+
__parentIndex = _.findIndex(table.props.value, function(item){
|
|
13785
|
+
return item[primaryKey] == parent[primaryKey];
|
|
13786
|
+
});
|
|
13787
|
+
}
|
|
13788
|
+
if(newItem[primaryKey]){
|
|
13789
|
+
// 如果newItem已经有主键字段值,则重新生成新的主键值,否则会重复。
|
|
13790
|
+
let uuidv4 = new Function("return (" + ${uuidv4.toString()} + ")()");
|
|
13791
|
+
newItem[primaryKey] = uuidv4();
|
|
13792
|
+
}
|
|
13624
13793
|
if(parent){
|
|
13625
13794
|
fieldValue[__parentIndex].children.push(newItem);
|
|
13626
13795
|
// 这里实测不需要fieldValue[__parentIndex] = ... 来重写整个父行让子表回显,所以没加相关代码
|
|
@@ -13844,13 +14013,24 @@ async function getButtonActions(props, mode) {
|
|
|
13844
14013
|
let wrapperServiceData = wrapperService.getData();
|
|
13845
14014
|
// 这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
|
|
13846
14015
|
// 这里_.clone是因为字段设计布局设置分组这种弹出窗口中的子表组件,直接删除后,点取消无法还原
|
|
14016
|
+
// 也因为这里clone没有直接删除,所以弹出编辑表单提交事件中event.data.__tableItems中取到的值会有被删除的行数据为undefined
|
|
13847
14017
|
let lastestFieldValue = _.clone(wrapperServiceData["${props.name}"]);
|
|
13848
14018
|
var currentIndex = event.data.index;
|
|
13849
14019
|
var parent = event.data.__super.parent;
|
|
13850
|
-
var primaryKey = "${
|
|
14020
|
+
var primaryKey = "${primaryKey}";
|
|
13851
14021
|
var __parentIndex = parent && _.findIndex(lastestFieldValue, function(item){
|
|
13852
14022
|
return item[primaryKey] == parent[primaryKey];
|
|
13853
14023
|
});
|
|
14024
|
+
if(parent && __parentIndex < 0){
|
|
14025
|
+
let tableId = "${props.id}";
|
|
14026
|
+
let table = scope.getComponentById(tableId)
|
|
14027
|
+
// autoGeneratePrimaryKeyValue不为true的情况下,即子表组件input-table的pipeOut函数中会移除表单了子表字段的primaryKey字段值,
|
|
14028
|
+
// 此时行primaryKey字段值为空,但是pipeIn函数中已经为input-table自动生成过primaryKey字段值了,只是没有输出到表单字段值中而已
|
|
14029
|
+
// 所以上面从表单字段值中没找到__parentIndex,是因为此时行primaryKey字段值只经过pipeIn保存到table组件内而没有保存到tableService
|
|
14030
|
+
__parentIndex = _.findIndex(table.props.value, function(item){
|
|
14031
|
+
return item[primaryKey] == parent[primaryKey];
|
|
14032
|
+
});
|
|
14033
|
+
}
|
|
13854
14034
|
if(parent){
|
|
13855
14035
|
lastestFieldValue[__parentIndex].children.splice(currentIndex, 1);
|
|
13856
14036
|
// 重写父节点,并且改变其某个属性以让子节点修改的内容回显到界面上
|
|
@@ -13862,6 +14042,11 @@ async function getButtonActions(props, mode) {
|
|
|
13862
14042
|
else{
|
|
13863
14043
|
lastestFieldValue.splice(currentIndex, 1);
|
|
13864
14044
|
}
|
|
14045
|
+
let fieldPrefix = "${props.fieldPrefix || ''}";
|
|
14046
|
+
if(fieldPrefix){
|
|
14047
|
+
let getTableValueWithoutFieldPrefix = new Function('v', 'f', "return (" + ${getTableValueWithoutFieldPrefix.toString()} + ")(v, f)");
|
|
14048
|
+
lastestFieldValue = getTableValueWithoutFieldPrefix(lastestFieldValue, fieldPrefix);
|
|
14049
|
+
}
|
|
13865
14050
|
doAction({
|
|
13866
14051
|
"componentId": "${props.id}",
|
|
13867
14052
|
"actionType": "setValue",
|
|
@@ -13947,16 +14132,15 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13947
14132
|
if (!props.id) {
|
|
13948
14133
|
props.id = "steedos_input_table_" + props.name + "_" + Math.random().toString(36).substr(2, 9);
|
|
13949
14134
|
}
|
|
13950
|
-
|
|
13951
|
-
props.primaryKey = "_id";
|
|
13952
|
-
}
|
|
14135
|
+
let primaryKey = getTablePrimaryKey(props);
|
|
13953
14136
|
let showOperation = props.showOperation;
|
|
13954
14137
|
if(showOperation !== false){
|
|
13955
14138
|
showOperation = true;
|
|
13956
14139
|
}
|
|
13957
|
-
|
|
13958
|
-
|
|
13959
|
-
|
|
14140
|
+
let fieldPrefix = props.fieldPrefix;
|
|
14141
|
+
let fields = props.fields || [];
|
|
14142
|
+
if (fieldPrefix) {
|
|
14143
|
+
fields = getTableFieldsWithoutFieldPrefix(fields, fieldPrefix);
|
|
13960
14144
|
}
|
|
13961
14145
|
let serviceId = getComponentId("table_service", props.id);
|
|
13962
14146
|
let buttonsForColumnOperations = [];
|
|
@@ -13969,7 +14153,7 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13969
14153
|
// 始终显示弹出子表表单按钮,如果需要判断只在有列被隐藏时才需要显示弹出表单按钮放开下面的if逻辑就好
|
|
13970
14154
|
showEditButton = true;
|
|
13971
14155
|
// // inline edit模式下只在有列被隐藏时才需要显示编辑按钮
|
|
13972
|
-
// if (props.columns && props.columns.length > 0 && props.columns.length <
|
|
14156
|
+
// if (props.columns && props.columns.length > 0 && props.columns.length < fields.length) {
|
|
13973
14157
|
// showEditButton = true;
|
|
13974
14158
|
// }
|
|
13975
14159
|
// else {
|
|
@@ -13984,7 +14168,7 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13984
14168
|
}
|
|
13985
14169
|
else {
|
|
13986
14170
|
// 只读时显示查看按钮
|
|
13987
|
-
// 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length <
|
|
14171
|
+
// 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length < fields.length)
|
|
13988
14172
|
let buttonViewSchema = await getButtonView(props);
|
|
13989
14173
|
buttonsForColumnOperations.push(buttonViewSchema);
|
|
13990
14174
|
}
|
|
@@ -13993,7 +14177,7 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
13993
14177
|
buttonsForColumnOperations.push(buttonDeleteSchema);
|
|
13994
14178
|
}
|
|
13995
14179
|
}
|
|
13996
|
-
let amis = props["input-table"] || props.amis;//额外支持"input-table"代替amis属性,是因为在字段yml文件中用amis作为key不好理解
|
|
14180
|
+
let amis = props["input-table"] || props.amis || {};//额外支持"input-table"代替amis属性,是因为在字段yml文件中用amis作为key不好理解
|
|
13997
14181
|
let inputTableSchema = {
|
|
13998
14182
|
"type": "input-table",
|
|
13999
14183
|
"label": props.label,
|
|
@@ -14012,13 +14196,42 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
14012
14196
|
"showTableAddBtn": false,
|
|
14013
14197
|
"showFooterAddBtn": false,
|
|
14014
14198
|
"className": props.tableClassName,
|
|
14199
|
+
"pipeIn": (value, data) => {
|
|
14200
|
+
if(fieldPrefix){
|
|
14201
|
+
value = getTableValueWithoutFieldPrefix(value, fieldPrefix);
|
|
14202
|
+
}
|
|
14203
|
+
if(primaryKey){
|
|
14204
|
+
// 这里临时给每行数据补上primaryKey字段值,如果库里不需要保存这里补上的字段值,pipeOut中会识别autoGeneratePrimaryKeyValue属性选择最终移除这里补上的字段值
|
|
14205
|
+
// 这里始终自动生成primaryKey字段值,而不是只在pipeOut输出整个子表字段值时才生成,是因为要支持当数据库里保存的子表字段行数据没有primaryKey字段值时的行嵌套模式(即节点的children属性)功能
|
|
14206
|
+
// 这里要注意,流程详细设置界面的字段设置功能中的子表组件中,数据库里保存的子表字段行数据是有primaryKey字段值的,它不依赖这里自动生成行primaryKey值功能
|
|
14207
|
+
value = getTableValueWithPrimaryKeyValue(value, primaryKey);
|
|
14208
|
+
}
|
|
14209
|
+
if(amis.pipeIn){
|
|
14210
|
+
if(typeof amis.pipeIn === 'function'){
|
|
14211
|
+
return amis.pipeIn(value, data);
|
|
14212
|
+
}
|
|
14213
|
+
}
|
|
14214
|
+
return value;
|
|
14215
|
+
},
|
|
14015
14216
|
"pipeOut": (value, data) => {
|
|
14016
14217
|
value = (value || []).map(function(item){
|
|
14017
14218
|
delete item.__fix_rerender_after_children_modified_tag;
|
|
14018
14219
|
return item;
|
|
14019
14220
|
});
|
|
14020
|
-
if(
|
|
14021
|
-
value = getTableValuePrependFieldPrefix(value,
|
|
14221
|
+
if(fieldPrefix){
|
|
14222
|
+
value = getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey);
|
|
14223
|
+
}
|
|
14224
|
+
if(props.autoGeneratePrimaryKeyValue === true){
|
|
14225
|
+
// 如果需要把自动生成的primaryKey值输出保存的库中,则补全所有行中的primaryKey值
|
|
14226
|
+
// 这里如果不全部补全的话,初始从库里返回的字段值中拿到的行没primaryKey值的话就不会自动补上
|
|
14227
|
+
value = getTableValueWithPrimaryKeyValue(value, primaryKey);
|
|
14228
|
+
}
|
|
14229
|
+
else {
|
|
14230
|
+
// 默认情况下,也就是没有配置autoGeneratePrimaryKey时,最终输出的字段值要移除行中的primaryKey值
|
|
14231
|
+
// 需要注意如果没有配置autoGeneratePrimaryKey时,因为每次弹出行编辑窗口保存后都会先后进入pipeOut和pipeIn,
|
|
14232
|
+
// 这里删除掉了primaryKey值,所以primaryKey值每次弹出编辑窗口保存后都会给每行重新生成新的primaryKey值
|
|
14233
|
+
// 只有autoGeneratePrimaryKey配置为true时,每行的primaryKey字段值才会始终保持不变
|
|
14234
|
+
value = getTableValueWithoutPrimaryKeyValue(value, primaryKey);
|
|
14022
14235
|
}
|
|
14023
14236
|
if(amis.pipeOut){
|
|
14024
14237
|
if(typeof amis.pipeOut === 'function'){
|
|
@@ -14028,20 +14241,6 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
14028
14241
|
return value;
|
|
14029
14242
|
}
|
|
14030
14243
|
};
|
|
14031
|
-
if(amis.pipeIn){
|
|
14032
|
-
inputTableSchema.pipeIn = amis.pipeIn;
|
|
14033
|
-
}
|
|
14034
|
-
if(props.fieldPrefix){
|
|
14035
|
-
inputTableSchema.pipeIn = (value, data) => {
|
|
14036
|
-
value = getTableValueWithoutFieldPrefix(value, props.fieldPrefix);
|
|
14037
|
-
if(amis.pipeIn){
|
|
14038
|
-
if(typeof amis.pipeIn === 'function'){
|
|
14039
|
-
return amis.pipeIn(value, data);
|
|
14040
|
-
}
|
|
14041
|
-
}
|
|
14042
|
-
return value;
|
|
14043
|
-
};
|
|
14044
|
-
}
|
|
14045
14244
|
if (buttonsForColumnOperations.length) {
|
|
14046
14245
|
inputTableSchema.columns.push({
|
|
14047
14246
|
"name": "__op__",
|
|
@@ -14060,7 +14259,7 @@ const getAmisInputTableSchema = async (props) => {
|
|
|
14060
14259
|
delete amis.pipeOut;//该属性在上面合并过了
|
|
14061
14260
|
Object.assign(inputTableSchema, amis);
|
|
14062
14261
|
}
|
|
14063
|
-
const isAnyFieldHasDependOn = (
|
|
14262
|
+
const isAnyFieldHasDependOn = (fields || []).find(function (item) {
|
|
14064
14263
|
return item.depend_on;
|
|
14065
14264
|
});
|
|
14066
14265
|
if (isAnyFieldHasDependOn) {
|