@steedos-widgets/amis-lib 1.2.10 → 1.2.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
@@ -430,7 +430,7 @@ function getContrastColor(bgColor) {
430
430
  * @Author: baozhoutao@steedos.com
431
431
  * @Date: 2022-05-23 09:53:08
432
432
  * @LastEditors: Please set LastEditors
433
- * @LastEditTime: 2023-05-18 16:34:39
433
+ * @LastEditTime: 2023-05-22 15:13:18
434
434
  * @Description:
435
435
  */
436
436
 
@@ -487,8 +487,9 @@ function getSelectMap(selectOptions){
487
487
  let map = {};
488
488
  _$1.forEach(selectOptions,(option)=>{
489
489
  const optionValue = option.value + '';
490
- if(option.color){
491
- const background = option.color.charAt(0) === '#' ? option.color : '#'+option.color;
490
+ const optionColor = option.color + '';
491
+ if(optionColor){
492
+ const background = optionColor.charAt(0) === '#' ? optionColor : '#'+optionColor;
492
493
  const color = getContrastColor(background);
493
494
  const optionColorStyle = 'background:'+background+';color:'+color;
494
495
  map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
@@ -1894,9 +1895,10 @@ const getSchema$1 = (uiSchema) => {
1894
1895
  {
1895
1896
  name: "template_url",
1896
1897
  label: "导入模板",
1897
- type: "tpl",
1898
- // type: "markdown",
1899
- // html: true,
1898
+ type: "markdown",
1899
+ options: {
1900
+ html: true
1901
+ },
1900
1902
  className: "whitespace-nowrap",
1901
1903
  },
1902
1904
  null,
@@ -2441,7 +2443,14 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2441
2443
  className: `button_${button.name}`
2442
2444
  }
2443
2445
  });
2444
- let dropdownButtons = ___default["default"].map(moreButtons, (button) => {
2446
+ let moreButtonsVisibleOn = '';
2447
+ let dropdownButtons = ___default["default"].map(moreButtons, (button, index) => {
2448
+ if(index === 0){
2449
+ moreButtonsVisibleOn = getButtonVisibleOn$1(button);
2450
+ }else {
2451
+ moreButtonsVisibleOn = moreButtonsVisibleOn + ' || ' +getButtonVisibleOn$1(button);
2452
+ }
2453
+
2445
2454
  return {
2446
2455
  type: 'steedos-object-button',
2447
2456
  name: button.name,
@@ -2451,12 +2460,13 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2451
2460
  });
2452
2461
  return {
2453
2462
  buttons: amisButtonsSchema,
2454
- moreButtons: dropdownButtons
2463
+ moreButtons: dropdownButtons,
2464
+ moreButtonsVisibleOn
2455
2465
  };
2456
2466
  };
2457
2467
 
2458
2468
  const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2459
- const { buttons, moreButtons } = getObjectDetailHeaderButtons(objectSchema, recordId);
2469
+ const { buttons, moreButtons, moreButtonsVisibleOn } = getObjectDetailHeaderButtons(objectSchema, recordId);
2460
2470
  if(ctx.formFactor === 'SMALL'){
2461
2471
  return {
2462
2472
  "type": "button",
@@ -2511,7 +2521,8 @@ const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2511
2521
  type: "steedos-dropdown-button",
2512
2522
  label: "",
2513
2523
  buttons: moreButtons,
2514
- className: 'slds-icon'
2524
+ className: 'slds-icon',
2525
+ visibleOn: moreButtonsVisibleOn
2515
2526
  };
2516
2527
  buttons.push(dropdownButtonsSchema);
2517
2528
  }
@@ -2743,6 +2754,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2743
2754
  if (!ctx) {
2744
2755
  ctx = {};
2745
2756
  }
2757
+ const btnSearchId = "btn_filter_form_search_" + new Date().getTime();
2746
2758
  const filterFormSchema = await getObjectFieldsFilterFormSchema(ctx);
2747
2759
  const onSearchScript = `
2748
2760
  const scope = event.context.scoped;
@@ -2759,7 +2771,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2759
2771
  // // 这会造成handleFilterSubmit时把移除掉的搜索项字段之前的值加到过滤条件中
2760
2772
  // for(var k in filterFormValues){
2761
2773
  // if(filterFormValues[k] === "" && !filterFormValues.hasOwnProperty(k)){
2762
- // removedValues[k] = "";
2774
+ // removedValues[k] = null;
2763
2775
  // }
2764
2776
  // }
2765
2777
  // listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
@@ -2798,7 +2810,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2798
2810
  const removedValues = {};
2799
2811
  for(var k in filterFormValues){
2800
2812
  if(/^__searchable__/.test(k)){
2801
- removedValues[k] = "";
2813
+ removedValues[k] = null;
2802
2814
  }
2803
2815
  }
2804
2816
  if(!event.data.isLookup){
@@ -2809,7 +2821,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2809
2821
  if(localListViewProps){
2810
2822
  localListViewProps = JSON.parse(localListViewProps);
2811
2823
  for(var k in localListViewProps){
2812
- removedValues[k] = "";
2824
+ removedValues[k] = null;
2813
2825
  }
2814
2826
  }
2815
2827
  }
@@ -2967,7 +2979,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2967
2979
  });
2968
2980
  const removedValues = {};
2969
2981
  removedKeys.forEach(function(key){
2970
- removedValues[key] = "";
2982
+ removedValues[key] = null;
2971
2983
  });
2972
2984
  filterForm.setValues(removedValues);//这里使用filterInnerForm也可以
2973
2985
 
@@ -2980,10 +2992,14 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2980
2992
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
2981
2993
  if(localListViewProps){
2982
2994
  localListViewProps = JSON.parse(localListViewProps);
2983
- // const removedValues = {};
2984
- removedKeys.forEach(function(key){
2985
- delete localListViewProps[key];
2986
- // removedValues[key] = "";
2995
+ _.each(localListViewProps, function(n,k){
2996
+ // __searchable__开头的不在searchableFields范围则清除其值
2997
+ let isRemoved = !!removedFields.find(function(fieldName){
2998
+ return new RegExp("__searchable__\.*" + fieldName + "$").test(k);
2999
+ });
3000
+ if(isRemoved){
3001
+ delete localListViewProps[k];
3002
+ }
2987
3003
  });
2988
3004
  sessionStorage.setItem(listViewPropsStoreKey, JSON.stringify(localListViewProps));
2989
3005
  }
@@ -3017,9 +3033,10 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3017
3033
  "body": [
3018
3034
  {
3019
3035
  "type": "button",
3036
+ "id": btnSearchId,
3020
3037
  "label": "搜索",
3021
3038
  "icon": "fa fa-search",
3022
- "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3039
+ // "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3023
3040
  "onEvent": {
3024
3041
  "click": {
3025
3042
  "actions": [
@@ -3035,7 +3052,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3035
3052
  "type": "button",
3036
3053
  "label": "取消",
3037
3054
  "name": "btn_filter_form_cancel",
3038
- "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3055
+ // "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3039
3056
  "onEvent": {
3040
3057
  "click": {
3041
3058
  "actions": [
@@ -3150,6 +3167,10 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3150
3167
  "actionType": "custom",
3151
3168
  "script": onSearchableFieldsChangeScript
3152
3169
  },
3170
+ {
3171
+ "actionType": "click",
3172
+ "componentId": btnSearchId
3173
+ },
3153
3174
  {
3154
3175
  "componentId": "",
3155
3176
  "args": {},
@@ -3504,7 +3525,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3504
3525
  // "tpl": "${(record && uiSchema && record[uiSchema.NAME_FIELD_KEY]) || name}",
3505
3526
  "inline": false,
3506
3527
  "wrapperComponent": "",
3507
- "className": "leading-5 text-xl font-bold"
3528
+ "className": "record-detail-header-name leading-5 text-xl font-bold"
3508
3529
  }
3509
3530
  ],
3510
3531
  "columnClassName": "p-l-xs"
@@ -3513,6 +3534,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3513
3534
  "className": "flex justify-between"
3514
3535
  }
3515
3536
  ],
3537
+ "columnClassName": "flex-initial",
3516
3538
  "md": "auto",
3517
3539
  });
3518
3540
  }
@@ -3533,7 +3555,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3533
3555
  {
3534
3556
  "type": "grid",
3535
3557
  "columns": gridBody,
3536
- "className": "flex justify-between"
3558
+ "className": "flex justify-between flex-nowrap"
3537
3559
  }
3538
3560
  ],
3539
3561
  "hiddenOn": "${recordLoaded != true}"
@@ -3750,12 +3772,13 @@ const getNewListviewButtonSchema = ()=>{
3750
3772
  "type": "dialog",
3751
3773
  "title": "新建 列表视图",
3752
3774
  "data": {
3753
- "&": "$$",
3775
+ //"&":"$$",2.7、2.9、3.0在此处失效
3754
3776
  "all": "${uiSchema.list_views.all}",
3755
3777
  "list_view": "${uiSchema.list_views[listName]}",
3756
3778
  "appId": "${appId}",
3757
3779
  "global": "${global}",
3758
3780
  "targetObjectName": "${objectName}",
3781
+ "context": "${context}"
3759
3782
  },
3760
3783
  "body": [
3761
3784
  {
@@ -3899,12 +3922,13 @@ const getCopyListviewButtonSchema = ()=>{
3899
3922
  "type": "dialog",
3900
3923
  "title": "复制 列表视图",
3901
3924
  "data": {
3902
- "&": "$$",
3925
+ //"&":"$$",2.7、2.9、3.0在此处失效
3903
3926
  "listName": "${listName}",
3904
3927
  "targetObjectName": "${objectName}",
3905
3928
  "list_view": "${uiSchema.list_views[listName]}",
3906
3929
  "appId": "${appId}",
3907
- "global": "${global}"
3930
+ "global": "${global}",
3931
+ "context": "${context}"
3908
3932
  },
3909
3933
  "body": [
3910
3934
  {
@@ -4046,7 +4070,8 @@ const getRenameListviewButtonSchema = ()=>{
4046
4070
  "data": {
4047
4071
  "targetObjectName": "${objectName}",
4048
4072
  "recordId": "${uiSchema.list_views[listName]._id}",
4049
- "appId": "${appId}"
4073
+ "appId": "${appId}",
4074
+ "context": "${context}"
4050
4075
  },
4051
4076
  "body": [
4052
4077
  {
@@ -4103,6 +4128,7 @@ const getSetListviewShareButtonSchema = ()=>{
4103
4128
  "title": "共享设置",
4104
4129
  "data": {
4105
4130
  "recordId": "${uiSchema.list_views[listName]._id}",
4131
+ "context": "${context}"
4106
4132
  },
4107
4133
  "body": [
4108
4134
  {
@@ -4148,7 +4174,8 @@ const getSetListviewFiltersButtonSchema = ()=>{
4148
4174
  "targetObjectName": "${objectName}",
4149
4175
  "recordId": "${uiSchema.list_views[listName]._id}",
4150
4176
  "listName": "${listName}",
4151
- "appId": "${appId}"
4177
+ "appId": "${appId}",
4178
+ "context": "${context}"
4152
4179
  },
4153
4180
  "body": [
4154
4181
  {
@@ -4292,11 +4319,12 @@ const getSetListviewColumnsButtonSchema = ()=>{
4292
4319
  "type": "dialog",
4293
4320
  "title": "显示的列",
4294
4321
  "data": {
4295
- "&": "$$",
4322
+ //"&":"$$",2.7、2.9、3.0在此处失效
4296
4323
  "targetObjectName": "${objectName}",
4297
4324
  "recordId": "${uiSchema.list_views[listName]._id}",
4298
4325
  "listName": "${listName}",
4299
- "appId": "${appId}"
4326
+ "appId": "${appId}",
4327
+ "context": "${context}"
4300
4328
  },
4301
4329
  "body": [
4302
4330
  {
@@ -4445,11 +4473,12 @@ const getSetListviewSortButtonSchema = ()=>{
4445
4473
  "type": "dialog",
4446
4474
  "title": "默认排序规则",
4447
4475
  "data": {
4448
- "&": "$$",
4476
+ //"&":"$$",2.7、2.9、3.0在此处失效
4449
4477
  "targetObjectName": "${objectName}",
4450
4478
  "recordId": "${uiSchema.list_views[listName]._id}",
4451
4479
  "listName": "${listName}",
4452
- "appId": "${appId}"
4480
+ "appId": "${appId}",
4481
+ "context": "${context}"
4453
4482
  },
4454
4483
  "body": [
4455
4484
  {
@@ -5139,24 +5168,13 @@ function getLookupSapceUserTreeSchema(){
5139
5168
  "actionType": "custom",
5140
5169
  "script": `
5141
5170
  const scope = event.context.scoped;
5142
- //TODO: 将form中的value一同加入筛选内
5143
- // var filterForm = scope.parent.parent.getComponents().find(function(n){
5144
- // return n.props.type === "form";
5145
- // });
5146
- // var filterFormValues = filterForm.getValues();
5147
- filterFormValues={
5171
+ var filterFormValues={
5148
5172
  "__searchable__organizations_parents":event.data.value.value
5149
5173
  }
5150
5174
  var listView = scope.parent.getComponents().find(function(n){
5151
5175
  return n.props.type === "crud";
5152
5176
  });
5153
- const removedValues = {};
5154
- // for(var k in filterFormValues){
5155
- // if(filterFormValues[k] === "" && !filterFormValues.hasOwnProperty(k)){
5156
- // removedValues[k] = "";
5157
- // }
5158
- // }
5159
- listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
5177
+ listView.handleFilterSubmit(Object.assign({}, filterFormValues));
5160
5178
  `
5161
5179
  }
5162
5180
  ]
@@ -5270,7 +5288,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
5270
5288
 
5271
5289
  const source = await getApi$1(refObjectConfig, null, fields, {expand: true, alias: 'rows', queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
5272
5290
 
5273
- if(source.url){
5291
+ if(source.url && !ctx.inFilterForm){
5274
5292
  const depend_on = [];
5275
5293
  const sendOn = [];
5276
5294
  ___namespace.each(field.depend_on, (fName)=>{
@@ -5334,9 +5352,10 @@ async function lookupToAmisPicker(field, readonly, ctx){
5334
5352
  filters.push(fieldFilters);
5335
5353
  }
5336
5354
 
5355
+ const inFilterForm = ${ctx.inFilterForm};
5337
5356
  const filtersFunction = ${field.filtersFunction || field._filtersFunction};
5338
5357
 
5339
- if(filtersFunction){
5358
+ if(filtersFunction && !inFilterForm){
5340
5359
  const _filters = filtersFunction(filters, api.data.$self.__super.__super);
5341
5360
  if(_filters && _filters.length > 0){
5342
5361
  filters.push(_filters);
@@ -5556,7 +5575,8 @@ async function lookupToAmisSelect(field, readonly, ctx){
5556
5575
  sort = getListViewSort(listView);
5557
5576
  }
5558
5577
 
5559
- if(apiInfo.url){
5578
+ // 列表视图搜索栏中,即inFilterForm=true时,不需要执行depend_on
5579
+ if(apiInfo.url && !ctx.inFilterForm){
5560
5580
  const depend_on = [];
5561
5581
  const sendOn = [];
5562
5582
  ___namespace.each(field.depend_on, (fName)=>{
@@ -5593,9 +5613,10 @@ async function lookupToAmisSelect(field, readonly, ctx){
5593
5613
  filters.push(fieldFilters);
5594
5614
  }
5595
5615
 
5616
+ const inFilterForm = ${ctx.inFilterForm};
5596
5617
  const filtersFunction = ${field.filtersFunction || field._filtersFunction};
5597
5618
 
5598
- if(filtersFunction){
5619
+ if(filtersFunction && !inFilterForm){
5599
5620
  const _filters = filtersFunction(filters, api.data.$);
5600
5621
  if(_filters && _filters.length > 0){
5601
5622
  filters.push(_filters);
@@ -5621,7 +5642,14 @@ async function lookupToAmisSelect(field, readonly, ctx){
5621
5642
  referenceTo ? referenceTo.valueField.name : '';
5622
5643
  if(field.optionsFunction || field._optionsFunction){
5623
5644
  apiInfo.adaptor = `
5624
- payload.data.options = eval(${field.optionsFunction || field._optionsFunction})(api.data.$);
5645
+ var options = eval(${field.optionsFunction || field._optionsFunction})(api.data.$);
5646
+ if(api.data.$term){
5647
+ options = _.filter(options, function(o) {
5648
+ var label = o.label;
5649
+ return label.toLowerCase().indexOf(api.data.$term.toLowerCase()) > -1;
5650
+ });
5651
+ }
5652
+ payload.data.options = options;
5625
5653
  return payload;
5626
5654
  `;
5627
5655
  }
@@ -5757,7 +5785,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
5757
5785
  source.data.$term = "$term";
5758
5786
  source.data.$self = "$$";
5759
5787
 
5760
- if(idsDependOn && source.url){
5788
+ if(idsDependOn && source.url && !ctx.inFilterForm){
5761
5789
  source.sendOn = `\${${idsDependOn} && ${idsDependOn}.length}`;
5762
5790
  source.url = `${source.url}&depend_on_${idsDependOn}=\${${idsDependOn}|join}`;
5763
5791
  }
@@ -6599,7 +6627,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6599
6627
  convertData.className = fieldTypeClassName;
6600
6628
  }
6601
6629
 
6602
- if(field.visible_on){
6630
+ if(field.visible_on && !ctx.inFilterForm){
6603
6631
  // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
6604
6632
  if(field.visible_on.startsWith("{{")){
6605
6633
  convertData.visibleOn = `${field.visible_on.substring(2, field.visible_on.length -2).replace(/formData./g, 'data.')}`;
@@ -6692,7 +6720,7 @@ async function getFieldSearchable(perField, permissionFields, ctx){
6692
6720
  _field.multiple = true;
6693
6721
  _field.is_wide = false;
6694
6722
  _field.defaultValue = undefined;
6695
- const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true}));
6723
+ const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
6696
6724
  if(amisField){
6697
6725
  return amisField;
6698
6726
  }
@@ -7532,11 +7560,12 @@ async function getObjectDetail(objectSchema, recordId, ctx){
7532
7560
  "expression": "this.__deletedRecord != true"
7533
7561
  },
7534
7562
  {
7535
- "args": {
7536
- "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7537
- "blank": false
7538
- },
7539
- "actionType": "link",
7563
+ // "args": {
7564
+ // "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7565
+ // "blank": false
7566
+ // },
7567
+ "actionType": "custom",
7568
+ "script": "Steedos.goBack()",
7540
7569
  "expression": "this.__deletedRecord === true"
7541
7570
  }
7542
7571
  ]
@@ -7694,7 +7723,7 @@ async function getTableColumns(fields, options){
7694
7723
  tpl: tpl,
7695
7724
  toggled: field.toggled,
7696
7725
  className,
7697
- html: field.type === 'html' ? true : null
7726
+ options: field.type === 'html' ? {html: true} : null
7698
7727
  // toggled: true
7699
7728
  }, field.amis, {name: field.name}));
7700
7729
  }