@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.cjs.js CHANGED
@@ -427,7 +427,7 @@ function getContrastColor(bgColor) {
427
427
  * @Author: baozhoutao@steedos.com
428
428
  * @Date: 2022-05-23 09:53:08
429
429
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
430
- * @LastEditTime: 2023-08-03 18:07:54
430
+ * @LastEditTime: 2023-08-29 15:04:39
431
431
  * @Description:
432
432
  */
433
433
 
@@ -531,7 +531,7 @@ function getRelatedFieldTpl(field, ctx){
531
531
  linkTarget = "target='_blank'";
532
532
  }
533
533
 
534
- const onlyDisplayLabel = ctx.onlyDisplayLabel;
534
+ const onlyDisplayLookLabel = ctx.onlyDisplayLookLabel;
535
535
 
536
536
  let fieldDataStrTpl = `data._display.${field.name}`;
537
537
 
@@ -542,7 +542,7 @@ function getRelatedFieldTpl(field, ctx){
542
542
  if(_.isString(field.reference_to) || !field.reference_to){
543
543
  if(field.multiple){
544
544
  let labelTpl = `<%=item.label%>`;
545
- if(!onlyDisplayLabel){
545
+ if(!onlyDisplayLookLabel){
546
546
  const href = Router.getObjectDetailPath({
547
547
  formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
548
548
  });
@@ -560,7 +560,7 @@ function getRelatedFieldTpl(field, ctx){
560
560
  objectNameTpl = `\${${field.name}.objectName}`;
561
561
  recordIdTpl = `\${${field.name}.value}`;
562
562
  }
563
- if(!onlyDisplayLabel){
563
+ if(!onlyDisplayLookLabel){
564
564
  const href = Router.getObjectDetailPath({
565
565
  formFactor: ctx.formFactor, appId: "${appId}", objectName: `${objectNameTpl}`, recordId: `${recordIdTpl}`
566
566
  });
@@ -572,7 +572,7 @@ function getRelatedFieldTpl(field, ctx){
572
572
 
573
573
  }else {
574
574
  let labelTpl = `<%=item.label%>`;
575
- if(!onlyDisplayLabel){
575
+ if(!onlyDisplayLookLabel){
576
576
  const href = Router.getObjectDetailPath({
577
577
  formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
578
578
  });
@@ -625,7 +625,7 @@ function getLocationTpl(field){
625
625
  }
626
626
 
627
627
  async function getFieldTpl (field, options){
628
- if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLabel){
628
+ if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel){
629
629
  return getNameTpl(field, options)
630
630
  }
631
631
  switch (field.type) {
@@ -3079,6 +3079,7 @@ const getObjectListViewButtonsSchemas = (objectSchema, ctx)=>{
3079
3079
  return {
3080
3080
  "type": "button",
3081
3081
  "icon": "fa fa-angle-down",
3082
+ "className": "mr-0",
3082
3083
  "onEvent": {
3083
3084
  "click": {
3084
3085
  "actions": [
@@ -5302,76 +5303,133 @@ function getObjectHeaderToolbar(mainObject, fields, formFactor, {
5302
5303
  if(isMobile){
5303
5304
  showDisplayAs = false;
5304
5305
  }
5306
+ let toolbarCount;
5307
+ if(!hiddenCount){
5308
+ toolbarCount = {
5309
+ "type": "tpl",
5310
+ "tpl": "${count} " + i18next__default["default"].t('frontend_record_sum')
5311
+ };
5312
+ }
5313
+ let toolbarReloadButton;
5305
5314
  if(formFactor === 'SMALL'){
5306
- const onReloadScript = `
5307
- const scope = event.context.scoped;
5308
- var listView = scope.parent.getComponents().find(function(n){
5309
- return n.props.type === "crud";
5310
- });
5311
- listView.handleChangePage(1);
5312
- `;
5315
+ // const onReloadScript = `
5316
+ // const scope = event.context.scoped;
5317
+ // var listView = scope.parent.getComponents().find(function(n){
5318
+ // return n.props.type === "crud";
5319
+ // });
5320
+ // listView.handleChangePage(1);
5321
+ // `;
5322
+ // toolbarReloadButton = {
5323
+ // // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页,这在加载更多按钮的翻页模式下会有问题
5324
+ // "type": "button",
5325
+ // "align": "right",
5326
+ // //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5327
+ // // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5328
+ // "tooltipPlacement": "top",
5329
+ // "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5330
+ // "label": "",
5331
+ // "icon": "fa fa-sync",
5332
+ // "visibleOn": "${!showFieldsFilter}",
5333
+ // "onEvent": {
5334
+ // "click": {
5335
+ // "actions": [
5336
+ // {
5337
+ // "actionType": "custom",
5338
+ // "script": onReloadScript
5339
+ // }
5340
+ // ]
5341
+ // }
5342
+ // },
5343
+ // };
5344
+
5345
+ // 后续如果换成加载更多按钮的翻页模式的话,不可以直接使用下面的reload,需要换成上面的自定义脚本模式
5346
+ toolbarReloadButton = {
5347
+ "type": "reload",
5348
+ "align": "right",
5349
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5350
+ // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5351
+ "tooltip":"",
5352
+ "tooltipPlacement": "top",
5353
+ "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5354
+ };
5355
+ }
5356
+ else {
5357
+ toolbarReloadButton = {
5358
+ "type": "reload",
5359
+ "align": "right",
5360
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5361
+ // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5362
+ "tooltip":"",
5363
+ "tooltipPlacement": "top",
5364
+ "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5365
+ };
5366
+ }
5367
+ let toolbarFilter;
5368
+ if(filterVisible){
5369
+ toolbarFilter ={
5370
+ "label": i18next__default["default"].t('frontend_button_search_tooltip'),
5371
+ "icon": "fa fa-filter",
5372
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5373
+ // "tooltip": i18next.t('frontend_button_search_tooltip'),
5374
+ // "tooltipPlacement": "top",
5375
+ "type": "button",
5376
+ "badge": {
5377
+ "offset": [
5378
+ -5,
5379
+ 1
5380
+ ],
5381
+ "size":8,
5382
+ "animation": true,
5383
+ "visibleOn": "${isFieldsFilterEmpty == false && isLookup != true}"
5384
+ },
5385
+ "align": "right",
5386
+ "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5387
+ "onEvent": {
5388
+ "click": {
5389
+ "actions": [
5390
+ {
5391
+ "actionType": "custom",
5392
+ "script": onFieldsFilterToggleScript
5393
+ }
5394
+ ]
5395
+ }
5396
+ }
5397
+ };
5398
+ }
5399
+ let toolbarDisplayAsButton = getDisplayAsButton(mainObject?.name);
5400
+ let toolbarDQuickSearchBox = getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLookup, keywordsSearchBoxName });
5401
+
5402
+ // toolbars返回的数组元素不可以是空对象{},比如hiddenCount ? {} : {"type": "tpl",...},因为空对象最终还是会生成一个空的.antd-Crud-toolbar-item dom
5403
+ // 当出现空的.antd-Crud-toolbar-item dom时会影响toolbar元素的maring-right css样式计算,如果有动态需要应该加到动态数组变量toolbars中
5404
+ let toolbars = [];
5405
+ if(formFactor === 'SMALL'){
5406
+ if(toolbarCount){
5407
+ toolbars.push(toolbarCount);
5408
+ }
5409
+ toolbars.push(toolbarReloadButton);
5410
+ if(toolbarFilter){
5411
+ toolbars.push(toolbarFilter);
5412
+ }
5413
+ toolbars.push(toolbarDisplayAsButton);
5414
+ toolbars.push(toolbarDQuickSearchBox);
5313
5415
  return [
5314
5416
  // "bulkActions",
5315
5417
  ...(headerToolbarItems || []),
5316
- hiddenCount ? {} :{
5317
- "type": "tpl",
5318
- "tpl": "${count} " + i18next__default["default"].t('frontend_record_sum')
5319
- },
5320
- {
5321
- // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页
5322
- "type": "button",
5323
- "align": "right",
5324
- //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5325
- // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5326
- "tooltipPlacement": "top",
5327
- "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5328
- "label": "",
5329
- "icon": "fa fa-sync",
5330
- "visibleOn": "${!showFieldsFilter}",
5331
- "onEvent": {
5332
- "click": {
5333
- "actions": [
5334
- {
5335
- "actionType": "custom",
5336
- "script": onReloadScript
5337
- }
5338
- ]
5339
- }
5340
- },
5341
- },
5342
- filterVisible ? {
5343
- "label": i18next__default["default"].t('frontend_button_search_tooltip'),
5344
- "icon": "fa fa-search",
5345
- "type": "button",
5346
- "tooltipPlacement": "top",
5347
- //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5348
- // "tooltip": i18next.t('frontend_button_search_tooltip'),
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
- getDisplayAsButton(mainObject?.name),
5372
- getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLookup, keywordsSearchBoxName })
5418
+ ...toolbars,
5373
5419
  ]
5374
5420
  }else {
5421
+ if(toolbarCount){
5422
+ toolbars.push(toolbarCount);
5423
+ }
5424
+ if(toolbarFilter){
5425
+ toolbars.push(toolbarFilter);
5426
+ }
5427
+ toolbars.push(toolbarReloadButton);
5428
+ if(mainObject?.permissions?.allowCreateListViews){
5429
+ toolbars.push(getSettingListviewToolbarButtonSchema());
5430
+ }
5431
+ toolbars.push(toolbarDisplayAsButton);
5432
+ toolbars.push(toolbarDQuickSearchBox);
5375
5433
  return [
5376
5434
  // "filter-toggler",
5377
5435
  ...(headerToolbarItems || []),
@@ -5380,56 +5438,12 @@ function getObjectHeaderToolbar(mainObject, fields, formFactor, {
5380
5438
  "type": "columns-toggler",
5381
5439
  "className": "hidden"
5382
5440
  },
5441
+ ...toolbars,
5383
5442
  // {
5384
5443
  // "type": "columns-toggler",
5385
5444
  // "className": "mr-2"
5386
5445
  // },
5387
- hiddenCount ? {} : {
5388
- "type": "tpl",
5389
- "tpl": "${count} " + i18next__default["default"].t('frontend_record_sum')
5390
- },
5391
- filterVisible ? {
5392
- "label": i18next__default["default"].t('frontend_button_search_tooltip'),
5393
- "icon": "fa fa-filter",
5394
- //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5395
- // "tooltip": i18next.t('frontend_button_search_tooltip'),
5396
- // "tooltipPlacement": "top",
5397
- "type": "button",
5398
- "badge": {
5399
- "offset": [
5400
- -5,
5401
- 1
5402
- ],
5403
- "size":8,
5404
- "animation": true,
5405
- "visibleOn": "${isFieldsFilterEmpty == false && isLookup != true}"
5406
- },
5407
- "align": "right",
5408
- "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5409
- "onEvent": {
5410
- "click": {
5411
- "actions": [
5412
- {
5413
- "actionType": "custom",
5414
- "script": onFieldsFilterToggleScript
5415
- }
5416
- ]
5417
- }
5418
- }
5419
- } : {},
5420
- {
5421
- "type": "reload",
5422
- "align": "right",
5423
- //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5424
- // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5425
- "tooltip":"",
5426
- "tooltipPlacement": "top",
5427
- "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5428
- },
5429
5446
  // getExportExcelToolbarButtonSchema(),
5430
- mainObject?.permissions?.allowCreateListViews ? getSettingListviewToolbarButtonSchema() : {},
5431
- getDisplayAsButton(mainObject?.name),
5432
- getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLookup, keywordsSearchBoxName }),
5433
5447
  // {
5434
5448
  // "type": "drag-toggler",
5435
5449
  // "align": "right"
@@ -6047,13 +6061,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
6047
6061
  }
6048
6062
 
6049
6063
  let pickerSchema = null;
6050
- if(ctx.formFactor === 'SMALL'){
6051
- pickerSchema = await getListSchema$1(tableFields, {
6052
- top: top,
6053
- ...ctx,
6054
- actions: false
6055
- });
6056
- }else {
6064
+ {
6057
6065
  pickerSchema = await getTableSchema$1(tableFields, {
6058
6066
  labelFieldName: refObjectConfig.NAME_FIELD_KEY,
6059
6067
  top: top,
@@ -6422,6 +6430,7 @@ async function lookupToAmis(field, readonly, ctx){
6422
6430
  }
6423
6431
 
6424
6432
  if(referenceTo.objectName === "space_users" && field.reference_to_field === "user"){
6433
+ ctx.onlyDisplayLookLabel = true;
6425
6434
  if(ctx.idsDependOn){
6426
6435
  // ids人员点选模式
6427
6436
  return await lookupToAmisIdsPicker(field, readonly, ctx);
@@ -6525,6 +6534,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
6525
6534
  pickerSchema = await getTableSchema$1(tableFields, {
6526
6535
  labelFieldName: refObjectConfig.NAME_FIELD_KEY,
6527
6536
  top: top,
6537
+ isLookup: true,
6528
6538
  ...ctx
6529
6539
  });
6530
6540
 
@@ -6567,8 +6577,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
6567
6577
  /*
6568
6578
  * @Author: baozhoutao@steedos.com
6569
6579
  * @Date: 2023-01-13 17:27:54
6570
- * @LastEditors: liaodaxue
6571
- * @LastEditTime: 2023-07-27 17:33:54
6580
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
6581
+ * @LastEditTime: 2023-08-28 17:45:38
6572
6582
  * @Description:
6573
6583
  */
6574
6584
 
@@ -6630,14 +6640,29 @@ const getMarkdownFieldSchema = (field, readonly, ctx)=>{
6630
6640
 
6631
6641
  const getHtmlFieldSchema = (field, readonly, ctx)=>{
6632
6642
  if(readonly){
6643
+ // return {
6644
+ // "type": "control",
6645
+ // "label": field.label,
6646
+ // "body": {
6647
+ // "type": "html",
6648
+ // "name": field.name
6649
+ // }
6650
+ // }
6633
6651
  return {
6634
- "type": "control",
6635
- "label": field.label,
6636
- "body": {
6637
- "type": "html",
6638
- "name": field.name
6639
- }
6652
+ "type": "input-rich-text",
6653
+ "receiver": "${context.rootUrl}/s3/images",
6654
+ "name": field.name,
6655
+ "options": {
6656
+ "plugins": [
6657
+ "autoresize"
6658
+ ],
6659
+ // "max_height": 2000,
6660
+ "statusbar": false,
6661
+ "readonly": true,
6662
+ "toolbar": false,
6663
+ "menubar": false
6640
6664
  }
6665
+ }
6641
6666
  }else {
6642
6667
  return {
6643
6668
  "type": "input-rich-text",
@@ -7415,7 +7440,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
7415
7440
  convertData.className = 'm-1';
7416
7441
  }
7417
7442
  if(readonly){
7418
- convertData.className = `${convertData.className} md:border-b`;
7443
+ convertData.className = `${convertData.className} border-b`;
7419
7444
  }
7420
7445
  if(readonly){
7421
7446
  convertData.quickEdit = false;
@@ -8120,7 +8145,7 @@ async function getMobileTableColumns(fields, options){
8120
8145
  let tpl = "";
8121
8146
  if(field.is_name || field.name === options.labelFieldName){
8122
8147
  nameField = field;
8123
- options.onlyDisplayLabel = true;
8148
+ options.onlyDisplayLookLabel = true;
8124
8149
  tpl = await getFieldTpl(field, options);
8125
8150
  }
8126
8151
  else if(field.type === 'avatar' || field.type === 'image' || field.type === 'file'){
@@ -8129,7 +8154,7 @@ async function getMobileTableColumns(fields, options){
8129
8154
  }
8130
8155
  else {
8131
8156
  if(field.type === 'lookup' || field.type === 'master_detail'){
8132
- options.onlyDisplayLabel = true;
8157
+ options.onlyDisplayLookLabel = true;
8133
8158
  }
8134
8159
  tpl = await getFieldTpl(field, options);
8135
8160
  }
@@ -8331,7 +8356,12 @@ async function getTableSchema$1(fields, options){
8331
8356
  options = {};
8332
8357
  }
8333
8358
  let columns = [];
8334
- if(options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1){
8359
+ let useMobileColumns = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
8360
+ if(isLookup){
8361
+ // 在lookup手机端列表模式调式好之前不使用getMobileTableColumns
8362
+ useMobileColumns = false;
8363
+ }
8364
+ if(useMobileColumns){
8335
8365
  columns = await getMobileTableColumns(fields, options);
8336
8366
  }
8337
8367
  else {
@@ -8351,7 +8381,7 @@ async function getTableSchema$1(fields, options){
8351
8381
  columns: columns,
8352
8382
  syncLocation: false,
8353
8383
  keepItemSelectionOnPageChange: true,
8354
- checkOnItemClick: false,
8384
+ checkOnItemClick: isLookup ? true : false,
8355
8385
  labelTpl: `\${${options.labelFieldName}}`,
8356
8386
  autoFillHeight: false, // 自动高度效果不理想,先关闭
8357
8387
  columnsTogglable: false,
@@ -10318,7 +10348,7 @@ const getRecordPermissions = async (objectName, recordId)=>{
10318
10348
  * @Author: baozhoutao@steedos.com
10319
10349
  * @Date: 2022-07-05 15:55:39
10320
10350
  * @LastEditors: liaodaxue
10321
- * @LastEditTime: 2023-08-21 14:50:21
10351
+ * @LastEditTime: 2023-08-28 14:55:23
10322
10352
  * @Description:
10323
10353
  */
10324
10354
 
@@ -10464,11 +10494,16 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
10464
10494
  // }
10465
10495
  const recordRelatedListHeader = await getObjectRecordDetailRelatedListHeader(relatedObjectUiSchema, relatedLabel, ctx);
10466
10496
  const componentId = `steedos-record-related-list-${relatedObjectName}`;
10497
+ const isMobile = window.innerWidth < 768;
10498
+ let headerToolbar = [];
10499
+ if(!isMobile){
10500
+ headerToolbar.push("bulkActions");
10501
+ }
10467
10502
  const options = {
10468
10503
  globalFilter,
10469
10504
  defaults: {
10470
10505
  listSchema: {
10471
- headerToolbar:["bulkActions"],
10506
+ headerToolbar,
10472
10507
  columnsTogglable: false,
10473
10508
  onEvent: {
10474
10509
  [`@data.changed.${relatedObjectName}`]: {