@steedos-widgets/amis-lib 1.1.6 → 1.1.8

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
@@ -1,7 +1,7 @@
1
1
  import * as _$1 from 'lodash';
2
2
  import ___default, { isEmpty, isArray, each, find, endsWith, cloneDeep, includes, get, map, keys, sortBy, compact, toArray, mergeWith, isBoolean, omitBy, isNil, isString, slice, defaultsDeep as defaultsDeep$1, isObject as isObject$1, has, filter, startsWith } from 'lodash';
3
- import isPlainObject from 'lodash/isPlainObject';
4
3
  import { Router as Router$1, getSteedosAuth as getSteedosAuth$1, lookupToAmis as lookupToAmis$1, fetchAPI as fetchAPI$1 } from '@steedos-widgets/amis-lib';
4
+ import isPlainObject from 'lodash/isPlainObject';
5
5
 
6
6
  /*
7
7
  * @Author: baozhoutao@steedos.com
@@ -1548,8 +1548,8 @@ const getSchema$3 = async (uiSchema, ctx) => {
1548
1548
  /*
1549
1549
  * @Author: 殷亮辉 yinlianghui@hotoa.com
1550
1550
  * @Date: 2023-03-22 09:31:21
1551
- * @LastEditors: Please set LastEditors
1552
- * @LastEditTime: 2023-03-28 14:06:47
1551
+ * @LastEditors: baozhoutao@steedos.com
1552
+ * @LastEditTime: 2023-04-06 16:04:20
1553
1553
  */
1554
1554
  const getSchema$2 = (uiSchema)=>{
1555
1555
  return {
@@ -1579,15 +1579,11 @@ const getSchema$2 = (uiSchema)=>{
1579
1579
  },
1580
1580
  "adaptor": `
1581
1581
  if(payload.errors){
1582
- payload.status = 2;
1583
- payload.msg = payload.errors[0].message;
1582
+ payload.status = 2;
1583
+ payload.msg = window.t ? window.t(payload.errors[0].message) : payload.errors[0].message;
1584
1584
  }
1585
1585
  return payload;
1586
1586
  `,
1587
- },
1588
- "messages": {
1589
- "success": "删除成功",
1590
- "failed": "删除失败"
1591
1587
  }
1592
1588
  },
1593
1589
  "actionType": "ajax"
