@steedos-widgets/amis-lib 3.6.2-beta.1 → 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/index.esm.js CHANGED
@@ -340,22 +340,26 @@ const getSteedosAuth = () => {
340
340
  * @Description:
341
341
  */
342
342
 
343
-
344
343
  const Router = {
345
344
  getTabDisplayAs(tab_id){
345
+ const uiSchema = getUISchemaSync$1(tab_id, false);
346
346
  var urlSearch = new URLSearchParams(document.location.search);
347
347
  if(urlSearch.has('display')){
348
348
  return urlSearch.get('display')
349
349
  }
350
350
  const key = `tab_${tab_id}_display`;
351
351
  // const key = `page_display`;
352
- const value = localStorage.getItem(key);
353
- return value ? value : 'grid'
352
+ const value = sessionStorage.getItem(key);
353
+ let defaultDisplay = "grid";
354
+ if(uiSchema.enable_split){
355
+ defaultDisplay = "split";
356
+ }
357
+ return value ? value : defaultDisplay;
354
358
  },
355
359
 
356
360
  setTabDisplayAs(tab_id, displayAs){
357
361
  const key = `tab_${tab_id}_display`;
358
- localStorage.setItem(key, displayAs);
362
+ sessionStorage.setItem(key, displayAs);
359
363
  },
360
364
  getAppPath({formFactor, appId}){
361
365
  return `/app/${appId}`;
@@ -459,7 +463,7 @@ function getComparableAmisVersion() {
459
463
  * @Author: baozhoutao@steedos.com
460
464
  * @Date: 2022-05-23 09:53:08
461
465
  * @LastEditors: liaodaxue
462
- * @LastEditTime: 2023-10-11 17:32:17
466
+ * @LastEditTime: 2024-01-17 16:00:27
463
467
  * @Description:
464
468
  */
465
469
 
@@ -531,7 +535,7 @@ function getSelectMap(selectOptions){
531
535
 
532
536
  function getNameTplUrl(field, ctx){
533
537
  if(ctx.objectName === 'cms_files'){
534
- return `\${context.rootUrl}/api/files/files/\${versions[0]}?download=true`
538
+ return "${(versions[0] && versions[0].url) ? versions[0].url+'?download=true' : context.rootUrl+'/api/files/files/'+versions[0]+'?download=true'}"
535
539
  }
536
540
  const href = Router.getObjectDetailPath({
537
541
  ...ctx, formFactor: ctx.formFactor, appId: "${appId}", objectName: ctx.objectName || "${objectName}", recordId: `\${${ctx.idFieldName}}`
@@ -1277,6 +1281,7 @@ var frontend_notifications$1 = "Notifications";
1277
1281
  var frontend_notifications_allread$1 = "Mark all as read";
1278
1282
  var frontend_notifications_allread_message$1 = "All marked as read";
1279
1283
  var frontend_profile$1 = "Profile";
1284
+ var switch_space$1 = "Switch Space";
1280
1285
  var frontend_about$1 = "About";
1281
1286
  var frontend_log_out$1 = "Log out";
1282
1287
  var frontend_listview_warning_start$1 = "The current ";
@@ -1364,6 +1369,7 @@ var en_us = {
1364
1369
  frontend_notifications_allread: frontend_notifications_allread$1,
1365
1370
  frontend_notifications_allread_message: frontend_notifications_allread_message$1,
1366
1371
  frontend_profile: frontend_profile$1,
1372
+ switch_space: switch_space$1,
1367
1373
  frontend_about: frontend_about$1,
1368
1374
  frontend_log_out: frontend_log_out$1,
1369
1375
  frontend_listview_warning_start: frontend_listview_warning_start$1,
@@ -1403,9 +1409,9 @@ var frontend_display_type_is_split = "分栏视图";
1403
1409
  var frontend_display_as = "显示为";
1404
1410
  var frontend_record_sum = "个项目";
1405
1411
  var frontend_button_reload_tooltip = "刷新";
1406
- var frontend_button_search_tooltip = "筛选";
1412
+ var frontend_button_search_tooltip = "搜索";
1407
1413
  var frontend_fields_filter_button_search = "搜索";
1408
- var frontend_fields_filter_button_settings = "设置搜索项";
1414
+ var frontend_fields_filter_button_settings = "选择搜索项";
1409
1415
  var frontend_button_listview_control_tooltip = "列表视图控制";
1410
1416
  var frontend_button_listview_control_label = "列表视图控制";
1411
1417
  var frontend_listview_control_columns = "显示的列";
@@ -1453,6 +1459,7 @@ var frontend_notifications = "通知";
1453
1459
  var frontend_notifications_allread = "全部标记为已读";
1454
1460
  var frontend_notifications_allread_message = "已全部标记为已读";
1455
1461
  var frontend_profile = "个人资料";
1462
+ var switch_space = "切换工作区";
1456
1463
  var frontend_about = "关于";
1457
1464
  var frontend_log_out = "注销";
1458
1465
  var frontend_listview_warning_start = "当前";
@@ -1541,6 +1548,7 @@ var zh_cn = {
1541
1548
  frontend_notifications_allread: frontend_notifications_allread,
1542
1549
  frontend_notifications_allread_message: frontend_notifications_allread_message,
1543
1550
  frontend_profile: frontend_profile,
1551
+ switch_space: switch_space,
1544
1552
  frontend_about: frontend_about,
1545
1553
  frontend_log_out: frontend_log_out,
1546
1554
  frontend_listview_warning_start: frontend_listview_warning_start,
@@ -2060,9 +2068,13 @@ async function getTableColumns(fields, options){
2060
2068
  const quickEditSchema = allowEdit ? await getQuickEditSchema(field, options) : allowEdit;
2061
2069
  let className = "";
2062
2070
  if(field.wrap != true){
2063
- className += " whitespace-nowrap ";
2071
+ if(field.wrap != false && field.is_wide){
2072
+ className += " break-words ";
2073
+ }else {
2074
+ className += " whitespace-nowrap ";
2075
+ }
2064
2076
  }else {
2065
- className += " break-all ";
2077
+ className += " break-words ";
2066
2078
  }
2067
2079
  let columnItem;
2068
2080
  if((field.is_name || field.name === options.labelFieldName) && options.objectName === 'cms_files'){
@@ -2159,12 +2171,24 @@ async function getTableColumns(fields, options){
2159
2171
  if(field.type === 'textarea'){
2160
2172
  className += 'min-w-56';
2161
2173
  }
2162
- if(field.type === 'date'){
2163
- className += 'date-min-w';
2164
- }
2165
- if(field.type === 'datetime'){
2166
- className += 'datetime-min-w';
2174
+ // if(field.type === 'date'){
2175
+ // className += 'date-min-w';
2176
+ // }
2177
+ // if(field.type === 'datetime'){
2178
+ // className += 'datetime-min-w';
2179
+ // }
2180
+
2181
+ //field上的amis属性里的clssname需要单独判断类型合并
2182
+ if (typeof field.amis?.className == "object") {
2183
+ className = {
2184
+ [className]: "true",
2185
+ ...field.amis.className
2186
+ };
2187
+ } else if (typeof field.amis?.className == "string") {
2188
+ className = `${className} ${field.amis.className} `;
2167
2189
  }
2190
+ delete field.amis?.className;
2191
+
2168
2192
  if(!field.hidden && !field.extra){
2169
2193
  columnItem = Object.assign({}, {
2170
2194
  name: field.name,
@@ -2247,7 +2271,7 @@ function getMobileLines(tpls){
2247
2271
  }
2248
2272
  if(isLeft){
2249
2273
  // 左侧半行
2250
- lineChildrenClassName = "steedos-listview-item-left truncate";
2274
+ lineChildrenClassName = "steedos-listview-item-left truncate h-5";
2251
2275
  if(item.field.is_wide){
2252
2276
  // 左侧全行样式可以单独写,如果需要配置两行省略号效果,可以加样式类 two-lines-truncate
2253
2277
  lineChildrenClassName = "steedos-listview-item-wide";
@@ -2259,14 +2283,26 @@ function getMobileLines(tpls){
2259
2283
  }
2260
2284
  else {
2261
2285
  // 右侧半行,这里加样式类 flex flex-shrink-0,是为了省略号只显示在左半行,右半行文字一般比较短,如果也加省略号效果的话,左侧文字多的话,右侧没几个字就显示省略号了
2262
- lineChildrenClassName = "steedos-listview-item-right truncate ml-2 flex flex-shrink-0";
2286
+ lineChildrenClassName = "steedos-listview-item-right truncate ml-2 flex flex-shrink-0 h-5";
2287
+ }
2288
+ //支持字段amis属性配置classname,识别classname的类型,与原样式合并
2289
+ var className;
2290
+ if (typeof item.field.amis?.className == "object") {
2291
+ className = {
2292
+ [lineChildrenClassName]: "true",
2293
+ ...item.field.amis.className
2294
+ };
2295
+ } else if (typeof item.field.amis?.className == "string") {
2296
+ className = `${lineChildrenClassName} ${item.field.amis.className} `;
2297
+ } else {
2298
+ className = lineChildrenClassName;
2263
2299
  }
2264
2300
  lineChildren.push({
2265
2301
  "type": "tpl",
2266
2302
  "tpl": item.tpl,
2267
- "className": lineChildrenClassName
2303
+ className
2268
2304
  });
2269
-
2305
+
2270
2306
  if(item.field.is_wide){
2271
2307
  // 宽字段占整行
2272
2308
  isLeft = true;
@@ -2316,8 +2352,7 @@ async function getMobileTableColumns(fields, options){
2316
2352
  tpl = await getFieldTpl(field, options);
2317
2353
  }
2318
2354
  if(!tpl){
2319
- //qhd需求简易处理,加上raw以支持审批王名称字段通过颜色区分缓急,若之后手机端列表支持配置amis,则可以去掉
2320
- tpl = `\${${field.name} | raw}`;
2355
+ tpl = `\${${field.name}}`;
2321
2356
  }
2322
2357
  if(!field.hidden && !field.extra){
2323
2358
  tpls.push({ field, tpl });
@@ -2330,7 +2365,7 @@ async function getMobileTableColumns(fields, options){
2330
2365
 
2331
2366
  let column = {
2332
2367
  name: nameField.name,
2333
- label: nameField.label,
2368
+ label: options.displayAs == 'split' ? '' : nameField.label,
2334
2369
  sortable: nameField.sortable,
2335
2370
  type: "button",
2336
2371
  level: "link",
@@ -2359,7 +2394,15 @@ async function getMobileTableColumns(fields, options){
2359
2394
  "actions": [
2360
2395
  {
2361
2396
  "script": `
2362
- let cms_url = "/api/files/files/"+event.data.versions[0]+"?download=true"
2397
+ let cms_url = '';
2398
+ let value = event.data.versions[0];
2399
+ if(value){
2400
+ if(value.url){
2401
+ cms_url = value.url;
2402
+ }else{
2403
+ cms_url = "/api/files/files/"+value+"?download=true"
2404
+ }
2405
+ }
2363
2406
  Steedos.cordovaDownload(encodeURI(Steedos.absoluteUrl(cms_url)), event.data.name);
2364
2407
  `,
2365
2408
  "actionType": "custom"
@@ -2475,7 +2518,8 @@ async function getTableOperation(ctx){
2475
2518
  label: " ",
2476
2519
  fixed: 'right',
2477
2520
  labelClassName: 'text-center',
2478
- className: 'text-center steedos-listview-operation w-10',
2521
+ //TODO:目前3.6.3-patch.3版本中对于动态classname处理存在问题,简单处理固定列问题,等待amis解决crud的columns不支持动态classname的问题
2522
+ className: 'text-center steedos-listview-operation w-10 is-sticky is-sticky-right is-sticky-first-right',
2479
2523
  buttons: [
2480
2524
  {
2481
2525
  "type": "steedos-dropdown-button",
@@ -2571,7 +2615,7 @@ async function getTableSchema$1(fields, options){
2571
2615
  }
2572
2616
  return {
2573
2617
  mode: "cards",
2574
- perPageAvailable: [5, 10, 20, 50, 100, 500],
2618
+ perPageAvailable: [20, 50, 100, 500],
2575
2619
  name: "thelist",
2576
2620
  headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
2577
2621
  className: "",
@@ -2604,7 +2648,7 @@ async function getTableSchema$1(fields, options){
2604
2648
 
2605
2649
  return {
2606
2650
  mode: "table",
2607
- perPageAvailable: [5, 10, 20, 50, 100, 500],
2651
+ perPageAvailable: [20, 50, 100, 500],
2608
2652
  name: "thelist",
2609
2653
  headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
2610
2654
  className: "",
@@ -2990,6 +3034,16 @@ async function getTableApi(mainObject, fields, options){
2990
3034
  }
2991
3035
  // SteedosUI.getRef(api.body.$self.$scopeId)?.parent?.getComponentById(setDataToComponentId)?.setData({$count: payload.data.count})
2992
3036
  };
3037
+ let formFactor = "${options.formFactor}";
3038
+ if(formFactor !== "SMALL"){
3039
+ const listviewComponent = $(".steedos-object-listview .antd-Table-table");
3040
+ const firstListviewComponent = listviewComponent && listviewComponent[0];
3041
+ if(firstListviewComponent){
3042
+ setTimeout(()=>{
3043
+ firstListviewComponent.scrollIntoView();
3044
+ }, 600);
3045
+ }
3046
+ }
2993
3047
  ${options.adaptor || ''}
2994
3048
  return payload;
2995
3049
  `;
@@ -3101,12 +3155,21 @@ function getReadonlyFormAdaptor(object, fields, options){
3101
3155
  }
3102
3156
  payload.data = data;
3103
3157
  payload.data.__objectName = "${object.name}";
3104
- payload.data.__record = record;
3158
+ payload.data.record = record;
3159
+
3160
+ payload.data.NAME_FIELD_VALUE = record.${object.NAME_FIELD_KEY || 'name'};
3161
+ payload.data._master = {
3162
+ record: record,
3163
+ objectName: "${object.name}",
3164
+ recordId: record._id
3165
+ }
3105
3166
  window.postMessage(Object.assign({type: "record.loaded"}, {record: record}), "*")
3106
3167
  }
3107
3168
  if(payload.errors){
3108
3169
  payload.status = 2;
3109
3170
  payload.msg = payload.errors[0].message;
3171
+ }else{
3172
+ payload.data.recordLoaded = true;
3110
3173
  }
3111
3174
  ${options && options.initApiAdaptor || ''}
3112
3175
  return payload;
@@ -3249,7 +3312,7 @@ async function getEditFormInitApi(object, recordId, fields, options){
3249
3312
  cache: API_CACHE,
3250
3313
  requestAdaptor: `
3251
3314
  // 所有不想在network请求中发送的数据都应该从data中分离出来,data变量只需要留下query才需要发送出去
3252
- var { recordId, objectName, uiSchema, global, context, ...data} = api.data;
3315
+ var { recordId, objectName, uiSchema, global, context, _master, ...data} = api.data;
3253
3316
  if(!recordId){
3254
3317
  // 新建则不请求任何数据
3255
3318
  data.query = "{data:" + objectName + "(filters: " + JSON.stringify(["_id", "=", null]) + ", top: 1){_id}}";
@@ -3327,10 +3390,11 @@ async function getEditFormInitApi(object, recordId, fields, options){
3327
3390
  ...initialValues
3328
3391
  }
3329
3392
  ${options.initApiAdaptor || ''}
3393
+ // console.log('getEditFormInitApi======>', payload);
3330
3394
  return payload;
3331
3395
  `,
3332
3396
  responseData: {
3333
- initialValues: "$$",
3397
+ "&": "$$",
3334
3398
  editFormInited: true
3335
3399
  },
3336
3400
  data: data,
@@ -3369,6 +3433,18 @@ function getBatchDelete(objectName){
3369
3433
  return {
3370
3434
  method: 'post',
3371
3435
  url: getApi$2(),
3436
+ adaptor: `
3437
+ if(payload.errors){
3438
+ payload.data.deleteErrorMessage = [];
3439
+ payload.errors.forEach(function(error){
3440
+ let errorRecord = error.path.map(function (item) {
3441
+ return item.split('delete__')[1].to_float() + 1;
3442
+ }).toString();
3443
+ payload.data.deleteErrorMessage.push("第" + errorRecord + "条记录删除出现异常,报错信息为(" + (window.t ? window.t(error.message) : error.message) + ")");
3444
+ })
3445
+ }
3446
+ return payload;
3447
+ `,
3372
3448
  requestAdaptor: `
3373
3449
  var ids = api.data.ids.split(",");
3374
3450
  var deleteArray = [];
@@ -4163,7 +4239,7 @@ async function getListBody(fields, options){
4163
4239
 
4164
4240
  function getDefaultParams(options){
4165
4241
  return {
4166
- perPage: options.top || options.perPage || 10
4242
+ perPage: options.top || options.perPage || 20
4167
4243
  }
4168
4244
  }
4169
4245
 
@@ -4366,7 +4442,6 @@ const getSchema$5 = async (uiSchema, ctx) => {
4366
4442
  "objectApiName": "\${objectName}",
4367
4443
  "recordId": "",
4368
4444
  "mode": "edit",
4369
- "layout": "normal"
4370
4445
  };
4371
4446
 
4372
4447
  if (payload && payload.schema) {
@@ -5071,7 +5146,7 @@ const StandardButtons = {
5071
5146
  }
5072
5147
  };
5073
5148
 
5074
- const getGlobalData$1 = () => {
5149
+ const getGlobalData = () => {
5075
5150
  return {
5076
5151
  now: new Date(),
5077
5152
  };
@@ -5130,7 +5205,7 @@ const getButtonVisible = (button, ctx) => {
5130
5205
  button._visible,
5131
5206
  props.record,
5132
5207
  "#",
5133
- getGlobalData$1(),
5208
+ getGlobalData(),
5134
5209
  props.userSession
5135
5210
  );
5136
5211
  };
@@ -6508,6 +6583,48 @@ function getObjectListHeader$1(objectSchema, listViewName, ctx) {
6508
6583
  return headerSchema;
6509
6584
  }
6510
6585
 
6586
+ function getBackButtonSchema(){
6587
+ return {
6588
+ "type": "service",
6589
+ "onEvent": {
6590
+ "@history_paths.changed": {
6591
+ "actions": [
6592
+ {
6593
+ "actionType": "reload",
6594
+ // amis 3.6需要传入data来触发下面的window:historyPaths重新计算,此问题随机偶发,加上data后正常
6595
+ "data": {
6596
+ }
6597
+ }
6598
+ ]
6599
+ }
6600
+ },
6601
+ "body":[{
6602
+ "type": "button",
6603
+ "visibleOn": "${window:innerWidth > 768 && (window:historyPaths.length > 1 || window:historyPaths[0].params.record_id) && display !== 'split'}",
6604
+ "className":"flex mr-4",
6605
+ "onEvent": {
6606
+ "click": {
6607
+ "actions": [
6608
+ {
6609
+ "actionType": "custom",
6610
+ "script": "window.goBack()"
6611
+ }
6612
+ ]
6613
+ }
6614
+ },
6615
+ "body": [
6616
+ {
6617
+ "type": "steedos-icon",
6618
+ "category": "utility",
6619
+ "name": "back",
6620
+ "colorVariant": "default",
6621
+ "className": "slds-button_icon slds-global-header__icon w-4"
6622
+ }
6623
+ ]
6624
+ }]
6625
+ }
6626
+ }
6627
+
6511
6628
  /**
6512
6629
  * 记录详细界面顶部头amisSchema,也是标题面板组件的amisSchema
6513
6630
  * @param {*} objectSchema 对象UISchema
@@ -6516,11 +6633,21 @@ function getObjectListHeader$1(objectSchema, listViewName, ctx) {
6516
6633
  * @returns amisSchema
6517
6634
  */
6518
6635
  async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
6636
+ // console.log(`getObjectRecordDetailHeader====>`, options)
6519
6637
  const { showRecordTitle = true } = options || {};
6520
6638
  // console.log('getObjectRecordDetailHeader==>', objectSchema, recordId)
6521
6639
  const { name, label, icon, NAME_FIELD_KEY } = objectSchema;
6522
6640
 
6523
- let amisButtonsSchema = getObjectDetailButtonsSchemas(objectSchema, recordId, options);
6641
+ let amisButtonsSchema = [];
6642
+ if(options.showButtons != false){
6643
+ amisButtonsSchema = getObjectDetailButtonsSchemas(objectSchema, recordId, options);
6644
+ }
6645
+
6646
+ let backButtonsSchema = null;
6647
+
6648
+ if(options.showBackButton != false){
6649
+ backButtonsSchema = getBackButtonSchema();
6650
+ }
6524
6651
 
6525
6652
  // console.log(`getObjectRecordDetailHeader==>`, amisButtonsSchema)
6526
6653
 
@@ -6535,45 +6662,9 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
6535
6662
  "type": "grid",
6536
6663
  "columns": [
6537
6664
  {
6538
- "body": [{
6539
- "type": "service",
6540
- "onEvent": {
6541
- "@history_paths.changed": {
6542
- "actions": [
6543
- {
6544
- "actionType": "reload",
6545
- // amis 3.6需要传入data来触发下面的window:historyPaths重新计算,此问题随机偶发,加上data后正常
6546
- "data": {
6547
- }
6548
- }
6549
- ]
6550
- }
6551
- },
6552
- "body":[{
6553
- "type": "button",
6554
- "visibleOn": "${window:innerWidth > 768 && (window:historyPaths.length > 1 || window:historyPaths[0].params.record_id) && display !== 'split'}",
6555
- "className":"flex mr-4",
6556
- "onEvent": {
6557
- "click": {
6558
- "actions": [
6559
- {
6560
- "actionType": "custom",
6561
- "script": "window.goBack()"
6562
- }
6563
- ]
6564
- }
6565
- },
6566
- "body": [
6567
- {
6568
- "type": "steedos-icon",
6569
- "category": "utility",
6570
- "name": "back",
6571
- "colorVariant": "default",
6572
- "className": "slds-button_icon slds-global-header__icon w-4"
6573
- }
6574
- ]
6575
- }]
6576
- },{
6665
+ "body": [
6666
+ backButtonsSchema
6667
+ ,{
6577
6668
  "type": "tpl",
6578
6669
  "className": "block",
6579
6670
  // "tpl": `<img class='slds-icon slds-icon_container slds-icon-standard-${standardIcon}' src='\${context.rootUrl}/unpkg.com/@salesforce-ux/design-system/assets/icons/standard/${icon}.svg'>`
@@ -6594,8 +6685,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
6594
6685
  },
6595
6686
  {
6596
6687
  "type": "tpl",
6597
- "tpl": "${name}",
6598
- // "tpl": "${(record && uiSchema && record[uiSchema.NAME_FIELD_KEY]) || name}",
6688
+ "tpl": "${NAME_FIELD_VALUE}",
6599
6689
  "inline": false,
6600
6690
  "wrapperComponent": "",
6601
6691
  "className": "record-detail-header-name leading-5 text-xl font-bold"
@@ -6623,7 +6713,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
6623
6713
  let body = [
6624
6714
  {
6625
6715
  "type": "wrapper",
6626
- "className": "p-0",
6716
+ "className": "p-4 bg-gray-100 border-b",
6627
6717
  "body": [
6628
6718
  {
6629
6719
  "type": "grid",
@@ -6638,7 +6728,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
6638
6728
  if(showRecordTitle){
6639
6729
  body.push({
6640
6730
  "type": "wrapper",
6641
- "className": "p-0",
6731
+ "className": "p-4",
6642
6732
  "body": [
6643
6733
  {
6644
6734
  "type": "grid",
@@ -6650,11 +6740,76 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
6650
6740
  });
6651
6741
  }
6652
6742
 
6743
+ let max = 10;
6744
+ if(options.formFactor === 'SMALL'){
6745
+ max = 4;
6746
+ }else {
6747
+
6748
+ let divWidth = window.innerWidth;
6749
+
6750
+ if(options.display === 'split'){
6751
+ divWidth = divWidth - 388;
6752
+ }
6753
+
6754
+ if(document.body.classList.contains('sidebar')){
6755
+ divWidth = divWidth - 210;
6756
+ }
6757
+
6758
+ // 根据屏幕宽度计算显示数量, 使高亮字段只占1行
6759
+ max = Math.trunc(divWidth / 200 );
6760
+ if(max > 10){
6761
+ max = 10;
6762
+ }
6763
+ }
6764
+
6765
+ // console.log('=======================max=========================', max)
6766
+
6767
+ if(objectSchema.compactLayouts){
6768
+ const details = [];
6769
+ _.each(_.slice(_.difference(objectSchema.compactLayouts, [objectSchema.NAME_FIELD_KEY]), 0, max), (fieldName)=>{
6770
+ const field = objectSchema.fields[fieldName];
6771
+ if(field){
6772
+ details.push({
6773
+ type: 'steedos-field',
6774
+ static: true,
6775
+ config: field,
6776
+ });
6777
+ }
6778
+ });
6779
+
6780
+ // 注意: 以下注释不能删除. tailwind css 动态编译时会识别以下注释, 生成对应的样式
6781
+ // lg:grid-cols-1
6782
+ // lg:grid-cols-2
6783
+ // lg:grid-cols-3
6784
+ // lg:grid-cols-4
6785
+ // lg:grid-cols-5
6786
+ // lg:grid-cols-6
6787
+ // lg:grid-cols-7
6788
+ // lg:grid-cols-8
6789
+ // lg:grid-cols-9
6790
+ // lg:grid-cols-10
6791
+ // lg:grid-cols-11
6792
+ // lg:grid-cols-12
6793
+
6794
+ body.push({
6795
+ "type": "wrapper",
6796
+ "body": {
6797
+ "type": "form",
6798
+ // "className": "gap-2 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-5 3xl:grid-cols-8 4xl:grid-cols-8 5xl:grid-cols-10", //max-h-12 overflow-hidden
6799
+ "className": `gap-2 grid grid-cols-1 lg:grid-cols-${max}`,
6800
+ "wrapWithPanel": false,
6801
+ "actions": [],
6802
+ "body": details,
6803
+ "hiddenOn": "${recordLoaded != true}"
6804
+ },
6805
+ "className": "steedos-record-compact-layouts p-4 bg-white compact-layouts border-b"
6806
+ });
6807
+ }
6808
+
6653
6809
  return {
6654
6810
  type: 'service',
6655
6811
  id: `page_readonly_${name}_header`,
6656
6812
  name: `page`,
6657
- data: { objectName: name, _id: recordId, recordPermissions: objectSchema.permissions, uiSchema: objectSchema, record: "${record}" },
6658
6813
  body: body,
6659
6814
  className: ''
6660
6815
  }
@@ -6726,7 +6881,7 @@ async function getObjectRecordDetailRelatedListHeader(relatedObjectSchema, relat
6726
6881
  "className": "flex justify-between"
6727
6882
  }
6728
6883
  ],
6729
- "className": "p-3"
6884
+ "className": "steedos-record-related-header py-2 px-0"
6730
6885
  };
6731
6886
  return recordRelatedListHeader;
6732
6887
  }
@@ -7711,14 +7866,14 @@ const getDisplayAsButton = function(objectName, showDisplayAs){
7711
7866
  {
7712
7867
  "type": "button",
7713
7868
  "label": i18next.t('frontend_display_type_is_table'),
7714
- "onClick": "const key = 'tab_"+objectName+"_display';localStorage.setItem(key, 'grid');let url = document.location.pathname; var urlSearch = new URLSearchParams(document.location.search); if(urlSearch.get(\"side_object\") && urlSearch.get(\"side_listview_id\")){url=`/app/${props.data.appId}/${urlSearch.get(\"side_object\")}/grid/${urlSearch.get(\"side_listview_id\")}`;}; props.env.jumpTo(url + '?display=grid');",
7869
+ "onClick": "const key = 'tab_"+objectName+"_display';sessionStorage.setItem(key, 'grid');let url = document.location.pathname; var urlSearch = new URLSearchParams(document.location.search); if(urlSearch.get(\"side_object\") && urlSearch.get(\"side_listview_id\")){url=`/app/${props.data.appId}/${urlSearch.get(\"side_object\")}/grid/${urlSearch.get(\"side_listview_id\")}`;}; props.env.jumpTo(url + '?display=grid');",
7715
7870
  "rightIcon": displayAs != 'split' ? "fa fa-check" : null,
7716
7871
  "rightIconClassName": "m-l-sm"
7717
7872
  },
7718
7873
  {
7719
7874
  "type": "button",
7720
7875
  "label": i18next.t('frontend_display_type_is_split'),
7721
- "onClick": "const key = 'tab_"+objectName+"_display';localStorage.setItem(key, 'split');const url = document.location.pathname + '?display=split'; props.env.jumpTo(url);",
7876
+ "onClick": "const key = 'tab_"+objectName+"_display';sessionStorage.setItem(key, 'split');const url = document.location.pathname + '?display=split'; props.env.jumpTo(url);",
7722
7877
  "rightIcon": displayAs === 'split' ? "fa fa-check" : null,
7723
7878
  "rightIconClassName": "m-l-sm"
7724
7879
  }
@@ -7861,7 +8016,7 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
7861
8016
  {
7862
8017
  "type": "search-box",
7863
8018
  "name": keywordsSearchBoxName,
7864
- "placeholder": "搜索此列表",
8019
+ "placeholder": "快捷搜索",
7865
8020
  "value": crudKeywords,
7866
8021
  // "clearable": true,//因为清除并不会触发失去焦点事件,只有禁用,但是它会触发change事件,所以等升级到amis 3.4+后可以重新放开
7867
8022
  "clearAndSubmit": true,
@@ -8065,7 +8220,10 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
8065
8220
  // ]
8066
8221
  if(options.displayAs === 'split'){
8067
8222
  return [
8068
- "switch-per-page",
8223
+ {
8224
+ "type": "switch-per-page",
8225
+ "visibleOn": "${count >= 20}"
8226
+ },
8069
8227
  {
8070
8228
  "type": "pagination",
8071
8229
  "maxButtons": 5,
@@ -8087,7 +8245,6 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
8087
8245
  else {
8088
8246
  if(options && options.isRelated){
8089
8247
  return [
8090
- "statistics",
8091
8248
  {
8092
8249
  "type": "pagination",
8093
8250
  "maxButtons": 10,
@@ -8100,7 +8257,6 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
8100
8257
  const no_pagination = mainObject.paging && (mainObject.paging.enabled === false);
8101
8258
  const is_lookup = options.isLookup;
8102
8259
  const commonConfig = [
8103
- "statistics",
8104
8260
  {
8105
8261
  "type": "pagination",
8106
8262
  "maxButtons": 10,
@@ -8111,7 +8267,10 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
8111
8267
  if (no_pagination && is_lookup) {
8112
8268
  return commonConfig;
8113
8269
  } else {
8114
- return ["switch-per-page", ...commonConfig];
8270
+ return [{
8271
+ "type": "switch-per-page",
8272
+ "visibleOn": "${count >= 20}"
8273
+ }, ...commonConfig];
8115
8274
  }
8116
8275
  }
8117
8276
  }
@@ -8219,6 +8378,29 @@ function getBulkActions(objectSchema){
8219
8378
  "className": "hidden",
8220
8379
  "id": "batchDelete",
8221
8380
  "api": getBatchDelete(objectSchema.name),
8381
+ "feedback": {
8382
+ "title": "删除警告",
8383
+ "visibleOn": "${deleteErrorMessage}",
8384
+ "body": [
8385
+ {
8386
+ "type": "each",
8387
+ "name": "deleteErrorMessage",
8388
+ "items": {
8389
+ "type": "alert",
8390
+ "body": "${item}",
8391
+ "level": "danger",
8392
+ "className": "mb-3"
8393
+ }
8394
+ }
8395
+ ],
8396
+ "actions": [
8397
+ {
8398
+ "type": "button",
8399
+ "actionType": "close",
8400
+ "label": "关闭"
8401
+ }
8402
+ ]
8403
+ }
8222
8404
  }
8223
8405
  // {
8224
8406
  // "label": "批量修改",
@@ -8365,6 +8547,10 @@ async function getObjectCRUD(objectSchema, fields, options){
8365
8547
  const rowsDiff = _.cloneDeep(api.data.rowsDiff);
8366
8548
  rowsDiff.forEach(function (item, index) {
8367
8549
  for(key in item){
8550
+ // image、select等字段清空值后保存的空字符串转换为null。
8551
+ if(item[key] === ''){
8552
+ item[key] = null;
8553
+ }
8368
8554
  if(_.includes(imageNames, key)){
8369
8555
  if(typeof item[key] == "string"){
8370
8556
  const match = item[key].match(/\\/([^\\/]+)$/);
@@ -8411,7 +8597,7 @@ async function getObjectCRUD(objectSchema, fields, options){
8411
8597
  // "is-steedos-crud-data-empty": "${!items || COUNT(items) == 0}"
8412
8598
  // },
8413
8599
  bodyClassName: {
8414
- "bg-white": "true",
8600
+ "mb-0": true,
8415
8601
  "is-steedos-crud-data-empty": "${!items || COUNT(items) == 0}"
8416
8602
  },
8417
8603
  crudClassName: crudClassName,
@@ -8431,7 +8617,9 @@ async function getObjectCRUD(objectSchema, fields, options){
8431
8617
  return payload;
8432
8618
  `
8433
8619
  },
8434
- rowClassNameExpr: options.rowClassNameExpr
8620
+ // 外层data发生变化的时候, 不会重新渲染rowClassNameExpr, 所以先用css标记tr唯一标识
8621
+ // 使用表达式给tr添加初始选中状态
8622
+ rowClassNameExpr: options.rowClassNameExpr || "<%= data._id === data.recordId ? 'steedos-record-tr steedos-record-tr-' + data._id + ' steedos-record-selected' : 'steedos-record-tr steedos-record-tr-' + data._id %>"
8435
8623
  }, bodyProps);
8436
8624
 
8437
8625
  }
@@ -8446,7 +8634,7 @@ async function getObjectCRUD(objectSchema, fields, options){
8446
8634
 
8447
8635
  if(body.columns && options.formFactor != 'SMALL'){
8448
8636
  //将_display放入crud的columns的倒数第二列中(最后一列会影响固定列),可以通过setvalue修改行内数据域的_display,而不影响上层items的_display,用于批量编辑
8449
- body.columns.splice(body.columns.length - 1, 0, {name: '_display',type: 'static', width: 32, placeholder: "",id: objectSchema.name + "_display_${_index}", className: "hidden"});
8637
+ body.columns.splice(body.columns.length -1 , 0, {name: '_display',type: 'static', width: 1, placeholder: "",id: objectSchema.name + "_display_${_index}", tpl: "${''}"});
8450
8638
  }
8451
8639
 
8452
8640
  if (defaults) {
@@ -8504,11 +8692,6 @@ async function getObjectCRUD(objectSchema, fields, options){
8504
8692
  }
8505
8693
  }
8506
8694
 
8507
- const getGlobalData = (mode)=>{
8508
- const user = getSteedosAuth();
8509
- return {mode: mode, user: user, spaceId: user.spaceId, userId: user.userId}
8510
- };
8511
-
8512
8695
  const getFormFields$1 = (objectSchema, formProps)=>{
8513
8696
  /**
8514
8697
  * fieldsExtend: 重写字段定义
@@ -8570,7 +8753,7 @@ async function getFormSchemaWithDataFilter(form, options = {}){
8570
8753
  }
8571
8754
 
8572
8755
  async function getObjectForm(objectSchema, ctx){
8573
- const { recordId, formFactor, layout = formFactor === 'SMALL' ? 'normal' : "normal", labelAlign, tabId, appId, defaults, submitSuccActions = [],
8756
+ const { recordId, formFactor, layout = formFactor === 'SMALL' ? 'normal' : "horizontal", labelAlign, tabId, appId, defaults, submitSuccActions = [],
8574
8757
  formDataFilter, onFormDataFilter, amisData, env } = ctx;
8575
8758
  const fields = ___default.values(objectSchema.fields);
8576
8759
  const formFields = getFormFields$1(objectSchema, ctx);
@@ -8586,9 +8769,7 @@ async function getObjectForm(objectSchema, ctx){
8586
8769
  id: `service_${formSchema.id}`,
8587
8770
  className: 'p-0',
8588
8771
  name: `page_edit_${recordId}`,
8589
- api: await getEditFormInitApi(objectSchema, recordId, fields, ctx),
8590
8772
  data:{
8591
- editFormInited: false,
8592
8773
  ...amisData
8593
8774
  },
8594
8775
  // data: {global: getGlobalData('edit'), recordId: recordId, objectName: objectSchema.name, context: {rootUrl: getRootUrl(), tenantId: getTenantId(), authToken: getAuthToken()}},
@@ -8597,8 +8778,9 @@ async function getObjectForm(objectSchema, ctx){
8597
8778
  body: [defaultsDeep({}, formSchema, {
8598
8779
  type: "form",
8599
8780
  mode: layout,
8781
+ initApi: await getEditFormInitApi(objectSchema, recordId, fields, ctx),
8600
8782
  data: {
8601
- "&": "${initialValues}"
8783
+ editFormInited: false,
8602
8784
  },
8603
8785
  labelAlign,
8604
8786
  persistData: false,
@@ -8612,11 +8794,15 @@ async function getObjectForm(objectSchema, ctx){
8612
8794
  submitText: "", // amis 表单不显示提交按钮, 表单提交由项目代码接管
8613
8795
  api: await getSaveApi(objectSchema, recordId, fields, ctx),
8614
8796
  initFetch: recordId != 'new',
8615
- body: await getFormBody(fields, formFields, Object.assign({}, ctx, {fieldGroups: objectSchema.field_groups})),
8797
+ body: {
8798
+ type: 'wrapper',
8799
+ className: 'p-0 m-0',
8800
+ body: await getFormBody(fields, formFields, Object.assign({}, ctx, {fieldGroups: objectSchema.field_groups})),
8801
+ hiddenOn: "${editFormInited != true}",
8802
+ },
8616
8803
  panelClassName:'m-0 sm:rounded-lg shadow-none border-none',
8617
8804
  bodyClassName: 'p-0',
8618
8805
  className: 'steedos-amis-form',
8619
- hiddenOn: "${editFormInited != true}",
8620
8806
  onEvent: {
8621
8807
  "submitSucc": {
8622
8808
  "weight": 0,
@@ -8661,7 +8847,7 @@ async function getObjectForm(objectSchema, ctx){
8661
8847
  }
8662
8848
 
8663
8849
  async function getObjectDetail(objectSchema, recordId, ctx){
8664
- const { formFactor, layout = formFactor === 'SMALL' ? 'normal' : "normal", labelAlign,
8850
+ const { formFactor, layout = formFactor === 'SMALL' ? 'normal' : "horizontal", labelAlign,
8665
8851
  formDataFilter, onFormDataFilter, amisData, env } = ctx;
8666
8852
  const fields = ___default.values(objectSchema.fields);
8667
8853
  const formFields = getFormFields$1(objectSchema, ctx);
@@ -8670,8 +8856,7 @@ async function getObjectDetail(objectSchema, recordId, ctx){
8670
8856
  type: 'service',
8671
8857
  name: `page_readonly_${recordId}`,
8672
8858
  id: serviceId,
8673
- data: {global: getGlobalData('read'), context: {rootUrl: getRootUrl(), tenantId: getTenantId(), authToken: getAuthToken()}},
8674
- api: await getReadonlyFormInitApi(objectSchema, recordId, fields, ctx),
8859
+ // api: await getReadonlyFormInitApi(objectSchema, recordId, fields, ctx),
8675
8860
  body: [
8676
8861
  {
8677
8862
  "type": "wrapper", //form 的 hiddenOn 会导致 form onEvent 异常, 使用wrapper包裹一次form,并在wrapper上控制显隐
@@ -8697,60 +8882,41 @@ async function getObjectDetail(objectSchema, recordId, ctx){
8697
8882
  ),
8698
8883
  className: 'steedos-amis-form bg-white',
8699
8884
  actions: [], // 不显示表单默认的提交按钮
8700
- onEvent: {
8701
- [`@data.changed.${objectSchema.name}`]: { // 由于amis service 组件的 onEvent 存在bug ,此处借助form来刷新 上层 service https://github.com/baidu/amis/issues/6294
8702
- "actions": [
8703
- {
8704
- "actionType": "reload",
8705
- "componentId": serviceId,
8706
- "expression": "this.__deletedRecord != true"
8707
- },
8708
- {
8709
- // "args": {
8710
- // "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
8711
- // "blank": false
8712
- // },
8713
- "actionType": "custom",
8714
- "script": "window.goBack()",
8715
- "expression": "this.__deletedRecord === true"
8716
- }
8717
- ]
8718
- }
8719
- }
8720
8885
  },
8721
8886
  }
8722
8887
  ],
8723
- onEvent: {
8724
- "fetchInited": {
8725
- "weight": 0,
8726
- "actions": [
8727
- {
8728
- actionType: 'broadcast',
8729
- eventName: "recordLoaded",
8730
- args: {
8731
- eventName: "recordLoaded"
8732
- },
8733
- data: {
8734
- objectName: "${event.data.__objectName}",
8735
- record: "${event.data.__record}"
8736
- },
8737
- expression: "${event.data.__response.error != true}"
8738
- },
8739
- {
8740
- "actionType": "setValue",
8741
- "args": {
8742
- value: {
8743
- "recordLoaded": true,
8744
- }
8745
- },
8746
- expression: "${event.data.__response.error != true}"
8747
- }
8748
- ]
8749
- }
8750
- }
8888
+ // onEvent: {
8889
+ // "fetchInited": {
8890
+ // "weight": 0,
8891
+ // "actions": [
8892
+ // {
8893
+ // actionType: 'broadcast',
8894
+ // eventName: "recordLoaded",
8895
+ // args: {
8896
+ // eventName: "recordLoaded"
8897
+ // },
8898
+ // data: {
8899
+ // objectName: "${event.data.__objectName}",
8900
+ // record: "${event.data.__record}"
8901
+ // },
8902
+ // expression: "${event.data.__response.error != true}"
8903
+ // },
8904
+ // {
8905
+ // "actionType": "setValue",
8906
+ // "args": {
8907
+ // value: {
8908
+ // "recordLoaded": true,
8909
+ // }
8910
+ // },
8911
+ // expression: "${event.data.__response.error != true}"
8912
+ // }
8913
+ // ]
8914
+ // }
8915
+ // }
8751
8916
  };
8752
8917
 
8753
8918
  amisSchema.body[0].body = await getFormSchemaWithDataFilter(amisSchema.body[0].body, { formDataFilter, onFormDataFilter, amisData, env });
8919
+ // console.log('getObjectDetail=====>', amisSchema);
8754
8920
  return amisSchema;
8755
8921
  }
8756
8922
 
@@ -8830,8 +8996,8 @@ const getRecordPermissions = async (objectName, recordId)=>{
8830
8996
  /*
8831
8997
  * @Author: baozhoutao@steedos.com
8832
8998
  * @Date: 2022-07-05 15:55:39
8833
- * @LastEditors: liaodaxue
8834
- * @LastEditTime: 2023-11-14 15:55:32
8999
+ * @LastEditors: baozhoutao@steedos.com
9000
+ * @LastEditTime: 2024-01-15 10:34:46
8835
9001
  * @Description:
8836
9002
  */
8837
9003
 
@@ -9006,7 +9172,7 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
9006
9172
  setDataToComponentId: componentId,
9007
9173
  // tableHiddenOn: hiddenEmptyTable ? "this.$count === 0" : null,
9008
9174
  appId: appId,
9009
- crudClassName: 'border-t border-gray-300 hidden',
9175
+ crudClassName: 'steedos-record-related-crud hidden',
9010
9176
  refField,
9011
9177
  ...ctx
9012
9178
  };
@@ -9019,7 +9185,7 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
9019
9185
  amisSchema: {
9020
9186
  type: "service",
9021
9187
  id: componentId,
9022
- className: `steedos-record-related-list ${componentId} rounded border border-gray-300 bg-gray-100 mb-4 ${className}`,
9188
+ className: `steedos-record-related-list py-2 first:pt-0 border-b last:border-b-0 ${componentId} ${className}`,
9023
9189
  data: {
9024
9190
  relatedKey: relatedKey,
9025
9191
  listViewId: `amis-\${appId}-${relatedObjectName}-listview`,
@@ -9211,11 +9377,44 @@ async function getRelatedListSchema(
9211
9377
  };
9212
9378
  }
9213
9379
 
9380
+ async function getObjectRelatedListsMiniSchema(objectApiName){
9381
+ const relatedLists = await getObjectRelatedList(objectApiName);
9382
+
9383
+ const relatedListsMiniSchema = [];
9384
+
9385
+ for (const relatedList of relatedLists) {
9386
+ relatedListsMiniSchema.push(
9387
+ {
9388
+ type: 'steedos-record-detail-list-mini',
9389
+ objectApiName: objectApiName,
9390
+ // recordId: recordId,
9391
+ formFactor: formFactor,
9392
+ relatedObjectApiName: relatedList.object_name,
9393
+ foreign_key: relatedList.foreign_key,
9394
+ relatedKey: relatedList.foreign_key,
9395
+ columns: relatedList.columns,
9396
+ sort: relatedList.sort,
9397
+ filters: relatedList.filters,
9398
+ visible_on: relatedList.visible_on,
9399
+ perPage: relatedList.page_size || perPage,
9400
+ hiddenEmptyTable: true,
9401
+ relatedLabel: relatedList.label
9402
+ }
9403
+ );
9404
+ }
9405
+
9406
+ return {
9407
+ type: 'wrapper',
9408
+ className: "steedos-record-detail-related-lists-mini",
9409
+ body: relatedListsMiniSchema
9410
+ }
9411
+ }
9412
+
9214
9413
  /*
9215
9414
  * @Author: baozhoutao@steedos.com
9216
9415
  * @Date: 2022-07-05 15:55:39
9217
- * @LastEditors: liaodaxue
9218
- * @LastEditTime: 2023-10-20 11:38:25
9416
+ * @LastEditors: baozhoutao@steedos.com
9417
+ * @LastEditTime: 2024-01-16 11:14:34
9219
9418
  * @Description:
9220
9419
  */
9221
9420
 
@@ -9387,7 +9586,7 @@ async function getField(objectName, fieldName) {
9387
9586
  async function getFormSchema(objectName, ctx) {
9388
9587
  const uiSchema = await getUISchema(objectName);
9389
9588
  const amisSchema = await getObjectForm(uiSchema, ctx);
9390
- console.log(`getFormSchema====>`, amisSchema);
9589
+ // console.log(`getFormSchema====>`, amisSchema)
9391
9590
  return {
9392
9591
  uiSchema,
9393
9592
  amisSchema,
@@ -9713,110 +9912,164 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
9713
9912
  "label": "对象表单",
9714
9913
  "objectApiName": "${objectName}",
9715
9914
  "recordId": "${recordId}",
9716
- "id": "u:d4a495811d57",
9717
9915
  appId: appId
9718
9916
  }
9719
9917
  ],
9720
- "id": "u:5d4e7e3f6ecc"
9721
9918
  };
9722
9919
  const related = {
9723
9920
  "title": i18next.t('frontend_record_detail_tab_related'),
9724
- "className": "px-0 pt-4",
9921
+ "className": "px-0 py-4",
9725
9922
  "body": [
9726
9923
  {
9727
9924
  "type": "steedos-object-related-lists",
9728
9925
  "label": "相关列表",
9729
9926
  "objectApiName": "${objectName}",
9730
9927
  "recordId": "${recordId}",
9731
- "id": "u:3b85b7b7a7f6",
9732
9928
  appId: appId
9733
9929
  }
9734
9930
  ],
9735
- "id": "u:1a0326aeec2b"
9736
9931
  };
9737
9932
  const content = {
9738
9933
  "type": "tabs",
9739
- "className": "sm:mt-3 bg-white sm:rounded sm:border border-gray-300 p-4",
9934
+ "className": "steedos-record-tabs bg-white p-4 m-0 mt-2 border-y",
9935
+ "contentClassName": "bg-none",
9740
9936
  "tabs": [
9741
9937
  detailed
9742
9938
  ],
9743
- "id": "u:a649e4094a12"
9744
9939
  };
9745
9940
  if(relatedLists.length){
9746
9941
  content.tabs.push(related);
9747
9942
  }
9943
+ // content.tabs = reverse(content.tabs)
9748
9944
  return {
9749
9945
  uiSchema,
9750
9946
  amisSchema: {
9751
- "type": "service",
9947
+ "type": "steedos-record-service",
9752
9948
  "body": [
9753
9949
  {
9754
9950
  "type": "steedos-record-detail-header",
9755
9951
  "label": "标题面板",
9756
9952
  "objectApiName": "${objectName}",
9757
9953
  "recordId": "${recordId}",
9758
- "id": "u:48d2c28eb755"
9954
+ "id": "u:48d2c28eb755",
9955
+ "showButtons": props.showButtons,
9956
+ "showBackButton": props.showBackButton,
9759
9957
  },
9760
9958
  content
9761
9959
  ],
9762
- data: {
9763
- "_master.objectName": "${objectName}",
9764
- "_master.recordId": "${recordId}"
9765
- },
9766
- onEvent: {
9767
- "recordLoaded": {
9768
- "actions": [
9769
- {
9770
- "actionType": "reload",
9771
- "data": {
9772
- "name": `\${record.${uiSchema.NAME_FIELD_KEY || 'name'}}`,
9773
- "_master.record": `\${record}`,
9774
- // 不清楚reload 如何给对象下的某个key复制, 所以此处重复设置_master的objectName、recordId
9775
- "_master.objectName": "${objectName}",
9776
- "_master.recordId": "${recordId}"
9777
- }
9778
- }
9779
- ]
9780
- },
9781
- ...props.onEvent
9782
- },
9960
+ "objectApiName": "${objectName}",
9961
+ "recordId": "${recordId}",
9962
+ onEvent: props.onEvent,
9783
9963
  }
9784
9964
  }
9785
9965
  }
9786
9966
 
9787
- async function getRecordServiceSchema(objectName, appId, props = {}) {
9967
+ async function getRecordServiceSchema(objectName, appId, props = {}, body) {
9788
9968
  const uiSchema = await getUISchema(objectName);
9969
+ const fields = ___default.values(uiSchema.fields);
9970
+ const serviceId = `u:steedos-record-service-${objectName}`;
9789
9971
  return {
9790
9972
  uiSchema,
9791
9973
  amisSchema: {
9792
- "type": "service",
9793
- "body": [],
9794
- data: {
9795
- "_master.objectName": "${objectName}",
9796
- "_master.recordId": "${recordId}"
9797
- },
9798
- "style": {
9799
- "padding": "var(--Page-body-padding)",
9800
- ...props.style
9801
- },
9974
+ type: 'service',
9975
+ className: "p-0 m-0",
9802
9976
  onEvent: {
9803
- "recordLoaded": {
9977
+ [`@data.changed.${objectName}`]: {
9804
9978
  "actions": [
9805
9979
  {
9806
9980
  "actionType": "reload",
9807
- "data": {
9808
- "name": `\${record.${uiSchema.NAME_FIELD_KEY || 'name'}}`,
9809
- "_master.record": `\${record}`,
9810
- // 不清楚reload 如何给对象下的某个key复制, 所以此处重复设置_master的objectName、recordId
9811
- "_master.objectName": "${objectName}",
9812
- "_master.recordId": "${recordId}"
9813
- }
9981
+ "componentId": serviceId,
9982
+ "expression": "this.__deletedRecord != true"
9983
+ },
9984
+ {
9985
+ "actionType": "custom",
9986
+ "script": "window.goBack()",
9987
+ "expression": "this.__deletedRecord === true"
9814
9988
  }
9815
9989
  ]
9816
9990
  },
9817
- ...props.onEvent
9991
+ },
9992
+ body: {
9993
+ "type": "service",
9994
+ id: serviceId,
9995
+ className: 'steedos-record-service p-0',
9996
+ api: await getReadonlyFormInitApi(uiSchema, props.recordId, fields, props),
9997
+ body: {
9998
+ "type": "wrapper",
9999
+ "className": "p-0 m-0",
10000
+ "body": body || [],
10001
+ "hiddenOn": "${recordLoaded != true}"
10002
+ },
10003
+ data: {
10004
+ "_master.objectName": "${objectName}",
10005
+ "_master.recordId": "${recordId}",
10006
+ ...(props.data || {})
10007
+ },
10008
+ "style": {
10009
+ // "padding": "var(--Page-body-padding)",
10010
+ ...props.style
10011
+ },
10012
+ onEvent: {
10013
+ // 如果定义了fetchInited,则无法接收到广播事件@data.changed
10014
+ "fetchInited": {
10015
+ "weight": 0,
10016
+ "actions": [
10017
+ {
10018
+ actionType: 'broadcast',
10019
+ eventName: "recordLoaded",
10020
+ data: {
10021
+ objectName: "${event.data.__objectName}",
10022
+ record: "${event.data.record}"
10023
+ },
10024
+ expression: "${event.data.__response.error != true}"
10025
+ },
10026
+ ]
10027
+ },
10028
+ ...props.onEvent
10029
+ }
9818
10030
  }
9819
10031
  }
10032
+
10033
+
10034
+ }
10035
+ }
10036
+
10037
+ async function getRecordDetailMiniSchema(objectName, appId, props = {}){
10038
+ const uiSchema = await getUISchema(objectName);
10039
+ const fields = ___default.values(uiSchema.fields);
10040
+
10041
+ props.initApiAdaptor = 'payload.data=Object.assign({}, payload.data, payload.data.record); payload.data._finished=true; console.log("payload data is ====>", payload)';
10042
+
10043
+ // TODO 处理相关表
10044
+ // getObjectRelatedListsMiniSchema
10045
+
10046
+ return {
10047
+ type: "form",
10048
+ wrapWithPanel: false,
10049
+ actions: [],
10050
+ initApi: await getReadonlyFormInitApi(uiSchema, props.recordId, fields, props),
10051
+ body: {
10052
+ "type": "wrapper",
10053
+ "className": "p-0 m-0",
10054
+ "body": [
10055
+ {
10056
+ "type": "steedos-record-detail-header",
10057
+ "showButtons": false,
10058
+ "showBackButton": false,
10059
+ "objectApiName": "${objectName}",
10060
+ "recordId": "${recordId}",
10061
+ },
10062
+ // {
10063
+ // "type": "steedos-object-related-lists",
10064
+ // "label": "相关列表",
10065
+ // "objectApiName": "${objectName}",
10066
+ // "staticRecordId": "${recordId}",
10067
+ // formFactor: "SMALL",
10068
+ // appId: appId
10069
+ // }
10070
+ ],
10071
+ "hiddenOn": "${_finished != true}"
10072
+ }
9820
10073
  }
9821
10074
  }
9822
10075
 
@@ -10757,9 +11010,11 @@ async function lookupToAmisPicker(field, readonly, ctx){
10757
11010
  */
10758
11011
  if(enable_tree){
10759
11012
  const rows = _.map(payload.data.rows, (item)=>{
10760
- delete item.children;
10761
- delete item.parent;
10762
- return item;
11013
+ if (!item.children) {
11014
+ return { ...item, children: [] };
11015
+ } else {
11016
+ return item;
11017
+ }
10763
11018
  })
10764
11019
  payload.data.rows = rows;
10765
11020
  }
@@ -11208,9 +11463,17 @@ async function lookupToAmis(field, readonly, ctx){
11208
11463
  }
11209
11464
  // console.log(`lookupToAmis====`, field, readonly, ctx)
11210
11465
  if(readonly){
11211
- return {
11212
- type: getAmisStaticFieldType('picker', readonly),
11213
- tpl: getRelatedFieldTpl(field, ctx)
11466
+ if(field.reference_to){
11467
+ return {
11468
+ type: 'steedos-field',
11469
+ config: field,
11470
+ static: true
11471
+ }
11472
+ }else {
11473
+ return {
11474
+ type: getAmisStaticFieldType('picker', readonly),
11475
+ tpl: getRelatedFieldTpl(field, ctx)
11476
+ }
11214
11477
  }
11215
11478
  }
11216
11479
  if(field.reference_to && !_$1.isString(field.reference_to) && !readonly){
@@ -12204,11 +12467,9 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
12204
12467
  if(field.subFields){
12205
12468
  convertData = {
12206
12469
  type: 'steedos-input-table',
12207
- showIndex: true,
12208
12470
  editable: !readonly,
12209
12471
  addable: !readonly,
12210
12472
  removable: !readonly,
12211
- draggable: !readonly,
12212
12473
  fields: [],
12213
12474
  amis:{
12214
12475
  columnsTogglable: false
@@ -12260,7 +12521,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
12260
12521
  if(field.is_wide || convertData.type === 'group'){
12261
12522
  convertData.className = 'col-span-2 m-0';
12262
12523
  }else {
12263
- convertData.className = 'm-1';
12524
+ convertData.className = 'm-0';
12264
12525
  }
12265
12526
  if(readonly){
12266
12527
  convertData.className = `${convertData.className} border-b`;
@@ -12285,6 +12546,10 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
12285
12546
  }
12286
12547
  }
12287
12548
 
12549
+ if(ctx.amisData && ctx.amisData._master && ctx.amisData._master.relatedKey === field.name){
12550
+ convertData.className = `${convertData.className || ''} hidden`;
12551
+ }
12552
+
12288
12553
  if(_$1.isString(baseData.required)){
12289
12554
  if(baseData.required.startsWith("{{")){
12290
12555
  baseData.requiredOn = `${baseData.required.substring(2, baseData.required.length -2).replace(/formData./g, 'data.')}`;
@@ -12662,19 +12927,151 @@ async function getFormBody(permissionFields, formFields, ctx){
12662
12927
  return await getSections(permissionFields, formFields, ctx);
12663
12928
  }
12664
12929
 
12930
+ /*
12931
+ * @Author: 殷亮辉 yinlianghui@hotoa.com
12932
+ * @Date: 2024-01-18 15:12:41
12933
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12934
+ * @LastEditTime: 2024-01-18 15:12:49
12935
+ */
12936
+ /**
12937
+ * 生成符合标准uuid格式的36位满足唯一性的随机串
12938
+ * @returns uuid
12939
+ */
12940
+ function uuidv4() {
12941
+ return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
12942
+ (c ^ window.crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
12943
+ );
12944
+ }
12945
+
12665
12946
  /*
12666
12947
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12667
12948
  * @Date: 2023-11-15 09:50:22
12668
- * @LastEditors: liaodaxue
12669
- * @LastEditTime: 2024-01-09 18:12:28
12949
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12950
+ * @LastEditTime: 2024-01-21 23:40:13
12951
+ */
12952
+
12953
+ function getTablePrimaryKey(props){
12954
+ return props.primaryKey || "_id";
12955
+ }
12956
+
12957
+ /**
12958
+ * 子表组件字段值中每行数据的补上唯一标识字段值,其值为随机uuid
12959
+ * @param {*} value 子表组件字段值,数组
12960
+ * @param {*} primaryKey 主键字段名,一般为_id
12961
+ * @returns 转换后的子表组件字段值
12962
+ */
12963
+ function getTableValueWithPrimaryKeyValue(value, primaryKey){
12964
+ if(!primaryKey){
12965
+ return value;
12966
+ }
12967
+ return (value || []).map((itemValue)=>{
12968
+ //这里不clone的话,会造成在pipeIn函数执行该函数后像pipeOut一样最终输出到表单项中,即库里把primaryKey字段值保存了
12969
+ const newItemValue = clone(itemValue);
12970
+ if(newItemValue[primaryKey]){
12971
+ if(newItemValue.children){
12972
+ newItemValue.children = getTableValueWithPrimaryKeyValue(newItemValue.children, primaryKey);
12973
+ }
12974
+ return newItemValue;
12975
+ }
12976
+ else {
12977
+ newItemValue[primaryKey] = uuidv4();
12978
+ if(newItemValue.children){
12979
+ newItemValue.children = getTableValueWithPrimaryKeyValue(newItemValue.children, primaryKey);
12980
+ }
12981
+ return newItemValue;
12982
+ }
12983
+ });
12984
+ }
12985
+
12986
+ /**
12987
+ * 子表组件字段值中每行数据的移除唯一标识字段值,因为该字段值一般只作临时标记,不存库
12988
+ * @param {*} value 子表组件字段值,数组
12989
+ * @param {*} primaryKey 主键字段名,一般为_id
12990
+ * @returns 转换后的子表组件字段值
12991
+ */
12992
+ function getTableValueWithoutPrimaryKeyValue(value, primaryKey){
12993
+ if(!primaryKey){
12994
+ return value;
12995
+ }
12996
+ return (value || []).map((itemValue)=>{
12997
+ //这里clone只是为了保险,不是必须的,每次修改子表数据是否都会生成新的primaryKey字段值是由pipeOut中识别autoGeneratePrimaryKeyValue决定的,跟这里没关系
12998
+ const newItemValue = clone(itemValue);
12999
+ if(newItemValue.children){
13000
+ newItemValue.children = getTableValueWithoutPrimaryKeyValue(newItemValue.children, primaryKey);
13001
+ }
13002
+ delete newItemValue[primaryKey];
13003
+ return newItemValue;
13004
+ });
13005
+ }
13006
+
13007
+ /**
13008
+ * 子表组件字段值中每行数据的键值key移除指定前缀
13009
+ * @param {*} value 子表组件字段值,数组
13010
+ * @param {*} fieldPrefix 字段前缀
13011
+ * @returns 转换后的子表组件字段值
13012
+ */
13013
+ function getTableValueWithoutFieldPrefix(value, fieldPrefix){
13014
+ let convertedValue = [];
13015
+ (value || []).forEach((itemValue)=>{
13016
+ var newItemValue = {};
13017
+ for(let n in itemValue){
13018
+ if(itemValue.hasOwnProperty(n)){
13019
+ newItemValue[n.replace(new RegExp(`^${fieldPrefix}`), "")] = itemValue[n];
13020
+ }
13021
+ }
13022
+ convertedValue.push(newItemValue);
13023
+ });
13024
+ return convertedValue;
13025
+ }
13026
+
13027
+ /**
13028
+ * 子表组件字段值中每行数据的键值key补上指定前缀
13029
+ * @param {*} value 子表组件字段值,数组
13030
+ * @param {*} fieldPrefix 字段前缀
13031
+ * @returns 转换后的子表组件字段值
13032
+ */
13033
+ function getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey){
13034
+ let convertedValue = [];
13035
+ (value || []).forEach((itemValue)=>{
13036
+ var newItemValue = {};
13037
+ for(let n in itemValue){
13038
+ if(itemValue.hasOwnProperty(n) && typeof itemValue[n] !== undefined && n !== primaryKey){
13039
+ newItemValue[`${fieldPrefix}${n}`] = itemValue[n];
13040
+ }
13041
+ }
13042
+ if(primaryKey && itemValue[primaryKey]){
13043
+ newItemValue[primaryKey] = itemValue[primaryKey];
13044
+ }
13045
+ convertedValue.push(newItemValue);
13046
+ });
13047
+ return convertedValue;
13048
+ }
13049
+
13050
+ /**
13051
+ * 子表组件字段集合属性中每个字段name移除指定前缀
13052
+ * @param {*} fields 子表组件字段集合,数组
13053
+ * @param {*} fieldPrefix 字段前缀
13054
+ * @returns 转换后的子表组件字段值
12670
13055
  */
13056
+ function getTableFieldsWithoutFieldPrefix(fields, fieldPrefix){
13057
+ return (fields || []).map((item) => {
13058
+ const newItem = clone(item);//这里不clone的话,会造成子表组件重新render,从而审批王那边点开子表行编辑窗口时报错
13059
+ newItem.name = newItem.name.replace(new RegExp(`^${fieldPrefix}`), "");
13060
+ return newItem;
13061
+ });
13062
+ }
12671
13063
 
12672
13064
  /**
12673
13065
  * @param {*} props
12674
13066
  * @param {*} mode edit/new/readonly
12675
13067
  */
12676
13068
  function getFormFields(props, mode = "edit") {
12677
- return (props.fields || []).map(function (item) {
13069
+ let fieldPrefix = props.fieldPrefix;
13070
+ let fields = props.fields || [];
13071
+ if (fieldPrefix) {
13072
+ fields = getTableFieldsWithoutFieldPrefix(fields, fieldPrefix);
13073
+ }
13074
+ return (fields || []).map(function (item) {
12678
13075
  let formItem = {
12679
13076
  "type": "steedos-field",
12680
13077
  "name": item.name,
@@ -12746,7 +13143,12 @@ async function getInputTableColumns(props) {
12746
13143
  let inlineEditMode = props.inlineEditMode;
12747
13144
  let showAsInlineEditMode = inlineEditMode && props.editable;
12748
13145
  // 实测过,直接不生成对应的隐藏column并不会对input-table值造成丢失问题,隐藏的列字段值能正常维护
12749
- let fields = props.fields;
13146
+
13147
+ let fieldPrefix = props.fieldPrefix;
13148
+ let fields = props.fields || [];
13149
+ if (fieldPrefix) {
13150
+ fields = getTableFieldsWithoutFieldPrefix(fields, fieldPrefix);
13151
+ }
12750
13152
  if (columns && columns.length) {
12751
13153
  return columns.map(function (column) {
12752
13154
  let field, extendColumnProps = {};
@@ -12815,7 +13217,21 @@ function getFormPagination(props, mode) {
12815
13217
  let currentIndex = event.data.index;
12816
13218
  // 翻页到下一页之前需要先把当前页改动的内容保存到中间变量__tableItems中
12817
13219
  let currentFormValues = scope.getComponentById(__formId).getValues();
12818
- fieldValue[currentIndex] = currentFormValues;
13220
+ // 这里不clone的话,其值会带上__super属性
13221
+ currentFormValues = _.clone(currentFormValues);
13222
+ var parent = event.data.parent;
13223
+ var __parentIndex = event.data.__parentIndex;
13224
+ if(parent){
13225
+ fieldValue[__parentIndex].children[currentIndex] = currentFormValues;
13226
+ // 重写父节点,并且改变其某个属性以让子节点修改的内容回显到界面上
13227
+ fieldValue[__parentIndex] = Object.assign({}, fieldValue[__parentIndex], {
13228
+ children: fieldValue[__parentIndex].children,
13229
+ __fix_rerender_after_children_modified_tag: new Date().getTime()
13230
+ });
13231
+ }
13232
+ else{
13233
+ fieldValue[currentIndex] = currentFormValues;
13234
+ }
12819
13235
  // 翻页到下一页前需要同时把改动的内容保存到最终正式的表单字段中,所以额外给正式表单字段执行一次setValue
12820
13236
  doAction({
12821
13237
  "componentId": "${props.id}",
@@ -12882,7 +13298,8 @@ function getFormPagination(props, mode) {
12882
13298
  },
12883
13299
  {
12884
13300
  "type": "tpl",
12885
- "tpl": "${__page}/${__tableItems.length}"
13301
+ // 这里用__super.parent,加__super是为了防止当前记录有字段名为parent的重名变量
13302
+ "tpl": "${__page}/${__super.parent ? __tableItems[__parentIndex]['children'].length : __tableItems.length}"
12886
13303
  },
12887
13304
  {
12888
13305
  "type": "button",
@@ -12890,7 +13307,9 @@ function getFormPagination(props, mode) {
12890
13307
  "icon": `fa fa-angle-right`,
12891
13308
  "level": "link",
12892
13309
  "pageChangeDirection": "next",
12893
- "disabledOn": showPagination ? "${__page >= __tableItems.length}" : "true",
13310
+ // "disabledOn": showPagination ? "${__page >= __tableItems.length}" : "true",
13311
+ // 这里用__super.parent,加__super是为了防止当前记录有字段名为parent的重名变量
13312
+ "disabledOn": showPagination ? "${__page >= (__super.parent ? __tableItems[__parentIndex]['children'].length : __tableItems.length)}" : "true",
12894
13313
  "size": "sm",
12895
13314
  "id": buttonNextId,
12896
13315
  "onEvent": {
@@ -12919,18 +13338,19 @@ function getFormPaginationWrapper(props, form, mode) {
12919
13338
  // console.log("==getFormPaginationWrapper===", props, mode);
12920
13339
  let serviceId = getComponentId("form_pagination", props.id);
12921
13340
  let tableServiceId = getComponentId("table_service", props.id);
13341
+ let primaryKey = getTablePrimaryKey(props);
12922
13342
  let innerForm = Object.assign({}, form, {
12923
13343
  "data": {
12924
13344
  // 这里加__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
12925
13345
  // 比如“对象字段”对象options字段是一个子表字段,但是主表(即“对象字段”对象)中正好有一个名为index的字段
12926
- "&": "${__tableItems[__super.index]}"
13346
+ "&": "${__super.parent ? __tableItems[__parentIndex]['children'][__super.index] : __tableItems[__super.index]}"
12927
13347
  }
12928
13348
  });
12929
13349
  let formBody = [
12930
13350
  {
12931
13351
  "type": "wrapper",
12932
13352
  "size": "none",
12933
- "className": "flex justify-end sticky top-0 right-0 left-0 z-20 bg-white -mt-2",
13353
+ "className": "flex justify-end sticky top-0 right-0 left-0 z-20 bg-white",
12934
13354
  "body": [
12935
13355
  getFormPagination(props, mode)
12936
13356
  ]
@@ -12946,7 +13366,7 @@ function getFormPaginationWrapper(props, form, mode) {
12946
13366
  }
12947
13367
  ];
12948
13368
  let onServiceInitedScript = `
12949
- // 以下脚本是为了解决有时弹出编辑表单时,表单中的值比最后一次编辑保存的值会延迟一拍。
13369
+ // 以下脚本解决了有时弹出编辑表单时,表单中的值比最后一次编辑保存的值会延迟一拍。
12950
13370
  // 比如:inlineEditMode模式时,用户在表格单元格中直接修改数据,然后弹出的表单form中并没有包含单元格中修改的内容
12951
13371
  // 另外有的地方在非inlineEditMode模式时也会有这种延迟一拍问题,比如对象字段中下拉框类型字段的”选择项“属性
12952
13372
  // 再比如工作流规则详细页面修改了子表字段”时间触发器“值后,在只读界面点击查看按钮弹出的表单中__tableItems值是修改前的值
@@ -12959,8 +13379,13 @@ function getFormPaginationWrapper(props, form, mode) {
12959
13379
  // 这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
12960
13380
  // 这里如果不.clone的话,在弹出窗口中显示的子表组件,添加行后点窗口的取消按钮关闭窗口后无法把之前的操作还原,即把之前添加的行自动移除
12961
13381
  let lastestFieldValue = _.clone(wrapperServiceData["${props.name}"] || []);
13382
+ let fieldPrefix = "${props.fieldPrefix || ''}";
13383
+ if(fieldPrefix){
13384
+ let getTableValueWithoutFieldPrefix = new Function('v', 'f', "return (" + ${getTableValueWithoutFieldPrefix.toString()} + ")(v, f)");
13385
+ lastestFieldValue = getTableValueWithoutFieldPrefix(lastestFieldValue, fieldPrefix);
13386
+ }
12962
13387
  //不可以直接像event.data.__tableItems = lastestFieldValue; 这样整个赋值,否则作用域会断
12963
- let mode = "${mode}";
13388
+ let mode = "${mode || ''}";
12964
13389
  if(mode === "new"){
12965
13390
  // 点击子表组件底部新增按钮时新增一条空白行并自动翻页到新增行
12966
13391
  // 注意点击弹出的子表行详细表单中的新增按钮不会进此service init事件函数中
@@ -12981,6 +13406,26 @@ function getFormPaginationWrapper(props, form, mode) {
12981
13406
  event.data.__tableItems.forEach(function(n,i){
12982
13407
  event.data.__tableItems[i] = lastestFieldValue[i];
12983
13408
  });
13409
+
13410
+ var parent = event.data.parent;
13411
+ var fieldValue = event.data.__tableItems;
13412
+ if(parent){
13413
+ // 如果是子行,即在节点嵌套情况下,当前节点如果是children属性下的子节点时,则算出其所属父行的索引值
13414
+ var primaryKey = "${primaryKey}";
13415
+ event.data.__parentIndex = _.findIndex(fieldValue, function(item){
13416
+ return item[primaryKey] == parent[primaryKey];
13417
+ });
13418
+ if(event.data.__parentIndex < 0){
13419
+ let tableId = "${props.id}";
13420
+ let table = scope.getComponentById(tableId)
13421
+ // autoGeneratePrimaryKeyValue不为true的情况下,即子表组件input-table的pipeOut函数中会移除表单了子表字段的primaryKey字段值,
13422
+ // 此时行primaryKey字段值为空,但是pipeIn函数中已经为input-table自动生成过primaryKey字段值了,只是没有输出到表单字段值中而已
13423
+ // 所以上面从表单字段值中没找到__parentIndex,是因为此时行primaryKey字段值只经过pipeIn保存到table组件内而没有保存到tableService
13424
+ event.data.__parentIndex = _.findIndex(table.props.value, function(item){
13425
+ return item[primaryKey] == parent[primaryKey];
13426
+ });
13427
+ }
13428
+ }
12984
13429
  `;
12985
13430
  let schema = {
12986
13431
  "type": "service",
@@ -13001,6 +13446,7 @@ function getFormPaginationWrapper(props, form, mode) {
13001
13446
  // "body": formBody,
13002
13447
  "data": {
13003
13448
  "__page": "${index + 1}",
13449
+ "__parentIndex": null,//兼容节点嵌套情况,即节点中有children属性时,这里记录当前节点所属上层节点index,只支持向上找一层,不支持多层
13004
13450
  // "__total": `\${${props.name}.length}`,
13005
13451
  // "__total": "${__tableItems.length}",
13006
13452
  // "__paginationServiceId": serviceId,
@@ -13027,6 +13473,7 @@ function getFormPaginationWrapper(props, form, mode) {
13027
13473
  async function getForm(props, mode = "edit", formId) {
13028
13474
  let formFields = getFormFields(props, mode);
13029
13475
  let body = await getFormBody(null, formFields);
13476
+ let primaryKey = getTablePrimaryKey(props);
13030
13477
  if (!formId) {
13031
13478
  formId = getComponentId("form", props.id);
13032
13479
  }
@@ -13045,10 +13492,41 @@ async function getForm(props, mode = "edit", formId) {
13045
13492
  // 新增行弹出编辑行表单,在弹出之前已经不用先增加一行,因为在翻页service初始化的时候会判断mode为new时自动新增一行
13046
13493
  let onEditItemSubmitScript = `
13047
13494
  // let fieldValue = _.cloneDeep(event.data["${props.name}"]);
13495
+ let removeEmptyItems = function(items){
13496
+ let i = _.findIndex(items, function(item){
13497
+ return item === undefined
13498
+ });
13499
+ if(i > -1){
13500
+ items.splice(i, 1);
13501
+ removeEmptyItems(items);
13502
+ }
13503
+ }
13504
+ // 因为删除时只是把input-table组件中的行数据删除了,并没有把父层service中的行删除,所以__tableItems会有值为undefined的数据,需要移除掉
13505
+ // 不用event.data.__tableItems = _.compact(event.data.__tableItems)是因为会把__tableItems变量保存到表单中
13506
+ removeEmptyItems(event.data.__tableItems);
13048
13507
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
13049
13508
  //这里加__super.__super前缀是因为__parentForm变量(即主表单)中可能会正好有名为index的字段
13050
13509
  // 比如“对象字段”对象options字段是一个子表字段,但是主表(即“对象字段”对象)中正好有一个名为index的字段
13051
- fieldValue[event.data.__super.__super.index] = JSON.parse(JSON.stringify(event.data));
13510
+ // fieldValue[event.data.__super.__super.index] = JSON.parse(JSON.stringify(event.data));
13511
+ var currentIndex = event.data.__super.__super.index;
13512
+ var currentFormValues = JSON.parse(JSON.stringify(event.data));
13513
+ var parent = event.data.__super.__super.parent;
13514
+ var __parentIndex = event.data.__super.__super.__parentIndex;
13515
+ let uuidv4 = new Function("return (" + ${uuidv4.toString()} + ")()");
13516
+ var primaryKey = "${primaryKey}";
13517
+ if(parent){
13518
+ fieldValue[__parentIndex].children[currentIndex] = currentFormValues;
13519
+ // 重写父节点,并且改变其某个属性以让子节点修改的内容回显到界面上
13520
+ fieldValue[__parentIndex] = Object.assign({}, fieldValue[__parentIndex], {
13521
+ children: fieldValue[__parentIndex].children,
13522
+ __fix_rerender_after_children_modified_tag: new Date().getTime()
13523
+ });
13524
+ }
13525
+ else{
13526
+ // 这里currentFormValues中如果没有primaryKey字段值不用处理,因为组件的pipeIn/pipeOut中会为每行自动生成
13527
+ // 也不用担心复制行时_id会重复,因为点击复制按钮时已经处理过了
13528
+ fieldValue[currentIndex] = currentFormValues;
13529
+ }
13052
13530
  doAction({
13053
13531
  "componentId": "${props.id}",
13054
13532
  "actionType": "setValue",
@@ -13144,6 +13622,7 @@ async function getForm(props, mode = "edit", formId) {
13144
13622
  */
13145
13623
  async function getButtonActions(props, mode) {
13146
13624
  let actions = [];
13625
+ let primaryKey = getTablePrimaryKey(props);
13147
13626
  let formId = getComponentId("form", props.id);
13148
13627
  let dialogId = getComponentId("dialog", props.id);
13149
13628
  let buttonNextId = getComponentId("button_next", props.id);
@@ -13186,9 +13665,42 @@ async function getButtonActions(props, mode) {
13186
13665
  // };
13187
13666
  let onSaveAndNewItemScript = `
13188
13667
  let scope = event.context.scoped;
13668
+ let removeEmptyItems = function(items){
13669
+ let i = _.findIndex(items, function(item){
13670
+ return item === undefined
13671
+ });
13672
+ if(i > -1){
13673
+ items.splice(i, 1);
13674
+ removeEmptyItems(items);
13675
+ }
13676
+ }
13677
+ // 因为删除时只是把input-table组件中的行数据删除了,并没有把父层service中的行删除,所以__tableItems会有值为undefined的数据,需要移除掉
13678
+ // 不用event.data.__tableItems = _.compact(event.data.__tableItems)是因为会把__tableItems变量保存到表单中
13679
+ removeEmptyItems(event.data.__tableItems);
13189
13680
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
13190
13681
  // 新建一条空白行并保存到子表组件
13191
- fieldValue.push({});
13682
+ var parent = event.data.__super.parent;
13683
+ var primaryKey = "${primaryKey}";
13684
+ var __parentIndex = parent && _.findIndex(fieldValue, function(item){
13685
+ return item[primaryKey] == parent[primaryKey];
13686
+ });
13687
+ if(parent && __parentIndex < 0){
13688
+ let tableId = "${props.id}";
13689
+ let table = scope.getComponentById(tableId)
13690
+ // autoGeneratePrimaryKeyValue不为true的情况下,即子表组件input-table的pipeOut函数中会移除表单了子表字段的primaryKey字段值,
13691
+ // 此时行primaryKey字段值为空,但是pipeIn函数中已经为input-table自动生成过primaryKey字段值了,只是没有输出到表单字段值中而已
13692
+ // 所以上面从表单字段值中没找到__parentIndex,是因为此时行primaryKey字段值只经过pipeIn保存到table组件内而没有保存到tableService
13693
+ __parentIndex = _.findIndex(table.props.value, function(item){
13694
+ return item[primaryKey] == parent[primaryKey];
13695
+ });
13696
+ }
13697
+ if(parent){
13698
+ fieldValue[__parentIndex].children.push({});
13699
+ // 这里实测不需要fieldValue[__parentIndex] = ... 来重写整个父行让子表回显,所以没加相关代码
13700
+ }
13701
+ else{
13702
+ fieldValue.push({});
13703
+ }
13192
13704
  doAction({
13193
13705
  "componentId": "${props.id}",
13194
13706
  "actionType": "setValue",
@@ -13200,7 +13712,13 @@ async function getButtonActions(props, mode) {
13200
13712
  let __paginationServiceId = "${formPaginationId}";
13201
13713
  let __paginationData = scope.getComponentById(__paginationServiceId).getData();
13202
13714
  event.data.index = __paginationData.index;
13203
- event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13715
+ if(parent){
13716
+ event.data.__page = fieldValue[__parentIndex].children.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13717
+ event.data.__parentIndex = __parentIndex; //执行下面的翻页按钮事件中依赖了__parentIndex值
13718
+ }
13719
+ else{
13720
+ event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13721
+ }
13204
13722
  // 触发翻页按钮事件,实现保存当前页数据并跳转到最后一行
13205
13723
  scope.getComponentById(buttonNextId).props.dispatchEvent("click", event.data);
13206
13724
  `;
@@ -13209,9 +13727,49 @@ async function getButtonActions(props, mode) {
13209
13727
  let __formId = "${formId}";
13210
13728
  // let newItem = JSON.parse(JSON.stringify(event.data));
13211
13729
  let newItem = scope.getComponentById(__formId).getValues();//这里不可以用event.data,因为其拿到的是弹出表单时的初始值,不是用户实时填写的数据
13730
+ newItem = _.clone(newItem);
13731
+ let removeEmptyItems = function(items){
13732
+ let i = _.findIndex(items, function(item){
13733
+ return item === undefined
13734
+ });
13735
+ if(i > -1){
13736
+ items.splice(i, 1);
13737
+ removeEmptyItems(items);
13738
+ }
13739
+ }
13740
+ // 因为删除时只是把input-table组件中的行数据删除了,并没有把父层service中的行删除,所以__tableItems会有值为undefined的数据,需要移除掉
13741
+ // 不用event.data.__tableItems = _.compact(event.data.__tableItems)是因为会把__tableItems变量保存到表单中
13742
+ removeEmptyItems(event.data.__tableItems);
13212
13743
  let fieldValue = event.data.__tableItems;//这里不可以_.cloneDeep,因为翻页form中用的是event.data.__tableItems,直接变更其值即可改变表单中的值
13213
13744
  // 复制当前页数据到新建行并保存到子表组件
13214
- fieldValue.push(newItem);
13745
+ // fieldValue.push(newItem);
13746
+ var parent = event.data.__super.parent;
13747
+ var primaryKey = "${primaryKey}";
13748
+ var __parentIndex = parent && _.findIndex(fieldValue, function(item){
13749
+ return item[primaryKey] == parent[primaryKey];
13750
+ });
13751
+ if(parent && __parentIndex < 0){
13752
+ let tableId = "${props.id}";
13753
+ let table = scope.getComponentById(tableId)
13754
+ // autoGeneratePrimaryKeyValue不为true的情况下,即子表组件input-table的pipeOut函数中会移除表单了子表字段的primaryKey字段值,
13755
+ // 此时行primaryKey字段值为空,但是pipeIn函数中已经为input-table自动生成过primaryKey字段值了,只是没有输出到表单字段值中而已
13756
+ // 所以上面从表单字段值中没找到__parentIndex,是因为此时行primaryKey字段值只经过pipeIn保存到table组件内而没有保存到tableService
13757
+ __parentIndex = _.findIndex(table.props.value, function(item){
13758
+ return item[primaryKey] == parent[primaryKey];
13759
+ });
13760
+ }
13761
+ if(newItem[primaryKey]){
13762
+ // 如果newItem已经有主键字段值,则重新生成新的主键值,否则会重复。
13763
+ let uuidv4 = new Function("return (" + ${uuidv4.toString()} + ")()");
13764
+ newItem[primaryKey] = uuidv4();
13765
+ }
13766
+ if(parent){
13767
+ fieldValue[__parentIndex].children.push(newItem);
13768
+ // 这里实测不需要fieldValue[__parentIndex] = ... 来重写整个父行让子表回显,所以没加相关代码
13769
+ }
13770
+ else{
13771
+ fieldValue.push(newItem);
13772
+ }
13215
13773
  doAction({
13216
13774
  "componentId": "${props.id}",
13217
13775
  "actionType": "setValue",
@@ -13223,7 +13781,13 @@ async function getButtonActions(props, mode) {
13223
13781
  let __paginationServiceId = "${formPaginationId}";
13224
13782
  let __paginationData = scope.getComponentById(__paginationServiceId).getData();
13225
13783
  event.data.index = __paginationData.index;
13226
- event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13784
+ if(parent){
13785
+ event.data.__page = fieldValue[__parentIndex].children.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13786
+ event.data.__parentIndex = __parentIndex; //执行下面的翻页按钮事件中依赖了__parentIndex值
13787
+ }
13788
+ else{
13789
+ event.data.__page = fieldValue.length - 1;//这里不可以用Object.assign否则,event.data中上层作用域数据会丢失
13790
+ }
13227
13791
  // 触发翻页按钮事件,实现保存当前页数据并跳转到最后一行
13228
13792
  scope.getComponentById(buttonNextId).props.dispatchEvent("click", event.data);
13229
13793
  `;
@@ -13299,13 +13863,16 @@ async function getButtonActions(props, mode) {
13299
13863
  "_master": "${_master}",
13300
13864
  "global": "${global}",
13301
13865
  "uiSchema": "${uiSchema}",
13302
- "index": "${index}",
13866
+ "index": "${index}",//amis组件自带行索引,在节点嵌套情况下,当前节点如果是children属性下的子节点时,这里的index是当前节点在children中的索引,而不是外层父节点的index
13867
+ "parent": "${__super.parent}",//amis组件自带父节点数据域数据,即节点嵌套情况下,当前节点为某个节点(比如A节点)的children属性下的子节点时,当前节点的父节点(即A节点)的数据域数据
13303
13868
  // "__tableItems": `\${${props.name}}`
13304
13869
  // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13305
13870
  // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13306
13871
  // "__tableItems": `\${${props.name}|json|toJson}`
13307
- "__tableItems": `\${(${props.name} || [])|json|toJson}`
13308
- },
13872
+ // 在节点嵌套情况下,当前节点正好是带children属性的节点的话,这里弹出的dialog映射到的会是children数组,这是amis目前的规则,
13873
+ // 所以这里加判断有children时,用__super.__super让映射到正确的作用域层,如果不加,则__tableItems取到的会是children数组,而不是整个子表组件的值
13874
+ "__tableItems": `\${((children ? __super.__super.${props.name} : __super.${props.name}) || [])|json|toJson}`
13875
+ },
13309
13876
  "actions": dialogButtons,
13310
13877
  "onEvent": {
13311
13878
  "confirm": {
@@ -13327,35 +13894,39 @@ async function getButtonActions(props, mode) {
13327
13894
  Object.assign(actionShowEditDialog.dialog, props.dialog);
13328
13895
  }
13329
13896
  if (mode == "new") {
13330
- `
13331
- let newItem = {};
13332
- if(event.data["${props.name}"]){
13333
- // let fieldValue = event.data.__tableItems;
13334
- // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
13335
- // let fieldValue = _.clone(event.data["${props.name}"]);
13336
- let fieldValue = event.data["${props.name}"];
13337
- fieldValue.push(newItem);
13338
- doAction({
13339
- "componentId": "${props.id}",
13340
- "actionType": "setValue",
13341
- "args": {
13342
- "value": fieldValue
13343
- }
13344
- });
13345
- event.data.index = fieldValue.length - 1;
13346
- }
13347
- else{
13348
- // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
13349
- doAction({
13350
- "componentId": "${props.id}",
13351
- "actionType": "setValue",
13352
- "args": {
13353
- "value": [newItem]
13354
- }
13355
- });
13356
- event.data.index = 1;
13357
- }
13358
- `;
13897
+ // let onNewLineScript = `
13898
+ // let newItem = {};
13899
+ // if(event.data["${props.name}"]){
13900
+ // // let fieldValue = event.data.__tableItems;
13901
+ // // 这里不用__tableItems是因为新建的时候没有翻页,里面没有也不需要走__tableItems变量
13902
+ // // let fieldValue = _.clone(event.data["${props.name}"]);
13903
+ // let fieldValue = event.data["${props.name}"];
13904
+ // fieldValue.push(newItem);
13905
+ // doAction({
13906
+ // "componentId": "${props.id}",
13907
+ // "actionType": "setValue",
13908
+ // "args": {
13909
+ // "value": fieldValue
13910
+ // }
13911
+ // });
13912
+ // event.data.index = fieldValue.length - 1;
13913
+ // }
13914
+ // else{
13915
+ // // 这里不可以执行event.data["${props.name}"]=[newItem],数据域会断掉
13916
+ // doAction({
13917
+ // "componentId": "${props.id}",
13918
+ // "actionType": "setValue",
13919
+ // "args": {
13920
+ // "value": [newItem]
13921
+ // }
13922
+ // });
13923
+ // event.data.index = 1;
13924
+ // }
13925
+ // `;
13926
+ // let actionNewLine = {
13927
+ // "actionType": "custom",
13928
+ // "script": onNewLineScript
13929
+ // };
13359
13930
  // 新增行时不需要在弹出编辑表单前先加一行,因为会在编辑表单所在service初始化时判断到是新增就自动增加一行,因为这里拿不到event.data.__tableItems,也无法变更其值
13360
13931
  // actions = [actionNewLine, actionShowEditDialog];
13361
13932
  actions = [actionShowEditDialog];
@@ -13390,15 +13961,17 @@ async function getButtonActions(props, mode) {
13390
13961
  // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13391
13962
  // "__parentForm": "${__super.__super || {}}",
13392
13963
  "__parentForm": parentFormData,
13964
+ "_master": "${_master}",
13393
13965
  "global": "${global}",
13394
13966
  "uiSchema": "${uiSchema}",
13395
13967
  "index": "${index}",
13968
+ "parent": "${__super.parent}",//amis组件自带父节点数据域数据,即节点嵌套情况下,当前节点为某个节点(比如A节点)的children属性下的子节点时,当前节点的父节点(即A节点)的数据域数据
13396
13969
  // "__tableItems": `\${${props.name}}`
13397
13970
  // 为了解决"弹出的dialog窗口中子表组件会影响页面布局界面中父作用域字段值",比如设计字段布局微页面中的设置分组功能,弹出的就是子表dialog
13398
13971
  // 所以这里使用json|toJson转一次,断掉event.data.__tableItems与上层任用域中props.name的联系
13399
13972
  // "__tableItems": `\${${props.name}|json|toJson}`
13400
- "__tableItems": `\${(${props.name} || [])|json|toJson}`
13401
- },
13973
+ "__tableItems": `\${((__super.parent ? __super.__super.${props.name} : __super.${props.name}) || [])|json|toJson}`
13974
+ },
13402
13975
  }
13403
13976
  }
13404
13977
  ];
@@ -13413,8 +13986,40 @@ async function getButtonActions(props, mode) {
13413
13986
  let wrapperServiceData = wrapperService.getData();
13414
13987
  // 这里不可以用event.data["${props.name}"]因为amis input talbe有一层单独的作用域,其值会延迟一拍
13415
13988
  // 这里_.clone是因为字段设计布局设置分组这种弹出窗口中的子表组件,直接删除后,点取消无法还原
13989
+ // 也因为这里clone没有直接删除,所以弹出编辑表单提交事件中event.data.__tableItems中取到的值会有被删除的行数据为undefined
13416
13990
  let lastestFieldValue = _.clone(wrapperServiceData["${props.name}"]);
13417
- lastestFieldValue.splice(event.data.index, 1);
13991
+ var currentIndex = event.data.index;
13992
+ var parent = event.data.__super.parent;
13993
+ var primaryKey = "${primaryKey}";
13994
+ var __parentIndex = parent && _.findIndex(lastestFieldValue, function(item){
13995
+ return item[primaryKey] == parent[primaryKey];
13996
+ });
13997
+ if(parent && __parentIndex < 0){
13998
+ let tableId = "${props.id}";
13999
+ let table = scope.getComponentById(tableId)
14000
+ // autoGeneratePrimaryKeyValue不为true的情况下,即子表组件input-table的pipeOut函数中会移除表单了子表字段的primaryKey字段值,
14001
+ // 此时行primaryKey字段值为空,但是pipeIn函数中已经为input-table自动生成过primaryKey字段值了,只是没有输出到表单字段值中而已
14002
+ // 所以上面从表单字段值中没找到__parentIndex,是因为此时行primaryKey字段值只经过pipeIn保存到table组件内而没有保存到tableService
14003
+ __parentIndex = _.findIndex(table.props.value, function(item){
14004
+ return item[primaryKey] == parent[primaryKey];
14005
+ });
14006
+ }
14007
+ if(parent){
14008
+ lastestFieldValue[__parentIndex].children.splice(currentIndex, 1);
14009
+ // 重写父节点,并且改变其某个属性以让子节点修改的内容回显到界面上
14010
+ lastestFieldValue[__parentIndex] = Object.assign({}, lastestFieldValue[__parentIndex], {
14011
+ children: lastestFieldValue[__parentIndex].children,
14012
+ __fix_rerender_after_children_modified_tag: new Date().getTime()
14013
+ });
14014
+ }
14015
+ else{
14016
+ lastestFieldValue.splice(currentIndex, 1);
14017
+ }
14018
+ let fieldPrefix = "${props.fieldPrefix || ''}";
14019
+ if(fieldPrefix){
14020
+ let getTableValueWithoutFieldPrefix = new Function('v', 'f', "return (" + ${getTableValueWithoutFieldPrefix.toString()} + ")(v, f)");
14021
+ lastestFieldValue = getTableValueWithoutFieldPrefix(lastestFieldValue, fieldPrefix);
14022
+ }
13418
14023
  doAction({
13419
14024
  "componentId": "${props.id}",
13420
14025
  "actionType": "setValue",
@@ -13500,39 +14105,52 @@ const getAmisInputTableSchema = async (props) => {
13500
14105
  if (!props.id) {
13501
14106
  props.id = "steedos_input_table_" + props.name + "_" + Math.random().toString(36).substr(2, 9);
13502
14107
  }
14108
+ let primaryKey = getTablePrimaryKey(props);
14109
+ let showOperation = props.showOperation;
14110
+ if(showOperation !== false){
14111
+ showOperation = true;
14112
+ }
14113
+ let fieldPrefix = props.fieldPrefix;
14114
+ let fields = props.fields || [];
14115
+ if (fieldPrefix) {
14116
+ fields = getTableFieldsWithoutFieldPrefix(fields, fieldPrefix);
14117
+ }
13503
14118
  let serviceId = getComponentId("table_service", props.id);
13504
14119
  let buttonsForColumnOperations = [];
13505
14120
  let inlineEditMode = props.inlineEditMode;
13506
14121
  let showAsInlineEditMode = inlineEditMode && props.editable;
13507
- if (props.editable) {
13508
- let showEditButton = true;
13509
- if (showAsInlineEditMode) {
13510
- // 始终显示弹出子表表单按钮,如果需要判断只在有列被隐藏时才需要显示弹出表单按钮放开下面的if逻辑就好
13511
- showEditButton = true;
13512
- // // inline edit模式下只在有列被隐藏时才需要显示编辑按钮
13513
- // if (props.columns && props.columns.length > 0 && props.columns.length < props.fields.length) {
13514
- // showEditButton = true;
13515
- // }
13516
- // else {
13517
- // showEditButton = false;
13518
- // }
14122
+ if(showOperation){
14123
+ if (props.editable) {
14124
+ let showEditButton = true;
14125
+ if (showAsInlineEditMode) {
14126
+ // 始终显示弹出子表表单按钮,如果需要判断只在有列被隐藏时才需要显示弹出表单按钮放开下面的if逻辑就好
14127
+ showEditButton = true;
14128
+ // // inline edit模式下只在有列被隐藏时才需要显示编辑按钮
14129
+ // if (props.columns && props.columns.length > 0 && props.columns.length < fields.length) {
14130
+ // showEditButton = true;
14131
+ // }
14132
+ // else {
14133
+ // showEditButton = false;
14134
+ // }
14135
+ }
14136
+ // 编辑时显示编辑按钮
14137
+ if (showEditButton) {
14138
+ let buttonEditSchema = await getButtonEdit(props, showAsInlineEditMode);
14139
+ buttonsForColumnOperations.push(buttonEditSchema);
14140
+ }
13519
14141
  }
13520
- // 编辑时显示编辑按钮
13521
- if (showEditButton) {
13522
- let buttonEditSchema = await getButtonEdit(props, showAsInlineEditMode);
13523
- buttonsForColumnOperations.push(buttonEditSchema);
14142
+ else {
14143
+ // 只读时显示查看按钮
14144
+ // 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length < fields.length)
14145
+ let buttonViewSchema = await getButtonView(props);
14146
+ buttonsForColumnOperations.push(buttonViewSchema);
14147
+ }
14148
+ if (props.removable) {
14149
+ let buttonDeleteSchema = await getButtonDelete(props);
14150
+ buttonsForColumnOperations.push(buttonDeleteSchema);
13524
14151
  }
13525
14152
  }
13526
- else {
13527
- // 只读时显示查看按钮
13528
- // 如果想只在有列被隐藏时才需要显示查看按钮可以加上判断:if (props.columns && props.columns.length > 0 && props.columns.length < props.fields.length)
13529
- let buttonViewSchema = await getButtonView(props);
13530
- buttonsForColumnOperations.push(buttonViewSchema);
13531
- }
13532
- if (props.removable) {
13533
- let buttonDeleteSchema = await getButtonDelete(props);
13534
- buttonsForColumnOperations.push(buttonDeleteSchema);
13535
- }
14153
+ let amis = props["input-table"] || props.amis || {};//额外支持"input-table"代替amis属性,是因为在字段yml文件中用amis作为key不好理解
13536
14154
  let inputTableSchema = {
13537
14155
  "type": "input-table",
13538
14156
  "label": props.label,
@@ -13550,7 +14168,51 @@ const getAmisInputTableSchema = async (props) => {
13550
14168
  "strictMode": props.strictMode,
13551
14169
  "showTableAddBtn": false,
13552
14170
  "showFooterAddBtn": false,
13553
- "className": props.tableClassName
14171
+ "className": props.tableClassName,
14172
+ "pipeIn": (value, data) => {
14173
+ if(fieldPrefix){
14174
+ value = getTableValueWithoutFieldPrefix(value, fieldPrefix);
14175
+ }
14176
+ if(primaryKey){
14177
+ // 这里临时给每行数据补上primaryKey字段值,如果库里不需要保存这里补上的字段值,pipeOut中会识别autoGeneratePrimaryKeyValue属性选择最终移除这里补上的字段值
14178
+ // 这里始终自动生成primaryKey字段值,而不是只在pipeOut输出整个子表字段值时才生成,是因为要支持当数据库里保存的子表字段行数据没有primaryKey字段值时的行嵌套模式(即节点的children属性)功能
14179
+ // 这里要注意,流程详细设置界面的字段设置功能中的子表组件中,数据库里保存的子表字段行数据是有primaryKey字段值的,它不依赖这里自动生成行primaryKey值功能
14180
+ value = getTableValueWithPrimaryKeyValue(value, primaryKey);
14181
+ }
14182
+ if(amis.pipeIn){
14183
+ if(typeof amis.pipeIn === 'function'){
14184
+ return amis.pipeIn(value, data);
14185
+ }
14186
+ }
14187
+ return value;
14188
+ },
14189
+ "pipeOut": (value, data) => {
14190
+ value = (value || []).map(function(item){
14191
+ delete item.__fix_rerender_after_children_modified_tag;
14192
+ return item;
14193
+ });
14194
+ if(fieldPrefix){
14195
+ value = getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey);
14196
+ }
14197
+ if(props.autoGeneratePrimaryKeyValue === true){
14198
+ // 如果需要把自动生成的primaryKey值输出保存的库中,则补全所有行中的primaryKey值
14199
+ // 这里如果不全部补全的话,初始从库里返回的字段值中拿到的行没primaryKey值的话就不会自动补上
14200
+ value = getTableValueWithPrimaryKeyValue(value, primaryKey);
14201
+ }
14202
+ else {
14203
+ // 默认情况下,也就是没有配置autoGeneratePrimaryKey时,最终输出的字段值要移除行中的primaryKey值
14204
+ // 需要注意如果没有配置autoGeneratePrimaryKey时,因为每次弹出行编辑窗口保存后都会先后进入pipeOut和pipeIn,
14205
+ // 这里删除掉了primaryKey值,所以primaryKey值每次弹出编辑窗口保存后都会给每行重新生成新的primaryKey值
14206
+ // 只有autoGeneratePrimaryKey配置为true时,每行的primaryKey字段值才会始终保持不变
14207
+ value = getTableValueWithoutPrimaryKeyValue(value, primaryKey);
14208
+ }
14209
+ if(amis.pipeOut){
14210
+ if(typeof amis.pipeOut === 'function'){
14211
+ return amis.pipeOut(value, data);
14212
+ }
14213
+ }
14214
+ return value;
14215
+ }
13554
14216
  };
13555
14217
  if (buttonsForColumnOperations.length) {
13556
14218
  inputTableSchema.columns.push({
@@ -13563,17 +14225,18 @@ const getAmisInputTableSchema = async (props) => {
13563
14225
  if (showAsInlineEditMode) {
13564
14226
  inputTableSchema.needConfirm = false;
13565
14227
  }
13566
- let amis = props["input-table"] || props.amis;//额外支持"input-table"代替amis属性,是因为在字段yml文件中用amis作为key不好理解
13567
14228
  if (amis) {
13568
14229
  // 支持配置amis属性重写或添加最终生成的input-table中任何属性。
13569
14230
  delete amis.id;//如果steedos-input-table组件配置了amis.id属性,会造成新建编辑行功能不生效
14231
+ delete amis.pipeIn;//该属性在上面合并过了
14232
+ delete amis.pipeOut;//该属性在上面合并过了
13570
14233
  Object.assign(inputTableSchema, amis);
13571
14234
  }
13572
- const isAnyFieldHasDependOn = (props.fields || []).find(function (item) {
14235
+ const isAnyFieldHasDependOn = (fields || []).find(function (item) {
13573
14236
  return item.depend_on;
13574
14237
  });
13575
14238
  if (isAnyFieldHasDependOn) {
13576
- // 有任意一个子字段有depend_on属性时,强制设置禁用静态模式
14239
+ // 有任意一个子字段有depend_on属性时,强制设置禁用静态模式,因为strictMode模式下,dependOn的字段值变更后,不会rerender整个子表
13577
14240
  Object.assign(inputTableSchema, {
13578
14241
  strictMode: false
13579
14242
  });
@@ -13678,7 +14341,7 @@ async function getListPageInitSchema(objectApiName, formFactor, userSession) {
13678
14341
  // 获取
13679
14342
  async function getRecordPageInitSchema(objectApiName){
13680
14343
  const relatedList = await getObjectRelatedList(objectApiName);
13681
- const uiSchema = await getUISchema(objectApiName);
14344
+ await getUISchema(objectApiName);
13682
14345
  let body = [
13683
14346
  // detailHeaderAmisSchema,
13684
14347
  {
@@ -13686,28 +14349,7 @@ async function getRecordPageInitSchema(objectApiName){
13686
14349
  "label": "标题面板",
13687
14350
  "objectApiName": "${objectName}",
13688
14351
  "recordId": "${recordId}",
13689
- "onEvent": {
13690
- "recordLoaded": {
13691
- "actions": [
13692
- {
13693
- "actionType": "setValue",
13694
- "args": {
13695
- "value": {
13696
- "recordLoaded": true,
13697
- }
13698
- }
13699
- },
13700
- {
13701
- "actionType": "reload",
13702
- "data": {
13703
- "name": `\${record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
13704
- "record": `\${record}`,
13705
- "recordLoaded": true,
13706
- }
13707
- }
13708
- ]
13709
- }
13710
- }
14352
+ "onEvent": {}
13711
14353
  }
13712
14354
  ];
13713
14355
  let contentBody = {
@@ -16272,5 +16914,5 @@ const getInstanceInfo = async ({ instanceId, box }) => {
16272
16914
  };
16273
16915
  };
16274
16916
 
16275
- export { index as Field, Router, absoluteUrl, amisRender, amisRootClick, cloneObject, conditionsToFilters, createObject, defaultsDeep, deleteVariable, execute, executeButton, extendObject, fetchAPI, filtersToConditions, getAmisInputTableSchema, getApp, getApps, getAuthToken, getAuthorization, getButton, getButtonVisible, getButtonVisibleOn, getButtons, getCalendarSchema, getDefaultRenderData, getEnv, getEnvs, getEvn, getField, getFileSrc, getFlowFormSchema, getFormPageInitSchema, getFormSchema, getGlobalNowData, getIdsPickerSchema, getImageSrc, getInstanceInfo, getListPageInitSchema, getListSchema, getListViewButtons, getListViewColumns, getListViewFilter, getListViewItemButtons, getListViewSort, getListviewInitSchema, getLookupSapceUserTreeSchema, getNotifications, getObjectDetailButtons, getObjectDetailButtonsSchemas, getObjectDetailMoreButtons, getObjectFieldsFilterBarSchema, getObjectFieldsFilterButtonSchema, getObjectFieldsFilterFormSchema, getObjectListHeader$1 as getObjectListHeader, getObjectListHeaderFieldsFilterBar, getObjectListHeaderFirstLine, getObjectListHeaderSecordLine, getObjectListViewButtonsSchemas, getObjectRecordDetailHeader, getObjectRecordDetailRelatedListButtonsSchemas, getObjectRecordDetailRelatedListHeader, getObjectRelated, getObjectRelatedList, getObjectRelatedListButtons, getObjectRelatedListHeader, getPage, getRecord, getRecordDetailHeaderSchema, getRecordDetailRelatedListSchema, getRecordDetailSchema, getRecordPageInitSchema, getRecordPermissions, getRecordServiceSchema, getReferenceTo, getReferenceToFieldSchema, getReferenceToSync, getRelatedFieldValue, getRelatedListSchema, getRelatedsCount, getRootUrl, getSelectUserSchema, getSpaceUsersPickerAmisSchema, getSpaceUsersPickerSchema, getSteedosAuth, getTableSchema, getTenantId, getUISchema, getUISchemaSync$1 as getUISchemaSync, getUserId, getViewSchema, isExpression, isObject, lookupToAmis, lookupToAmisIdsPicker, lookupToAmisPicker, lookupToAmisSelect, lookupToAmisSelectUser, markReadAll, parseSingleExpression, registerRemoteAssets, registerRenders, setEnv, setEnvs, setRootUrl, setSteedosAuth, setUISchemaFunction, setVariable, standardButtonsTodo };
16917
+ export { index as Field, Router, absoluteUrl, amisRender, amisRootClick, cloneObject, conditionsToFilters, createObject, defaultsDeep, deleteVariable, execute, executeButton, extendObject, fetchAPI, filtersToConditions, getAmisInputTableSchema, getApp, getApps, getAuthToken, getAuthorization, getButton, getButtonVisible, getButtonVisibleOn, getButtons, getCalendarSchema, getDefaultRenderData, getEnv, getEnvs, getEvn, getField, getFileSrc, getFlowFormSchema, getFormPageInitSchema, getFormSchema, getGlobalNowData, getIdsPickerSchema, getImageSrc, getInstanceInfo, getListPageInitSchema, getListSchema, getListViewButtons, getListViewColumns, getListViewFilter, getListViewItemButtons, getListViewSort, getListviewInitSchema, getLookupSapceUserTreeSchema, getNotifications, getObjectDetailButtons, getObjectDetailButtonsSchemas, getObjectDetailMoreButtons, getObjectFieldsFilterBarSchema, getObjectFieldsFilterButtonSchema, getObjectFieldsFilterFormSchema, getObjectListHeader$1 as getObjectListHeader, getObjectListHeaderFieldsFilterBar, getObjectListHeaderFirstLine, getObjectListHeaderSecordLine, getObjectListViewButtonsSchemas, getObjectRecordDetailHeader, getObjectRecordDetailRelatedListButtonsSchemas, getObjectRecordDetailRelatedListHeader, getObjectRelated, getObjectRelatedList, getObjectRelatedListButtons, getObjectRelatedListHeader, getObjectRelatedListsMiniSchema, getPage, getRecord, getRecordDetailHeaderSchema, getRecordDetailMiniSchema, getRecordDetailRelatedListSchema, getRecordDetailSchema, getRecordPageInitSchema, getRecordPermissions, getRecordServiceSchema, getReferenceTo, getReferenceToFieldSchema, getReferenceToSync, getRelatedFieldValue, getRelatedListSchema, getRelatedsCount, getRootUrl, getSelectUserSchema, getSpaceUsersPickerAmisSchema, getSpaceUsersPickerSchema, getSteedosAuth, getTableSchema, getTenantId, getUISchema, getUISchemaSync$1 as getUISchemaSync, getUserId, getViewSchema, isExpression, isObject, lookupToAmis, lookupToAmisIdsPicker, lookupToAmisPicker, lookupToAmisSelect, lookupToAmisSelectUser, markReadAll, parseSingleExpression, registerRemoteAssets, registerRenders, setEnv, setEnvs, setRootUrl, setSteedosAuth, setUISchemaFunction, setVariable, standardButtonsTodo };
16276
16918
  //# sourceMappingURL=index.esm.js.map