@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.cjs.js CHANGED
@@ -426,8 +426,8 @@ function getContrastColor(bgColor) {
426
426
  /*
427
427
  * @Author: baozhoutao@steedos.com
428
428
  * @Date: 2022-05-23 09:53:08
429
- * @LastEditors: liaodaxue
430
- * @LastEditTime: 2023-07-28 16:26:31
429
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
430
+ * @LastEditTime: 2023-08-03 18:07:54
431
431
  * @Description:
432
432
  */
433
433
 
@@ -509,7 +509,11 @@ function getNameTplUrl(field, ctx){
509
509
 
510
510
  function getNameTpl(field, ctx){
511
511
  const href = getNameTplUrl(field, ctx);
512
- return `<a href="${href}">\${${field.name}}</a>`
512
+ let linkTarget = "";
513
+ if(ctx && ctx.isLookup){
514
+ linkTarget = "target='_blank'";
515
+ }
516
+ return `<a href="${href}" ${linkTarget}>\${${field.name}}</a>`
513
517
  }
514
518
 
515
519
  function getRelatedFieldTpl(field, ctx){
@@ -522,6 +526,11 @@ function getRelatedFieldTpl(field, ctx){
522
526
  }
523
527
  }
524
528
 
529
+ let linkTarget = "";
530
+ if(ctx && ctx.isLookup){
531
+ linkTarget = "target='_blank'";
532
+ }
533
+
525
534
  const onlyDisplayLabel = ctx.onlyDisplayLabel;
526
535
 
527
536
  let fieldDataStrTpl = `data._display.${field.name}`;
@@ -537,7 +546,7 @@ function getRelatedFieldTpl(field, ctx){
537
546
  const href = Router.getObjectDetailPath({
538
547
  formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
539
548
  });
540
- labelTpl = `<a href="${href}"><%=item.label%></a>`;
549
+ labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
541
550
  }
542
551
  tpl = `
543
552
  <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item,index) { %> <% if(index>0 && index<${fieldDataStrTpl}.length){ %> , <% } %> ${labelTpl} <% }); %><% } %>
@@ -555,7 +564,7 @@ function getRelatedFieldTpl(field, ctx){
555
564
  const href = Router.getObjectDetailPath({
556
565
  formFactor: ctx.formFactor, appId: "${appId}", objectName: `${objectNameTpl}`, recordId: `${recordIdTpl}`
557
566
  });
558
- labelTpl = `<a href="${href}">${labelTpl}</a>`;
567
+ labelTpl = `<a href="${href}" ${linkTarget}>${labelTpl}</a>`;
559
568
  }
560
569
  tpl = labelTpl;
561
570
  }
@@ -567,7 +576,7 @@ function getRelatedFieldTpl(field, ctx){
567
576
  const href = Router.getObjectDetailPath({
568
577
  formFactor: ctx.formFactor, appId: "<%=data.appId%>", objectName: `<%=item.objectName%>`, recordId: `<%=item.value%>`, _templateType: "JavaScript"
569
578
  });
570
- labelTpl = `<a href="${href}"><%=item.label%></a>`;
579
+ labelTpl = `<a href="${href}" ${linkTarget}><%=item.label%></a>`;
571
580
  }
572
581
  tpl = `
573
582
  <% if (${fieldDataStrTpl} && ${fieldDataStrTpl}.length) { %><% ${fieldDataStrTpl}.forEach(function(item) { %> ${labelTpl} <% }); %><% } %>
@@ -3278,12 +3287,6 @@ async function getObjectFieldsFilterFormSchema(ctx) {
3278
3287
  if (
3279
3288
  field && window.isFieldTypeSearchable(field.type)
3280
3289
  ) {
3281
- delete field.defaultValue;
3282
- delete field.required;
3283
- delete field.is_wide;
3284
- delete field.readonly;
3285
- delete field.hidden;
3286
- delete field.omit;
3287
3290
  var ctx = ${JSON.stringify(ctx)};
3288
3291
  const amisField = window.getFieldSearchable(field, fields, ctx);
3289
3292
  return amisField;
@@ -3379,7 +3382,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3379
3382
  if(!event.data.isLookup){
3380
3383
  // 刷新浏览器后,filterFormValues值是空的,只能从本地存储中取出并重置为空值
3381
3384
  const listViewId = event.data.listViewId;
3382
- const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
3385
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (listViewId || "");
3383
3386
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
3384
3387
  if(localListViewProps){
3385
3388
  localListViewProps = JSON.parse(localListViewProps);
@@ -3411,7 +3414,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3411
3414
  searchableFieldsStoreKey += "lookup/" + objectName;
3412
3415
  }
3413
3416
  else{
3414
- searchableFieldsStoreKey += listViewId;
3417
+ searchableFieldsStoreKey += (listViewId || "");
3415
3418
  }
3416
3419
  let defaultSearchableFields = sessionStorage.getItem(searchableFieldsStoreKey);
3417
3420
  if(defaultSearchableFields){
@@ -3438,7 +3441,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3438
3441
  setData({ showFieldsFilter: false });
3439
3442
  }
3440
3443
  else{
3441
- const listViewPropsStoreKey = location.pathname + "/crud/" + data.listViewId ;
3444
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (data.listViewId || "");
3442
3445
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
3443
3446
  if(localListViewProps){
3444
3447
  localListViewProps = JSON.parse(localListViewProps);
@@ -3484,7 +3487,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3484
3487
  searchableFieldsStoreKey += "lookup/" + objectName;
3485
3488
  }
3486
3489
  else{
3487
- searchableFieldsStoreKey += listViewId;
3490
+ searchableFieldsStoreKey += (listViewId || "");
3488
3491
  }
3489
3492
  sessionStorage.setItem(searchableFieldsStoreKey, value);
3490
3493
 
@@ -3542,7 +3545,7 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3542
3545
  }
3543
3546
 
3544
3547
  // 列表视图crud支持本地缓存,所以需要进一步清除浏览器本地缓存里面用户在可搜索项中移除的字段值
3545
- const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
3548
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (listViewId || "");
3546
3549
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
3547
3550
  if(localListViewProps){
3548
3551
  localListViewProps = JSON.parse(localListViewProps);
@@ -3661,7 +3664,8 @@ async function getObjectFieldsFilterBarSchema(objectSchema, ctx) {
3661
3664
  const fields = uiSchema.fields;
3662
3665
  const options = (payload.data?.options || []).filter(function(item){
3663
3666
  let field = fields[item.value];
3664
- return !!field && window.isFieldTypeSearchable(field.type)
3667
+ // TODO: 暂时禁用location类型字段的列表搜索
3668
+ return !!field && window.isFieldTypeSearchable(field.type) && field.type !== 'location'
3665
3669
  });
3666
3670
  payload.data = {
3667
3671
  "options": options
@@ -5264,6 +5268,7 @@ crudService && crudService.setData({showFieldsFilter: toShowFieldsFilter});
5264
5268
 
5265
5269
  function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false, hiddenCount = false, headerToolbarItems, filterVisible = true} = {}){
5266
5270
  // console.log(`getObjectHeaderToolbar====>`, filterVisible)
5271
+ console.log(`getObjectHeaderToolbar`, mainObject);
5267
5272
  const isMobile = window.innerWidth < 768;
5268
5273
  if(isMobile){
5269
5274
  showDisplayAs = false;
@@ -5363,7 +5368,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5363
5368
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5364
5369
  },
5365
5370
  // getExportExcelToolbarButtonSchema(),
5366
- getSettingListviewToolbarButtonSchema(),
5371
+ mainObject?.permissions?.allowCreateListViews ? getSettingListviewToolbarButtonSchema() : {},
5367
5372
  getDisplayAsButton(mainObject?.name),
5368
5373
  filterVisible ? {
5369
5374
  "label": i18next__default["default"].t('frontend_button_search_tooltip'),
@@ -5759,6 +5764,10 @@ async function lookupToAmisPicker(field, readonly, ctx){
5759
5764
  return ;
5760
5765
  }
5761
5766
  const refObjectConfig = await getUISchema(referenceTo.objectName);
5767
+
5768
+ ctx.idFieldName = refObjectConfig.idFieldName;
5769
+ ctx.objectName = refObjectConfig.name;
5770
+
5762
5771
  const tableFields = [];
5763
5772
  let i = 0;
5764
5773
  const searchableFields = [];
@@ -6126,7 +6135,6 @@ async function lookupToAmisPicker(field, readonly, ctx){
6126
6135
  if(readonly){
6127
6136
  data.tpl = await getLookupTpl(field, ctx);
6128
6137
  }
6129
-
6130
6138
  return data;
6131
6139
  }
6132
6140
 
@@ -7203,12 +7211,35 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
7203
7211
  }
7204
7212
  }
7205
7213
 
7214
+ const coordinatesType = field.coordinatesType || "bd09";
7206
7215
  convertData = {
7207
7216
  type: getAmisStaticFieldType('location', readonly),
7208
7217
  tpl: readonly ? getLocationTpl(field) : null,
7209
7218
  ak,
7210
7219
  vendor,
7211
- label: field.label
7220
+ clearable: true,
7221
+ coordinatesType,
7222
+ label: field.label,
7223
+ pipeOut: (value, oldValue, data) => {
7224
+ if (value) {
7225
+ const lng = value.lng;
7226
+ const lat = value.lat;
7227
+ let coordinates = [lng,lat];
7228
+ if(window.coordtransform){
7229
+ if(coordinatesType.toLowerCase() === 'bd09'){
7230
+ const bd09togcj02 = window.coordtransform.bd09togcj02(lng,lat);
7231
+ coordinates = window.coordtransform.gcj02towgs84(bd09togcj02[0],bd09togcj02[1]);
7232
+ }else if(coordinatesType.toLowerCase() === 'gcj02'){
7233
+ coordinates = window.coordtransform.gcj02towgs84(lng,lat);
7234
+ }
7235
+ }
7236
+ value.wgs84 = {
7237
+ type: "Point",
7238
+ coordinates
7239
+ };
7240
+ return value; // 切换到数字之后的默认值
7241
+ }
7242
+ }
7212
7243
  };
7213
7244
  break;
7214
7245
  case 'avatar':
@@ -7433,6 +7464,24 @@ async function getFieldSearchable(perField, permissionFields, ctx){
7433
7464
  _field.multiple = true;
7434
7465
  _field.is_wide = false;
7435
7466
  _field.defaultValue = undefined;
7467
+ _field.required = false;
7468
+ _field.hidden = false;
7469
+ _field.omit = false;
7470
+
7471
+ if(_field.amis){
7472
+ delete _field.amis.static;
7473
+ delete _field.amis.staticOn;
7474
+ delete _field.amis.disabled;
7475
+ delete _field.amis.disabledOn;
7476
+ delete _field.amis.required;
7477
+ delete _field.amis.requiredOn;
7478
+ delete _field.amis.visible;
7479
+ delete _field.amis.visibleOn;
7480
+ delete _field.amis.hidden;
7481
+ delete _field.amis.hiddenOn;
7482
+ delete _field.amis.autoFill;
7483
+ }
7484
+
7436
7485
  const amisField = await convertSFieldToAmisField(_field, false, Object.assign({}, ctx, {fieldNamePrefix: fieldNamePrefix, required: false, showSystemFields: true, inFilterForm: true}));
7437
7486
  if(amisField){
7438
7487
  return amisField;
@@ -7676,6 +7725,10 @@ async function getQuickEditSchema(field, options){
7676
7725
  if(field.type == "file" && field.multiple){
7677
7726
  quickEditSchema = false;
7678
7727
  }
7728
+ //TODO:location字段在列表中快速编辑后存在bug,保存时可能会丢失部分数据,暂时禁用
7729
+ if(field.type == "location"){
7730
+ quickEditSchema = false;
7731
+ }
7679
7732
  }
7680
7733
  return quickEditSchema;
7681
7734
  }
@@ -7706,6 +7759,7 @@ async function getTableColumns(fields, options){
7706
7759
  if(field.wrap != true){
7707
7760
  className += " whitespace-nowrap";
7708
7761
  }
7762
+ let columnItem;
7709
7763
  if((field.is_name || field.name === options.labelFieldName) && options.objectName === 'cms_files'){
7710
7764
  const previewFileScript = `
7711
7765
  var data = event.data;
@@ -7713,12 +7767,11 @@ async function getTableColumns(fields, options){
7713
7767
  var file_id = data._id;
7714
7768
  SteedosUI.previewFile && SteedosUI.previewFile({file_name, file_id});
7715
7769
  `;
7716
- columns.push({
7770
+ columnItem = {
7717
7771
  "type": "button",
7718
7772
  "label": `<%=data.versions ? data.name : "${field.label}"%>`,
7719
7773
  className,
7720
7774
  "level": "link",
7721
- "quickEdit": quickEditSchema,
7722
7775
  "onEvent": {
7723
7776
  "click": {
7724
7777
  "actions": [
@@ -7744,9 +7797,9 @@ async function getTableColumns(fields, options){
7744
7797
  ]
7745
7798
  }
7746
7799
  }
7747
- });
7800
+ };
7748
7801
  }else if(field.type === 'toggle'){
7749
- columns.push(Object.assign({}, {
7802
+ columnItem = Object.assign({}, {
7750
7803
  type: "switch",
7751
7804
  name: field.name,
7752
7805
  label: field.label,
@@ -7754,24 +7807,22 @@ async function getTableColumns(fields, options){
7754
7807
  toggled: field.toggled,
7755
7808
  static: true,
7756
7809
  className,
7757
- quickEdit: quickEditSchema
7758
- }, field.amis, {name: field.name}));
7810
+ }, field.amis, {name: field.name});
7759
7811
  }else if(field.type === 'avatar' || field.type === 'image' || field.type === 'file'){
7760
- columns.push(Object.assign({}, {
7812
+ columnItem = Object.assign({}, {
7761
7813
  type: "switch",
7762
7814
  name: field.name,
7763
7815
  label: field.label,
7764
7816
  width: getFieldWidth(field.width),
7765
7817
  toggled: field.toggled,
7766
- quickEdit: quickEditSchema,
7767
7818
  static: true,
7768
7819
  className,
7769
7820
  ...getAmisFileReadonlySchema(field)
7770
- }, field.amis, {name: field.name}));
7821
+ }, field.amis, {name: field.name});
7771
7822
  }
7772
7823
  else if(field.type === 'select'){
7773
7824
  const map = getSelectMap(field.options);
7774
- columns.push(Object.assign({}, {
7825
+ columnItem = Object.assign({}, {
7775
7826
  type: "mapping",
7776
7827
  name: field.name,
7777
7828
  label: field.label,
@@ -7781,8 +7832,7 @@ async function getTableColumns(fields, options){
7781
7832
  toggled: field.toggled,
7782
7833
  className,
7783
7834
  static: true,
7784
- quickEdit: quickEditSchema
7785
- }, field.amis, {name: field.name}));
7835
+ }, field.amis, {name: field.name});
7786
7836
  }
7787
7837
  else {
7788
7838
  const tpl = await getFieldTpl(field, options);
@@ -7802,7 +7852,7 @@ async function getTableColumns(fields, options){
7802
7852
  className += 'min-w-56';
7803
7853
  }
7804
7854
  if(!field.hidden && !field.extra){
7805
- columns.push(Object.assign({}, {
7855
+ columnItem = Object.assign({}, {
7806
7856
  name: field.name,
7807
7857
  label: field.label,
7808
7858
  sortable: field.sortable,
@@ -7813,13 +7863,18 @@ async function getTableColumns(fields, options){
7813
7863
  toggled: field.toggled,
7814
7864
  className,
7815
7865
  static: true,
7816
- quickEdit: quickEditSchema,
7817
7866
  options: field.type === 'html' ? {html: true} : null
7818
7867
  // toggled: true
7819
- }, field.amis, {name: field.name}));
7868
+ }, field.amis, {name: field.name});
7820
7869
  }
7821
7870
  }
7822
-
7871
+ if(columnItem){
7872
+ if(quickEditSchema){
7873
+ columnItem.quickEdit = quickEditSchema;
7874
+ columnItem.quickEditEnabledOn = "${is_system !== true}";
7875
+ }
7876
+ columns.push(columnItem);
7877
+ }
7823
7878
  }
7824
7879
  // columns.push(getOperation(fields));
7825
7880
  if(!___namespace.some(columns, { name: options.labelFieldName })){
@@ -8125,6 +8180,7 @@ async function getTableOperation(ctx){
8125
8180
  }
8126
8181
 
8127
8182
  async function getTableSchema$1(fields, options){
8183
+ let isLookup = options && options.isLookup;
8128
8184
  if(!options){
8129
8185
  options = {};
8130
8186
  }
@@ -8134,7 +8190,9 @@ async function getTableSchema$1(fields, options){
8134
8190
  }
8135
8191
  else {
8136
8192
  columns = await getTableColumns(fields, options);
8137
- columns.push(await getTableOperation(options));
8193
+ if(!isLookup){
8194
+ columns.push(await getTableOperation(options));
8195
+ }
8138
8196
  }
8139
8197
  return {
8140
8198
  mode: "table",
@@ -8230,7 +8288,7 @@ async function getTableApi(mainObject, fields, options){
8230
8288
  try{
8231
8289
  // TODO: 不应该直接在这里取localStorage,应该从外面传入
8232
8290
  const listViewId = api.data.listViewId;
8233
- const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
8291
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (listViewId || "");
8234
8292
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
8235
8293
  if(localListViewProps){
8236
8294
  localListViewProps = JSON.parse(localListViewProps);
@@ -8431,7 +8489,7 @@ async function getTableApi(mainObject, fields, options){
8431
8489
  try{
8432
8490
  // TODO: 不应该直接在这里取localStorage,应该从外面传入
8433
8491
  const listViewId = api.body.listViewId;
8434
- const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
8492
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (listViewId || "");
8435
8493
  /**
8436
8494
  * localListViewProps规范来自crud请求api中api.data.$self参数值的。
8437
8495
  * 比如:{"perPage":20,"page":1,"__searchable__name":"7","__searchable__between__n1__c":[null,null],"filter":[["name","contains","a"]]}
@@ -10399,8 +10457,8 @@ async function getRelatedListSchema(
10399
10457
  /*
10400
10458
  * @Author: baozhoutao@steedos.com
10401
10459
  * @Date: 2022-07-05 15:55:39
10402
- * @LastEditors: baozhoutao@steedos.com
10403
- * @LastEditTime: 2023-07-29 13:58:07
10460
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
10461
+ * @LastEditTime: 2023-08-01 14:50:23
10404
10462
  * @Description:
10405
10463
  */
10406
10464
 
@@ -10665,7 +10723,7 @@ async function getListSchema(
10665
10723
  * 本次存储代码段
10666
10724
  */
10667
10725
  try {
10668
- const listViewPropsStoreKey = location.pathname + "/crud/" + ctx.listViewId;
10726
+ const listViewPropsStoreKey = location.pathname + "/crud/" + (ctx.listViewId || "");
10669
10727
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
10670
10728
  /**
10671
10729
  * localListViewProps规范来自crud请求api中api.data.$self参数值的。