@steedos-widgets/amis-lib 1.2.35-beta.2 → 1.2.36

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
@@ -399,8 +399,8 @@ function getContrastColor(bgColor) {
399
399
  /*
400
400
  * @Author: baozhoutao@steedos.com
401
401
  * @Date: 2022-05-23 09:53:08
402
- * @LastEditors: liaodaxue
403
- * @LastEditTime: 2023-07-28 16:26:31
402
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
403
+ * @LastEditTime: 2023-08-03 18:07:54
404
404
  * @Description:
405
405
  */
406
406
 
@@ -482,7 +482,11 @@ function getNameTplUrl(field, ctx){
482
482
 
483
483
  function getNameTpl(field, ctx){
484
484
  const href = getNameTplUrl(field, ctx);
485
- return `<a href="${href}">\${${field.name}}</a>`
485
+ let linkTarget = "";
486
+ if(ctx && ctx.isLookup){
487
+ linkTarget = "target='_blank'";
488
+ }
489
+ return `<a href="${href}" ${linkTarget}>\${${field.name}}</a>`
486
490
  }
487
491
 
488
492
  function getRelatedFieldTpl(field, ctx){
@@ -495,6 +499,11 @@ function getRelatedFieldTpl(field, ctx){
495
499
  }
496
500
  }
497
501
 
502
+ let linkTarget = "";
503
+ if(ctx && ctx.isLookup){
504
+ linkTarget = "target='_blank'";
505
+ }
506
+
498
507
  const onlyDisplayLabel = ctx.onlyDisplayLabel;
499
508
 
500
509
  let fieldDataStrTpl = `data._display.${field.name}`;
@@ -510,7 +519,7 @@ function getRelatedFieldTpl(field, ctx){
510
519
  const href = Router.getObjectDetailPath({
511
520
  formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
512
521
  });
513
- labelTpl = `<a href="${href}"><%=item.label%></a>`;
522
+ labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
514
523
  }
515
524
  tpl = `
516
525
  <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item,index) { %> <% if(index>0 && index<${fieldDataStrTpl}.length){ %> , <% } %> ${labelTpl} <% }); %><% } %>
@@ -528,7 +537,7 @@ function getRelatedFieldTpl(field, ctx){
528
537
  const href = Router.getObjectDetailPath({
529
538
  formFactor: ctx.formFactor, appId: "${appId}", objectName: `${objectNameTpl}`, recordId: `${recordIdTpl}`
530
539
  });
531
- labelTpl = `<a href="${href}">${labelTpl}</a>`;
540
+ labelTpl = `<a href="${href}" ${linkTarget}>${labelTpl}</a>`;
532
541
  }
533
542
  tpl = labelTpl;
534
543
  }
@@ -540,7 +549,7 @@ function getRelatedFieldTpl(field, ctx){
540
549
  const href = Router.getObjectDetailPath({
541
550
  formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
542
551
  });
543
- labelTpl = `<a href="${href}"><%=item.label%></a>`;
552
+ labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
544
553
  }
545
554
  tpl = `
546
555
  <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item) { %> ${labelTpl} <% }); %><% } %>
