@steedos-widgets/amis-lib 1.3.4-beta.5 → 1.3.4-beta.7

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
@@ -479,39 +479,39 @@ function getCreatedInfoTpl(formFactor){
479
479
  const href = Router.getObjectDetailPath({
480
480
  formFactor, appId: "admin", objectName: 'users', recordId: '${created_by._id}'
481
481
  });
482
- return `<div><a href='${href}'>\${_display.created_by.label}</a>\${_display.created}</div>`
482
+ return `<span><a href='${href}'>\${_display.created_by.label}</a>\${_display.created}</span>`
483
483
  }
484
484
 
485
485
  function getModifiedInfoTpl(formFactor){
486
486
  const href = Router.getObjectDetailPath({
487
487
  formFactor, appId: "admin", objectName: 'users', recordId: '${modified_by._id}'
488
488
  });
489
- return `<div><a href='${href}'>\${_display.modified_by.label}</a>\${_display.modified}</div>`
489
+ return `<span><a href='${href}'>\${_display.modified_by.label}</a>\${_display.modified}</span>`
490
490
  }
491
491
 
492
492
  function getNumberTpl(field){
493
- return `<div>\${_display.${field.name}}</div>`
493
+ return `<span>\${_display.${field.name}}</span>`
494
494
  }
495
495
 
496
496
  function getTimeTpl(field){
497
- return `<div>\${_display.${field.name}}</div>`
497
+ return `<span>\${_display.${field.name}}</span>`
498
498
  }
499
499
 
500
500
  function getDateTpl(field){
501
- return `<div>\${_display.${field.name}}</div>`
501
+ return `<span>\${_display.${field.name}}</span>`
502
502
  }
503
503
 
504
504
 
505
505
  function getDateTimeTpl(field){
506
- return `<div>\${_display.${field.name}}</div>`
506
+ return `<span>\${_display.${field.name}}</span>`
507
507
  }
508
508
 
509
509
  function getUiFieldTpl(field){
510
- return `<div>\${_display.${field.name}}</div>`
510
+ return `<span>\${_display.${field.name}}</span>`
511
511
  }
512
512
 
513
513
  function getUiFileSizeTpl(field){
514
- return `<div>\${_display.${field.name}}</div>`
514
+ return `<span>\${_display.${field.name}}</span>`
515
515
  }
516
516
 
517
517
  //TODO 处理name字段
@@ -522,7 +522,7 @@ async function getRefObjectNameFieldName(field){
522
522
  }
523
523
 
524
524
  function getSelectTpl(field){
525
- return `<div>\${_display.${field.name}}</div>`
525
+ return `<span>\${_display.${field.name}}</span>`
526
526
  }
