@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.cjs.js CHANGED
@@ -409,8 +409,8 @@ const Router = {
409
409
  /*
410
410
  * @Author: baozhoutao@steedos.com
411
411
  * @Date: 2022-07-20 16:29:22
412
- * @LastEditors: liaodaxue
413
- * @LastEditTime: 2023-09-11 17:19:53
412
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
413
+ * @LastEditTime: 2023-12-28 14:59:08
414
414
  * @Description:
415
415
  */
416
416
 
@@ -467,6 +467,21 @@ function getLookupListView(refObjectConfig) {
467
467
  return listView;
468
468
  }
469
469
 
470
+
471
+ /**
472
+ * 获取可比较的amis版本号
473
+ * @returns 只返回前两位版本,第三位忽略,比如3.6.3返回3.6
474
+ */
475
+ function getComparableAmisVersion() {
476
+ let amis = (window.amisRequire && window.amisRequire('amis')) || window.Amis;
477
+ let amisVersion = amis && amis.version;
478
+ if(amisVersion){
479
+ let comparableVersions = amisVersion.split(".");
480
+ let comparableVersion = parseFloat(comparableVersions[0].toString() + "." + comparableVersions[1].toString());
481
+ return comparableVersion;
482
+ }
483
+ }
484
+
470
485
  /*
471
486
  * @Author: baozhoutao@steedos.com
472
487
  * @Date: 2022-05-23 09:53:08
@@ -557,7 +572,7 @@ function getNameTpl(field, ctx){
557
572
  if(ctx && ctx.isLookup){
558
573
  linkTarget = "target='_blank'";
559
574
  }
560
- return `<a href="${href}" ${linkTarget}>\${${field.name}}</a>`
575
+ return `<a href="${href}" ${linkTarget}>\${${field.name} | raw}</a>`
561
576
  }
562
577
 
563
578
  function getRelatedFieldTpl(field, ctx){
@@ -1114,7 +1129,7 @@ function getAmisStaticFieldType(type, readonly, options){
1114
1129
  * @Author: baozhoutao@steedos.com
1115
1130
  * @Date: 2022-10-28 14:15:09
1116
1131
  * @LastEditors: liaodaxue
1117
- * @LastEditTime: 2023-10-30 17:51:54
1132
+ * @LastEditTime: 2023-12-29 10:46:50
1118
1133
  * @Description:
1119
1134
  */
1120
1135
 
@@ -1168,7 +1183,8 @@ const getAmisFileEditSchema = (steedosField)=>{
1168
1183
  dataType: "form-data",
1169
1184
  url: `\${context.rootUrl}/s3/${tableName}`,
1170
1185
  requestAdaptor: `
1171
- const { _master, global,context } = api.body;
1186
+ const superData = (typeof context != 'undefined') ? context : api.body;
1187
+ const { _master, global } = superData;
1172
1188
  // const { recordId, objectName } = _master;
1173
1189
  const { spaceId, userId, user } = global;
1174
1190
  /*
@@ -1186,8 +1202,9 @@ const getAmisFileEditSchema = (steedosField)=>{
1186
1202
  return api;
1187
1203
  `,
1188
1204
  adaptor: `
1189
- const { context } = api.body;
1190
- var rootUrl = context.rootUrl + "/api/files/${tableName}/";
1205
+ const superData = (typeof context != 'undefined') ? context : api.body;
1206
+ const { context:pageContext } = superData;
1207
+ var rootUrl = pageContext.rootUrl + "/api/files/${tableName}/";
1191
1208
  payload = {
1192
1209
  status: response.status == 200 ? 0 : response.status,
1193
1210
  msg: response.statusText,
@@ -1791,8 +1808,9 @@ async function getQuickEditSchema(field, options){
1791
1808
  case "avatar":
1792
1809
  case "image":
1793
1810
  quickEditSchema.body[0].receiver.adaptor = `
1794
- const { context } = api.body;
1795
- var rootUrl = context.rootUrl + "/api/files/${field.type}s/";
1811
+ const superData = (typeof context != 'undefined') ? context : api.body;
1812
+ const { context:pageContext } = superData;
1813
+ var rootUrl = pageContext.rootUrl + "/api/files/${field.type}s/";
1796
1814
  payload = {
1797
1815
  status: response.status == 200 ? 0 : response.status,
1798
1816
  msg: response.statusText,
@@ -2195,8 +2213,8 @@ async function getTableColumns(fields, options){
2195
2213
  const href = Router.getObjectDetailPath({
2196
2214
  ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
2197
2215
  });
2198
- columns[1].type = "tpl";
2199
- columns[1].tpl = `<a href="${href}">\${${columns[1].name}}</a>`;
2216
+ columns[0].type = "tpl";
2217
+ columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
2200
2218
  }
2201
2219
  return columns;
2202
2220
  }
@@ -2455,7 +2473,7 @@ async function getTableOperation(ctx){
2455
2473
  type: 'steedos-object-button',
2456
2474
  name: button.name,
2457
2475
  objectName: button.objectName,
2458
- visibleOn: getButtonVisibleOn$1(button),
2476
+ visibleOnAlias: getButtonVisibleOn$1(button),
2459
2477
  className: 'antd-Button--default'
2460
2478
  });
2461
2479
  });
