@donglegeyu/company-ui 2.5.0 → 2.7.0

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.
@@ -181,6 +181,7 @@ var TEMPLATE_GROUPS = [
181
181
  children: [
182
182
  { title: "布局模板 AdminLayoutTemplate", link: "/template-components/admin-layout-template" },
183
183
  { title: "统计列表页 StatisticsListPage", link: "/template-components/statistics-list-page" },
184
+ { title: "左树右表模板 TreeTableTemplate", link: "/template-components/tree-table-template" },
184
185
  { title: "智能列表模板 SmartListTemplate", link: "/template-components/smart-list-template" },
185
186
  { title: "表单页模板 FormPageTemplate", link: "/template-components/form-page-template" },
186
187
  {
@@ -102,6 +102,11 @@ export interface StatisticsListPageProps<T = Record<string, unknown>> {
102
102
  schemeId: string;
103
103
  filters: Record<string, unknown>;
104
104
  }) => void;
105
+ /**
106
+ * 视图切换器挂载容器(portal 提升):不传(undefined)时渲染在组件自带标题栏;
107
+ * 由外部模板(如 TreeTableTemplate)统一渲染标题栏时传入容器,将切换器提升渲染(分割线由宿主提供)
108
+ */
109
+ viewSwitcherPortalContainer?: HTMLElement | null;
105
110
  /** 自定义 className */
106
111
  className?: string;
107
112
  }
@@ -42,6 +42,7 @@ var import_shared_components = require("../../shared-components");
42
42
  var import_tableActionColumn = require("../../shared-components/tableActionColumn");
43
43
  var import_ColumnSettingsPanel = __toESM(require("../ColumnSettingsPanel"));
44
44
  var import_useCompanyToken = require("../../theme/useCompanyToken");
45
+ var import_react_dom = require("react-dom");
45
46
  var import_index = require("./index.scss");
46
47
  var import_jsx_runtime = require("react/jsx-runtime");
47
48
  var { Text } = import_antd.Typography;
@@ -99,6 +100,7 @@ var StatisticsListPage = (props) => {
99
100
  toolbarRightExtra,
100
101
  viewEndpoint,
101
102
  onViewChange,
103
+ viewSwitcherPortalContainer,
102
104
  className
103
105
  } = props;
104
106
  const [searchValue, setSearchValue] = (0, import_react.useState)("");
@@ -453,7 +455,7 @@ var StatisticsListPage = (props) => {
453
455
  [filterParams]
454
456
  );
455
457
  const extraNode = titleExtra ?? titleSuffix;
456
- const viewSwitcherNode = viewEndpoint ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
458
+ const viewSwitcher = viewEndpoint ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
457
459
  import_shared_components.ViewSwitcher,
458
460
  {
459
461
  viewEndpoint,
@@ -468,6 +470,7 @@ var StatisticsListPage = (props) => {
468
470
  onSaveAsOpen: () => setViewModified(false)
469
471
  }
470
472
  ) : null;
473
+ const viewSwitcherNode = !viewSwitcher ? null : viewSwitcherPortalContainer === void 0 ? viewSwitcher : viewSwitcherPortalContainer ? (0, import_react_dom.createPortal)(viewSwitcher, viewSwitcherPortalContainer) : null;
471
474
  const titleExtraNode = viewSwitcherNode || extraNode ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "slp-title-extra", children: [
472
475
  showTitleExtraDivider && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "slp-divider" }),
473
476
  viewSwitcherNode,
