@steedos-widgets/amis-object 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.
@@ -1237,6 +1237,9 @@ body {
1237
1237
  -moz-column-gap: 1rem;
1238
1238
  column-gap: 1rem;
1239
1239
  }
1240
+ .steedos-amis-form .antd-Collapse .antd-Collapse-header.hidden {
1241
+ display: none !important;
1242
+ }
1240
1243
 
1241
1244
  @media (max-width: 768px) {
1242
1245
  .record-detail-header-name {
@@ -2253,7 +2253,23 @@
2253
2253
  {
2254
2254
  name: "template_url",
2255
2255
  label: "导入模板",
2256
- type: "markdown",
2256
+ type: "button-group",
2257
+ buttons: [
2258
+ {
2259
+ type: "button",
2260
+ label: "下载",
2261
+ visibleOn: "${template_url}",
2262
+ level: "link",
2263
+ actionType: "download",
2264
+ api:{
2265
+ url: "${template_url}",
2266
+ method: "get",
2267
+ headers: {
2268
+ Authorization: "Bearer ${context.tenantId},${context.authToken}"
2269
+ }
2270
+ }
2271
+ }
2272
+ ],
2257
2273
  options: {
2258
2274
  html: true
2259
2275
  },
@@ -2801,7 +2817,14 @@
2801
2817
  className: `button_${button.name}`
2802
2818
  }
2803
2819
  });
