@steedos-widgets/amis-lib 1.2.32 → 1.2.34

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
@@ -5139,7 +5139,8 @@ const getSettingListviewToolbarButtonSchema = ()=>{
5139
5139
  "type": "dropdown-button",
5140
5140
  "trigger": "click",
5141
5141
  "icon": "fa fa-cog",
5142
- "tooltip": i18next__default["default"].t('frontend_button_listview_control_tooltip'),
5142
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5143
+ // "tooltip": i18next.t('frontend_button_listview_control_tooltip'),
5143
5144
  "btnClassName": "antd-Button--iconOnly bg-white !p-2 rounded border-gray-300 text-gray-500",
5144
5145
  "align": "right",
5145
5146
  "visibleOn": "${!isLookup}",
@@ -5179,11 +5180,12 @@ const getDisplayAsButton = function(objectName, showDisplayAs){
5179
5180
  "rightIconClassName": "m-l-sm"
5180
5181
  }
5181
5182
  ];
5182
- const displayAsLabel = displayAs === 'split'? i18next__default["default"].t('frontend_display_type_is_split') : i18next__default["default"].t('frontend_display_type_is_table');
5183
+ displayAs === 'split'? i18next__default["default"].t('frontend_display_type_is_split') : i18next__default["default"].t('frontend_display_type_is_table');
5183
5184
  return {
5184
5185
  "type": "dropdown-button",
5185
5186
  "icon": "fa fa-table-columns",
5186
- "tooltip": `${i18next__default["default"].t('frontend_display_as')} ${displayAsLabel}`,
5187
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5188
+ // "tooltip": `${i18next.t('frontend_display_as')} ${displayAsLabel}`,
5187
5189
  "btnClassName": "antd-Button--iconOnly bg-white !p-2 rounded border-gray-300 text-gray-500",
5188
5190
  "align": "right",
5189
5191
  "visibleOn": "${window:innerWidth > 768 && !!!isLookup}",
@@ -5265,7 +5267,8 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5265
5267
  // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页
5266
5268
  "type": "button",
5267
5269
  "align": "right",
5268
- "tooltip": i18next__default["default"].t('frontend_button_reload_tooltip'),
5270
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5271
+ // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5269
5272
  "tooltipPlacement": "top",
5270
5273
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5271
5274
  "label": "",
@@ -5287,7 +5290,8 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5287
5290
  "icon": "fa fa-search",
5288
5291
  "type": "button",
5289
5292
  "tooltipPlacement": "top",
5290
- "tooltip": i18next__default["default"].t('frontend_button_search_tooltip'),
5293
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5294
+ // "tooltip": i18next.t('frontend_button_search_tooltip'),
5291
5295
  "badge": {
5292
5296
  "offset": [
5293
5297
  -5,
@@ -5332,7 +5336,9 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5332
5336
  {
5333
5337
  "type": "reload",
5334
5338
  "align": "right",
5335
- "tooltip": i18next__default["default"].t('frontend_button_reload_tooltip'),
5339
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5340
+ // "tooltip": i18next.t('frontend_button_reload_tooltip'),
5341
+ "tooltip":"",
5336
5342
  "tooltipPlacement": "top",
5337
5343
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5338
5344
  },
@@ -5342,8 +5348,9 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5342
5348
  filterVisible ? {
5343
5349
  "label": i18next__default["default"].t('frontend_button_search_tooltip'),
5344
5350
  "icon": "fa fa-search",
5345
- "tooltip": i18next__default["default"].t('frontend_button_search_tooltip'),
5346
- "tooltipPlacement": "top",
5351
+ //TODO: dropdown-button只支持在按钮上方配置提示,对于上方按钮的点击会有影响,为保持统一,暂时去除,等待amis优化,https://github.com/baidu/amis/issues/7330
5352
+ // "tooltip": i18next.t('frontend_button_search_tooltip'),
5353
+ // "tooltipPlacement": "top",
5347
5354
  "type": "button",
5348
5355
  "badge": {
5349
5356
  "offset": [
@@ -5449,9 +5456,16 @@ async function getSource(field, ctx) {
5449
5456
  valueField = `${ctx.fieldNamePrefix}${valueField}`;
5450
5457
  }
5451
5458
  data.$value = `$${valueField}`;
5452
- // data["&"] = "$$";
5459
+ data['$'] = `$$`;
5453
5460
  const requestAdaptor = `
5454
5461
  var filters = [['parent', '=', null]];
5462
+ const filtersFunction = ${field.filtersFunction || field._filtersFunction};
5463
+ if(filtersFunction){
5464
+ const _filters = filtersFunction(filters, api.data.$);
5465
+ if(_filters && _filters.length > 0){
5466
+ filters.push(_filters);
5467
+ }
5468
+ }
5455
5469
  api.data.query = api.data.query.replace(/{__filters}/g, JSON.stringify(filters));
5456
5470
  var defaultValue = api.data.$value;
5457
5471
  var optionsFiltersOp = "${field.multiple ? "in" : "="}";
@@ -5649,7 +5663,7 @@ function getLookupSapceUserTreeSchema(){
5649
5663
  const tree = [{
5650
5664
  "type": "input-tree",
5651
5665
  "className": "",
5652
- "inputClassName": "pl-0",
5666
+ "inputClassName": "p-0",
5653
5667
  "id": "u:7fd77b7915b0",
5654
5668
  "source": {
5655
5669
  "method": "post",
@@ -5710,7 +5724,7 @@ function getLookupSapceUserTreeSchema(){
5710
5724
  "left": "-200px",
5711
5725
  "width": "190px",
5712
5726
  "bottom": 0,
5713
- "top": "-14px",
5727
+ "top": "2px",
5714
5728
  "overflow": "auto",
5715
5729
  "min-height":"300px"
5716
5730
  },
@@ -5976,7 +5990,9 @@ async function lookupToAmisPicker(field, readonly, ctx){
5976
5990
  "margin-left":"200px",
5977
5991
  "min-height": "300px"
5978
5992
  };
5993
+ pickerSchema.className = pickerSchema.className || "" + " steedos-select-user";
5979
5994
  }
5995
+
5980
5996
  pickerSchema.headerToolbar = getObjectHeaderToolbar(refObjectConfig, ctx.formFactor, { headerToolbarItems });
5981
5997
  const isAllowCreate = refObjectConfig.permissions.allowCreate;
5982
5998
  if (isAllowCreate) {
@@ -6073,6 +6089,8 @@ async function lookupToAmisPicker(field, readonly, ctx){
6073
6089
  modalTitle: i18next__default["default"].t('frontend_form_please_select') + " " + refObjectConfig.label,
6074
6090
  labelField: referenceTo.labelField.name,
6075
6091
  valueField: referenceTo.valueField.name,
6092
+ // disabledOn: this._master目的是相关表新建时禁止编辑关联字段; this.relatedKey目的是相关表编辑时禁止编辑关联字段。
6093
+ disabledOn: `${readonly} || ( (this._master && (this._master.relatedKey ==='${field.name}')) || (this.relatedKey ==='${field.name}') )`,
6076
6094
  modalMode: 'dialog', //TODO 设置 dialog 或者 drawer,用来配置弹出方式
6077
6095
  source: source,
6078
6096
  size: "lg",
@@ -6253,6 +6271,8 @@ async function lookupToAmisSelect(field, readonly, ctx){
6253
6271
  joinValues: false,
6254
6272
  extractValue: true,
6255
6273
  clearable: true,
6274
+ // disabledOn: this._master目的是相关表新建时禁止编辑关联字段; this.relatedKey目的是相关表编辑时禁止编辑关联字段。
6275
+ disabledOn: `${readonly} || ( (this._master && (this._master.relatedKey ==='${field.name}')) || (this.relatedKey ==='${field.name}') )`,
6256
6276
  // labelField: labelField,
6257
6277
  // valueField: valueField,
6258
6278
  source: apiInfo,
@@ -6437,6 +6457,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
6437
6457
  valueField: referenceTo.valueField.name,
6438
6458
  modalMode: 'dialog',
6439
6459
  source: source,
6460
+ // disabledOn: this._master目的是相关表新建时禁止编辑关联字段; this.relatedKey目的是相关表编辑时禁止编辑关联字段。
6461
+ disabledOn: `${readonly} || ( (this._master && (this._master.relatedKey ==='${field.name}')) || (this.relatedKey ==='${field.name}') )`,
6440
6462
  size: "lg",
6441
6463
  pickerSchema: pickerSchema,
6442
6464
  joinValues: false,
@@ -6465,7 +6487,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
6465
6487
  * @Author: baozhoutao@steedos.com
6466
6488
  * @Date: 2023-01-13 17:27:54
6467
6489
  * @LastEditors: liaodaxue
6468
- * @LastEditTime: 2023-06-30 10:29:52
6490
+ * @LastEditTime: 2023-07-24 15:23:12
6469
6491
  * @Description:
6470
6492
  */
6471
6493
 
@@ -6487,21 +6509,39 @@ const getMarkdownFieldSchema = (field, readonly, ctx)=>{
6487
6509
  }
6488
6510
  }else {
6489
6511
  return {
6490
- "type": "group",
6512
+ "type": "control",
6513
+ "label": field.label,
6491
6514
  "body": [
6492
6515
  {
6493
- "type": "editor",
6494
- "name": field.name,
6495
- "language": "markdown",
6496
- },
6497
- {
6498
- "type": "markdown",
6499
- "name": field.name,
6500
- "options": {
6501
- "linkify": true,
6502
- "html": true,
6503
- "breaks": true
6504
- }
6516
+ "type": "tabs",
6517
+ "tabsMode": "strong",
6518
+ "className": "steedos-markdown",
6519
+ "tabs": [
6520
+ {
6521
+ "title": "Write",
6522
+ "tab": [
6523
+ {
6524
+ "type": "editor",
6525
+ "name": field.name,
6526
+ "language": "markdown",
6527
+ }
6528
+ ]
6529
+ },
6530
+ {
6531
+ "title": "Preview",
6532
+ "tab": [
6533
+ {
6534
+ "type": "markdown",
6535
+ "name": field.name,
6536
+ "options": {
6537
+ "linkify": true,
6538
+ "html": true,
6539
+ "breaks": true
6540
+ }
6541
+ }
6542
+ ]
6543
+ }
6544
+ ]
6505
6545
  }
6506
6546
  ]
6507
6547
  }
@@ -7447,26 +7487,45 @@ async function getQuickEditSchema(field, options){
7447
7487
  let labelField = quickEditSchema.body[0].labelField || "label";
7448
7488
  let valueField = quickEditSchema.body[0].valueField || "value";
7449
7489
  if (field.multiple) {
7490
+ /*
7491
+ 多选分两种情况。
7492
+ 第一种是减少选项时(判断新的数据是否比老的数据短),按照index删除_display中对应选项,保证回显没问题;
7493
+ 第二种是增加选项时,按照value的值,找到对应选项,并按照_display的规则为其赋值
7494
+ */
7450
7495
  TempDisplayField = `
7496
+ const preData = event.data.__super.${field.name};
7497
+ if(preData && event.data.${field.name}.length < preData.length){
7498
+ let deletedIndex;
7499
+ preData.forEach(function(item,index){
7500
+ if(_.indexOf(event.data.${field.name}, item) == -1) _display["${field.name}"].splice(index, 1);
7501
+ })
7502
+ }else{
7451
7503
  _display["${field.name}"] = [];
7452
- event.data.selectedItems.forEach(function(item,index){
7504
+ event.data.value.forEach(function(val,index){
7505
+ const item = _.find(event.data.selectedItems, { ${valueField}: val });
7453
7506
  _display["${field.name}"].push(
7454
7507
  {
7455
7508
  "label": item.${labelField},
7456
- "value": item.${valueField},
7509
+ "value": item[event.data.uiSchema.idFieldName],
7457
7510
  "objectName": "${field.reference_to}"
7458
7511
  }
7459
7512
  )
7460
7513
  })
7461
- `;
7514
+ }
7515
+
7516
+ `;
7462
7517
  } else {
7463
7518
  TempDisplayField = `
7519
+ if(event.data.value){
7464
7520
  _display["${field.name}"] = {
7465
7521
  "label": event.data.selectedItems.${labelField},
7466
- "value": event.data.selectedItems.${valueField},
7522
+ "value": event.data.selectedItems[event.data.uiSchema.idFieldName],
7467
7523
  "objectName": "${field.reference_to}"
7468
7524
  }
7469
- `;
7525
+ }else{
7526
+ _display["${field.name}"] = {}
7527
+ }
7528
+ `;
7470
7529
  }
7471
7530
  quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
7472
7531
  break;
@@ -7576,10 +7635,25 @@ async function getQuickEditSchema(field, options){
7576
7635
  return quickEditSchema;
7577
7636
  }
7578
7637
 
7638
+ function getFieldWidth(width){
7639
+ const defaultWidth = "unset";//用于使table内的td标签下生成div,实现将快速编辑按钮固定在右侧的效果,并不是为了unset效果
7640
+ if(typeof width == 'string'){
7641
+ if(isNaN(width)){
7642
+ return width;
7643
+ }else {
7644
+ return Number(width);
7645
+ }
7646
+ }else if(typeof width == 'number'){
7647
+ return width;
7648
+ }else {
7649
+ return defaultWidth;
7650
+ }
7651
+ }
7652
+
7579
7653
  async function getTableColumns(fields, options){
7580
7654
  const columns = [{name: '_index',type: 'text', width: 32, placeholder: ""}];
7581
7655
  const allowEdit = options.permissions?.allowEdit && options.permissions?.modifyAllRecords && !options.isLookup && options.enable_inline_edit != false;
7582
- const defaultWidth = "unset";//用于使table内的td标签下生成div,实现将快速编辑按钮固定在右侧的效果,并不是为了unset效果
7656
+
7583
7657
  for (const field of fields) {
7584
7658
  //增加quickEdit属性,实现快速编辑
7585
7659
  const quickEditSchema = allowEdit ? await getQuickEditSchema(field, options) : allowEdit;
@@ -7627,7 +7701,7 @@ async function getTableColumns(fields, options){
7627
7701
  type: "switch",
7628
7702
  name: field.name,
7629
7703
  label: field.label,
7630
- width: field.width || defaultWidth,
7704
+ width: getFieldWidth(field.width),
7631
7705
  toggled: field.toggled,
7632
7706
  static: true,
7633
7707
  className:"whitespace-nowrap",
@@ -7638,7 +7712,7 @@ async function getTableColumns(fields, options){
7638
7712
  type: "switch",
7639
7713
  name: field.name,
7640
7714
  label: field.label,
7641
- width: field.width || defaultWidth,
7715
+ width: getFieldWidth(field.width),
7642
7716
  toggled: field.toggled,
7643
7717
  quickEdit: quickEditSchema,
7644
7718
  static: true,
@@ -7658,7 +7732,7 @@ async function getTableColumns(fields, options){
7658
7732
  label: field.label,
7659
7733
  map: map,
7660
7734
  sortable: field.sortable,
7661
- width: field.width || defaultWidth,
7735
+ width: getFieldWidth(field.width),
7662
7736
  toggled: field.toggled,
7663
7737
  className,
7664
7738
  static: true,
@@ -7692,7 +7766,7 @@ async function getTableColumns(fields, options){
7692
7766
  label: field.label,
7693
7767
  sortable: field.sortable,
7694
7768
  // searchable: field.searchable,
7695
- width: field.width || defaultWidth,
7769
+ width: getFieldWidth(field.width),
7696
7770
  type: type,
7697
7771
  tpl: tpl,
7698
7772
  toggled: field.toggled,
@@ -7990,14 +8064,7 @@ async function getTableOperation(ctx){
7990
8064
  onOpenApi: {
7991
8065
  url: `\${context.rootUrl}/service/api/@\${objectName}/recordPermissions/\${_id}`,
7992
8066
  method: "get",
7993
- data: {
7994
- $: "$$",
7995
- objectName: "${objectName}",
7996
- listViewId: "${listViewId}",
7997
- appId: "${appId}",
7998
- formFactor: "${formFactor}",
7999
- context: `\${context}`
8000
- },
8067
+ requestAdaptor: "api.data={}; return api;",
8001
8068
  headers: {
8002
8069
  Authorization: "Bearer ${context.tenantId},${context.authToken}"
8003
8070
  },