@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.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,
@@ -2743,6 +2745,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2743
2745
  if (!ctx) {
2744
2746
  ctx = {};
2745
2747
  }
2748
+ const btnSearchId = "btn_filter_form_search_" + new Date().getTime();
2746
2749
  const filterFormSchema = await getObjectFieldsFilterFormSchema(ctx);
2747
2750
  const onSearchScript = `
2748
2751
  const scope = event.context.scoped;
@@ -2759,7 +2762,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2759
2762
  // // 这会造成handleFilterSubmit时把移除掉的搜索项字段之前的值加到过滤条件中
2760
2763
  // for(var k in filterFormValues){
2761
2764
  // if(filterFormValues[k] === "" && !filterFormValues.hasOwnProperty(k)){
2762
- // removedValues[k] = "";
2765
+ // removedValues[k] = null;
2763
2766
  // }
2764
2767
  // }
2765
2768
  // listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
@@ -2798,7 +2801,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2798
2801
  const removedValues = {};
2799
2802
  for(var k in filterFormValues){
2800
2803
  if(/^__searchable__/.test(k)){
2801
- removedValues[k] = "";
2804
+ removedValues[k] = null;
2802
2805
  }
2803
2806
  }
2804
2807
  if(!event.data.isLookup){
@@ -2809,7 +2812,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2809
2812
  if(localListViewProps){
2810
2813
  localListViewProps = JSON.parse(localListViewProps);
2811
2814
  for(var k in localListViewProps){
2812
- removedValues[k] = "";
2815
+ removedValues[k] = null;
2813
2816
  }
2814
2817
  }
2815
2818
  }
@@ -2967,7 +2970,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2967
2970
  });
2968
2971
  const removedValues = {};
2969
2972
  removedKeys.forEach(function(key){
2970
- removedValues[key] = "";
2973
+ removedValues[key] = null;
2971
2974
  });
2972
2975
  filterForm.setValues(removedValues);//这里使用filterInnerForm也可以
2973
2976
 
@@ -2980,10 +2983,14 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2980
2983
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
2981
2984
  if(localListViewProps){
2982
2985
  localListViewProps = JSON.parse(localListViewProps);
2983
- // const removedValues = {};
2984
- removedKeys.forEach(function(key){
2985
- delete localListViewProps[key];
2986
- // removedValues[key] = "";
2986
+ _.each(localListViewProps, function(n,k){
2987
+ // __searchable__开头的不在searchableFields范围则清除其值
2988
+ let isRemoved = !!removedFields.find(function(fieldName){
2989
+ return new RegExp("__searchable__\.*" + fieldName + "$").test(k);
2990
+ });
2991
+ if(isRemoved){
2992
+ delete localListViewProps[k];
2993
+ }
2987
2994
  });
2988
2995
  sessionStorage.setItem(listViewPropsStoreKey, JSON.stringify(localListViewProps));
2989
2996
  }
@@ -3017,9 +3024,10 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3017
3024
  "body": [
3018
3025
  {
3019
3026
  "type": "button",
3027
+ "id": btnSearchId,
3020
3028
  "label": "搜索",
3021
3029
  "icon": "fa fa-search",
3022
- "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3030
+ // "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3023
3031
  "onEvent": {
3024
3032
  "click": {
3025
3033
  "actions": [
@@ -3035,7 +3043,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3035
3043
  "type": "button",
3036
3044
  "label": "取消",
3037
3045
  "name": "btn_filter_form_cancel",
3038
- "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3046
+ // "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3039
3047
  "onEvent": {
3040
3048
  "click": {
3041
3049
  "actions": [
@@ -3150,6 +3158,10 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3150
3158
  "actionType": "custom",
3151
3159
  "script": onSearchableFieldsChangeScript
3152
3160
  },
3161
+ {
3162
+ "actionType": "click",
3163
+ "componentId": btnSearchId
3164
+ },
3153
3165
  {
3154
3166
  "componentId": "",
3155
3167
  "args": {},
@@ -3504,7 +3516,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3504
3516
  // "tpl": "${(record && uiSchema && record[uiSchema.NAME_FIELD_KEY]) || name}",
3505
3517
  "inline": false,
3506
3518
  "wrapperComponent": "",
3507
- "className": "leading-5 text-xl font-bold"
3519
+ "className": "record-detail-header-name leading-5 text-xl font-bold"
3508
3520
  }
3509
3521
  ],
3510
3522
  "columnClassName": "p-l-xs"
@@ -3513,6 +3525,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3513
3525
  "className": "flex justify-between"
3514
3526
  }
3515
3527
  ],
3528
+ "columnClassName": "flex-initial",
3516
3529
  "md": "auto",
3517
3530
  });
3518
3531
  }
@@ -3533,7 +3546,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3533
3546
  {
3534
3547
  "type": "grid",
3535
3548
  "columns": gridBody,
3536
- "className": "flex justify-between"
3549
+ "className": "flex justify-between flex-nowrap"
3537
3550
  }
3538
3551
  ],
3539
3552
  "hiddenOn": "${recordLoaded != true}"
@@ -3750,12 +3763,13 @@ const getNewListviewButtonSchema = ()=>{
3750
3763
  "type": "dialog",
3751
3764
  "title": "新建 列表视图",
3752
3765
  "data": {
3753
- "&": "$$",
3766
+ //"&":"$$",2.7、2.9、3.0在此处失效
3754
3767
  "all": "${uiSchema.list_views.all}",
3755
3768
  "list_view": "${uiSchema.list_views[listName]}",
3756
3769
  "appId": "${appId}",
3757
3770
  "global": "${global}",
3758
3771
  "targetObjectName": "${objectName}",
3772
+ "context": "${context}"
3759
3773
  },
3760
3774
  "body": [
3761
3775
  {
@@ -3899,12 +3913,13 @@ const getCopyListviewButtonSchema = ()=>{
3899
3913
  "type": "dialog",
3900
3914
  "title": "复制 列表视图",
3901
3915
  "data": {
3902
- "&": "$$",
3916
+ //"&":"$$",2.7、2.9、3.0在此处失效
3903
3917
  "listName": "${listName}",
3904
3918
  "targetObjectName": "${objectName}",
3905
3919
  "list_view": "${uiSchema.list_views[listName]}",
3906
3920
  "appId": "${appId}",
3907
- "global": "${global}"
3921
+ "global": "${global}",
3922
+ "context": "${context}"
3908
3923
  },
3909
3924
  "body": [
3910
3925
  {
@@ -4046,7 +4061,8 @@ const getRenameListviewButtonSchema = ()=>{
4046
4061
  "data": {
4047
4062
  "targetObjectName": "${objectName}",
4048
4063
  "recordId": "${uiSchema.list_views[listName]._id}",
4049
- "appId": "${appId}"
4064
+ "appId": "${appId}",
4065
+ "context": "${context}"
4050
4066
  },
4051
4067
  "body": [
4052
4068
  {
@@ -4103,6 +4119,7 @@ const getSetListviewShareButtonSchema = ()=>{
4103
4119
  "title": "共享设置",
4104
4120
  "data": {
4105
4121
  "recordId": "${uiSchema.list_views[listName]._id}",
4122
+ "context": "${context}"
4106
4123
  },
4107
4124
  "body": [
4108
4125
  {
@@ -4148,7 +4165,8 @@ const getSetListviewFiltersButtonSchema = ()=>{
4148
4165
  "targetObjectName": "${objectName}",
4149
4166
  "recordId": "${uiSchema.list_views[listName]._id}",
4150
4167
  "listName": "${listName}",
4151
- "appId": "${appId}"
4168
+ "appId": "${appId}",
4169
+ "context": "${context}"
4152
4170
  },
4153
4171
  "body": [
4154
4172
  {
@@ -4292,11 +4310,12 @@ const getSetListviewColumnsButtonSchema = ()=>{
4292
4310
  "type": "dialog",
4293
4311
  "title": "显示的列",
4294
4312
  "data": {
4295
- "&": "$$",
4313
+ //"&":"$$",2.7、2.9、3.0在此处失效
4296
4314
  "targetObjectName": "${objectName}",
4297
4315
  "recordId": "${uiSchema.list_views[listName]._id}",
4298
4316
  "listName": "${listName}",
4299
- "appId": "${appId}"
4317
+ "appId": "${appId}",
4318
+ "context": "${context}"
4300
4319
  },
4301
4320
  "body": [
4302
4321
  {
@@ -4445,11 +4464,12 @@ const getSetListviewSortButtonSchema = ()=>{
4445
4464
  "type": "dialog",
4446
4465
  "title": "默认排序规则",
4447
4466
  "data": {
4448
- "&": "$$",
4467
+ //"&":"$$",2.7、2.9、3.0在此处失效
4449
4468
  "targetObjectName": "${objectName}",
4450
4469
  "recordId": "${uiSchema.list_views[listName]._id}",
4451
4470
  "listName": "${listName}",
4452
- "appId": "${appId}"
4471
+ "appId": "${appId}",
4472
+ "context": "${context}"
4453
4473
  },
4454
4474
  "body": [
4455
4475
  {
@@ -5139,24 +5159,13 @@ function getLookupSapceUserTreeSchema(){
5139
5159
  "actionType": "custom",
5140
5160
  "script": `
