@steedos-widgets/amis-lib 1.2.6 → 1.2.8

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.umd.js CHANGED
@@ -2622,7 +2622,7 @@
2622
2622
  return Promise.all(filterFormSearchableFields.map(function (item) {
2623
2623
  const field = _.clone(fields[item]);
2624
2624
  if (
2625
- !_.includes(
2625
+ field && !_.includes(
2626
2626
  [
2627
2627
  "grid",
2628
2628
  "avatar",
@@ -2669,7 +2669,7 @@
2669
2669
  var filterForm = scope.parent.parent.getComponents().find(function(n){
2670
2670
  return n.props.type === "form";
2671
2671
  });
2672
- filterForm.handleFormSubmit(event)
2672
+ filterForm.handleFormSubmit(event);
2673
2673
  // var filterFormValues = filterForm.getValues();
2674
2674
  // var listView = scope.parent.parent.parent.getComponents().find(function(n){
2675
2675
  // return n.props.type === "crud";
@@ -2683,8 +2683,30 @@
2683
2683
  // }
2684
2684
  // }
2685
2685
  // listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
2686
+
2687
+ let isMobile = Steedos.isMobile();
2688
+ if(isMobile){
2689
+ // 手机端点击搜索的时候自动收起搜索栏
2690
+ let resizeWindow = function(){
2691
+ //触发amis crud 高度重算
2692
+ setTimeout(()=>{
2693
+ window.dispatchEvent(new Event("resize"))
2694
+ }, 500);
2695
+ }
2696
+ const filterService = filterForm.context.getComponents().find(function(n){
2697
+ return n.props.type === "service";
2698
+ });
2699
+ filterService.setData({showFieldsFilter: false});
2700
+ resizeWindow();
2701
+ // 使用filterForm.getValues()的话,并不能拿到本地存储中的过滤条件,所以需要从event.data中取。
2702
+ let filterFormValues = event.data;
2703
+ let isFieldsFilterEmpty = SteedosUI.isFilterFormValuesEmpty(filterFormValues);
2704
+ let crud = SteedosUI.getClosestAmisComponentByType(scope, "crud");
2705
+ let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
2706
+ crudService && crudService.setData({isFieldsFilterEmpty, showFieldsFilter: false});
2707
+ }
2686
2708
  `;
2687
- const onResetScript = `
2709
+ const onCancelScript = `
2688
2710
  const scope = event.context.scoped;
2689
2711
  var filterForm = scope.parent.parent.getComponents().find(function(n){
2690
2712
  return n.props.type === "form";
@@ -2712,7 +2734,21 @@
2712
2734
  }
2713
2735
  }
2714
2736
  listView.handleFilterSubmit(removedValues);
2715
- `;
2737
+ const filterService = filterForm.context.getComponents().find(function(n){
2738
+ return n.props.type === "service";
2739
+ });
2740
+ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsFilter});
2741
+ //触发amis crud 高度重算
2742
+ setTimeout(()=>{
2743
+ window.dispatchEvent(new Event("resize"))
2744
+ }, 100);
2745
+ let isMobile = Steedos.isMobile();
2746
+ if(isMobile){
2747
+ // 手机端移除搜索按钮上的红点
2748
+ let crudService = scope.getComponentById("service_listview_" + event.data.objectName);
2749
+ crudService && crudService.setData({isFieldsFilterEmpty: true, showFieldsFilter: false});
2750
+ }
2751
+ `;
2716
2752
  const dataProviderInited = `
2717
2753
  const objectName = data.objectName;
2718
2754
  const isLookup = data.isLookup;
@@ -2766,7 +2802,15 @@
2766
2802
  });
2767
2803
  // 有过滤条件时自动展开搜索栏
2768
2804
  if(!_.isEmpty(omitedEmptyFormValue)){
2769
- setData({ showFieldsFilter: true });
2805
+ let isMobile = Steedos.isMobile();
2806
+ if(isMobile){
2807
+ // 手机端不展开,只显示搜索按钮上的红点
2808
+ let crudService = SteedosUI.getRef(data.$scopeId).getComponentById("service_listview_" + data.objectName)
2809
+ crudService && crudService.setData({isFieldsFilterEmpty: false});
2810
+ }
2811
+ else{
2812
+ setData({ showFieldsFilter: true });
2813
+ }
2770
2814
  }
2771
2815
  }
2772
2816
  }
@@ -2908,14 +2952,15 @@
2908
2952
  },
