@steedos-widgets/amis-lib 1.2.10 → 1.2.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
@@ -403,7 +403,7 @@ function getContrastColor(bgColor) {
403
403
  * @Author: baozhoutao@steedos.com
404
404
  * @Date: 2022-05-23 09:53:08
405
405
  * @LastEditors: Please set LastEditors
406
- * @LastEditTime: 2023-05-18 16:34:39
406
+ * @LastEditTime: 2023-05-22 15:13:18
407
407
  * @Description:
408
408
  */
409
409
 
@@ -460,8 +460,9 @@ function getSelectMap(selectOptions){
460
460
  let map = {};
461
461
  forEach(selectOptions,(option)=>{
462
462
  const optionValue = option.value + '';
463
- if(option.color){
464
- const background = option.color.charAt(0) === '#' ? option.color : '#'+option.color;
463
+ const optionColor = option.color + '';
464
+ if(optionColor){
465
+ const background = optionColor.charAt(0) === '#' ? optionColor : '#'+optionColor;
465
466
  const color = getContrastColor(background);
466
467
  const optionColorStyle = 'background:'+background+';color:'+color;
467
468
  map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
@@ -1867,9 +1868,10 @@ const getSchema$1 = (uiSchema) => {
1867
1868
  {
1868
1869
  name: "template_url",
1869
1870
  label: "导入模板",
1870
- type: "tpl",
1871
- // type: "markdown",
1872
- // html: true,
1871
+ type: "markdown",
1872
+ options: {
1873
+ html: true
1874
+ },
1873
1875
  className: "whitespace-nowrap",
1874
1876
  },
1875
1877
  null,
@@ -2716,6 +2718,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2716
2718
  if (!ctx) {
2717
2719
  ctx = {};
2718
2720
  }
2721
+ const btnSearchId = "btn_filter_form_search_" + new Date().getTime();
2719
2722
  const filterFormSchema = await getObjectFieldsFilterFormSchema(ctx);
2720
2723
  const onSearchScript = `
2721
2724
  const scope = event.context.scoped;
@@ -2732,7 +2735,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2732
2735
  // // 这会造成handleFilterSubmit时把移除掉的搜索项字段之前的值加到过滤条件中
2733
2736
  // for(var k in filterFormValues){
2734
2737
  // if(filterFormValues[k] === "" && !filterFormValues.hasOwnProperty(k)){
2735
- // removedValues[k] = "";
2738
+ // removedValues[k] = null;
2736
2739
  // }
2737
2740
  // }
2738
2741
  // listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
@@ -2771,7 +2774,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2771
2774
  const removedValues = {};
2772
2775
  for(var k in filterFormValues){
2773
2776
  if(/^__searchable__/.test(k)){
2774
- removedValues[k] = "";
2777
+ removedValues[k] = null;
2775
2778
  }
2776
2779
  }
2777
2780
  if(!event.data.isLookup){
@@ -2782,7 +2785,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2782
2785
  if(localListViewProps){
2783
2786
  localListViewProps = JSON.parse(localListViewProps);
2784
2787
  for(var k in localListViewProps){
2785
- removedValues[k] = "";
2788
+ removedValues[k] = null;
2786
2789
  }
2787
2790
  }
2788
2791
  }
@@ -2940,7 +2943,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2940
2943
  });
2941
2944
  const removedValues = {};
2942
2945
  removedKeys.forEach(function(key){
2943
- removedValues[key] = "";
2946
+ removedValues[key] = null;
2944
2947
  });
2945
2948
  filterForm.setValues(removedValues);//这里使用filterInnerForm也可以
2946
2949
 
@@ -2953,10 +2956,14 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2953
2956
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
2954
2957
  if(localListViewProps){
2955
2958
  localListViewProps = JSON.parse(localListViewProps);
2956
- // const removedValues = {};
2957
- removedKeys.forEach(function(key){
2958
- delete localListViewProps[key];
2959
- // removedValues[key] = "";
2959
+ _.each(localListViewProps, function(n,k){
2960
+ // __searchable__开头的不在searchableFields范围则清除其值
2961
+ let isRemoved = !!removedFields.find(function(fieldName){
2962
+ return new RegExp("__searchable__\.*" + fieldName + "$").test(k);
2963
+ });
2964
+ if(isRemoved){
2965
+ delete localListViewProps[k];
2966
+ }
2960
2967
  });
2961
2968
  sessionStorage.setItem(listViewPropsStoreKey, JSON.stringify(localListViewProps));
2962
2969
  }
@@ -2990,9 +2997,10 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2990
2997
  "body": [
2991
2998
  {
2992
2999
  "type": "button",
3000
+ "id": btnSearchId,
2993
3001
  "label": "搜索",
2994
3002
  "icon": "fa fa-search",
2995
- "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3003
+ // "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
2996
3004
  "onEvent": {
2997
3005
  "click": {
2998
3006
  "actions": [
@@ -3008,7 +3016,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3008
3016
  "type": "button",
3009
3017
  "label": "取消",
3010
3018
  "name": "btn_filter_form_cancel",
3011
- "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3019
+ // "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3012
3020
  "onEvent": {
3013
3021
  "click": {
3014
3022
  "actions": [
@@ -3123,6 +3131,10 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3123
3131
  "actionType": "custom",
3124
3132
  "script": onSearchableFieldsChangeScript
3125
3133
  },
3134
+ {
3135
+ "actionType": "click",
3136
+ "componentId": btnSearchId
3137
+ },
3126
3138
  {
3127
3139
  "componentId": "",
3128
3140
  "args": {},
@@ -3477,7 +3489,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3477
3489
  // "tpl": "${(record && uiSchema && record[uiSchema.NAME_FIELD_KEY]) || name}",
3478
3490
  "inline": false,
3479
3491
  "wrapperComponent": "",
3480
- "className": "leading-5 text-xl font-bold"
3492
+ "className": "record-detail-header-name leading-5 text-xl font-bold"
3481
3493
  }
3482
3494
  ],
3483
3495
  "columnClassName": "p-l-xs"
@@ -3486,6 +3498,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3486
3498
  "className": "flex justify-between"
3487
3499
  }
3488
3500
  ],
3501
+ "columnClassName": "flex-initial",
3489
3502
  "md": "auto",
3490
3503
  });
3491
3504
  }
@@ -3506,7 +3519,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3506
3519
  {
3507
3520
  "type": "grid",
3508
3521
  "columns": gridBody,
3509
- "className": "flex justify-between"
3522
+ "className": "flex justify-between flex-nowrap"
3510
3523
  }
3511
3524
  ],
3512
3525
  "hiddenOn": "${recordLoaded != true}"
@@ -3723,12 +3736,13 @@ const getNewListviewButtonSchema = ()=>{
3723
3736
  "type": "dialog",
3724
3737
  "title": "新建 列表视图",
3725
3738
  "data": {
3726
- "&": "$$",
3739
+ //"&":"$$",2.7、2.9、3.0在此处失效
3727
3740
  "all": "${uiSchema.list_views.all}",
3728
3741
  "list_view": "${uiSchema.list_views[listName]}",
3729
3742
  "appId": "${appId}",
3730
3743
  "global": "${global}",
3731
3744
  "targetObjectName": "${objectName}",
3745
+ "context": "${context}"
3732
3746
  },
3733
3747
  "body": [
3734
3748
  {
@@ -3872,12 +3886,13 @@ const getCopyListviewButtonSchema = ()=>{
3872
3886
  "type": "dialog",
3873
3887
  "title": "复制 列表视图",
3874
3888
  "data": {
3875
- "&": "$$",
3889
+ //"&":"$$",2.7、2.9、3.0在此处失效
3876
3890
  "listName": "${listName}",
3877
3891
  "targetObjectName": "${objectName}",
3878
3892
  "list_view": "${uiSchema.list_views[listName]}",
3879
3893
  "appId": "${appId}",
3880
- "global": "${global}"
3894
+ "global": "${global}",
3895
+ "context": "${context}"
3881
3896
  },
3882
3897
  "body": [
3883
3898
  {
@@ -4019,7 +4034,8 @@ const getRenameListviewButtonSchema = ()=>{
4019
4034
  "data": {
4020
4035
  "targetObjectName": "${objectName}",
4021
4036
  "recordId": "${uiSchema.list_views[listName]._id}",
4022
- "appId": "${appId}"
4037
+ "appId": "${appId}",
4038
+ "context": "${context}"
4023
4039
  },
4024
4040
  "body": [
4025
4041
  {
@@ -4076,6 +4092,7 @@ const getSetListviewShareButtonSchema = ()=>{
4076
4092
  "title": "共享设置",
4077
4093
  "data": {
4078
4094
  "recordId": "${uiSchema.list_views[listName]._id}",
4095
+ "context": "${context}"
4079
4096
  },
4080
4097
  "body": [
4081
4098
  {
@@ -4121,7 +4138,8 @@ const getSetListviewFiltersButtonSchema = ()=>{
4121
4138
  "targetObjectName": "${objectName}",
4122
4139
  "recordId": "${uiSchema.list_views[listName]._id}",
4123
4140
  "listName": "${listName}",
4124
- "appId": "${appId}"
4141
+ "appId": "${appId}",
4142
+ "context": "${context}"
4125
4143
  },
4126
4144
  "body": [
4127
4145
  {
@@ -4265,11 +4283,12 @@ const getSetListviewColumnsButtonSchema = ()=>{
4265
4283
  "type": "dialog",
4266
4284
  "title": "显示的列",
4267
4285
  "data": {
4268
- "&": "$$",
4286
+ //"&":"$$",2.7、2.9、3.0在此处失效
4269
4287
  "targetObjectName": "${objectName}",
4270
4288
  "recordId": "${uiSchema.list_views[listName]._id}",
4271
4289
  "listName": "${listName}",
4272
- "appId": "${appId}"
4290
+ "appId": "${appId}",
4291
+ "context": "${context}"
4273
4292
  },
4274
4293
  "body": [
4275
4294
  {
@@ -4418,11 +4437,12 @@ const getSetListviewSortButtonSchema = ()=>{
4418
4437
  "type": "dialog",
4419
4438
  "title": "默认排序规则",
4420
4439
  "data": {
4421
- "&": "$$",
4440
+ //"&":"$$",2.7、2.9、3.0在此处失效
4422
4441
  "targetObjectName": "${objectName}",
4423
4442
  "recordId": "${uiSchema.list_views[listName]._id}",
4424
4443
  "listName": "${listName}",
4425
- "appId": "${appId}"
4444
+ "appId": "${appId}",
4445
+ "context": "${context}"
4426
4446
  },
4427
4447
  "body": [
4428
4448
  {
@@ -5112,24 +5132,13 @@ function getLookupSapceUserTreeSchema(){
5112
5132
  "actionType": "custom",
5113
5133
  "script": `
5114
5134
  const scope = event.context.scoped;
5115
- //TODO: 将form中的value一同加入筛选内
5116
- // var filterForm = scope.parent.parent.getComponents().find(function(n){
5117
- // return n.props.type === "form";
5118
- // });
5119
- // var filterFormValues = filterForm.getValues();
5120
- filterFormValues={
5135
+ var filterFormValues={
5121
5136
  "__searchable__organizations_parents":event.data.value.value
5122
5137
  }
5123
5138
  var listView = scope.parent.getComponents().find(function(n){
5124
5139
  return n.props.type === "crud";
5125
5140
  });
5126
- const removedValues = {};
5127
- // for(var k in filterFormValues){
5128
- // if(filterFormValues[k] === "" && !filterFormValues.hasOwnProperty(k)){
5129
- // removedValues[k] = "";
5130
- // }
5131
- // }
5132
- listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
5141
+ listView.handleFilterSubmit(Object.assign({}, filterFormValues));
5133
5142
  `
5134
5143
  }
5135
5144
  ]
@@ -5243,7 +5252,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
5243
5252
 
5244
5253
  const source = await getApi$1(refObjectConfig, null, fields, {expand: true, alias: 'rows', queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
5245
5254
 
5246
- if(source.url){
5255
+ if(source.url && !ctx.inFilterForm){
5247
5256
  const depend_on = [];
5248
5257
  const sendOn = [];
5249
5258
  _$1.each(field.depend_on, (fName)=>{
@@ -5307,9 +5316,10 @@ async function lookupToAmisPicker(field, readonly, ctx){
5307
5316
  filters.push(fieldFilters);
5308
5317
  }
5309
5318
 
5319
+ const inFilterForm = ${ctx.inFilterForm};
5310
5320
  const filtersFunction = ${field.filtersFunction || field._filtersFunction};
5311
5321
 
5312
- if(filtersFunction){
5322
+ if(filtersFunction && !inFilterForm){
5313
5323
  const _filters = filtersFunction(filters, api.data.$self.__super.__super);
5314
5324
  if(_filters && _filters.length > 0){
5315
5325
  filters.push(_filters);
@@ -5529,7 +5539,8 @@ async function lookupToAmisSelect(field, readonly, ctx){
5529
5539
  sort = getListViewSort(listView);
5530
5540
  }
5531
5541
 
5532
- if(apiInfo.url){
5542
+ // 列表视图搜索栏中,即inFilterForm=true时,不需要执行depend_on
5543
+ if(apiInfo.url && !ctx.inFilterForm){
5533
5544
  const depend_on = [];
5534
5545
  const sendOn = [];
5535
5546
  _$1.each(field.depend_on, (fName)=>{
@@ -5566,9 +5577,10 @@ async function lookupToAmisSelect(field, readonly, ctx){
5566
5577
  filters.push(fieldFilters);
5567
5578
  }
5568
5579
 
5580
+ const inFilterForm = ${ctx.inFilterForm};
5569
5581
  const filtersFunction = ${field.filtersFunction || field._filtersFunction};
5570
5582
 
5571
- if(filtersFunction){
5583
+ if(filtersFunction && !inFilterForm){
5572
5584
  const _filters = filtersFunction(filters, api.data.$);
5573
5585
  if(_filters && _filters.length > 0){
5574
5586
  filters.push(_filters);
@@ -5594,7 +5606,14 @@ async function lookupToAmisSelect(field, readonly, ctx){
5594
5606
  referenceTo ? referenceTo.valueField.name : '';
5595
5607
  if(field.optionsFunction || field._optionsFunction){
5596
5608
  apiInfo.adaptor = `
5597
- payload.data.options = eval(${field.optionsFunction || field._optionsFunction})(api.data.$);
5609
+ var options = eval(${field.optionsFunction || field._optionsFunction})(api.data.$);
5610
+ if(api.data.$term){
5611
+ options = _.filter(options, function(o) {
5612
+ var label = o.label;
5613
+ return label.toLowerCase().indexOf(api.data.$term.toLowerCase()) > -1;
5614
+ });
5615
+ }
5616
+ payload.data.options = options;
5598
5617
  return payload;
5599
5618
  `;
5600
5619
  }
@@ -5730,7 +5749,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
5730
5749
  source.data.$term = "$term";
5731
5750
  source.data.$self = "$$";
5732
5751
 
5733
- if(idsDependOn && source.url){
5752
+ if(idsDependOn && source.url && !ctx.inFilterForm){
5734
5753
  source.sendOn = `\${${idsDependOn} && ${idsDependOn}.length}`;
5735
5754
  source.url = `${source.url}&depend_on_${idsDependOn}=\${${idsDependOn}|join}`;
5736
5755
  }
@@ -6572,7 +6591,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6572
6591
  convertData.className = fieldTypeClassName;
6573
6592
  }
6574
6593
 
6575
- if(field.visible_on){
6594
+ if(field.visible_on && !ctx.inFilterForm){
6576
6595
  // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
6577
6596
  if(field.visible_on.startsWith("{{")){
6578
6597
  convertData.visibleOn = `${field.visible_on.substring(2, field.visible_on.length -2).replace(/formData./g, 'data.')}`;
@@ -6665,7 +6684,7 @@ async function getFieldSearchable(perField, permissionFields, ctx){
6665
6684
  _field.multiple = true;
6666
6685
  _field.is_wide = false;
6667
6686
  _field.defaultValue = undefined;
6668
- const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true}));
6687
+ const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
6669
6688
  if(amisField){
6670
6689
  return amisField;
6671
6690
  }
@@ -7667,7 +7686,7 @@ async function getTableColumns(fields, options){
7667
7686
  tpl: tpl,
7668
7687
  toggled: field.toggled,
7669
7688
  className,
7670
- html: field.type === 'html' ? true : null
7689
+ options: field.type === 'html' ? {html: true} : null
7671
7690
  // toggled: true
7672
7691
  }, field.amis, {name: field.name}));
7673
7692
  }