@steedos-widgets/amis-lib 1.2.12 → 1.2.14

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
@@ -1868,7 +1868,23 @@ const getSchema$1 = (uiSchema) => {
1868
1868
  {
1869
1869
  name: "template_url",
1870
1870
  label: "导入模板",
1871
- type: "markdown",
1871
+ type: "button-group",
1872
+ buttons: [
1873
+ {
1874
+ type: "button",
1875
+ label: "下载",
1876
+ visibleOn: "${template_url}",
1877
+ level: "link",
1878
+ actionType: "download",
1879
+ api:{
1880
+ url: "${template_url}",
1881
+ method: "get",
1882
+ headers: {
1883
+ Authorization: "Bearer ${context.tenantId},${context.authToken}"
1884
+ }
1885
+ }
1886
+ }
1887
+ ],
1872
1888
  options: {
1873
1889
  html: true
1874
1890
  },
@@ -4628,12 +4644,13 @@ const getSettingListviewToolbarButtonSchema = ()=>{
4628
4644
  "type": "dropdown-button",
4629
4645
  "trigger": "click",
4630
4646
  "icon": "fa fa-cog",
4647
+ "tooltip": "列表视图控制",
4631
4648
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
4632
4649
  "align": "right",
4633
4650
  "visibleOn": "${!isLookup}",
4634
4651
  "buttons": [
4635
4652
  {
4636
- "label": "列表视图操作",
4653
+ "label": "列表视图控制",
4637
4654
  "children": [
4638
4655
  getNewListviewButtonSchema(),
4639
4656
  getCopyListviewButtonSchema(),
@@ -4667,9 +4684,11 @@ const getDisplayAsButton = function(objectName, showDisplayAs){
4667
4684
  "rightIconClassName": "m-l-sm"
4668
4685
  }
4669
4686
  ];
4687
+ const displayAsLabel = displayAs === 'split'? "分栏视图" : "表格";
4670
4688
  return {
4671
4689
  "type": "dropdown-button",
4672
4690
  "icon": "fa fa-table-columns",
4691
+ "tooltip": `显示为 ${displayAsLabel}`,
4673
4692
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
4674
4693
  "align": "right",
4675
4694
  "visibleOn": "${window:innerWidth > 768 && !!!isLookup}",
@@ -4749,6 +4768,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4749
4768
  // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页
4750
4769
  "type": "button",
4751
4770
  "align": "right",
4771
+ "tooltip": "刷新",
4752
4772
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
4753
4773
  "label": "",
4754
4774
  "icon": "fa fa-sync",
@@ -4768,6 +4788,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4768
4788
  "label": "",
4769
4789
  "icon": "fa fa-search",
4770
4790
  "type": "button",
4791
+ "tooltip": "搜索",
4771
4792
  "badge": {
4772
4793
  "offset": [
4773
4794
  -5,
@@ -4812,6 +4833,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4812
4833
  {
4813
4834
  "type": "reload",
4814
4835
  "align": "right",
4836
+ "tooltip": "刷新",
4815
4837
  "tooltipPlacement": "bottom",
4816
4838
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
4817
4839
  },
@@ -4819,6 +4841,8 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4819
4841
  filterVisible ? {
4820
4842
  "label": "",
4821
4843
  "icon": "fa fa-search",
4844
+ "tooltip": "搜索",
4845
+ "tooltipPlacement": "bottom",
4822
4846
  "type": "button",
4823
4847
  "align": "right",
4824
4848
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
@@ -5468,6 +5492,10 @@ async function lookupToAmisPicker(field, readonly, ctx){
5468
5492
  };
5469
5493
  }
5470
5494
 
5495
+ if(field.pickerSchema){
5496
+ pickerSchema = Object.assign({}, pickerSchema, field.pickerSchema);
5497
+ }
5498
+
5471
5499
  const data = {
5472
5500
  type: getAmisStaticFieldType('picker', readonly),
5473
5501
  labelField: referenceTo.labelField.name,
@@ -5843,8 +5871,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
5843
5871
  /*
5844
5872
  * @Author: baozhoutao@steedos.com
5845
5873
  * @Date: 2023-01-13 17:27:54
5846
- * @LastEditors: baozhoutao@steedos.com
5847
- * @LastEditTime: 2023-01-16 10:36:27
5874
+ * @LastEditors: Please set LastEditors
5875
+ * @LastEditTime: 2023-05-31 13:34:22
5848
5876
  * @Description:
5849
5877
  */
5850
5878
 
@@ -5886,8 +5914,12 @@ const getMarkdownFieldSchema = (field, readonly, ctx)=>{
5886
5914
  const getHtmlFieldSchema = (field, readonly, ctx)=>{
5887
5915
  if(readonly){
5888
5916
  return {
5889
- "type": "html",
5890
- "name": field.name
5917
+ "type": "control",
5918
+ "label": field.label,
5919
+ "body": {
5920
+ "type": "html",
5921
+ "name": field.name
5922
+ }
5891
5923
  }
5892
5924
  }else {
5893
5925
  return {
@@ -5914,8 +5946,8 @@ const getHtmlFieldSchema = (field, readonly, ctx)=>{
5914
5946
  /*
5915
5947
  * @Author: baozhoutao@steedos.com
5916
5948
  * @Date: 2022-10-28 14:52:55
5917
- * @LastEditors: baozhoutao@steedos.com
5918
- * @LastEditTime: 2022-10-28 14:53:02
5949
+ * @LastEditors: Please set LastEditors
5950
+ * @LastEditTime: 2023-05-31 13:25:53
5919
5951
  * @Description:
5920
5952
  */
5921
5953
 
@@ -6464,8 +6496,19 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6464
6496
  break;
6465
6497
  case 'url':
6466
6498
  convertData = {
6467
- type: getAmisStaticFieldType('url', readonly)
6499
+ type: getAmisStaticFieldType('url', readonly, field)
6468
6500
  };
6501
+ if(readonly && field.show_as_qr){
6502
+ convertData = {
6503
+ type: "control",
6504
+ label: field.label,
6505
+ body: {
6506
+ type: "qr-code",
6507
+ codeSize: 128,
6508
+ name: field.name
6509
+ }
6510
+ };
6511
+ }
6469
6512
  break;
6470
6513
  case 'email':
6471
6514
  convertData = {
@@ -6500,6 +6543,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6500
6543
  case 'code':
6501
6544
  convertData = {
6502
6545
  type: "editor",
6546
+ disabled: readonly ? true : false,
6503
6547
  language: field.language,
6504
6548
  editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
6505
6549
  };
@@ -7082,12 +7126,12 @@ function getBatchDelete(objectName){
7082
7126
  /*
7083
7127
  * @Author: baozhoutao@steedos.com
7084
7128
  * @Date: 2022-05-26 16:02:08
7085
- * @LastEditors: baozhoutao@steedos.com
7086
- * @LastEditTime: 2023-03-13 16:01:40
7129
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
7130
+ * @LastEditTime: 2023-06-02 16:54:41
7087
7131
  * @Description:
7088
7132
  */
7089
7133
 
7090
- const getFieldSchemaArray = (formFields)=>{
7134
+ const getFieldSchemaArray = (formFields) => {
7091
7135
  let fieldSchemaArray = [];
7092
7136
  fieldSchemaArray.length = 0;
7093
7137
 
@@ -7100,10 +7144,10 @@ const getFieldSchemaArray = (formFields)=>{
7100
7144
  // field.group = field.label
7101
7145
  field.is_wide = true;
7102
7146
  }
7103
-
7104
- if (!isObjectField){
7105
- if(!field.hidden){
7106
- fieldSchemaArray.push(Object.assign({name: fieldName}, field, {permission: {allowEdit: true}}));
7147
+
7148
+ if (!isObjectField) {
7149
+ if (!field.hidden) {
7150
+ fieldSchemaArray.push(Object.assign({ name: fieldName }, field, { permission: { allowEdit: true } }));
7107
7151
  }
7108
7152
  }
7109
7153
  });
@@ -7111,58 +7155,104 @@ const getFieldSchemaArray = (formFields)=>{
7111
7155
  };
7112
7156
 
7113
7157
  const getSection = async (formFields, permissionFields, fieldSchemaArray, sectionName, ctx) => {
7158
+ if (!ctx) {
7159
+ ctx = {};
7160
+ }
7114
7161
  const sectionFields = _$1.filter(fieldSchemaArray, { 'group': sectionName });
7115
- if(sectionFields.length == _$1.filter(sectionFields, ['hidden', true]).length){
7116
- return ;
7162
+ if (sectionFields.length == _$1.filter(sectionFields, ['hidden', true]).length) {
7163
+ return;
7117
7164
  }
7118
7165
 
7119
7166
  const fieldSetBody = [];
7120
7167
 
7121
7168
  for (const perField of sectionFields) {
7122
7169
  let field = perField;
7123
- if(perField.type === 'grid'){
7124
- field = await getGridFieldSubFields(perField, formFields);
7125
- // console.log(`perField.type grid ===> field`, field)
7126
- }else if(perField.type === 'object'){
7127
- field = await getObjectFieldSubFields(perField, formFields);
7128
- // console.log(`perField.type object ===> field`, field)
7129
- }
7130
- if(field.name.indexOf(".") < 0){
7131
- ctx.__formFields = formFields;
7132
- const amisField = await convertSFieldToAmisField(field, field.readonly, ctx);
7133
- // console.log(`${field.name} amisField`, field, amisField)
7134
- if(amisField){
7135
- fieldSetBody.push(amisField);
7136
- }
7170
+ if (perField.type === 'grid') {
7171
+ field = await getGridFieldSubFields(perField, formFields);
7172
+ // console.log(`perField.type grid ===> field`, field)
7173
+ } else if (perField.type === 'object') {
7174
+ field = await getObjectFieldSubFields(perField, formFields);
7175
+ // console.log(`perField.type object ===> field`, field)
7176
+ }
7177
+ if (field.name.indexOf(".") < 0) {
7178
+ ctx.__formFields = formFields;
7179
+ const amisField = await convertSFieldToAmisField(field, field.readonly, ctx);
7180
+ // console.log(`${field.name} amisField`, field, amisField)
7181
+ if (amisField) {
7182
+ fieldSetBody.push(amisField);
7137
7183
  }
7184
+ }
7138
7185
  }
7139
7186
 
7140
7187
  // fieldSet 已支持显隐控制
7141
- const sectionFieldsVisibleOn = _$1.map(_$1.compact(_$1.map(fieldSetBody, 'visibleOn')) , (visibleOn)=>{
7188
+ const sectionFieldsVisibleOn = _$1.map(_$1.compact(_$1.map(fieldSetBody, 'visibleOn')), (visibleOn) => {
7142
7189
  return visibleOn;
7143
7190
  });
7144
- const section = {
7191
+
7192
+ let section = {
7145
7193
  "type": "fieldSet",
7146
7194
  "title": sectionName,
7147
7195
  "collapsable": true,
7148
7196
  "body": fieldSetBody,
7149
7197
  };
7150
- if(sectionFieldsVisibleOn.length > 0 && fieldSetBody.length === sectionFieldsVisibleOn.length){
7198
+
7199
+ if (ctx.enableTabs) {
7200
+ section = {
7201
+ "title": sectionName,
7202
+ "body": fieldSetBody,
7203
+ };
7204
+ }
7205
+
7206
+ if (sectionFieldsVisibleOn.length > 0 && fieldSetBody.length === sectionFieldsVisibleOn.length) {
7151
7207
  section.visibleOn = `${sectionFieldsVisibleOn.join(" || ")}`;
7152
7208
  }
7153
7209
  return section
7154
7210
  };
7155
7211
 
7156
7212
  const getSections = async (permissionFields, formFields, ctx) => {
7213
+ if (!ctx) {
7214
+ ctx = {};
7215
+ }
7157
7216
  const fieldSchemaArray = getFieldSchemaArray(formFields);
7158
7217
  const _sections = _$1.groupBy(fieldSchemaArray, 'group');
7159
7218
  const sections = [];
7219
+ var sectionVisibleOns = [];
7160
7220
  for (const key in _sections) {
7161
7221
  const section = await getSection(formFields, permissionFields, fieldSchemaArray, key, ctx);
7162
- if(section.body.length > 0){
7222
+ if (section.body.length > 0) {
7223
+ if (section.visibleOn) {
7224
+ sectionVisibleOns.push(section.visibleOn);
7225
+ }
7226
+ else {
7227
+ sectionVisibleOns.push("true");
7228
+ }
7163
7229
  sections.push(section);
7164
7230
  }
7165
7231
  }
7232
+ /*
7233
+ 为了实现只有一个分组时隐藏该分组标题,需要分三种情况(分组如果没有visibleon属性就代表一定显示,有visibleon需要进行判断)
7234
+ 1 当前分组为隐藏时,标题就设置为隐藏
7235
+ 2 当前分组为显示时,其他分组只要有一个是显示,就显示该分组标题
7236
+ 3 当前分组为显示时,其他分组都隐藏,就隐藏该分组标题
7237
+ */
7238
+ sections.forEach((section, index) => {
7239
+ var tempSectionVisibleOns = sectionVisibleOns.slice();
7240
+ tempSectionVisibleOns.splice(index, 1);
7241
+ section.headingClassName = {
7242
+ "hidden": `!((${tempSectionVisibleOns.join(" || ") || 'false'}) && ${sectionVisibleOns[index]})`
7243
+ };
7244
+ });
7245
+
7246
+ if (ctx.enableTabs) {
7247
+ return [
7248
+ {
7249
+ "type": "tabs",
7250
+ "tabs": sections,
7251
+ "tabsMode": ctx.tabsMode
7252
+ }
7253
+ ]
7254
+ }
7255
+
7166
7256
  return sections;
7167
7257
  };
7168
7258
 
@@ -7677,6 +7767,8 @@ async function getTableColumns(fields, options){
7677
7767
  type = 'tpl';
7678
7768
  }else if(field.type === 'html'){
7679
7769
  type = 'markdown';
7770
+ }else if(field.type === 'url' && field.show_as_qr){
7771
+ type = 'qr-code';
7680
7772
  }
7681
7773
  let className = "";
7682
7774
  if(field.type === 'textarea'){
@@ -7704,7 +7796,13 @@ async function getTableColumns(fields, options){
7704
7796
 
7705
7797
  }
7706
7798
  // columns.push(getOperation(fields));
7707
-
7799
+ if(!_$1.some(columns, { name: options.labelFieldName })){
7800
+ const href = Router.getObjectDetailPath({
7801
+ ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
7802
+ });
7803
+ columns[0].type = "tpl";
7804
+ columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
7805
+ }
7708
7806
  return columns;
7709
7807
  }
7710
7808
 
@@ -8070,6 +8168,8 @@ async function getTableApi(mainObject, fields, options){
8070
8168
 
8071
8169
  const fileFields = {};
8072
8170
  const fileFieldsKeys = [];
8171
+ // 含有optionsFunction属性, 无reference_to属性的lookup字段
8172
+ const lookupFields = {};
8073
8173
  fields.forEach((item)=>{
8074
8174
  if(_$1.includes(['image','avatar','file'], item.type)){
8075
8175
  fileFieldsKeys.push(item.name);
@@ -8079,6 +8179,9 @@ async function getTableApi(mainObject, fields, options){
8079
8179
  multiple: item.multiple
8080
8180
  };
8081
8181
  }
8182
+ if(_$1.includes(['lookup'], item.type) && !item.reference_to ){
8183
+ lookupFields[item.name] = item;
8184
+ }
8082
8185
  });
8083
8186
 
8084
8187
  let valueField = mainObject.key_field || '_id';
@@ -8095,6 +8198,7 @@ async function getTableApi(mainObject, fields, options){
8095
8198
  api.data.filter = "$filter";
8096
8199
  api.data.loaded = "${loaded}";
8097
8200
  api.data.listViewId = "${listViewId}";
8201
+ api.data.listName = "${listName}";
8098
8202
  api.requestAdaptor = `
8099
8203
  // selfData 中的数据由 CRUD 控制. selfData中,只能获取到 CRUD 给定的data. 无法从数据链中获取数据.
8100
8204
  let selfData = JSON.parse(JSON.stringify(api.data.$self));
@@ -8125,9 +8229,13 @@ async function getTableApi(mainObject, fields, options){
8125
8229
  console.error("本地存储中crud参数解析异常:", ex);
8126
8230
  }
8127
8231
  ${baseFilters ? `var systemFilters = ${JSON.stringify(baseFilters)};` : 'var systemFilters = [];'}
8232
+ var _ids = []
8128
8233
  const filtersFunction = ${filtersFunction};
8129
8234
  if(filtersFunction){
8130
8235
  const _filters = filtersFunction(systemFilters, api.data.$self);
8236
+ if(api.data.listName == "recent"){
8237
+ _ids = _filters[2]
8238
+ }
8131
8239
  if(_filters && _filters.length > 0){
8132
8240
  if(_.isEmpty(systemFilters)){
8133
8241
  systemFilters = _filters || [];
@@ -8239,6 +8347,7 @@ async function getTableApi(mainObject, fields, options){
8239
8347
  filters = [filters, 'and', userFilters]
8240
8348
  }
8241
8349
  }
8350
+ api.data._ids = _ids;
8242
8351
  api.data = {
8243
8352
  query: api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim())
8244
8353
  }
@@ -8246,6 +8355,11 @@ async function getTableApi(mainObject, fields, options){
8246
8355
  return api;
8247
8356
  `;
8248
8357
  api.adaptor = `
8358
+ if(api.body.listName == "recent"){
8359
+ payload.data.rows = _.sortBy(payload.data.rows, function(item){
8360
+ return _.indexOf(api.body._ids, item._id)
8361
+ });
8362
+ }
8249
8363
  const enable_tree = ${mainObject.enable_tree};
8250
8364
  if(!enable_tree){
8251
8365
  _.each(payload.data.rows, function(item, index){
@@ -8256,9 +8370,10 @@ async function getTableApi(mainObject, fields, options){
8256
8370
  }
8257
8371
  window.postMessage(Object.assign({type: "listview.loaded"}), "*");
8258
8372
  let fileFields = ${JSON.stringify(fileFields)};
8373
+ let lookupFields = ${JSON.stringify(lookupFields)};
8259
8374
  _.each(payload.data.rows, function(item, index){
8260
8375
  _.each(fileFields , (field, key)=>{
8261
- if(item[key] && item._display && item._display [key]){
8376
+ if(item[key] && item._display && item._display[key]){
8262
8377
  let value = item._display[key];
8263
8378
  if(!_.isArray(value)){
8264
8379
  value = [value]
@@ -8270,6 +8385,14 @@ async function getTableApi(mainObject, fields, options){
8270
8385
  }
8271
8386
  }
8272
8387
  })
8388
+ _.each(lookupFields , (field, key)=>{
8389
+ if(item[key]){
8390
+ if(field._optionsFunction){
8391
+ const optionsFunction = eval("(" + field._optionsFunction+ ")")(item);
8392
+ item[key + '__label'] = _.map(_.filter(optionsFunction, function(option){return _.includes(item[key], option.value)}), 'label').join(' ');
8393
+ }
8394
+ }
8395
+ })
8273
8396
  })
8274
8397
 
8275
8398
  if(enable_tree){
@@ -9599,6 +9722,24 @@ async function getListSchema(
9599
9722
 
9600
9723
  ctx.defaults = defaults;
9601
9724
 
9725
+ if (listViewName == "recent") {
9726
+ listview_filters = `
9727
+ function(filters, data) {
9728
+ var result = Steedos.authRequest('/graphql', {
9729
+ type: 'POST',
9730
+ async: false,
9731
+ data: JSON.stringify({
9732
+ query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
9733
+ }),
9734
+ });
9735
+ var _ids = []
9736
+ result.data.object_recent_viewed.forEach(function (item) {
9737
+ _ids = _ids.concat(item.record.ids)
9738
+ })
9739
+ return ["_id", "=", _ids];
9740
+ }
9741
+ `;
9742
+ }
9602
9743
  const amisSchema = {
9603
9744
  "type": "steedos-object-table",
9604
9745
  "objectApiName": objectName,