@steedos-widgets/amis-lib 1.1.6 → 1.2.0-beta.0

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
@@ -3392,7 +3392,7 @@ function getExportApiRequestAdaptorScript(){
3392
3392
  `
3393
3393
  }
3394
3394
 
3395
- function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false, hiddenCount = false} = {}){
3395
+ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false, hiddenCount = false, headerToolbarItems} = {}){
3396
3396
  const isMobile = window.innerWidth < 768;
3397
3397
  if(isMobile){
3398
3398
  showDisplayAs = false;
@@ -3451,6 +3451,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
3451
3451
  }else {
3452
3452
  return [
3453
3453
  // "filter-toggler",
3454
+ ...(headerToolbarItems || []),
3454
3455
  "bulkActions",
3455
3456
  {
3456
3457
  "type": "columns-toggler",
@@ -3805,6 +3806,89 @@ const getReferenceTo = async (field)=>{
3805
3806
  }
3806
3807
  };
3807
3808
 
3809
+ function getLookupSapceUserTreeSchema(){
3810
+ const tree = [{
3811
+ "type": "input-tree",
3812
+ "className": "",
3813
+ "id": "u:7fd77b7915b0",
3814
+ "source": {
3815
+ "method": "post",
3816
+ "url": "${context.rootUrl}/graphql",
3817
+ "headers": {
3818
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
3819
+ },
3820
+ "adaptor": " const records = payload.data.options;\n const treeRecords = [];\n const getChildren = (records, childrenIds) => {\n if (!childrenIds) {\n return;\n }\n const children = _.filter(records, (record) => {\n return _.includes(childrenIds, record.value)\n });\n _.each(children, (item) => {\n if (item.children) {\n item.children = getChildren(records, item.children)\n }\n })\n return children;\n }\n\n const getRoot = (records) => {\n for (var i = 0; i < records.length; i++){\n records[i].noParent = 0;\n if (!!records[i].parent) {\n biaozhi = 1\n for (var j = 0; j < records.length; j++){\n if (records[i].parent == records[j].value)\n biaozhi = 0;\n }\n if (biaozhi == 1) records[i].noParent = 1;\n } else records[i].noParent = 1;\n }\n }\n getRoot(records);\n console.log(records)\n\n _.each(records, (record) => {\n if (record.noParent ==1) {\n treeRecords.push(Object.assign({}, record, { children: getChildren(records, record.children) }));\n }\n });\n console.log(treeRecords)\n\n payload.data.options = treeRecords;\n return payload;\n ",
3821
+ "requestAdaptor": "\n ",
3822
+ "data": {
3823
+ "query": "{options:organizations(filters:[\"hidden\", \"!=\", true],sort:\"sort_no desc\"){value:_id label:name,parent,children}}"
3824
+ },
3825
+ "messages": {
3826
+ }
3827
+ },
3828
+ "onEvent": {
3829
+ "change": {
3830
+ "actions": [
3831
+ {
3832
+ "actionType": "custom",
3833
+ "script": `
3834
+ debugger;
3835
+ const scope = event.context.scoped;
3836
+ //TODO: 将form中的value一同加入筛选内
3837
+ // var filterForm = scope.parent.parent.getComponents().find(function(n){
3838
+ // return n.props.type === "form";
3839
+ // });
3840
+ // var filterFormValues = filterForm.getValues();
3841
+ filterFormValues={
3842
+ "__searchable__organizations_parents":event.data.value.value
3843
+ }
3844
+ var listView = scope.parent.getComponents().find(function(n){
3845
+ return n.props.type === "crud";
3846
+ });
3847
+ const removedValues = {};
3848
+ // for(var k in filterFormValues){
3849
+ // if(filterFormValues[k] === "" && !filterFormValues.hasOwnProperty(k)){
3850
+ // removedValues[k] = "";
3851
+ // }
3852
+ // }
3853
+ listView.handleFilterSubmit(Object.assign({}, removedValues, filterFormValues));
3854
+ `
3855
+ }
3856
+ ]
3857
+ }
3858
+ },
3859
+ "label": "",
3860
+ "name": "organizations",
3861
+ "multiple": false,
3862
+ "joinValues": false,
3863
+ "clearValueOnHidden": false,
3864
+ "fieldName": "organizations",
3865
+ "hideRoot": true,
3866
+ "initiallyOpen": false,
3867
+ "extractValue": true,
3868
+ "onlyChildren": true,
3869
+ "treeContainerClassName": "no-border",
3870
+ "showIcon": false,
3871
+ "enableNodePath": false,
3872
+ "autoCheckChildren": false,
3873
+ "searchable": true,
3874
+ "searchConfig": {
3875
+ "sticky": true
3876
+ },
3877
+ "unfoldedLevel": 2,
3878
+ "style": {
3879
+ "max-height": "100%",
3880
+ "position": "absolute",
3881
+ "left": "-190px",
3882
+ "width": "190px",
3883
+ "bottom": 0,
3884
+ "top": "0",
3885
+ "overflow": "auto",
3886
+ "min-height":"300px"
3887
+ },
3888
+ "originPosition": "left-top"
3889
+ }];
3890
+ return tree;
3891
+ }
3808
3892
 
3809
3893
  async function lookupToAmisPicker(field, readonly, ctx){
3810
3894
  let referenceTo = await getReferenceTo(field);
@@ -4047,7 +4131,16 @@ async function lookupToAmisPicker(field, readonly, ctx){
4047
4131
  ...ctx
4048
4132
  });
4049
4133
 
4050
- pickerSchema.headerToolbar = getObjectHeaderToolbar(refObjectConfig, ctx.formFactor);
4134
+ var headerToolbarItems = [];
4135
+ const isMobile = window.innerWidth < 768;
4136
+ if(referenceTo.objectName === "space_users" && field.reference_to_field === "user" && !isMobile){
4137
+ headerToolbarItems = getLookupSapceUserTreeSchema();
4138
+ pickerSchema["style"] = {
4139
+ "margin-left":"200px",
4140
+ "min-height": "300px"
4141
+ };
4142
+ }
4143
+ pickerSchema.headerToolbar = getObjectHeaderToolbar(refObjectConfig, ctx.formFactor, { headerToolbarItems });
4051
4144
  const isAllowCreate = refObjectConfig.permissions.allowCreate;
4052
4145
  if (isAllowCreate) {
4053
4146
  const new_button = await getSchema$4(refObjectConfig, { appId: ctx.appId, objectName: refObjectConfig.name, formFactor: ctx.formFactor });
@@ -4055,15 +4148,18 @@ async function lookupToAmisPicker(field, readonly, ctx){
4055
4148
  pickerSchema.headerToolbar.push(new_button);
4056
4149
  }
4057
4150
  pickerSchema.footerToolbar = refObjectConfig.enable_tree ? [] : getObjectFooterToolbar();
4058
- if(ctx.filterVisible !== false){
4059
- let filterLoopCount = ctx.filterLoopCount || 0;
4060
- filterLoopCount++;
4061
- // 可以传入filterVisible为false防止死循环
4062
- pickerSchema.filter = await getObjectFilter(refObjectConfig, fields, {
4063
- isLookup: true,
4064
- ...ctx,
4065
- filterLoopCount,
4066
- });
4151
+ //TODO: 等待放大镜bug修复,if会去掉,始终显示放大镜
4152
+ if(referenceTo.objectName != "space_users" || field.reference_to_field != "user"){
4153
+ if (ctx.filterVisible !== false) {
4154
+ let filterLoopCount = ctx.filterLoopCount || 0;
4155
+ filterLoopCount++;
4156
+ // 可以传入filterVisible为false防止死循环
4157
+ pickerSchema.filter = await getObjectFilter(refObjectConfig, fields, {
4158
+ isLookup: true,
4159
+ ...ctx,
4160
+ filterLoopCount,
4161
+ });
4162
+ }
4067
4163
  }
4068
4164
  pickerSchema.data = Object.assign({}, pickerSchema.data, {
4069
4165
  "&": "$$",
@@ -4311,7 +4407,7 @@ async function lookupToAmis(field, readonly, ctx){
4311
4407
  if(ctx.idsDependOn || field.amis){
4312
4408
  return await lookupToAmisIdsPicker(field, readonly, ctx);
4313
4409
  }
4314
- return await lookupToAmisSelectUser(field, readonly, ctx);
4410
+ // return await lookupToAmisSelectUser(field, readonly, ctx);
4315
4411
  }
4316
4412
 
4317
4413
  const refObject = await getUISchema(referenceTo.objectName);
@@ -4947,13 +5043,19 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
4947
5043
  };
4948
5044
  break;
4949
5045
  case 'percent':
4950
- //TODO
4951
- convertData = {
4952
- type: getAmisStaticFieldType('number', readonly),
4953
- min: field.min,
4954
- max: field.max,
4955
- precision: field.scale
4956
- };
5046
+ if(readonly){
5047
+ convertData = {
5048
+ type: 'static-tpl',
5049
+ tpl: getUiFieldTpl(field)
5050
+ };
5051
+ }else {
5052
+ convertData = {
5053
+ type: getAmisStaticFieldType('number', readonly),
5054
+ min: field.min,
5055
+ max: field.max,
5056
+ precision: field.scale
5057
+ };
5058
+ }
4957
5059
  break;
4958
5060
  case 'password':
4959
5061
  convertData = {
@@ -4995,12 +5097,18 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
4995
5097
  break;
4996
5098
  case 'formula':
4997
5099
  if(readonly){
4998
- convertData.type = getAmisStaticFieldType(field.data_type, readonly);
5100
+ convertData = {
5101
+ type: 'static-tpl',
5102
+ tpl: getUiFieldTpl(field)
5103
+ };
4999
5104
  }
5000
5105
  break;
5001
5106
  case 'summary':
5002
5107
  if(readonly){
5003
- convertData.type = getAmisStaticFieldType(field.data_type, readonly);
5108
+ convertData = {
5109
+ type: 'static-tpl',
5110
+ tpl: getUiFieldTpl(field)
5111
+ };
5004
5112
  }
5005
5113
  break;
5006
5114
  case 'code':
@@ -5713,7 +5821,11 @@ async function getObjectCRUD(objectSchema, fields, options){
5713
5821
  }
5714
5822
  }
5715
5823
 
5716
- bodyProps.headerToolbar = getObjectHeaderToolbar(objectSchema, options.formFactor, {showDisplayAs, hiddenCount: options.queryCount === false});
5824
+ bodyProps.headerToolbar = getObjectHeaderToolbar(objectSchema, options.formFactor, {
5825
+ showDisplayAs,
5826
+ hiddenCount: options.queryCount === false,
5827
+ headerToolbarItems: options.headerToolbarItems
5828
+ });
5717
5829
 
5718
5830
 
5719
5831
  let body = null;
@@ -7947,7 +8059,8 @@ async function getListSchema(
7947
8059
  "sort": sort,
7948
8060
  "ctx": ctx,
7949
8061
  "requestAdaptor": listView.requestAdaptor,
7950
- "adaptor": listView.adaptor
8062
+ "adaptor": listView.adaptor,
8063
+ "headerToolbarItems": ctx.headerToolbarItems
7951
8064
  };
7952
8065
  return {
7953
8066
  uiSchema,
@@ -8008,6 +8121,7 @@ async function getTableSchema(
8008
8121
  ...ctx,
8009
8122
  filter: ctx.filters,
8010
8123
  sort,
8124
+ headerToolbarItems: ctx.headerToolbarItems,
8011
8125
  buttons: await getListViewItemButtons(uiSchema, ctx)
8012
8126
  });
8013
8127
  return {
@@ -11045,5 +11159,5 @@ const getInstanceInfo = async ({ instanceId, box }) => {
11045
11159
  };
11046
11160
  };
11047
11161
 
11048
- export { index as Field, Router, absoluteUrl, amisRender, amisRootClick, cloneObject, conditionsToFilters, createObject, defaultsDeep, deleteVariable, execute, executeButton, extendObject, fetchAPI, filtersToConditions, getApp, getApps, getAuthToken, getAuthorization, getButton, getButtonVisible, getButtonVisibleOn$1 as getButtonVisibleOn, getButtons, getCalendarSchema, getDefaultRenderData, getEnv, getEnvs, getEvn, getField, getFileSrc, getFlowFormSchema, getFormPageInitSchema, getFormSchema, getIdsPickerSchema, getImageSrc, getInstanceInfo, getListPageInitSchema, getListSchema, getListViewButtons, getListViewColumns, getListViewFilter, getListViewItemButtons, getListViewSort, getListviewInitSchema, getNotifications, getObjectDetailButtons, getObjectDetailMoreButtons, getObjectFieldsFilterBarSchema, getObjectFieldsFilterButtonSchema, getObjectFieldsFilterFormSchema, getObjectListHeader$1 as getObjectListHeader, getObjectListHeaderFieldsFilterBar, getObjectListHeaderFirstLine, getObjectListHeaderSecordLine, getObjectRecordDetailHeader, getObjectRecordDetailRelatedListHeader, getObjectRelated, getObjectRelatedList, getObjectRelatedListButtons, getObjectRelatedListHeader, getPage, getRecord, getRecordDetailHeaderSchema, getRecordDetailRelatedListSchema, getRecordDetailSchema, getRecordPageInitSchema, getRecordPermissions, getRelatedFieldValue, getRelatedListSchema, getRelatedsCount, getRootUrl, getSelectUserSchema, getSpaceUsersPickerAmisSchema, getSpaceUsersPickerSchema, getSteedosAuth, getTableSchema, getTenantId, getUISchema, getUISchemaSync, getUserId, getViewSchema, isExpression, isObject, lookupToAmis, lookupToAmisIdsPicker, lookupToAmisPicker, lookupToAmisSelect, lookupToAmisSelectUser, markReadAll, parseSingleExpression, registerRemoteAssets, registerRenders, setEnv, setEnvs, setRootUrl, setSteedosAuth, setUISchemaFunction, setVariable, standardButtonsTodo };
11162
+ export { index as Field, Router, absoluteUrl, amisRender, amisRootClick, cloneObject, conditionsToFilters, createObject, defaultsDeep, deleteVariable, execute, executeButton, extendObject, fetchAPI, filtersToConditions, getApp, getApps, getAuthToken, getAuthorization, getButton, getButtonVisible, getButtonVisibleOn$1 as getButtonVisibleOn, getButtons, getCalendarSchema, getDefaultRenderData, getEnv, getEnvs, getEvn, getField, getFileSrc, getFlowFormSchema, getFormPageInitSchema, getFormSchema, getIdsPickerSchema, getImageSrc, getInstanceInfo, getListPageInitSchema, getListSchema, getListViewButtons, getListViewColumns, getListViewFilter, getListViewItemButtons, getListViewSort, getListviewInitSchema, getLookupSapceUserTreeSchema, getNotifications, getObjectDetailButtons, getObjectDetailMoreButtons, getObjectFieldsFilterBarSchema, getObjectFieldsFilterButtonSchema, getObjectFieldsFilterFormSchema, getObjectListHeader$1 as getObjectListHeader, getObjectListHeaderFieldsFilterBar, getObjectListHeaderFirstLine, getObjectListHeaderSecordLine, getObjectRecordDetailHeader, getObjectRecordDetailRelatedListHeader, getObjectRelated, getObjectRelatedList, getObjectRelatedListButtons, getObjectRelatedListHeader, getPage, getRecord, getRecordDetailHeaderSchema, getRecordDetailRelatedListSchema, getRecordDetailSchema, getRecordPageInitSchema, getRecordPermissions, getRelatedFieldValue, getRelatedListSchema, getRelatedsCount, getRootUrl, getSelectUserSchema, getSpaceUsersPickerAmisSchema, getSpaceUsersPickerSchema, getSteedosAuth, getTableSchema, getTenantId, getUISchema, getUISchemaSync, getUserId, getViewSchema, isExpression, isObject, lookupToAmis, lookupToAmisIdsPicker, lookupToAmisPicker, lookupToAmisSelect, lookupToAmisSelectUser, markReadAll, parseSingleExpression, registerRemoteAssets, registerRenders, setEnv, setEnvs, setRootUrl, setSteedosAuth, setUISchemaFunction, setVariable, standardButtonsTodo };
11049
11163
  //# sourceMappingURL=index.esm.js.map