@steedos-widgets/amis-lib 3.6.0-beta.6 → 3.6.0-beta.9

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
@@ -1643,7 +1643,6 @@ async function getQuickEditSchema(field, options){
1643
1643
  {
1644
1644
  "actionType": "custom",
1645
1645
  "script": `
1646
-
1647
1646
  var _display = _.cloneDeep(event.data._display);
1648
1647
  ${displayField}
1649
1648
  doAction({actionType: 'setValue', "args": {"value": {_display}},componentId: "${quickEditId}"});
@@ -1814,6 +1813,23 @@ async function getQuickEditSchema(field, options){
1814
1813
  "onEvent":{
1815
1814
  "init":{
1816
1815
  "actions":[
1816
+ //amis3.6无法从数据域中直接拿到正确的selectitems,需要通过crud组件的getSelected()函数获取
1817
+ {
1818
+ "actionType": "custom",
1819
+ "script": `
1820
+ crudScoped = event.context.scoped.getComponentById('${options.crudId}');
1821
+ const selectedItems = crudScoped && crudScoped.control.getSelected();
1822
+ doAction({
1823
+ "componentId": "${quickEditId}",
1824
+ "actionType": "setValue",
1825
+ "args": {
1826
+ "value": {
1827
+ selectedItems
1828
+ }
1829
+ }
1830
+ });
1831
+ `
1832
+ },
1817
1833
  {
1818
1834
  "actionType": "setValue",
1819
1835
  "componentId": quickEditId,
@@ -2577,6 +2593,14 @@ async function getTableSchema$1(fields, options){
2577
2593
 
2578
2594
  }
2579
2595
 
2596
+ const treeConfig = {};
2597
+
2598
+ if(options.enable_tree){
2599
+ treeConfig.expandConfig = {
2600
+ expand: 'first'
2601
+ };
2602
+ }
2603
+
2580
2604
  return {
2581
2605
  mode: "table",
2582
2606
  perPageAvailable: [5, 10, 20, 50, 100, 500],
@@ -2592,6 +2616,7 @@ async function getTableSchema$1(fields, options){
2592
2616
  labelTpl: `\${${options.labelFieldName}}`,
2593
2617
  autoFillHeight: false, // 自动高度效果不理想,先关闭
2594
2618
  columnsTogglable: false,
2619
+ ...treeConfig
2595
2620
  }
2596
2621
  }
2597
2622
 
@@ -2908,17 +2933,6 @@ async function getTableApi(mainObject, fields, options){
2908
2933
  payload.data.rows = getTreeOptions(records,{"valueField":"_id"});
2909
2934
  assignIndexToTreeRecords(payload.data.rows, '');
2910
2935
  }
2911
- try{
2912
- setTimeout(() => {
2913
- let expandBtn = $('.steedos-object-listview-content .antd-Table-content .antd-Table-table thead .antd-Table-expandBtn');
2914
- if(expandBtn && expandBtn.length > 0 && !expandBtn.hasClass("is-active")){
2915
- expandBtn[0].click();
2916
- }
2917
- }, 600);
2918
- }
2919
- catch(ex){
2920
- console.error("tree数据格式展开异常:", ex);
2921
- }
2922
2936
  }
2923
2937
 
2924
2938
 
@@ -5746,12 +5760,16 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
5746
5760
  // }
5747
5761
  // listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
5748
5762
  // 点击搜索的时候自动收起搜索栏
5749
- let resizeWindow = function(){
5750
- //触发amis crud 高度重算
5751
- setTimeout(()=>{
5752
- window.dispatchEvent(new Event("resize"))
5753
- }, 500);
5754
- }
5763
+ //触发amis crud 高度重算
5764
+ doAction({
5765
+ "actionType": "broadcast",
5766
+ "args": {
5767
+ "eventName": "@height.changed.${objectSchema.name}"
5768
+ },
5769
+ "data": {
5770
+ "timeOut": 500
5771
+ }
5772
+ });
5755
5773
  const filterService = filterForm.context.getComponents().find(function(n){
5756
5774
  return n.props.type === "service";
5757
5775
  });
@@ -5853,9 +5871,16 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
5853
5871
  let filterFormService = SteedosUI.getClosestAmisComponentByType(filterForm.context, "service");
5854
5872
  filterFormService.setData({showFieldsFilter: !!!filterFormService.props.data.showFieldsFilter});
5855
5873
  //触发amis crud 高度重算
5856
- setTimeout(()=>{
5857
- window.dispatchEvent(new Event("resize"))
5858
- }, 100);
5874
+ doAction({
5875
+ "actionType": "broadcast",
5876
+ "args": {
5877
+ "eventName": "@height.changed.${objectSchema.name}"
5878
+ },
5879
+ "data": {
5880
+ "timeOut": 100
5881
+ }
5882
+ });
5883
+
5859
5884
  // 移除搜索按钮上的红点
5860
5885
  // let crudService = scope.getComponentById("service_listview_" + event.data.objectName);
5861
5886
  let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
@@ -6012,9 +6037,15 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
6012
6037
  sessionStorage.setItem(listViewPropsStoreKey, JSON.stringify(localListViewProps));
6013
6038
  }
6014
6039
  //触发amis crud 高度重算
6015
- setTimeout(()=>{
6016
- window.dispatchEvent(new Event("resize"))
6017
- }, 100)
6040
+ doAction({
6041
+ "actionType": "broadcast",
6042
+ "args": {
6043
+ "eventName": "@height.changed.${objectSchema.name}"
6044
+ },
6045
+ "data": {
6046
+ "timeOut": 100
6047
+ }
6048
+ });
6018
6049
  // ===END===
6019
6050
  `;
6020
6051
  return {
@@ -6509,7 +6540,10 @@ async function getObjectRecordDetailHeader(objectSchema, recordId, options) {
6509
6540
  "@history_paths.changed": {
6510
6541
  "actions": [
6511
6542
  {
6512
- "actionType": "reload"
6543
+ "actionType": "reload",
6544
+ // amis 3.6需要传入data来触发下面的window:historyPaths重新计算,此问题随机偶发,加上data后正常
6545
+ "data": {
6546
+ }
6513
6547
  }
6514
6548
  ]
6515
6549
  }
@@ -7717,13 +7751,16 @@ const filterService = filterForm.context.getComponents().find(function(n){
7717
7751
  });
7718
7752
  let toShowFieldsFilter = !!!filterService.props.data.showFieldsFilter;
7719
7753
  filterService.setData({showFieldsFilter: toShowFieldsFilter});
7720
- let resizeWindow = function(){
7721
- //触发amis crud 高度重算
7722
- setTimeout(()=>{
7723
- window.dispatchEvent(new Event("resize"))
7724
- }, 1000);
7725
- }
7726
- resizeWindow();
7754
+ //触发amis crud 高度重算
7755
+ doAction({
7756
+ "actionType": "broadcast",
7757
+ "args": {
7758
+ "eventName": "@height.changed." + event.data.objectName
7759
+ },
7760
+ "data": {
7761
+ "timeOut": 1000
7762
+ }
7763
+ });
7727
7764
  // 手机端在显示搜索栏时隐藏crud上的刷新按钮,因为点击后crud高度显示有问题
7728
7765
  let crudService = scope.getComponentById("service_listview_" + event.data.objectName);
7729
7766
  crudService && crudService.setData({showFieldsFilter: toShowFieldsFilter});
@@ -8087,12 +8124,16 @@ async function getObjectFilter(objectSchema, fields, options) {
8087
8124
  return;
8088
8125
  }
8089
8126
  // 列表搜索栏字段值变更后立刻触发提交表单执行crud搜索,所以这里需要额外重算crud高度及筛选按钮红色星号图标显示隐藏
8090
- let resizeWindow = function(){
8091
- //触发amis crud 高度重算
8092
- setTimeout(()=>{
8093
- window.dispatchEvent(new Event("resize"))
8094
- }, 1000);
8095
- }
8127
+ //触发amis crud 高度重算
8128
+ doAction({
8129
+ "actionType": "broadcast",
8130
+ "args": {
8131
+ "eventName": "@height.changed.${objectSchema.name}"
8132
+ },
8133
+ "data": {
8134
+ "timeOut": 1000
8135
+ }
8136
+ });
8096
8137
  resizeWindow();
8097
8138
  const scope = event.context.scoped;
8098
8139
  // let filterFormValues = event.data;
@@ -8441,7 +8482,24 @@ async function getObjectCRUD(objectSchema, fields, options){
8441
8482
  id: `service_${id}`,
8442
8483
  name: `page`,
8443
8484
  data: options.amisData,
8444
- body: body
8485
+ body: body,
8486
+ //监听广播事件,重算crud高度
8487
+ onEvent: {
8488
+ [`@height.changed.${objectSchema.name}`]: {
8489
+ "actions": [
8490
+ {
8491
+ "actionType": "custom",
8492
+ "script": `
8493
+ var crudScoped = event.context.scoped.getComponentById('${body.id}');
8494
+ var timeOut = event.data.timeOut || 500;
8495
+ setTimeout(()=>{
8496
+ crudScoped && crudScoped.control.updateAutoFillHeight();
8497
+ }, timeOut);
8498
+ `
8499
+ }
8500
+ ]
8501
+ }
8502
+ }
8445
8503
  }
8446
8504
  }
8447
8505
 
@@ -10737,14 +10795,6 @@ async function lookupToAmisPicker(field, readonly, ctx){
10737
10795
  }
10738
10796
  });
10739
10797
  payload.data.rows = treeRecords;
10740
- try{
10741
- setTimeout(() => {
10742
- $('.amis-dialog-widget.antd-Modal .antd-Table-content .antd-Table-table thead .antd-Table-expandBtn')[0]?.click();
10743
- }, 600);
10744
- }
10745
- catch(ex){
10746
- console.error("tree数据格式展开异常:", ex);
10747
- }
10748
10798
  }
