@steedos-widgets/amis-lib 3.6.0-beta.3 → 3.6.0-beta.5

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
@@ -382,8 +382,8 @@ const Router = {
382
382
  /*
383
383
  * @Author: baozhoutao@steedos.com
384
384
  * @Date: 2022-07-20 16:29:22
385
- * @LastEditors: liaodaxue
386
- * @LastEditTime: 2023-09-11 17:19:53
385
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
386
+ * @LastEditTime: 2023-12-28 14:59:08
387
387
  * @Description:
388
388
  */
389
389
 
@@ -440,6 +440,21 @@ function getLookupListView(refObjectConfig) {
440
440
  return listView;
441
441
  }
442
442
 
443
+
444
+ /**
445
+ * 获取可比较的amis版本号
446
+ * @returns 只返回前两位版本,第三位忽略,比如3.6.3返回3.6
447
+ */
448
+ function getComparableAmisVersion() {
449
+ let amis = (window.amisRequire && window.amisRequire('amis')) || window.Amis;
450
+ let amisVersion = amis && amis.version;
451
+ if(amisVersion){
452
+ let comparableVersions = amisVersion.split(".");
453
+ let comparableVersion = parseFloat(comparableVersions[0].toString() + "." + comparableVersions[1].toString());
454
+ return comparableVersion;
455
+ }
456
+ }
457
+
443
458
  /*
444
459
  * @Author: baozhoutao@steedos.com
445
460
  * @Date: 2022-05-23 09:53:08
@@ -530,7 +545,7 @@ function getNameTpl(field, ctx){
530
545
  if(ctx && ctx.isLookup){
531
546
  linkTarget = "target='_blank'";
532
547
  }
533
- return `<a href="${href}" ${linkTarget}>\${${field.name}}</a>`
548
+ return `<a href="${href}" ${linkTarget}>\${${field.name} | raw}</a>`
534
549
  }
535
550
 
536
551
  function getRelatedFieldTpl(field, ctx){
@@ -1087,7 +1102,7 @@ function getAmisStaticFieldType(type, readonly, options){
1087
1102
  * @Author: baozhoutao@steedos.com
1088
1103
  * @Date: 2022-10-28 14:15:09
1089
1104
  * @LastEditors: liaodaxue
1090
- * @LastEditTime: 2023-10-30 17:51:54
1105
+ * @LastEditTime: 2023-12-29 10:46:50
1091
1106
  * @Description:
1092
1107
  */
1093
1108
 
@@ -1141,7 +1156,8 @@ const getAmisFileEditSchema = (steedosField)=>{
1141
1156
  dataType: "form-data",
1142
1157
  url: `\${context.rootUrl}/s3/${tableName}`,
1143
1158
  requestAdaptor: `
1144
- const { _master, global,context } = api.body;
1159
+ const superData = (typeof context != 'undefined') ? context : api.body;
1160
+ const { _master, global } = superData;
1145
1161
  // const { recordId, objectName } = _master;
1146
1162
  const { spaceId, userId, user } = global;
1147
1163
  /*
@@ -1159,8 +1175,9 @@ const getAmisFileEditSchema = (steedosField)=>{
1159
1175
  return api;
1160
1176
  `,
1161
1177
  adaptor: `
1162
- const { context } = api.body;
1163
- var rootUrl = context.rootUrl + "/api/files/${tableName}/";
1178
+ const superData = (typeof context != 'undefined') ? context : api.body;
1179
+ const { context:pageContext } = superData;
1180
+ var rootUrl = pageContext.rootUrl + "/api/files/${tableName}/";
1164
1181
  payload = {
1165
1182
  status: response.status == 200 ? 0 : response.status,
1166
1183
  msg: response.statusText,
@@ -1764,8 +1781,9 @@ async function getQuickEditSchema(field, options){
1764
1781
  case "avatar":
1765
1782
  case "image":
1766
1783
  quickEditSchema.body[0].receiver.adaptor = `
1767
- const { context } = api.body;
1768
- var rootUrl = context.rootUrl + "/api/files/${field.type}s/";
1784
+ const superData = (typeof context != 'undefined') ? context : api.body;
1785
+ const { context:pageContext } = superData;
1786
+ var rootUrl = pageContext.rootUrl + "/api/files/${field.type}s/";
1769
1787
  payload = {
1770
1788
  status: response.status == 200 ? 0 : response.status,
1771
1789
  msg: response.statusText,
@@ -2168,8 +2186,8 @@ async function getTableColumns(fields, options){
2168
2186
  const href = Router.getObjectDetailPath({
2169
2187
  ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
2170
2188
  });
2171
- columns[1].type = "tpl";
2172
- columns[1].tpl = `<a href="${href}">\${${columns[1].name}}</a>`;
2189
+ columns[0].type = "tpl";
2190
+ columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
2173
2191
  }
2174
2192
  return columns;
2175
2193
  }
@@ -2428,7 +2446,7 @@ async function getTableOperation(ctx){
2428
2446
  type: 'steedos-object-button',
2429
2447
  name: button.name,
2430
2448
  objectName: button.objectName,
2431
- visibleOn: getButtonVisibleOn$1(button),
2449
+ visibleOnAlias: getButtonVisibleOn$1(button),
2432
2450
  className: 'antd-Button--default'
2433
2451
  });
2434
2452
  });
