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

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
@@ -2597,20 +2597,29 @@ function getButtonVisibleOn$1(button){
2597
2597
  // return 'false';
2598
2598
  // }
2599
2599
  if(visible.trim().startsWith('function')){
2600
- return `${visible}.apply({
2600
+ visible = `${visible}.apply({
2601
2601
  object: uiSchema
2602
- }, [objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`
2602
+ }, [objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data])`;
2603
2603
  }
2604
- return visible;
2605
2604
  }
2606
2605
 
2607
2606
  if(button.type === 'amis_button'){
2608
- const amisSchema = button.amis_schema;
2607
+ let amisSchema = button.amis_schema;
2608
+ if(___namespace.isString(amisSchema)){
2609
+ amisSchema = JSON.parse(amisSchema);
2610
+ }
2609
2611
  if(amisSchema && amisSchema.body && amisSchema.body.length > 0){
2610
2612
  const btn1 = amisSchema.body[0];
2611
- return btn1.visibleOn
2613
+ if(___namespace.hasIn(btn1, 'visibleOn')){
2614
+ /* 当含有“更多”按钮或者“下拉”箭头按钮时,单个按钮的visibleOn需要合并到 “更多”按钮或者“下拉”箭头按钮的 visibleOn 中,用||隔开。
2615
+ visibleOn的格式需要保持一致; 不能是 js 和 ${xxx} 混合的表达式;
2616
+ visibleOn的值需要是js格式,因为默认的编辑、删除等系统按钮的visibleOn的格式就是js格式(function(){});
2617
+ */
2618
+ return btn1.visibleOn
2619
+ }
2612
2620
  }
2613
2621
  }
2622
+ return visible;
2614
2623
  }
2615
2624
 
2616
2625
  const getButtonVisible = (button, ctx) => {
@@ -5406,6 +5415,7 @@ function getObjectHeaderToolbar(mainObject, fields, formFactor, {
5406
5415
  }
5407
5416
 
5408
5417
  function getObjectFooterToolbar(mainObject, formFactor, options) {
5418
+ // crud card模式与table模式两种情况下showPageInput默认值不一样,所以需要显式设置为false
5409
5419
  if (formFactor === 'SMALL') {
5410
5420
  // return [
5411
5421
  // "load-more",
@@ -5415,15 +5425,17 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
5415
5425
  "switch-per-page",
5416
5426
  {
5417
5427
  "type": "pagination",
5418
- "maxButtons": 5
5428
+ "maxButtons": 5,
5429
+ "showPageInput": false
5419
5430
  }
5420
5431
  ]
5421
5432
  }else {
5422
5433
  return [
5423
- "statistics",
5434
+ // "statistics",
5424
5435
  {
5425
5436
  "type": "pagination",
5426
- "maxButtons": 5
5437
+ "maxButtons": 5,
5438
+ "showPageInput": false
5427
5439
  }
5428
5440
  ]
5429
5441
  }
@@ -5432,7 +5444,11 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
5432
5444
  if(options && options.isRelated){
5433
5445
  return [
5434
5446
  "statistics",
5435
- "pagination"
5447
+ {
5448
+ "type": "pagination",
5449
+ "maxButtons": 10,
5450
+ "showPageInput": false
5451
+ }
5436
5452
  ]
5437
5453
 
5438
5454
  }
@@ -5440,7 +5456,11 @@ function getObjectFooterToolbar(mainObject, formFactor, options) {
5440
5456
  return [
5441
5457
  "switch-per-page",
5442
5458
  "statistics",
5443
- "pagination"
5459
+ {
5460
+ "type": "pagination",
5461
+ "maxButtons": 10,
5462
+ "showPageInput": false
5463
+ }
5444
5464
  ]
5445
5465
  }
5446
5466
  }
@@ -6323,15 +6343,17 @@ async function lookupToAmisSelect(field, readonly, ctx){
6323
6343
  var optionsFilters = [["${valueFieldKey}", optionsFiltersOp, []]];
6324
6344
  if (defaultValue && !api.data.$term) {
6325
6345
  const defaultValueOptionsQueryData = ${JSON.stringify(defaultValueOptionsQueryData)};
6326
- const defaultValueOptionsQuery = defaultValueOptionsQueryData.query.replace(/^{/,"").replace(/}$/,"");
6346
+ const defaultValueOptionsQuery = defaultValueOptionsQueryData?.query?.replace(/^{/,"").replace(/}$/,"");
6327
6347
  // 字段值单独请求,没值的时候在请求中返回空
6328
6348
  optionsFilters = [["${valueFieldKey}", optionsFiltersOp, defaultValue]];
6329
6349
  if(filters.length > 0){
6330
6350
  optionsFilters = [filters, optionsFilters];
6331
6351
  }
6332
- api.data.query = "{"+api.data.query.replace(/^{/,"").replace(/}$/,"")+","+defaultValueOptionsQuery+"}";
6333
- api.data.query = api.data.query.replace(/{__options_filters}/g, JSON.stringify(optionsFilters))
6352
+ if(defaultValueOptionsQuery){
6353
+ api.data.query = "{"+api.data.query.replace(/^{/,"").replace(/}$/,"")+","+defaultValueOptionsQuery+"}";
6354
+ }
6334
6355
  }
6356
+ api.data.query = api.data.query.replace(/{__options_filters}/g, JSON.stringify(optionsFilters));
6335
6357
  return api;
6336
6358
  `;
6337
6359
  referenceTo ? referenceTo.labelField.name : '';
@@ -7265,7 +7287,20 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
7265
7287
  type: getAmisStaticFieldType('number', readonly),
7266
7288
  min: field.min,
7267
7289
  max: field.max,
7268
- precision: field.scale
7290
+ precision: field.scale,
7291
+ suffix: "%",
7292
+ pipeIn: (value, data) => {
7293
+ if(value){
7294
+ return value*100;
7295
+ }
7296
+ return value;
7297
+ },
7298
+ pipeOut: (value, oldValue, data) => {
7299
+ if(value){
7300
+ return value/100;
7301
+ }
7302
+ return value;
7303
+ },
7269
7304
  };
7270
7305
  }
7271
7306
  break;
@@ -7761,7 +7796,7 @@ async function getQuickEditSchema(field, options){
7761
7796
  break;
7762
7797
  case "percent":
7763
7798
  TempDisplayField = `
7764
- _display["${field.name}"] = (event.data.value * 100).toFixed(${field.scale}) + '%';
7799
+ _display["${field.name}"] = event.data.value.toFixed(${field.scale}) + '%';
7765
7800
  `;
7766
7801
  quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
7767
7802
  break;
@@ -8392,23 +8427,86 @@ async function getTableOperation(ctx){
8392
8427
  }
8393
8428
  }
8394
8429
 
8430
+ async function getDefaultCrudCard(columns, options) {
8431
+ let labelFieldName = options?.labelFieldName || "name";
8432
+ let titleColumn, bodyColumns = [];
8433
+ columns.forEach(function (item) {
8434
+ delete item.quickEdit;
8435
+ delete item.width;
8436
+ if (item.name === labelFieldName) {
8437
+ titleColumn = item;
8438
+ }
8439
+ else {
8440
+ if (item.name !== "_index") {
8441
+ bodyColumns.push(item);
8442
+ }
8443
+ }
8444
+ });
8445
+ let card = {
8446
+ "header": {
8447
+ "title": titleColumn.tpl
8448
+ },
8449
+ body: bodyColumns,
8450
+ // useCardLabel: false,
8451
+ toolbar: []
8452
+ };
8453
+ let hideToolbarOperation = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
8454
+ if(!hideToolbarOperation){
8455
+ let toolbarOperation = await getTableOperation(options);
8456
+ if (toolbarOperation) {
8457
+ toolbarOperation.className += " inline-block w-auto";
8458
+ }
8459
+ card.toolbar.push(toolbarOperation);
8460
+ }
8461
+ return card;
8462
+ }
8463
+
8395
8464
  async function getTableSchema$1(fields, options){
8396
8465
  if(!options){
8397
8466
  options = {};
8398
8467
  }
8399
8468
  let { isLookup, hiddenColumnOperation } = options;
8469
+ const defaults = options.defaults;
8470
+ const listSchema = (defaults && defaults.listSchema) || {};
8471
+
8400
8472
  let columns = [];
8401
8473
  let useMobileColumns = options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1;
8402
8474
  if(isLookup){
8403
8475
  // 在lookup手机端列表模式调式好之前不使用getMobileTableColumns
8404
8476
  useMobileColumns = false;
8405
8477
  }
8478
+ if(listSchema.mode && listSchema.mode !== "table"){
8479
+ // 如果指定的mode,则不走我们内置的手机端列表效果,使用steedos组件内部开发的默认card/list效果,或者由用户自己实现card/list模式的crud列表
8480
+ useMobileColumns = false;
8481
+ }
8406
8482
  if(useMobileColumns){
8407
8483
  columns = await getMobileTableColumns(fields, options);
8408
8484
  }
8409
8485
  else {
8410
8486
  columns = await getTableColumns(fields, options);
8411
8487
 
8488
+ if(listSchema.mode === "cards"){
8489
+ let card = listSchema.card;
8490
+ if(!card){
8491
+ card = await getDefaultCrudCard(columns, options);
8492
+ }
8493
+ return {
8494
+ mode: "cards",
8495
+ name: "thelist",
8496
+ headerToolbarClassName: "py-2 px-2 border-gray-300 border-solid border-b",
8497
+ className: "",
8498
+ draggable: false,
8499
+ defaultParams: getDefaultParams(options),
8500
+ card: card,
8501
+ syncLocation: false,
8502
+ keepItemSelectionOnPageChange: true,
8503
+ checkOnItemClick: isLookup ? true : false,
8504
+ labelTpl: `\${${options.labelFieldName}}`,
8505
+ autoFillHeight: false, // 自动高度效果不理想,先关闭
8506
+ columnsTogglable: false
8507
+ }
8508
+ }
8509
+
8412
8510
  if(!isLookup && !hiddenColumnOperation){
8413
8511
  columns.push(await getTableOperation(options));
8414
8512
  }
@@ -10148,6 +10246,9 @@ async function getObjectCRUD(objectSchema, fields, options){
10148
10246
  const nonpaged = objectSchema.paging && objectSchema.paging.enabled === false;
10149
10247
  const isTreeObject = objectSchema.enable_tree;
10150
10248
  const bulkActions = getBulkActions(objectSchema);
10249
+ const defaults = options.defaults;
10250
+ const listSchema = (defaults && defaults.listSchema) || {};
10251
+
10151
10252
  const bodyProps = {
10152
10253
  // toolbar: getToolbar(),
10153
10254
  // headerToolbar: getObjectHeaderToolbar(objectSchema, options.formFactor, {showDisplayAs}),
@@ -10159,9 +10260,12 @@ async function getObjectCRUD(objectSchema, fields, options){
10159
10260
  filter: options.filterVisible !== false && await getObjectFilter(objectSchema, fields, options),
10160
10261
  };
10161
10262
  if(options.formFactor !== 'SMALL' || ["split"].indexOf(options.displayAs) == -1){
10162
- Object.assign(bodyProps, {
10163
- bulkActions: options.bulkActions != false ? bulkActions : false
10164
- });
10263
+ if(listSchema.mode !== "cards"){
10264
+ // card模式时默认不显示勾选框
10265
+ Object.assign(bodyProps, {
10266
+ bulkActions: options.bulkActions != false ? bulkActions : false
10267
+ });
10268
+ }
10165
10269
  }
10166
10270
  // yml里配置的 不分页和enable_tree:true 优先级最高,组件中输入的top次之。
10167
10271
  options.queryCount = true;
@@ -10224,7 +10328,7 @@ async function getObjectCRUD(objectSchema, fields, options){
10224
10328
  }, options);
10225
10329
  tableOptions.amisData = createObject(options.amisData || {}, {});
10226
10330
  const table = await getTableSchema$1(fields, tableOptions);
10227
- delete table.mode;
10331
+ // delete table.mode;
10228
10332
  //image与avatar需要在提交修改时特别处理
10229
10333
  const imageNames = ___default["default"].compact(___default["default"].map(___default["default"].filter(fields, (field) => ["image","avatar"].includes(field.type)), 'name'));
10230
10334
  const quickSaveApiRequestAdaptor = `
@@ -10294,12 +10398,14 @@ async function getObjectCRUD(objectSchema, fields, options){
10294
10398
 
10295
10399
  }
10296
10400
 
10297
- const defaults = options.defaults;
10298
-
10299
- const listSchema = (defaults && defaults.listSchema) || {};
10300
10401
  body = defaultsDeep({}, listSchema, body);
10301
10402
  body = await getCrudSchemaWithDataFilter(body, { crudDataFilter, onCrudDataFilter, amisData, env });
10302
10403
 
10404
+ let crudModeClassName = "";
10405
+ if(body.mode){
10406
+ crudModeClassName = `steedos-crud-mode-${body.mode}`;
10407
+ }
10408
+
10303
10409
  if (defaults) {
10304
10410
  const headerSchema = defaults.headerSchema;
10305
10411
  const footerSchema = defaults.footerSchema;
@@ -10328,7 +10434,7 @@ async function getObjectCRUD(objectSchema, fields, options){
10328
10434
  // TODO: data应该只留loaded,其他属性都改为从上层传递下来
10329
10435
  return {
10330
10436
  type: 'service',
10331
- className: '',
10437
+ className: crudModeClassName,
10332
10438
  //目前crud的service层id不认用户自定义id,只支持默认规则id,许多地方的格式都写死了service_listview_${objectname}
10333
10439
  id: `service_${id}`,
10334
10440
  name: `page`,
@@ -11012,8 +11118,8 @@ async function getRelatedListSchema(
11012
11118
  /*
11013
11119
  * @Author: baozhoutao@steedos.com
11014
11120
  * @Date: 2022-07-05 15:55:39
11015
- * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
11016
- * @LastEditTime: 2023-09-21 17:35:06
11121
+ * @LastEditors: liaodaxue
11122
+ * @LastEditTime: 2023-10-20 11:38:25
11017
11123
  * @Description:
11018
11124
  */
11019
11125
 
@@ -11342,8 +11448,8 @@ async function getListSchema(
11342
11448
  "filtersFunction": listview_filters,
11343
11449
  "sort": sort,
11344
11450
  "ctx": ctx,
11345
- "requestAdaptor": listView.requestAdaptor,
11346
- "adaptor": listView.adaptor,
11451
+ "requestAdaptor": listView.requestAdaptor || ctx.requestAdaptor,
11452
+ "adaptor": listView.adaptor || ctx.adaptor,
11347
11453
  "headerToolbarItems": ctx.headerToolbarItems,
11348
11454
  "filterVisible": ctx.filterVisible,
11349
11455
  "rowClassNameExpr": ctx.rowClassNameExpr,