2909
2953
  {
2910
2954
  "type": "button",
2911
- "label": "重置",
2955
+ "label": "取消",
2956
+ "name": "btn_filter_form_cancel",
2912
2957
  "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
2913
2958
  "onEvent": {
2914
2959
  "click": {
2915
2960
  "actions": [
2916
2961
  {
2917
2962
  "actionType": "custom",
2918
- "script": onResetScript
2963
+ "script": onCancelScript
2919
2964
  }
2920
2965
  ]
2921
2966
  }
@@ -3519,11 +3564,36 @@ const filterForm = scope.getComponents().find(function(n){
3519
3564
  const filterService = filterForm.context.getComponents().find(function(n){
3520
3565
  return n.props.type === "service";
3521
3566
  });
3522
- filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsFilter});
3523
- //触发amis crud 高度重算
3524
- setTimeout(()=>{
3525
- window.dispatchEvent(new Event("resize"))
3526
- }, 100)
3567
+ // filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsFilter});
3568
+ let resizeWindow = function(){
3569
+ //触发amis crud 高度重算
3570
+ setTimeout(()=>{
3571
+ window.dispatchEvent(new Event("resize"))
3572
+ }, 500);
3573
+ }
3574
+ let isMobile = Steedos.isMobile();
3575
+ if(filterService.props.data.showFieldsFilter){
3576
+ if(isMobile){
3577
+ // 手机上只能通过取消按钮来关闭搜索栏
3578
+ return;
3579
+ }
3580
+ let buttonCancel = SteedosUI.getClosestAmisComponentByType(filterForm.context, "button", {
3581
+ direction: "down",
3582
+ name: "btn_filter_form_cancel"
3583
+ });
3584
+ buttonCancel.props.dispatchEvent('click', {}).then(function(){
3585
+ resizeWindow();
3586
+ });
3587
+ }
3588
+ else{
3589
+ filterService.setData({showFieldsFilter: true});
3590
+ resizeWindow();
3591
+ if(isMobile){
3592
+ // 手机端在显示搜索栏时隐藏刷新按钮
3593
+ let crudService = scope.getComponentById("service_listview_" + event.data.objectName);
3594
+ crudService && crudService.setData({showFieldsFilter: true});
3595
+ }
3596
+ }
3527
3597
  `;
3528
3598
 
3529
3599
  function getExportApiRequestAdaptorScript(){
@@ -3608,6 +3678,7 @@ setTimeout(()=>{
3608
3678
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
3609
3679
  "label": "",
3610
3680
  "icon": "fa fa-sync",
3681
+ "visibleOn": "${!showFieldsFilter}",
3611
3682
  "onEvent": {
3612
3683
  "click": {
3613
3684
  "actions": [
@@ -3623,6 +3694,15 @@ setTimeout(()=>{
3623
3694
  "label": "",
3624
3695
  "icon": "fa fa-search",
3625
3696
  "type": "button",
3697
+ "badge": {
3698
+ "offsetx": [
3699
+ -2,
3700
+ 2
3701
+ ],
3702
+ "size":8,
3703
+ "animation": true,
3704
+ "visibleOn": "${isFieldsFilterEmpty == false}"
3705
+ },
3626
3706
  "align": "right",
3627
3707
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
3628
3708
  "onEvent": {
@@ -4262,8 +4342,8 @@ setTimeout(()=>{
4262
4342
  }
4263
4343
  else {
4264
4344
  return [
4345
+ "switch-per-page",
4265
4346
  "statistics",
4266
- // "switch-per-page",
4267
4347
  "pagination"
4268
4348
  ]
4269
4349
  }
@@ -5455,6 +5535,23 @@ setTimeout(()=>{
5455
5535
  return readonly ? getAmisFileReadonlySchema(steedosField) : getAmisFileEditSchema(steedosField);
5456
5536
  };
5457
5537
 
5538
+ /*
5539
+ * @Author: baozhoutao@steedos.com
5540
+ * @Date: 2022-07-20 16:29:22
5541
+ * @LastEditors: Please set LastEditors
5542
+ * @LastEditTime: 2023-05-11 11:19:54
5543
+ * @Description:
5544
+ */
5545
+
5546
+ function getContrastColor(bgColor) {
5547
+ var backgroundColor = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor;
5548
+ var r = parseInt(backgroundColor.substr(0, 2), 16);
5549
+ var g = parseInt(backgroundColor.substr(2, 2), 16);
5550
+ var b = parseInt(backgroundColor.substr(4, 2), 16);
5551
+ var brightness = (r * 299 + g * 587 + b * 114) / 1000;
5552
+ return brightness >= 128 ? "#000000" : "#ffffff";
5553
+ }
5554
+
5458
5555
  const OMIT_FIELDS = ['created', 'created_by', 'modified', 'modified_by'];
5459
5556
  // const Lookup = require('./lookup');
5460
5557
 
@@ -5608,6 +5705,8 @@ setTimeout(()=>{
5608
5705
  }
5609
5706
 
5610
5707
  async function convertSFieldToAmisField(field, readonly, ctx) {
5708
+ // console.log('convertSFieldToAmisField====>', field, readonly, ctx)
5709
+ const isMobile = window.innerWidth <= 768;
5611
5710
  // 创建人和修改人、创建时间和修改时间不显示
5612
5711
  if(___namespace.includes(OMIT_FIELDS, field.name) && ctx.showSystemFields != true){
5613
5712
  return;
@@ -5642,20 +5741,42 @@ setTimeout(()=>{
5642
5741
  // }
5643
5742
  // break;
5644
5743
  case 'select':
5645
- convertData = {
5646
- type: getAmisStaticFieldType('select', readonly),
5647
- joinValues: false,
5648
- options: getSelectFieldOptions(field),
5649
- extractValue: true,
5650
- clearable: true,
5651
- labelField: 'label',
5652
- valueField: 'value',
5653
- tpl: readonly ? getSelectTpl(field) : null
5654
- };
5655
- if(field.multiple){
5656
- convertData.multiple = true;
5657
- convertData.extractValue = true;
5744
+ if(readonly){
5745
+ const selectOptions = field.options;
5746
+ let map = {};
5747
+ ___namespace.forEach(selectOptions,(option)=>{
5748
+ const optionValue = option.value + '';
5749
+ if(option.color){
5750
+ const background = '#'+option.color;
5751
+ const color = getContrastColor(background);
5752
+ const optionColorStyle = 'background:'+background+';color:'+color;
5753
+ map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
5754
+ }else {
5755
+ map[optionValue] = option.label;
5756
+ }
5757
+ });
5758
+ convertData = {
5759
+ type: "static-mapping",
5760
+ name: field.name,
5761
+ label: field.label,
5762
+ map: map
5763
+ };
5764
+ }else {
5765
+ convertData = {
5766
+ type: getAmisStaticFieldType('select', readonly),
5767
+ joinValues: false,
5768
+ options: getSelectFieldOptions(field),
5769
+ extractValue: true,
5770
+ clearable: true,
5771
+ labelField: 'label',
5772
+ valueField: 'value'
5773
+ };
5774
+ if(field.multiple){
5775
+ convertData.multiple = true;
5776
+ convertData.extractValue = true;
5777
+ }
5658
5778
  }
5779
+
5659
5780
  break;
5660
5781
  case 'boolean':
5661
5782
  convertData = {
@@ -5675,7 +5796,26 @@ setTimeout(()=>{
5675
5796
  };
5676
5797
  break;
5677
5798
  case 'date':
5678
- convertData = {
5799
+ convertData = isMobile && !readonly ? {
5800
+ type: "native-date",
5801
+ pipeIn: (value, data) => {
5802
+ if (value) {
5803
+ value = moment(value).utc().format('YYYY-MM-DD');
5804
+ return value;
5805
+ } else {
5806
+ return "";
5807
+ }
5808
+
5809
+ },
5810
+ pipeOut: (value, oldValue, data) => {
5811
+ if (value) {
5812
+ value = moment(value).format('YYYY-MM-DDT00:00:00.000[Z]');
5813
+ return value;
5814
+ } else {
5815
+ return "";
5816
+ }
5817
+ }
5818
+ } : {
5679
5819
  type: getAmisStaticFieldType('date', readonly),
5680
5820
  inputFormat: "YYYY-MM-DD",
5681
5821
  format:'YYYY-MM-DDT00:00:00.000[Z]',
@@ -5694,12 +5834,48 @@ setTimeout(()=>{
5694
5834
  };
5695
5835
  break;
5696
5836
  case 'datetime':
5697
- convertData = {
5837
+ convertData = isMobile && !readonly ? {
5838
+ type: "combo",
5839
+ pipeIn: (value, data) => {
5840
+ let revalue = {};
5841
+ if (value && value != "Invalid date") {
5842
+ value = moment(value).format('YYYY-MM-DD HH:mm:ss');
5843
+ revalue[field.name + "-native-date"] = value.split(' ')[0];
5844
+ revalue[field.name + "-native-time"] = value.split(' ')[1];
5845
+ } else {
5846
+ revalue[field.name + "-native-date"] = "";
5847
+ revalue[field.name + "-native-time"] = "";
5848
+ }
5849
+ return revalue;
5850
+ },
5851
+ pipeOut: (value, oldValue, data) => {
5852
+ let revalue = "";
5853
+ if (value[field.name + "-native-date"] && value[field.name + "-native-time"]) {
5854
+ revalue = value[field.name + "-native-date"] + " " + value[field.name + "-native-time"];
5855
+ revalue = moment(revalue).utc().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]');
5856
+ }
5857
+ return revalue;
5858
+ },
5859
+ items: [
5860
+ {
5861
+ type: "native-date",
5862
+ name: field.name + "-native-date",
5863
+ className: "steedos-native-date",
5864
+ value: ""
5865
+ },
5866
+ {
5867
+ type: "native-time",
5868
+ name: field.name + "-native-time",
5869
+ className: "steedos-native-time",
5870
+ value: ""
5871
+ }
5872
+ ]
5873
+ } : {
5698
5874
  type: getAmisStaticFieldType('datetime', readonly),
5699
5875
  inputFormat: 'YYYY-MM-DD HH:mm',
5700
- format:'YYYY-MM-DDTHH:mm:ss.SSSZ',
5876
+ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ',
5701
5877
  tpl: readonly ? getDateTimeTpl(field) : null,
5702
- utc: true
5878
+ utc: true,
5703
5879
  };
5704
5880
  break;
5705
5881
  case 'input-time-range':
@@ -5714,7 +5890,26 @@ setTimeout(()=>{
5714
5890
  };
5715
5891
  break;
5716
5892
  case 'time':
5717
- convertData = {
5893
+ convertData = isMobile && !readonly ? {
5894
+ type: "native-time",
5895
+ pipeIn: (value, data) => {
5896
+ if (value) {
5897
+ value = moment(value).utc().format('HH:mm');
5898
+ return value;
5899
+ } else {
5900
+ return "";
5901
+ }
5902
+
5903
+ },
5904
+ pipeOut: (value, oldValue, data) => {
5905
+ if (value) {
5906
+ value = moment('1970-01-01 ' + value).format('1970-01-01THH:mm:00.000[Z]');
5907
+ return value;
5908
+ } else {
5909
+ return "";
5910
+ }
5911
+ }
5912
+ } : {
5718
5913
  type: getAmisStaticFieldType('time', readonly),
5719
5914
  inputFormat: 'HH:mm',
5720
5915
  timeFormat:'HH:mm',
@@ -5918,6 +6113,13 @@ setTimeout(()=>{
5918
6113
  convertData.quickEdit = false;
5919
6114
  }
5920
6115
 
6116
+ let fieldTypeClassName = ' steedos-' + convertData.type + (readonly ? '-readonly' : '-edit');
6117
+ if (convertData.className) {
6118
+ convertData.className = convertData.className + fieldTypeClassName;
6119
+ } else {
6120
+ convertData.className = fieldTypeClassName;
6121
+ }
6122
+
5921
6123
  if(field.visible_on){
5922
6124
  // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
5923
6125
  if(field.visible_on.startsWith("{{")){
@@ -6602,6 +6804,7 @@ setTimeout(()=>{
6602
6804
  hiddenOn: options.tableHiddenOn,
6603
6805
  autoFillHeight: options.isRelated ? false : true,
6604
6806
  className: `flex-auto ${crudClassName || ""}`,
6807
+ bodyClassName: "bg-white",
6605
6808
  crudClassName: crudClassName,
6606
6809
  },
6607
6810
  bodyProps,
@@ -6947,7 +7150,31 @@ setTimeout(()=>{
6947
7150
  ...getAmisFileReadonlySchema(field)
6948
7151
  }, field.amis, {name: field.name}));
6949
7152
  }
6950
-
7153
+ else if(field.type === 'select'){
7154
+ const selectOptions = field.options;
7155
+ let map = {};
7156
+ _$1.forEach(selectOptions,(option)=>{
7157
+ const optionValue = option.value + '';
7158
+ if(option.color){
7159
+ const background = '#'+option.color;
7160
+ const color = getContrastColor(background);
7161
+ const optionColorStyle = 'background:'+background+';color:'+color;
7162
+ map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
7163
+ }else {
7164
+ map[optionValue] = option.label;
7165
+ }
7166
+ });
7167
+ columns.push(Object.assign({}, {
7168
+ type: "mapping",
7169
+ name: field.name,
7170
+ label: field.label,
7171
+ map: map,
7172
+ sortable: field.sortable,
7173
+ width: field.width,
7174
+ toggled: field.toggled,
7175
+ className:"whitespace-nowrap",
7176
+ }, field.amis, {name: field.name}));
7177
+ }
6951
7178
  else {
6952
7179
  const tpl = await getFieldTpl(field, options);
6953
7180