@steedos-widgets/amis-lib 6.3.0-beta.7 → 6.3.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
@@ -570,10 +570,23 @@ function getNameTpl(field, ctx){
570
570
  if(ctx && ctx.isLookup){
571
571
  linkTarget = "target='_blank'";
572
572
  }
573
+ let nameLabel = field.name;
574
+ //若字段类型是lookup,则按照相关表tpl的label规则显示;若是其它类型,则显示_display或字段本身的值
575
+ if (field.type == "lookup") {
576
+ if(!field.reference_to && (field.optionsFunction || field._optionsFunction || field.options)){
577
+ if(!field.isTableField){
578
+ nameLabel = `\${${field.name}__label}`;
579
+ }
580
+ } else {
581
+ nameLabel = `\${_display.${field.name}.label}`;
582
+ }
583
+ } else {
584
+ nameLabel = `\${_display.${field.name} || ${field.name}}`;
585
+ }
573
586
  if(ctx.isRelated && window.innerWidth >= 768){
574
- return `<a href="${href}" ${linkTarget} onclick="return false;">\${${field.name} | raw}</a>`
587
+ return `<a href="${href}" ${linkTarget} onclick="return false;">\${${nameLabel} | raw}</a>`
575
588
  }else {
576
- return `<a href="${href}" ${linkTarget}>\${${field.name} | raw}</a>`
589
+ return `<a href="${href}" ${linkTarget}>\${${nameLabel} | raw}</a>`
577
590
  }
578
591
  }
579
592
 
@@ -698,7 +711,7 @@ function getLocationTpl(field){
698
711
  }
699
712
 
