@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.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,
@@ -2414,7 +2416,14 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2414
2416
  className: `button_${button.name}`
2415
2417
  }
2416
2418
  });
2417
- let dropdownButtons = ___default.map(moreButtons, (button) => {
2419
+ let moreButtonsVisibleOn = '';
2420
+ let dropdownButtons = ___default.map(moreButtons, (button, index) => {
2421
+ if(index === 0){
2422
+ moreButtonsVisibleOn = getButtonVisibleOn$1(button);
2423
+ }else {
2424
+ moreButtonsVisibleOn = moreButtonsVisibleOn + ' || ' +getButtonVisibleOn$1(button);
2425
+ }
2426
+
2418
2427
  return {
2419
2428
  type: 'steedos-object-button',
2420
2429
  name: button.name,
@@ -2424,12 +2433,13 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2424
2433
  });
2425
2434
  return {
2426
2435
  buttons: amisButtonsSchema,
2427
- moreButtons: dropdownButtons
2436
+ moreButtons: dropdownButtons,
2437
+ moreButtonsVisibleOn
2428
2438
  };
2429
2439
  };
2430
2440
 
2431
2441
  const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2432
- const { buttons, moreButtons } = getObjectDetailHeaderButtons(objectSchema, recordId);
2442
+ const { buttons, moreButtons, moreButtonsVisibleOn } = getObjectDetailHeaderButtons(objectSchema, recordId);
2433
2443
  if(ctx.formFactor === 'SMALL'){
2434
2444
  return {
2435
2445
  "type": "button",
@@ -2484,7 +2494,8 @@ const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2484
2494
  type: "steedos-dropdown-button",
2485
2495
  label: "",
2486
2496
  buttons: moreButtons,
2487
- className: 'slds-icon'
2497
+ className: 'slds-icon',
2498
+ visibleOn: moreButtonsVisibleOn
2488
2499
  };
2489
2500
  buttons.push(dropdownButtonsSchema);
2490
2501
  }
@@ -2716,6 +2727,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2716
2727
  if (!ctx) {
2717
2728
  ctx = {};
2718
2729
  }
2730
+ const btnSearchId = "btn_filter_form_search_" + new Date().getTime();
2719
2731
  const filterFormSchema = await getObjectFieldsFilterFormSchema(ctx);
2720
2732
  const onSearchScript = `
2721
2733
  const scope = event.context.scoped;
@@ -2732,7 +2744,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2732
2744
  // // 这会造成handleFilterSubmit时把移除掉的搜索项字段之前的值加到过滤条件中
2733
2745
  // for(var k in filterFormValues){
2734
2746
  // if(filterFormValues[k] === "" && !filterFormValues.hasOwnProperty(k)){
2735
- // removedValues[k] = "";
2747
+ // removedValues[k] = null;
2736
2748
  // }
2737
2749
  // }
2738
2750
  // listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
@@ -2771,7 +2783,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2771
2783
  const removedValues = {};
2772
2784
  for(var k in filterFormValues){
2773
2785
  if(/^__searchable__/.test(k)){
2774
- removedValues[k] = "";
2786
+ removedValues[k] = null;
2775
2787
  }
2776
2788
  }
2777
2789
  if(!event.data.isLookup){
@@ -2782,7 +2794,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2782
2794
  if(localListViewProps){
2783
2795
  localListViewProps = JSON.parse(localListViewProps);
2784
2796
  for(var k in localListViewProps){
2785
- removedValues[k] = "";
2797
+ removedValues[k] = null;
2786
2798
  }
2787
2799
  }
2788
2800
  }
@@ -2940,7 +2952,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2940
2952
  });
2941
2953
  const removedValues = {};
2942
2954
  removedKeys.forEach(function(key){
2943
- removedValues[key] = "";
2955
+ removedValues[key] = null;
2944
2956
  });
2945
2957
  filterForm.setValues(removedValues);//这里使用filterInnerForm也可以
2946
2958
 
@@ -2953,10 +2965,14 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2953
2965
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
2954
2966
  if(localListViewProps){
2955
2967
  localListViewProps = JSON.parse(localListViewProps);
2956
- // const removedValues = {};
2957
- removedKeys.forEach(function(key){
2958
- delete localListViewProps[key];
2959
- // removedValues[key] = "";
2968
+ _.each(localListViewProps, function(n,k){
2969
+ // __searchable__开头的不在searchableFields范围则清除其值
2970
+ let isRemoved = !!removedFields.find(function(fieldName){
2971
+ return new RegExp("__searchable__\.*" + fieldName + "$").test(k);
2972
+ });
2973
+ if(isRemoved){
2974
+ delete localListViewProps[k];
2975
+ }
2960
2976
  });
2961
2977
  sessionStorage.setItem(listViewPropsStoreKey, JSON.stringify(localListViewProps));
2962
2978
  }
@@ -2990,9 +3006,10 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
2990
3006
  "body": [
2991
3007
  {
2992
3008
  "type": "button",
3009
+ "id": btnSearchId,
2993
3010
  "label": "搜索",
2994
3011
  "icon": "fa fa-search",
2995
- "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3012
+ // "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
2996
3013
  "onEvent": {
2997
3014
  "click": {
2998
3015
  "actions": [
@@ -3008,7 +3025,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3008
3025
  "type": "button",
3009
3026
  "label": "取消",
3010
3027
  "name": "btn_filter_form_cancel",
3011
- "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3028
+ // "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
3012
3029
  "onEvent": {
3013
3030
  "click": {
3014
3031
  "actions": [
@@ -3123,6 +3140,10 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3123
3140
  "actionType": "custom",
3124
3141
  "script": onSearchableFieldsChangeScript
3125
3142
  },
3143
+ {
3144
+ "actionType": "click",
3145
+ "componentId": btnSearchId
3146
+ },
3126
3147
  {
3127
3148
  "componentId": "",
3128
3149
  "args": {},
@@ -3477,7 +3498,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3477
3498
  // "tpl": "${(record && uiSchema && record[uiSchema.NAME_FIELD_KEY]) || name}",
3478
3499
  "inline": false,
3479
3500
  "wrapperComponent": "",
3480
- "className": "leading-5 text-xl font-bold"
3501
+ "className": "record-detail-header-name leading-5 text-xl font-bold"
3481
3502
  }
3482
3503
  ],
3483
3504
  "columnClassName": "p-l-xs"
@@ -3486,6 +3507,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3486
3507
  "className": "flex justify-between"
3487
3508
  }
3488
3509
  ],
3510
+ "columnClassName": "flex-initial",
3489
3511
  "md": "auto",
3490
3512
  });
3491
3513
  }
@@ -3506,7 +3528,7 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
3506
3528
  {
3507
3529
  "type": "grid",
3508
3530
  "columns": gridBody,
3509
- "className": "flex justify-between"
3531
+ "className": "flex justify-between flex-nowrap"
3510
3532
  }
3511
3533
  ],
3512
3534
  "hiddenOn": "${recordLoaded != true}"
@@ -3723,12 +3745,13 @@ const getNewListviewButtonSchema = ()=>{
3723
3745
  "type": "dialog",
3724
3746
  "title": "新建 列表视图",
3725
3747
  "data": {
3726
- "&": "$$",
3748
+ //"&":"$$",2.7、2.9、3.0在此处失效
3727
3749
  "all": "${uiSchema.list_views.all}",
3728
3750
  "list_view": "${uiSchema.list_views[listName]}",
3729
3751
  "appId": "${appId}",
3730
3752
  "global": "${global}",
3731
3753
  "targetObjectName": "${objectName}",
3754
+ "context": "${context}"
3732
3755
  },
3733
3756
  "body": [
3734
3757
  {
@@ -3872,12 +3895,13 @@ const getCopyListviewButtonSchema = ()=>{
3872
3895
  "type": "dialog",
3873
3896
  "title": "复制 列表视图",
3874
3897
  "data": {
3875
- "&": "$$",
3898
+ //"&":"$$",2.7、2.9、3.0在此处失效
3876
3899
  "listName": "${listName}",
3877
3900
  "targetObjectName": "${objectName}",
3878
3901
  "list_view": "${uiSchema.list_views[listName]}",
3879
3902
  "appId": "${appId}",
3880
- "global": "${global}"
3903
+ "global": "${global}",
3904
+ "context": "${context}"
3881
3905
  },
3882
3906
  "body": [
3883
3907
  {
@@ -4019,7 +4043,8 @@ const getRenameListviewButtonSchema = ()=>{
4019
4043
  "data": {
4020
4044
  "targetObjectName": "${objectName}",
4021
4045
  "recordId": "${uiSchema.list_views[listName]._id}",
4022
- "appId": "${appId}"
4046
+ "appId": "${appId}",
4047
+ "context": "${context}"
4023
4048
  },
4024
4049
  "body": [
4025
4050
  {
@@ -4076,6 +4101,7 @@ const getSetListviewShareButtonSchema = ()=>{
4076
4101
  "title": "共享设置",
4077
4102
  "data": {
4078
4103
  "recordId": "${uiSchema.list_views[listName]._id}",
4104
+ "context": "${context}"
4079
4105
  },
4080
4106
  "body": [
4081
4107
  {
@@ -4121,7 +4147,8 @@ const getSetListviewFiltersButtonSchema = ()=>{
4121
4147
  "targetObjectName": "${objectName}",
4122
4148
  "recordId": "${uiSchema.list_views[listName]._id}",
4123
4149
  "listName": "${listName}",
4124
- "appId": "${appId}"
4150
+ "appId": "${appId}",
4151
+ "context": "${context}"
4125
4152
  },
4126
4153
  "body": [
4127
4154
  {
@@ -4265,11 +4292,12 @@ const getSetListviewColumnsButtonSchema = ()=>{
4265
4292
  "type": "dialog",
4266
4293
  "title": "显示的列",
4267
4294
  "data": {
4268
- "&": "$$",
4295
+ //"&":"$$",2.7、2.9、3.0在此处失效
4269
4296
  "targetObjectName": "${objectName}",
4270
4297
  "recordId": "${uiSchema.list_views[listName]._id}",
4271
4298
  "listName": "${listName}",
4272
- "appId": "${appId}"
4299
+ "appId": "${appId}",
4300
+ "context": "${context}"
4273
4301
  },
4274
4302
  "body": [
4275
4303
  {
@@ -4418,11 +4446,12 @@ const getSetListviewSortButtonSchema = ()=>{
4418
4446
  "type": "dialog",
4419
4447
  "title": "默认排序规则",
4420
4448
  "data": {
4421
- "&": "$$",
4449
+ //"&":"$$",2.7、2.9、3.0在此处失效
4422
4450
  "targetObjectName": "${objectName}",
4423
4451
  "recordId": "${uiSchema.list_views[listName]._id}",
4424
4452
  "listName": "${listName}",
4425
- "appId": "${appId}"
4453
+ "appId": "${appId}",
4454
+ "context": "${context}"
4426
4455
  },
4427
4456
  "body": [
4428
4457
  {
@@ -5112,24 +5141,13 @@ function getLookupSapceUserTreeSchema(){
5112
5141
  "actionType": "custom",
5113
5142
  "script": `
5114
5143
  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={
5144
+ var filterFormValues={
5121
5145
  "__searchable__organizations_parents":event.data.value.value
5122
5146
  }
5123
5147
  var listView = scope.parent.getComponents().find(function(n){
5124
5148
  return n.props.type === "crud";
5125
5149
  });
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));
5150
+ listView.handleFilterSubmit(Object.assign({}, filterFormValues));
5133
5151
  `
5134
5152
  }
5135
5153
  ]
@@ -5243,7 +5261,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
5243
5261
 
5244
5262
  const source = await getApi$1(refObjectConfig, null, fields, {expand: true, alias: 'rows', queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
5245
5263
 
5246
- if(source.url){
5264
+ if(source.url && !ctx.inFilterForm){
5247
5265
  const depend_on = [];
5248
5266
  const sendOn = [];
5249
5267
  _$1.each(field.depend_on, (fName)=>{
@@ -5307,9 +5325,10 @@ async function lookupToAmisPicker(field, readonly, ctx){
5307
5325
  filters.push(fieldFilters);
5308
5326
  }
5309
5327
 
5328
+ const inFilterForm = ${ctx.inFilterForm};
5310
5329
  const filtersFunction = ${field.filtersFunction || field._filtersFunction};
5311
5330
 
5312
- if(filtersFunction){
5331
+ if(filtersFunction && !inFilterForm){
5313
5332
  const _filters = filtersFunction(filters, api.data.$self.__super.__super);
5314
5333
  if(_filters && _filters.length > 0){
5315
5334
  filters.push(_filters);
@@ -5529,7 +5548,8 @@ async function lookupToAmisSelect(field, readonly, ctx){
5529
5548
  sort = getListViewSort(listView);
5530
5549
  }
5531
5550
 
5532
- if(apiInfo.url){
5551
+ // 列表视图搜索栏中,即inFilterForm=true时,不需要执行depend_on
5552
+ if(apiInfo.url && !ctx.inFilterForm){
5533
5553
  const depend_on = [];
5534
5554
  const sendOn = [];
5535
5555
  _$1.each(field.depend_on, (fName)=>{
@@ -5566,9 +5586,10 @@ async function lookupToAmisSelect(field, readonly, ctx){
5566
5586
  filters.push(fieldFilters);
5567
5587
  }
5568
5588
 
5589
+ const inFilterForm = ${ctx.inFilterForm};
5569
5590
  const filtersFunction = ${field.filtersFunction || field._filtersFunction};
5570
5591
 
5571
- if(filtersFunction){
5592
+ if(filtersFunction && !inFilterForm){
5572
5593
  const _filters = filtersFunction(filters, api.data.$);
5573
5594
  if(_filters && _filters.length > 0){
5574
5595
  filters.push(_filters);
@@ -5594,7 +5615,14 @@ async function lookupToAmisSelect(field, readonly, ctx){
5594
5615
  referenceTo ? referenceTo.valueField.name : '';
5595
5616
  if(field.optionsFunction || field._optionsFunction){
5596
5617
  apiInfo.adaptor = `
5597
- payload.data.options = eval(${field.optionsFunction || field._optionsFunction})(api.data.$);
5618
+ var options = eval(${field.optionsFunction || field._optionsFunction})(api.data.$);
5619
+ if(api.data.$term){
5620
+ options = _.filter(options, function(o) {
5621
+ var label = o.label;
5622
+ return label.toLowerCase().indexOf(api.data.$term.toLowerCase()) > -1;
5623
+ });
5624
+ }
5625
+ payload.data.options = options;
5598
5626
  return payload;
5599
5627
  `;
5600
5628
  }
@@ -5730,7 +5758,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
5730
5758
  source.data.$term = "$term";
5731
5759
  source.data.$self = "$$";
5732
5760
 
5733
- if(idsDependOn && source.url){
5761
+ if(idsDependOn && source.url && !ctx.inFilterForm){
5734
5762
  source.sendOn = `\${${idsDependOn} && ${idsDependOn}.length}`;
5735
5763
  source.url = `${source.url}&depend_on_${idsDependOn}=\${${idsDependOn}|join}`;
5736
5764
  }
@@ -6572,7 +6600,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6572
6600
  convertData.className = fieldTypeClassName;
6573
6601
  }
6574
6602
 
6575
- if(field.visible_on){
6603
+ if(field.visible_on && !ctx.inFilterForm){
6576
6604
  // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
6577
6605
  if(field.visible_on.startsWith("{{")){
6578
6606
  convertData.visibleOn = `${field.visible_on.substring(2, field.visible_on.length -2).replace(/formData./g, 'data.')}`;
@@ -6665,7 +6693,7 @@ async function getFieldSearchable(perField, permissionFields, ctx){
6665
6693
  _field.multiple = true;
6666
6694
  _field.is_wide = false;
6667
6695
  _field.defaultValue = undefined;
6668
- const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true}));
6696
+ const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
6669
6697
  if(amisField){
6670
6698
  return amisField;
6671
6699
  }
@@ -7505,11 +7533,12 @@ async function getObjectDetail(objectSchema, recordId, ctx){
7505
7533
  "expression": "this.__deletedRecord != true"
7506
7534
  },
7507
7535
  {
7508
- "args": {
7509
- "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7510
- "blank": false
7511
- },
7512
- "actionType": "link",
7536
+ // "args": {
7537
+ // "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7538
+ // "blank": false
7539
+ // },
7540
+ "actionType": "custom",
7541
+ "script": "Steedos.goBack()",
7513
7542
  "expression": "this.__deletedRecord === true"
7514
7543
  }
7515
7544
  ]
@@ -7667,7 +7696,7 @@ async function getTableColumns(fields, options){
7667
7696
  tpl: tpl,
7668
7697
  toggled: field.toggled,
7669
7698
  className,
7670
- html: field.type === 'html' ? true : null
7699
+ options: field.type === 'html' ? {html: true} : null
7671
7700
  // toggled: true
7672
7701
  }, field.amis, {name: field.name}));
7673
7702
  }