@steedos-widgets/amis-lib 1.3.0 → 1.3.2-beta.2

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,11 +382,26 @@ const Router = {
382
382
  /*
383
383
  * @Author: baozhoutao@steedos.com
384
384
  * @Date: 2022-07-20 16:29:22
385
- * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
386
- * @LastEditTime: 2023-09-06 18:59:40
385
+ * @LastEditors: liaodaxue
386
+ * @LastEditTime: 2023-09-11 17:19:53
387
387
  * @Description:
388
388
  */
389
389
 
390
+ function getImageFieldUrl(url) {
391
+ if (window.Meteor && window.Meteor.isCordova != true) {
392
+ // '//'的位置
393
+ const doubleSlashIndex = url.indexOf('//');
394
+ const urlIndex = url.indexOf('/', doubleSlashIndex + 2);
395
+ const rootUrl = url.substring(urlIndex);
396
+ return rootUrl;
397
+ }
398
+ return url;
399
+ }
400
+
401
+ if(typeof window != 'undefined'){
402
+ window.getImageFieldUrl = getImageFieldUrl;
403
+ }
404
+
390
405
  function getContrastColor(bgColor) {
391
406
  var backgroundColor = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor;
392
407
  var r = parseInt(backgroundColor.substr(0, 2), 16);
@@ -397,6 +412,9 @@ function getContrastColor(bgColor) {
397
412
  }
398
413
 
399
414
  function getLookupListView(refObjectConfig) {
415
+ if(!refObjectConfig){
416
+ return null;
417
+ }
400
418
  const listNameAll = "all";
401
419
  const listNameLookup = "lookup";
402
420
  let listViewAll, listViewLookup;
@@ -8545,7 +8563,13 @@ async function getTableApi(mainObject, fields, options){
8545
8563
  if(field.type === 'file'){
8546
8564
  item[key] = value
8547
8565
  }else{
8548
- item[key] = _.map(value, 'url')
8566
+ item[key] = _.map(value, (item)=>{
8567
+ if(field.type === 'image'){
8568
+ const url = window.getImageFieldUrl(item.url);
8569
+ return url;
8570
+ }
8571
+ return item.url;
8572
+ })
8549
8573
  }
8550
8574
  }
8551
8575
  })
@@ -8787,10 +8811,14 @@ function getScriptForAddUrlPrefixForImgFields(fields){
8787
8811
  let fieldProps = imgFields[item];
8788
8812
  if(fieldProps.multiple){
8789
8813
  if(imgFieldDisplayValue instanceof Array){
8790
- data[item] = imgFieldDisplayValue.map((i)=>{ return i.url });
8814
+ data[item] = imgFieldDisplayValue.map((i)=>{
8815
+ const url = window.getImageFieldUrl(i.url);
8816
+ return url;
8817
+ });
8791
8818
  }
8792
8819
  }else{
8793
- data[item] = imgFieldDisplayValue && imgFieldDisplayValue.url;
8820
+ const url = imgFieldDisplayValue && window.getImageFieldUrl(imgFieldDisplayValue.url);
8821
+ data[item] = url;
8794
8822
  }
8795
8823
  }
8796
8824
  })
@@ -10951,53 +10979,34 @@ async function getListSchema(
10951
10979
  };
10952
10980
  }
10953
10981
 