@@ -3294,17 +3290,22 @@ async function getObjectRecordDetailRelatedListHeader(relatedObjectSchema, relat
3294
3290
  async function getObjectRelatedListHeader(objectSchema, recordId, relatedObjectName) {
3295
3291
  }
3296
3292
 
3297
- const getDisplayAsButton = function(showDisplayAs){
3293
+ const getDisplayAsButton = function(objectName, showDisplayAs){
3294
+ let displayAs = Router$1.getTabDisplayAs(objectName);
3298
3295
  let buttons = [
3299
3296
  {
3300
3297
  "type": "button",
3301
3298
  "label": "表格",
3302
- "onClick": "const url = document.location.pathname + '?display=grid'; props.env.jumpTo(url);"
3299
+ "onClick": "let url = document.location.pathname; var urlSearch = new URLSearchParams(document.location.search); if(urlSearch.get(\"side_object\") && urlSearch.get(\"side_listview_id\")){url=`/app/${props.data.appId}/${urlSearch.get(\"side_object\")}/grid/${urlSearch.get(\"side_listview_id\")}`;}; props.env.jumpTo(url + '?display=grid');",
3300
+ "rightIcon": displayAs != 'split' ? "fa fa-check" : null,
3301
+ "rightIconClassName": "m-l-sm"
3303
3302
  },
3304
3303
  {
3305
3304
  "type": "button",
3306
3305
  "label": "分栏视图",
3307
- "onClick": "const url = document.location.pathname + '?display=split'; props.env.jumpTo(url);"
3306
+ "onClick": "const url = document.location.pathname + '?display=split'; props.env.jumpTo(url);",
3307
+ "rightIcon": displayAs === 'split' ? "fa fa-check" : null,
3308
+ "rightIconClassName": "m-l-sm"
3308
3309
  }
3309
3310
  ];
3310
3311
  return {
@@ -3392,7 +3393,7 @@ function getExportApiRequestAdaptorScript(){
3392
3393
  `
3393
3394
  }
3394
3395
 
3395
- function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false, hiddenCount = false} = {}){
3396
+ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false, hiddenCount = false, headerToolbarItems} = {}){
3396
3397
  const isMobile = window.innerWidth < 768;
3397
3398
  if(isMobile){
3398
3399
  showDisplayAs = false;
@@ -3446,11 +3447,12 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3446
3447
  }
3447
3448
  }
3448
3449
  },
3449
- showDisplayAs? getDisplayAsButton() : {}
3450
+ showDisplayAs? getDisplayAsButton(mainObject?.name) : {}
3450
3451
  ]
3451
3452
  }else {
3452
3453
  return [
3453
3454
  // "filter-toggler",
3455
+ ...(headerToolbarItems || []),
3454
3456
  "bulkActions",
3455
3457
  {
3456
3458
  "type": "columns-toggler",
@@ -3526,7 +3528,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3526
3528
  }
3527
3529
  }
3528
3530
  },
3529
- showDisplayAs? getDisplayAsButton() : {}
3531
+ showDisplayAs? getDisplayAsButton(showDisplayAs) : {}
3530
3532
  // {
3531
3533
  // "type": "search-box",
3532
3534
  // "align": "right",
@@ -4118,20 +4120,20 @@ async function lookupToAmisSelect(field, readonly, ctx){
4118
4120
 
4119
4121
  if(referenceTo){
4120
4122
  // 字段值单独走一个请求合并到source的同一个GraphQL接口中
4121
- const defaultValueOptionsQueryData = await getFindQuery({ name: referenceTo.objectName }, null, {
4122
- [referenceTo.labelField.name]: Object.assign({}, referenceTo.labelField, {alias: 'label'}),
4123
- [referenceTo.valueField.name]: Object.assign({}, referenceTo.valueField, {alias: 'value'})
4124
- }, {
4123
+ const defaultValueOptionsQueryData = await getFindQuery({ name: referenceTo.objectName }, null, [
4124
+ Object.assign({}, referenceTo.labelField, {alias: 'label'}),
4125
+ Object.assign({}, referenceTo.valueField, {alias: 'value'})
4126
+ ], {
4125
4127
  alias: "defaultValueOptions",
4126
4128
  filters: "{__options_filters}",
4127
4129
  count: false
4128
4130
  });
4129
4131
  apiInfo = await getApi$1({
4130
4132
  name: referenceTo.objectName
4131
- }, null, {
4132
- [referenceTo.labelField.name]: Object.assign({}, referenceTo.labelField, {alias: 'label'}),
4133
- [referenceTo.valueField.name]: Object.assign({}, referenceTo.valueField, {alias: 'value'})
4134
- }, {expand: false, alias: 'options', queryOptions: `filters: {__filters}, top: {__top}, sort: "{__sort}"`, moreQueries: [defaultValueOptionsQueryData.query]});
4133
+ }, null, [
4134
+ Object.assign({}, referenceTo.labelField, {alias: 'label'}),
4135
+ Object.assign({}, referenceTo.valueField, {alias: 'value'})
4136
+ ], {expand: false, alias: 'options', queryOptions: `filters: {__filters}, top: {__top}, sort: "{__sort}"`, moreQueries: [defaultValueOptionsQueryData.query]});
4135
4137
 
4136
4138
  apiInfo.adaptor = `
4137
4139
  const data = payload.data;
@@ -4947,13 +4949,19 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
4947
4949
  };
4948
4950
  break;
4949
4951
  case 'percent':
4950
- //TODO
4951
- convertData = {
4952
- type: getAmisStaticFieldType('number', readonly),
4953
- min: field.min,
4954
- max: field.max,
4955
- precision: field.scale
4956
- };
4952
+ if(readonly){
4953
+ convertData = {
4954
+ type: 'static-tpl',
4955
+ tpl: getUiFieldTpl(field)
4956
+ };
4957
+ }else {
4958
+ convertData = {
4959
+ type: getAmisStaticFieldType('number', readonly),
4960
+ min: field.min,
4961
+ max: field.max,
4962
+ precision: field.scale
4963
+ };
4964
+ }
4957
4965
  break;
4958
4966
  case 'password':
4959
4967
  convertData = {
@@ -4995,12 +5003,18 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
4995
5003
  break;
4996
5004
  case 'formula':
4997
5005
  if(readonly){
4998
- convertData.type = getAmisStaticFieldType(field.data_type, readonly);
5006
+ convertData = {
5007
+ type: 'static-tpl',
5008
+ tpl: getUiFieldTpl(field)
5009
+ };
4999
5010
  }
5000
5011
  break;
5001
5012
  case 'summary':
5002
5013
  if(readonly){
5003
- convertData.type = getAmisStaticFieldType(field.data_type, readonly);
5014
+ convertData = {
5015
+ type: 'static-tpl',
5016
+ tpl: getUiFieldTpl(field)
5017
+ };
5004
5018
  }
5005
5019
  break;
5006
5020
  case 'code':
@@ -5713,7 +5727,11 @@ async function getObjectCRUD(objectSchema, fields, options){
5713
5727
  }
5714
5728
  }
5715
5729
 
5716
- bodyProps.headerToolbar = getObjectHeaderToolbar(objectSchema, options.formFactor, {showDisplayAs, hiddenCount: options.queryCount === false});
5730
+ bodyProps.headerToolbar = getObjectHeaderToolbar(objectSchema, options.formFactor, {
5731
+ showDisplayAs,
5732
+ hiddenCount: options.queryCount === false,
5733
+ headerToolbarItems: options.headerToolbarItems
5734
+ });
5717
5735
 
5718
5736
 
5719
5737
  let body = null;
@@ -5752,7 +5770,7 @@ async function getObjectCRUD(objectSchema, fields, options){
5752
5770
  keepItemSelectionOnPageChange: true,
5753
5771
  api: await getTableApi(objectSchema, fields, options),
5754
5772
  hiddenOn: options.tableHiddenOn,
5755
- autoFillHeight: true,
5773
+ autoFillHeight: options.isRelated ? false : true,
5756
5774
  className: `flex-auto ${crudClassName || ""}`,
5757
5775
  crudClassName: crudClassName,
5758
5776
  },
@@ -5912,6 +5930,10 @@ async function getObjectForm(objectSchema, ctx){
5912
5930
  "objectName": "${_master.objectName}"
5913
5931
  },
5914
5932
  "expression": `\${_master.objectName != '${objectSchema.name}' && _master.objectName}`
5933
+ },
5934
+ {
5935
+ "args": {},
5936
+ "actionType": "closeDialog"
5915
5937
  }
5916
5938
  ]
5917
5939
  }
@@ -7947,7 +7969,8 @@ async function getListSchema(
7947
7969
  "sort": sort,
7948
7970
  "ctx": ctx,
7949
7971
  "requestAdaptor": listView.requestAdaptor,
7950
- "adaptor": listView.adaptor
7972
+ "adaptor": listView.adaptor,
7973
+ "headerToolbarItems": ctx.headerToolbarItems
7951
7974
  };
7952
7975
  return {
7953
7976
  uiSchema,
@@ -8008,6 +8031,7 @@ async function getTableSchema(
8008
8031
  ...ctx,
8009
8032
  filter: ctx.filters,
8010
8033
  sort,
8034
+ headerToolbarItems: ctx.headerToolbarItems,
8011
8035
  buttons: await getListViewItemButtons(uiSchema, ctx)
8012
8036
  });
8013
8037
  return {