@steedos-widgets/amis-lib 1.3.4-beta.15 → 1.3.4-beta.17

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.esm.js CHANGED
@@ -2570,20 +2570,29 @@ function getButtonVisibleOn$1(button){
2570
2570
  // return 'false';
2571
2571
  // }
2572
2572
  if(visible.trim().startsWith('function')){
2573
- return `${visible}.apply({
2573
+ visible = `${visible}.apply({
2574
2574
  object: uiSchema
2575
- }, [objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`
2575
+ }, [objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`;
2576
2576
  }
2577
- return visible;
2578
2577
  }
2579
2578
 
2580
2579
  if(button.type === 'amis_button'){
2581
- const amisSchema = button.amis_schema;
2580
+ let amisSchema = button.amis_schema;
2581
+ if(_$1.isString(amisSchema)){
2582
+ amisSchema = JSON.parse(amisSchema);
2583
+ }
2582
2584
  if(amisSchema && amisSchema.body && amisSchema.body.length > 0){
2583
2585
  const btn1 = amisSchema.body[0];
2584
- return btn1.visibleOn
2586
+ if(_$1.hasIn(btn1, 'visibleOn')){
2587
+ /* 当含有“更多”按钮或者“下拉”箭头按钮时,单个按钮的visibleOn需要合并到 “更多”按钮或者“下拉”箭头按钮的 visibleOn 中,用||隔开。
2588
+ visibleOn的格式需要保持一致; 不能是 js 和 ${xxx} 混合的表达式;
2589
+ visibleOn的值需要是js格式,因为默认的编辑、删除等系统按钮的visibleOn的格式就是js格式(function(){});
2590
+ */
2591
+ return btn1.visibleOn
2592
+ }
2585
2593
  }
2586
2594
  }
2595
+ return visible;
2587
2596
  }
2588
2597
 
2589
2598
  const getButtonVisible = (button, ctx) => {
@@ -5379,6 +5388,7 @@ function getObjectHeaderToolbar(mainObject, fields, formFactor, {
5379
5388
  }
5380
5389
 
5381
5390
  function getObjectFooterToolbar(mainObject, formFactor, options) {
5391
+ // crud card模式与table模式两种情况下showPageInput默认值不一样,所以需要显式设置为false
5382
5392
  if (formFactor === 'SMALL') {
5383
5393
  // return [
5384
5394
  // "load-more",
@@ -5388,15 +5398,17 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
5388
5398
  "switch-per-page",
5389
5399
  {
5390
5400
  "type": "pagination",
5391
- "maxButtons": 5
5401
+ "maxButtons": 5,
5402
+ "showPageInput": false
5392
5403
  }
5393
5404
  ]
5394
5405
  }else {
5395
5406
  return [
5396
- "statistics",
5407
+ // "statistics",
5397
5408
  {
5398
5409
  "type": "pagination",
5399
- "maxButtons": 5
5410
+ "maxButtons": 5,
5411
+ "showPageInput": false
5400
5412
  }
5401
5413
  ]
5402
5414
  }
@@ -5405,7 +5417,11 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
5405
5417
  if(options && options.isRelated){
5406
5418
  return [
5407
5419
  "statistics",
5408
- "pagination"
5420
+ {
5421
+ "type": "pagination",
5422
+ "maxButtons": 10,
5423
+ "showPageInput": false
5424
+ }
5409
5425
  ]
5410
5426
 
5411
5427
  }
@@ -5413,7 +5429,11 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
5413
5429
  return [
5414
5430
  "switch-per-page",
5415
5431
  "statistics",
5416
- "pagination"
5432
+ {
5433
+ "type": "pagination",
5434
+ "maxButtons": 10,
5435
+ "showPageInput": false
5436
+ }
5417
5437
  ]
5418
5438
  }
5419
5439
  }
@@ -6296,15 +6316,17 @@ async function lookupToAmisSelect(field, readonly, ctx){
6296
6316
  var optionsFilters = [["${valueFieldKey}", optionsFiltersOp, []]];
6297
6317
  if (defaultValue && !api.data.$term) {
6298
6318
  const defaultValueOptionsQueryData = ${JSON.stringify(defaultValueOptionsQueryData)};
6299
- const defaultValueOptionsQuery = defaultValueOptionsQueryData.query.replace(/^{/,"").replace(/}$/,"");
6319
+ const defaultValueOptionsQuery = defaultValueOptionsQueryData?.query?.replace(/^{/,"").replace(/}$/,"");
6300
6320
  // 字段值单独请求,没值的时候在请求中返回空
6301
6321
  optionsFilters = [["${valueFieldKey}", optionsFiltersOp, defaultValue]];
6302
6322
  if(filters.length > 0){
6303
6323
  optionsFilters = [filters, optionsFilters];
6304
6324
  }
6305
- api.data.query = "{"+api.data.query.replace(/^{/,"").replace(/}$/,"")+","+defaultValueOptionsQuery+"}";
6306
- api.data.query = api.data.query.replace(/{__options_filters}/g, JSON.stringify(optionsFilters))
6325
+ if(defaultValueOptionsQuery){
6326
+ api.data.query = "{"+api.data.query.replace(/^{/,"").replace(/}$/,"")+","+defaultValueOptionsQuery+"}";
6327
+ }
6307
6328
  }
6329
+ api.data.query = api.data.query.replace(/{__options_filters}/g, JSON.stringify(optionsFilters));
6308
6330
  return api;
6309
6331
  `;
6310
6332
  referenceTo ? referenceTo.labelField.name : '';
@@ -7238,7 +7260,20 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
7238
7260
  type: getAmisStaticFieldType('number', readonly),
7239
7261
  min: field.min,
7240
7262
  max: field.max,
7241
- precision: field.scale
7263
+ precision: field.scale,
7264
+ suffix: "%",
7265
+ pipeIn: (value, data) => {
7266
+ if(value){
7267
+ return value*100;
7268
+ }
7269
+ return value;
7270
+ },
7271
+ pipeOut: (value, oldValue, data) => {
7272
+ if(value){
7273
+ return value/100;
7274
+ }
7275
+ return value;
7276
+ },
7242
7277
  };
7243
7278
  }
7244
7279
  break;
@@ -7734,7 +7769,7 @@ async function getQuickEditSchema(field, options){
7734
7769
  break;
7735
7770
  case "percent":
7736
7771
  TempDisplayField = `
7737
- _display["${field.name}"] = (event.data.value * 100).toFixed(${field.scale}) + '%';
7772
+ _display["${field.name}"] = event.data.value.toFixed(${field.scale}) + '%';
7738
7773
  `;
7739
7774
  quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
7740
7775
  break;
@@ -8365,23 +8400,86 @@ async function getTableOperation(ctx){
8365
8400
  }
8366
8401
  }
8367
8402
 
8403
+ async function getDefaultCrudCard(columns, options) {
8404
+ let labelFieldName = options?.labelFieldName || "name";
8405
+ let titleColumn, bodyColumns = [];
8406
+ columns.forEach(function (item) {
8407
+ delete item.quickEdit;
8408
+ delete item.width;
8409
+ if (item.name === labelFieldName) {
8410
+ titleColumn = item;
8411
+ }
8412
+ else {
8413
+ if (item.name !== "_index") {
8414
+ bodyColumns.push(item);
8415
+ }
8416
+ }
8417
+ });
8418
+ let card = {
8419
+ "header": {
8420
+ "title": titleColumn.tpl
8421
+ },
8422
+ body: bodyColumns,
8423
+ // useCardLabel: false,
8424
+ toolbar: []
8425
+ };
8426
+ let hideToolbarOperation = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
8427
+ if(!hideToolbarOperation){
8428
+ let toolbarOperation = await getTableOperation(options);
8429
+ if (toolbarOperation) {
8430
+ toolbarOperation.className += " inline-block w-auto";
8431
+ }
8432
+ card.toolbar.push(toolbarOperation);
8433
+ }
8434
+ return card;
8435
+ }
8436
+
8368
8437
  async function getTableSchema$1(fields, options){
8369
8438
  if(!options){
8370
8439
  options = {};
8371
8440
  }
8372
8441
  let { isLookup, hiddenColumnOperation } = options;
8442
+ const defaults = options.defaults;
8443
+ const listSchema = (defaults && defaults.listSchema) || {};
8444
+
8373
8445
  let columns = [];
8374
8446
  let useMobileColumns = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
8375
8447
  if(isLookup){
8376
8448
  // 在lookup手机端列表模式调式好之前不使用getMobileTableColumns
8377
8449
  useMobileColumns = false;
8378
8450
  }
8451
+ if(listSchema.mode && listSchema.mode !== "table"){
8452
+ // 如果指定的mode,则不走我们内置的手机端列表效果,使用steedos组件内部开发的默认card/list效果,或者由用户自己实现card/list模式的crud列表
8453
+ useMobileColumns = false;
8454
+ }
8379
8455
  if(useMobileColumns){
8380
8456
  columns = await getMobileTableColumns(fields, options);
8381
8457
  }
8382
8458
  else {
8383
8459
  columns = await getTableColumns(fields, options);
8384
8460
 
8461
+ if(listSchema.mode === "cards"){
8462
+ let card = listSchema.card;
8463
+ if(!card){
8464
+ card = await getDefaultCrudCard(columns, options);
8465
+ }
8466
+ return {
8467
+ mode: "cards",
8468
+ name: "thelist",
8469
+ headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
8470
+ className: "",
8471
+ draggable: false,
8472
+ defaultParams: getDefaultParams(options),
8473
+ card: card,
8474
+ syncLocation: false,
8475
+ keepItemSelectionOnPageChange: true,
8476
+ checkOnItemClick: isLookup ? true : false,
8477
+ labelTpl: `\${${options.labelFieldName}}`,
8478
+ autoFillHeight: false, // 自动高度效果不理想,先关闭
8479
+ columnsTogglable: false
8480
+ }
8481
+ }
8482
+
8385
8483
  if(!isLookup && !hiddenColumnOperation){
8386
8484
  columns.push(await getTableOperation(options));
8387
8485
  }
@@ -10121,6 +10219,9 @@ async function getObjectCRUD(objectSchema, fields, options){
10121
10219
  const nonpaged = objectSchema.paging && objectSchema.paging.enabled === false;
10122
10220
  const isTreeObject = objectSchema.enable_tree;
10123
10221
  const bulkActions = getBulkActions(objectSchema);
10222
+ const defaults = options.defaults;
10223
+ const listSchema = (defaults && defaults.listSchema) || {};
10224
+
10124
10225
  const bodyProps = {
10125
10226
  // toolbar: getToolbar(),
10126
10227
  // headerToolbar: getObjectHeaderToolbar(objectSchema, options.formFactor, {showDisplayAs}),
@@ -10132,9 +10233,12 @@ async function getObjectCRUD(objectSchema, fields, options){
10132
10233
  filter: options.filterVisible !== false && await getObjectFilter(objectSchema, fields, options),
10133
10234
  };
10134
10235
  if(options.formFactor !== 'SMALL' || ["split"].indexOf(options.displayAs) == -1){
10135
- Object.assign(bodyProps, {
10136
- bulkActions: options.bulkActions != false ? bulkActions : false
10137
- });
10236
+ if(listSchema.mode !== "cards"){
10237
+ // card模式时默认不显示勾选框
10238
+ Object.assign(bodyProps, {
10239
+ bulkActions: options.bulkActions != false ? bulkActions : false
10240
+ });
10241
+ }
10138
10242
  }
10139
10243
  // yml里配置的 不分页和enable_tree:true 优先级最高,组件中输入的top次之。
10140
10244
  options.queryCount = true;
@@ -10197,7 +10301,7 @@ async function getObjectCRUD(objectSchema, fields, options){
10197
10301
  }, options);
10198
10302
  tableOptions.amisData = createObject(options.amisData || {}, {});
10199
10303
  const table = await getTableSchema$1(fields, tableOptions);
10200
- delete table.mode;
10304
+ // delete table.mode;
10201
10305
  //image与avatar需要在提交修改时特别处理
10202
10306
  const imageNames = ___default.compact(___default.map(___default.filter(fields, (field) => ["image","avatar"].includes(field.type)), 'name'));
10203
10307
  const quickSaveApiRequestAdaptor = `
@@ -10267,12 +10371,14 @@ async function getObjectCRUD(objectSchema, fields, options){
10267
10371
 
10268
10372
  }
10269
10373
 
10270
- const defaults = options.defaults;
10271
-
10272
- const listSchema = (defaults && defaults.listSchema) || {};
10273
10374
  body = defaultsDeep({}, listSchema, body);
10274
10375
  body = await getCrudSchemaWithDataFilter(body, { crudDataFilter, onCrudDataFilter, amisData, env });
10275
10376
 
10377
+ let crudModeClassName = "";
10378
+ if(body.mode){
10379
+ crudModeClassName = `steedos-crud-mode-${body.mode}`;
10380
+ }
10381
+
10276
10382
  if (defaults) {
10277
10383
  const headerSchema = defaults.headerSchema;
10278
10384
  const footerSchema = defaults.footerSchema;
@@ -10301,7 +10407,7 @@ async function getObjectCRUD(objectSchema, fields, options){
10301
10407
  // TODO: data应该只留loaded,其他属性都改为从上层传递下来
10302
10408
  return {
10303
10409
  type: 'service',
10304
- className: '',
10410
+ className: crudModeClassName,
10305
10411
  //目前crud的service层id不认用户自定义id,只支持默认规则id,许多地方的格式都写死了service_listview_${objectname}
10306
10412
  id: `service_${id}`,
10307
10413
  name: `page`,
@@ -10610,7 +10716,7 @@ const getRecordPermissions = async (objectName, recordId)=>{
10610
10716
  * @Author: baozhoutao@steedos.com
10611
10717
  * @Date: 2022-07-05 15:55:39
10612
10718
  * @LastEditors: liaodaxue
10613
- * @LastEditTime: 2023-09-25 17:18:08
10719
+ * @LastEditTime: 2023-10-23 15:55:46
10614
10720
  * @Description:
10615
10721
  */
10616
10722
 
@@ -10901,11 +11007,15 @@ async function getRelatedListSchema(
10901
11007
  ctx
10902
11008
  ) {
10903
11009
  const uiSchema = await getUISchema(objectName);
11010
+ if(!uiSchema){
11011
+ return {}
11012
+ }
11013
+ const listViewNames = map(uiSchema.list_views, 'name');
10904
11014
  const listView = find(
10905
11015
  uiSchema.list_views,
10906
11016
  (listView, name) => {
10907
- // 传入listViewName空值则取第一个
10908
- if(!listViewName){
11017
+ // 传入listViewName空值 或者 不存在 则取第一个
11018
+ if(!listViewName || listViewNames.indexOf(listViewName)<0){
10909
11019
  listViewName = name;
10910
11020
  }
10911
11021
  return name === listViewName || listView._id === listViewName;
@@ -10985,8 +11095,8 @@ async function getRelatedListSchema(
10985
11095
  /*
10986
11096
  * @Author: baozhoutao@steedos.com
10987
11097
  * @Date: 2022-07-05 15:55:39
10988
- * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
10989
- * @LastEditTime: 2023-09-21 17:35:06
11098
+ * @LastEditors: liaodaxue
11099
+ * @LastEditTime: 2023-10-20 11:38:25
10990
11100
  * @Description:
10991
11101
  */
10992
11102
 
@@ -11315,8 +11425,8 @@ async function getListSchema(
11315
11425
  "filtersFunction": listview_filters,
11316
11426
  "sort": sort,
11317
11427
  "ctx": ctx,
11318
- "requestAdaptor": listView.requestAdaptor,
11319
- "adaptor": listView.adaptor,
11428
+ "requestAdaptor": listView.requestAdaptor || ctx.requestAdaptor,
11429
+ "adaptor": listView.adaptor || ctx.adaptor,
11320
11430
  "headerToolbarItems": ctx.headerToolbarItems,
11321
11431
  "filterVisible": ctx.filterVisible,
11322
11432
  "rowClassNameExpr": ctx.rowClassNameExpr,