5141
5161
  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={
5162
+ var filterFormValues={
5148
5163
  "__searchable__organizations_parents":event.data.value.value
5149
5164
  }
5150
5165
  var listView = scope.parent.getComponents().find(function(n){
5151
5166
  return n.props.type === "crud";
5152
5167
  });
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));
5168
+ listView.handleFilterSubmit(Object.assign({}, filterFormValues));
5160
5169
  `
5161
5170
  }
5162
5171
  ]
@@ -5270,7 +5279,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
5270
5279
 
5271
5280
  const source = await getApi$1(refObjectConfig, null, fields, {expand: true, alias: 'rows', queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
5272
5281
 
5273
- if(source.url){
5282
+ if(source.url && !ctx.inFilterForm){
5274
5283
  const depend_on = [];
5275
5284
  const sendOn = [];
5276
5285
  ___namespace.each(field.depend_on, (fName)=>{
@@ -5334,9 +5343,10 @@ async function lookupToAmisPicker(field, readonly, ctx){
5334
5343
  filters.push(fieldFilters);
5335
5344
  }
5336
5345
 
5346
+ const inFilterForm = ${ctx.inFilterForm};
5337
5347
  const filtersFunction = ${field.filtersFunction || field._filtersFunction};
5338
5348
 
5339
- if(filtersFunction){
5349
+ if(filtersFunction && !inFilterForm){
5340
5350
  const _filters = filtersFunction(filters, api.data.$self.__super.__super);
5341
5351
  if(_filters && _filters.length > 0){
5342
5352
  filters.push(_filters);
@@ -5556,7 +5566,8 @@ async function lookupToAmisSelect(field, readonly, ctx){
5556
5566
  sort = getListViewSort(listView);
5557
5567
  }
5558
5568
 
5559
- if(apiInfo.url){
5569
+ // 列表视图搜索栏中,即inFilterForm=true时,不需要执行depend_on
5570
+ if(apiInfo.url && !ctx.inFilterForm){
5560
5571
  const depend_on = [];
5561
5572
  const sendOn = [];
5562
5573
  ___namespace.each(field.depend_on, (fName)=>{
@@ -5593,9 +5604,10 @@ async function lookupToAmisSelect(field, readonly, ctx){
5593
5604
  filters.push(fieldFilters);
5594
5605
  }
5595
5606
 
5607
+ const inFilterForm = ${ctx.inFilterForm};
5596
5608
  const filtersFunction = ${field.filtersFunction || field._filtersFunction};
5597
5609
 
5598
- if(filtersFunction){
5610
+ if(filtersFunction && !inFilterForm){
5599
5611
  const _filters = filtersFunction(filters, api.data.$);
5600
5612
  if(_filters && _filters.length > 0){
5601
5613
  filters.push(_filters);
@@ -5621,7 +5633,14 @@ async function lookupToAmisSelect(field, readonly, ctx){
5621
5633
  referenceTo ? referenceTo.valueField.name : '';
5622
5634
  if(field.optionsFunction || field._optionsFunction){
5623
5635
  apiInfo.adaptor = `