700
713
  async function getFieldTpl (field, options){
701
- if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel){
714
+ if((field.is_name || field.name === options.labelFieldName) && !options.onlyDisplayLookLabel && field.multiple !== true){
702
715
  return getNameTpl(field, options)
703
716
  }
704
717
  switch (field.type) {
@@ -2171,7 +2184,7 @@ async function getTableColumns(object, fields, options){
2171
2184
  var file_id = data.versions && data.versions[0] && data.versions[0]._id;
2172
2185
  window.previewFile && window.previewFile({file_name, file_id});
2173
2186
  `;
2174
- columnItem = {
2187
+ columnItem = Object.assign({}, {
2175
2188
  "type": "button",
2176
2189
  "label": `<%=data.versions ? data.name : "${field.label}"%>`,
2177
2190
  className,
@@ -2203,7 +2216,7 @@ async function getTableColumns(object, fields, options){
2203
2216
  ]
2204
2217
  }
2205
2218
  }
2206
- };
2219
+ }, fieldAmis);
2207
2220
  }else if(field.type === 'toggle'){
2208
2221
  columnItem = Object.assign({}, {
2209
2222
  type: "switch",
@@ -2319,7 +2332,7 @@ async function getTableColumns(object, fields, options){
2319
2332
  "title": "&nbsp;",
2320
2333
  "headerClassName": "hidden",
2321
2334
  "size": "lg",
2322
- "bodyClassName": "p-0 m-0",
2335
+ "bodyClassName": "p-0 m-0 bg-gray-100",
2323
2336
  "closeOnEsc": true,
2324
2337
  "closeOnOutside": true,
2325
2338
  "resizable": true,
@@ -3255,6 +3268,19 @@ function getReadonlyFormAdaptor(object, fields, options){
3255
3268
  // })
3256
3269
 
3257
3270
  var fieldNames = _$1.map(fields, function(n){return n.name});
3271
+ var nameField = object.fields[object.NAME_FIELD_KEY];
3272
+ let nameLabel = nameField.name;
3273
+ if (nameField.type == "lookup") {
3274
+ if(!nameField.reference_to && (nameField.optionsFunction || nameField._optionsFunction || nameField.options)){
3275
+ if(!nameField.isTableField){
3276
+ nameLabel = `record.${nameField.name}__label`;
3277
+ }
3278
+ } else {
3279
+ nameLabel = `record._display.${nameField.name}.label`;
3280
+ }
3281
+ } else {
3282
+ nameLabel = `record._display.${nameField.name} || record.${nameField.name}`;
3283
+ }
3258
3284
  return `
3259
3285
  if(payload.data.data.length === 0){
3260
3286
  var isEditor = !!${options && options.isEditor};
@@ -3296,8 +3322,7 @@ function getReadonlyFormAdaptor(object, fields, options){
3296
3322
  payload.data = data;
3297
3323
  payload.data.__objectName = "${object.name}";
3298
3324
  payload.data.record = record;
3299
-
3300
- payload.data.NAME_FIELD_VALUE = record.${object.NAME_FIELD_KEY || 'name'};
3325
+ payload.data.NAME_FIELD_VALUE = ${nameLabel} || record.name;
3301
3326
  payload.data._master = {
3302
3327
  record: record,
3303
3328
  objectName: "${object.name}",
@@ -10096,15 +10121,15 @@ async function getListSchema(
10096
10121
  async function convertColumnsToTableFields(columns, uiSchema, ctx = {}) {
10097
10122
  let fields = [];
10098
10123
  for (const column of columns) {
10124
+ let columnField, fieldName, displayName, filedInfo, rfUiSchema, rfFieldInfo;
10099
10125
  if (isString(column)) {
10100
- let columnField;
10101
10126
  if (column.indexOf('.') > 0) {
10102
- const fieldName = column.split('.')[0];
10103
- const displayName = column.split('.')[1];
10104
- const filedInfo = uiSchema.fields[fieldName];
10127
+ fieldName = column.split('.')[0];
10128
+ displayName = column.split('.')[1];
10129
+ filedInfo = uiSchema.fields[fieldName];
10105
10130
  if (filedInfo && (filedInfo.type === 'lookup' || filedInfo.type === 'master_detail') && isString(filedInfo.reference_to)) {
10106
- const rfUiSchema = await getUISchema(filedInfo.reference_to);
10107
- const rfFieldInfo = rfUiSchema.fields[displayName];
10131
+ rfUiSchema = await getUISchema(filedInfo.reference_to);
10132
+ rfFieldInfo = rfUiSchema.fields[displayName];
10108
10133
  columnField = Object.assign({}, rfFieldInfo, { name: `${fieldName}__expand.${displayName}`, expand: true, expandInfo: { fieldName, displayName } }, ctx);
10109
10134
  }else if(filedInfo && filedInfo.type === 'object'){
10110
10135
  columnField = uiSchema.fields[column];
@@ -10128,14 +10153,13 @@ async function convertColumnsToTableFields(columns, uiSchema, ctx = {}) {
10128
10153
  }
10129
10154
 
10130
10155
  } else if (isObject$1(column)) {
10131
- let columnField;
10132
10156
  if (column.field.indexOf('.') > 0) {
10133
- const fieldName = column.field.split('.')[0];
10134
- const displayName = column.field.split('.')[1];
10135
- const filedInfo = uiSchema.fields[fieldName];
10157
+ fieldName = column.field.split('.')[0];
10158
+ displayName = column.field.split('.')[1];
10159
+ filedInfo = uiSchema.fields[fieldName];
10136
10160
  if (filedInfo && (filedInfo.type === 'lookup' || filedInfo.type === 'master_detail') && isString(filedInfo.reference_to)) {
10137
- const rfUiSchema = await getUISchema(filedInfo.reference_to);
10138
- const rfFieldInfo = rfUiSchema.fields[displayName];
10161
+ rfUiSchema = await getUISchema(filedInfo.reference_to);
10162
+ rfFieldInfo = rfUiSchema.fields[displayName];
10139
10163
  columnField = Object.assign({}, rfFieldInfo, ctx,
10140
10164
  { name: `${fieldName}__expand.${displayName}`, expand: true, expandInfo: { fieldName, displayName } },
10141
10165
  {
@@ -10277,7 +10301,7 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
10277
10301
  };
10278
10302
  const content = {
10279
10303
  "type": "tabs",
10280
- "className": "steedos-record-tabs bg-white p-4 mt-2",
10304
+ "className": "steedos-record-tabs bg-white p-4 m-2 border rounded",
10281
10305
  "contentClassName": "bg-none",
10282
10306
  "tabs": [
10283
10307
  detailed
@@ -11395,7 +11419,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
11395
11419
  // 如果当前元素不是数组,则处理该元素
11396
11420
  // 下面正则用于匹配amis公式\${}
11397
11421
  if(/\\\$\\\{([^}]*)\\\}/.test(arr[i])) {
11398
- arr[i] = currentAmis.evaluate(arr[i], api.data.$);
11422
+ arr[i] = currentAmis.evaluate(arr[i], api.data.$self);
11399
11423
  }
11400
11424
  }
11401
11425
  }
@@ -11812,7 +11836,7 @@ async function lookupToAmisSelect(field, readonly, ctx){
11812
11836
  // 如果当前元素不是数组,则处理该元素
11813
11837
  // 下面正则用于匹配amis公式\${}
11814
11838
  if(/\\\$\\\{([^}]*)\\\}/.test(arr[i])) {
11815
- arr[i] = currentAmis.evaluate(arr[i], api.data.$);
11839
+ arr[i] = currentAmis.evaluate(arr[i], api.data.$self);
11816
11840
  }
11817
11841
  }
11818
11842
  }