@@ -0,0 +1,66 @@
1
+ import type React from "react";
2
+ import type { CSSProperties, ReactNode } from "react";
3
+ import type { StatisticsListPageProps } from "../StatisticsListPage";
4
+ import "./index.scss";
5
+ /** 左树扁平节点:parent 为空表示顶级,组件内部按 parent 关系组装为树 */
6
+ export interface TreeTableNode {
7
+ /** 节点唯一标识 */
8
+ key: string;
9
+ /** 节点显示名称 */
10
+ label: string;
11
+ /** 父节点 key,为空表示顶级节点 */
12
+ parent?: string;
13
+ }
14
+ /** 虚拟根节点配置(如「全部组织」);不传则不渲染根入口 */
15
+ export interface TreeTableRootNode {
16
+ /** 根节点 key(选中根节点时 onTreeSelect 返回该 key) */
17
+ key: string;
18
+ /** 根节点显示名称 */
19
+ label: string;
20
+ /** 根入口图标,默认使用内置「全部应用」图标 */
21
+ icon?: ReactNode;
22
+ }
23
+ /** 左树右表模板 Props:列表区完整透传 StatisticsListPageProps(隐藏其内置标题栏,页面标题由模板统一渲染) */
24
+ export interface TreeTableTemplateProps<T = Record<string, unknown>> extends Omit<StatisticsListPageProps<T>, "title" | "titleSuffix" | "titleExtra" | "showTitleExtraDivider" | "titleActions" | "className" | "viewSwitcherPortalContainer"> {
25
+ /** 页面标题 */
26
+ title: ReactNode;
27
+ /** 紧跟标题右侧的区域:标题的延伸/补充(如状态标签、说明文字) */
28
+ titleExtra?: ReactNode;
29
+ /** 标题栏最右侧的独立操作区(如按钮组、说明+链接) */
30
+ titleActions?: ReactNode;
31
+ /** 左树节点数据(扁平结构,parent 为空表示顶级) */
32
+ treeData: TreeTableNode[];
33
+ /** 虚拟根节点配置(如「全部组织」),不传则不渲染根入口 */
34
+ rootNode?: TreeTableRootNode;
35
+ /** 左树搜索框占位符 */
36
+ treeSearchPlaceholder?: string;
37
+ /** 左树初始选中节点 key(含根节点 key;不传则初始不选中) */
38
+ defaultSelectedKey?: string;
39
+ /** 树节点选中变化回调(选中根节点时为其 key) */
40
+ onTreeSelect?: (key: string) => void;
41
+ /** 树节点 hover 操作:新增按钮回调 */
42
+ onNodeAdd?: (key: string) => void;
43
+ /** 树节点 hover 操作:编辑按钮回调 */
44
+ onNodeEdit?: (key: string) => void;
45
+ /** 树节点 hover 操作:删除按钮回调 */
46
+ onNodeDelete?: (key: string) => void;
47
+ /** 左树底部「新增」按钮回调(不传则不显示按钮) */
48
+ onTreeAdd?: () => void;
49
+ /** 左树底部新增按钮文案 */
50
+ treeAddText?: string;
51
+ /** 左树面板初始宽度(支持拖拽调节) */
52
+ treeWidth?: number;
53
+ /** 左树面板最小宽度(拖拽下限) */
54
+ minTreeWidth?: number;
55
+ /** 左树面板最大宽度(拖拽上限) */
56
+ maxTreeWidth?: number;
57
+ /** 自定义根容器 className */
58
+ className?: string;
59
+ /** 自定义根容器 style */
60
+ style?: CSSProperties;
61
+ }
62
+ /**
63
+ * 左树右表模板:左侧组织/分类树(搜索 + 虚拟根入口 + 节点 hover 操作 + 拖拽调宽),
64
+ * 右侧复用统计列表页(StatisticsListPage)承载列表区。
65
+ */
66
+ export declare const TreeTableTemplate: <T extends Record<string, unknown>>(props: TreeTableTemplateProps<T>) => React.JSX.Element;
@@ -0,0 +1,282 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/template-components/TreeTableTemplate/index.tsx
20
+ var TreeTableTemplate_exports = {};
21
+ __export(TreeTableTemplate_exports, {
22
+ TreeTableTemplate: () => TreeTableTemplate
23
+ });
24
+ module.exports = __toCommonJS(TreeTableTemplate_exports);
25
+ var import_react = require("react");
26
+ var import_icons = require("@ant-design/icons");
27
+ var import_basic_components = require("../../basic-components");
28
+ var import_shared_components = require("../../shared-components");
29
+ var import_StatisticsListPage = require("../StatisticsListPage");
30
+ var import_useCompanyToken = require("../../theme/useCompanyToken");
31
+ var import_index = require("./index.scss");
32
+ var import_jsx_runtime = require("react/jsx-runtime");
33
+ function collectAllKeys(nodes) {
34
+ return nodes.flatMap((node) => [node.key, ...collectAllKeys(node.children)]);
35
+ }
36
+ function filterTree(nodes, keyword) {
37
+ const k = keyword.trim().toLowerCase();
38
+ if (!k)
39
+ return nodes;
40
+ const walk = (list) => list.filter((node) => node.title.toLowerCase().includes(k) || walk(node.children).length > 0).map((node) => ({ ...node, children: walk(node.children) }));
41
+ return walk(nodes);
42
+ }
43
+ var TreeTableTemplate = (props) => {
44
+ const token = (0, import_useCompanyToken.useCompanyToken)();
45
+ const {
46
+ title,
47
+ titleExtra,
48
+ titleActions,
49
+ viewEndpoint,
50
+ treeData,
51
+ rootNode,
52
+ treeSearchPlaceholder = "搜索",
53
+ defaultSelectedKey,
54
+ onTreeSelect,
55
+ onNodeAdd,
56
+ onNodeEdit,
57
+ onNodeDelete,
58
+ onTreeAdd,
59
+ treeAddText = "新增部门",
60
+ treeWidth = 232,
61
+ minTreeWidth = 200,
62
+ maxTreeWidth = 480,
63
+ className,
64
+ style,
65
+ ...listProps
66
+ } = props;
67
+ const [selectedKey, setSelectedKey] = (0, import_react.useState)(defaultSelectedKey ?? "");
68
+ const [keyword, setKeyword] = (0, import_react.useState)("");
69
+ const assembledTree = (0, import_react.useMemo)(() => {
70
+ const nodeMap = /* @__PURE__ */ new Map();
71
+ (treeData || []).forEach((node) => {
72
+ nodeMap.set(node.key, { key: node.key, title: node.label, children: [] });
73
+ });
74
+ const roots = [];
75
+ (treeData || []).forEach((node) => {
76
+ const current = nodeMap.get(node.key);
77
+ if (!current)
78
+ return;
79
+ const parent = node.parent ? nodeMap.get(node.parent) : void 0;
80
+ if (parent)
81
+ parent.children.push(current);
82
+ else
83
+ roots.push(current);
84
+ });
85
+ return roots;
86
+ }, [treeData]);
87
+ const [expandedKeys, setExpandedKeys] = (0, import_react.useState)([]);
88
+ (0, import_react.useEffect)(() => {
89
+ setExpandedKeys(collectAllKeys(assembledTree));
90
+ }, [assembledTree]);
91
+ const shownTree = (0, import_react.useMemo)(() => filterTree(assembledTree, keyword), [assembledTree, keyword]);
92
+ const effectiveExpandedKeys = keyword.trim() ? collectAllKeys(shownTree) : expandedKeys;
93
+ const handleTreeSelect = (0, import_react.useCallback)(
94
+ (keys) => {
95
+ if (keys.length === 0)
96
+ return;
97
+ const key = String(keys[0]);
98
+ setSelectedKey(key);
99
+ onTreeSelect == null ? void 0 : onTreeSelect(key);
100
+ },
101
+ [onTreeSelect]
102
+ );
103
+ const handleRootSelect = (0, import_react.useCallback)(() => {
104
+ if (!rootNode)
105
+ return;
106
+ setSelectedKey(rootNode.key);
107
+ onTreeSelect == null ? void 0 : onTreeSelect(rootNode.key);
108
+ }, [rootNode, onTreeSelect]);
109
+ const hasNodeActions = Boolean(onNodeAdd || onNodeEdit || onNodeDelete);
110
+ const [viewSwitcherSlot, setViewSwitcherSlot] = (0, import_react.useState)(null);
111
+ const [panelWidth, setPanelWidth] = (0, import_react.useState)(treeWidth);
112
+ const dragStartRef = (0, import_react.useRef)(null);
113
+ const [dragging, setDragging] = (0, import_react.useState)(false);
114
+ const handleResizeStart = (0, import_react.useCallback)(
115
+ (e) => {
116
+ e.preventDefault();
117
+ dragStartRef.current = { startX: e.clientX, startWidth: panelWidth };
118
+ setDragging(true);
119
+ document.body.style.cursor = "col-resize";
120
+ document.body.style.userSelect = "none";
121
+ },
122
+ [panelWidth]
123
+ );
124
+ (0, import_react.useEffect)(() => {
125
+ if (!dragging)
126
+ return;
127
+ const onMove = (e) => {
128
+ const start = dragStartRef.current;
129
+ if (!start)
130
+ return;
131
+ const next = Math.min(
132
+ maxTreeWidth,
133
+ Math.max(minTreeWidth, start.startWidth + (e.clientX - start.startX))
134
+ );
135
+ setPanelWidth(next);
136
+ };
137
+ const onUp = () => {
138
+ dragStartRef.current = null;
139
+ setDragging(false);
140
+ document.body.style.cursor = "";
141
+ document.body.style.userSelect = "";
142
+ };
143
+ window.addEventListener("mousemove", onMove);
144
+ window.addEventListener("mouseup", onUp);
145
+ return () => {
146
+ window.removeEventListener("mousemove", onMove);
147
+ window.removeEventListener("mouseup", onUp);
148
+ document.body.style.cursor = "";
149
+ document.body.style.userSelect = "";
150
+ };
151
+ }, [dragging, minTreeWidth, maxTreeWidth]);
152
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
153
+ "div",
154
+ {
155
+ className: `tree-table-template${dragging ? " ttt-dragging" : ""}${className ? ` ${className}` : ""}`,
156
+ style,
157
+ children: [
158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
159
+ import_shared_components.PageTitle,
160
+ {
161
+ title,
162
+ titleExtra: titleExtra || viewEndpoint ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "ttt-title-extra", children: [
163
+ viewEndpoint && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ttt-divider" }),
164
+ viewEndpoint && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { ref: setViewSwitcherSlot, className: "ttt-view-switcher-slot" }),
165
+ titleExtra
166
+ ] }) : void 0,
167
+ actions: titleActions
168
+ }
169
+ ),
170
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ttt-body", children: [
171
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ttt-tree-panel", style: { width: panelWidth }, children: [
172
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
173
+ import_basic_components.CompanyInput,
174
+ {
175
+ className: "ttt-tree-search",
176
+ allowClear: true,
177
+ value: keyword,
178
+ onChange: (e) => setKeyword(e.target.value),
179
+ placeholder: treeSearchPlaceholder,
180
+ suffix: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_shared_components.SvgIcon, { href: "search", size: 16, style: { color: token == null ? void 0 : token.colorTextTertiary } })
181
+ }
182
+ ),
183
+ rootNode && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
184
+ "div",
185
+ {
186
+ className: selectedKey === rootNode.key ? "ttt-tree-root active" : "ttt-tree-root",
187
+ onClick: handleRootSelect,
188
+ children: [
189
+ rootNode.icon ?? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_shared_components.SvgIcon, { href: "all-application", size: 14 }),
190
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ttt-tree-root-label", children: rootNode.label })
191
+ ]
192
+ }
193
+ ),
194
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
195
+ import_basic_components.CompanyTree,
196
+ {
197
+ blockNode: true,
198
+ treeData: shownTree,
199
+ selectedKeys: selectedKey === (rootNode == null ? void 0 : rootNode.key) ? [] : [selectedKey],
200
+ expandedKeys: effectiveExpandedKeys,
201
+ onExpand: (keys) => setExpandedKeys(keys.map(String)),
202
+ onSelect: handleTreeSelect,
203
+ titleRender: (node) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "ttt-tree-node", children: [
204
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
205
+ "span",
206
+ {
207
+ className: "ttt-tree-node-label",
208
+ title: typeof node.title === "string" ? node.title : void 0,
209
+ children: typeof node.title === "function" ? node.title(node) : node.title
210
+ }
211
+ ),
212
+ hasNodeActions && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ttt-tree-node-actions", onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
213
+ import_basic_components.CompanyDropdown,
214
+ {
215
+ trigger: ["click"],
216
+ menu: {
217
+ items: [
218
+ ...onNodeAdd ? [{ key: "add", icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.PlusOutlined, {}), label: "新增" }] : [],
219
+ ...onNodeEdit ? [{ key: "edit", icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.EditOutlined, {}), label: "编辑" }] : [],
220
+ ...onNodeDelete ? [{ key: "delete", icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.DeleteOutlined, {}), label: "删除" }] : []
221
+ ],
222
+ onClick: ({ key }) => {
223
+ if (key === "add")
224
+ onNodeAdd == null ? void 0 : onNodeAdd(String(node.key));
225
+ else if (key === "edit")
226
+ onNodeEdit == null ? void 0 : onNodeEdit(String(node.key));
227
+ else if (key === "delete")
228
+ onNodeDelete == null ? void 0 : onNodeDelete(String(node.key));
229
+ }
230
+ },
231
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
232
+ import_basic_components.CompanyButton,
233
+ {
234
+ type: "text",
235
+ size: "small",
236
+ className: "ttt-tree-action-btn",
237
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.MoreOutlined, {}),
238
+ onClick: (e) => e.stopPropagation()
239
+ }
240
+ )
241
+ }
242
+ ) })
243
+ ] })
244
+ }
245
+ ),
246
+ onTreeAdd && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
247
+ import_basic_components.CompanyButton,
248
+ {
249
+ block: true,
250
+ className: "ttt-tree-add-btn",
251
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.PlusOutlined, {}),
252
+ onClick: onTreeAdd,
253
+ children: treeAddText
254
+ }
255
+ )
256
+ ] }),
257
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
258
+ import_StatisticsListPage.StatisticsListPage,
259
+ {
260
+ ...listProps,
261
+ viewEndpoint,
262
+ viewSwitcherPortalContainer: viewSwitcherSlot
263
+ },
264
+ selectedKey
265
+ ),
266
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
267
+ "div",
268
+ {
269
+ className: dragging ? "ttt-resize-handle dragging" : "ttt-resize-handle",
270
+ style: { left: panelWidth - 3 },
271
+ onMouseDown: handleResizeStart
272
+ }
273
+ )
274
+ ] })
275
+ ]
276
+ }
277
+ );
278
+ };
279
+ // Annotate the CommonJS export names for ESM import in node:
280
+ 0 && (module.exports = {
281
+ TreeTableTemplate
282
+ });
@@ -0,0 +1,208 @@
1
+ // 左树右表模板:左树面板(搜索 + 虚拟根入口 + 树 + hover 操作 + 拖拽调宽)+ 右侧 StatisticsListPage
2
+ .tree-table-template {
3
+ display: flex;
4
+ flex-direction: column;
5
+ height: 100%;
6
+ min-height: 0;
7
+ min-width: 0;
8
+
9
+ // 灰底白卡视觉层次(对齐 StatisticsListPage:灰底容器 + 白卡浮起)
10
+ padding: 0 calc(var(--spacing-sm, 12) * 1px);
11
+ background: var(--color-bg-layout);
12
+
13
+ // 抵消 SmartListTemplate 泄漏的全局 .page-title { font-weight: 600 }(会粗化标题右侧文字),恢复 PageTitle 默认表现
14
+ // 右侧留白与列表区 padding-right 对齐
15
+ > .page-title {
16
+ padding-right: calc(var(--spacing-sm, 12) * 1px);
17
+ font-weight: normal;
18
+ }
19
+
20
+ // 页面标题右侧:视图切换器区域(前置分割线 + portal 挂载位,视觉对齐 StatisticsListPage .slp-title-extra)
21
+ .ttt-title-extra {
22
+ display: flex;
23
+ align-items: center;
24
+ gap: calc(var(--spacing-md, 16) * 1px);
25
+ margin-left: calc(var(--spacing-xs, 8) * 1px);
26
+
27
+ .ttt-divider {
28
+ width: 1px;
29
+ height: 16px;
30
+ background: var(--color-border, rgba(5, 5, 5, 0.15));
31
+ }
32
+
33
+ // StatisticsListPage 视图切换器的 portal 挂载位
34
+ .ttt-view-switcher-slot {
35
+ display: inline-flex;
36
+ align-items: center;
37
+ }
38
+ }
39
+
40
+ &.ttt-dragging {
41
+ cursor: col-resize;
42
+ user-select: none;
43
+ }
44
+
45
+ .ttt-body {
46
+ position: relative;
47
+ flex: 1;
48
+ min-height: 0;
49
+ min-width: 0;
50
+ display: flex;
51
+
52
+ // 左树与右侧列表之间的灰底间隔(右侧列表 padding 已归零对齐根容器灰边,间隔统一由 body gap 提供)
53
+ gap: calc(var(--spacing-sm, 12) * 1px);
54
+ }
55
+
56
+ // 左树面板:白底卡片,圆角仅顶部(与列表区白卡卡片形态一致)
57
+ // box-sizing 显式声明:antd 6 无全局 reset,普通 div 默认 content-box 会导致
58
+ // width(panelWidth) + padding 撑出 24px,拖拽把手(left: panelWidth - 3)与面板右缘错位
59
+ .ttt-tree-panel {
60
+ box-sizing: border-box;
61
+ flex-shrink: 0;
62
+ padding: calc(var(--spacing-sm, 12) * 1px);
63
+ overflow: auto;
64
+ background: var(--color-bg-container);
65
+ border-radius: calc(var(--border-radius-base, 8) * 1px) calc(var(--border-radius-base, 8) * 1px)
66
+ 0 0;
67
+ }
68
+
69
+ .ttt-tree-search {
70
+ width: 100%;
71
+ margin-bottom: calc(var(--spacing-xs, 8) * 1px);
72
+ }
73
+
74
+ // 虚拟根入口(如「全部组织」):hover / 选中背景与树节点视觉一致
75
+ .ttt-tree-root {
76
+ display: flex;
77
+ align-items: center;
78
+ margin-bottom: 2px;
79
+ font-size: calc(var(--font-size-base, 14) * 1px);
80
+ cursor: pointer;
81
+
82
+ // 图标水平中心对齐树一级节点的展开/收起箭头(switcher 占位内居中)
83
+ > svg {
84
+ margin-left: 7px;
85
+ }
86
+
87
+ .ttt-tree-root-label {
88
+ flex: 1;
89
+ min-width: 0;
90
+ overflow: hidden;
91
+ text-overflow: ellipsis;
92
+ white-space: nowrap;
93
+ margin-left: 9px;
94
+ padding-left: 4px;
95
+ padding-right: 0;
96
+ line-height: 28px;
97
+ border-radius: 6px;
98
+ transition: all var(--motion-duration-fast, 0.2s)
99
+ var(--motion-ease-in-out, cubic-bezier(0.4, 0, 0.2, 1));
100
+ }
101
+
102
+ &:hover .ttt-tree-root-label {
103
+ background: var(--color-bg-layout);
104
+ }
105
+
106
+ &.active .ttt-tree-root-label {
107
+ background: var(--color-primary-bg);
108
+ }
109
+ }
110
+
111
+ // 树节点:hover 时在右侧显示「更多」操作按钮(点击弹出新增 / 编辑 / 删除下拉菜单)
112
+ .ttt-tree-node {
113
+ display: flex;
114
+ align-items: center;
115
+ width: 100%;
116
+ min-width: 0;
117
+
118
+ .ttt-tree-node-label {
119
+ flex: 1;
120
+ min-width: 0;
121
+ overflow: hidden;
122
+ text-overflow: ellipsis;
123
+ white-space: nowrap;
124
+ }
125
+
126
+ .ttt-tree-node-actions {
127
+ display: none;
128
+ align-items: center;
129
+ flex-shrink: 0;
130
+ margin-right: 0;
131
+
132
+ .ttt-tree-action-btn {
133
+ // 压缩按钮内边距,避免挤占节点标题空间
134
+ padding-inline: 2px;
135
+ }
136
+ }
137
+ }
138
+
139
+ // 树节点内容容器:左内边距 8px → 4px(收紧文字与箭头间距),右内边距归零(选中背景/内容区贴齐右侧)
140
+ .ttt-tree-panel .ant-tree-node-content-wrapper {
141
+ padding-inline: 4px 0;
142
+ }
143
+
144
+ // 树展开/收起箭头(open/close/noop 状态统一):去掉 antd 默认 6px 右外边距,箭头与节点内容贴紧
145
+ .ttt-tree-panel .ant-tree-switcher {
146
+ margin-inline-end: 0;
147
+ }
148
+
149
+ .ttt-tree-panel .ant-tree-node-content-wrapper:hover .ttt-tree-node-actions {
150
+ display: inline-flex;
151
+ }
152
+
153
+ // 左树底部「新增」按钮:树内容不超一屏时跟随内容,超一屏时吸底(sticky 原生行为,无需 JS 判断)
154
+ .ttt-tree-add-btn {
155
+ position: sticky;
156
+ bottom: 0;
157
+ z-index: 1;
158
+ margin-top: calc(var(--spacing-xs, 8) * 1px);
159
+ background: var(--color-bg-container);
160
+ }
161
+
162
+ // 右侧列表:复用 StatisticsListPage,隐藏其内置标题栏(页面标题由模板统一渲染)
163
+ .ttt-body > .statistics-list-page {
164
+ flex: 1;
165
+ min-width: 0;
166
+
167
+ // 灰底已由模板根容器提供,归零自带左右 padding,避免白卡距右边缘出现双边距(24px ≠ 左侧 12px)
168
+ padding: 0;
169
+
170
+ > .page-title {
171
+ display: none;
172
+ }
173
+
174
+ // 单元格单行省略,对齐左树右表场景的紧凑表格形态
175
+ .ant-table-cell {
176
+ white-space: nowrap;
177
+ overflow: hidden;
178
+ text-overflow: ellipsis;
179
+ }
180
+ }
181
+
182
+ // 拖拽调宽把手:覆盖左右面板边界,hover / 拖拽中显示主色分割线
183
+ .ttt-resize-handle {
184
+ position: absolute;
185
+ top: 0;
186
+ bottom: 0;
187
+ width: 6px;
188
+ cursor: col-resize;
189
+ z-index: 10;
190
+
191
+ &::after {
192
+ content: "";
193
+ position: absolute;
194
+ top: 0;
195
+ bottom: 0;
196
+ left: 2px;
197
+ width: 2px;
198
+ background: transparent;
199
+ transition: background var(--motion-duration-fast, 0.2s)
200
+ var(--motion-ease-in-out, cubic-bezier(0.4, 0, 0.2, 1));
201
+ }
202
+
203
+ &:hover::after,
204
+ &.dragging::after {
205
+ background: var(--color-primary);
206
+ }
207
+ }
208
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./StatisticsListPage";
2
+ export * from "./TreeTableTemplate";
2
3
  export { default as ColumnSettingsPanel } from "./ColumnSettingsPanel";
3
4
  export type { ColumnField } from "./ColumnSettingsPanel";
4
5
  export { default as FilterForm } from "./FilterForm";
@@ -45,6 +45,7 @@ __export(template_components_exports, {
45
45
  });
46
46
  module.exports = __toCommonJS(template_components_exports);
47
47
  __reExport(template_components_exports, require("./StatisticsListPage"), module.exports);
48
+ __reExport(template_components_exports, require("./TreeTableTemplate"), module.exports);
48
49
  var import_ColumnSettingsPanel = __toESM(require("./ColumnSettingsPanel"));
49
50
  var import_FilterForm = __toESM(require("./FilterForm"));
50
51
  var import_SmartListTemplate = __toESM(require("./SmartListTemplate"));
@@ -71,5 +72,6 @@ var import_AiAssistantDock = __toESM(require("./AiAssistantDock"));
71
72
  FormPageTemplate,
72
73
  IconSelect,
73
74
  SmartListTemplate,
74
- ...require("./StatisticsListPage")
75
+ ...require("./StatisticsListPage"),
76
+ ...require("./TreeTableTemplate")
75
77
  });