527
527
  function getSelectMap(selectOptions){
528
528
  let map = {};
@@ -1857,7 +1857,7 @@ const parseSingleExpression = function (func, formData, dataPath, global, userSe
1857
1857
  * @Author: baozhoutao@steedos.com
1858
1858
  * @Date: 2022-11-01 15:51:00
1859
1859
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
1860
- * @LastEditTime: 2023-06-28 23:19:41
1860
+ * @LastEditTime: 2023-09-25 14:53:05
1861
1861
  * @Description:
1862
1862
  */
1863
1863
 
@@ -1876,18 +1876,31 @@ const getSchema$5 = async (uiSchema, ctx) => {
1876
1876
  formSchema = _.isString(payload.schema) ? JSON.parse(payload.schema) : payload.schema;
1877
1877
  }
1878
1878
 
1879
+ const fields = ${JSON.stringify(uiSchema.fields)};
1880
+ const selectedRowResponseResult = api.body.selectedRowResponseResult;
1881
+ let defaultData = {};
1882
+
1883
+ if(!_.isEmpty(selectedRowResponseResult)){
1884
+ const fieldsKeys = _.keys(fields);
1885
+ // 如果新建记录时复制的数据中有omit或其他不相关字段数据时不应该一起保存到数据库,
1886
+ // 原规则见:https://github.com/steedos/steedos-frontend/issues/297
1887
+ _.forEach(selectedRowResponseResult, (val, key) => {
1888
+ if (fieldsKeys.indexOf(key) > -1 && fields[key].omit !== true) {
1889
+ defaultData[key] = val;
1890
+ }
1891
+ })
1892
+ }
1893
+
1879
1894
  const _master = api.body._master;
1880
1895
  if(_master && _master._isRelated){
1881
1896
  const relatedKey = _master.relatedKey;
1882
1897
  const masterObjectName = _master.objectName;
1883
1898
  const recordId = _master.recordId;
1884
1899
  let relatedKeySaveValue = recordId;
1885
- const fields = ${JSON.stringify(uiSchema.fields)};
1886
1900
  const relatedField = fields[relatedKey];
1887
1901
  if(relatedField.reference_to_field && relatedField.reference_to_field !== '_id'){
1888
1902
  relatedKeySaveValue = _master.record[relatedField.reference_to_field];
1889
1903
  }
1890
- let defaultData = {};
1891
1904
  let relatedKeyValue;
1892
1905
  if(!_.isString(relatedField.reference_to)){
1893
1906
  relatedKeyValue = { o: masterObjectName, ids: [relatedKeySaveValue] };
@@ -1897,6 +1910,9 @@ const getSchema$5 = async (uiSchema, ctx) => {
1897
1910
  relatedKeyValue = relatedKeySaveValue;
1898
1911
  }
1899
1912
  defaultData[relatedKey]=relatedKeyValue;
1913
+ }
1914
+
1915
+ if(!_.isEmpty(defaultData)){
1900
1916
  if(payload.schema){
1901
1917
  // 表单微页面第一层要求是page
1902
1918
  formSchema.data.defaultData = defaultData;
@@ -1919,6 +1935,18 @@ const getSchema$5 = async (uiSchema, ctx) => {
1919
1935
  });
1920
1936
  }, 200);
1921
1937
  `;
1938
+ const getSelectedRowsScript = `
1939
+ const isLookup = event.data.isLookup;
1940
+ if(isLookup){
1941
+ // lookup弹出窗口的新建功能不需要支持复制新建
1942
+ return;
1943
+ }
1944
+ const uiSchema = event.data.uiSchema;
1945
+ const objectName = event.data.objectName;
1946
+ const listViewRef = event.context.scoped.getComponentById("listview_" + objectName);
1947
+ const selectedItems = listViewRef && listViewRef.props.store.toJSON().selectedItems || [];
1948
+ event.data.selectedIds = _.map(selectedItems, uiSchema.idFieldName || '_id');
1949
+ `;
1922
1950
  return {
1923
1951
  "type": "service",
1924
1952
  "body": [
@@ -1931,6 +1959,21 @@ const getSchema$5 = async (uiSchema, ctx) => {
1931
1959
  "click": {
1932
1960
  "weight": 0,
1933
1961
  "actions": [
1962
+ {
1963
+ "actionType": "custom",
1964
+ "script": getSelectedRowsScript
1965
+ },
1966
+ {
1967
+ "actionType": "ajax",
1968
+ "outputVar": "selectedRowResponseResult",
1969
+ "args": {
1970
+ "api": {
1971
+ "url": "${context.rootUrl}/api/v1/${uiSchema.name}/${selectedIds|first}",
1972
+ "method": "get"
1973
+ }
1974
+ },
1975
+ "expression": "${selectedIds.length > 0}"
1976
+ },
1934
1977
  {
1935
1978
  "actionType": "dialog",
1936
1979
  "dialog": {
@@ -1948,7 +1991,8 @@ const getSchema$5 = async (uiSchema, ctx) => {
1948
1991
  "displayAs": "${displayAs}",
1949
1992
  "uiSchema": "${uiSchema}",
1950
1993
  "isLookup": "${isLookup}",
1951
- "listName": "${listName}"
1994
+ "listName": "${listName}",
1995
+ "selectedRowResponseResult": "${selectedRowResponseResult}",
1952
1996
  },
1953
1997
  "title":i18next__default["default"].t('frontend_form_new') + " ${uiSchema.label | raw}",
1954
1998
  "body": [
@@ -1960,7 +2004,8 @@ const getSchema$5 = async (uiSchema, ctx) => {
1960
2004
  "data": {
1961
2005
  "isLookup": "${isLookup}",
1962
2006
  "_master": "${_master}",
1963
- "url": "${context.rootUrl}/api/pageSchema/form?app=${appId}&objectApiName=${objectName}&formFactor=${formFactor}"
2007
+ "url": "${context.rootUrl}/api/pageSchema/form?app=${appId}&objectApiName=${objectName}&formFactor=${formFactor}",
2008
+ "selectedRowResponseResult": "${selectedRowResponseResult}"
1964
2009
  },
1965
2010
  "url": "${context.rootUrl}/api/pageSchema/form?app=${appId}&objectApiName=${objectName}&formFactor=${formFactor}",
1966
2011
  "method": "get",
@@ -10203,17 +10248,26 @@ async function getObjectCRUD(objectSchema, fields, options){
10203
10248
  Authorization: "Bearer ${context.tenantId},${context.authToken}",
10204
10249
  },
10205
10250
  requestAdaptor: quickSaveApiRequestAdaptor,
10251
+ adaptor: `
10252
+ if(payload.errors){
10253
+ payload.status = 2;
10254
+ payload.msg = window.t ? window.t(payload.errors[0].message) : payload.errors[0].message;
10255
+ }
10256
+ return payload;
10257
+ `
10206
10258
  },
10207
10259
  rowClassNameExpr: options.rowClassNameExpr
10208
10260
  }, bodyProps);
10209
10261
 
10210
- body = await getCrudSchemaWithDataFilter(body, { crudDataFilter, onCrudDataFilter, amisData, env });
10211
10262
  }
10212
10263
 
10213
10264
  const defaults = options.defaults;
10265
+
10266
+ const listSchema = (defaults && defaults.listSchema) || {};
10267
+ body = defaultsDeep({}, listSchema, body);
10268
+ body = await getCrudSchemaWithDataFilter(body, { crudDataFilter, onCrudDataFilter, amisData, env });
10269
+
10214
10270
  if (defaults) {
10215
- const listSchema = defaults.listSchema || {};
10216
- body = defaultsDeep({}, listSchema, body);
10217
10271
  const headerSchema = defaults.headerSchema;
10218
10272
  const footerSchema = defaults.footerSchema;
10219
10273
  if (headerSchema || footerSchema) {
@@ -10545,7 +10599,7 @@ const getRecordPermissions = async (objectName, recordId)=>{
10545
10599
  * @Author: baozhoutao@steedos.com
10546
10600
  * @Date: 2022-07-05 15:55:39
10547
10601
  * @LastEditors: liaodaxue
10548
- * @LastEditTime: 2023-08-28 14:55:23
10602
+ * @LastEditTime: 2023-09-25 17:18:08
10549
10603
  * @Description:
10550
10604
  */
10551
10605
 
@@ -10721,6 +10775,7 @@ async function getRecordDetailRelatedListSchema(objectName, recordId, relatedObj
10721
10775
  // tableHiddenOn: hiddenEmptyTable ? "this.$count === 0" : null,
10722
10776
  appId: appId,
10723
10777
  crudClassName: 'border-t border-gray-300 hidden',
10778
+ refField,
10724
10779
  ...ctx
10725
10780
  };
10726
10781
  const amisSchema= (await getRelatedListSchema(relatedObjectName, 'all', options)).amisSchema;
@@ -10835,10 +10890,33 @@ async function getRelatedListSchema(
10835
10890
  ctx
10836
10891
  ) {
10837
10892
  const uiSchema = await getUISchema(objectName);
10838
- const listView = uiSchema.list_views;
10893
+ const listView = _$1.find(
10894
+ uiSchema.list_views,
10895
+ (listView, name) => {
10896
+ // 传入listViewName空值则取第一个
10897
+ if(!listViewName){
10898
+ listViewName = name;
10899
+ }
10900
+ return name === listViewName || listView._id === listViewName;
10901
+ }
10902
+ );
10839
10903
  const listViewProps = getRelatedListProps(uiSchema,listViewName, ctx);
10840
10904
  // console.log('listViewProps==>', listViewProps)
10841
10905
  const {columns: listViewColumns, sort: listViewSort, filter: listviewFilter, filtersFunction } = listViewProps;
10906
+
10907
+ const refFieldName = ctx.refField && ctx.refField.name;
10908
+
10909
+ let relatedListColumns = listViewColumns;
10910
+ if(refFieldName){
10911
+ relatedListColumns = listViewColumns.filter(function(columnItem){
10912
+ if(typeof columnItem === "string"){
10913
+ return columnItem !== refFieldName;
10914
+ }
10915
+ else {
10916
+ return columnItem.field !== refFieldName;
10917
+ }
10918
+ });
10919
+ }
10842
10920
 
10843
10921
  const defaults = ctx.defaults || {};
10844
10922
 
@@ -10876,7 +10954,7 @@ async function getRelatedListSchema(
10876
10954
  const amisSchema = {
10877
10955
  "type": "steedos-object-table",
10878
10956
  "objectApiName": objectName,
10879
- "columns": listViewColumns,
10957
+ "columns": relatedListColumns,
10880
10958
  "extraColumns": listView.extra_columns,
10881
10959
  "filters": listviewFilter,
10882
10960
  "filtersFunction": filtersFunction,