10954
- // 获取对象表格
10955
- async function getTableSchema(
10956
- appName,
10957
- objectName,
10958
- columns,
10959
- ctx = {}
10960
- ) {
10961
- // console.time('getTableSchema', columns);
10962
- const uiSchema = await getUISchema(objectName);
10963
-
10964
- let sort = ctx.sort;
10965
- if(!sort){
10966
- const sortField = ctx.sortField;
10967
- const sortOrder = ctx.sortOrder;
10968
- if(sortField){
10969
- let sortStr = sortField + ' ' + sortOrder || 'asc';
10970
- sort = sortStr;
10971
- }
10972
- }
10973
-
10982
+ async function convertColumnsToTableFields(columns, uiSchema, ctx = {}) {
10974
10983
  let fields = [];
10975
- for(const column of columns){
10984
+ for (const column of columns) {
10976
10985
  if (isString(column)) {
10977
- if(column.indexOf('.') > 0){
10986
+ if (column.indexOf('.') > 0) {
10978
10987
  const fieldName = column.split('.')[0];
10979
10988
  const displayName = column.split('.')[1];
10980
10989
  const filedInfo = uiSchema.fields[fieldName];
10981
- if(filedInfo && (filedInfo.type === 'lookup' || filedInfo.type === 'master_detail') && isString(filedInfo.reference_to) ){
10990
+ if (filedInfo && (filedInfo.type === 'lookup' || filedInfo.type === 'master_detail') && isString(filedInfo.reference_to)) {
10982
10991
  const rfUiSchema = await getUISchema(filedInfo.reference_to);
10983
10992
  const rfFieldInfo = rfUiSchema.fields[displayName];
10984
- fields.push(Object.assign({}, rfFieldInfo, {name: `${fieldName}__expand.${displayName}`, expand: true, expandInfo: {fieldName, displayName}}));
10993
+ fields.push(Object.assign({}, rfFieldInfo, { name: `${fieldName}__expand.${displayName}`, expand: true, expandInfo: { fieldName, displayName } }, ctx));
10985
10994
  }
10986
- }else {
10987
- if(uiSchema.fields[column]){
10988
- fields.push(uiSchema.fields[column]);
10995
+ } else {
10996
+ if (uiSchema.fields[column]) {
10997
+ fields.push(Object.assign({}, uiSchema.fields[column], ctx));
10989
10998
  }
10990
10999
  }
10991
11000
  } else if (isObject$1(column)) {
10992
- if(column.field.indexOf('.') > 0){
11001
+ if (column.field.indexOf('.') > 0) {
10993
11002
  const fieldName = column.field.split('.')[0];
10994
11003
  const displayName = column.field.split('.')[1];
10995
11004
  const filedInfo = uiSchema.fields[fieldName];
10996
- if(filedInfo && (filedInfo.type === 'lookup' || filedInfo.type === 'master_detail') && isString(filedInfo.reference_to) ){
11005
+ if (filedInfo && (filedInfo.type === 'lookup' || filedInfo.type === 'master_detail') && isString(filedInfo.reference_to)) {
10997
11006
  const rfUiSchema = await getUISchema(filedInfo.reference_to);
10998
11007
  const rfFieldInfo = rfUiSchema.fields[displayName];
10999
- fields.push(Object.assign({}, rfFieldInfo,
11000
- {name: `${fieldName}__expand.${displayName}`, expand: true, expandInfo: {fieldName, displayName}},
11008
+ fields.push(Object.assign({}, rfFieldInfo, ctx,
11009
+ { name: `${fieldName}__expand.${displayName}`, expand: true, expandInfo: { fieldName, displayName } },
11001
11010
  {
11002
11011
  width: column.width,
11003
11012
  wrap: column.wrap, // wrap = true 是没效果的
@@ -11005,10 +11014,10 @@ async function getTableSchema(
11005
11014
  }
11006
11015
  ));
11007
11016
  }
11008
- }else {
11009
- if(uiSchema.fields[column.field]){
11017
+ } else {
11018
+ if (uiSchema.fields[column.field]) {
11010
11019
  fields.push(
11011
- Object.assign({}, uiSchema.fields[column.field], {
11020
+ Object.assign({}, uiSchema.fields[column.field], ctx, {
11012
11021
  width: column.width,
11013
11022
  wrap: column.wrap, // wrap = true 是没效果的
11014
11023
  amis: column.amis
@@ -11018,17 +11027,36 @@ async function getTableSchema(
11018
11027
  }
11019
11028
  }
11020
11029
  }
11030
+ return fields;
11031
+ }
11032
+
11033
+ // 获取对象表格
11034
+ async function getTableSchema(
11035
+ appName,
11036
+ objectName,
11037
+ columns,
11038
+ ctx = {}
11039
+ ) {
11040
+ // console.time('getTableSchema', columns);
11041
+ const uiSchema = await getUISchema(objectName);
11042
+
11043
+ let sort = ctx.sort;
11044
+ if(!sort){
11045
+ const sortField = ctx.sortField;
11046
+ const sortOrder = ctx.sortOrder;
11047
+ if(sortField){
11048
+ let sortStr = sortField + ' ' + sortOrder || 'asc';
11049
+ sort = sortStr;
11050
+ }
11051
+ }
11052
+
11053
+ let fields = await convertColumnsToTableFields(columns, uiSchema);
11021
11054
 
11022
11055
  const extraColumns = ctx.extraColumns;
11023
11056
 
11024
11057
  if (extraColumns) {
11025
- each(extraColumns, function (column) {
11026
- if (isString(column)) {
11027
- fields.push({ extra: true, name: column });
11028
- } else if (isObject$1(column)) {
11029
- fields.push({ extra: true, name: column.field });
11030
- }
11031
- });
11058
+ let extraFields = await convertColumnsToTableFields(extraColumns, uiSchema, {extra: true});
11059
+ fields = fields.concat(extraFields);
11032
11060
  }
11033
11061
 
11034
11062
  const amisSchema = await getObjectCRUD(uiSchema, fields, {