@@ -2553,7 +2571,8 @@ async function getTableSchema$1(fields, options){
2553
2571
  }
2554
2572
 
2555
2573
  if(!isLookup && !hiddenColumnOperation){
2556
- columns.push(await getTableOperation(options));
2574
+ const toolbarOperation = await getTableOperation(options);
2575
+ columns.push(toolbarOperation);
2557
2576
  }
2558
2577
 
2559
2578
  }
@@ -5765,6 +5784,8 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
5765
5784
  `;
5766
5785
  const onCancelScript = `
5767
5786
  // console.log("===onCancelScript=form==");
5787
+ let isLookup = event.data.isLookup;
5788
+ let __lookupField = event.data.__lookupField;
5768
5789
  const scope = event.context.scoped;
5769
5790
  var filterForm = scope.parent.parent.getComponents().find(function(n){
5770
5791
  return n.props.type === "form";
@@ -5812,7 +5833,20 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
5812
5833
  // });
5813
5834
 
5814
5835
  // 清除__changedFilterFormValues中的值
5815
- crud && crud.setData({__changedFilterFormValues: {}});
5836
+ // crud && crud.setData({__changedFilterFormValues: {}});
5837
+ let __changedFilterFormValuesKey = "__changedFilterFormValues";
5838
+ if(isLookup && __lookupField){
5839
+ let lookupTag = "__" + __lookupField.name + "__" + __lookupField.reference_to;
5840
+ if(__lookupField.reference_to_field){
5841
+ lookupTag += "__" + __lookupField.reference_to_field;
5842
+ }
5843
+ __changedFilterFormValuesKey += lookupTag;
5844
+ }
5845
+ if(crud){
5846
+ let crudData = crud.getData();
5847
+ crudData[__changedFilterFormValuesKey] = {};
5848
+ crud.setData(crudData);
5849
+ }
5816
5850
  filterForm.handleFormSubmit(event);
5817
5851
  // crud.handleFilterSubmit(removedValues);
5818
5852
 
@@ -7740,7 +7774,12 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
7740
7774
  __changedSearchBoxValues["${keywordsSearchBoxName}"] = event.data["${keywordsSearchBoxName}"];
7741
7775
  // crudService && crudService.setData({__changedSearchBoxValues: __changedSearchBoxValues});
7742
7776
  // 这里不用crudService而用crud是因为lookup字段弹出的列表中的crudService中的变量无法传入crud的发送适配器中
7743
- crud && crud.setData({__changedSearchBoxValues: __changedSearchBoxValues});
7777
+ // crud && crud.setData({__changedSearchBoxValues: __changedSearchBoxValues});
7778
+ if(crud){
7779
+ let crudData = crud.getData();
7780
+ crudData.__changedSearchBoxValues = __changedSearchBoxValues;
7781
+ crud.setData(crudData);
7782
+ }
7744
7783
  `;
7745
7784
 
7746
7785
  // onSearchScript中加上了onChangeScript中的脚本,是因为amis 3.2不能用change事件执行onChangeScript
@@ -7753,9 +7792,19 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
7753
7792
  // const scope = event.context.scoped;
7754
7793
  // 如果点击过顶部搜索栏表单的取消按钮,会把此处event.data.__super.__super.__super中的搜索表单项的所有字段设置为null
7755
7794
  // 点击取消按钮后继续在表单项中输入过滤条件且最后没有点击回车按键或点击表单项搜索按钮的话,在快速搜索中点击回车按钮提交搜索会所顶部搜索表单中的字段值清空
7795
+ let isLookup = event.data.isLookup;
7796
+ let __lookupField = event.data.__lookupField;
7797
+ let __changedFilterFormValuesKey = "__changedFilterFormValues";
7798
+ if(isLookup && __lookupField){
7799
+ let lookupTag = "__" + __lookupField.name + "__" + __lookupField.reference_to;
7800
+ if(__lookupField.reference_to_field){
7801
+ lookupTag += "__" + __lookupField.reference_to_field;
7802
+ }
7803
+ __changedFilterFormValuesKey += lookupTag;
7804
+ }
7756
7805
  let filterForm = SteedosUI.getClosestAmisComponentByType(scope, "form");
7757
7806
  setTimeout(function(){
7758
- filterForm.setValues(event.data.__changedFilterFormValues);
7807
+ filterForm.setValues(event.data[__changedFilterFormValuesKey]);
7759
7808
  }, 500);
7760
7809
  `;
7761
7810
 
@@ -7776,8 +7825,8 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
7776
7825
  "name": keywordsSearchBoxName,
7777
7826
  "placeholder": "搜索此列表",
7778
7827
  "value": crudKeywords,
7779
- "clearable": true,
7780
- // "clearAndSubmit": true,//因为清除并不会触发失去焦点事件,只有禁用,但是它会触发change事件,所以等升级到amis 3.4+后可以重新放开
7828
+ // "clearable": true,//因为清除并不会触发失去焦点事件,只有禁用,但是它会触发change事件,所以等升级到amis 3.4+后可以重新放开
7829
+ "clearAndSubmit": true,
7781
7830
  "searchImediately": false,
7782
7831
  "onEvent": {
7783
7832
  "search": {
@@ -8057,6 +8106,9 @@ async function getObjectFilter(objectSchema, fields, options) {
8057
8106
  crudService && crudService.setData({isFieldsFilterEmpty});
8058
8107
  `;
8059
8108
  let onChangeScript = `
8109
+ let isLookup = event.data.isLookup;
8110
+ let __lookupField = event.data.__lookupField;
8111
+ console.log("==onChangeScript=isLookup===", isLookup);
8060
8112
  const scope = event.context.scoped;
8061
8113
  // let filterFormValues = event.data;
8062
8114
  let filterForm = SteedosUI.getClosestAmisComponentByType(scope, "form");
@@ -8068,7 +8120,20 @@ async function getObjectFilter(objectSchema, fields, options) {
8068
8120
  // let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
8069
8121
  // crudService && crudService.setData({__changedFilterFormValues: changedFilterFormValues});
8070
8122
  // 这里不用crudService而用crud是因为lookup字段弹出的列表中的crudService中的变量无法传入crud的发送适配器中
8071
- crud && crud.setData({__changedFilterFormValues: changedFilterFormValues});
8123
+ // crud && crud.setData({__changedFilterFormValues: changedFilterFormValues});
8124
+ let __changedFilterFormValuesKey = "__changedFilterFormValues";
8125
+ if(isLookup && __lookupField){
8126
+ let lookupTag = "__" + __lookupField.name + "__" + __lookupField.reference_to;
8127
+ if(__lookupField.reference_to_field){
8128
+ lookupTag += "__" + __lookupField.reference_to_field;
8129
+ }
8130
+ __changedFilterFormValuesKey += lookupTag;
8131
+ }
8132
+ if(crud){
8133
+ let crudData = crud.getData();
8134
+ crudData[__changedFilterFormValuesKey] = changedFilterFormValues;
8135
+ crud.setData(crudData);
8136
+ }
8072
8137
  `;
8073
8138
  return {
8074
8139
  "title": "",
@@ -10466,13 +10531,24 @@ async function lookupToAmisPicker(field, readonly, ctx){
10466
10531
  let keywordsSearchBoxName = `__keywords_lookup__${field.name.replace(/\./g, "_")}__to__${refObjectConfig.name}`;
10467
10532
 
10468
10533
  source.requestAdaptor = `
10469
- let __changedFilterFormValues = api.data.$self.__changedFilterFormValues || {};
10534
+ let __changedFilterFormValuesKey = "__changedFilterFormValues";
10535
+ let __lookupField = api.data.$self.__lookupField;
10536
+ if(__lookupField){
10537
+ let lookupTag = "__" + __lookupField.name + "__" + __lookupField.reference_to;
10538
+ if(__lookupField.reference_to_field){
10539
+ lookupTag += "__" + __lookupField.reference_to_field;
10540
+ }
10541
+ __changedFilterFormValuesKey += lookupTag;
10542
+ }
10543
+ let __changedFilterFormValues = api.data.$self[__changedFilterFormValuesKey] || {};
10470
10544
  let __changedSearchBoxValues = api.data.$self.__changedSearchBoxValues || {};
10471
10545
  // 把表单搜索和快速搜索中的change事件中记录的过滤条件也拼到$self中,是为解决触发搜索请求时,两边输入的过滤条件都带上,即:
10472
10546
  // 有时在搜索表单中输入过滤条件事,忘记点击回车键或搜索按钮,而是进一步修改快速搜索框中的关键字点击其中回车键触发搜索
10473
10547
  // 这种情况下,触发的搜索请求中没有带上搜索表单中输入的过滤条件。
10474
10548
  // 反过来先在快速搜索框中输入过滤条件却不点击其中回车键触发搜索,而是到搜索表单中触发搜索请求也是一样的。
10475
- Object.assign(api.data.$self, __changedSearchBoxValues, __changedFilterFormValues);
10549
+ if(api.data.$self.op !== 'loadOptions'){
10550
+ Object.assign(api.data.$self, __changedSearchBoxValues, __changedFilterFormValues);
10551
+ }
10476
10552
  const selfData = JSON.parse(JSON.stringify(api.data.$self));
10477
10553
  var filters = [];
10478
10554
  var pageSize = api.data.pageSize || 10;
@@ -10679,7 +10755,12 @@ async function lookupToAmisPicker(field, readonly, ctx){
10679
10755
  "objectName": refObjectConfig.name,
10680
10756
  "uiSchema": refObjectConfig,
10681
10757
  "listName": listName,// 需要按视图取可搜索项
10682
- "isLookup": true
10758
+ "isLookup": true,
10759
+ "__lookupField": {
10760
+ "name": field.name,
10761
+ "reference_to": refObjectConfig.name,
10762
+ "reference_to_field": field.reference_to_field
10763
+ }
10683
10764
  });
10684
10765
 
10685
10766
  if(!pickerSchema.onEvent){
@@ -10852,7 +10933,7 @@ async function lookupToAmisSelect(field, readonly, ctx){
10852
10933
  sendOn.push(`this.${fName}`);
10853
10934
  });
10854
10935
  if(depend_on.length > 0){
10855
- apiInfo.url = `${apiInfo.url}?${depend_on.join('&')}`;
10936
+ apiInfo.url = `${apiInfo.url}&${depend_on.join('&')}`;
10856
10937
  apiInfo.sendOn = `${sendOn.join(' && ')}`;
10857
10938
  }
10858
10939
  }
@@ -10960,6 +11041,13 @@ async function lookupToAmisSelect(field, readonly, ctx){
10960
11041
  autoComplete: apiInfo,
10961
11042
  searchable: true,
10962
11043
  };
11044
+ let amisVersion = getComparableAmisVersion();
11045
+ if(amisVersion >= 3.6){
11046
+ // amis 3.6中不加source会造成子表组件中弹出行编辑窗口的lookup字段有时不请求接口(概率现象,同一个地方反复操作有时请求有时不请求)
11047
+ // 但是同时配置autoComplete和source会多请求一次接口
11048
+ // TODO:应该想办法把是否字段在子表组件内,即ctx.isInputTable,如果不在子表组件内不需要加source
11049
+ data.source = apiInfo;
11050
+ }
10963
11051
  //删除xlink:href中的rootUrl前缀,解决客户端svg为空的问题
10964
11052
  const select_menuTpl = `<span class='flex items-center mt-0.5'>
10965
11053
  <span role='img' aria-label='smile' class='anticon anticon-smile'>
@@ -11041,6 +11129,14 @@ async function lookupToAmis(field, readonly, ctx){
11041
11129
 
11042
11130
  // 优先取字段中配置的enable_enhanced_lookup,字段上没配置时,才从对象上取enable_enhanced_lookup属性
11043
11131
  let enableEnhancedLookup = _$1.isBoolean(field.enable_enhanced_lookup) ? field.enable_enhanced_lookup : refObject.enable_enhanced_lookup;
11132
+ let amisVersion = getComparableAmisVersion();
11133
+ if(amisVersion >= 3.6){
11134
+ // amis 3.6.3单选的树picker有严重bug(https://github.com/baidu/amis/issues/9279),先强制使用下拉方式显示
11135
+ // amis 3.6.3多选的树会自动把下层节点,及下下层等所有子节点自动选中,跟amis 3.2不一样,而且目前没有开关,这不适合目前的业务场景,也先强制使用下拉方式显示
11136
+ if(enableEnhancedLookup && refObject.enable_tree){
11137
+ enableEnhancedLookup = false;
11138
+ }
11139
+ }
11044
11140
  // 默认使用下拉框模式显示lookup选项,只能配置了enable_enhanced_lookup才使用弹出增强模式
11045
11141
  if(enableEnhancedLookup == true){
11046
11142
  return await lookupToAmisPicker(field, readonly, ctx);
@@ -11319,9 +11415,9 @@ const OMIT_FIELDS = ['created', 'created_by', 'modified', 'modified_by'];
11319
11415
  // const Lookup = require('./lookup');
11320
11416
 
11321
11417
  function getBaseFields(readonly){
11322
- let calssName = 'm-1';
11418
+ let className = 'm-0';
11323
11419
  if(readonly){
11324
- calssName = `${calssName}`;
11420
+ className = `${className}`;
11325
11421
  }
11326
11422
  return [
11327
11423
  {
@@ -11329,7 +11425,7 @@ function getBaseFields(readonly){
11329
11425
  label: "创建人",
11330
11426
  type: "static",
11331
11427
  labelClassName: 'text-left',
11332
- className: calssName,
11428
+ className: className,
11333
11429
  tpl: getCreatedInfoTpl()
11334
11430
  },
11335
11431
  {
@@ -11337,7 +11433,7 @@ function getBaseFields(readonly){
11337
11433
  label: "修改人",
11338
11434
  type: "static",
11339
11435
  labelClassName: 'text-left',
11340
- className: calssName,
11436
+ className: className,
11341
11437
  tpl: getModifiedInfoTpl()
11342
11438
  }
11343
11439
  ]
@@ -12033,9 +12129,9 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
12033
12129
  }
12034
12130
  if(!_$1.isEmpty(convertData)){
12035
12131
  if(field.is_wide || convertData.type === 'group'){
12036
- convertData.className = 'col-span-2 m-1';
12132
+ convertData.className = 'col-span-2 m-0';
12037
12133
  }else {
12038
- convertData.className = 'm-1';
12134
+ convertData.className = 'm-0';
12039
12135
  }
12040
12136
  if(readonly){
12041
12137
  convertData.className = `${convertData.className} border-b`;
@@ -12441,7 +12537,7 @@ async function getFormBody(permissionFields, formFields, ctx){
12441
12537
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12442
12538
  * @Date: 2023-11-15 09:50:22
12443
12539
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12444
- * @LastEditTime: 2023-12-27 13:50:26
12540
+ * @LastEditTime: 2023-12-28 15:54:36
12445
12541
  */
12446
12542
 
12447
12543
  /**
@@ -12922,6 +13018,11 @@ async function getButtonActions(props, mode) {
12922
13018
  let dialogId = getComponentId("dialog", props.id);
12923
13019
  let buttonNextId = getComponentId("button_next", props.id);
12924
13020
  let formPaginationId = getComponentId("form_pagination", props.id);
13021
+ let parentFormData = "${__super.__super.__super.__super || {}}";
13022
+ let amisVersion = getComparableAmisVersion();
13023
+ if(amisVersion < 3.6){
13024
+ parentFormData = "${__super.__super || {}}";
13025
+ }
12925
13026
  if (mode == "new" || mode == "edit") {
12926
13027
  // let actionShowNewDialog = {
12927
13028
  // "actionType": "dialog",
@@ -13063,7 +13164,8 @@ async function getButtonActions(props, mode) {
13063
13164
  // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
13064
13165
  // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13065
13166
  // "__parentForm": "${__super.__super || {}}",
13066
- "__parentForm": mode == "new" ? "$$" : "${__super.__super || {}}",
13167
+ // "__parentForm": mode == "new" ? "$$" : "${__super.__super || {}}",
13168
+ "__parentForm": mode == "new" ? "$$" : parentFormData,
13067
13169
  "global": "${global}",
13068
13170
  "uiSchema": "${uiSchema}",
13069
13171
  "index": "${index}",
@@ -13156,7 +13258,7 @@ async function getButtonActions(props, mode) {
13156
13258
  // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
13157
13259
  // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13158
13260
  // "__parentForm": "${__super.__super || {}}",
13159
- "__parentForm": "${__super.__super || {}}",
13261
+ "__parentForm": parentFormData,
13160
13262
  "global": "${global}",
13161
13263
  "uiSchema": "${uiSchema}",
13162
13264
  "index": "${index}",
@@ -14773,8 +14875,8 @@ const getInstanceApprovalHistory = async ()=>{
14773
14875
  /*
14774
14876
  * @Author: baozhoutao@steedos.com
14775
14877
  * @Date: 2022-09-07 16:20:45
14776
- * @LastEditors: baozhoutao@steedos.com
14777
- * @LastEditTime: 2023-03-23 16:49:44
14878
+ * @LastEditors: liaodaxue
14879
+ * @LastEditTime: 2023-12-29 16:06:35
14778
14880
  * @Description:
14779
14881
  */
14780
14882
 
@@ -15600,7 +15702,6 @@ const getFlowFormSchema = async (instance, box) => {
15600
15702
  "messages": {
15601
15703
  },
15602
15704
  "requestAdaptor": `
15603
- const { context } = api.data;
15604
15705
  api.data = {
15605
15706
  query: \`
15606
15707
  {
@@ -15623,7 +15724,7 @@ const getFlowFormSchema = async (instance, box) => {
15623
15724
  `,
15624
15725
  "data": {
15625
15726
  // "&": "$$",
15626
- "context": "${context}",
15727
+ // "context": "${context}",
15627
15728
  "judge": "${new_judge}",
15628
15729
  }
15629
15730
  },