@steedos-widgets/amis-lib 1.2.6 → 1.2.7

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
@@ -2684,7 +2684,7 @@
2684
2684
  // }
2685
2685
  // listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
2686
2686
  `;
2687
- const onResetScript = `
2687
+ const onCancelScript = `
2688
2688
  const scope = event.context.scoped;
2689
2689
  var filterForm = scope.parent.parent.getComponents().find(function(n){
2690
2690
  return n.props.type === "form";
@@ -2712,6 +2712,14 @@
2712
2712
  }
2713
2713
  }
2714
2714
  listView.handleFilterSubmit(removedValues);
2715
+ const filterService = filterForm.context.getComponents().find(function(n){
2716
+ return n.props.type === "service";
2717
+ });
2718
+ filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsFilter});
2719
+ //触发amis crud 高度重算
2720
+ setTimeout(()=>{
2721
+ window.dispatchEvent(new Event("resize"))
2722
+ }, 100);
2715
2723
  `;
2716
2724
  const dataProviderInited = `
2717
2725
  const objectName = data.objectName;
@@ -2908,14 +2916,15 @@
2908
2916
  },
2909
2917
  {
2910
2918
  "type": "button",
2911
- "label": "重置",
2919
+ "label": "取消",
2920
+ "name": "btn_filter_form_cancel",
2912
2921
  "visibleOn": "this.filterFormSearchableFields && this.filterFormSearchableFields.length",
2913
2922
  "onEvent": {
2914
2923
  "click": {
2915
2924
  "actions": [
2916
2925
  {
2917
2926
  "actionType": "custom",
2918
- "script": onResetScript
2927
+ "script": onCancelScript
2919
2928
  }
2920
2929
  ]
2921
2930
  }
@@ -3519,11 +3528,26 @@ const filterForm = scope.getComponents().find(function(n){
3519
3528
  const filterService = filterForm.context.getComponents().find(function(n){
3520
3529
  return n.props.type === "service";
3521
3530
  });
3522
- filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsFilter});
3523
- //触发amis crud 高度重算
3524
- setTimeout(()=>{
3525
- window.dispatchEvent(new Event("resize"))
3526
- }, 100)
3531
+ // filterService.setData({showFieldsFilter: !!!filterService.props.data.showFieldsFilter});
3532
+ let resizeWindow = function(){
3533
+ //触发amis crud 高度重算
3534
+ setTimeout(()=>{
3535
+ window.dispatchEvent(new Event("resize"))
3536
+ }, 500);
3537
+ }
3538
+ if(filterService.props.data.showFieldsFilter){
3539
+ let buttonCancel = SteedosUI.getClosestAmisComponentByType(filterForm.context, "button", {
3540
+ direction: "down",
3541
+ name: "btn_filter_form_cancel"
3542
+ });
3543
+ buttonCancel.props.dispatchEvent('click', {}).then(function(){
3544
+ resizeWindow();
3545
+ });
3546
+ }
3547
+ else{
3548
+ filterService.setData({showFieldsFilter: true});
3549
+ resizeWindow();
3550
+ }
3527
3551
  `;
3528
3552
 