@@ -325,6 +325,9 @@ export var TEMPLATE_GROUPS = [{
325
325
  }, {
326
326
  title: "统计列表页 StatisticsListPage",
327
327
  link: "/template-components/statistics-list-page"
328
+ }, {
329
+ title: "左树右表模板 TreeTableTemplate",
330
+ link: "/template-components/tree-table-template"
328
331
  }, {
329
332
  title: "智能列表模板 SmartListTemplate",
330
333
  link: "/template-components/smart-list-template"
@@ -102,6 +102,11 @@ export interface StatisticsListPageProps<T = Record<string, unknown>> {
102
102
  schemeId: string;
103
103
  filters: Record<string, unknown>;
104
104
  }) => void;
105
+ /**
106
+ * 视图切换器挂载容器(portal 提升):不传(undefined)时渲染在组件自带标题栏;
107
+ * 由外部模板(如 TreeTableTemplate)统一渲染标题栏时传入容器,将切换器提升渲染(分割线由宿主提供)
108
+ */
109
+ viewSwitcherPortalContainer?: HTMLElement | null;
105
110
  /** 自定义 className */
106
111
  className?: string;
107
112
  }
@@ -32,6 +32,7 @@ import { PageTitle, SvgIcon, EllipsisText, ViewSwitcher } from "../../shared-com
32
32
  import { createActionColumn, DENSITY_CELL_PADDING, TABLE_CELL_INLINE_PADDING } from "../../shared-components/tableActionColumn";
