@steedos-widgets/amis-lib 3.6.14 → 6.3.0-beta.10

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
@@ -597,10 +597,23 @@ function getNameTpl(field, ctx){
597
597
  if(ctx && ctx.isLookup){
598
598
  linkTarget = "target='_blank'";
599
599
  }
600
+ let nameLabel = field.name;
601
+ //若字段类型是lookup,则按照相关表tpl的label规则显示;若是其它类型,则显示_display或字段本身的值
602
+ if (field.type == "lookup") {
603
+ if(!field.reference_to && (field.optionsFunction || field._optionsFunction || field.options)){
604
+ if(!field.isTableField){
605
+ nameLabel = `\${${field.name}__label}`;
606
+ }
607
+ } else {
608
+ nameLabel = `\${_display.${field.name}.label}`;
609
+ }
610
+ } else {
611
+ nameLabel = `\${_display.${field.name} || ${field.name}}`;
612
+ }
600
613
  if(ctx.isRelated && window.innerWidth >= 768){
601
- return `<a href="${href}" ${linkTarget} onclick="return false;">\${${field.name} | raw}</a>`
614
+ return `<a href="${href}" ${linkTarget} onclick="return false;">\${${nameLabel} | raw}</a>`
602
615
  }else {
603
- return `<a href="${href}" ${linkTarget}>\${${field.name} | raw}</a>`
616
+ return `<a href="${href}" ${linkTarget}>\${${nameLabel} | raw}</a>`
604
617
  }
605
618
  }
606
619
 
@@ -725,7 +738,7 @@ function getLocationTpl(field){
725
738
  }
726
739
 
727
740
  async function getFieldTpl (field, options){
728
- if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel){
741
+ if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel && field.multiple !== true){
729
742
  return getNameTpl(field, options)
730
743
  }