10749
10799
  return payload;
10750
10800
  `;
@@ -10771,6 +10821,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
10771
10821
  labelFieldName,
10772
10822
  top: top,
10773
10823
  isLookup: true,
10824
+ enable_tree: refObjectConfig.enable_tree,
10774
10825
  ...ctx
10775
10826
  });
10776
10827
 
@@ -11189,18 +11240,28 @@ async function lookupToAmis(field, readonly, ctx){
11189
11240
  enableEnhancedLookup = true;
11190
11241
  }
11191
11242
  }
11243
+ let amisSchema;
11192
11244
  // 默认使用下拉框模式显示lookup选项,只能配置了enable_enhanced_lookup才使用弹出增强模式
11193
11245
  if(enableEnhancedLookup == true){
11194
- return await lookupToAmisPicker(field, readonly, ctx);
11246
+ amisSchema = await lookupToAmisPicker(field, readonly, ctx);
11195
11247
  }else if(refObject.enable_tree) {
11196
- return await lookupToAmisTreeSelect(field, readonly, Object.assign({}, ctx, {
11248
+ amisSchema = await lookupToAmisTreeSelect(field, readonly, Object.assign({}, ctx, {
11197
11249
  labelField: referenceTo.labelField?.name || 'name',
11198
11250
  valueField: referenceTo.valueField?.name || '_id',
11199
11251
  objectName: referenceTo.objectName
11200
11252
  }));
11201
11253
  }else {
11202
- return await lookupToAmisSelect(field, readonly, ctx);
11254
+ amisSchema = await lookupToAmisSelect(field, readonly, ctx);
11255
+ }
11256
+ let refLookupPage = refObject.pages && refObject.pages.lookup;
11257
+ if(refLookupPage){
11258
+ if(typeof refLookupPage == 'string'){
11259
+ refLookupPage = JSON.parse(refLookupPage);
11260
+ }
11261
+ // Object.assign(amisSchema, refLookupPage);
11262
+ // amisSchema = _.defaultsDeep({}, refLookupPage, amisSchema);
11203
11263
  }
11264
+ return amisSchema;
11204
11265
  }
11205
11266
 
11206
11267
  async function lookupToAmisSelectUser(field, readonly, ctx){