5624
- payload.data.options = eval(${field.optionsFunction || field._optionsFunction})(api.data.$);
5636
+ var options = eval(${field.optionsFunction || field._optionsFunction})(api.data.$);
5637
+ if(api.data.$term){
5638
+ options = _.filter(options, function(o) {
5639
+ var label = o.label;
5640
+ return label.toLowerCase().indexOf(api.data.$term.toLowerCase()) > -1;
5641
+ });
5642
+ }
5643
+ payload.data.options = options;
5625
5644
  return payload;
5626
5645
  `;
5627
5646
  }
@@ -5757,7 +5776,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
5757
5776
  source.data.$term = "$term";
5758
5777
  source.data.$self = "$$";
5759
5778
 
5760
- if(idsDependOn && source.url){
5779
+ if(idsDependOn && source.url && !ctx.inFilterForm){
5761
5780
  source.sendOn = `\${${idsDependOn} && ${idsDependOn}.length}`;
5762
5781
  source.url = `${source.url}&depend_on_${idsDependOn}=\${${idsDependOn}|join}`;
5763
5782
  }
@@ -6599,7 +6618,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6599
6618
  convertData.className = fieldTypeClassName;
6600
6619
  }
6601
6620
 
6602
- if(field.visible_on){
6621
+ if(field.visible_on && !ctx.inFilterForm){
6603
6622
  // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
6604
6623
  if(field.visible_on.startsWith("{{")){
6605
6624
  convertData.visibleOn = `${field.visible_on.substring(2, field.visible_on.length -2).replace(/formData./g, 'data.')}`;
@@ -6692,7 +6711,7 @@ async function getFieldSearchable(perField, permissionFields, ctx){
6692
6711
  _field.multiple = true;
6693
6712
  _field.is_wide = false;
6694
6713
  _field.defaultValue = undefined;
6695
- const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true}));
6714
+ const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
6696
6715
  if(amisField){
6697
6716
  return amisField;
6698
6717
  }
@@ -7694,7 +7713,7 @@ async function getTableColumns(fields, options){
7694
7713
  tpl: tpl,
7695
7714
  toggled: field.toggled,
7696
7715
  className,
7697
- html: field.type === 'html' ? true : null
7716
+ options: field.type === 'html' ? {html: true} : null
7698
7717
  // toggled: true
7699
7718
  }, field.amis, {name: field.name}));
7700
7719
  }