731
744
  switch (field.type) {
@@ -2346,7 +2359,7 @@ async function getTableColumns(object, fields, options){
2346
2359
  "title": "&nbsp;",
2347
2360
  "headerClassName": "hidden",
2348
2361
  "size": "lg",
2349
- "bodyClassName": "p-0 m-0",
2362
+ "bodyClassName": "p-0 m-0 bg-gray-100",
2350
2363
  "closeOnEsc": true,
2351
2364
  "closeOnOutside": true,
2352
2365
  "resizable": true,
@@ -3282,6 +3295,19 @@ function getReadonlyFormAdaptor(object, fields, options){
3282
3295
  // })
3283
3296
 
3284
3297
  var fieldNames = ___namespace.map(fields, function(n){return n.name});
3298
+ var nameField = object.fields[object.NAME_FIELD_KEY];
3299
+ let nameLabel = nameField && nameField.name;
3300
+ if (nameField && nameField.type == "lookup") {
3301
+ if(!nameField.reference_to && (nameField.optionsFunction || nameField._optionsFunction || nameField.options)){
3302
+ if(!nameField.isTableField){
3303
+ nameLabel = `record.${nameField.name}__label`;
3304
+ }
3305
+ } else {
3306
+ nameLabel = `record._display.${nameField.name}.label`;
3307
+ }
3308
+ } else if (nameField){
3309
+ nameLabel = `record._display.${nameField.name} || record.${nameField.name}`;
3310
+ }
3285
3311
  return `
3286
3312
  if(payload.data.data.length === 0){
3287
3313
  var isEditor = !!${options && options.isEditor};
@@ -3323,8 +3349,7 @@ function getReadonlyFormAdaptor(object, fields, options){
3323
3349
  payload.data = data;
3324
3350
  payload.data.__objectName = "${object.name}";
3325
3351
  payload.data.record = record;
3326
-
3327
- payload.data.NAME_FIELD_VALUE = record.${object.NAME_FIELD_KEY || 'name'};
3352
+ payload.data.NAME_FIELD_VALUE = ${nameLabel} || record.name;
3328
3353
  payload.data._master = {
3329
3354
  record: record,
3330
3355
  objectName: "${object.name}",
@@ -4791,7 +4816,8 @@ const getSchema$5 = async (uiSchema, ctx) => {
4791
4816
  type: 'button',
4792
4817
  actionType: 'confirm',
4793
4818
  label: i18next__default["default"].t('frontend_form_save'),
4794
- primary: true
4819
+ primary: true,
4820
+ close: `object_actions_drawer_${uiSchema.name}`
4795
4821
  },
4796
4822
  ]
4797
4823
  }
@@ -4910,6 +4936,20 @@ const getSchema$4 = async (uiSchema, ctx) => {
4910
4936
  ]
4911
4937
  }
4912
4938
  },
4939
+ "actions": [
4940
+ {
4941
+ type: 'button',
4942
+ actionType: 'cancel',
4943
+ label: i18next__default["default"].t('frontend_form_cancel')
4944
+ },
4945
+ {
4946
+ type: 'button',
4947
+ actionType: 'confirm',
4948
+ label: i18next__default["default"].t('frontend_form_save'),
4949
+ primary: true,
4950
+ close: `object_actions_drawer_${uiSchema.name}`
4951
+ },
4952
+ ]
4913
4953
  },
4914
4954
  },
4915
4955
  ],
@@ -4991,7 +5031,8 @@ const getSchema$3 = (uiSchema)=>{
4991
5031
  }
4992
5032
  ]
4993
5033
  }
4994
- }
5034
+ },
5035
+ "close": `object_actions_drawer_${uiSchema.name}`
4995
5036
  }
4996
5037
  ],
4997
5038
  "regions": [
@@ -8926,10 +8967,6 @@ async function getObjectCRUD(objectSchema, fields, options){
8926
8967
  }
8927
8968
  }
8928
8969
  `;
8929
- let autoFillHeight = true;
8930
- if(options.isRelated || window.innerWidth < 768){
8931
- autoFillHeight = false;
8932
- }
8933
8970
 
8934
8971
  body = Object.assign({}, table, {
8935
8972
  type: 'crud',
@@ -8940,7 +8977,7 @@ async function getObjectCRUD(objectSchema, fields, options){
8940
8977
  keepItemSelectionOnPageChange: true,
8941
8978
  api: await getTableApi(objectSchema, fields, options),
8942
8979
  hiddenOn: options.tableHiddenOn,
8943
- autoFillHeight,
8980
+ // autoFillHeight,//autoFillHeight按amis规范默认为false,需要配置此属性时在各个组件层配置,比如列表视图组件那边传入此属性为true
8944
8981
  className: `flex-auto ${crudClassName || ""}`,
8945
8982
  // 这里不可以用动态className,因为它会把样式类加到.antd-Crud和.antd-Table.antd-Crud-body这两层div中,而子表列表中crudClassName中有hidden样式类会造成所有子表都不显示的bug
8946
8983
  // className: {
@@ -9113,6 +9150,10 @@ async function getFormSchemaWithDataFilter(form, options = {}){
9113
9150
  async function getObjectForm(objectSchema, ctx){
9114
9151
  const { recordId, formFactor, layout = formFactor === 'SMALL' ? 'normal' : "horizontal", labelAlign, tabId, appId, defaults, submitSuccActions = [],
9115
9152
  formDataFilter, onFormDataFilter, amisData, env } = ctx;
9153
+ //优先识别组件上的enableTabs属性,若不存在,则识别对象上定义的
9154
+ if (typeof ctx.enableTabs !== 'boolean') {
9155
+ ctx.enableTabs = objectSchema.enable_form_tabs;
9156
+ }
9116
9157
  const fields = ___default["default"].values(objectSchema.fields);
9117
9158
  const formFields = getFormFields$1(objectSchema, ctx);
9118
9159
  const formSchema = defaults && defaults.formSchema || {};
@@ -9206,7 +9247,7 @@ async function getObjectForm(objectSchema, ctx){
9206
9247
 
9207
9248
  async function getObjectDetail(objectSchema, recordId, ctx){
9208
9249
  const { formFactor, layout = formFactor === 'SMALL' ? 'normal' : "horizontal", labelAlign,
9209
- formDataFilter, onFormDataFilter, amisData, env } = ctx;
9250
+ formDataFilter, onFormDataFilter, amisData, env, enableInitApi } = ctx;
9210
9251
  const fields = ___default["default"].values(objectSchema.fields);
9211
9252
  const formFields = getFormFields$1(objectSchema, ctx);
9212
9253
  const serviceId = `service_detail_page`;
@@ -9273,6 +9314,16 @@ async function getObjectDetail(objectSchema, recordId, ctx){
9273
9314
  // }
9274
9315
  };
9275
9316
 
9317
+ if(enableInitApi){
9318
+ amisSchema.api = await getReadonlyFormInitApi(objectSchema, recordId, fields, ctx);
9319
+ // 开启初始化api请求时,如果不把recordLoaded默认设置为false,recordLoaded值会取RecordServic组件中的recordLoaded值
9320
+ // 这会造成表单内steedos field组件lookup字段中props.data取到的是RecordServic组件
9321
+ amisSchema.data = {
9322
+ ...amisSchema.data,
9323
+ recordLoaded: false
9324
+ };
9325
+ }
9326
+
9276
9327
  amisSchema.body[0].body = await getFormSchemaWithDataFilter(amisSchema.body[0].body, { formDataFilter, onFormDataFilter, amisData, env });
9277
9328
  // console.log('getObjectDetail=====>', amisSchema);
9278
9329
  return amisSchema;
@@ -9764,7 +9815,7 @@ async function getObjectRelatedListsMiniSchema(objectApiName){
9764
9815
  * @Author: baozhoutao@steedos.com
9765
9816
  * @Date: 2022-07-05 15:55:39
9766
9817
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
9767
- * @LastEditTime: 2024-02-23 16:37:06
9818
+ * @LastEditTime: 2024-04-26 16:46:44
9768
9819
  * @Description:
9769
9820
  */
9770
9821
 
@@ -10029,37 +10080,44 @@ async function getListSchema(
10029
10080
  * 本次存储代码段
10030
10081
  */
10031
10082
  try {
10032
- const listViewPropsStoreKey = location.pathname + "/crud";
10033
- let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
10034
- /**
10035
- * localListViewProps规范来自crud请求api中api.data.$self参数值的。
10036
- * 比如:{"perPage":20,"page":1,"__searchable__name":"7","__searchable__between__n1__c":[null,null],"filter":[["name","contains","a"]]}
10037
- * __searchable__...:顶部放大镜搜索条件
10038
- * filter:右侧过滤器
10039
- * perPage:每页条数
10040
- * page:当前页码
10041
- * orderBy:排序字段
10042
- * orderDir:排序方向
10043
- */
10044
- if (localListViewProps) {
10045
- localListViewProps = JSON.parse(localListViewProps);
10046
- // localListViewProps.perPage = 3;
10047
- let listSchema = {};
10048
- if(localListViewProps.orderBy){
10049
- listSchema.orderBy = localListViewProps.orderBy;
10050
- }
10051
- if(localListViewProps.orderDir){
10052
- listSchema.orderDir = localListViewProps.orderDir;
10053
- }
10083
+ const listViewPropsStoreKey = location.pathname + "/crud";
10084
+ let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
10085
+ /**
10086
+ * localListViewProps规范来自crud请求api中api.data.$self参数值的。
10087
+ * 比如:{"perPage":20,"page":1,"__searchable__name":"7","__searchable__between__n1__c":[null,null],"filter":[["name","contains","a"]]}
10088
+ * __searchable__...:顶部放大镜搜索条件
10089
+ * filter:右侧过滤器
10090
+ * perPage:每页条数
10091
+ * page:当前页码
10092
+ * orderBy:排序字段
10093
+ * orderDir:排序方向
10094
+ */
10095
+ if (localListViewProps) {
10096
+ localListViewProps = JSON.parse(localListViewProps);
10097
+ // localListViewProps.perPage = 3;
10098
+ let listSchema = {};
10099
+ if (localListViewProps.orderBy) {
10100
+ listSchema.orderBy = localListViewProps.orderBy;
10101
+ }
10102
+ if (localListViewProps.orderDir) {
10103
+ listSchema.orderDir = localListViewProps.orderDir;
10104
+ }
10054
10105
 
10055
- if(localListViewProps.perPage){
10056
- listSchema.perPage = localListViewProps.perPage;
10106
+ if (localListViewProps.perPage) {
10107
+ listSchema.perPage = localListViewProps.perPage;
10108
+ }
10109
+ defaults.listSchema = _$1.defaultsDeep({}, listSchema, defaults.listSchema || {});
10057
10110
  }
10058
- defaults.listSchema = _$1.defaultsDeep({}, listSchema, defaults.listSchema || {});
10059
- }
10060
10111
  }
10061
10112
  catch (ex) {
10062
- console.error("本地存储中crud参数解析异常:", ex);
10113
+ console.error("本地存储中crud参数解析异常:", ex);
10114
+ }
10115
+
10116
+ if (window.innerWidth > 768) {
10117
+ // 列表视图组件PC端高度自动计算实现满屏效果,手机端不需要满屏效果,所以不用autofillheight,且允许重写微页面中重新组件autoFillHeight属性
10118
+ defaults.listSchema = _$1.defaultsDeep({}, defaults.listSchema || {}, {
10119
+ autoFillHeight: true
10120
+ });
10063
10121
  }
10064
10122
 
10065
10123
  ctx.defaults = defaults;
@@ -10109,15 +10167,15 @@ async function getListSchema(
10109
10167
  async function convertColumnsToTableFields(columns, uiSchema, ctx = {}) {
10110
10168
  let fields = [];
10111
10169
  for (const column of columns) {
10170
+ let columnField, fieldName, displayName, filedInfo, rfUiSchema, rfFieldInfo;
10112
10171
  if (_$1.isString(column)) {
10113
- let columnField;
10114
10172
  if (column.indexOf('.') > 0) {
10115
- const fieldName = column.split('.')[0];
10116
- const displayName = column.split('.')[1];
10117
- const filedInfo = uiSchema.fields[fieldName];
10173
+ fieldName = column.split('.')[0];
10174
+ displayName = column.split('.')[1];
10175
+ filedInfo = uiSchema.fields[fieldName];
10118
10176
  if (filedInfo && (filedInfo.type === 'lookup' || filedInfo.type === 'master_detail') && _$1.isString(filedInfo.reference_to)) {
10119
- const rfUiSchema = await getUISchema(filedInfo.reference_to);
10120
- const rfFieldInfo = rfUiSchema.fields[displayName];
10177
+ rfUiSchema = await getUISchema(filedInfo.reference_to);
10178
+ rfFieldInfo = rfUiSchema.fields[displayName];
10121
10179
  columnField = Object.assign({}, rfFieldInfo, { name: `${fieldName}__expand.${displayName}`, expand: true, expandInfo: { fieldName, displayName } }, ctx);
10122
10180
  }else if(filedInfo && filedInfo.type === 'object'){
10123
10181
  columnField = uiSchema.fields[column];
@@ -10141,14 +10199,13 @@ async function convertColumnsToTableFields(columns, uiSchema, ctx = {}) {
10141
10199
  }
10142
10200
 
10143
10201
  } else if (_$1.isObject(column)) {
10144
- let columnField;
10145
10202
  if (column.field.indexOf('.') > 0) {
10146
- const fieldName = column.field.split('.')[0];
10147
- const displayName = column.field.split('.')[1];
10148
- const filedInfo = uiSchema.fields[fieldName];
10203
+ fieldName = column.field.split('.')[0];
10204
+ displayName = column.field.split('.')[1];
10205
+ filedInfo = uiSchema.fields[fieldName];
10149
10206
  if (filedInfo && (filedInfo.type === 'lookup' || filedInfo.type === 'master_detail') && _$1.isString(filedInfo.reference_to)) {
10150
- const rfUiSchema = await getUISchema(filedInfo.reference_to);
10151
- const rfFieldInfo = rfUiSchema.fields[displayName];
10207
+ rfUiSchema = await getUISchema(filedInfo.reference_to);
10208
+ rfFieldInfo = rfUiSchema.fields[displayName];
10152
10209
  columnField = Object.assign({}, rfFieldInfo, ctx,
10153
10210
  { name: `${fieldName}__expand.${displayName}`, expand: true, expandInfo: { fieldName, displayName } },
10154
10211
  {
@@ -10156,6 +10213,8 @@ async function convertColumnsToTableFields(columns, uiSchema, ctx = {}) {
10156
10213
  wrap: column.wrap // wrap = true 是没效果的
10157
10214
  }
10158
10215
  );
10216
+ } else if (filedInfo && filedInfo.type === 'object') {
10217
+ columnField = uiSchema.fields[column.field];
10159
10218
  }
10160
10219
  } else {
10161
10220
  if (uiSchema.fields[column.field]) {
@@ -10290,7 +10349,7 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
10290
10349
  };
10291
10350
  const content = {
10292
10351
  "type": "tabs",
10293
- "className": "steedos-record-tabs bg-white p-4 mt-2",
10352
+ "className": "steedos-record-tabs bg-white p-4 m-2 border rounded",
10294
10353
  "contentClassName": "bg-none",
10295
10354
  "tabs": [
10296
10355
  detailed
@@ -10366,6 +10425,10 @@ async function getRecordServiceSchema(objectName, appId, props = {}, body) {
10366
10425
  data: {
10367
10426
  "_master.objectName": "${objectName}",
10368
10427
  "_master.recordId": "${recordId}",
10428
+ // 微页面设计器中用RecordServic组件包裹一个ObjectForm只读组件时,如果这里不把recordLoaded默认设置为false
10429
+ // recordLoaded值会取父作用域中已经被设置为true的值(比如父级有RecordServic组件,在加载完数据后,父作用域中recordLoaded值为true)
10430
+ // 这会造成表单内steedos field组件lookup字段中props.data取到的是父作用域中的数据
10431
+ "recordLoaded": false,
10369
10432
  ...(props.data || {})
10370
10433
  },
10371
10434
  "style": {
@@ -11254,7 +11317,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
11254
11317
  });
11255
11318
 
11256
11319
  // 把自动填充规则中依赖的字段也加到api请求中
11257
- let autoFillMapping = !field.multiple && field.auto_fill_mapping;
11320
+ let autoFillMapping = field.auto_fill_mapping;
11258
11321
  if (autoFillMapping && autoFillMapping.length) {
11259
11322
  autoFillMapping.forEach(function (item) {
11260
11323
  if(!___namespace.find(tableFields, function(f){
@@ -11404,7 +11467,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
11404
11467
  // 如果当前元素不是数组,则处理该元素
11405
11468
  // 下面正则用于匹配amis公式\${}
11406
11469
  if(/\\\$\\\{([^}]*)\\\}/.test(arr[i])) {
11407
- arr[i] = currentAmis.evaluate(arr[i], api.data.$);
11470
+ arr[i] = currentAmis.evaluate(arr[i], api.data.$self);
11408
11471
  }
11409
11472
  }
11410
11473
  }
@@ -11726,7 +11789,7 @@ async function lookupToAmisSelect(field, readonly, ctx){
11726
11789
  ];
11727
11790
 
11728
11791
  // 把自动填充规则中依赖的字段也加到api请求中
11729
- let autoFillMapping = !field.multiple && field.auto_fill_mapping;
11792
+ let autoFillMapping = field.auto_fill_mapping;
11730
11793
  if (autoFillMapping && autoFillMapping.length) {
11731
11794
  autoFillMapping.forEach(function (item) {
11732
11795
  queryFields.push(refObjectConfig.fields[item.from]);
@@ -11821,7 +11884,7 @@ async function lookupToAmisSelect(field, readonly, ctx){
11821
11884
  // 如果当前元素不是数组,则处理该元素
11822
11885
  // 下面正则用于匹配amis公式\${}
11823
11886
  if(/\\\$\\\{([^}]*)\\\}/.test(arr[i])) {
11824
- arr[i] = currentAmis.evaluate(arr[i], api.data.$);
11887
+ arr[i] = currentAmis.evaluate(arr[i], api.data.$self);
11825
11888
  }
11826
11889
  }
11827
11890
  }
@@ -11968,14 +12031,25 @@ async function getApi(object, recordId, fields, options){
11968
12031
  }
11969
12032
 
11970
12033
  async function getAutoFill(field, refObject) {
11971
- let autoFillMapping = !field.multiple && field.auto_fill_mapping;
12034
+ let autoFillMapping = field.auto_fill_mapping;
11972
12035
  if (autoFillMapping && autoFillMapping.length) {
11973
12036
  let fillMapping = {};
12037
+ if (field.multiple) {
12038
+ autoFillMapping.forEach(function (item) {
12039
+ //from的字段类型为lookup、master_detail、select时,需要保留数组格式;其他类型需要转变为字符串格式
12040
+ if (___namespace.includes(["lookup","master_detail","select"], refObject.fields[item.from].type)) {
12041
+ fillMapping[item.to] = `\${items | pick:${item.from}}`;
12042
+ } else {
12043
+ fillMapping[item.to] = `\${items | pick:${item.from} | join}`;
12044
+ }
12045
+ });
12046
+ }else {
12047
+ autoFillMapping.forEach(function (item) {
12048
+ fillMapping[item.to] = `\${${item.from}}`;
12049
+ });
12050
+ }
11974
12051
  // let fieldsForApi = [];
11975
- autoFillMapping.forEach(function (item) {
11976
- fillMapping[item.to] = `\${${item.from}}`;
11977
- // fieldsForApi.push(item.from);
11978
- });
12052
+ // fieldsForApi.push(item.from);
11979
12053
  // let api = {
11980
12054
  // // "url": "/amis/api/mock2/form/autoUpdate?browser=${browser}&version=${version}",
11981
12055
  // "url": `/api/v1/${refObject.name}/\${${field.name}}?fields=${JSON.stringify(fieldsForApi)}`,
@@ -12077,7 +12151,7 @@ async function lookupToAmis(field, readonly, ctx){
12077
12151
  amisSchema = ___namespace.defaultsDeep({}, pageAmisSchema, amisSchema);
12078
12152
  }
12079
12153
  }
12080
- const autoFill = await getAutoFill(field);
12154
+ const autoFill = await getAutoFill(field, refObject);
12081
12155
  if(autoFill){
12082
12156
  amisSchema.autoFill = autoFill;
12083
12157
  // 这里不配置initAutoFill值,按amis规则initAutoFill默认值为fillIfNotSet处理--需要amis sdk 版本 > 3.6.3-patch.6(不包括)版本