@steedos-widgets/amis-lib 1.3.0-beta.10 → 1.3.0-beta.12

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
@@ -400,7 +400,7 @@ function getContrastColor(bgColor) {
400
400
  * @Author: baozhoutao@steedos.com
401
401
  * @Date: 2022-05-23 09:53:08
402
402
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
403
- * @LastEditTime: 2023-08-03 18:07:54
403
+ * @LastEditTime: 2023-08-29 15:04:39
404
404
  * @Description:
405
405
  */
406
406
 
@@ -504,7 +504,7 @@ function getRelatedFieldTpl(field, ctx){
504
504
  linkTarget = "target='_blank'";
505
505
  }
506
506
 
507
- const onlyDisplayLabel = ctx.onlyDisplayLabel;
507
+ const onlyDisplayLookLabel = ctx.onlyDisplayLookLabel;
508
508
 
509
509
  let fieldDataStrTpl = `data._display.${field.name}`;
510
510
 
@@ -515,7 +515,7 @@ function getRelatedFieldTpl(field, ctx){
515
515
  if(_.isString(field.reference_to) || !field.reference_to){
516
516
  if(field.multiple){
517
517
  let labelTpl = `<%=item.label%>`;
518
- if(!onlyDisplayLabel){
518
+ if(!onlyDisplayLookLabel){
519
519
  const href = Router.getObjectDetailPath({
520
520
  formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
521
521
  });
@@ -533,7 +533,7 @@ function getRelatedFieldTpl(field, ctx){
533
533
  objectNameTpl = `\${${field.name}.objectName}`;
534
534
  recordIdTpl = `\${${field.name}.value}`;
535
535
  }
536
- if(!onlyDisplayLabel){
536
+ if(!onlyDisplayLookLabel){
537
537
  const href = Router.getObjectDetailPath({
538
538
  formFactor: ctx.formFactor, appId: "${appId}", objectName: `${objectNameTpl}`, recordId: `${recordIdTpl}`
539
539
  });
@@ -545,7 +545,7 @@ function getRelatedFieldTpl(field, ctx){
545
545
 
546
546
  }else {
547
547
  let labelTpl = `<%=item.label%>`;
548
- if(!onlyDisplayLabel){
548
+ if(!onlyDisplayLookLabel){
549
549
  const href = Router.getObjectDetailPath({
550
550
  formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
551
551
  });
@@ -598,7 +598,7 @@ function getLocationTpl(field){
598
598
  }
599
599
 
600
600
  async function getFieldTpl (field, options){
601
- if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLabel){
601
+ if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel){
602
602
  return getNameTpl(field, options)
603
603
  }
604
604
  switch (field.type) {
@@ -3052,6 +3052,7 @@ const getObjectListViewButtonsSchemas = (objectSchema, ctx)=>{
3052
3052
  return {
3053
3053
  "type": "button",
3054
3054
  "icon": "fa fa-angle-down",
3055
+ "className": "mr-0",
3055
3056
  "onEvent": {
3056
3057
  "click": {
3057
3058
  "actions": [
@@ -5275,76 +5276,133 @@ function getObjectHeaderToolbar(mainObject, fields, formFactor, {
5275
5276
  if(isMobile){
5276
5277
  showDisplayAs = false;
5277
5278
  }
5279
+ let toolbarCount;
5280
+ if(!hiddenCount){
5281
+ toolbarCount = {
5282
+ "type": "tpl",
5283
+ "tpl": "${count} " + i18next.t('frontend_record_sum')
5284
+ };
5285
+ }
5286
+ let toolbarReloadButton;
5278
5287
  if(formFactor === 'SMALL'){
5279
- const onReloadScript = `
5280
- const scope = event.context.scoped;
5281
- var listView = scope.parent.getComponents().find(function(n){
5282
- return n.props.type === "crud";
5283
- });
5284
- listView.handleChangePage(1);
5285
- `;
5288
+ // const onReloadScript = `
5289
+ // const scope = event.context.scoped;
5290
+ // var listView = scope.parent.getComponents().find(function(n){
5291
+ // return n.props.type === "crud";
5292
+ // });
5293
+ // listView.handleChangePage(1);
5294
+ // `;
5295
+ // toolbarReloadButton = {
5296
+ // // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页,这在加载更多按钮的翻页模式下会有问题
5297
+ // "type": "button",
5298
+ // "align": "right",
5299
+ // //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5300
+ // // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5301
+ // "tooltipPlacement": "top",
5302
+ // "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5303
+ // "label": "",
5304
+ // "icon": "fa fa-sync",
5305
+ // "visibleOn": "${!showFieldsFilter}",
5306
+ // "onEvent": {
5307
+ // "click": {
5308
+ // "actions": [
5309
+ // {
5310
+ // "actionType": "custom",
5311
+ // "script": onReloadScript
5312
+ // }
5313
+ // ]
5314
+ // }
5315
+ // },
5316
+ // };
5317
+
5318
+ // 后续如果换成加载更多按钮的翻页模式的话,不可以直接使用下面的reload,需要换成上面的自定义脚本模式
5319
+ toolbarReloadButton = {
5320
+ "type": "reload",
5321
+ "align": "right",
5322
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5323
+ // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5324
+ "tooltip":"",
5325
+ "tooltipPlacement": "top",
5326
+ "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5327
+ };
5328
+ }
5329
+ else {
5330
+ toolbarReloadButton = {
5331
+ "type": "reload",
5332
+ "align": "right",
5333
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5334
+ // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5335
+ "tooltip":"",
5336
+ "tooltipPlacement": "top",
5337
+ "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5338
+ };
5339
+ }
5340
+ let toolbarFilter;
5341
+ if(filterVisible){
5342
+ toolbarFilter ={
5343
+ "label": i18next.t('frontend_button_search_tooltip'),
5344
+ "icon": "fa fa-filter",
5345
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5346
+ // "tooltip": i18next.t('frontend_button_search_tooltip'),
5347
+ // "tooltipPlacement": "top",
5348
+ "type": "button",
5349
+ "badge": {
5350
+ "offset": [
5351
+ -5,
5352
+ 1
5353
+ ],
5354
+ "size":8,
5355
+ "animation": true,
5356
+ "visibleOn": "${isFieldsFilterEmpty == false && isLookup != true}"
5357
+ },
5358
+ "align": "right",
5359
+ "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5360
+ "onEvent": {
5361
+ "click": {
5362
+ "actions": [
5363
+ {
5364
+ "actionType": "custom",
5365
+ "script": onFieldsFilterToggleScript
5366
+ }
5367
+ ]
5368
+ }
5369
+ }
5370
+ };
5371
+ }
5372
+ let toolbarDisplayAsButton = getDisplayAsButton(mainObject?.name);
5373
+ let toolbarDQuickSearchBox = getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLookup, keywordsSearchBoxName });
5374
+
5375
+ // toolbars返回的数组元素不可以是空对象{},比如hiddenCount ? {} : {"type": "tpl",...},因为空对象最终还是会生成一个空的.antd-Crud-toolbar-item dom
5376
+ // 当出现空的.antd-Crud-toolbar-item dom时会影响toolbar元素的maring-right css样式计算,如果有动态需要应该加到动态数组变量toolbars中
5377
+ let toolbars = [];
5378
+ if(formFactor === 'SMALL'){
5379
+ if(toolbarCount){
5380
+ toolbars.push(toolbarCount);
5381
+ }
5382
+ toolbars.push(toolbarReloadButton);
5383
+ if(toolbarFilter){
5384
+ toolbars.push(toolbarFilter);
5385
+ }
5386
+ toolbars.push(toolbarDisplayAsButton);
5387
+ toolbars.push(toolbarDQuickSearchBox);
5286
5388
  return [
5287
5389
  // "bulkActions",
5288
5390
  ...(headerToolbarItems || []),
5289
- hiddenCount ? {} :{
5290
- "type": "tpl",
5291
- "tpl": "${count} " + i18next.t('frontend_record_sum')
5292
- },
5293
- {
5294
- // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页
5295
- "type": "button",
5296
- "align": "right",
5297
- //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5298
- // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5299
- "tooltipPlacement": "top",
5300
- "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5301
- "label": "",
5302
- "icon": "fa fa-sync",
5303
- "visibleOn": "${!showFieldsFilter}",
5304
- "onEvent": {
5305
- "click": {
5306
- "actions": [
5307
- {
5308
- "actionType": "custom",
5309
- "script": onReloadScript
5310
- }
5311
- ]
5312
- }
5313
- },
5314
- },
5315
- filterVisible ? {
5316
- "label": i18next.t('frontend_button_search_tooltip'),
5317
- "icon": "fa fa-search",
5318
- "type": "button",
5319
- "tooltipPlacement": "top",
5320
- //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5321
- // "tooltip": i18next.t('frontend_button_search_tooltip'),
5322
- "badge": {
5323
- "offset": [
5324
- -5,
5325
- 1
5326
- ],
5327
- "size":8,
5328
- "animation": true,
5329
- "visibleOn": "${isFieldsFilterEmpty == false && isLookup != true}"
5330
- },
5331
- "align": "right",
5332
- "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5333
- "onEvent": {
5334
- "click": {
5335
- "actions": [
5336
- {
5337
- "actionType": "custom",
5338
- "script": onFieldsFilterToggleScript
5339
- }
5340
- ]
5341
- }
5342
- }
5343
- } : {},
5344
- getDisplayAsButton(mainObject?.name),
5345
- getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLookup, keywordsSearchBoxName })
5391
+ ...toolbars,
5346
5392
  ]
5347
5393
  }else {
5394
+ if(toolbarCount){
5395
+ toolbars.push(toolbarCount);
5396
+ }
5397
+ if(toolbarFilter){
5398
+ toolbars.push(toolbarFilter);
5399
+ }
5400
+ toolbars.push(toolbarReloadButton);
5401
+ if(mainObject?.permissions?.allowCreateListViews){
5402
+ toolbars.push(getSettingListviewToolbarButtonSchema());
5403
+ }
5404
+ toolbars.push(toolbarDisplayAsButton);
5405
+ toolbars.push(toolbarDQuickSearchBox);
5348
5406
  return [
5349
5407
  // "filter-toggler",
5350
5408
  ...(headerToolbarItems || []),
@@ -5353,56 +5411,12 @@ function getObjectHeaderToolbar(mainObject, fields, formFactor, {
5353
5411
  "type": "columns-toggler",
5354
5412
  "className": "hidden"
5355
5413
  },
5414
+ ...toolbars,
5356
5415
  // {
5357
5416
  // "type": "columns-toggler",
5358
5417
  // "className": "mr-2"
5359
5418
  // },
5360
- hiddenCount ? {} : {
5361
- "type": "tpl",
5362
- "tpl": "${count} " + i18next.t('frontend_record_sum')
5363
- },
5364
- filterVisible ? {
5365
- "label": i18next.t('frontend_button_search_tooltip'),
5366
- "icon": "fa fa-filter",
5367
- //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5368
- // "tooltip": i18next.t('frontend_button_search_tooltip'),
5369
- // "tooltipPlacement": "top",
5370
- "type": "button",
5371
- "badge": {
5372
- "offset": [
5373
- -5,
5374
- 1
5375
- ],
5376
- "size":8,
5377
- "animation": true,
5378
- "visibleOn": "${isFieldsFilterEmpty == false && isLookup != true}"
5379
- },
5380
- "align": "right",
5381
- "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5382
- "onEvent": {
5383
- "click": {
5384
- "actions": [
5385
- {
5386
- "actionType": "custom",
5387
- "script": onFieldsFilterToggleScript
5388
- }
5389
- ]
5390
- }
5391
- }
5392
- } : {},
5393
- {
5394
- "type": "reload",
5395
- "align": "right",
5396
- //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5397
- // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5398
- "tooltip":"",
5399
- "tooltipPlacement": "top",
5400
- "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5401
- },
5402
5419
  // getExportExcelToolbarButtonSchema(),
5403
- mainObject?.permissions?.allowCreateListViews ? getSettingListviewToolbarButtonSchema() : {},
5404
- getDisplayAsButton(mainObject?.name),
5405
- getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLookup, keywordsSearchBoxName }),
5406
5420
  // {
5407
5421
  // "type": "drag-toggler",
5408
5422
  // "align": "right"
@@ -6020,13 +6034,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
6020
6034
  }
6021
6035
 
6022
6036
  let pickerSchema = null;
6023
- if(ctx.formFactor === 'SMALL'){
6024
- pickerSchema = await getListSchema$1(tableFields, {
6025
- top: top,
6026
- ...ctx,
6027
- actions: false
6028
- });
6029
- }else {
6037
+ {
6030
6038
  pickerSchema = await getTableSchema$1(tableFields, {
6031
6039
  labelFieldName: refObjectConfig.NAME_FIELD_KEY,
6032
6040
  top: top,
@@ -6395,6 +6403,7 @@ async function lookupToAmis(field, readonly, ctx){
6395
6403
  }
6396
6404
 
6397
6405
  if(referenceTo.objectName === "space_users" && field.reference_to_field === "user"){
6406
+ ctx.onlyDisplayLookLabel = true;
6398
6407
  if(ctx.idsDependOn){
6399
6408
  // ids人员点选模式
6400
6409
  return await lookupToAmisIdsPicker(field, readonly, ctx);
@@ -6498,6 +6507,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
6498
6507
  pickerSchema = await getTableSchema$1(tableFields, {
6499
6508
  labelFieldName: refObjectConfig.NAME_FIELD_KEY,
6500
6509
  top: top,
6510
+ isLookup: true,
6501
6511
  ...ctx
6502
6512
  });
6503
6513
 
@@ -6540,8 +6550,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
6540
6550
  /*
6541
6551
  * @Author: baozhoutao@steedos.com
6542
6552
  * @Date: 2023-01-13 17:27:54
6543
- * @LastEditors: liaodaxue
6544
- * @LastEditTime: 2023-07-27 17:33:54
6553
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
6554
+ * @LastEditTime: 2023-08-28 17:45:38
6545
6555
  * @Description:
6546
6556
  */
6547
6557
 
@@ -6603,14 +6613,29 @@ const getMarkdownFieldSchema = (field, readonly, ctx)=>{
6603
6613
 
6604
6614
  const getHtmlFieldSchema = (field, readonly, ctx)=>{
6605
6615
  if(readonly){
6616
+ // return {
6617
+ // "type": "control",
6618
+ // "label": field.label,
6619
+ // "body": {
6620
+ // "type": "html",
6621
+ // "name": field.name
6622
+ // }
6623
+ // }
6606
6624
  return {
6607
- "type": "control",
6608
- "label": field.label,
6609
- "body": {
6610
- "type": "html",
6611
- "name": field.name
6612
- }
6625
+ "type": "input-rich-text",
6626
+ "receiver": "${context.rootUrl}/s3/images",
6627
+ "name": field.name,
6628
+ "options": {
6629
+ "plugins": [
6630
+ "autoresize"
6631
+ ],
6632
+ // "max_height": 2000,
6633
+ "statusbar": false,
6634
+ "readonly": true,
6635
+ "toolbar": false,
6636
+ "menubar": false
6613
6637
  }
6638
+ }
6614
6639
  }else {
6615
6640
  return {
6616
6641
  "type": "input-rich-text",
@@ -7388,7 +7413,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
7388
7413
  convertData.className = 'm-1';
7389
7414
  }
7390
7415
  if(readonly){
7391
- convertData.className = `${convertData.className} md:border-b`;
7416
+ convertData.className = `${convertData.className} border-b`;
7392
7417
  }
7393
7418
  if(readonly){
7394
7419
  convertData.quickEdit = false;
@@ -8093,7 +8118,7 @@ async function getMobileTableColumns(fields, options){
8093
8118
  let tpl = "";
8094
8119
  if(field.is_name || field.name === options.labelFieldName){
8095
8120
  nameField = field;
8096
- options.onlyDisplayLabel = true;
8121
+ options.onlyDisplayLookLabel = true;
8097
8122
  tpl = await getFieldTpl(field, options);
8098
8123
  }
8099
8124
  else if(field.type === 'avatar' || field.type === 'image' || field.type === 'file'){
@@ -8102,7 +8127,7 @@ async function getMobileTableColumns(fields, options){
8102
8127
  }
8103
8128
  else {
8104
8129
  if(field.type === 'lookup' || field.type === 'master_detail'){
8105
- options.onlyDisplayLabel = true;
8130
+ options.onlyDisplayLookLabel = true;
8106
8131
  }
8107
8132
  tpl = await getFieldTpl(field, options);
8108
8133
  }
@@ -8304,7 +8329,12 @@ async function getTableSchema$1(fields, options){
8304
8329
  options = {};
8305
8330
  }
8306
8331
  let columns = [];
8307
- if(options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1){
8332
+ let useMobileColumns = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
8333
+ if(isLookup){
8334
+ // 在lookup手机端列表模式调式好之前不使用getMobileTableColumns
8335
+ useMobileColumns = false;
8336
+ }
8337
+ if(useMobileColumns){
8308
8338
  columns = await getMobileTableColumns(fields, options);
8309
8339
  }
8310
8340
  else {
@@ -8324,7 +8354,7 @@ async function getTableSchema$1(fields, options){
8324
8354
  columns: columns,
8325
8355
  syncLocation: false,
8326
8356
  keepItemSelectionOnPageChange: true,
8327
- checkOnItemClick: false,
8357
+ checkOnItemClick: isLookup ? true : false,
8328
8358
  labelTpl: `\${${options.labelFieldName}}`,
8329
8359
  autoFillHeight: false, // 自动高度效果不理想,先关闭
8330
8360
  columnsTogglable: false,
@@ -10291,7 +10321,7 @@ const getRecordPermissions = async (objectName, recordId)=>{
10291
10321
  * @Author: baozhoutao@steedos.com
10292
10322
  * @Date: 2022-07-05 15:55:39
10293
10323
  * @LastEditors: liaodaxue
10294
- * @LastEditTime: 2023-08-21 14:50:21
10324
+ * @LastEditTime: 2023-08-28 14:55:23
10295
10325
  * @Description:
10296
10326
  */
10297
10327
 
@@ -10437,11 +10467,16 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
10437
10467
  // }
10438
10468
  const recordRelatedListHeader = await getObjectRecordDetailRelatedListHeader(relatedObjectUiSchema, relatedLabel, ctx);
10439
10469
  const componentId = `steedos-record-related-list-${relatedObjectName}`;
10470
+ const isMobile = window.innerWidth < 768;
10471
+ let headerToolbar = [];
10472
+ if(!isMobile){
10473
+ headerToolbar.push("bulkActions");
10474
+ }
10440
10475
  const options = {
10441
10476
  globalFilter,
10442
10477
  defaults: {
10443
10478
  listSchema: {
10444
- headerToolbar:["bulkActions"],
10479
+ headerToolbar,
10445
10480
  columnsTogglable: false,
10446
10481
  onEvent: {
10447
10482
  [`@data.changed.${relatedObjectName}`]: {