@@ -2580,7 +2598,8 @@ async function getTableSchema$1(fields, options){
2580
2598
  }
2581
2599
 
2582
2600
  if(!isLookup && !hiddenColumnOperation){
2583
- columns.push(await getTableOperation(options));
2601
+ const toolbarOperation = await getTableOperation(options);
2602
+ columns.push(toolbarOperation);
2584
2603
  }
2585
2604
 
2586
2605
  }
@@ -5792,6 +5811,8 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
5792
5811
  `;
5793
5812
  const onCancelScript = `
5794
5813
  // console.log("===onCancelScript=form==");
5814
+ let isLookup = event.data.isLookup;
5815
+ let __lookupField = event.data.__lookupField;
5795
5816
  const scope = event.context.scoped;
5796
5817
  var filterForm = scope.parent.parent.getComponents().find(function(n){
5797
5818
  return n.props.type === "form";
@@ -5839,7 +5860,20 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
5839
5860
  // });
5840
5861
 
5841
5862
  // 清除__changedFilterFormValues中的值
5842
- crud && crud.setData({__changedFilterFormValues: {}});
5863
+ // crud && crud.setData({__changedFilterFormValues: {}});
5864
+ let __changedFilterFormValuesKey = "__changedFilterFormValues";
5865
+ if(isLookup && __lookupField){
5866
+ let lookupTag = "__" + __lookupField.name + "__" + __lookupField.reference_to;
5867
+ if(__lookupField.reference_to_field){
5868
+ lookupTag += "__" + __lookupField.reference_to_field;
5869
+ }
5870
+ __changedFilterFormValuesKey += lookupTag;
5871
+ }
5872
+ if(crud){
5873
+ let crudData = crud.getData();
5874
+ crudData[__changedFilterFormValuesKey] = {};
5875
+ crud.setData(crudData);
5876
+ }
5843
5877
  filterForm.handleFormSubmit(event);
5844
5878
  // crud.handleFilterSubmit(removedValues);
5845
5879
 
@@ -7767,7 +7801,12 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
7767
7801
  __changedSearchBoxValues["${keywordsSearchBoxName}"] = event.data["${keywordsSearchBoxName}"];
7768
7802
  // crudService && crudService.setData({__changedSearchBoxValues: __changedSearchBoxValues});
7769
7803
  // 这里不用crudService而用crud是因为lookup字段弹出的列表中的crudService中的变量无法传入crud的发送适配器中
7770
- crud && crud.setData({__changedSearchBoxValues: __changedSearchBoxValues});
7804
+ // crud && crud.setData({__changedSearchBoxValues: __changedSearchBoxValues});
7805
+ if(crud){
7806
+ let crudData = crud.getData();
7807
+ crudData.__changedSearchBoxValues = __changedSearchBoxValues;
7808
+ crud.setData(crudData);
7809
+ }
7771
7810
  `;
7772
7811
 
7773
7812
  // onSearchScript中加上了onChangeScript中的脚本,是因为amis 3.2不能用change事件执行onChangeScript
@@ -7780,9 +7819,19 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
7780
7819
  // const scope = event.context.scoped;
7781
7820
  // 如果点击过顶部搜索栏表单的取消按钮,会把此处event.data.__super.__super.__super中的搜索表单项的所有字段设置为null
7782
7821
  // 点击取消按钮后继续在表单项中输入过滤条件且最后没有点击回车按键或点击表单项搜索按钮的话,在快速搜索中点击回车按钮提交搜索会所顶部搜索表单中的字段值清空
7822
+ let isLookup = event.data.isLookup;
7823
+ let __lookupField = event.data.__lookupField;
7824
+ let __changedFilterFormValuesKey = "__changedFilterFormValues";
7825
+ if(isLookup && __lookupField){
7826
+ let lookupTag = "__" + __lookupField.name + "__" + __lookupField.reference_to;
7827
+ if(__lookupField.reference_to_field){
7828
+ lookupTag += "__" + __lookupField.reference_to_field;
7829
+ }
7830
+ __changedFilterFormValuesKey += lookupTag;
7831
+ }
7783
7832
  let filterForm = SteedosUI.getClosestAmisComponentByType(scope, "form");
7784
7833
  setTimeout(function(){
7785
- filterForm.setValues(event.data.__changedFilterFormValues);
7834
+ filterForm.setValues(event.data[__changedFilterFormValuesKey]);
7786
7835
  }, 500);
7787
7836
  `;
7788
7837
 
@@ -7803,8 +7852,8 @@ function getObjectHeaderQuickSearchBox(mainObject, fields, formFactor, { isLooku
7803
7852
  "name": keywordsSearchBoxName,
7804
7853
  "placeholder": "搜索此列表",
7805
7854
  "value": crudKeywords,
7806
- "clearable": true,
7807
- // "clearAndSubmit": true,//因为清除并不会触发失去焦点事件,只有禁用,但是它会触发change事件,所以等升级到amis 3.4+后可以重新放开
7855
+ // "clearable": true,//因为清除并不会触发失去焦点事件,只有禁用,但是它会触发change事件,所以等升级到amis 3.4+后可以重新放开
7856
+ "clearAndSubmit": true,
7808
7857
  "searchImediately": false,
7809
7858
  "onEvent": {
7810
7859
  "search": {
@@ -8084,6 +8133,9 @@ async function getObjectFilter(objectSchema, fields, options) {
8084
8133
  crudService && crudService.setData({isFieldsFilterEmpty});
8085
8134
  `;
8086
8135
  let onChangeScript = `
8136
+ let isLookup = event.data.isLookup;
8137
+ let __lookupField = event.data.__lookupField;
8138
+ console.log("==onChangeScript=isLookup===", isLookup);
8087
8139
  const scope = event.context.scoped;
8088
8140
  // let filterFormValues = event.data;
8089
8141
  let filterForm = SteedosUI.getClosestAmisComponentByType(scope, "form");
@@ -8095,7 +8147,20 @@ async function getObjectFilter(objectSchema, fields, options) {
8095
8147
  // let crudService = crud && SteedosUI.getClosestAmisComponentByType(crud.context, "service");
8096
8148
  // crudService && crudService.setData({__changedFilterFormValues: changedFilterFormValues});
8097
8149
  // 这里不用crudService而用crud是因为lookup字段弹出的列表中的crudService中的变量无法传入crud的发送适配器中
8098
- crud && crud.setData({__changedFilterFormValues: changedFilterFormValues});
8150
+ // crud && crud.setData({__changedFilterFormValues: changedFilterFormValues});
8151
+ let __changedFilterFormValuesKey = "__changedFilterFormValues";
8152
+ if(isLookup && __lookupField){
8153
+ let lookupTag = "__" + __lookupField.name + "__" + __lookupField.reference_to;
8154
+ if(__lookupField.reference_to_field){
8155
+ lookupTag += "__" + __lookupField.reference_to_field;
8156
+ }
8157
+ __changedFilterFormValuesKey += lookupTag;
8158
+ }
8159
+ if(crud){
8160
+ let crudData = crud.getData();
8161
+ crudData[__changedFilterFormValuesKey] = changedFilterFormValues;
8162
+ crud.setData(crudData);
8163
+ }
8099
8164
  `;
8100
8165
  return {
8101
8166
  "title": "",
@@ -10493,13 +10558,24 @@ async function lookupToAmisPicker(field, readonly, ctx){
10493
10558
  let keywordsSearchBoxName = `__keywords_lookup__${field.name.replace(/\./g, "_")}__to__${refObjectConfig.name}`;
10494
10559
 
10495
10560
  source.requestAdaptor = `
10496
- let __changedFilterFormValues = api.data.$self.__changedFilterFormValues || {};
10561
+ let __changedFilterFormValuesKey = "__changedFilterFormValues";
10562
+ let __lookupField = api.data.$self.__lookupField;
10563
+ if(__lookupField){
10564
+ let lookupTag = "__" + __lookupField.name + "__" + __lookupField.reference_to;
10565
+ if(__lookupField.reference_to_field){
10566
+ lookupTag += "__" + __lookupField.reference_to_field;
10567
+ }
10568
+ __changedFilterFormValuesKey += lookupTag;
10569
+ }
10570
+ let __changedFilterFormValues = api.data.$self[__changedFilterFormValuesKey] || {};
10497
10571
  let __changedSearchBoxValues = api.data.$self.__changedSearchBoxValues || {};
10498
10572
  // 把表单搜索和快速搜索中的change事件中记录的过滤条件也拼到$self中,是为解决触发搜索请求时,两边输入的过滤条件都带上,即:
10499
10573
  // 有时在搜索表单中输入过滤条件事,忘记点击回车键或搜索按钮,而是进一步修改快速搜索框中的关键字点击其中回车键触发搜索
10500
10574
  // 这种情况下,触发的搜索请求中没有带上搜索表单中输入的过滤条件。
10501
10575
  // 反过来先在快速搜索框中输入过滤条件却不点击其中回车键触发搜索,而是到搜索表单中触发搜索请求也是一样的。
10502
- Object.assign(api.data.$self, __changedSearchBoxValues, __changedFilterFormValues);
10576
+ if(api.data.$self.op !== 'loadOptions'){
10577
+ Object.assign(api.data.$self, __changedSearchBoxValues, __changedFilterFormValues);
10578
+ }
10503
10579
  const selfData = JSON.parse(JSON.stringify(api.data.$self));
10504
10580
  var filters = [];
10505
10581
  var pageSize = api.data.pageSize || 10;
@@ -10706,7 +10782,12 @@ async function lookupToAmisPicker(field, readonly, ctx){
10706
10782
  "objectName": refObjectConfig.name,
10707
10783
  "uiSchema": refObjectConfig,
10708
10784
  "listName": listName,// 需要按视图取可搜索项
10709
- "isLookup": true
10785
+ "isLookup": true,
10786
+ "__lookupField": {
10787
+ "name": field.name,
10788
+ "reference_to": refObjectConfig.name,
10789
+ "reference_to_field": field.reference_to_field
10790
+ }
10710
10791
  });
10711
10792
 
10712
10793
  if(!pickerSchema.onEvent){
@@ -10879,7 +10960,7 @@ async function lookupToAmisSelect(field, readonly, ctx){
10879
10960
  sendOn.push(`this.${fName}`);
10880
10961
  });
10881
10962
  if(depend_on.length > 0){
10882
- apiInfo.url = `${apiInfo.url}?${depend_on.join('&')}`;
10963
+ apiInfo.url = `${apiInfo.url}&${depend_on.join('&')}`;
10883
10964
  apiInfo.sendOn = `${sendOn.join(' && ')}`;
10884
10965
  }
10885
10966
  }
@@ -10987,6 +11068,13 @@ async function lookupToAmisSelect(field, readonly, ctx){
10987
11068
  autoComplete: apiInfo,
10988
11069
  searchable: true,
10989
11070
  };
11071
+ let amisVersion = getComparableAmisVersion();
11072
+ if(amisVersion >= 3.6){
11073
+ // amis 3.6中不加source会造成子表组件中弹出行编辑窗口的lookup字段有时不请求接口(概率现象,同一个地方反复操作有时请求有时不请求)
11074
+ // 但是同时配置autoComplete和source会多请求一次接口
11075
+ // TODO:应该想办法把是否字段在子表组件内,即ctx.isInputTable,如果不在子表组件内不需要加source
11076
+ data.source = apiInfo;
11077
+ }
10990
11078
  //删除xlink:href中的rootUrl前缀,解决客户端svg为空的问题
10991
11079
  const select_menuTpl = `<span class='flex items-center mt-0.5'>
10992
11080
  <span role='img' aria-label='smile' class='anticon anticon-smile'>
@@ -11068,6 +11156,14 @@ async function lookupToAmis(field, readonly, ctx){
11068
11156
 
11069
11157
  // 优先取字段中配置的enable_enhanced_lookup,字段上没配置时,才从对象上取enable_enhanced_lookup属性
11070
11158
  let enableEnhancedLookup = ___namespace.isBoolean(field.enable_enhanced_lookup) ? field.enable_enhanced_lookup : refObject.enable_enhanced_lookup;
11159
+ let amisVersion = getComparableAmisVersion();
11160
+ if(amisVersion >= 3.6){
11161
+ // amis 3.6.3单选的树picker有严重bug(https://github.com/baidu/amis/issues/9279),先强制使用下拉方式显示
11162
+ // amis 3.6.3多选的树会自动把下层节点,及下下层等所有子节点自动选中,跟amis 3.2不一样,而且目前没有开关,这不适合目前的业务场景,也先强制使用下拉方式显示
11163
+ if(enableEnhancedLookup && refObject.enable_tree){
11164
+ enableEnhancedLookup = false;
11165
+ }
11166
+ }
11071
11167
  // 默认使用下拉框模式显示lookup选项,只能配置了enable_enhanced_lookup才使用弹出增强模式
11072
11168
  if(enableEnhancedLookup == true){
11073
11169
  return await lookupToAmisPicker(field, readonly, ctx);
@@ -11346,9 +11442,9 @@ const OMIT_FIELDS = ['created', 'created_by', 'modified', 'modified_by'];
11346
11442
  // const Lookup = require('./lookup');
11347
11443
 
11348
11444
  function getBaseFields(readonly){
11349
- let calssName = 'm-1';
11445
+ let className = 'm-0';
11350
11446
  if(readonly){
11351
- calssName = `${calssName}`;
11447
+ className = `${className}`;
11352
11448
  }
11353
11449
  return [
11354
11450
  {
@@ -11356,7 +11452,7 @@ function getBaseFields(readonly){
11356
11452
  label: "创建人",
11357
11453
  type: "static",
11358
11454
  labelClassName: 'text-left',
11359
- className: calssName,
11455
+ className: className,
11360
11456
  tpl: getCreatedInfoTpl()
11361
11457
  },
11362
11458
  {
@@ -11364,7 +11460,7 @@ function getBaseFields(readonly){
11364
11460
  label: "修改人",
11365
11461
  type: "static",
11366
11462
  labelClassName: 'text-left',
11367
- className: calssName,
11463
+ className: className,
11368
11464
  tpl: getModifiedInfoTpl()
11369
11465
  }
11370
11466
  ]
@@ -12060,9 +12156,9 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
12060
12156
  }
12061
12157
  if(!___namespace.isEmpty(convertData)){
12062
12158
  if(field.is_wide || convertData.type === 'group'){
12063
- convertData.className = 'col-span-2 m-1';
12159
+ convertData.className = 'col-span-2 m-0';
12064
12160
  }else {
12065
- convertData.className = 'm-1';
12161
+ convertData.className = 'm-0';
12066
12162
  }
12067
12163
  if(readonly){
12068
12164
  convertData.className = `${convertData.className} border-b`;
@@ -12468,7 +12564,7 @@ async function getFormBody(permissionFields, formFields, ctx){
12468
12564
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12469
12565
  * @Date: 2023-11-15 09:50:22
12470
12566
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12471
- * @LastEditTime: 2023-12-27 13:50:26
12567
+ * @LastEditTime: 2023-12-28 15:54:36
12472
12568
  */
12473
12569
 
12474
12570
  /**
@@ -12949,6 +13045,11 @@ async function getButtonActions(props, mode) {
12949
13045
  let dialogId = getComponentId("dialog", props.id);
12950
13046
  let buttonNextId = getComponentId("button_next", props.id);
12951
13047
  let formPaginationId = getComponentId("form_pagination", props.id);
13048
+ let parentFormData = "${__super.__super.__super.__super || {}}";
13049
+ let amisVersion = getComparableAmisVersion();
13050
+ if(amisVersion < 3.6){
13051
+ parentFormData = "${__super.__super || {}}";
13052
+ }
12952
13053
  if (mode == "new" || mode == "edit") {
12953
13054
  // let actionShowNewDialog = {
12954
13055
  // "actionType": "dialog",
@@ -13090,7 +13191,8 @@ async function getButtonActions(props, mode) {
13090
13191
  // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
13091
13192
  // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13092
13193
  // "__parentForm": "${__super.__super || {}}",
13093
- "__parentForm": mode == "new" ? "$$" : "${__super.__super || {}}",
13194
+ // "__parentForm": mode == "new" ? "$$" : "${__super.__super || {}}",
13195
+ "__parentForm": mode == "new" ? "$$" : parentFormData,
13094
13196
  "global": "${global}",
13095
13197
  "uiSchema": "${uiSchema}",
13096
13198
  "index": "${index}",
@@ -13183,7 +13285,7 @@ async function getButtonActions(props, mode) {
13183
13285
  // 换成从__super来映射上级表单数据是因为对象列表视图界面中每行下拉菜单中的编辑按钮弹出的表单中的子表所在作用域中没有record变量
13184
13286
  // 映射到中间变量__parentForm而不是直接用&展开映射是为了避免表单中字段名与作用域中变量重名
13185
13287
  // "__parentForm": "${__super.__super || {}}",
13186
- "__parentForm": "${__super.__super || {}}",
13288
+ "__parentForm": parentFormData,
13187
13289
  "global": "${global}",
13188
13290
  "uiSchema": "${uiSchema}",
13189
13291
  "index": "${index}",
@@ -14800,8 +14902,8 @@ const getInstanceApprovalHistory = async ()=>{
14800
14902
  /*
14801
14903
  * @Author: baozhoutao@steedos.com
14802
14904
  * @Date: 2022-09-07 16:20:45
14803
- * @LastEditors: baozhoutao@steedos.com
14804
- * @LastEditTime: 2023-03-23 16:49:44
14905
+ * @LastEditors: liaodaxue
14906
+ * @LastEditTime: 2023-12-29 16:06:35
14805
14907
  * @Description:
14806
14908
  */
14807
14909
 
@@ -15627,7 +15729,6 @@ const getFlowFormSchema = async (instance, box) => {
15627
15729
  "messages": {
15628
15730
  },
15629
15731
  "requestAdaptor": `
15630
- const { context } = api.data;
15631
15732
  api.data = {
15632
15733
  query: \`
15633
15734
  {
@@ -15650,7 +15751,7 @@ const getFlowFormSchema = async (instance, box) => {
15650
15751
  `,
15651
15752
  "data": {
15652
15753
  // "&": "$$",
15653
- "context": "${context}",
15754
+ // "context": "${context}",
15654
15755
  "judge": "${new_judge}",
15655
15756
  }
15656
15757
  },