@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 {
@@ -2255,7 +2255,23 @@ const getSchema$1 = (uiSchema) => {
2255
2255
  {
2256
2256
  name: "template_url",
2257
2257
  label: "导入模板",
2258
- type: "markdown",
2258
+ type: "button-group",
2259
+ buttons: [
2260
+ {
2261
+ type: "button",
2262
+ label: "下载",
2263
+ visibleOn: "${template_url}",
2264
+ level: "link",
2265
+ actionType: "download",
2266
+ api:{
2267
+ url: "${template_url}",
2268
+ method: "get",
2269
+ headers: {
2270
+ Authorization: "Bearer ${context.tenantId},${context.authToken}"
2271
+ }
2272
+ }
2273
+ }
2274
+ ],
2259
2275
  options: {
2260
2276
  html: true
2261
2277
  },
@@ -2803,7 +2819,14 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2803
2819
  className: `button_${button.name}`
2804
2820
  }
2805
2821
  });
2806
- let dropdownButtons = ___default__default["default"].map(moreButtons, (button) => {
2822
+ let moreButtonsVisibleOn = '';
2823
+ let dropdownButtons = ___default__default["default"].map(moreButtons, (button, index) => {
2824
+ if(index === 0){
2825
+ moreButtonsVisibleOn = getButtonVisibleOn$1(button);
2826
+ }else {
2827
+ moreButtonsVisibleOn = moreButtonsVisibleOn + ' || ' +getButtonVisibleOn$1(button);
2828
+ }
2829
+
2807
2830
  return {
2808
2831
  type: 'steedos-object-button',
2809
2832
  name: button.name,
@@ -2813,12 +2836,13 @@ const getObjectDetailHeaderButtons = (objectSchema, recordId)=>{
2813
2836
  });
2814
2837
  return {
2815
2838
  buttons: amisButtonsSchema,
2816
- moreButtons: dropdownButtons
2839
+ moreButtons: dropdownButtons,
2840
+ moreButtonsVisibleOn
2817
2841
  };
2818
2842
  };
2819
2843
 
2820
2844
  const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2821
- const { buttons, moreButtons } = getObjectDetailHeaderButtons(objectSchema, recordId);
2845
+ const { buttons, moreButtons, moreButtonsVisibleOn } = getObjectDetailHeaderButtons(objectSchema, recordId);
2822
2846
  if(ctx.formFactor === 'SMALL'){
2823
2847
  return {
2824
2848
  "type": "button",
@@ -2873,7 +2897,8 @@ const getObjectDetailButtonsSchemas = (objectSchema, recordId, ctx)=>{
2873
2897
  type: "steedos-dropdown-button",
2874
2898
  label: "",
2875
2899
  buttons: moreButtons,
2876
- className: 'slds-icon'
2900
+ className: 'slds-icon',
2901
+ visibleOn: moreButtonsVisibleOn
2877
2902
  };
2878
2903
  buttons.push(dropdownButtonsSchema);
2879
2904
  }
@@ -5006,12 +5031,13 @@ const getSettingListviewToolbarButtonSchema = ()=>{
5006
5031
  "type": "dropdown-button",
5007
5032
  "trigger": "click",
5008
5033
  "icon": "fa fa-cog",
5034
+ "tooltip": "列表视图控制",
5009
5035
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
5010
5036
  "align": "right",
5011
5037
  "visibleOn": "${!isLookup}",
5012
5038
  "buttons": [
5013
5039
  {
5014
- "label": "列表视图操作",
5040
+ "label": "列表视图控制",
5015
5041
  "children": [
5016
5042
  getNewListviewButtonSchema(),
5017
5043
  getCopyListviewButtonSchema(),
@@ -5045,9 +5071,11 @@ const getDisplayAsButton = function(objectName, showDisplayAs){
5045
5071
  "rightIconClassName": "m-l-sm"
5046
5072
  }
5047
5073
  ];
5074
+ const displayAsLabel = displayAs === 'split'? "分栏视图" : "表格";
5048
5075
  return {
5049
5076
  "type": "dropdown-button",
5050
5077
  "icon": "fa fa-table-columns",
5078
+ "tooltip": `显示为 ${displayAsLabel}`,
5051
5079
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
5052
5080
  "align": "right",
5053
5081
  "visibleOn": "${window:innerWidth > 768 && !!!isLookup}",
@@ -5127,6 +5155,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5127
5155
  // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页
5128
5156
  "type": "button",
5129
5157
  "align": "right",
5158
+ "tooltip": "刷新",
5130
5159
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
5131
5160
  "label": "",
5132
5161
  "icon": "fa fa-sync",
@@ -5146,6 +5175,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5146
5175
  "label": "",
5147
5176
  "icon": "fa fa-search",
5148
5177
  "type": "button",
5178
+ "tooltip": "搜索",
5149
5179
  "badge": {
5150
5180
  "offset": [
5151
5181
  -5,
@@ -5190,6 +5220,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5190
5220
  {
5191
5221
  "type": "reload",
5192
5222
  "align": "right",
5223
+ "tooltip": "刷新",
5193
5224
  "tooltipPlacement": "bottom",
5194
5225
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
5195
5226
  },
@@ -5197,6 +5228,8 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
5197
5228
  filterVisible ? {
5198
5229
  "label": "",
5199
5230
  "icon": "fa fa-search",
5231
+ "tooltip": "搜索",
5232
+ "tooltipPlacement": "bottom",
5200
5233
  "type": "button",
5201
5234
  "align": "right",
5202
5235
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
@@ -6221,8 +6254,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
6221
6254
  /*
6222
6255
  * @Author: baozhoutao@steedos.com
6223
6256
  * @Date: 2023-01-13 17:27:54
6224
- * @LastEditors: baozhoutao@steedos.com
6225
- * @LastEditTime: 2023-01-16 10:36:27
6257
+ * @LastEditors: Please set LastEditors
6258
+ * @LastEditTime: 2023-05-31 13:34:22
6226
6259
  * @Description:
6227
6260
  */
6228
6261
 
@@ -6264,8 +6297,12 @@ const getMarkdownFieldSchema = (field, readonly, ctx)=>{
6264
6297
  const getHtmlFieldSchema = (field, readonly, ctx)=>{
6265
6298
  if(readonly){
6266
6299
  return {
6267
- "type": "html",
6268
- "name": field.name
6300
+ "type": "control",
6301
+ "label": field.label,
6302
+ "body": {
6303
+ "type": "html",
6304
+ "name": field.name
6305
+ }
6269
6306
  }
6270
6307
  }else {
6271
6308
  return {
@@ -6292,8 +6329,8 @@ const getHtmlFieldSchema = (field, readonly, ctx)=>{
6292
6329
  /*
6293
6330
  * @Author: baozhoutao@steedos.com
6294
6331
  * @Date: 2022-10-28 14:52:55
6295
- * @LastEditors: baozhoutao@steedos.com
6296
- * @LastEditTime: 2022-10-28 14:53:02
6332
+ * @LastEditors: Please set LastEditors
6333
+ * @LastEditTime: 2023-05-31 13:25:53
6297
6334
  * @Description:
6298
6335
  */
6299
6336
 
@@ -6842,8 +6879,19 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6842
6879
  break;
6843
6880
  case 'url':
6844
6881
  convertData = {
6845
- type: getAmisStaticFieldType('url', readonly)
6882
+ type: getAmisStaticFieldType('url', readonly, field)
6846
6883
  };
6884
+ if(readonly && field.show_as_qr){
6885
+ convertData = {
6886
+ type: "control",
6887
+ label: field.label,
6888
+ body: {
6889
+ type: "qr-code",
6890
+ codeSize: 128,
6891
+ name: field.name
6892
+ }
6893
+ };
6894
+ }
6847
6895
  break;
6848
6896
  case 'email':
6849
6897
  convertData = {
@@ -6878,6 +6926,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6878
6926
  case 'code':
6879
6927
  convertData = {
6880
6928
  type: "editor",
6929
+ disabled: readonly ? true : false,
6881
6930
  language: field.language,
6882
6931
  editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
6883
6932
  };
@@ -7535,12 +7584,43 @@ const getSections = async (permissionFields, formFields, ctx) => {
7535
7584
  const fieldSchemaArray = getFieldSchemaArray(formFields);
7536
7585
  const _sections = ___default__namespace.groupBy(fieldSchemaArray, 'group');
7537
7586
  const sections = [];
7587
+ var sectionHeaderVisibleOn=[];
7538
7588
  for (const key in _sections) {
7539
7589
  const section = await getSection(formFields, permissionFields, fieldSchemaArray, key, ctx);
7540
7590
  if(section.body.length > 0){
7591
+ if(section.visibleOn){
7592
+ sectionHeaderVisibleOn.push(section.visibleOn);
7593
+ }
7541
7594
  sections.push(section);
7542
7595
  }
7543
7596
  }
7597
+ /*
7598
+ 为了实现只有一个分组时隐藏该分组标题,需要分三种情况(分组如果没有visibleon属性就代表一定显示,有visibleon需要进行判断)
7599
+ 1.所有分组中只有一个分组没有visibleon,还需要判断其他有visibleon的分组是否显示,只有其他都不显示时,才需要隐藏标题;反之,有任何一个显示,就不需要隐藏标题
7600
+ 2.所有分组都有visibleon
7601
+ 2.1 当前分组为隐藏时,标题就设置为隐藏
7602
+ 2.2 当前分组为显示时,其他分组只要有一个是显示,就显示该分组标题
7603
+ 2.3 当前分组为显示时,其他分组都隐藏,就隐藏该分组标题
7604
+ 3.所有分组中有两个以上的分组没有visibleon(这种情况不用处理)
7605
+ */
7606
+ if(ctx.mode == "edit"){
7607
+ if (sections.length - sectionHeaderVisibleOn.length == 1) {
7608
+ sections.forEach((section) => {
7609
+ section.headingClassName = {
7610
+ "hidden": `!(${sectionHeaderVisibleOn.join(" || ") || 'false'})`
7611
+ };
7612
+ });
7613
+ } else if (sections.length == sectionHeaderVisibleOn.length) {
7614
+ sections.forEach((section, index) => {
7615
+ var tempSectionHeaderVisibleOn = sectionHeaderVisibleOn.slice();
7616
+ tempSectionHeaderVisibleOn.splice(index, 1);
7617
+ section.headingClassName = {
7618
+ "hidden": `!((${tempSectionHeaderVisibleOn.join(" || ") || 'false'}) && ${sectionHeaderVisibleOn[index]})`
7619
+ };
7620
+ });
7621
+ }
7622
+ }
7623
+
7544
7624
  return sections;
7545
7625
  };
7546
7626
 
@@ -7911,11 +7991,12 @@ async function getObjectDetail(objectSchema, recordId, ctx){
7911
7991
  "expression": "this.__deletedRecord != true"
7912
7992
  },
7913
7993
  {
7914
- "args": {
7915
- "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7916
- "blank": false
7917
- },
7918
- "actionType": "link",
7994
+ // "args": {
7995
+ // "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
7996
+ // "blank": false
7997
+ // },
7998
+ "actionType": "custom",
7999
+ "script": "Steedos.goBack()",
7919
8000
  "expression": "this.__deletedRecord === true"
7920
8001
  }
7921
8002
  ]
@@ -8054,6 +8135,8 @@ async function getTableColumns$1(fields, options){
8054
8135
  type = 'tpl';
8055
8136
  }else if(field.type === 'html'){
8056
8137
  type = 'markdown';
8138
+ }else if(field.type === 'url' && field.show_as_qr){
8139
+ type = 'qr-code';
8057
8140
  }
8058
8141
  let className = "";
8059
8142
  if(field.type === 'textarea'){
@@ -8081,7 +8164,13 @@ async function getTableColumns$1(fields, options){
8081
8164
 
8082
8165
  }
8083
8166
  // columns.push(getOperation(fields));
8084
-
8167
+ if(!___default__namespace.some(columns, { name: options.labelFieldName })){
8168
+ const href = Router$1.getObjectDetailPath({
8169
+ ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
8170
+ });
8171
+ columns[0].type = "tpl";
8172
+ columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
8173
+ }
8085
8174
  return columns;
8086
8175
  }
8087
8176
 
@@ -8447,6 +8536,8 @@ async function getTableApi(mainObject, fields, options){
8447
8536
 
8448
8537
  const fileFields = {};
8449
8538
  const fileFieldsKeys = [];
8539
+ // 含有optionsFunction属性, 无reference_to属性的lookup字段
8540
+ const lookupFields = {};
8450
8541
  fields.forEach((item)=>{
8451
8542
  if(___default__namespace.includes(['image','avatar','file'], item.type)){
8452
8543
  fileFieldsKeys.push(item.name);
@@ -8456,6 +8547,9 @@ async function getTableApi(mainObject, fields, options){
8456
8547
  multiple: item.multiple
8457
8548
  };
8458
8549
  }
8550
+ if(___default__namespace.includes(['lookup'], item.type) && !item.reference_to ){
8551
+ lookupFields[item.name] = item;
8552
+ }
8459
8553
  });
8460
8554
 
8461
8555
  let valueField = mainObject.key_field || '_id';
@@ -8472,6 +8566,7 @@ async function getTableApi(mainObject, fields, options){
8472
8566
  api.data.filter = "$filter";
8473
8567
  api.data.loaded = "${loaded}";
8474
8568
  api.data.listViewId = "${listViewId}";
8569
+ api.data.listName = "${listName}";
8475
8570
  api.requestAdaptor = `
8476
8571
  // selfData 中的数据由 CRUD 控制. selfData中,只能获取到 CRUD 给定的data. 无法从数据链中获取数据.
8477
8572
  let selfData = JSON.parse(JSON.stringify(api.data.$self));
@@ -8502,9 +8597,13 @@ async function getTableApi(mainObject, fields, options){
8502
8597
  console.error("本地存储中crud参数解析异常:", ex);
8503
8598
  }
8504
8599
  ${baseFilters ? `var systemFilters = ${JSON.stringify(baseFilters)};` : 'var systemFilters = [];'}
8600
+ var _ids = []
8505
8601
  const filtersFunction = ${filtersFunction};
8506
8602
  if(filtersFunction){
8507
8603
  const _filters = filtersFunction(systemFilters, api.data.$self);
8604
+ if(api.data.listName == "recent"){
8605
+ _ids = _filters[2]
8606
+ }
8508
8607
  if(_filters && _filters.length > 0){
8509
8608
  if(_.isEmpty(systemFilters)){
8510
8609
  systemFilters = _filters || [];
@@ -8616,6 +8715,7 @@ async function getTableApi(mainObject, fields, options){
8616
8715
  filters = [filters, 'and', userFilters]
8617
8716
  }
8618
8717
  }
8718
+ api.data._ids = _ids;
8619
8719
  api.data = {
8620
8720
  query: api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim())
8621
8721
  }
@@ -8623,6 +8723,11 @@ async function getTableApi(mainObject, fields, options){
8623
8723
  return api;
8624
8724
  `;
8625
8725
  api.adaptor = `
8726
+ if(api.body.listName == "recent"){
8727
+ payload.data.rows = _.sortBy(payload.data.rows, function(item){
8728
+ return _.indexOf(api.body._ids, item._id)
8729
+ });
8730
+ }
8626
8731
  const enable_tree = ${mainObject.enable_tree};
8627
8732
  if(!enable_tree){
8628
8733
  _.each(payload.data.rows, function(item, index){
@@ -8633,9 +8738,10 @@ async function getTableApi(mainObject, fields, options){
8633
8738
  }
8634
8739
  window.postMessage(Object.assign({type: "listview.loaded"}), "*");
8635
8740
  let fileFields = ${JSON.stringify(fileFields)};
8741
+ let lookupFields = ${JSON.stringify(lookupFields)};
8636
8742
  _.each(payload.data.rows, function(item, index){
8637
8743
  _.each(fileFields , (field, key)=>{
8638
- if(item[key] && item._display && item._display [key]){
8744
+ if(item[key] && item._display && item._display[key]){
8639
8745
  let value = item._display[key];
8640
8746
  if(!_.isArray(value)){
8641
8747
  value = [value]
@@ -8647,6 +8753,14 @@ async function getTableApi(mainObject, fields, options){
8647
8753
  }
8648
8754
  }
8649
8755
  })
8756
+ _.each(lookupFields , (field, key)=>{
8757
+ if(item[key]){
8758
+ if(field._optionsFunction){
8759
+ const optionsFunction = eval("(" + field._optionsFunction+ ")")(item);
8760
+ item[key + '__label'] = _.map(_.filter(optionsFunction, function(option){return _.includes(item[key], option.value)}), 'label').join(' ');
8761
+ }
8762
+ }
8763
+ })
8650
8764
  })
8651
8765
 
8652
8766
  if(enable_tree){
@@ -9976,6 +10090,24 @@ async function getListSchema(
9976
10090
 
9977
10091
  ctx.defaults = defaults;
9978
10092
 
10093
+ if (listViewName == "recent") {
10094
+ listview_filters = `
10095
+ function(filters, data) {
10096
+ var result = Steedos.authRequest('/graphql', {
10097
+ type: 'POST',
10098
+ async: false,
10099
+ data: JSON.stringify({
10100
+ query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
10101
+ }),
10102
+ });
10103
+ var _ids = []
10104
+ result.data.object_recent_viewed.forEach(function (item) {
10105
+ _ids = _ids.concat(item.record.ids)
10106
+ })
10107
+ return ["_id", "=", _ids];
10108
+ }
10109
+ `;
10110
+ }
9979
10111
  const amisSchema = {
9980
10112
  "type": "steedos-object-table",
9981
10113
  "objectApiName": objectName,
@@ -13711,6 +13843,7 @@ var AmisObjectListView = function (props) { return __awaiter(void 0, void 0, voi
13711
13843
  // className不传入crud组件,crud单独识别crudClassName属性
13712
13844
  listSchema.className = crudClassName;
13713
13845
  listSchema.onEvent = {}; // 为啥要将一个内置event放在此处?
13846
+ // 下面expression中_isRelated参数判断的是列表视图分栏模式下,新建、编辑、删除相关子表记录时不应该刷新左侧(主表)列表视图组件
13714
13847
  listSchema.onEvent["@data.changed.".concat(objectApiName)] = {
13715
13848
  "actions": [
13716
13849
  {
@@ -15290,7 +15423,7 @@ var getSelectFlowSchema = function (id, props) {
15290
15423
  "method": "post",
15291
15424
  "url": "${context.rootUrl}/graphql?keywords=${keywords}",
15292
15425
  "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 "),
15293
- "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 ",
15426
+ "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 ",
15294
15427
  "headers": {
15295
15428
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
15296
15429
  }