2804
- let dropdownButtons = ___default__default["default"].map(moreButtons, (button) => {
2820
+ let moreButtonsVisibleOn = '';
2821
+ let dropdownButtons = ___default__default["default"].map(moreButtons, (button, index) => {
2822
+ if(index === 0){
2823
+ moreButtonsVisibleOn = getButtonVisibleOn$1(button);
2824
+ }else {
2825
+ moreButtonsVisibleOn = moreButtonsVisibleOn + ' || ' +getButtonVisibleOn$1(button);
2826
+ }
2827
+
2805
2828
  return {
2806
2829
  type: 'steedos-object-button',
2807
2830
  name: button.name,
@@ -2811,12 +2834,13 @@
2811
2834
  });
2812
2835
  return {
2813
2836
  buttons: amisButtonsSchema,
2814
- moreButtons: dropdownButtons
2837
+ moreButtons: dropdownButtons,
2838
+ moreButtonsVisibleOn
2815
2839
  };
2816
2840
  };
2817
2841
 
2818
2842
  const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2819
- const { buttons, moreButtons } = getObjectDetailHeaderButtons(objectSchema, recordId);
2843
+ const { buttons, moreButtons, moreButtonsVisibleOn } = getObjectDetailHeaderButtons(objectSchema, recordId);
2820
2844
  if(ctx.formFactor === 'SMALL'){
2821
2845
  return {
2822
2846
  "type": "button",
@@ -2871,7 +2895,8 @@
2871
2895
  type: "steedos-dropdown-button",
2872
2896
  label: "",
2873
2897
  buttons: moreButtons,
2874
- className: 'slds-icon'
2898
+ className: 'slds-icon',
2899
+ visibleOn: moreButtonsVisibleOn
2875
2900
  };
2876
2901
  buttons.push(dropdownButtonsSchema);
2877
2902
  }
@@ -5004,12 +5029,13 @@
5004
5029
  "type": "dropdown-button",
5005
5030
  "trigger": "click",
5006
5031
  "icon": "fa fa-cog",
5032
+ "tooltip": "列表视图控制",
5007
5033
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
5008
5034
  "align": "right",
5009
5035
  "visibleOn": "${!isLookup}",
5010
5036
  "buttons": [
5011
5037
  {
5012
- "label": "列表视图操作",
5038
+ "label": "列表视图控制",
5013
5039
  "children": [
5014
5040
  getNewListviewButtonSchema(),
5015
5041
  getCopyListviewButtonSchema(),
@@ -5043,9 +5069,11 @@
5043
5069
  "rightIconClassName": "m-l-sm"
5044
5070
  }
5045
5071
  ];
5072
+ const displayAsLabel = displayAs === 'split'? "分栏视图" : "表格";
5046
5073
  return {
5047
5074
  "type": "dropdown-button",
5048
5075
  "icon": "fa fa-table-columns",
5076
+ "tooltip": `显示为 ${displayAsLabel}`,
5049
5077
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
5050
5078
  "align": "right",
5051
5079
  "visibleOn": "${window:innerWidth > 768 && !!!isLookup}",
@@ -5125,6 +5153,7 @@ else{
5125
5153
  // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页
5126
5154
  "type": "button",
5127
5155
  "align": "right",
5156
+ "tooltip": "刷新",
5128
5157
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5129
5158
  "label": "",
5130
5159
  "icon": "fa fa-sync",
@@ -5144,6 +5173,7 @@ else{
5144
5173
  "label": "",
5145
5174
  "icon": "fa fa-search",
5146
5175
  "type": "button",
5176
+ "tooltip": "搜索",
5147
5177
  "badge": {
5148
5178
  "offset": [
5149
5179
  -5,
@@ -5188,6 +5218,7 @@ else{
5188
5218
  {
5189
5219
  "type": "reload",
5190
5220
  "align": "right",
5221
+ "tooltip": "刷新",
5191
5222
  "tooltipPlacement": "bottom",
5192
5223
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5193
5224
  },
@@ -5195,6 +5226,8 @@ else{
5195
5226
  filterVisible ? {
5196
5227
  "label": "",
5197
5228
  "icon": "fa fa-search",
5229
+ "tooltip": "搜索",
5230
+ "tooltipPlacement": "bottom",
5198
5231
  "type": "button",
5199
5232
  "align": "right",
5200
5233
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
@@ -6219,8 +6252,8 @@ else{
6219
6252
  /*
6220
6253
  * @Author: baozhoutao@steedos.com
6221
6254
  * @Date: 2023-01-13 17:27:54
6222
- * @LastEditors: baozhoutao@steedos.com
6223
- * @LastEditTime: 2023-01-16 10:36:27
6255
+ * @LastEditors: Please set LastEditors
6256
+ * @LastEditTime: 2023-05-31 13:34:22
6224
6257
  * @Description:
6225
6258
  */
6226
6259
 
@@ -6262,8 +6295,12 @@ else{
6262
6295
  const getHtmlFieldSchema = (field, readonly, ctx)=>{
6263
6296
  if(readonly){
6264
6297
  return {
6265
- "type": "html",
6266
- "name": field.name
6298
+ "type": "control",
6299
+ "label": field.label,
6300
+ "body": {
6301
+ "type": "html",
6302
+ "name": field.name
6303
+ }
6267
6304
  }
6268
6305
  }else {
6269
6306
  return {
@@ -6290,8 +6327,8 @@ else{
6290
6327
  /*
6291
6328
  * @Author: baozhoutao@steedos.com
6292
6329
  * @Date: 2022-10-28 14:52:55
6293
- * @LastEditors: baozhoutao@steedos.com
6294
- * @LastEditTime: 2022-10-28 14:53:02
6330
+ * @LastEditors: Please set LastEditors
6331
+ * @LastEditTime: 2023-05-31 13:25:53
6295
6332
  * @Description:
6296
6333
  */
6297
6334
 
@@ -6840,8 +6877,19 @@ else{
6840
6877
  break;
6841
6878
  case 'url':
6842
6879
  convertData = {
6843
- type: getAmisStaticFieldType('url', readonly)
6880
+ type: getAmisStaticFieldType('url', readonly, field)
6844
6881
  };
6882
+ if(readonly && field.show_as_qr){
6883
+ convertData = {
6884
+ type: "control",
6885
+ label: field.label,
6886
+ body: {
6887
+ type: "qr-code",
6888
+ codeSize: 128,
6889
+ name: field.name
6890
+ }
6891
+ };
6892
+ }
6845
6893
  break;
6846
6894
  case 'email':
6847
6895
  convertData = {
@@ -6876,6 +6924,7 @@ else{
6876
6924
  case 'code':
6877
6925
  convertData = {
6878
6926
  type: "editor",
6927
+ disabled: readonly ? true : false,
6879
6928
  language: field.language,
6880
6929
  editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
6881
6930
  };
@@ -7533,12 +7582,43 @@ else{
7533
7582
  const fieldSchemaArray = getFieldSchemaArray(formFields);
7534
7583
  const _sections = ___default__namespace.groupBy(fieldSchemaArray, 'group');
7535
7584
  const sections = [];
7585
+ var sectionHeaderVisibleOn=[];
7536
7586
  for (const key in _sections) {
7537
7587
  const section = await getSection(formFields, permissionFields, fieldSchemaArray, key, ctx);
7538
7588
  if(section.body.length > 0){
7589
+ if(section.visibleOn){
7590
+ sectionHeaderVisibleOn.push(section.visibleOn);
7591
+ }
7539
7592
  sections.push(section);
7540
7593
  }
7541
7594
  }
7595
+ /*
7596
+ 为了实现只有一个分组时隐藏该分组标题,需要分三种情况(分组如果没有visibleon属性就代表一定显示,有visibleon需要进行判断)
7597
+ 1.所有分组中只有一个分组没有visibleon,还需要判断其他有visibleon的分组是否显示,只有其他都不显示时,才需要隐藏标题;反之,有任何一个显示,就不需要隐藏标题
7598
+ 2.所有分组都有visibleon
7599
+ 2.1 当前分组为隐藏时,标题就设置为隐藏
7600
+ 2.2 当前分组为显示时,其他分组只要有一个是显示,就显示该分组标题
7601
+ 2.3 当前分组为显示时,其他分组都隐藏,就隐藏该分组标题
7602
+ 3.所有分组中有两个以上的分组没有visibleon(这种情况不用处理)
7603
+ */
7604
+ if(ctx.mode == "edit"){
7605
+ if (sections.length - sectionHeaderVisibleOn.length == 1) {
7606
+ sections.forEach((section) => {
7607
+ section.headingClassName = {
7608
+ "hidden": `!(${sectionHeaderVisibleOn.join(" || ") || 'false'})`
7609
+ };
7610
+ });
7611
+ } else if (sections.length == sectionHeaderVisibleOn.length) {
7612
+ sections.forEach((section, index) => {
7613
+ var tempSectionHeaderVisibleOn = sectionHeaderVisibleOn.slice();
7614
+ tempSectionHeaderVisibleOn.splice(index, 1);
7615
+ section.headingClassName = {
7616
+ "hidden": `!((${tempSectionHeaderVisibleOn.join(" || ") || 'false'}) && ${sectionHeaderVisibleOn[index]})`
7617
+ };
7618
+ });
7619
+ }
7620
+ }
7621
+
7542
7622
  return sections;
7543
7623
  };
7544
7624
 
@@ -7909,11 +7989,12 @@ else{
7909
7989
  "expression": "this.__deletedRecord != true"
7910
7990
  },
7911
7991
  {
7912
- "args": {
7913
- "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7914
- "blank": false
7915
- },
7916
- "actionType": "link",
7992
+ // "args": {
7993
+ // "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7994
+ // "blank": false
7995
+ // },
7996
+ "actionType": "custom",
7997
+ "script": "Steedos.goBack()",
7917
7998
  "expression": "this.__deletedRecord === true"
7918
7999
  }
7919
8000
  ]
@@ -8052,6 +8133,8 @@ else{
8052
8133
  type = 'tpl';
8053
8134
  }else if(field.type === 'html'){
8054
8135
  type = 'markdown';
8136
+ }else if(field.type === 'url' && field.show_as_qr){
8137
+ type = 'qr-code';
8055
8138
  }
8056
8139
  let className = "";
8057
8140
  if(field.type === 'textarea'){
@@ -8079,7 +8162,13 @@ else{
8079
8162
 
8080
8163
  }
8081
8164
  // columns.push(getOperation(fields));
8082
-
8165
+ if(!___default__namespace.some(columns, { name: options.labelFieldName })){
8166
+ const href = Router$1.getObjectDetailPath({
8167
+ ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
8168
+ });
8169
+ columns[0].type = "tpl";
8170
+ columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
8171
+ }
8083
8172
  return columns;
8084
8173
  }
8085
8174
 
@@ -8445,6 +8534,8 @@ else{
8445
8534
 
8446
8535
  const fileFields = {};
8447
8536
  const fileFieldsKeys = [];
8537
+ // 含有optionsFunction属性, 无reference_to属性的lookup字段
8538
+ const lookupFields = {};
8448
8539
  fields.forEach((item)=>{
8449
8540
  if(___default__namespace.includes(['image','avatar','file'], item.type)){
8450
8541
  fileFieldsKeys.push(item.name);
@@ -8454,6 +8545,9 @@ else{
8454
8545
  multiple: item.multiple
8455
8546
  };
8456
8547
  }
8548
+ if(___default__namespace.includes(['lookup'], item.type) && !item.reference_to ){
8549
+ lookupFields[item.name] = item;
8550
+ }
8457
8551
  });
8458
8552
 
8459
8553
  let valueField = mainObject.key_field || '_id';
@@ -8470,6 +8564,7 @@ else{
8470
8564
  api.data.filter = "$filter";
8471
8565
  api.data.loaded = "${loaded}";
8472
8566
  api.data.listViewId = "${listViewId}";
8567
+ api.data.listName = "${listName}";
8473
8568
  api.requestAdaptor = `
8474
8569
  // selfData 中的数据由 CRUD 控制. selfData中,只能获取到 CRUD 给定的data. 无法从数据链中获取数据.
8475
8570
  let selfData = JSON.parse(JSON.stringify(api.data.$self));
@@ -8500,9 +8595,13 @@ else{
8500
8595
  console.error("本地存储中crud参数解析异常:", ex);
8501
8596
  }
8502
8597
  ${baseFilters ? `var systemFilters = ${JSON.stringify(baseFilters)};` : 'var systemFilters = [];'}
8598
+ var _ids = []
8503
8599
  const filtersFunction = ${filtersFunction};
8504
8600
  if(filtersFunction){
8505
8601
  const _filters = filtersFunction(systemFilters, api.data.$self);
8602
+ if(api.data.listName == "recent"){
8603
+ _ids = _filters[2]
8604
+ }
8506
8605
  if(_filters && _filters.length > 0){
8507
8606
  if(_.isEmpty(systemFilters)){
8508
8607
  systemFilters = _filters || [];
@@ -8614,6 +8713,7 @@ else{
8614
8713
  filters = [filters, 'and', userFilters]
8615
8714
  }
8616
8715
  }
8716
+ api.data._ids = _ids;
8617
8717
  api.data = {
8618
8718
  query: api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim())
8619
8719
  }
@@ -8621,6 +8721,11 @@ else{
8621
8721
  return api;
8622
8722
  `;
8623
8723
  api.adaptor = `
8724
+ if(api.body.listName == "recent"){
8725
+ payload.data.rows = _.sortBy(payload.data.rows, function(item){
8726
+ return _.indexOf(api.body._ids, item._id)
8727
+ });
8728
+ }
8624
8729
  const enable_tree = ${mainObject.enable_tree};
8625
8730
  if(!enable_tree){
8626
8731
  _.each(payload.data.rows, function(item, index){
@@ -8631,9 +8736,10 @@ else{
8631
8736
  }
8632
8737
  window.postMessage(Object.assign({type: "listview.loaded"}), "*");
8633
8738
  let fileFields = ${JSON.stringify(fileFields)};
8739
+ let lookupFields = ${JSON.stringify(lookupFields)};
8634
8740
  _.each(payload.data.rows, function(item, index){
8635
8741
  _.each(fileFields , (field, key)=>{
8636
- if(item[key] && item._display && item._display [key]){
8742
+ if(item[key] && item._display && item._display[key]){
8637
8743
  let value = item._display[key];
8638
8744
  if(!_.isArray(value)){
8639
8745
  value = [value]
@@ -8645,6 +8751,14 @@ else{
8645
8751
  }
8646
8752
  }
8647
8753
  })
8754
+ _.each(lookupFields , (field, key)=>{
8755
+ if(item[key]){
8756
+ if(field._optionsFunction){
8757
+ const optionsFunction = eval("(" + field._optionsFunction+ ")")(item);
8758
+ item[key + '__label'] = _.map(_.filter(optionsFunction, function(option){return _.includes(item[key], option.value)}), 'label').join(' ');
8759
+ }
8760
+ }
8761
+ })
8648
8762
  })
8649
8763
 
8650
8764
  if(enable_tree){
@@ -9974,6 +10088,24 @@ else{
9974
10088
 
9975
10089
  ctx.defaults = defaults;
9976
10090
 
10091
+ if (listViewName == "recent") {
10092
+ listview_filters = `
10093
+ function(filters, data) {
10094
+ var result = Steedos.authRequest('/graphql', {
10095
+ type: 'POST',
10096
+ async: false,
10097
+ data: JSON.stringify({
10098
+ query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
10099
+ }),
10100
+ });
10101
+ var _ids = []
10102
+ result.data.object_recent_viewed.forEach(function (item) {
10103
+ _ids = _ids.concat(item.record.ids)
10104
+ })
10105
+ return ["_id", "=", _ids];
10106
+ }
10107
+ `;
10108
+ }
9977
10109
  const amisSchema = {
9978
10110
  "type": "steedos-object-table",
9979
10111
  "objectApiName": objectName,
@@ -13709,6 +13841,7 @@ else{
13709
13841
  // className不传入crud组件,crud单独识别crudClassName属性
13710
13842
  listSchema.className = crudClassName;
13711
13843
  listSchema.onEvent = {}; // 为啥要将一个内置event放在此处?
13844
+ // 下面expression中_isRelated参数判断的是列表视图分栏模式下,新建、编辑、删除相关子表记录时不应该刷新左侧(主表)列表视图组件
13712
13845
  listSchema.onEvent["@data.changed.".concat(objectApiName)] = {
13713
13846
  "actions": [
13714
13847
  {
@@ -15288,7 +15421,7 @@ else{
15288
15421
  "method": "post",
15289
15422
  "url": "${context.rootUrl}/graphql?keywords=${keywords}",
15290
15423
  "requestAdaptor": "\n const keywords = api.body.keywords || '';\n const appId = '".concat(data.app_id || '', "';\n api.data = {\n query: `\n {\n options: flows__getList(action: \"").concat(action, "\", keywords: \"${keywords}\", appId: \"${appId}\", distributeInstanceId: \"").concat(distributeInstanceId, "\", distributeStepId: \"").concat(distributeStepId, "\"){\n value:_id\n label:name\n children: flows{\n value: _id,\n label: name\n }\n }\n }\n `\n }\n "),
15291
- "adaptor": "\n payload.data.options?.forEach(function(item,index) {\n if(!item.children || item.children.length == 0){\n payload.data.options.splice(index)\n }\n })\n return payload;\n ",
15424
+ "adaptor": "\n payload.data.options?.forEach(function(item,index) {\n if(!item.children || item.children.length == 0){\n payload.data.options.splice(index,1)\n }\n })\n return payload;\n ",
15292
15425
  "headers": {
15293
15426
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
15294
15427
  }