@steedos-widgets/amis-lib 1.2.12 → 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
  },
@@ -4655,12 +4671,13 @@ const getSettingListviewToolbarButtonSchema = ()=>{
4655
4671
  "type": "dropdown-button",
4656
4672
  "trigger": "click",
4657
4673
  "icon": "fa fa-cog",
4674
+ "tooltip": "列表视图控制",
4658
4675
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
4659
4676
  "align": "right",
4660
4677
  "visibleOn": "${!isLookup}",
4661
4678
  "buttons": [
4662
4679
  {
4663
- "label": "列表视图操作",
4680
+ "label": "列表视图控制",
4664
4681
  "children": [
4665
4682
  getNewListviewButtonSchema(),
4666
4683
  getCopyListviewButtonSchema(),
@@ -4694,9 +4711,11 @@ const getDisplayAsButton = function(objectName, showDisplayAs){
4694
4711
  "rightIconClassName": "m-l-sm"
4695
4712
  }
4696
4713
  ];
4714
+ const displayAsLabel = displayAs === 'split'? "分栏视图" : "表格";
4697
4715
  return {
4698
4716
  "type": "dropdown-button",
4699
4717
  "icon": "fa fa-table-columns",
4718
+ "tooltip": `显示为 ${displayAsLabel}`,
4700
4719
  "btnClassName": "antd-Button--iconOnly bg-white p-2 rounded border-gray-300 text-gray-500",
4701
4720
  "align": "right",
4702
4721
  "visibleOn": "${window:innerWidth > 768 && !!!isLookup}",
@@ -4776,6 +4795,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4776
4795
  // "type": "reload",//不可以直接使用reload,因为它不会设置页码到第一页
4777
4796
  "type": "button",
4778
4797
  "align": "right",
4798
+ "tooltip": "刷新",
4779
4799
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
4780
4800
  "label": "",
4781
4801
  "icon": "fa fa-sync",
@@ -4795,6 +4815,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4795
4815
  "label": "",
4796
4816
  "icon": "fa fa-search",
4797
4817
  "type": "button",
4818
+ "tooltip": "搜索",
4798
4819
  "badge": {
4799
4820
  "offset": [
4800
4821
  -5,
@@ -4839,6 +4860,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4839
4860
  {
4840
4861
  "type": "reload",
4841
4862
  "align": "right",
4863
+ "tooltip": "刷新",
4842
4864
  "tooltipPlacement": "bottom",
4843
4865
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500"
4844
4866
  },
@@ -4846,6 +4868,8 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4846
4868
  filterVisible ? {
4847
4869
  "label": "",
4848
4870
  "icon": "fa fa-search",
4871
+ "tooltip": "搜索",
4872
+ "tooltipPlacement": "bottom",
4849
4873
  "type": "button",
4850
4874
  "align": "right",
4851
4875
  "className": "bg-white p-2 rounded border-gray-300 text-gray-500",
@@ -5870,8 +5894,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
5870
5894
  /*
5871
5895
  * @Author: baozhoutao@steedos.com
5872
5896
  * @Date: 2023-01-13 17:27:54
5873
- * @LastEditors: baozhoutao@steedos.com
5874
- * @LastEditTime: 2023-01-16 10:36:27
5897
+ * @LastEditors: Please set LastEditors
5898
+ * @LastEditTime: 2023-05-31 13:34:22
5875
5899
  * @Description:
5876
5900
  */
5877
5901
 
@@ -5913,8 +5937,12 @@ const getMarkdownFieldSchema = (field, readonly, ctx)=>{
5913
5937
  const getHtmlFieldSchema = (field, readonly, ctx)=>{
5914
5938
  if(readonly){
5915
5939
  return {
5916
- "type": "html",
5917
- "name": field.name
5940
+ "type": "control",
5941
+ "label": field.label,
5942
+ "body": {
5943
+ "type": "html",
5944
+ "name": field.name
5945
+ }
5918
5946
  }
5919
5947
  }else {
5920
5948
  return {
@@ -5941,8 +5969,8 @@ const getHtmlFieldSchema = (field, readonly, ctx)=>{
5941
5969
  /*
5942
5970
  * @Author: baozhoutao@steedos.com
5943
5971
  * @Date: 2022-10-28 14:52:55
5944
- * @LastEditors: baozhoutao@steedos.com
5945
- * @LastEditTime: 2022-10-28 14:53:02
5972
+ * @LastEditors: Please set LastEditors
5973
+ * @LastEditTime: 2023-05-31 13:25:53
5946
5974
  * @Description:
5947
5975
  */
5948
5976
 
@@ -6491,8 +6519,19 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6491
6519
  break;
6492
6520
  case 'url':
6493
6521
  convertData = {
6494
- type: getAmisStaticFieldType('url', readonly)
6522
+ type: getAmisStaticFieldType('url', readonly, field)
6495
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
+ }
6496
6535
  break;
6497
6536
  case 'email':
6498
6537
  convertData = {
@@ -6527,6 +6566,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6527
6566
  case 'code':
6528
6567
  convertData = {
6529
6568
  type: "editor",
6569
+ disabled: readonly ? true : false,
6530
6570
  language: field.language,
6531
6571
  editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
6532
6572
  };
@@ -7184,12 +7224,43 @@ const getSections = async (permissionFields, formFields, ctx) => {
7184
7224
  const fieldSchemaArray = getFieldSchemaArray(formFields);
7185
7225
  const _sections = ___namespace.groupBy(fieldSchemaArray, 'group');
7186
7226
  const sections = [];
7227
+ var sectionHeaderVisibleOn=[];
7187
7228
  for (const key in _sections) {
7188
7229
  const section = await getSection(formFields, permissionFields, fieldSchemaArray, key, ctx);
7189
7230
  if(section.body.length > 0){
7231
+ if(section.visibleOn){
7232
+ sectionHeaderVisibleOn.push(section.visibleOn);
7233
+ }
7190
7234
  sections.push(section);
7191
7235
  }
7192
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
+
7193
7264
  return sections;
7194
7265
  };
7195
7266
 
@@ -7704,6 +7775,8 @@ async function getTableColumns(fields, options){
7704
7775
  type = 'tpl';
7705
7776
  }else if(field.type === 'html'){
7706
7777
  type = 'markdown';
7778
+ }else if(field.type === 'url' && field.show_as_qr){
7779
+ type = 'qr-code';
7707
7780
  }
7708
7781
  let className = "";
7709
7782
  if(field.type === 'textarea'){
@@ -7731,7 +7804,13 @@ async function getTableColumns(fields, options){
7731
7804
 
7732
7805
  }
7733
7806
  // columns.push(getOperation(fields));
7734
-
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
+ }
7735
7814
  return columns;
7736
7815
  }
7737
7816
 
@@ -8097,6 +8176,8 @@ async function getTableApi(mainObject, fields, options){
8097
8176
 
8098
8177
  const fileFields = {};
8099
8178
  const fileFieldsKeys = [];
8179
+ // 含有optionsFunction属性, 无reference_to属性的lookup字段
8180
+ const lookupFields = {};
8100
8181
  fields.forEach((item)=>{
8101
8182
  if(___namespace.includes(['image','avatar','file'], item.type)){
8102
8183
  fileFieldsKeys.push(item.name);
@@ -8106,6 +8187,9 @@ async function getTableApi(mainObject, fields, options){
8106
8187
  multiple: item.multiple
8107
8188
  };
8108
8189
  }
8190
+ if(___namespace.includes(['lookup'], item.type) && !item.reference_to ){
8191
+ lookupFields[item.name] = item;
8192
+ }
8109
8193
  });
8110
8194
 
8111
8195
  let valueField = mainObject.key_field || '_id';
@@ -8122,6 +8206,7 @@ async function getTableApi(mainObject, fields, options){
8122
8206
  api.data.filter = "$filter";
8123
8207
  api.data.loaded = "${loaded}";
8124
8208
  api.data.listViewId = "${listViewId}";
8209
+ api.data.listName = "${listName}";
8125
8210
  api.requestAdaptor = `
8126
8211
  // selfData 中的数据由 CRUD 控制. selfData中,只能获取到 CRUD 给定的data. 无法从数据链中获取数据.
8127
8212
  let selfData = JSON.parse(JSON.stringify(api.data.$self));
@@ -8152,9 +8237,13 @@ async function getTableApi(mainObject, fields, options){
8152
8237
  console.error("本地存储中crud参数解析异常:", ex);
8153
8238
  }
8154
8239
  ${baseFilters ? `var systemFilters = ${JSON.stringify(baseFilters)};` : 'var systemFilters = [];'}
8240
+ var _ids = []
8155
8241
  const filtersFunction = ${filtersFunction};
8156
8242
  if(filtersFunction){
8157
8243
  const _filters = filtersFunction(systemFilters, api.data.$self);
8244
+ if(api.data.listName == "recent"){
8245
+ _ids = _filters[2]
8246
+ }
8158
8247
  if(_filters && _filters.length > 0){
8159
8248
  if(_.isEmpty(systemFilters)){
8160
8249
  systemFilters = _filters || [];
@@ -8266,6 +8355,7 @@ async function getTableApi(mainObject, fields, options){
8266
8355
  filters = [filters, 'and', userFilters]
8267
8356
  }
8268
8357
  }
8358
+ api.data._ids = _ids;
8269
8359
  api.data = {
8270
8360
  query: api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim())
8271
8361
  }
@@ -8273,6 +8363,11 @@ async function getTableApi(mainObject, fields, options){
8273
8363
  return api;
8274
8364
  `;
8275
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
+ }
8276
8371
  const enable_tree = ${mainObject.enable_tree};
8277
8372
  if(!enable_tree){
8278
8373
  _.each(payload.data.rows, function(item, index){
@@ -8283,9 +8378,10 @@ async function getTableApi(mainObject, fields, options){
8283
8378
  }
8284
8379
  window.postMessage(Object.assign({type: "listview.loaded"}), "*");
8285
8380
  let fileFields = ${JSON.stringify(fileFields)};
8381
+ let lookupFields = ${JSON.stringify(lookupFields)};
8286
8382
  _.each(payload.data.rows, function(item, index){
8287
8383
  _.each(fileFields , (field, key)=>{
8288
- if(item[key] && item._display && item._display [key]){
8384
+ if(item[key] && item._display && item._display[key]){
8289
8385
  let value = item._display[key];
8290
8386
  if(!_.isArray(value)){
8291
8387
  value = [value]
@@ -8297,6 +8393,14 @@ async function getTableApi(mainObject, fields, options){
8297
8393
  }
8298
8394
  }
8299
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
+ })
8300
8404
  })
8301
8405
 
8302
8406
  if(enable_tree){
@@ -9626,6 +9730,24 @@ async function getListSchema(
9626
9730
 
9627
9731
  ctx.defaults = defaults;
9628
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
+ }
9629
9751
  const amisSchema = {
9630
9752
  "type": "steedos-object-table",
9631
9753
  "objectApiName": objectName,