3529
3553
  function getExportApiRequestAdaptorScript(){
@@ -4262,8 +4286,8 @@ setTimeout(()=>{
4262
4286
  }
4263
4287
  else {
4264
4288
  return [
4289
+ "switch-per-page",
4265
4290
  "statistics",
4266
- // "switch-per-page",
4267
4291
  "pagination"
4268
4292
  ]
4269
4293
  }
@@ -5455,6 +5479,23 @@ setTimeout(()=>{
5455
5479
  return readonly ? getAmisFileReadonlySchema(steedosField) : getAmisFileEditSchema(steedosField);
5456
5480
  };
5457
5481
 
5482
+ /*
5483
+ * @Author: baozhoutao@steedos.com
5484
+ * @Date: 2022-07-20 16:29:22
5485
+ * @LastEditors: Please set LastEditors
5486
+ * @LastEditTime: 2023-05-11 11:19:54
5487
+ * @Description:
5488
+ */
5489
+
5490
+ function getContrastColor(bgColor) {
5491
+ var backgroundColor = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor;
5492
+ var r = parseInt(backgroundColor.substr(0, 2), 16);
5493
+ var g = parseInt(backgroundColor.substr(2, 2), 16);
5494
+ var b = parseInt(backgroundColor.substr(4, 2), 16);
5495
+ var brightness = (r * 299 + g * 587 + b * 114) / 1000;
5496
+ return brightness >= 128 ? "#000000" : "#ffffff";
5497
+ }
5498
+
5458
5499
  const OMIT_FIELDS = ['created', 'created_by', 'modified', 'modified_by'];
5459
5500
  // const Lookup = require('./lookup');
5460
5501
 
@@ -5608,6 +5649,8 @@ setTimeout(()=>{
5608
5649
  }
5609
5650
 
5610
5651
  async function convertSFieldToAmisField(field, readonly, ctx) {
5652
+ // console.log('convertSFieldToAmisField====>', field, readonly, ctx)
5653
+ const isMobile = window.innerWidth <= 768;
5611
5654
  // 创建人和修改人、创建时间和修改时间不显示
5612
5655
  if(___namespace.includes(OMIT_FIELDS, field.name) && ctx.showSystemFields != true){
5613
5656
  return;
@@ -5642,20 +5685,42 @@ setTimeout(()=>{
5642
5685
  // }
5643
5686
  // break;
5644
5687
  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;
5688
+ if(readonly){
5689
+ const selectOptions = field.options;
5690
+ let map = {};
5691
+ ___namespace.forEach(selectOptions,(option)=>{
5692
+ const optionValue = option.value + '';
5693
+ if(option.color){
5694
+ const background = '#'+option.color;
5695
+ const color = getContrastColor(background);
5696
+ const optionColorStyle = 'background:'+background+';color:'+color;
5697
+ map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
5698
+ }else {
5699
+ map[optionValue] = option.label;
5700
+ }
5701
+ });
5702
+ convertData = {
5703
+ type: "static-mapping",
5704
+ name: field.name,
5705
+ label: field.label,
5706
+ map: map
5707
+ };
5708
+ }else {
5709
+ convertData = {
5710
+ type: getAmisStaticFieldType('select', readonly),
5711
+ joinValues: false,
5712
+ options: getSelectFieldOptions(field),
5713
+ extractValue: true,
5714
+ clearable: true,
5715
+ labelField: 'label',
5716
+ valueField: 'value'
5717
+ };
5718
+ if(field.multiple){
5719
+ convertData.multiple = true;
5720
+ convertData.extractValue = true;
5721
+ }
5658
5722
  }
5723
+
5659
5724
  break;
5660
5725
  case 'boolean':
5661
5726
  convertData = {
@@ -5675,7 +5740,26 @@ setTimeout(()=>{
5675
5740
  };
5676
5741
  break;
5677
5742
  case 'date':
5678
- convertData = {
5743
+ convertData = isMobile && !readonly ? {
5744
+ type: "native-date",
5745
+ pipeIn: (value, data) => {
5746
+ if (value) {
5747
+ value = moment(value).utc().format('YYYY-MM-DD');
5748
+ return value;
5749
+ } else {
5750
+ return "";
5751
+ }
5752
+
5753
+ },
5754
+ pipeOut: (value, oldValue, data) => {
5755
+ if (value) {
5756
+ value = moment(value).format('YYYY-MM-DDT00:00:00.000[Z]');
5757
+ return value;
5758
+ } else {
5759
+ return "";
5760
+ }
5761
+ }
5762
+ } : {
5679
5763
  type: getAmisStaticFieldType('date', readonly),
5680
5764
  inputFormat: "YYYY-MM-DD",
5681
5765
  format:'YYYY-MM-DDT00:00:00.000[Z]',
@@ -5694,12 +5778,48 @@ setTimeout(()=>{
5694
5778
  };
5695
5779
  break;
5696
5780
  case 'datetime':
5697
- convertData = {
5781
+ convertData = isMobile && !readonly ? {
5782
+ type: "combo",
5783
+ pipeIn: (value, data) => {
5784
+ let revalue = {};
5785
+ if (value && value != "Invalid date") {
5786
+ value = moment(value).format('YYYY-MM-DD HH:mm:ss');
5787
+ revalue[field.name + "-native-date"] = value.split(' ')[0];
5788
+ revalue[field.name + "-native-time"] = value.split(' ')[1];
5789
+ } else {
5790
+ revalue[field.name + "-native-date"] = "";
5791
+ revalue[field.name + "-native-time"] = "";
5792
+ }
5793
+ return revalue;
5794
+ },
5795
+ pipeOut: (value, oldValue, data) => {
5796
+ let revalue = "";
5797
+ if (value[field.name + "-native-date"] && value[field.name + "-native-time"]) {
5798
+ revalue = value[field.name + "-native-date"] + " " + value[field.name + "-native-time"];
5799
+ revalue = moment(revalue).utc().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]');
5800
+ }
5801
+ return revalue;
5802
+ },
5803
+ items: [
5804
+ {
5805
+ type: "native-date",
5806
+ name: field.name + "-native-date",
5807
+ className: "steedos-native-date",
5808
+ value: ""
5809
+ },
5810
+ {
5811
+ type: "native-time",
5812
+ name: field.name + "-native-time",
5813
+ className: "steedos-native-time",
5814
+ value: ""
5815
+ }
5816
+ ]
5817
+ } : {
5698
5818
  type: getAmisStaticFieldType('datetime', readonly),
5699
5819
  inputFormat: 'YYYY-MM-DD HH:mm',
5700
- format:'YYYY-MM-DDTHH:mm:ss.SSSZ',
5820
+ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ',
5701
5821
  tpl: readonly ? getDateTimeTpl(field) : null,
5702
- utc: true
5822
+ utc: true,
5703
5823
  };
5704
5824
  break;
5705
5825
  case 'input-time-range':
@@ -5714,7 +5834,26 @@ setTimeout(()=>{
5714
5834
  };
5715
5835
  break;
5716
5836
  case 'time':
5717
- convertData = {
5837
+ convertData = isMobile && !readonly ? {
5838
+ type: "native-time",
5839
+ pipeIn: (value, data) => {
5840
+ if (value) {
5841
+ value = moment(value).utc().format('HH:mm');
5842
+ return value;
5843
+ } else {
5844
+ return "";
5845
+ }
5846
+
5847
+ },
5848
+ pipeOut: (value, oldValue, data) => {
5849
+ if (value) {
5850
+ value = moment('1970-01-01 ' + value).format('1970-01-01THH:mm:00.000[Z]');
5851
+ return value;
5852
+ } else {
5853
+ return "";
5854
+ }
5855
+ }
5856
+ } : {
5718
5857
  type: getAmisStaticFieldType('time', readonly),
5719
5858
  inputFormat: 'HH:mm',
5720
5859
  timeFormat:'HH:mm',
@@ -5918,6 +6057,13 @@ setTimeout(()=>{
5918
6057
  convertData.quickEdit = false;
5919
6058
  }
5920
6059
 
6060
+ let fieldTypeClassName = ' steedos-' + convertData.type + (readonly ? '-readonly' : '-edit');
6061
+ if (convertData.className) {
6062
+ convertData.className = convertData.className + fieldTypeClassName;
6063
+ } else {
6064
+ convertData.className = fieldTypeClassName;
6065
+ }
6066
+
5921
6067
  if(field.visible_on){
5922
6068
  // convertData.visibleOn = `\$${field.visible_on.substring(1, field.visible_on.length -1).replace(/formData./g, '')}`;
5923
6069
  if(field.visible_on.startsWith("{{")){
@@ -6601,7 +6747,7 @@ setTimeout(()=>{
6601
6747
  api: await getTableApi(objectSchema, fields, options),
6602
6748
  hiddenOn: options.tableHiddenOn,
6603
6749
  autoFillHeight: options.isRelated ? false : true,
6604
- className: `flex-auto ${crudClassName || ""}`,
6750
+ className: `flex-auto bg-white ${crudClassName || ""}`,
6605
6751
  crudClassName: crudClassName,
6606
6752
  },
6607
6753
  bodyProps,
@@ -6947,7 +7093,31 @@ setTimeout(()=>{
6947
7093
  ...getAmisFileReadonlySchema(field)
6948
7094
  }, field.amis, {name: field.name}));
6949
7095
  }
6950
-
7096
+ else if(field.type === 'select'){
7097
+ const selectOptions = field.options;
7098
+ let map = {};
7099
+ _$1.forEach(selectOptions,(option)=>{
7100
+ const optionValue = option.value + '';
7101
+ if(option.color){
7102
+ const background = '#'+option.color;
7103
+ const color = getContrastColor(background);
7104
+ const optionColorStyle = 'background:'+background+';color:'+color;
7105
+ map[optionValue] = `<span class="rounded-xl px-2 py-1" style='${optionColorStyle}'>${option.label}</span>`;
7106
+ }else {
7107
+ map[optionValue] = option.label;
7108
+ }
7109
+ });
7110
+ columns.push(Object.assign({}, {
7111
+ type: "mapping",
7112
+ name: field.name,
7113
+ label: field.label,
7114
+ map: map,
7115
+ sortable: field.sortable,
7116
+ width: field.width,
7117
+ toggled: field.toggled,
7118
+ className:"whitespace-nowrap",
7119
+ }, field.amis, {name: field.name}));
7120
+ }
6951
7121
  else {
6952
7122
  const tpl = await getFieldTpl(field, options);
6953
7123