@steedos-widgets/amis-lib 1.2.11 → 1.2.13

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
  },
@@ -2416,7 +2432,14 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2416
2432
  className: `button_${button.name}`
2417
2433
  }
2418
2434
  });
2419
- let dropdownButtons = ___default.map(moreButtons, (button) => {
2435
+ let moreButtonsVisibleOn = '';
2436
+ let dropdownButtons = ___default.map(moreButtons, (button, index) => {
2437
+ if(index === 0){
2438
+ moreButtonsVisibleOn = getButtonVisibleOn$1(button);
2439
+ }else {
2440
+ moreButtonsVisibleOn = moreButtonsVisibleOn + ' || ' +getButtonVisibleOn$1(button);
2441
+ }
2442
+
2420
2443
  return {
2421
2444
  type: 'steedos-object-button',
2422
2445
  name: button.name,
@@ -2426,12 +2449,13 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2426
2449
  });
2427
2450
  return {
2428
2451
  buttons: amisButtonsSchema,
2429
- moreButtons: dropdownButtons
2452
+ moreButtons: dropdownButtons,
2453
+ moreButtonsVisibleOn
2430
2454
  };
2431
2455
  };
2432
2456
 
2433
2457
  const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2434
- const { buttons, moreButtons } = getObjectDetailHeaderButtons(objectSchema, recordId);
2458
+ const { buttons, moreButtons, moreButtonsVisibleOn } = getObjectDetailHeaderButtons(objectSchema, recordId);
2435
2459
  if(ctx.formFactor === 'SMALL'){
2436
2460
  return {
2437
2461
  "type": "button",
@@ -2486,7 +2510,8 @@ const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2486
2510
  type: "steedos-dropdown-button",
2487
2511
  label: "",
2488
2512
  buttons: moreButtons,
2489
- className: 'slds-icon'
2513
+ className: 'slds-icon',
2514
+ visibleOn: moreButtonsVisibleOn
2490
2515
  };
2491
2516
  buttons.push(dropdownButtonsSchema);
2492
2517
  }
@@ -4619,12 +4644,13 @@ const getSettingListviewToolbarButtonSchema = ()=>{
4619
4644
  "type": "dropdown-button",
4620
4645
  "trigger": "click",
4621
4646
  "icon": "fa fa-cog",
4647
+ "tooltip": "列表视图控制",
4622
4648
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
4623
4649
  "align": "right",
4624
4650
  "visibleOn": "${!isLookup}",
4625
4651
  "buttons": [
4626
4652
  {
4627
- "label": "列表视图操作",
4653
+ "label": "列表视图控制",
4628
4654
  "children": [
4629
4655
  getNewListviewButtonSchema(),
4630
4656
  getCopyListviewButtonSchema(),
@@ -4658,9 +4684,11 @@ const getDisplayAsButton = function(objectName, showDisplayAs){
4658
4684
  "rightIconClassName": "m-l-sm"
4659
4685
  }
4660
4686
  ];
4687
+ const displayAsLabel = displayAs === 'split'? "分栏视图" : "表格";
4661
4688
  return {
4662
4689
  "type": "dropdown-button",
4663
4690
  "icon": "fa fa-table-columns",
4691
+ "tooltip": `显示为 ${displayAsLabel}`,
4664
4692
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
4665
4693
  "align": "right",
4666
4694
  "visibleOn": "${window:innerWidth > 768 && !!!isLookup}",
@@ -4740,6 +4768,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4740
4768
  // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页
4741
4769
  "type": "button",
4742
4770
  "align": "right",
4771
+ "tooltip": "刷新",
4743
4772
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
4744
4773
  "label": "",
4745
4774
  "icon": "fa fa-sync",
@@ -4759,6 +4788,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4759
4788
  "label": "",
4760
4789
  "icon": "fa fa-search",
4761
4790
  "type": "button",
4791
+ "tooltip": "搜索",
4762
4792
  "badge": {
4763
4793
  "offset": [
4764
4794
  -5,
@@ -4803,6 +4833,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4803
4833
  {
4804
4834
  "type": "reload",
4805
4835
  "align": "right",
4836
+ "tooltip": "刷新",
4806
4837
  "tooltipPlacement": "bottom",
4807
4838
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
4808
4839
  },
@@ -4810,6 +4841,8 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4810
4841
  filterVisible ? {
4811
4842
  "label": "",
4812
4843
  "icon": "fa fa-search",
4844
+ "tooltip": "搜索",
4845
+ "tooltipPlacement": "bottom",
4813
4846
  "type": "button",
4814
4847
  "align": "right",
4815
4848
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
@@ -5834,8 +5867,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
5834
5867
  /*
5835
5868
  * @Author: baozhoutao@steedos.com
5836
5869
  * @Date: 2023-01-13 17:27:54
5837
- * @LastEditors: baozhoutao@steedos.com
5838
- * @LastEditTime: 2023-01-16 10:36:27
5870
+ * @LastEditors: Please set LastEditors
5871
+ * @LastEditTime: 2023-05-31 13:34:22
5839
5872
  * @Description:
5840
5873
  */
5841
5874
 
@@ -5877,8 +5910,12 @@ const getMarkdownFieldSchema = (field, readonly, ctx)=>{
5877
5910
  const getHtmlFieldSchema = (field, readonly, ctx)=>{
5878
5911
  if(readonly){
5879
5912
  return {
5880
- "type": "html",
5881
- "name": field.name
5913
+ "type": "control",
5914
+ "label": field.label,
5915
+ "body": {
5916
+ "type": "html",
5917
+ "name": field.name
5918
+ }
5882
5919
  }
5883
5920
  }else {
5884
5921
  return {
@@ -5905,8 +5942,8 @@ const getHtmlFieldSchema = (field, readonly, ctx)=>{
5905
5942
  /*
5906
5943
  * @Author: baozhoutao@steedos.com
5907
5944
  * @Date: 2022-10-28 14:52:55
5908
- * @LastEditors: baozhoutao@steedos.com
5909
- * @LastEditTime: 2022-10-28 14:53:02
5945
+ * @LastEditors: Please set LastEditors
5946
+ * @LastEditTime: 2023-05-31 13:25:53
5910
5947
  * @Description:
5911
5948
  */
5912
5949
 
@@ -6455,8 +6492,19 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6455
6492
  break;
6456
6493
  case 'url':
6457
6494
  convertData = {
6458
- type: getAmisStaticFieldType('url', readonly)
6495
+ type: getAmisStaticFieldType('url', readonly, field)
6459
6496
  };
6497
+ if(readonly && field.show_as_qr){
6498
+ convertData = {
6499
+ type: "control",
6500
+ label: field.label,
6501
+ body: {
6502
+ type: "qr-code",
6503
+ codeSize: 128,
6504
+ name: field.name
6505
+ }
6506
+ };
6507
+ }
6460
6508
  break;
6461
6509
  case 'email':
6462
6510
  convertData = {
@@ -6491,6 +6539,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6491
6539
  case 'code':
6492
6540
  convertData = {
6493
6541
  type: "editor",
6542
+ disabled: readonly ? true : false,
6494
6543
  language: field.language,
6495
6544
  editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
6496
6545
  };
@@ -7148,12 +7197,43 @@ const getSections = async (permissionFields, formFields, ctx) => {
7148
7197
  const fieldSchemaArray = getFieldSchemaArray(formFields);
7149
7198
  const _sections = _$1.groupBy(fieldSchemaArray, 'group');
7150
7199
  const sections = [];
7200
+ var sectionHeaderVisibleOn=[];
7151
7201
  for (const key in _sections) {
7152
7202
  const section = await getSection(formFields, permissionFields, fieldSchemaArray, key, ctx);
7153
7203
  if(section.body.length > 0){
7204
+ if(section.visibleOn){
7205
+ sectionHeaderVisibleOn.push(section.visibleOn);
7206
+ }
7154
7207
  sections.push(section);
7155
7208
  }
7156
7209
  }
7210
+ /*
7211
+ 为了实现只有一个分组时隐藏该分组标题,需要分三种情况(分组如果没有visibleon属性就代表一定显示,有visibleon需要进行判断)
7212
+ 1.所有分组中只有一个分组没有visibleon,还需要判断其他有visibleon的分组是否显示,只有其他都不显示时,才需要隐藏标题;反之,有任何一个显示,就不需要隐藏标题
7213
+ 2.所有分组都有visibleon
7214
+ 2.1 当前分组为隐藏时,标题就设置为隐藏
7215
+ 2.2 当前分组为显示时,其他分组只要有一个是显示,就显示该分组标题
7216
+ 2.3 当前分组为显示时,其他分组都隐藏,就隐藏该分组标题
7217
+ 3.所有分组中有两个以上的分组没有visibleon(这种情况不用处理)
7218
+ */
7219
+ if(ctx.mode == "edit"){
7220
+ if (sections.length - sectionHeaderVisibleOn.length == 1) {
7221
+ sections.forEach((section) => {
7222
+ section.headingClassName = {
7223
+ "hidden": `!(${sectionHeaderVisibleOn.join(" || ") || 'false'})`
7224
+ };
7225
+ });
7226
+ } else if (sections.length == sectionHeaderVisibleOn.length) {
7227
+ sections.forEach((section, index) => {
7228
+ var tempSectionHeaderVisibleOn = sectionHeaderVisibleOn.slice();
7229
+ tempSectionHeaderVisibleOn.splice(index, 1);
7230
+ section.headingClassName = {
7231
+ "hidden": `!((${tempSectionHeaderVisibleOn.join(" || ") || 'false'}) && ${sectionHeaderVisibleOn[index]})`
7232
+ };
7233
+ });
7234
+ }
7235
+ }
7236
+
7157
7237
  return sections;
7158
7238
  };
7159
7239
 
@@ -7524,11 +7604,12 @@ async function getObjectDetail(objectSchema, recordId, ctx){
7524
7604
  "expression": "this.__deletedRecord != true"
7525
7605
  },
7526
7606
  {
7527
- "args": {
7528
- "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7529
- "blank": false
7530
- },
7531
- "actionType": "link",
7607
+ // "args": {
7608
+ // "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7609
+ // "blank": false
7610
+ // },
7611
+ "actionType": "custom",
7612
+ "script": "Steedos.goBack()",
7532
7613
  "expression": "this.__deletedRecord === true"
7533
7614
  }
7534
7615
  ]
@@ -7667,6 +7748,8 @@ async function getTableColumns(fields, options){
7667
7748
  type = 'tpl';
7668
7749
  }else if(field.type === 'html'){
7669
7750
  type = 'markdown';
7751
+ }else if(field.type === 'url' && field.show_as_qr){
7752
+ type = 'qr-code';
7670
7753
  }
7671
7754
  let className = "";
7672
7755
  if(field.type === 'textarea'){
@@ -7694,7 +7777,13 @@ async function getTableColumns(fields, options){
7694
7777
 
7695
7778
  }
7696
7779
  // columns.push(getOperation(fields));
7697
-
7780
+ if(!_$1.some(columns, { name: options.labelFieldName })){
7781
+ const href = Router.getObjectDetailPath({
7782
+ ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
7783
+ });
7784
+ columns[0].type = "tpl";
7785
+ columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
7786
+ }
7698
7787
  return columns;
7699
7788
  }
7700
7789
 
@@ -8060,6 +8149,8 @@ async function getTableApi(mainObject, fields, options){
8060
8149
 
8061
8150
  const fileFields = {};
8062
8151
  const fileFieldsKeys = [];
8152
+ // 含有optionsFunction属性, 无reference_to属性的lookup字段
8153
+ const lookupFields = {};
8063
8154
  fields.forEach((item)=>{
8064
8155
  if(_$1.includes(['image','avatar','file'], item.type)){
8065
8156
  fileFieldsKeys.push(item.name);
@@ -8069,6 +8160,9 @@ async function getTableApi(mainObject, fields, options){
8069
8160
  multiple: item.multiple
8070
8161
  };
8071
8162
  }
8163
+ if(_$1.includes(['lookup'], item.type) && !item.reference_to ){
8164
+ lookupFields[item.name] = item;
8165
+ }
8072
8166
  });
8073
8167
 
8074
8168
  let valueField = mainObject.key_field || '_id';
@@ -8085,6 +8179,7 @@ async function getTableApi(mainObject, fields, options){
8085
8179
  api.data.filter = "$filter";
8086
8180
  api.data.loaded = "${loaded}";
8087
8181
  api.data.listViewId = "${listViewId}";
8182
+ api.data.listName = "${listName}";
8088
8183
  api.requestAdaptor = `
8089
8184
  // selfData 中的数据由 CRUD 控制. selfData中,只能获取到 CRUD 给定的data. 无法从数据链中获取数据.
8090
8185
  let selfData = JSON.parse(JSON.stringify(api.data.$self));
@@ -8115,9 +8210,13 @@ async function getTableApi(mainObject, fields, options){
8115
8210
  console.error("本地存储中crud参数解析异常:", ex);
8116
8211
  }
8117
8212
  ${baseFilters ? `var systemFilters = ${JSON.stringify(baseFilters)};` : 'var systemFilters = [];'}
8213
+ var _ids = []
8118
8214
  const filtersFunction = ${filtersFunction};
8119
8215
  if(filtersFunction){
8120
8216
  const _filters = filtersFunction(systemFilters, api.data.$self);
8217
+ if(api.data.listName == "recent"){
8218
+ _ids = _filters[2]
8219
+ }
8121
8220
  if(_filters && _filters.length > 0){
8122
8221
  if(_.isEmpty(systemFilters)){
8123
8222
  systemFilters = _filters || [];
@@ -8229,6 +8328,7 @@ async function getTableApi(mainObject, fields, options){
8229
8328
  filters = [filters, 'and', userFilters]
8230
8329
  }
8231
8330
  }
8331
+ api.data._ids = _ids;
8232
8332
  api.data = {
8233
8333
  query: api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim())
8234
8334
  }
@@ -8236,6 +8336,11 @@ async function getTableApi(mainObject, fields, options){
8236
8336
  return api;
8237
8337
  `;
8238
8338
  api.adaptor = `
8339
+ if(api.body.listName == "recent"){
8340
+ payload.data.rows = _.sortBy(payload.data.rows, function(item){
8341
+ return _.indexOf(api.body._ids, item._id)
8342
+ });
8343
+ }
8239
8344
  const enable_tree = ${mainObject.enable_tree};
8240
8345
  if(!enable_tree){
8241
8346
  _.each(payload.data.rows, function(item, index){
@@ -8246,9 +8351,10 @@ async function getTableApi(mainObject, fields, options){
8246
8351
  }
8247
8352
  window.postMessage(Object.assign({type: "listview.loaded"}), "*");
8248
8353
  let fileFields = ${JSON.stringify(fileFields)};
8354
+ let lookupFields = ${JSON.stringify(lookupFields)};
8249
8355
  _.each(payload.data.rows, function(item, index){
8250
8356
  _.each(fileFields , (field, key)=>{
8251
- if(item[key] && item._display && item._display [key]){
8357
+ if(item[key] && item._display && item._display[key]){
8252
8358
  let value = item._display[key];
8253
8359
  if(!_.isArray(value)){
8254
8360
  value = [value]
@@ -8260,6 +8366,14 @@ async function getTableApi(mainObject, fields, options){
8260
8366
  }
8261
8367
  }
8262
8368
  })
8369
+ _.each(lookupFields , (field, key)=>{
8370
+ if(item[key]){
8371
+ if(field._optionsFunction){
8372
+ const optionsFunction = eval("(" + field._optionsFunction+ ")")(item);
8373
+ item[key + '__label'] = _.map(_.filter(optionsFunction, function(option){return _.includes(item[key], option.value)}), 'label').join(' ');
8374
+ }
8375
+ }
8376
+ })
8263
8377
  })
8264
8378
 
8265
8379
  if(enable_tree){
@@ -9589,6 +9703,24 @@ async function getListSchema(
9589
9703
 
9590
9704
  ctx.defaults = defaults;
9591
9705
 
9706
+ if (listViewName == "recent") {
9707
+ listview_filters = `
9708
+ function(filters, data) {
9709
+ var result = Steedos.authRequest('/graphql', {
9710
+ type: 'POST',
9711
+ async: false,
9712
+ data: JSON.stringify({
9713
+ query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
9714
+ }),
9715
+ });
9716
+ var _ids = []
9717
+ result.data.object_recent_viewed.forEach(function (item) {
9718
+ _ids = _ids.concat(item.record.ids)
9719
+ })
9720
+ return ["_id", "=", _ids];
9721
+ }
9722
+ `;
9723
+ }
9592
9724
  const amisSchema = {
9593
9725
  "type": "steedos-object-table",
9594
9726
  "objectApiName": objectName,