@steedos-widgets/amis-lib 1.3.0-beta.13 → 1.3.0-beta.15

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
@@ -409,8 +409,8 @@ const Router = {
409
409
  /*
410
410
  * @Author: baozhoutao@steedos.com
411
411
  * @Date: 2022-07-20 16:29:22
412
- * @LastEditors: Please set LastEditors
413
- * @LastEditTime: 2023-05-18 15:22:51
412
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
413
+ * @LastEditTime: 2023-09-06 18:59:40
414
414
  * @Description:
415
415
  */
416
416
 
@@ -423,6 +423,32 @@ function getContrastColor(bgColor) {
423
423
  return brightness < 128 ? "#ffffff" : "#000000";
424
424
  }
425
425
 
426
+ function getLookupListView(refObjectConfig) {
427
+ const listNameAll = "all";
428
+ const listNameLookup = "lookup";
429
+ let listViewAll, listViewLookup;
430
+
431
+ _.each(
432
+ refObjectConfig.list_views,
433
+ (view, name) => {
434
+ if (name === listNameAll) {
435
+ listViewAll = view;
436
+ if(!listViewAll.name){
437
+ listViewAll.name = name;
438
+ }
439
+ }
440
+ else if (name === listNameLookup) {
441
+ listViewLookup = view;
442
+ if(!listViewLookup.name){
443
+ listViewLookup.name = name;
444
+ }
445
+ }
446
+ }
447
+ );
448
+ let listView = listViewLookup || listViewAll;
449
+ return listView;
450
+ }
451
+
426
452
  /*
427
453
  * @Author: baozhoutao@steedos.com
428
454
  * @Date: 2022-05-23 09:53:08
@@ -995,7 +1021,7 @@ function getApi$2 (isMobile){
995
1021
  }
996
1022
  }
997
1023
 
998
- var frontend_field_group_generalization$1 = "Generalization";
1024
+ var frontend_field_group_generalization$1 = "General";
999
1025
  var frontend_download$1 = "Download";
1000
1026
  var frontend_form_save$1 = "Save";
1001
1027
  var frontend_form_save_and_new$1 = "Save and New";
@@ -1680,10 +1706,7 @@ async function getSearchApi(field, ctx) {
1680
1706
  }
1681
1707
 
1682
1708
  function getRefListViewSort$1(refObject){
1683
- const listView = ___namespace.find(
1684
- refObject.list_views,
1685
- (view, name) => name === "all"
1686
- );
1709
+ let listView = getLookupListView(refObject);
1687
1710
  let sort = "";
1688
1711
  if(listView){
1689
1712
  sort = getListViewSort(listView);
@@ -3618,6 +3641,10 @@ function getObjectListHeaderFirstLine(objectSchema, listViewName, ctx) {
3618
3641
  _$1.each(
3619
3642
  objectSchema.list_views,
3620
3643
  (listView, name) => {
3644
+ if(name === "lookup"){
3645
+ // 内置lookup为弹出选择专用视图,不显示在列表切换区域
3646
+ return;
3647
+ }
3621
3648
  listViewButtonOptions.push({
3622
3649
  type: "button",
3623
3650
  label: listView.label,
@@ -5481,10 +5508,8 @@ async function getDeferApi(field, ctx) {
5481
5508
  }
5482
5509
 
5483
5510
  function getRefListViewSort(refObject){
5484
- const listView = ___namespace.find(
5485
- refObject.list_views,
5486
- (view, name) => name === "all"
5487
- );
5511
+ let listView = getLookupListView(refObject);
5512
+
5488
5513
  let sort = "";
5489
5514
  if(listView){
5490
5515
  sort = getListViewSort(listView);
@@ -5701,19 +5726,14 @@ async function lookupToAmisPicker(field, readonly, ctx){
5701
5726
  ctx.objectName = refObjectConfig.name;
5702
5727
 
5703
5728
  let tableFields = [];
5704
- let i = 0;
5705
5729
  const searchableFields = [];
5706
5730
 
5707
- const fieldsArr = [];
5708
-
5709
- const listName = "all";
5731
+ let fieldsArr = [];
5710
5732
 
5711
5733
  const isMobile = window.innerWidth < 768;
5712
5734
 
5713
- const listView = ___namespace.find(
5714
- refObjectConfig.list_views,
5715
- (listView, name) => name === listName
5716
- );
5735
+ let listView = getLookupListView(refObjectConfig);
5736
+ let listName = listView && listView.name;
5717
5737
  if (listView && listView.columns) {
5718
5738
  ___namespace.each(listView.columns, function (column) {
5719
5739
  if (___namespace.isString(column) && refObjectConfig.fields[column]) {
@@ -5728,7 +5748,7 @@ async function lookupToAmisPicker(field, readonly, ctx){
5728
5748
  }
5729
5749
  });
5730
5750
  }else {
5731
- ___namespace.each(refObjectConfig.fields , (field, field_name)=>{
5751
+ ___namespace.each(refObjectConfig.fields, (field, field_name)=>{
5732
5752
  if(field_name != '_id' && !field.hidden){
5733
5753
  if(!___namespace.has(field, "name")){
5734
5754
  field.name = field_name;
@@ -5736,16 +5756,15 @@ async function lookupToAmisPicker(field, readonly, ctx){
5736
5756
  fieldsArr.push(field);
5737
5757
  }
5738
5758
  });
5759
+ // 没有视图权限时,取对象上前5个字段,按sort_no排序
5760
+ fieldsArr = ___namespace.sortBy(fieldsArr, "sort_no").slice(0,5);
5739
5761
  }
5740
5762
 
5741
- ___namespace.each(___namespace.sortBy(fieldsArr, "sort_no"),function(field){
5742
- if(i < 5){
5743
- if(!___namespace.find(tableFields, function(f){
5744
- return f.name === field.name
5745
- })){
5746
- i++;
5747
- tableFields.push(field);
5748
- }
5763
+ ___namespace.each(fieldsArr,function(field){
5764
+ if(!___namespace.find(tableFields, function(f){
5765
+ return f.name === field.name
5766
+ })){
5767
+ tableFields.push(field);
5749
5768
  }
5750
5769
  });
5751
5770
 
@@ -6065,8 +6084,8 @@ async function lookupToAmisPicker(field, readonly, ctx){
6065
6084
  modalTitle: i18next__default["default"].t('frontend_form_please_select') + " " + refObjectConfig.label,
6066
6085
  labelField: referenceTo.labelField.name,
6067
6086
  valueField: referenceTo.valueField.name,
6068
- // disabledOn: this._master目的是相关表新建时禁止编辑关联字段; this.relatedKey目的是相关表编辑时禁止编辑关联字段。
6069
- disabledOn: `${readonly} || ( (this._master && (this._master.relatedKey ==='${field.name}')) || (this.relatedKey ==='${field.name}') )`,
6087
+ // disabledOn: this._master目的是相关表新建时禁止编辑关联字段; this.relatedKey目的是相关表编辑时禁止编辑关联字段,多选字段可以编辑。
6088
+ disabledOn: `${readonly} || ( (this._master && (this._master.relatedKey ==='${field.name}')) || ((this.relatedKey ==='${field.name}') && (${field.multiple} != true)) )`,
6070
6089
  modalMode: 'dialog', //TODO 设置 dialog 或者 drawer,用来配置弹出方式
6071
6090
  source: source,
6072
6091
  size: "lg",
@@ -6132,10 +6151,7 @@ async function lookupToAmisSelect(field, readonly, ctx){
6132
6151
  }
6133
6152
 
6134
6153
  const refObjectConfig = referenceTo && await getUISchema(referenceTo.objectName);
6135
- const listView = refObjectConfig && ___namespace.find(
6136
- refObjectConfig.list_views,
6137
- (listView, name) => name === "all"
6138
- );
6154
+ let listView = getLookupListView(refObjectConfig);
6139
6155
 
6140
6156
  let sort = "";
6141
6157
  if(listView){
@@ -6246,8 +6262,8 @@ async function lookupToAmisSelect(field, readonly, ctx){
6246
6262
  joinValues: false,
6247
6263
  extractValue: true,
6248
6264
  clearable: true,
6249
- // disabledOn: this._master目的是相关表新建时禁止编辑关联字段; this.relatedKey目的是相关表编辑时禁止编辑关联字段。
6250
- disabledOn: `${readonly} || ( (this._master && (this._master.relatedKey ==='${field.name}')) || (this.relatedKey ==='${field.name}') )`,
6265
+ // disabledOn: this._master目的是相关表新建时禁止编辑关联字段; this.relatedKey目的是相关表编辑时禁止编辑关联字段,多选字段可以编辑。
6266
+ disabledOn: `${readonly} || ( (this._master && (this._master.relatedKey ==='${field.name}')) || ((this.relatedKey ==='${field.name}') && (${field.multiple} != true)) )`,
6251
6267
  // labelField: labelField,
6252
6268
  // valueField: valueField,
6253
6269
  source: apiInfo,
@@ -6370,7 +6386,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
6370
6386
 
6371
6387
  const tableFields = [referenceTo.labelField];
6372
6388
 
6373
- const source = await getApi$1(refObjectConfig, null, fields, {expand: true, alias: 'rows', queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}`});
6389
+ const source = await getApi$1(refObjectConfig, null, fields, {expand: true, alias: 'rows', queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
6374
6390
 
6375
6391
  source.data.$term = "$term";
6376
6392
  source.data.$self = "$$";
@@ -6379,6 +6395,12 @@ async function getIdsPickerSchema(field, readonly, ctx){
6379
6395
  source.sendOn = `\${${idsDependOn} && ${idsDependOn}.length}`;
6380
6396
  source.url = `${source.url}&depend_on_${idsDependOn}=\${${idsDependOn}|join}`;
6381
6397
  }
6398
+
6399
+ let listView = getLookupListView(refObjectConfig);
6400
+ let sort = "";
6401
+ if(listView){
6402
+ sort = getListViewSort(listView);
6403
+ }
6382
6404
 
6383
6405
  source.requestAdaptor = `
6384
6406
  const selfData = JSON.parse(JSON.stringify(api.data.$self));
@@ -6386,6 +6408,10 @@ async function getIdsPickerSchema(field, readonly, ctx){
6386
6408
  var pageSize = api.data.pageSize || 1000;
6387
6409
  var pageNo = api.data.pageNo || 1;
6388
6410
  var skip = (pageNo - 1) * pageSize;
6411
+ var orderBy = api.data.orderBy || '';
6412
+ var orderDir = api.data.orderDir || '';
6413
+ var sort = orderBy + ' ' + orderDir;
6414
+ sort = orderBy ? sort : "${sort}";
6389
6415
  if(selfData.op === 'loadOptions' && selfData.value){
6390
6416
  if(selfData.value && selfData.value.indexOf(',') > 0){
6391
6417
  filters = [["${referenceTo.valueField.name}", "=", selfData.value.split(',')]];
@@ -6403,7 +6429,7 @@ async function getIdsPickerSchema(field, readonly, ctx){
6403
6429
  filters.push(["${referenceTo.valueField.name}", "=", ids]);
6404
6430
  }
6405
6431
 
6406
- api.data.query = api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip);
6432
+ api.data.query = api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim());
6407
6433
  return api;
6408
6434
  `;
6409
6435
 
@@ -6434,8 +6460,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
6434
6460
  valueField: referenceTo.valueField.name,
6435
6461
  modalMode: 'dialog',
6436
6462
  source: source,
6437
- // disabledOn: this._master目的是相关表新建时禁止编辑关联字段; this.relatedKey目的是相关表编辑时禁止编辑关联字段。
6438
- disabledOn: `${readonly} || ( (this._master && (this._master.relatedKey ==='${field.name}')) || (this.relatedKey ==='${field.name}') )`,
6463
+ // disabledOn: this._master目的是相关表新建时禁止编辑关联字段; this.relatedKey目的是相关表编辑时禁止编辑关联字段,多选字段可以编辑。
6464
+ disabledOn: `${readonly} || ( (this._master && (this._master.relatedKey ==='${field.name}')) || ((this.relatedKey ==='${field.name}') && (${field.multiple} != true)) )`,
6439
6465
  size: "lg",
6440
6466
  pickerSchema: pickerSchema,
6441
6467
  joinValues: false,
@@ -8908,7 +8934,7 @@ async function getEditFormInitApi(object, recordId, fields, options){
8908
8934
  var defaultValues = {};
8909
8935
  _.each(uiSchema && uiSchema.fields, function(field){
8910
8936
  var value = SteedosUI.getFieldDefaultValue(field, api.body.global);
8911
- if(value){
8937
+ if(!_.isNil(value)){
8912
8938
  defaultValues[field.name] = value;
8913
8939
  }
8914
8940
  });
@@ -9566,14 +9592,15 @@ async function getObjectCalendar(objectSchema, calendarOptions, options) {
9566
9592
  /*
9567
9593
  * @Author: baozhoutao@steedos.com
9568
9594
  * @Date: 2022-05-26 16:02:08
9569
- * @LastEditors: liaodaxue
9570
- * @LastEditTime: 2023-07-12 15:45:55
9595
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
9596
+ * @LastEditTime: 2023-09-05 15:42:26
9571
9597
  * @Description:
9572
9598
  */
9573
9599
 
9574
- const getFieldSchemaArray = (formFields) => {
9600
+ const getFieldSchemaArray = (formFields, ctx) => {
9575
9601
  let fieldSchemaArray = [];
9576
9602
  fieldSchemaArray.length = 0;
9603
+ const recordId = ctx && ctx.recordId;
9577
9604
 
9578
9605
  ___namespace.forEach(formFields, (field) => {
9579
9606
  if (!field.group || field.group == 'null' || field.group == '-')
@@ -9585,8 +9612,14 @@ const getFieldSchemaArray = (formFields) => {
9585
9612
  field.is_wide = true;
9586
9613
  }
9587
9614
 
9615
+ let forceHidden = false;
9616
+ if(!recordId && field.readonly){
9617
+ // 新建记录时,只读字段先隐藏,后续支持显示后,即任务:https://github.com/steedos/steedos-platform/issues/3164 完成后再放开
9618
+ forceHidden = true;
9619
+ }
9620
+
9588
9621
  if (!isObjectField) {
9589
- if (!field.hidden) {
9622
+ if (!field.hidden && !forceHidden) {
9590
9623
  fieldSchemaArray.push(Object.assign({ name: fieldName }, field, { permission: { allowEdit: true } }));
9591
9624
  }
9592
9625
  }
@@ -9657,7 +9690,7 @@ const getSections = async (permissionFields, formFields, ctx) => {
9657
9690
  if (!ctx) {
9658
9691
  ctx = {};
9659
9692
  }
9660
- const fieldSchemaArray = getFieldSchemaArray(formFields);
9693
+ const fieldSchemaArray = getFieldSchemaArray(formFields, ctx);
9661
9694
  const _sections = ___namespace.groupBy(fieldSchemaArray, 'group');
9662
9695
  const sections = [];
9663
9696
  var sectionVisibleOns = [];