33
33
  import ColumnSettingsPanel from "../ColumnSettingsPanel";
34
34
  import { useCompanyToken } from "../../theme/useCompanyToken";
35
+ import { createPortal } from "react-dom";
35
36
  import "./index.scss";
36
37
  import { jsx as _jsx } from "react/jsx-runtime";
37
38
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -134,6 +135,7 @@ export var StatisticsListPage = function StatisticsListPage(props) {
134
135
  toolbarRightExtra = props.toolbarRightExtra,
135
136
  viewEndpoint = props.viewEndpoint,
136
137
  onViewChange = props.onViewChange,
138
+ viewSwitcherPortalContainer = props.viewSwitcherPortalContainer,
137
139
  className = props.className;
138
140
 
139
141
  // 顶部搜索
@@ -645,7 +647,7 @@ export var StatisticsListPage = function StatisticsListPage(props) {
645
647
  var extraNode = titleExtra !== null && titleExtra !== void 0 ? titleExtra : titleSuffix;
646
648
 
647
649
  // 视图切换器:紧跟页面标题右侧(带前置分割线,与 SmartListTemplate 一致),仅在传入 viewEndpoint 时启用
648
- var viewSwitcherNode = viewEndpoint ? /*#__PURE__*/_jsx(ViewSwitcher, {
650
+ var viewSwitcher = viewEndpoint ? /*#__PURE__*/_jsx(ViewSwitcher, {
649
651
  viewEndpoint: viewEndpoint,
650
652
  fields: filterFields,
651
653
  filterParams: filterParams,
@@ -661,6 +663,9 @@ export var StatisticsListPage = function StatisticsListPage(props) {
661
663
  return setViewModified(false);
662
664
  }
663
665
  }) : null;
666
+ // portal 提升:外部模板统一渲染标题栏时(viewSwitcherPortalContainer 非 undefined)渲染到指定容器;
667
+ // 容器未就绪(null)前暂不渲染,避免闪现后重挂;undefined 表示未启用提升,原地渲染在自带标题栏
668
+ var viewSwitcherNode = !viewSwitcher ? null : viewSwitcherPortalContainer === undefined ? viewSwitcher : viewSwitcherPortalContainer ? /*#__PURE__*/createPortal(viewSwitcher, viewSwitcherPortalContainer) : null;
664
669
  var titleExtraNode = viewSwitcherNode || extraNode ? /*#__PURE__*/_jsxs("span", {
665
670
  className: "slp-title-extra",
666
671
  children: [showTitleExtraDivider && /*#__PURE__*/_jsx("span", {
@@ -0,0 +1,66 @@
1
+ import type React from "react";
2
+ import type { CSSProperties, ReactNode } from "react";
3
+ import type { StatisticsListPageProps } from "../StatisticsListPage";
4
+ import "./index.scss";
5
+ /** 左树扁平节点:parent 为空表示顶级,组件内部按 parent 关系组装为树 */
6
+ export interface TreeTableNode {
7
+ /** 节点唯一标识 */
8
+ key: string;
9
+ /** 节点显示名称 */
10
+ label: string;
11
+ /** 父节点 key,为空表示顶级节点 */
12
+ parent?: string;
13
+ }
14
+ /** 虚拟根节点配置(如「全部组织」);不传则不渲染根入口 */
15
+ export interface TreeTableRootNode {
16
+ /** 根节点 key(选中根节点时 onTreeSelect 返回该 key) */
17
+ key: string;
18
+ /** 根节点显示名称 */
19
+ label: string;
20
+ /** 根入口图标,默认使用内置「全部应用」图标 */
21
+ icon?: ReactNode;
22
+ }
23
+ /** 左树右表模板 Props:列表区完整透传 StatisticsListPageProps(隐藏其内置标题栏,页面标题由模板统一渲染) */
24
+ export interface TreeTableTemplateProps<T = Record<string, unknown>> extends Omit<StatisticsListPageProps<T>, "title" | "titleSuffix" | "titleExtra" | "showTitleExtraDivider" | "titleActions" | "className" | "viewSwitcherPortalContainer"> {
25
+ /** 页面标题 */
26
+ title: ReactNode;
27
+ /** 紧跟标题右侧的区域:标题的延伸/补充(如状态标签、说明文字) */
28
+ titleExtra?: ReactNode;
29
+ /** 标题栏最右侧的独立操作区(如按钮组、说明+链接) */
30
+ titleActions?: ReactNode;
31
+ /** 左树节点数据(扁平结构,parent 为空表示顶级) */
32
+ treeData: TreeTableNode[];
33
+ /** 虚拟根节点配置(如「全部组织」),不传则不渲染根入口 */
34
+ rootNode?: TreeTableRootNode;
35
+ /** 左树搜索框占位符 */
36
+ treeSearchPlaceholder?: string;
37
+ /** 左树初始选中节点 key(含根节点 key;不传则初始不选中) */
38
+ defaultSelectedKey?: string;
39
+ /** 树节点选中变化回调(选中根节点时为其 key) */
40
+ onTreeSelect?: (key: string) => void;
41
+ /** 树节点 hover 操作:新增按钮回调 */
42
+ onNodeAdd?: (key: string) => void;
43
+ /** 树节点 hover 操作:编辑按钮回调 */
44
+ onNodeEdit?: (key: string) => void;
45
+ /** 树节点 hover 操作:删除按钮回调 */
46
+ onNodeDelete?: (key: string) => void;
47
+ /** 左树底部「新增」按钮回调(不传则不显示按钮) */
48
+ onTreeAdd?: () => void;
49
+ /** 左树底部新增按钮文案 */
50
+ treeAddText?: string;
51
+ /** 左树面板初始宽度(支持拖拽调节) */
52
+ treeWidth?: number;
53
+ /** 左树面板最小宽度(拖拽下限) */
54
+ minTreeWidth?: number;
55
+ /** 左树面板最大宽度(拖拽上限) */
56
+ maxTreeWidth?: number;
57
+ /** 自定义根容器 className */
58
+ className?: string;
59
+ /** 自定义根容器 style */
60
+ style?: CSSProperties;
61
+ }
62
+ /**
63
+ * 左树右表模板:左侧组织/分类树(搜索 + 虚拟根入口 + 节点 hover 操作 + 拖拽调宽),
64
+ * 右侧复用统计列表页(StatisticsListPage)承载列表区。
65
+ */
66
+ export declare const TreeTableTemplate: <T extends Record<string, unknown>>(props: TreeTableTemplateProps<T>) => React.JSX.Element;
@@ -0,0 +1,324 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["title", "titleExtra", "titleActions", "viewEndpoint", "treeData", "rootNode", "treeSearchPlaceholder", "defaultSelectedKey", "onTreeSelect", "onNodeAdd", "onNodeEdit", "onNodeDelete", "onTreeAdd", "treeAddText", "treeWidth", "minTreeWidth", "maxTreeWidth", "className", "style"];
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
8
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
16
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
18
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
20
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
21
+ import { MoreOutlined, PlusOutlined, EditOutlined, DeleteOutlined } from "@ant-design/icons";
22
+ import { CompanyButton, CompanyDropdown, CompanyInput, CompanyTree } from "../../basic-components";
23
+ import { PageTitle, SvgIcon } from "../../shared-components";
24
+ import { StatisticsListPage } from "../StatisticsListPage";
25
+ import { useCompanyToken } from "../../theme/useCompanyToken";
26
+ import "./index.scss";
27
+
28
+ /** 左树扁平节点:parent 为空表示顶级,组件内部按 parent 关系组装为树 */
29
+
30
+ /** 虚拟根节点配置(如「全部组织」);不传则不渲染根入口 */
31
+
32
+ /** 组件内部组装产物,结构对齐 antd TreeDataNode */
33
+ import { jsx as _jsx } from "react/jsx-runtime";
34
+ import { jsxs as _jsxs } from "react/jsx-runtime";
35
+ /** 收集树全部节点 key(受控展开 / 搜索展开用) */
36
+ function collectAllKeys(nodes) {
37
+ return nodes.flatMap(function (node) {
38
+ return [node.key].concat(_toConsumableArray(collectAllKeys(node.children)));
39
+ });
40
+ }
41
+
42
+ /** 按关键词过滤树:命中节点与其祖先链保留 */
43
+ function filterTree(nodes, keyword) {
44
+ var k = keyword.trim().toLowerCase();
45
+ if (!k) return nodes;
46
+ var walk = function walk(list) {
47
+ return list.filter(function (node) {
48
+ return node.title.toLowerCase().includes(k) || walk(node.children).length > 0;
49
+ }).map(function (node) {
50
+ return _objectSpread(_objectSpread({}, node), {}, {
51
+ children: walk(node.children)
52
+ });
53
+ });
54
+ };
55
+ return walk(nodes);
56
+ }
57
+
58
+ /** 左树右表模板 Props:列表区完整透传 StatisticsListPageProps(隐藏其内置标题栏,页面标题由模板统一渲染) */
59
+
60
+ /**
61
+ * 左树右表模板:左侧组织/分类树(搜索 + 虚拟根入口 + 节点 hover 操作 + 拖拽调宽),
62
+ * 右侧复用统计列表页(StatisticsListPage)承载列表区。
63
+ */
64
+ export var TreeTableTemplate = function TreeTableTemplate(props) {
65
+ var _rootNode$icon;
66
+ var token = useCompanyToken();
67
+ var title = props.title,
68
+ titleExtra = props.titleExtra,
69
+ titleActions = props.titleActions,
70
+ viewEndpoint = props.viewEndpoint,
71
+ treeData = props.treeData,
72
+ rootNode = props.rootNode,
73
+ _props$treeSearchPlac = props.treeSearchPlaceholder,
74
+ treeSearchPlaceholder = _props$treeSearchPlac === void 0 ? "搜索" : _props$treeSearchPlac,
75
+ defaultSelectedKey = props.defaultSelectedKey,
76
+ onTreeSelect = props.onTreeSelect,
77
+ onNodeAdd = props.onNodeAdd,
78
+ onNodeEdit = props.onNodeEdit,
79
+ onNodeDelete = props.onNodeDelete,
80
+ onTreeAdd = props.onTreeAdd,
81
+ _props$treeAddText = props.treeAddText,
82
+ treeAddText = _props$treeAddText === void 0 ? "新增部门" : _props$treeAddText,
83
+ _props$treeWidth = props.treeWidth,
84
+ treeWidth = _props$treeWidth === void 0 ? 232 : _props$treeWidth,
85
+ _props$minTreeWidth = props.minTreeWidth,
86
+ minTreeWidth = _props$minTreeWidth === void 0 ? 200 : _props$minTreeWidth,
87
+ _props$maxTreeWidth = props.maxTreeWidth,
88
+ maxTreeWidth = _props$maxTreeWidth === void 0 ? 480 : _props$maxTreeWidth,
89
+ className = props.className,
90
+ style = props.style,
91
+ listProps = _objectWithoutProperties(props, _excluded);
92
+
93
+ // ===== 左树状态 =====
94
+ var _useState = useState(defaultSelectedKey !== null && defaultSelectedKey !== void 0 ? defaultSelectedKey : ""),
95
+ _useState2 = _slicedToArray(_useState, 2),
96
+ selectedKey = _useState2[0],
97
+ setSelectedKey = _useState2[1];
98
+ var _useState3 = useState(""),
99
+ _useState4 = _slicedToArray(_useState3, 2),
100
+ keyword = _useState4[0],
101
+ setKeyword = _useState4[1];
102
+
103
+ // 扁平结构 → antd 树结构
104
+ var assembledTree = useMemo(function () {
105
+ var nodeMap = new Map();
106
+ (treeData || []).forEach(function (node) {
107
+ nodeMap.set(node.key, {
108
+ key: node.key,
109
+ title: node.label,
110
+ children: []
111
+ });
112
+ });
113
+ var roots = [];
114
+ (treeData || []).forEach(function (node) {
115
+ var current = nodeMap.get(node.key);
116
+ if (!current) return;
117
+ var parent = node.parent ? nodeMap.get(node.parent) : undefined;
118
+ if (parent) parent.children.push(current);else roots.push(current);
119
+ });
120
+ return roots;
121
+ }, [treeData]);
122
+
123
+ // 树数据变化(首次挂载 / 异步重载 / 增删节点)后恢复全部展开
124
+ var _useState5 = useState([]),
125
+ _useState6 = _slicedToArray(_useState5, 2),
126
+ expandedKeys = _useState6[0],
127
+ setExpandedKeys = _useState6[1];
128
+ useEffect(function () {
129
+ setExpandedKeys(collectAllKeys(assembledTree));
130
+ }, [assembledTree]);
131
+ var shownTree = useMemo(function () {
132
+ return filterTree(assembledTree, keyword);
133
+ }, [assembledTree, keyword]);
134
+ // 搜索时强制展开命中链
135
+ var effectiveExpandedKeys = keyword.trim() ? collectAllKeys(shownTree) : expandedKeys;
136
+ var handleTreeSelect = useCallback(function (keys) {
137
+ // 与源页面一致:点击已选中节点不取消选中
138
+ if (keys.length === 0) return;
139
+ var key = String(keys[0]);
140
+ setSelectedKey(key);
141
+ onTreeSelect === null || onTreeSelect === void 0 || onTreeSelect(key);
142
+ }, [onTreeSelect]);
143
+ var handleRootSelect = useCallback(function () {
144
+ if (!rootNode) return;
145
+ setSelectedKey(rootNode.key);
146
+ onTreeSelect === null || onTreeSelect === void 0 || onTreeSelect(rootNode.key);
147
+ }, [rootNode, onTreeSelect]);
148
+
149
+ // ===== 树节点 hover 操作(新增 / 编辑 / 删除) =====
150
+ var hasNodeActions = Boolean(onNodeAdd || onNodeEdit || onNodeDelete);
151
+
152
+ // ===== 视图切换器 portal 容器 =====
153
+ // 传入 viewEndpoint 时在模板标题栏放置挂载位,StatisticsListPage 的视图切换器经 portal 提升渲染到此
154
+ // (视图状态与联动逻辑全部留在 StatisticsListPage 内部,portal 仅改变 DOM 位置)
155
+ var _useState7 = useState(null),
156
+ _useState8 = _slicedToArray(_useState7, 2),
157
+ viewSwitcherSlot = _useState8[0],
158
+ setViewSwitcherSlot = _useState8[1];
159
+
160
+ // ===== 拖拽调宽(左树面板宽度) =====
161
+ var _useState9 = useState(treeWidth),
162
+ _useState10 = _slicedToArray(_useState9, 2),
163
+ panelWidth = _useState10[0],
164
+ setPanelWidth = _useState10[1];
165
+ var dragStartRef = useRef(null);
166
+ var _useState11 = useState(false),
167
+ _useState12 = _slicedToArray(_useState11, 2),
168
+ dragging = _useState12[0],
169
+ setDragging = _useState12[1];
170
+ var handleResizeStart = useCallback(function (e) {
171
+ e.preventDefault();
172
+ dragStartRef.current = {
173
+ startX: e.clientX,
174
+ startWidth: panelWidth
175
+ };
176
+ setDragging(true);
177
+ document.body.style.cursor = "col-resize";
178
+ document.body.style.userSelect = "none";
179
+ }, [panelWidth]);
180
+ useEffect(function () {
181
+ if (!dragging) return;
182
+ var onMove = function onMove(e) {
183
+ var start = dragStartRef.current;
184
+ if (!start) return;
185
+ var next = Math.min(maxTreeWidth, Math.max(minTreeWidth, start.startWidth + (e.clientX - start.startX)));
186
+ setPanelWidth(next);
187
+ };
188
+ var onUp = function onUp() {
189
+ dragStartRef.current = null;
190
+ setDragging(false);
191
+ document.body.style.cursor = "";
192
+ document.body.style.userSelect = "";
193
+ };
194
+ window.addEventListener("mousemove", onMove);
195
+ window.addEventListener("mouseup", onUp);
196
+ return function () {
197
+ window.removeEventListener("mousemove", onMove);
198
+ window.removeEventListener("mouseup", onUp);
199
+ document.body.style.cursor = "";
200
+ document.body.style.userSelect = "";
201
+ };
202
+ }, [dragging, minTreeWidth, maxTreeWidth]);
203
+ return /*#__PURE__*/_jsxs("div", {
204
+ className: "tree-table-template".concat(dragging ? " ttt-dragging" : "").concat(className ? " ".concat(className) : ""),
205
+ style: style,
206
+ children: [/*#__PURE__*/_jsx(PageTitle, {
207
+ title: title,
208
+ titleExtra: titleExtra || viewEndpoint ? /*#__PURE__*/_jsxs("span", {
209
+ className: "ttt-title-extra",
210
+ children: [viewEndpoint && /*#__PURE__*/_jsx("span", {
211
+ className: "ttt-divider"
212
+ }), viewEndpoint && /*#__PURE__*/_jsx("span", {
213
+ ref: setViewSwitcherSlot,
214
+ className: "ttt-view-switcher-slot"
215
+ }), titleExtra]
216
+ }) : undefined,
217
+ actions: titleActions
218
+ }), /*#__PURE__*/_jsxs("div", {
219
+ className: "ttt-body",
220
+ children: [/*#__PURE__*/_jsxs("div", {
221
+ className: "ttt-tree-panel",
222
+ style: {
223
+ width: panelWidth
224
+ },
225
+ children: [/*#__PURE__*/_jsx(CompanyInput, {
226
+ className: "ttt-tree-search",
227
+ allowClear: true,
228
+ value: keyword,
229
+ onChange: function onChange(e) {
230
+ return setKeyword(e.target.value);
231
+ },
232
+ placeholder: treeSearchPlaceholder,
233
+ suffix: /*#__PURE__*/_jsx(SvgIcon, {
234
+ href: "search",
235
+ size: 16,
236
+ style: {
237
+ color: token === null || token === void 0 ? void 0 : token.colorTextTertiary
238
+ }
239
+ })
240
+ }), rootNode && /*#__PURE__*/_jsxs("div", {
241
+ className: selectedKey === rootNode.key ? "ttt-tree-root active" : "ttt-tree-root",
242
+ onClick: handleRootSelect,
243
+ children: [(_rootNode$icon = rootNode.icon) !== null && _rootNode$icon !== void 0 ? _rootNode$icon : /*#__PURE__*/_jsx(SvgIcon, {
244
+ href: "all-application",
245
+ size: 14
246
+ }), /*#__PURE__*/_jsx("span", {
247
+ className: "ttt-tree-root-label",
248
+ children: rootNode.label
249
+ })]
250
+ }), /*#__PURE__*/_jsx(CompanyTree, {
251
+ blockNode: true,
252
+ treeData: shownTree,
253
+ selectedKeys: selectedKey === (rootNode === null || rootNode === void 0 ? void 0 : rootNode.key) ? [] : [selectedKey],
254
+ expandedKeys: effectiveExpandedKeys,
255
+ onExpand: function onExpand(keys) {
256
+ return setExpandedKeys(keys.map(String));
257
+ },
258
+ onSelect: handleTreeSelect,
259
+ titleRender: function titleRender(node) {
260
+ return /*#__PURE__*/_jsxs("span", {
261
+ className: "ttt-tree-node",
262
+ children: [/*#__PURE__*/_jsx("span", {
263
+ className: "ttt-tree-node-label",
264
+ title: typeof node.title === "string" ? node.title : undefined,
265
+ children: typeof node.title === "function" ? node.title(node) : node.title
266
+ }), hasNodeActions && /*#__PURE__*/_jsx("span", {
267
+ className: "ttt-tree-node-actions",
268
+ onClick: function onClick(e) {
269
+ return e.stopPropagation();
270
+ },
271
+ children: /*#__PURE__*/_jsx(CompanyDropdown, {
272
+ trigger: ["click"],
273
+ menu: {
274
+ items: [].concat(_toConsumableArray(onNodeAdd ? [{
275
+ key: "add",
276
+ icon: /*#__PURE__*/_jsx(PlusOutlined, {}),
277
+ label: "新增"
278
+ }] : []), _toConsumableArray(onNodeEdit ? [{
279
+ key: "edit",
280
+ icon: /*#__PURE__*/_jsx(EditOutlined, {}),
281
+ label: "编辑"
282
+ }] : []), _toConsumableArray(onNodeDelete ? [{
283
+ key: "delete",
284
+ icon: /*#__PURE__*/_jsx(DeleteOutlined, {}),
285
+ label: "删除"
286
+ }] : [])),
287
+ onClick: function onClick(_ref) {
288
+ var key = _ref.key;
289
+ if (key === "add") onNodeAdd === null || onNodeAdd === void 0 || onNodeAdd(String(node.key));else if (key === "edit") onNodeEdit === null || onNodeEdit === void 0 || onNodeEdit(String(node.key));else if (key === "delete") onNodeDelete === null || onNodeDelete === void 0 || onNodeDelete(String(node.key));
290
+ }
291
+ },
292
+ children: /*#__PURE__*/_jsx(CompanyButton, {
293
+ type: "text",
294
+ size: "small",
295
+ className: "ttt-tree-action-btn",
296
+ icon: /*#__PURE__*/_jsx(MoreOutlined, {}),
297
+ onClick: function onClick(e) {
298
+ return e.stopPropagation();
299
+ }
300
+ })
301
+ })
302
+ })]
303
+ });
304
+ }
305
+ }), onTreeAdd && /*#__PURE__*/_jsx(CompanyButton, {
306
+ block: true,
307
+ className: "ttt-tree-add-btn",
308
+ icon: /*#__PURE__*/_jsx(PlusOutlined, {}),
309
+ onClick: onTreeAdd,
310
+ children: treeAddText
311
+ })]
312
+ }), /*#__PURE__*/_jsx(StatisticsListPage, _objectSpread(_objectSpread({}, listProps), {}, {
313
+ viewEndpoint: viewEndpoint,
314
+ viewSwitcherPortalContainer: viewSwitcherSlot
315
+ }), selectedKey), /*#__PURE__*/_jsx("div", {
316
+ className: dragging ? "ttt-resize-handle dragging" : "ttt-resize-handle",
317
+ style: {
318
+ left: panelWidth - 3
319
+ },
320
+ onMouseDown: handleResizeStart
321
+ })]
322
+ })]
323
+ });
324
+ };
@@ -0,0 +1,208 @@
1
+ // 左树右表模板:左树面板(搜索 + 虚拟根入口 + 树 + hover 操作 + 拖拽调宽)+ 右侧 StatisticsListPage
2
+ .tree-table-template {
3
+ display: flex;
4
+ flex-direction: column;
5
+ height: 100%;
6
+ min-height: 0;
7
+ min-width: 0;
8
+
9
+ // 灰底白卡视觉层次(对齐 StatisticsListPage:灰底容器 + 白卡浮起)
10
+ padding: 0 calc(var(--spacing-sm, 12) * 1px);
11
+ background: var(--color-bg-layout);
12
+
13
+ // 抵消 SmartListTemplate 泄漏的全局 .page-title { font-weight: 600 }(会粗化标题右侧文字),恢复 PageTitle 默认表现
14
+ // 右侧留白与列表区 padding-right 对齐
15
+ > .page-title {
16
+ padding-right: calc(var(--spacing-sm, 12) * 1px);
17
+ font-weight: normal;
18
+ }
19
+
20
+ // 页面标题右侧:视图切换器区域(前置分割线 + portal 挂载位,视觉对齐 StatisticsListPage .slp-title-extra)
21
+ .ttt-title-extra {
22
+ display: flex;
23
+ align-items: center;
24
+ gap: calc(var(--spacing-md, 16) * 1px);
25
+ margin-left: calc(var(--spacing-xs, 8) * 1px);
26
+
27
+ .ttt-divider {
28
+ width: 1px;
29
+ height: 16px;
30
+ background: var(--color-border, rgba(5, 5, 5, 0.15));
31
+ }
32
+
33
+ // StatisticsListPage 视图切换器的 portal 挂载位
34
+ .ttt-view-switcher-slot {
35
+ display: inline-flex;
36
+ align-items: center;
37
+ }
38
+ }
39
+
40
+ &.ttt-dragging {
41
+ cursor: col-resize;
42
+ user-select: none;
43
+ }
44
+
45
+ .ttt-body {
46
+ position: relative;
47
+ flex: 1;
48
+ min-height: 0;
49
+ min-width: 0;
50
+ display: flex;
51
+
52
+ // 左树与右侧列表之间的灰底间隔(右侧列表 padding 已归零对齐根容器灰边,间隔统一由 body gap 提供)
53
+ gap: calc(var(--spacing-sm, 12) * 1px);
54
+ }
55
+
56
+ // 左树面板:白底卡片,圆角仅顶部(与列表区白卡卡片形态一致)
57
+ // box-sizing 显式声明:antd 6 无全局 reset,普通 div 默认 content-box 会导致
58
+ // width(panelWidth) + padding 撑出 24px,拖拽把手(left: panelWidth - 3)与面板右缘错位
59
+ .ttt-tree-panel {
60
+ box-sizing: border-box;
61
+ flex-shrink: 0;
62
+ padding: calc(var(--spacing-sm, 12) * 1px);
63
+ overflow: auto;
64
+ background: var(--color-bg-container);
65
+ border-radius: calc(var(--border-radius-base, 8) * 1px) calc(var(--border-radius-base, 8) * 1px)
66
+ 0 0;
67
+ }
68
+
69
+ .ttt-tree-search {
70
+ width: 100%;
71
+ margin-bottom: calc(var(--spacing-xs, 8) * 1px);
72
+ }
73
+
74
+ // 虚拟根入口(如「全部组织」):hover / 选中背景与树节点视觉一致
75
+ .ttt-tree-root {
76
+ display: flex;
77
+ align-items: center;
78
+ margin-bottom: 2px;
79
+ font-size: calc(var(--font-size-base, 14) * 1px);
80
+ cursor: pointer;
81
+
82
+ // 图标水平中心对齐树一级节点的展开/收起箭头(switcher 占位内居中)
83
+ > svg {
84
+ margin-left: 7px;
85
+ }
86
+
87
+ .ttt-tree-root-label {
88
+ flex: 1;
89
+ min-width: 0;
90
+ overflow: hidden;
91
+ text-overflow: ellipsis;
92
+ white-space: nowrap;
93
+ margin-left: 9px;
94
+ padding-left: 4px;
95
+ padding-right: 0;
96
+ line-height: 28px;
97
+ border-radius: 6px;
98
+ transition: all var(--motion-duration-fast, 0.2s)
99
+ var(--motion-ease-in-out, cubic-bezier(0.4, 0, 0.2, 1));
100
+ }
101
+
102
+ &:hover .ttt-tree-root-label {
103
+ background: var(--color-bg-layout);
104
+ }
105
+
106
+ &.active .ttt-tree-root-label {
107
+ background: var(--color-primary-bg);
108
+ }
109
+ }
110
+
111
+ // 树节点:hover 时在右侧显示「更多」操作按钮(点击弹出新增 / 编辑 / 删除下拉菜单)
112
+ .ttt-tree-node {
113
+ display: flex;
114
+ align-items: center;
115
+ width: 100%;
116
+ min-width: 0;
117
+
118
+ .ttt-tree-node-label {
119
+ flex: 1;
120
+ min-width: 0;
121
+ overflow: hidden;
122
+ text-overflow: ellipsis;
123
+ white-space: nowrap;
124
+ }
125
+
126
+ .ttt-tree-node-actions {
127
+ display: none;
128
+ align-items: center;
129
+ flex-shrink: 0;
130
+ margin-right: 0;
131
+
132
+ .ttt-tree-action-btn {
133
+ // 压缩按钮内边距,避免挤占节点标题空间
134
+ padding-inline: 2px;
135
+ }
136
+ }
137
+ }
138
+
139
+ // 树节点内容容器:左内边距 8px → 4px(收紧文字与箭头间距),右内边距归零(选中背景/内容区贴齐右侧)
140
+ .ttt-tree-panel .ant-tree-node-content-wrapper {
141
+ padding-inline: 4px 0;
142
+ }
143
+
144
+ // 树展开/收起箭头(open/close/noop 状态统一):去掉 antd 默认 6px 右外边距,箭头与节点内容贴紧
145
+ .ttt-tree-panel .ant-tree-switcher {
146
+ margin-inline-end: 0;
147
+ }
148
+
149
+ .ttt-tree-panel .ant-tree-node-content-wrapper:hover .ttt-tree-node-actions {
150
+ display: inline-flex;
151
+ }
152
+
153
+ // 左树底部「新增」按钮:树内容不超一屏时跟随内容,超一屏时吸底(sticky 原生行为,无需 JS 判断)
154
+ .ttt-tree-add-btn {
155
+ position: sticky;
156
+ bottom: 0;
157
+ z-index: 1;
158
+ margin-top: calc(var(--spacing-xs, 8) * 1px);
159
+ background: var(--color-bg-container);
160
+ }
161
+
162
+ // 右侧列表:复用 StatisticsListPage,隐藏其内置标题栏(页面标题由模板统一渲染)
163
+ .ttt-body > .statistics-list-page {
164
+ flex: 1;
165
+ min-width: 0;
166
+
167
+ // 灰底已由模板根容器提供,归零自带左右 padding,避免白卡距右边缘出现双边距(24px ≠ 左侧 12px)
168
+ padding: 0;
169
+
170
+ > .page-title {
171
+ display: none;
172
+ }
173
+
174
+ // 单元格单行省略,对齐左树右表场景的紧凑表格形态
175
+ .ant-table-cell {
176
+ white-space: nowrap;
177
+ overflow: hidden;
178
+ text-overflow: ellipsis;
179
+ }
180
+ }
181
+
182
+ // 拖拽调宽把手:覆盖左右面板边界,hover / 拖拽中显示主色分割线
183
+ .ttt-resize-handle {
184
+ position: absolute;
185
+ top: 0;
186
+ bottom: 0;
187
+ width: 6px;
188
+ cursor: col-resize;
189
+ z-index: 10;
190
+
191
+ &::after {
192
+ content: "";
193
+ position: absolute;
194
+ top: 0;
195
+ bottom: 0;
196
+ left: 2px;
197
+ width: 2px;
198
+ background: transparent;
199
+ transition: background var(--motion-duration-fast, 0.2s)
200
+ var(--motion-ease-in-out, cubic-bezier(0.4, 0, 0.2, 1));
201
+ }
202
+
203
+ &:hover::after,
204
+ &.dragging::after {
205
+ background: var(--color-primary);
206
+ }
207
+ }
208
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./StatisticsListPage";
2
+ export * from "./TreeTableTemplate";
2
3
  export { default as ColumnSettingsPanel } from "./ColumnSettingsPanel";
3
4
  export type { ColumnField } from "./ColumnSettingsPanel";
4
5
  export { default as FilterForm } from "./FilterForm";
@@ -1,5 +1,6 @@
1
1
  // 业务模板组件统一导出
2
2
  export * from "./StatisticsListPage";
3
+ export * from "./TreeTableTemplate";
3
4
  export { default as ColumnSettingsPanel } from "./ColumnSettingsPanel";
4
5
  export { default as FilterForm } from "./FilterForm";
5
6
  export { default as SmartListTemplate } from "./SmartListTemplate";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donglegeyu/company-ui",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/es/index.js",
6
6
  "types": "dist/es/index.d.ts",