@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.cjs.js CHANGED
@@ -1895,7 +1895,23 @@ const getSchema$1 = (uiSchema) => {
1895
1895
  {
1896
1896
  name: "template_url",
1897
1897
  label: "导入模板",
1898
- type: "markdown",
1898
+ type: "button-group",
1899
+ buttons: [
1900
+ {
1901
+ type: "button",
1902
+ label: "下载",
1903
+ visibleOn: "${template_url}",
1904
+ level: "link",
1905
+ actionType: "download",
1906
+ api:{
1907
+ url: "${template_url}",
1908
+ method: "get",
1909
+ headers: {
1910
+ Authorization: "Bearer ${context.tenantId},${context.authToken}"
1911
+ }
1912
+ }
1913
+ }
1914
+ ],
1899
1915
  options: {
1900
1916
  html: true
1901
1917
  },
@@ -2443,7 +2459,14 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2443
2459
  className: `button_${button.name}`
2444
2460
  }
2445
2461
  });
2446
- let dropdownButtons = ___default["default"].map(moreButtons, (button) => {
2462
+ let moreButtonsVisibleOn = '';
2463
+ let dropdownButtons = ___default["default"].map(moreButtons, (button, index) => {
2464
+ if(index === 0){
2465
+ moreButtonsVisibleOn = getButtonVisibleOn$1(button);
2466
+ }else {
2467
+ moreButtonsVisibleOn = moreButtonsVisibleOn + ' || ' +getButtonVisibleOn$1(button);
2468
+ }
2469
+
2447
2470
  return {
2448
2471
  type: 'steedos-object-button',
2449
2472
  name: button.name,
@@ -2453,12 +2476,13 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2453
2476
  });
2454
2477
  return {
2455
2478
  buttons: amisButtonsSchema,
2456
- moreButtons: dropdownButtons
2479
+ moreButtons: dropdownButtons,
2480
+ moreButtonsVisibleOn
2457
2481
  };
2458
2482
  };
2459
2483
 
2460
2484
  const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2461
- const { buttons, moreButtons } = getObjectDetailHeaderButtons(objectSchema, recordId);
2485
+ const { buttons, moreButtons, moreButtonsVisibleOn } = getObjectDetailHeaderButtons(objectSchema, recordId);
2462
2486
  if(ctx.formFactor === 'SMALL'){
2463
2487
  return {
2464
2488
  "type": "button",
@@ -2513,7 +2537,8 @@ const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2513
2537
  type: "steedos-dropdown-button",
2514
2538
  label: "",
2515
2539
  buttons: moreButtons,
2516
- className: 'slds-icon'
2540
+ className: 'slds-icon',
2541
+ visibleOn: moreButtonsVisibleOn
2517
2542
  };
2518
2543
  buttons.push(dropdownButtonsSchema);
2519
2544
  }
@@ -4646,12 +4671,13 @@ const getSettingListviewToolbarButtonSchema = ()=>{
4646
4671
  "type": "dropdown-button",
4647
4672
  "trigger": "click",
4648
4673
  "icon": "fa fa-cog",
4674
+ "tooltip": "列表视图控制",
4649
4675
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
4650
4676
  "align": "right",
4651
4677
  "visibleOn": "${!isLookup}",
4652
4678
  "buttons": [
4653
4679
  {
4654
- "label": "列表视图操作",
4680
+ "label": "列表视图控制",
4655
4681
  "children": [
4656
4682
  getNewListviewButtonSchema(),
4657
4683
  getCopyListviewButtonSchema(),
@@ -4685,9 +4711,11 @@ const getDisplayAsButton = function(objectName, showDisplayAs){
4685
4711
  "rightIconClassName": "m-l-sm"
4686
4712
  }
4687
4713
  ];
4714
+ const displayAsLabel = displayAs === 'split'? "分栏视图" : "表格";
4688
4715
  return {
4689
4716
  "type": "dropdown-button",
4690
4717
  "icon": "fa fa-table-columns",
4718
+ "tooltip": `显示为 ${displayAsLabel}`,
4691
4719
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
4692
4720
  "align": "right",
4693
4721
  "visibleOn": "${window:innerWidth > 768 && !!!isLookup}",
@@ -4767,6 +4795,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4767
4795
  // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页
4768
4796
  "type": "button",
4769
4797
  "align": "right",
4798
+ "tooltip": "刷新",
4770
4799
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
4771
4800
  "label": "",
4772
4801
  "icon": "fa fa-sync",
@@ -4786,6 +4815,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4786
4815
  "label": "",
4787
4816
  "icon": "fa fa-search",
4788
4817
  "type": "button",
4818
+ "tooltip": "搜索",
4789
4819
  "badge": {
4790
4820
  "offset": [
4791
4821
  -5,
@@ -4830,6 +4860,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4830
4860
  {
4831
4861
  "type": "reload",
4832
4862
  "align": "right",
4863
+ "tooltip": "刷新",
4833
4864
  "tooltipPlacement": "bottom",
4834
4865
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
4835
4866
  },
@@ -4837,6 +4868,8 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4837
4868
  filterVisible ? {
4838
4869
  "label": "",
4839
4870
  "icon": "fa fa-search",
4871
+ "tooltip": "搜索",
4872
+ "tooltipPlacement": "bottom",
4840
4873
  "type": "button",
4841
4874
  "align": "right",
4842
4875
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
@@ -5861,8 +5894,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
5861
5894
  /*
5862
5895
  * @Author: baozhoutao@steedos.com
5863
5896
  * @Date: 2023-01-13 17:27:54
5864
- * @LastEditors: baozhoutao@steedos.com
5865
- * @LastEditTime: 2023-01-16 10:36:27
5897
+ * @LastEditors: Please set LastEditors
5898
+ * @LastEditTime: 2023-05-31 13:34:22
5866
5899
  * @Description:
5867
5900
  */
5868
5901
 
@@ -5904,8 +5937,12 @@ const getMarkdownFieldSchema = (field, readonly, ctx)=>{
5904
5937
  const getHtmlFieldSchema = (field, readonly, ctx)=>{
5905
5938
  if(readonly){
5906
5939
  return {
5907
- "type": "html",
5908
- "name": field.name
5940
+ "type": "control",
5941
+ "label": field.label,
5942
+ "body": {
5943
+ "type": "html",
5944
+ "name": field.name
5945
+ }
5909
5946
  }
5910
5947
  }else {
5911
5948
  return {
@@ -5932,8 +5969,8 @@ const getHtmlFieldSchema = (field, readonly, ctx)=>{
5932
5969
  /*
5933
5970
  * @Author: baozhoutao@steedos.com
5934
5971
  * @Date: 2022-10-28 14:52:55
5935
- * @LastEditors: baozhoutao@steedos.com
5936
- * @LastEditTime: 2022-10-28 14:53:02
5972
+ * @LastEditors: Please set LastEditors
5973
+ * @LastEditTime: 2023-05-31 13:25:53
5937
5974
  * @Description:
5938
5975
  */
5939
5976
 
@@ -6482,8 +6519,19 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6482
6519
  break;
6483
6520
  case 'url':
6484
6521
  convertData = {
6485
- type: getAmisStaticFieldType('url', readonly)
6522
+ type: getAmisStaticFieldType('url', readonly, field)
6486
6523
  };
6524
+ if(readonly && field.show_as_qr){
6525
+ convertData = {
6526
+ type: "control",
6527
+ label: field.label,
6528
+ body: {
6529
+ type: "qr-code",
6530
+ codeSize: 128,
6531
+ name: field.name
6532
+ }
6533
+ };
6534
+ }
6487
6535
  break;
6488
6536
  case 'email':
6489
6537
  convertData = {
@@ -6518,6 +6566,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6518
6566
  case 'code':
6519
6567
  convertData = {
6520
6568
  type: "editor",
6569
+ disabled: readonly ? true : false,
6521
6570
  language: field.language,
6522
6571
  editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
6523
6572
  };
@@ -7175,12 +7224,43 @@ const getSections = async (permissionFields, formFields, ctx) => {
7175
7224
  const fieldSchemaArray = getFieldSchemaArray(formFields);
7176
7225
  const _sections = ___namespace.groupBy(fieldSchemaArray, 'group');
7177
7226
  const sections = [];
7227
+ var sectionHeaderVisibleOn=[];
7178
7228
  for (const key in _sections) {
7179
7229
  const section = await getSection(formFields, permissionFields, fieldSchemaArray, key, ctx);
7180
7230
  if(section.body.length > 0){
7231
+ if(section.visibleOn){
7232
+ sectionHeaderVisibleOn.push(section.visibleOn);
7233
+ }
7181
7234
  sections.push(section);
7182
7235
  }
7183
7236
  }
7237
+ /*
7238
+ 为了实现只有一个分组时隐藏该分组标题,需要分三种情况(分组如果没有visibleon属性就代表一定显示,有visibleon需要进行判断)
7239
+ 1.所有分组中只有一个分组没有visibleon,还需要判断其他有visibleon的分组是否显示,只有其他都不显示时,才需要隐藏标题;反之,有任何一个显示,就不需要隐藏标题
7240
+ 2.所有分组都有visibleon
7241
+ 2.1 当前分组为隐藏时,标题就设置为隐藏
7242
+ 2.2 当前分组为显示时,其他分组只要有一个是显示,就显示该分组标题
7243
+ 2.3 当前分组为显示时,其他分组都隐藏,就隐藏该分组标题
7244
+ 3.所有分组中有两个以上的分组没有visibleon(这种情况不用处理)
7245
+ */
7246
+ if(ctx.mode == "edit"){
7247
+ if (sections.length - sectionHeaderVisibleOn.length == 1) {
7248
+ sections.forEach((section) => {
7249
+ section.headingClassName = {
7250
+ "hidden": `!(${sectionHeaderVisibleOn.join(" || ") || 'false'})`
7251
+ };
7252
+ });
7253
+ } else if (sections.length == sectionHeaderVisibleOn.length) {
7254
+ sections.forEach((section, index) => {
7255
+ var tempSectionHeaderVisibleOn = sectionHeaderVisibleOn.slice();
7256
+ tempSectionHeaderVisibleOn.splice(index, 1);
7257
+ section.headingClassName = {
7258
+ "hidden": `!((${tempSectionHeaderVisibleOn.join(" || ") || 'false'}) && ${sectionHeaderVisibleOn[index]})`
7259
+ };
7260
+ });
7261
+ }
7262
+ }
7263
+
7184
7264
  return sections;
7185
7265
  };
7186
7266
 
@@ -7551,11 +7631,12 @@ async function getObjectDetail(objectSchema, recordId, ctx){
7551
7631
  "expression": "this.__deletedRecord != true"
7552
7632
  },
7553
7633
  {
7554
- "args": {
7555
- "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7556
- "blank": false
7557
- },
7558
- "actionType": "link",
7634
+ // "args": {
7635
+ // "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7636
+ // "blank": false
7637
+ // },
7638
+ "actionType": "custom",
7639
+ "script": "Steedos.goBack()",
7559
7640
  "expression": "this.__deletedRecord === true"
7560
7641
  }
7561
7642
  ]
@@ -7694,6 +7775,8 @@ async function getTableColumns(fields, options){
7694
7775
  type = 'tpl';
7695
7776
  }else if(field.type === 'html'){
7696
7777
  type = 'markdown';
7778
+ }else if(field.type === 'url' && field.show_as_qr){
7779
+ type = 'qr-code';
7697
7780
  }
7698
7781
  let className = "";
7699
7782
  if(field.type === 'textarea'){
@@ -7721,7 +7804,13 @@ async function getTableColumns(fields, options){
7721
7804
 
7722
7805
  }
7723
7806
  // columns.push(getOperation(fields));
7724
-
7807
+ if(!___namespace.some(columns, { name: options.labelFieldName })){
7808
+ const href = Router.getObjectDetailPath({
7809
+ ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
7810
+ });
7811
+ columns[0].type = "tpl";
7812
+ columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
7813
+ }
7725
7814
  return columns;
7726
7815
  }
7727
7816
 
@@ -8087,6 +8176,8 @@ async function getTableApi(mainObject, fields, options){
8087
8176
 
8088
8177
  const fileFields = {};
8089
8178
  const fileFieldsKeys = [];
8179
+ // 含有optionsFunction属性, 无reference_to属性的lookup字段
8180
+ const lookupFields = {};
8090
8181
  fields.forEach((item)=>{
8091
8182
  if(___namespace.includes(['image','avatar','file'], item.type)){
8092
8183
  fileFieldsKeys.push(item.name);
@@ -8096,6 +8187,9 @@ async function getTableApi(mainObject, fields, options){
8096
8187
  multiple: item.multiple
8097
8188
  };
8098
8189
  }
8190
+ if(___namespace.includes(['lookup'], item.type) && !item.reference_to ){
8191
+ lookupFields[item.name] = item;
8192
+ }
8099
8193
  });
8100
8194
 
8101
8195
  let valueField = mainObject.key_field || '_id';
@@ -8112,6 +8206,7 @@ async function getTableApi(mainObject, fields, options){
8112
8206
  api.data.filter = "$filter";
8113
8207
  api.data.loaded = "${loaded}";
8114
8208
  api.data.listViewId = "${listViewId}";
8209
+ api.data.listName = "${listName}";
8115
8210
  api.requestAdaptor = `
8116
8211
  // selfData 中的数据由 CRUD 控制. selfData中,只能获取到 CRUD 给定的data. 无法从数据链中获取数据.
8117
8212
  let selfData = JSON.parse(JSON.stringify(api.data.$self));
@@ -8142,9 +8237,13 @@ async function getTableApi(mainObject, fields, options){
8142
8237
  console.error("本地存储中crud参数解析异常:", ex);
8143
8238
  }
8144
8239
  ${baseFilters ? `var systemFilters = ${JSON.stringify(baseFilters)};` : 'var systemFilters = [];'}
8240
+ var _ids = []
8145
8241
  const filtersFunction = ${filtersFunction};
8146
8242
  if(filtersFunction){
8147
8243
  const _filters = filtersFunction(systemFilters, api.data.$self);
8244
+ if(api.data.listName == "recent"){
8245
+ _ids = _filters[2]
8246
+ }
8148
8247
  if(_filters && _filters.length > 0){
8149
8248
  if(_.isEmpty(systemFilters)){
8150
8249
  systemFilters = _filters || [];
@@ -8256,6 +8355,7 @@ async function getTableApi(mainObject, fields, options){
8256
8355
  filters = [filters, 'and', userFilters]
8257
8356
  }
8258
8357
  }
8358
+ api.data._ids = _ids;
8259
8359
  api.data = {
8260
8360
  query: api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim())
8261
8361
  }
@@ -8263,6 +8363,11 @@ async function getTableApi(mainObject, fields, options){
8263
8363
  return api;
8264
8364
  `;
8265
8365
  api.adaptor = `
8366
+ if(api.body.listName == "recent"){
8367
+ payload.data.rows = _.sortBy(payload.data.rows, function(item){
8368
+ return _.indexOf(api.body._ids, item._id)
8369
+ });
8370
+ }
8266
8371
  const enable_tree = ${mainObject.enable_tree};
8267
8372
  if(!enable_tree){
8268
8373
  _.each(payload.data.rows, function(item, index){
@@ -8273,9 +8378,10 @@ async function getTableApi(mainObject, fields, options){
8273
8378
  }
8274
8379
  window.postMessage(Object.assign({type: "listview.loaded"}), "*");
8275
8380
  let fileFields = ${JSON.stringify(fileFields)};
8381
+ let lookupFields = ${JSON.stringify(lookupFields)};
8276
8382
  _.each(payload.data.rows, function(item, index){
8277
8383
  _.each(fileFields , (field, key)=>{
8278
- if(item[key] && item._display && item._display [key]){
8384
+ if(item[key] && item._display && item._display[key]){
8279
8385
  let value = item._display[key];
8280
8386
  if(!_.isArray(value)){
8281
8387
  value = [value]
@@ -8287,6 +8393,14 @@ async function getTableApi(mainObject, fields, options){
8287
8393
  }
8288
8394
  }
8289
8395
  })
8396
+ _.each(lookupFields , (field, key)=>{
8397
+ if(item[key]){
8398
+ if(field._optionsFunction){
8399
+ const optionsFunction = eval("(" + field._optionsFunction+ ")")(item);
8400
+ item[key + '__label'] = _.map(_.filter(optionsFunction, function(option){return _.includes(item[key], option.value)}), 'label').join(' ');
8401
+ }
8402
+ }
8403
+ })
8290
8404
  })
8291
8405
 
8292
8406
  if(enable_tree){
@@ -9616,6 +9730,24 @@ async function getListSchema(
9616
9730
 
9617
9731
  ctx.defaults = defaults;
9618
9732
 
9733
+ if (listViewName == "recent") {
9734
+ listview_filters = `
9735
+ function(filters, data) {
9736
+ var result = Steedos.authRequest('/graphql', {
9737
+ type: 'POST',
9738
+ async: false,
9739
+ data: JSON.stringify({
9740
+ query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
9741
+ }),
9742
+ });
9743
+ var _ids = []
9744
+ result.data.object_recent_viewed.forEach(function (item) {
9745
+ _ids = _ids.concat(item.record.ids)
9746
+ })
9747
+ return ["_id", "=", _ids];
9748
+ }
9749
+ `;
9750
+ }
9619
9751
  const amisSchema = {
9620
9752
  "type": "steedos-object-table",
9621
9753
  "objectApiName": objectName,