@steedos-widgets/amis-lib 1.2.12 → 1.2.14

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",
@@ -5495,6 +5519,10 @@ async function lookupToAmisPicker(field, readonly, ctx){
5495
5519
  };
5496
5520
  }
5497
5521
 
5522
+ if(field.pickerSchema){
5523
+ pickerSchema = Object.assign({}, pickerSchema, field.pickerSchema);
5524
+ }
5525
+
5498
5526
  const data = {
5499
5527
  type: getAmisStaticFieldType('picker', readonly),
5500
5528
  labelField: referenceTo.labelField.name,
@@ -5870,8 +5898,8 @@ async function getIdsPickerSchema(field, readonly, ctx){
5870
5898
  /*
5871
5899
  * @Author: baozhoutao@steedos.com
5872
5900
  * @Date: 2023-01-13 17:27:54
5873
- * @LastEditors: baozhoutao@steedos.com
5874
- * @LastEditTime: 2023-01-16 10:36:27
5901
+ * @LastEditors: Please set LastEditors
5902
+ * @LastEditTime: 2023-05-31 13:34:22
5875
5903
  * @Description:
5876
5904
  */
5877
5905
 
@@ -5913,8 +5941,12 @@ const getMarkdownFieldSchema = (field, readonly, ctx)=>{
5913
5941
  const getHtmlFieldSchema = (field, readonly, ctx)=>{
5914
5942
  if(readonly){
5915
5943
  return {
5916
- "type": "html",
5917
- "name": field.name
5944
+ "type": "control",
5945
+ "label": field.label,
5946
+ "body": {
5947
+ "type": "html",
5948
+ "name": field.name
5949
+ }
5918
5950
  }
5919
5951
  }else {
5920
5952
  return {
@@ -5941,8 +5973,8 @@ const getHtmlFieldSchema = (field, readonly, ctx)=>{
5941
5973
  /*
5942
5974
  * @Author: baozhoutao@steedos.com
5943
5975
  * @Date: 2022-10-28 14:52:55
5944
- * @LastEditors: baozhoutao@steedos.com
5945
- * @LastEditTime: 2022-10-28 14:53:02
5976
+ * @LastEditors: Please set LastEditors
5977
+ * @LastEditTime: 2023-05-31 13:25:53
5946
5978
  * @Description:
5947
5979
  */
5948
5980
 
@@ -6491,8 +6523,19 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6491
6523
  break;
6492
6524
  case 'url':
6493
6525
  convertData = {
6494
- type: getAmisStaticFieldType('url', readonly)
6526
+ type: getAmisStaticFieldType('url', readonly, field)
6495
6527
  };
6528
+ if(readonly && field.show_as_qr){
6529
+ convertData = {
6530
+ type: "control",
6531
+ label: field.label,
6532
+ body: {
6533
+ type: "qr-code",
6534
+ codeSize: 128,
6535
+ name: field.name
6536
+ }
6537
+ };
6538
+ }
6496
6539
  break;
6497
6540
  case 'email':
6498
6541
  convertData = {
@@ -6527,6 +6570,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
6527
6570
  case 'code':
6528
6571
  convertData = {
6529
6572
  type: "editor",
6573
+ disabled: readonly ? true : false,
6530
6574
  language: field.language,
6531
6575
  editorDidMount: new Function('editor', 'monaco', field.editorDidMount)
6532
6576
  };
@@ -7109,12 +7153,12 @@ function getBatchDelete(objectName){
7109
7153
  /*
7110
7154
  * @Author: baozhoutao@steedos.com
7111
7155
  * @Date: 2022-05-26 16:02:08
7112
- * @LastEditors: baozhoutao@steedos.com
7113
- * @LastEditTime: 2023-03-13 16:01:40
7156
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
7157
+ * @LastEditTime: 2023-06-02 16:54:41
7114
7158
  * @Description:
7115
7159
  */
7116
7160
 
7117
- const getFieldSchemaArray = (formFields)=>{
7161
+ const getFieldSchemaArray = (formFields) => {
7118
7162
  let fieldSchemaArray = [];
7119
7163
  fieldSchemaArray.length = 0;
7120
7164
 
@@ -7127,10 +7171,10 @@ const getFieldSchemaArray = (formFields)=>{
7127
7171
  // field.group = field.label
7128
7172
  field.is_wide = true;
7129
7173
  }
7130
-
7131
- if (!isObjectField){
7132
- if(!field.hidden){
7133
- fieldSchemaArray.push(Object.assign({name: fieldName}, field, {permission: {allowEdit: true}}));
7174
+
7175
+ if (!isObjectField) {
7176
+ if (!field.hidden) {
7177
+ fieldSchemaArray.push(Object.assign({ name: fieldName }, field, { permission: { allowEdit: true } }));
7134
7178
  }
7135
7179
  }
7136
7180
  });
@@ -7138,58 +7182,104 @@ const getFieldSchemaArray = (formFields)=>{
7138
7182
  };
7139
7183
 
7140
7184
  const getSection = async (formFields, permissionFields, fieldSchemaArray, sectionName, ctx) => {
7185
+ if (!ctx) {
7186
+ ctx = {};
7187
+ }
7141
7188
  const sectionFields = ___namespace.filter(fieldSchemaArray, { 'group': sectionName });
7142
- if(sectionFields.length == ___namespace.filter(sectionFields, ['hidden', true]).length){
7143
- return ;
7189
+ if (sectionFields.length == ___namespace.filter(sectionFields, ['hidden', true]).length) {
7190
+ return;
7144
7191
  }
7145
7192
 
7146
7193
  const fieldSetBody = [];
7147
7194
 
7148
7195
  for (const perField of sectionFields) {
7149
7196
  let field = perField;
7150
- if(perField.type === 'grid'){
7151
- field = await getGridFieldSubFields(perField, formFields);
7152
- // console.log(`perField.type grid ===> field`, field)
7153
- }else if(perField.type === 'object'){
7154
- field = await getObjectFieldSubFields(perField, formFields);
7155
- // console.log(`perField.type object ===> field`, field)
7156
- }
7157
- if(field.name.indexOf(".") < 0){
7158
- ctx.__formFields = formFields;
7159
- const amisField = await convertSFieldToAmisField(field, field.readonly, ctx);
7160
- // console.log(`${field.name} amisField`, field, amisField)
7161
- if(amisField){
7162
- fieldSetBody.push(amisField);
7163
- }
7197
+ if (perField.type === 'grid') {
7198
+ field = await getGridFieldSubFields(perField, formFields);
7199
+ // console.log(`perField.type grid ===> field`, field)
7200
+ } else if (perField.type === 'object') {
7201
+ field = await getObjectFieldSubFields(perField, formFields);
7202
+ // console.log(`perField.type object ===> field`, field)
7203
+ }
7204
+ if (field.name.indexOf(".") < 0) {
7205
+ ctx.__formFields = formFields;
7206
+ const amisField = await convertSFieldToAmisField(field, field.readonly, ctx);
7207
+ // console.log(`${field.name} amisField`, field, amisField)
7208
+ if (amisField) {
7209
+ fieldSetBody.push(amisField);
7164
7210
  }
7211
+ }
7165
7212
  }
7166
7213
 
7167
7214
  // fieldSet 已支持显隐控制
7168
- const sectionFieldsVisibleOn = ___namespace.map(___namespace.compact(___namespace.map(fieldSetBody, 'visibleOn')) , (visibleOn)=>{
7215
+ const sectionFieldsVisibleOn = ___namespace.map(___namespace.compact(___namespace.map(fieldSetBody, 'visibleOn')), (visibleOn) => {
7169
7216
  return visibleOn;
7170
7217
  });
7171
- const section = {
7218
+
7219
+ let section = {
7172
7220
  "type": "fieldSet",
7173
7221
  "title": sectionName,
7174
7222
  "collapsable": true,
7175
7223
  "body": fieldSetBody,
7176
7224
  };
7177
- if(sectionFieldsVisibleOn.length > 0 && fieldSetBody.length === sectionFieldsVisibleOn.length){
7225
+
7226
+ if (ctx.enableTabs) {
7227
+ section = {
7228
+ "title": sectionName,
7229
+ "body": fieldSetBody,
7230
+ };
7231
+ }
7232
+
7233
+ if (sectionFieldsVisibleOn.length > 0 && fieldSetBody.length === sectionFieldsVisibleOn.length) {
7178
7234
  section.visibleOn = `${sectionFieldsVisibleOn.join(" || ")}`;
7179
7235
  }
7180
7236
  return section
7181
7237
  };
7182
7238
 
7183
7239
  const getSections = async (permissionFields, formFields, ctx) => {
7240
+ if (!ctx) {
7241
+ ctx = {};
7242
+ }
7184
7243
  const fieldSchemaArray = getFieldSchemaArray(formFields);
7185
7244
  const _sections = ___namespace.groupBy(fieldSchemaArray, 'group');
7186
7245
  const sections = [];
7246
+ var sectionVisibleOns = [];
7187
7247
  for (const key in _sections) {
7188
7248
  const section = await getSection(formFields, permissionFields, fieldSchemaArray, key, ctx);
7189
- if(section.body.length > 0){
7249
+ if (section.body.length > 0) {
7250
+ if (section.visibleOn) {
7251
+ sectionVisibleOns.push(section.visibleOn);
7252
+ }
7253
+ else {
7254
+ sectionVisibleOns.push("true");
7255
+ }
7190
7256
  sections.push(section);
7191
7257
  }
7192
7258
  }
7259
+ /*
7260
+ 为了实现只有一个分组时隐藏该分组标题,需要分三种情况(分组如果没有visibleon属性就代表一定显示,有visibleon需要进行判断)
7261
+ 1 当前分组为隐藏时,标题就设置为隐藏
7262
+ 2 当前分组为显示时,其他分组只要有一个是显示,就显示该分组标题
7263
+ 3 当前分组为显示时,其他分组都隐藏,就隐藏该分组标题
7264
+ */
7265
+ sections.forEach((section, index) => {
7266
+ var tempSectionVisibleOns = sectionVisibleOns.slice();
7267
+ tempSectionVisibleOns.splice(index, 1);
7268
+ section.headingClassName = {
7269
+ "hidden": `!((${tempSectionVisibleOns.join(" || ") || 'false'}) && ${sectionVisibleOns[index]})`
7270
+ };
7271
+ });
7272
+
7273
+ if (ctx.enableTabs) {
7274
+ return [
7275
+ {
7276
+ "type": "tabs",
7277
+ "tabs": sections,
7278
+ "tabsMode": ctx.tabsMode
7279
+ }
7280
+ ]
7281
+ }
7282
+
7193
7283
  return sections;
7194
7284
  };
7195
7285
 
@@ -7704,6 +7794,8 @@ async function getTableColumns(fields, options){
7704
7794
  type = 'tpl';
7705
7795
  }else if(field.type === 'html'){
7706
7796
  type = 'markdown';
7797
+ }else if(field.type === 'url' && field.show_as_qr){
7798
+ type = 'qr-code';
7707
7799
  }
7708
7800
  let className = "";
7709
7801
  if(field.type === 'textarea'){
@@ -7731,7 +7823,13 @@ async function getTableColumns(fields, options){
7731
7823
 
7732
7824
  }
7733
7825
  // columns.push(getOperation(fields));
7734
-
7826
+ if(!___namespace.some(columns, { name: options.labelFieldName })){
7827
+ const href = Router.getObjectDetailPath({
7828
+ ...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
7829
+ });
7830
+ columns[0].type = "tpl";
7831
+ columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
7832
+ }
7735
7833
  return columns;
7736
7834
  }
7737
7835
 
@@ -8097,6 +8195,8 @@ async function getTableApi(mainObject, fields, options){
8097
8195
 
8098
8196
  const fileFields = {};
8099
8197
  const fileFieldsKeys = [];
8198
+ // 含有optionsFunction属性, 无reference_to属性的lookup字段
8199
+ const lookupFields = {};
8100
8200
  fields.forEach((item)=>{
8101
8201
  if(___namespace.includes(['image','avatar','file'], item.type)){
8102
8202
  fileFieldsKeys.push(item.name);
@@ -8106,6 +8206,9 @@ async function getTableApi(mainObject, fields, options){
8106
8206
  multiple: item.multiple
8107
8207
  };
8108
8208
  }
8209
+ if(___namespace.includes(['lookup'], item.type) && !item.reference_to ){
8210
+ lookupFields[item.name] = item;
8211
+ }
8109
8212
  });
8110
8213
 
8111
8214
  let valueField = mainObject.key_field || '_id';
@@ -8122,6 +8225,7 @@ async function getTableApi(mainObject, fields, options){
8122
8225
  api.data.filter = "$filter";
8123
8226
  api.data.loaded = "${loaded}";
8124
8227
  api.data.listViewId = "${listViewId}";
8228
+ api.data.listName = "${listName}";
8125
8229
  api.requestAdaptor = `
8126
8230
  // selfData 中的数据由 CRUD 控制. selfData中,只能获取到 CRUD 给定的data. 无法从数据链中获取数据.
8127
8231
  let selfData = JSON.parse(JSON.stringify(api.data.$self));
@@ -8152,9 +8256,13 @@ async function getTableApi(mainObject, fields, options){
8152
8256
  console.error("本地存储中crud参数解析异常:", ex);
8153
8257
  }
8154
8258
  ${baseFilters ? `var systemFilters = ${JSON.stringify(baseFilters)};` : 'var systemFilters = [];'}
8259
+ var _ids = []
8155
8260
  const filtersFunction = ${filtersFunction};
8156
8261
  if(filtersFunction){
8157
8262
  const _filters = filtersFunction(systemFilters, api.data.$self);
8263
+ if(api.data.listName == "recent"){
8264
+ _ids = _filters[2]
8265
+ }
8158
8266
  if(_filters && _filters.length > 0){
8159
8267
  if(_.isEmpty(systemFilters)){
8160
8268
  systemFilters = _filters || [];
@@ -8266,6 +8374,7 @@ async function getTableApi(mainObject, fields, options){
8266
8374
  filters = [filters, 'and', userFilters]
8267
8375
  }
8268
8376
  }
8377
+ api.data._ids = _ids;
8269
8378
  api.data = {
8270
8379
  query: api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim())
8271
8380
  }
@@ -8273,6 +8382,11 @@ async function getTableApi(mainObject, fields, options){
8273
8382
  return api;
8274
8383
  `;
8275
8384
  api.adaptor = `
8385
+ if(api.body.listName == "recent"){
8386
+ payload.data.rows = _.sortBy(payload.data.rows, function(item){
8387
+ return _.indexOf(api.body._ids, item._id)
8388
+ });
8389
+ }
8276
8390
  const enable_tree = ${mainObject.enable_tree};
8277
8391
  if(!enable_tree){
8278
8392
  _.each(payload.data.rows, function(item, index){
@@ -8283,9 +8397,10 @@ async function getTableApi(mainObject, fields, options){
8283
8397
  }
8284
8398
  window.postMessage(Object.assign({type: "listview.loaded"}), "*");
8285
8399
  let fileFields = ${JSON.stringify(fileFields)};
8400
+ let lookupFields = ${JSON.stringify(lookupFields)};
8286
8401
  _.each(payload.data.rows, function(item, index){
8287
8402
  _.each(fileFields , (field, key)=>{
8288
- if(item[key] && item._display && item._display [key]){
8403
+ if(item[key] && item._display && item._display[key]){
8289
8404
  let value = item._display[key];
8290
8405
  if(!_.isArray(value)){
8291
8406
  value = [value]
@@ -8297,6 +8412,14 @@ async function getTableApi(mainObject, fields, options){
8297
8412
  }
8298
8413
  }
8299
8414
  })
8415
+ _.each(lookupFields , (field, key)=>{
8416
+ if(item[key]){
8417
+ if(field._optionsFunction){
8418
+ const optionsFunction = eval("(" + field._optionsFunction+ ")")(item);
8419
+ item[key + '__label'] = _.map(_.filter(optionsFunction, function(option){return _.includes(item[key], option.value)}), 'label').join(' ');
8420
+ }
8421
+ }
8422
+ })
8300
8423
  })
8301
8424
 
8302
8425
  if(enable_tree){
@@ -9626,6 +9749,24 @@ async function getListSchema(
9626
9749
 
9627
9750
  ctx.defaults = defaults;
9628
9751
 
9752
+ if (listViewName == "recent") {
9753
+ listview_filters = `
9754
+ function(filters, data) {
9755
+ var result = Steedos.authRequest('/graphql', {
9756
+ type: 'POST',
9757
+ async: false,
9758
+ data: JSON.stringify({
9759
+ query: '{object_recent_viewed(filters: [["record.o","=","' + data.objectName + '"],["space","=","' + data.context.tenantId + '"],["owner","=","' + data.context.userId + '"]],sort:"modified desc",top:50){ _id,record} }'
9760
+ }),
9761
+ });
9762
+ var _ids = []
9763
+ result.data.object_recent_viewed.forEach(function (item) {
9764
+ _ids = _ids.concat(item.record.ids)
9765
+ })
9766
+ return ["_id", "=", _ids];
9767
+ }
9768
+ `;
9769
+ }
9629
9770
  const amisSchema = {
9630
9771
  "type": "steedos-object-table",
9631
9772
  "objectApiName": objectName,