@@ -3251,12 +3260,6 @@ async function getObjectFieldsFilterFormSchema(ctx) {
3251
3260
  if (
3252
3261
  field && window.isFieldTypeSearchable(field.type)
3253
3262
  ) {
3254
- delete field.defaultValue;
3255
- delete field.required;
3256
- delete field.is_wide;
3257
- delete field.readonly;
3258
- delete field.hidden;
3259
- delete field.omit;
3260
3263
  var ctx = ${JSON.stringify(ctx)};
3261
3264
  const amisField = window.getFieldSearchable(field, fields, ctx);
3262
3265
  return amisField;
@@ -3352,7 +3355,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3352
3355
  if(!event.data.isLookup){
3353
3356
  // 刷新浏览器后,filterFormValues值是空的,只能从本地存储中取出并重置为空值
3354
3357
  const listViewId = event.data.listViewId;
3355
- const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
3358
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (listViewId || "");
3356
3359
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
3357
3360
  if(localListViewProps){
3358
3361
  localListViewProps = JSON.parse(localListViewProps);
@@ -3384,7 +3387,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3384
3387
  searchableFieldsStoreKey += "lookup/" + objectName;
3385
3388
  }
3386
3389
  else{
3387
- searchableFieldsStoreKey += listViewId;
3390
+ searchableFieldsStoreKey += (listViewId || "");
3388
3391
  }
3389
3392
  let defaultSearchableFields = sessionStorage.getItem(searchableFieldsStoreKey);
3390
3393
  if(defaultSearchableFields){
@@ -3411,7 +3414,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3411
3414
  setData({ showFieldsFilter: false });
3412
3415
  }
3413
3416
  else{
3414
- const listViewPropsStoreKey = location.pathname + "/crud/" + data.listViewId ;
3417
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (data.listViewId || "");
3415
3418
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
3416
3419
  if(localListViewProps){
3417
3420
  localListViewProps = JSON.parse(localListViewProps);
@@ -3457,7 +3460,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3457
3460
  searchableFieldsStoreKey += "lookup/" + objectName;
3458
3461
  }
3459
3462
  else{
3460
- searchableFieldsStoreKey += listViewId;
3463
+ searchableFieldsStoreKey += (listViewId || "");
3461
3464
  }
3462
3465
  sessionStorage.setItem(searchableFieldsStoreKey, value);
3463
3466
 
@@ -3515,7 +3518,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3515
3518
  }
3516
3519
 
3517
3520
  // 列表视图crud支持本地缓存,所以需要进一步清除浏览器本地缓存里面用户在可搜索项中移除的字段值
3518
- const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
3521
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (listViewId || "");
3519
3522
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
3520
3523
  if(localListViewProps){
3521
3524
  localListViewProps = JSON.parse(localListViewProps);
@@ -3634,7 +3637,8 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3634
3637
  const fields = uiSchema.fields;
3635
3638
  const options = (payload.data?.options || []).filter(function(item){
3636
3639
  let field = fields[item.value];
3637
- return !!field && window.isFieldTypeSearchable(field.type)
3640
+ // TODO: 暂时禁用location类型字段的列表搜索
3641
+ return !!field && window.isFieldTypeSearchable(field.type) && field.type !== 'location'
3638
3642
  });
3639
3643
  payload.data = {
3640
3644
  "options": options
@@ -5237,6 +5241,7 @@ crudService && crudService.setData({showFieldsFilter: toShowFieldsFilter});
5237
5241
 
5238
5242
  function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false, hiddenCount = false, headerToolbarItems, filterVisible = true} = {}){
5239
5243
  // console.log(`getObjectHeaderToolbar====>`, filterVisible)
5244
+ console.log(`getObjectHeaderToolbar`, mainObject);
5240
5245
  const isMobile = window.innerWidth < 768;
5241
5246
  if(isMobile){
5242
5247
  showDisplayAs = false;
@@ -5336,7 +5341,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5336
5341
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5337
5342
  },
5338
5343
  // getExportExcelToolbarButtonSchema(),
5339
- getSettingListviewToolbarButtonSchema(),
5344
+ mainObject?.permissions?.allowCreateListViews ? getSettingListviewToolbarButtonSchema() : {},
5340
5345
  getDisplayAsButton(mainObject?.name),
5341
5346
  filterVisible ? {
5342
5347
  "label": i18next.t('frontend_button_search_tooltip'),
@@ -5732,6 +5737,10 @@ async function lookupToAmisPicker(field, readonly, ctx){
5732
5737
  return ;
5733
5738
  }
5734
5739
  const refObjectConfig = await getUISchema(referenceTo.objectName);
5740
+
5741
+ ctx.idFieldName = refObjectConfig.idFieldName;
5742
+ ctx.objectName = refObjectConfig.name;
5743
+
5735
5744
  const tableFields = [];
5736
5745
  let i = 0;
5737
5746
  const searchableFields = [];
@@ -6099,7 +6108,6 @@ async function lookupToAmisPicker(field, readonly, ctx){
6099
6108
  if(readonly){
6100
6109
  data.tpl = await getLookupTpl(field, ctx);
6101
6110
  }
6102
-
6103
6111
  return data;
6104
6112
  }
6105
6113
 
@@ -7176,12 +7184,35 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
7176
7184
  }
7177
7185
  }
7178
7186
 
7187
+ const coordinatesType = field.coordinatesType || "bd09";
7179
7188
  convertData = {
7180
7189
  type: getAmisStaticFieldType('location', readonly),
7181
7190
  tpl: readonly ? getLocationTpl(field) : null,
7182
7191
  ak,
7183
7192
  vendor,
7184
- label: field.label
7193
+ clearable: true,
7194
+ coordinatesType,
7195
+ label: field.label,
7196
+ pipeOut: (value, oldValue, data) => {
7197
+ if (value) {
7198
+ const lng = value.lng;
7199
+ const lat = value.lat;
7200
+ let coordinates = [lng,lat];
7201
+ if(window.coordtransform){
7202
+ if(coordinatesType.toLowerCase() === 'bd09'){
7203
+ const bd09togcj02 = window.coordtransform.bd09togcj02(lng,lat);
7204
+ coordinates = window.coordtransform.gcj02towgs84(bd09togcj02[0],bd09togcj02[1]);
7205
+ }else if(coordinatesType.toLowerCase() === 'gcj02'){
7206
+ coordinates = window.coordtransform.gcj02towgs84(lng,lat);
7207
+ }
7208
+ }
7209
+ value.wgs84 = {
7210
+ type: "Point",
7211
+ coordinates
7212
+ };
7213
+ return value; // 切换到数字之后的默认值
7214
+ }
7215
+ }
7185
7216
  };
7186
7217
  break;
7187
7218
  case 'avatar':
@@ -7406,6 +7437,24 @@ async function getFieldSearchable(perField, permissionFields, ctx){
7406
7437
  _field.multiple = true;
7407
7438
  _field.is_wide = false;
7408
7439
  _field.defaultValue = undefined;
7440
+ _field.required = false;
7441
+ _field.hidden = false;
7442
+ _field.omit = false;
7443
+
7444
+ if(_field.amis){
7445
+ delete _field.amis.static;
7446
+ delete _field.amis.staticOn;
7447
+ delete _field.amis.disabled;
7448
+ delete _field.amis.disabledOn;
7449
+ delete _field.amis.required;
7450
+ delete _field.amis.requiredOn;
7451
+ delete _field.amis.visible;
7452
+ delete _field.amis.visibleOn;
7453
+ delete _field.amis.hidden;
7454
+ delete _field.amis.hiddenOn;
7455
+ delete _field.amis.autoFill;
7456
+ }
7457
+
7409
7458
  const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
7410
7459
  if(amisField){
7411
7460
  return amisField;
@@ -7649,6 +7698,10 @@ async function getQuickEditSchema(field, options){
7649
7698
  if(field.type == "file" && field.multiple){
7650
7699
  quickEditSchema = false;
7651
7700
  }
7701
+ //TODO:location字段在列表中快速编辑后存在bug,保存时可能会丢失部分数据,暂时禁用
7702
+ if(field.type == "location"){
7703
+ quickEditSchema = false;
7704
+ }
7652
7705
  }
7653
7706
  return quickEditSchema;
7654
7707
  }
@@ -7679,6 +7732,7 @@ async function getTableColumns(fields, options){
7679
7732
  if(field.wrap != true){
7680
7733
  className += " whitespace-nowrap";
7681
7734
  }
7735
+ let columnItem;
7682
7736
  if((field.is_name || field.name === options.labelFieldName) && options.objectName === 'cms_files'){
7683
7737
  const previewFileScript = `
7684
7738
  var data = event.data;
@@ -7686,12 +7740,11 @@ async function getTableColumns(fields, options){
7686
7740
  var file_id = data._id;
7687
7741
  SteedosUI.previewFile && SteedosUI.previewFile({file_name, file_id});
7688
7742
  `;
7689
- columns.push({
7743
+ columnItem = {
7690
7744
  "type": "button",
7691
7745
  "label": `<%=data.versions ? data.name : "${field.label}"%>`,
7692
7746
  className,
7693
7747
  "level": "link",
7694
- "quickEdit": quickEditSchema,
7695
7748
  "onEvent": {
7696
7749
  "click": {
7697
7750
  "actions": [
@@ -7717,9 +7770,9 @@ async function getTableColumns(fields, options){
7717
7770
  ]
7718
7771
  }
7719
7772
  }
7720
- });
7773
+ };
7721
7774
  }else if(field.type === 'toggle'){
7722
- columns.push(Object.assign({}, {
7775
+ columnItem = Object.assign({}, {
7723
7776
  type: "switch",
7724
7777
  name: field.name,
7725
7778
  label: field.label,
@@ -7727,24 +7780,22 @@ async function getTableColumns(fields, options){
7727
7780
  toggled: field.toggled,
7728
7781
  static: true,
7729
7782
  className,
7730
- quickEdit: quickEditSchema
7731
- }, field.amis, {name: field.name}));
7783
+ }, field.amis, {name: field.name});
7732
7784
  }else if(field.type === 'avatar' || field.type === 'image' || field.type === 'file'){
7733
- columns.push(Object.assign({}, {
7785
+ columnItem = Object.assign({}, {
7734
7786
  type: "switch",
7735
7787
  name: field.name,
7736
7788
  label: field.label,
7737
7789
  width: getFieldWidth(field.width),
7738
7790
  toggled: field.toggled,
7739
- quickEdit: quickEditSchema,
7740
7791
  static: true,
7741
7792
  className,
7742
7793
  ...getAmisFileReadonlySchema(field)
7743
- }, field.amis, {name: field.name}));
7794
+ }, field.amis, {name: field.name});
7744
7795
  }
7745
7796
  else if(field.type === 'select'){
7746
7797
  const map = getSelectMap(field.options);
7747
- columns.push(Object.assign({}, {
7798
+ columnItem = Object.assign({}, {
7748
7799
  type: "mapping",
7749
7800
  name: field.name,
7750
7801
  label: field.label,
@@ -7754,8 +7805,7 @@ async function getTableColumns(fields, options){
7754
7805
  toggled: field.toggled,
7755
7806
  className,
7756
7807
  static: true,
7757
- quickEdit: quickEditSchema
7758
- }, field.amis, {name: field.name}));
7808
+ }, field.amis, {name: field.name});
7759
7809
  }
7760
7810
  else {
7761
7811
  const tpl = await getFieldTpl(field, options);
@@ -7775,7 +7825,7 @@ async function getTableColumns(fields, options){
7775
7825
  className += 'min-w-56';
7776
7826
  }
7777
7827
  if(!field.hidden && !field.extra){
7778
- columns.push(Object.assign({}, {
7828
+ columnItem = Object.assign({}, {
7779
7829
  name: field.name,
7780
7830
  label: field.label,
7781
7831
  sortable: field.sortable,
@@ -7786,13 +7836,18 @@ async function getTableColumns(fields, options){
7786
7836
  toggled: field.toggled,
7787
7837
  className,
7788
7838
  static: true,
7789
- quickEdit: quickEditSchema,
7790
7839
  options: field.type === 'html' ? {html: true} : null
7791
7840
  // toggled: true
7792
- }, field.amis, {name: field.name}));
7841
+ }, field.amis, {name: field.name});
7793
7842
  }
7794
7843
  }
7795
-
7844
+ if(columnItem){
7845
+ if(quickEditSchema){
7846
+ columnItem.quickEdit = quickEditSchema;
7847
+ columnItem.quickEditEnabledOn = "${is_system !== true}";
7848
+ }
7849
+ columns.push(columnItem);
7850
+ }
7796
7851
  }
7797
7852
  // columns.push(getOperation(fields));
7798
7853
  if(!_$1.some(columns, { name: options.labelFieldName })){
@@ -8098,6 +8153,7 @@ async function getTableOperation(ctx){
8098
8153
  }
8099
8154
 
8100
8155
  async function getTableSchema$1(fields, options){
8156
+ let isLookup = options && options.isLookup;
8101
8157
  if(!options){
8102
8158
  options = {};
8103
8159
  }
@@ -8107,7 +8163,9 @@ async function getTableSchema$1(fields, options){
8107
8163
  }
8108
8164
  else {
8109
8165
  columns = await getTableColumns(fields, options);
8110
- columns.push(await getTableOperation(options));
8166
+ if(!isLookup){
8167
+ columns.push(await getTableOperation(options));
8168
+ }
8111
8169
  }
8112
8170
  return {
8113
8171
  mode: "table",
@@ -8203,7 +8261,7 @@ async function getTableApi(mainObject, fields, options){
8203
8261
  try{
8204
8262
  // TODO: 不应该直接在这里取localStorage,应该从外面传入
8205
8263
  const listViewId = api.data.listViewId;
8206
- const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
8264
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (listViewId || "");
8207
8265
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
8208
8266
  if(localListViewProps){
8209
8267
  localListViewProps = JSON.parse(localListViewProps);
@@ -8404,7 +8462,7 @@ async function getTableApi(mainObject, fields, options){
8404
8462
  try{
8405
8463
  // TODO: 不应该直接在这里取localStorage,应该从外面传入
8406
8464
  const listViewId = api.body.listViewId;
8407
- const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
8465
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (listViewId || "");
8408
8466
  /**
8409
8467
  * localListViewProps规范来自crud请求api中api.data.$self参数值的。
8410
8468
  * 比如:{"perPage":20,"page":1,"__searchable__name":"7","__searchable__between__n1__c":[null,null],"filter":[["name","contains","a"]]}
@@ -10372,8 +10430,8 @@ async function getRelatedListSchema(
10372
10430
  /*
10373
10431
  * @Author: baozhoutao@steedos.com
10374
10432
  * @Date: 2022-07-05 15:55:39
10375
- * @LastEditors: baozhoutao@steedos.com
10376
- * @LastEditTime: 2023-07-29 13:58:07
10433
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
10434
+ * @LastEditTime: 2023-08-01 14:50:23
10377
10435
  * @Description:
10378
10436
  */
10379
10437
 
@@ -10638,7 +10696,7 @@ async function getListSchema(
10638
10696
  * 本次存储代码段
10639
10697
  */
10640
10698
  try {
10641
- const listViewPropsStoreKey = location.pathname + "/crud/" + ctx.listViewId;
10699
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (ctx.listViewId || "");
10642
10700
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
10643
10701
  /**
10644
10702
  * localListViewProps规范来自crud请求api中api.data.$self参数值的。