@steedos-widgets/amis-lib 1.2.1 → 1.2.3-beta.1

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
@@ -361,14 +361,19 @@ const getSteedosAuth = () => {
361
361
  * @Author: baozhoutao@steedos.com
362
362
  * @Date: 2022-08-16 17:02:08
363
363
  * @LastEditors: baozhoutao@steedos.com
364
- * @LastEditTime: 2023-04-11 09:57:37
364
+ * @LastEditTime: 2023-04-17 15:24:21
365
365
  * @Description:
366
366
  */
367
367
 
368
368
 
369
369
  const Router = {
370
370
  getTabDisplayAs(tab_id){
371
- const key = `tab.${tab_id}.display`;
371
+ var urlSearch = new URLSearchParams(document.location.search);
372
+ if(urlSearch.has('display')){
373
+ return urlSearch.get('display')
374
+ }
375
+ // const key = `tab.${tab_id}.display`;
376
+ const key = `page.display`;
372
377
  const value = localStorage.getItem(key);
373
378
  return value ? value : 'grid'
374
379
  },
@@ -1390,8 +1395,8 @@ var config = {
1390
1395
  /*
1391
1396
  * @Author: baozhoutao@steedos.com
1392
1397
  * @Date: 2022-11-01 15:51:00
1393
- * @LastEditors: Please set LastEditors
1394
- * @LastEditTime: 2023-04-11 13:58:24
1398
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
1399
+ * @LastEditTime: 2023-04-16 17:04:16
1395
1400
  * @Description:
1396
1401
  */
1397
1402
 
@@ -1469,6 +1474,7 @@ const getSchema$4 = async (uiSchema, ctx) => {
1469
1474
  "context": "${context}",
1470
1475
  "global": "${global}",
1471
1476
  "listViewId": "${listViewId}",
1477
+ "displayAs": "${displayAs}",
1472
1478
  "uiSchema": "${uiSchema}",
1473
1479
  "isLookup": "${isLookup}",
1474
1480
  "listName": "${listName}"
@@ -2854,7 +2860,6 @@ async function getObjectFieldsFilterBarSchema(objectSchema, fields, ctx) {
2854
2860
  function getObjectListHeaderFirstLine(objectSchema, listViewName, ctx) {
2855
2861
  const { icon, label } = objectSchema;
2856
2862
  const listViewButtonOptions = [];
2857
- // let currentListView;
2858
2863
  _$1.each(
2859
2864
  objectSchema.list_views,
2860
2865
  (listView, name) => {
@@ -2862,19 +2867,11 @@ function getObjectListHeaderFirstLine(objectSchema, listViewName, ctx) {
2862
2867
  type: "button",
2863
2868
  label: listView.label,
2864
2869
  actionType: "link",
2865
- // icon: "fa fa-plus",
2866
2870
  link: `/app/\${appId}/${objectSchema.name}/grid/${name}`
2867
2871
  });
2868
- // if(name === listViewName){
2869
- // currentListView = listView;
2870
- // }
2871
2872
  }
2872
2873
  );
2873
2874
 
2874
- // if(!currentListView){
2875
- // return {};
2876
- // }
2877
-
2878
2875
  const buttons = getListViewButtons(objectSchema, {});
2879
2876
  let amisButtonsSchema = _$1.map(buttons, (button) => {
2880
2877
  return {
@@ -2885,34 +2882,7 @@ function getObjectListHeaderFirstLine(objectSchema, listViewName, ctx) {
2885
2882
  className: `button_${button.name}`
2886
2883
  }
2887
2884
  });
2888
- // if(objectSchema.permissions?.allowDelete){
2889
- // const bulkDeleteScript = `
2890
- // const data = event.data;
2891
- // const listViewId = data.listViewId;
2892
- // const uiSchema = data.uiSchema;
2893
- // const scopeId = data.scopeId;
2894
- // BuilderAmisObject.AmisLib.standardButtonsTodo.standard_delete_many.call({
2895
- // listViewId,
2896
- // uiSchema,
2897
- // scopeId
2898
- // })
2899
- // `;
2900
- // amisButtonsSchema.push({
2901
- // type: 'button',
2902
- // label: "删除",
2903
- // className: `antd-Button antd-Button--default antd-Button--size-default`,
2904
- // "onEvent": {
2905
- // "click": {
2906
- // "actions": [
2907
- // {
2908
- // "actionType": "custom",
2909
- // "script": bulkDeleteScript
2910
- // }
2911
- // ]
2912
- // }
2913
- // }
2914
- // });
2915
- // }
2885
+
2916
2886
  const reg = new RegExp('_', 'g');
2917
2887
  const standardIcon = icon && icon.replace(reg, '-');
2918
2888
  return {
@@ -3102,27 +3072,14 @@ async function getObjectListHeaderFieldsFilterBar(objectSchema, listViewName, ct
3102
3072
  * @param {*} objectSchema 对象UISchema
3103
3073
  * @returns amisSchema
3104
3074
  */
3105
- async function getObjectListHeader$1(objectSchema, listViewName, ctx) {
3075
+ function getObjectListHeader$1(objectSchema, listViewName, ctx) {
3106
3076
  let firstLineSchema = getObjectListHeaderFirstLine(objectSchema);
3107
- // let secordLineSchema = await getObjectListHeaderSecordLine(objectSchema, listViewName, ctx);
3108
- // let body = [firstLineSchema, secordLineSchema];
3109
3077
  let body = [firstLineSchema];
3110
- // let roundedCss = "";
3111
- // if (ctx.onlyFirstLine) {
3112
- // body = [firstLineSchema];
3113
- // }
3114
- // else if (ctx.onlySecordLine) {
3115
- // // 列表视图自定义amisSchema时不能加圆角
3116
- // roundedCss = "";
3117
- // // body = [secordLineSchema];
3118
- // }
3119
3078
  let headerSchema = [{
3120
3079
  "type": "wrapper",
3121
3080
  "body": body,
3122
3081
  "className": `bg-gray-100 sm:rounded-tl sm:rounded-tr p-4 -mb-4`
3123
3082
  }];
3124
- // const fieldsFilterBarSchema = await getObjectListHeaderFieldsFilterBar(objectSchema, listViewName, ctx);
3125
- // headerSchema.push(fieldsFilterBarSchema);
3126
3083
  return headerSchema;
3127
3084
  }
3128
3085
 
@@ -3376,6 +3333,7 @@ const getDisplayAsButton = function(objectName, showDisplayAs){
3376
3333
  "icon": "fa fa-table-columns",
3377
3334
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
3378
3335
  "align": "right",
3336
+ "visibleOn": "${formFactor !== 'SMALL'}",
3379
3337
  "buttons": [
3380
3338
  {
3381
3339
  "label": "显示为",
@@ -3512,7 +3470,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3512
3470
  }
3513
3471
  }
3514
3472
  } : {},
3515
- showDisplayAs? getDisplayAsButton(mainObject?.name) : {}
3473
+ getDisplayAsButton(mainObject?.name)
3516
3474
  ]
3517
3475
  }else {
3518
3476
  return [
@@ -3767,7 +3725,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3767
3725
  {
3768
3726
  "type": "button",
3769
3727
  "label": "重命名",
3770
- "visibleOn": "(global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && ['all', 'recent', 'my'].indexOf(listName) == -1",
3728
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
3771
3729
  "onEvent": {
3772
3730
  "click": {
3773
3731
  "weight": 0,
@@ -3822,7 +3780,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3822
3780
  {
3823
3781
  "type": "button",
3824
3782
  "label": "共享设置",
3825
- "visibleOn": "global.user.is_space_admin && ['all', 'recent', 'my'].indexOf(listName) == -1",
3783
+ "disabledOn": "!(global.user.is_space_admin && !!uiSchema.list_views[listName].owner)",
3826
3784
  "onEvent": {
3827
3785
  "click": {
3828
3786
  "weight": 0,
@@ -3862,7 +3820,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3862
3820
  {
3863
3821
  "type": "button",
3864
3822
  "label": "过滤设置",
3865
- "visibleOn": "(global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && ['all', 'recent', 'my'].indexOf(listName) == -1",
3823
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
3866
3824
  "onEvent": {
3867
3825
  "click": {
3868
3826
  "weight": 0,
@@ -3924,7 +3882,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3924
3882
  {
3925
3883
  "type": "button",
3926
3884
  "label": "显示的列",
3927
- "visibleOn": "(global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && ['all', 'recent', 'my'].indexOf(listName) == -1",
3885
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
3928
3886
  "onEvent": {
3929
3887
  "click": {
3930
3888
  "weight": 0,
@@ -3983,10 +3941,74 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3983
3941
  }
3984
3942
  }
3985
3943
  },
3944
+ {
3945
+ "type": "button",
3946
+ "label": "默认排序规则",
3947
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
3948
+ "onEvent": {
3949
+ "click": {
3950
+ "weight": 0,
3951
+ "actions": [
3952
+ {
3953
+ "dialog": {
3954
+ "type": "dialog",
3955
+ "title": "弹框标题",
3956
+ "data": {
3957
+ "&": "$$",
3958
+ "objectName": "${objectName}",
3959
+ "recordId": "${uiSchema.list_views[listName]._id}",
3960
+ "listName": "${listName}",
3961
+ "appId": "${appId}"
3962
+ },
3963
+ "body": [
3964
+ {
3965
+ "type": "steedos-object-form",
3966
+ "label": "对象表单",
3967
+ "objectApiName": "object_listviews",
3968
+ "recordId": "${recordId}",
3969
+ "className": "",
3970
+ "id": "u:061f158b4c5a",
3971
+ "mode": "edit",
3972
+ "fields": [
3973
+ "sort",
3974
+ "sort.$.field_name",
3975
+ "sort.$.order"
3976
+ ],
3977
+ "onEvent": {
3978
+ "submitSucc": {
3979
+ "weight": 0,
3980
+ "actions": [
3981
+ {
3982
+ "args": {
3983
+ "url": "${context.rootUrl}/app/${appId}/${objectName}/grid/${listName}",
3984
+ "blank": false
3985
+ },
3986
+ "actionType": "url"
3987
+ }
3988
+ ]
3989
+ }
3990
+ },
3991
+ "fieldsExtend": "{\n \"sort\": {\n \"amis\": {\n \"type\": \"tabs-transfer\",\n \"sortable\": true,\n \"searchable\": true,\n \"source\": {\n \"method\": \"get\",\n \"url\": \"${context.rootUrl}/service/api/amis-metadata-objects/objects/${objectName}/sortFields/options\",\n \"headers\": {\n \"Authorization\": \"Bearer ${context.tenantId},${context.authToken}\"\n }\n }\n }\n }\n}",
3992
+ "initApiAdaptor": "let sort;\nif (recordId) {\n sort = payload.data.initialValues.sort;\n //数据格式转换\n if (sort instanceof Array) {\n sort = lodash.map(sort, (item) => {\n return item.field_name + ':' + (item.order || 'asc')\n });\n }\n}\npayload.data.initialValues.sort = sort;\ndelete payload.extensions;",
3993
+ "apiRequestAdaptor": "const recordId = api.body.recordId;\n//数据格式转换\nif (typeof formData.sort == 'string') {\n formData.sort = formData.sort?.split(',');\n}\nformData.sort = lodash.map(formData.sort, (item) => {\n const arr = item.split(':');\n return { field_name: arr[0], order: arr[1] };\n});\nif (recordId) {\n query = 'mutation{record: ' + objectName + '__update(id: \"' + recordId + '\", doc: {__saveData}){_id}}';\n}\n__saveData = JSON.stringify(JSON.stringify(formData));\napi.data = { query: query.replace('{__saveData}', __saveData) };\n"
3994
+ }
3995
+ ],
3996
+ "showCloseButton": true,
3997
+ "showErrorMsg": true,
3998
+ "showLoading": true,
3999
+ "id": "u:d3f6947b6acf",
4000
+ "size": "lg"
4001
+ },
4002
+ "actionType": "dialog"
4003
+ }
4004
+ ]
4005
+ }
4006
+ }
4007
+ },
3986
4008
  {
3987
4009
  "type": "button",
3988
4010
  "label": "删除",
3989
- "visibleOn": "(global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && ['all', 'recent', 'my'].indexOf(listName) == -1",
4011
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
3990
4012
  "confirmText": "如果您删除此列表视图,该视图将为所有具备访问权限的用户永久删除。是否确定要删除?",
3991
4013
  "onEvent": {
3992
4014
  "click": {
@@ -4041,7 +4063,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4041
4063
  }
4042
4064
  ]
4043
4065
  },
4044
- showDisplayAs ? getDisplayAsButton(showDisplayAs) : {}
4066
+ getDisplayAsButton(showDisplayAs)
4045
4067
  // {
4046
4068
  // "type": "search-box",
4047
4069
  // "align": "right",
@@ -4347,7 +4369,6 @@ function getLookupSapceUserTreeSchema(){
4347
4369
  {
4348
4370
  "actionType": "custom",
4349
4371
  "script": `
4350
- debugger;
4351
4372
  const scope = event.context.scoped;
4352
4373
  //TODO: 将form中的value一同加入筛选内
4353
4374
  // var filterForm = scope.parent.parent.getComponents().find(function(n){
@@ -5831,7 +5852,7 @@ var index = /*#__PURE__*/Object.freeze({
5831
5852
 
5832
5853
  const API_CACHE = 100;
5833
5854
 
5834
- function getReadonlyFormAdaptor(fields){
5855
+ function getReadonlyFormAdaptor(object, fields){
5835
5856
  let scriptStr = '';
5836
5857
  const selectFields = ___namespace.filter(fields, function(field){return field.name.indexOf('.') < 0 && ((field.type == 'select' && field.options) || ((field.type == 'lookup' || field.type == 'master_detail') && !field.reference_to))});
5837
5858
  const gridAndObjectFieldsName = ___namespace.map(___namespace.filter(fields, function(field){return field.name.indexOf('.') < 0 && (field.type === 'object' || field.type === 'grid')}), 'name');
@@ -5890,6 +5911,7 @@ function getReadonlyFormAdaptor(fields){
5890
5911
  console.error(e)
5891
5912
  }
5892
5913
  payload.data = data;
5914
+ payload.data.__objectName = "${object.name}";
5893
5915
  payload.data.__record = record;
5894
5916
  window.postMessage(Object.assign({type: "record.loaded"}, {record: record}), "*")
5895
5917
  }
@@ -5907,7 +5929,7 @@ async function getReadonlyFormInitApi(object, recordId, fields, options){
5907
5929
  url: getApi$2()+"&recordId=${recordId}",
5908
5930
  cache: API_CACHE,
5909
5931
  // requestAdaptor: "console.log('getReadonlyFormInitApi requestAdaptor', api);return api;",
5910
- adaptor: getReadonlyFormAdaptor(fields),
5932
+ adaptor: getReadonlyFormAdaptor(object, fields),
5911
5933
  data: await getFindOneQuery$1(object, recordId, fields, options),
5912
5934
  headers: {
5913
5935
  Authorization: "Bearer ${context.tenantId},${context.authToken}"
@@ -6625,6 +6647,7 @@ async function getObjectDetail(objectSchema, recordId, ctx){
6625
6647
  eventName: "recordLoaded"
6626
6648
  },
6627
6649
  data: {
6650
+ objectName: "${event.data.__objectName}",
6628
6651
  record: "${event.data.__record}"
6629
6652
  }
6630
6653
  },
@@ -7061,7 +7084,7 @@ async function getTableApi(mainObject, fields, options){
7061
7084
  const api = await getApi(mainObject, null, fields, {count: options.queryCount, alias: 'rows', limit: top, queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
7062
7085
 
7063
7086
  if(options.isRelated){
7064
- api.url += "&recordId=${recordId}";
7087
+ api.url += "&recordId=${_master.recordId}";
7065
7088
  }
7066
7089
 
7067
7090
  api.data.$term = "$term";
@@ -8306,7 +8329,7 @@ async function getRelatedListSchema(
8306
8329
  * @Author: baozhoutao@steedos.com
8307
8330
  * @Date: 2022-07-05 15:55:39
8308
8331
  * @LastEditors: baozhoutao@steedos.com
8309
- * @LastEditTime: 2023-04-12 14:24:09
8332
+ * @LastEditTime: 2023-04-17 15:26:17
8310
8333
  * @Description:
8311
8334
  */
8312
8335
 
@@ -8519,6 +8542,7 @@ async function getListSchema(
8519
8542
  return { uiSchema };
8520
8543
  }
8521
8544
 
8545
+ // 直接返回自定义的列表视图schema
8522
8546
  if(listView.enable_amis_schema && listView.amis_schema){
8523
8547
  const amisSchema = _$1.isString(listView.amis_schema) ? JSON.parse(listView.amis_schema) : listView.amis_schema;
8524
8548
  return {
@@ -8532,6 +8556,7 @@ async function getListSchema(
8532
8556
  let sort = getListViewSort(listView);
8533
8557
  let listviewFilter = getListViewFilter(listView);
8534
8558
  let listview_filters = listView && listView._filters;
8559
+ // 返回 calendar 组件
8535
8560
  if(listView.type === "calendar"){
8536
8561
  const amisSchema = {
8537
8562
  "type": "steedos-object-calendar",
@@ -8550,14 +8575,21 @@ async function getListSchema(
8550
8575
 
8551
8576
  const defaults = ctx.defaults || {};
8552
8577
 
8553
- if(!defaults.headerSchema && ctx.showHeader){
8554
- defaults.headerSchema = await getObjectListHeader$1(uiSchema);
8555
- }
8578
+ // // 未自定义header 且显示header的时候, 使用系统header
8579
+ // if(!defaults.headerSchema && ctx.showHeader){
8580
+ // defaults.headerSchema = getObjectListHeader(uiSchema, listViewName);
8581
+ // }
8582
+
8583
+ // // 如果不显示header,则清理掉
8584
+ // if(!ctx.showHeader){
8585
+ // defaults.headerSchema = null;
8586
+ // }
8556
8587
 
8557
- if(!ctx.showHeader){
8558
- defaults.headerSchema = null;
8559
- }
8588
+ defaults.headerSchema = null;
8560
8589
 
8590
+ /**
8591
+ * 本次存储代码段
8592
+ */
8561
8593
  try {
8562
8594
  const listViewPropsStoreKey = location.pathname + "/crud/" + ctx.listViewId;
8563
8595
  let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
@@ -8672,7 +8704,7 @@ async function getTableSchema(
8672
8704
  headerToolbarItems: ctx.headerToolbarItems,
8673
8705
  buttons: await getListViewItemButtons(uiSchema, ctx)
8674
8706
  });
8675
- // console.log('getTableSchema====>amisSchema', amisSchema)
8707
+ console.log('getTableSchema====>amisSchema', amisSchema);
8676
8708
  // console.timeEnd('getTableSchema');
8677
8709
  return {
8678
8710
  uiSchema,
@@ -8792,6 +8824,41 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
8792
8824
  }
8793
8825
  }
8794
8826
 
8827
+ async function getRecordServiceSchema(objectName, appId, props = {}) {
8828
+ const uiSchema = await getUISchema(objectName);
8829
+ return {
8830
+ uiSchema,
8831
+ amisSchema: {
8832
+ "type": "service",
8833
+ "body": [],
8834
+ data: {
8835
+ "_master.objectName": "${objectName}",
8836
+ "_master.recordId": "${recordId}"
8837
+ },
8838
+ "style": {
8839
+ "padding": "var(--Page-body-padding)",
8840
+ ...props.style
8841
+ },
8842
+ onEvent: {
8843
+ "recordLoaded": {
8844
+ "actions": [
8845
+ {
8846
+ "actionType": "reload",
8847
+ "data": {
8848
+ "name": `\${record.${uiSchema.NAME_FIELD_KEY || 'name'}}`,
8849
+ "_master.record": `\${record}`,
8850
+ // 不清楚reload 如何给对象下的某个key复制, 所以此处重复设置_master的objectName、recordId
8851
+ "_master.objectName": "${objectName}",
8852
+ "_master.recordId": "${recordId}"
8853
+ }
8854
+ }
8855
+ ]
8856
+ },
8857
+ ...props.onEvent
8858
+ }
8859
+ }
8860
+ }
8861
+ }
8795
8862
 
8796
8863
  // 获取单个相关表
8797
8864
  async function getObjectRelated(
@@ -8835,6 +8902,7 @@ async function getObjectRelated(
8835
8902
  if(typeof window != 'undefined'){
8836
8903
  window.getUISchema = getUISchema;
8837
8904
  window.getUISchemaSync = getUISchemaSync;
8905
+ window.getListSchema = getListSchema;
8838
8906
  }
8839
8907
 
8840
8908
  // import { getListSchema } from './objects';
@@ -11709,6 +11777,7 @@ exports.getRecordDetailRelatedListSchema = getRecordDetailRelatedListSchema;
11709
11777
  exports.getRecordDetailSchema = getRecordDetailSchema;
11710
11778
  exports.getRecordPageInitSchema = getRecordPageInitSchema;
11711
11779
  exports.getRecordPermissions = getRecordPermissions;
11780
+ exports.getRecordServiceSchema = getRecordServiceSchema;
11712
11781
  exports.getRelatedFieldValue = getRelatedFieldValue;
11713
11782
  exports.getRelatedListSchema = getRelatedListSchema;
11714
11783
  exports.getRelatedsCount = getRelatedsCount;