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