@qq1948037137/adminsmart-ui 0.1.32 → 0.1.33

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/README.md CHANGED
@@ -61,6 +61,16 @@ function Example() {
61
61
 
62
62
  `SessionReplay` 默认关闭鼠标轨迹。宿主传入 `mouseTrail` 与已录制的 rrweb `MouseMove` 事件后,播放器以主题主色显示原生轨迹。轨迹跟随录像坐标和播放倍率;拖动时间轴保留该时刻的鼠标位置。文档示例可实时开关轨迹。
63
63
 
64
+ ## 表格序号和分页
65
+
66
+ `Table`、`DataTable` 默认把「序号」作为第一列业务数据,表头和内容均居中。选择框和独立展开控件保留其原生位置。内置分页默认每页 10 条,自动连续编号。业务页面单独调用后端分页时,把实际页码和每页条数传给序号列:
67
+
68
+ ```jsx
69
+ <DataTable rowKey="id" dataSource={rows} columns={columns} pagination={false} rowNumber={{ current: pageNum, pageSize }} />
70
+ ```
71
+
72
+ `rowNumber={false}` 用于保留自有编号或关闭子表序号。`rowNumber` 也可传 `title` 和数字 `width`。编号取当前表格显示顺序;数据主键和勾选状态仍通过 `rowKey` 管理。
73
+
64
74
  ## 首次发布与可信自动发布
65
75
 
66
76
  GitHub 工作流通过仓库变量 `NPM_RELEASE_ENABLED` 控制发布;变量未设为 `true` 时,仅显示待设置通知。首次包不存在时,发布状态机只返回 `bootstrap-needed`,不猜版本、不创建版本提交。首次发布前应完成账号 2FA 和 npm CLI 登录,确认源码已提交到私有仓库 `1948037137/adminsmart-ui` 的当前 `main`,然后执行:
package/dist/index.cjs CHANGED
@@ -373,6 +373,7 @@ var import_antd10 = require("antd");
373
373
  var import_react3 = require("react");
374
374
 
375
375
  // src/internal/paginationTotal.ts
376
+ var DEFAULT_PAGE_SIZE = 10;
376
377
  function paginationTotal(total) {
377
378
  return `\u5171 ${total} \u6761`;
378
379
  }
@@ -407,19 +408,119 @@ function TableEmpty({ className, description = "\u6682\u65E0\u6570\u636E", image
407
408
  }
408
409
 
409
410
  // src/components/Table.ts
411
+ var ROW_NUMBER_KEY = "__adminsmart_row_number";
412
+ var DEFAULT_NUMBER_WIDTH = 64;
410
413
  function normalizeTableProps(props) {
411
414
  const locale = props.locale ?? {};
412
415
  const content = locale.emptyText;
413
416
  const emptyText = content === void 0 ? (0, import_react3.createElement)(TableEmpty) : typeof content === "string" || typeof content === "number" ? (0, import_react3.createElement)(TableEmpty, { description: content }) : content;
414
417
  const pagination = props.pagination;
415
- const tablePagination = pagination === false ? false : { showTotal: paginationTotal, ...pagination };
418
+ const tablePagination = pagination === false ? false : { defaultPageSize: DEFAULT_PAGE_SIZE, showTotal: paginationTotal, ...pagination };
416
419
  return { ...props, locale: { ...locale, emptyText }, pagination: tablePagination };
417
420
  }
421
+ function isControlColumn(column) {
422
+ return column === import_antd10.Table.SELECTION_COLUMN || column === import_antd10.Table.EXPAND_COLUMN;
423
+ }
424
+ function NumberedTable({ rowNumber = true, pagination, columns, children, dataSource, expandable, expandIconColumnIndex, onChange, scroll, ...props }) {
425
+ const nativePagination = pagination || void 0;
426
+ const [innerPage, setInnerPage] = (0, import_react3.useState)(() => ({
427
+ current: nativePagination?.defaultCurrent ?? 1,
428
+ // 未显式控制页码时跟踪 native Table 的切页结果。
429
+ size: nativePagination?.defaultPageSize ?? DEFAULT_PAGE_SIZE
430
+ // 以与 Ant 相同的首次实际页大小为准。
431
+ }));
432
+ const [, refreshTreeNumbers] = (0, import_react3.useState)(0);
433
+ const passedChildren = import_react3.Children.toArray(children).filter(import_react3.isValidElement);
434
+ const numberConfig = typeof rowNumber === "object" ? rowNumber : void 0;
435
+ const firstBusiness = columns?.findIndex((column) => !isControlColumn(column)) ?? 0;
436
+ if (!rowNumber || firstBusiness < 0 || columns == null && passedChildren.length === 0) {
437
+ return (0, import_react3.createElement)(import_antd10.Table, { ...props, pagination, columns, children, dataSource, expandable, expandIconColumnIndex, onChange, scroll });
438
+ }
439
+ const pageSize = numberConfig?.pageSize ?? nativePagination?.pageSize ?? innerPage.size;
440
+ const requestedPage = numberConfig?.current ?? (pagination === false ? 1 : nativePagination?.current ?? innerPage.current);
441
+ const maximumPage = pagination === false || numberConfig?.current != null ? requestedPage : Math.max(1, Math.ceil((nativePagination?.total || dataSource?.length || 0) / pageSize));
442
+ const current = Math.min(requestedPage, maximumPage);
443
+ const offset = (current - 1) * pageSize;
444
+ const width = numberConfig?.width ?? DEFAULT_NUMBER_WIDTH;
445
+ const childField = expandable?.childrenColumnName ?? props.childrenColumnName ?? "children";
446
+ const treeRows = Boolean(dataSource?.some((row) => row[childField]));
447
+ const visibleTreeOrder = treeRows ? /* @__PURE__ */ new WeakMap() : void 0;
448
+ const numberColumn = {
449
+ key: ROW_NUMBER_KEY,
450
+ // 序号列不占用宿主字段、不参与筛选或列显隐设置。
451
+ title: numberConfig?.title ?? "\u5E8F\u53F7",
452
+ // 空列表也显示序号表头。
453
+ width,
454
+ // 保证带选择按钮或横向滚动时列尺寸稳定。
455
+ align: "center",
456
+ // Ant 的新列表头和数据单元格一起居中。
457
+ className: "adminsmart-table-row-number",
458
+ // 可供宿主做视觉或无障碍验收的固定类名。
459
+ onCell: visibleTreeOrder ? (row, index) => {
460
+ if (index != null) visibleTreeOrder.set(row, index);
461
+ return {};
462
+ } : void 0,
463
+ render: (_value, row, index) => offset + (visibleTreeOrder?.get(row) ?? index) + 1
464
+ // 跟随排序、筛选及本页展开顺序。
465
+ };
466
+ const numberedColumns = columns == null ? void 0 : [...columns.slice(0, firstBusiness), numberColumn, ...columns.slice(firstBusiness)];
467
+ const numberedChildren = columns == null ? [(0, import_react3.createElement)(import_antd10.Table.Column, numberColumn), ...passedChildren] : children;
468
+ const nativeExpandIndex = expandable?.expandIconColumnIndex ?? expandIconColumnIndex;
469
+ const originalTreeIndex = nativeExpandIndex == null ? props.rowSelection ? 1 : 0 : props.rowSelection && nativeExpandIndex > 0 ? nativeExpandIndex - 1 : nativeExpandIndex;
470
+ const selectionBefore = props.rowSelection && !columns?.includes(import_antd10.Table.SELECTION_COLUMN) ? 1 : 0;
471
+ const actualIntro = firstBusiness + selectionBefore;
472
+ const shiftedTreeIndex = originalTreeIndex >= actualIntro ? originalTreeIndex + 1 : originalTreeIndex;
473
+ const nextExpandIndex = treeRows ? props.rowSelection && shiftedTreeIndex > 0 ? shiftedTreeIndex + 1 : shiftedTreeIndex : nativeExpandIndex != null && nativeExpandIndex > firstBusiness ? nativeExpandIndex + 1 : nativeExpandIndex;
474
+ const numberedExpandable = {
475
+ ...expandable,
476
+ ...nextExpandIndex == null ? {} : { expandIconColumnIndex: nextExpandIndex },
477
+ // 保留既有展开图标所在的业务列。
478
+ ...treeRows ? {
479
+ onExpandedRowsChange: (keys) => {
480
+ refreshTreeNumbers((revision) => revision + 1);
481
+ if (expandable?.onExpandedRowsChange) expandable.onExpandedRowsChange(keys);
482
+ else props.onExpandedRowsChange?.([...keys]);
483
+ }
484
+ } : {}
485
+ // 只跟踪原生展开事件;宿主控制的展开键和回调仍照常执行。
486
+ };
487
+ const handleChange = (next, filters, sorter, extra) => {
488
+ if (pagination !== false) {
489
+ setInnerPage({
490
+ current: next.current ?? 1,
491
+ // Ant 的筛选过程会把当前页重置到 1。
492
+ size: next.pageSize ?? DEFAULT_PAGE_SIZE
493
+ // 原生切换每页条数会同步更新编号偏移。
494
+ });
495
+ }
496
+ onChange?.(next, filters, sorter, extra);
497
+ };
498
+ return (0, import_react3.createElement)(import_antd10.Table, {
499
+ ...props,
500
+ pagination,
501
+ columns: numberedColumns,
502
+ children: numberedChildren,
503
+ dataSource,
504
+ expandable: treeRows || nextExpandIndex != null ? numberedExpandable : expandable,
505
+ onChange: handleChange,
506
+ scroll: typeof scroll?.x === "number" ? { ...scroll, x: scroll.x + width } : scroll
507
+ });
508
+ }
418
509
  var Summary = Object.assign(wrapAntComponent(import_antd10.Table.Summary, "Table.Summary"), {
419
510
  Row: wrapAntComponent(import_antd10.Table.Summary.Row, "Table.Summary.Row"),
420
511
  Cell: wrapAntComponent(import_antd10.Table.Summary.Cell, "Table.Summary.Cell")
421
512
  });
422
- var Table = Object.assign(wrapAntComponent(import_antd10.Table, "Table", {}, normalizeTableProps), {
513
+ var Table = Object.assign(wrapAntComponent(NumberedTable, "Table", {}, normalizeTableProps), {
514
+ EXPAND_COLUMN: import_antd10.Table.EXPAND_COLUMN,
515
+ // 与 Ant 内部引用相同,否则不能识别占位列。
516
+ SELECTION_COLUMN: import_antd10.Table.SELECTION_COLUMN,
517
+ // 保留显式勾选列的位置控制。
518
+ SELECTION_ALL: import_antd10.Table.SELECTION_ALL,
519
+ // 透传原生全选选项。
520
+ SELECTION_INVERT: import_antd10.Table.SELECTION_INVERT,
521
+ // 透传原生反选选项。
522
+ SELECTION_NONE: import_antd10.Table.SELECTION_NONE,
523
+ // 透传原生清空选项。
423
524
  Column: wrapAntComponent(import_antd10.Table.Column, "Table.Column"),
424
525
  ColumnGroup: wrapAntComponent(import_antd10.Table.ColumnGroup, "Table.ColumnGroup"),
425
526
  Summary
@@ -478,12 +579,17 @@ var ListItem = Object.assign(wrapAntComponent(import_antd13.List.Item, "List.Ite
478
579
  });
479
580
  function normalizeListProps(props) {
480
581
  const pagination = props.pagination;
481
- return pagination && typeof pagination === "object" ? { ...props, pagination: { showTotal: paginationTotal, ...pagination } } : props;
582
+ return pagination && typeof pagination === "object" ? { ...props, pagination: { defaultPageSize: DEFAULT_PAGE_SIZE, showTotal: paginationTotal, ...pagination } } : props;
482
583
  }
483
584
  var List = Object.assign(wrapAntComponent(import_antd13.List, "List", {}, normalizeListProps), {
484
585
  Item: ListItem
485
586
  });
486
- var Pagination = wrapAntComponent(import_antd13.Pagination, "Pagination", { showTotal: paginationTotal });
587
+ var Pagination = wrapAntComponent(import_antd13.Pagination, "Pagination", {
588
+ defaultPageSize: DEFAULT_PAGE_SIZE,
589
+ // 宿主可用 pageSize 或 defaultPageSize 覆盖初始十条。
590
+ showTotal: paginationTotal
591
+ // 默认展示筛选后的完整记录数。
592
+ });
487
593
  var Tree = Object.assign(wrapAntComponent(import_antd13.Tree, "Tree"), {
488
594
  DirectoryTree: wrapAntComponent(import_antd13.Tree.DirectoryTree, "Tree.DirectoryTree"),
489
595
  TreeNode: wrapAntComponent(import_antd13.Tree.TreeNode, "Tree.TreeNode")