@creekjs/web-components 1.0.16 → 1.0.18
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/.turbo/turbo-father$colon$build.log +25 -25
- package/dist/creek-keep-alive/index.d.ts +4 -0
- package/dist/creek-keep-alive/index.js +46 -31
- package/dist/creek-keep-alive/index.js.map +3 -3
- package/dist/creek-layout/ActionRender/UserInfo.js +2 -2
- package/dist/creek-layout/ActionRender/UserInfo.js.map +2 -2
- package/dist/creek-layout/ActionRender/index.d.ts +1 -1
- package/dist/creek-layout/ActionRender/index.js.map +2 -2
- package/dist/creek-layout/index.d.ts +12 -2
- package/dist/creek-layout/index.js +14 -2
- package/dist/creek-layout/index.js.map +3 -3
- package/dist/creek-table/hooks/useTableScrollHeight.js +22 -1
- package/dist/creek-table/hooks/useTableScrollHeight.js.map +2 -2
- package/package.json +1 -1
- package/src/creek-keep-alive/index.tsx +65 -60
- package/src/creek-layout/ActionRender/UserInfo.tsx +3 -3
- package/src/creek-layout/ActionRender/index.tsx +1 -1
- package/src/creek-layout/index.tsx +24 -4
- package/src/creek-table/hooks/useTableScrollHeight.tsx +30 -1
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @creekjs/web-components@1.0.
|
|
3
|
+
> @creekjs/web-components@1.0.17 father:build /Users/ernestwang/Documents/code-resoorce/creek/packages/web-components
|
|
4
4
|
> father build
|
|
5
5
|
|
|
6
6
|
[36minfo[39m - Clean output directories
|
|
7
7
|
[36minfo[39m - Bundless for [33msrc[39m directory to [33mcjs[39m format
|
|
8
8
|
[35mevent[39m - Bundless [90mCreekConfigContext.tsx[39m to [90mdist/creek-config-provider/CreekConfigContext.js[39m (with declaration)
|
|
9
|
-
[35mevent[39m - Bundless [
|
|
9
|
+
[35mevent[39m - Bundless [90mCreekI18nProvider.tsx[39m to [90mdist/creek-config-provider/CreekI18nProvider.js[39m (with declaration)
|
|
10
10
|
[35mevent[39m - Bundless [90mModalHelper.tsx[39m to [90mdist/creek-hooks/useApp/ModalHelper.js[39m (with declaration)
|
|
11
|
-
[35mevent[39m - Bundless [90mindex.
|
|
11
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-config-provider/index.js[39m (with declaration)
|
|
12
12
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-hooks/useApp/index.js[39m (with declaration)
|
|
13
13
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-icon/index.js[39m (with declaration)
|
|
14
|
-
[35mevent[39m - Bundless [90mtypes.ts[39m to [90mdist/creek-hooks/useApp/types.js[39m (with declaration)
|
|
15
|
-
[35mevent[39m - Bundless [90mDrawerHelper.tsx[39m to [90mdist/creek-hooks/useApp/DrawerHelper.js[39m (with declaration)
|
|
16
14
|
[35mevent[39m - Bundless [90museViewportHeight.tsx[39m to [90mdist/creek-hooks/useViewportHeight.js[39m (with declaration)
|
|
15
|
+
[35mevent[39m - Bundless [90mindex.ts[39m to [90mdist/creek-hooks/index.js[39m (with declaration)
|
|
17
16
|
[35mevent[39m - Bundless [90mFullScreen.tsx[39m to [90mdist/creek-layout/ActionRender/FullScreen.js[39m (with declaration)
|
|
18
|
-
[35mevent[39m - Bundless [
|
|
19
|
-
[35mevent[39m - Bundless [
|
|
20
|
-
[35mevent[39m - Bundless [
|
|
17
|
+
[35mevent[39m - Bundless [90mLayoutSettings.tsx[39m to [90mdist/creek-layout/ActionRender/LayoutSettings.js[39m (with declaration)
|
|
18
|
+
[35mevent[39m - Bundless [90mtypes.ts[39m to [90mdist/creek-hooks/useApp/types.js[39m (with declaration)
|
|
19
|
+
[35mevent[39m - Bundless [90mDrawerHelper.tsx[39m to [90mdist/creek-hooks/useApp/DrawerHelper.js[39m (with declaration)
|
|
21
20
|
[35mevent[39m - Bundless [90mNotFound.tsx[39m to [90mdist/creek-layout/Exception/NotFound.js[39m (with declaration)
|
|
22
|
-
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-layout/Exception/index.js[39m (with declaration)
|
|
23
21
|
[35mevent[39m - Bundless [90mNotFoundPage.tsx[39m to [90mdist/creek-layout/Exception/NotFoundPage.js[39m (with declaration)
|
|
24
|
-
[35mevent[39m - Bundless [
|
|
25
|
-
[35mevent[39m - Bundless [
|
|
26
|
-
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-layout/index.js[39m (with declaration)
|
|
22
|
+
[35mevent[39m - Bundless [90mUserInfo.tsx[39m to [90mdist/creek-layout/ActionRender/UserInfo.js[39m (with declaration)
|
|
23
|
+
[35mevent[39m - Bundless [90mCollapseButton.tsx[39m to [90mdist/creek-layout/CollapseButton.js[39m (with declaration)
|
|
24
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-layout/Exception/index.js[39m (with declaration)
|
|
27
25
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-page-container/index.js[39m (with declaration)
|
|
26
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-loading/index.js[39m (with declaration)
|
|
28
27
|
[35mevent[39m - Bundless [90museLayoutSettingsStore.ts[39m to [90mdist/creek-layout/useLayoutSettingsStore.js[39m (with declaration)
|
|
28
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-locale-button/index.js[39m (with declaration)
|
|
29
29
|
[35mevent[39m - Bundless [90mscrollbar.ts[39m to [90mdist/creek-style/scrollbar.js[39m (with declaration)
|
|
30
30
|
[35mevent[39m - Bundless [90mDensityIcon.tsx[39m to [90mdist/creek-table/components/DensityIcon.js[39m (with declaration)
|
|
31
|
-
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-loading/index.js[39m (with declaration)
|
|
32
|
-
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-locale-button/index.js[39m (with declaration)
|
|
33
|
-
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-table/components/index.js[39m (with declaration)
|
|
34
|
-
[35mevent[39m - Bundless [90museElementDistance.tsx[39m to [90mdist/creek-table/hooks/useElementDistance.js[39m (with declaration)
|
|
35
31
|
[35mevent[39m - Bundless [90museAdaptiveToolBar.tsx[39m to [90mdist/creek-table/hooks/useAdaptiveToolBar.js[39m (with declaration)
|
|
32
|
+
[35mevent[39m - Bundless [90mindex.ts[39m to [90mdist/creek-style/index.js[39m (with declaration)
|
|
33
|
+
[35mevent[39m - Bundless [90museElementDistance.tsx[39m to [90mdist/creek-table/hooks/useElementDistance.js[39m (with declaration)
|
|
36
34
|
[35mevent[39m - Bundless [90museIndexColumn.tsx[39m to [90mdist/creek-table/hooks/useIndexColumn.js[39m (with declaration)
|
|
37
35
|
[35mevent[39m - Bundless [90mEllipsisTooltip.tsx[39m to [90mdist/creek-table/components/EllipsisTooltip.js[39m (with declaration)
|
|
38
36
|
[35mevent[39m - Bundless [90museAutoWidthColumns.tsx[39m to [90mdist/creek-table/hooks/useAutoWidthColumns.js[39m (with declaration)
|
|
39
|
-
[35mevent[39m - Bundless [90museEllipsisColumns.tsx[39m to [90mdist/creek-table/hooks/useEllipsisColumns.js[39m (with declaration)
|
|
40
|
-
[35mevent[39m - Bundless [90museTableOptions.tsx[39m to [90mdist/creek-table/hooks/useTableOptions.js[39m (with declaration)
|
|
41
37
|
[35mevent[39m - Bundless [90mindex.ts[39m to [90mdist/creek-table/hooks/index.js[39m (with declaration)
|
|
42
|
-
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-table/index.js[39m (with declaration)
|
|
38
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-table/components/index.js[39m (with declaration)
|
|
39
|
+
[35mevent[39m - Bundless [90museResizableColumns.tsx[39m to [90mdist/creek-table/hooks/useResizableColumns.js[39m (with declaration)
|
|
40
|
+
[35mevent[39m - Bundless [90museTableOptions.tsx[39m to [90mdist/creek-table/hooks/useTableOptions.js[39m (with declaration)
|
|
41
|
+
[35mevent[39m - Bundless [90museEllipsisColumns.tsx[39m to [90mdist/creek-table/hooks/useEllipsisColumns.js[39m (with declaration)
|
|
43
42
|
[35mevent[39m - Bundless [90museTableScrollHeight.tsx[39m to [90mdist/creek-table/hooks/useTableScrollHeight.js[39m (with declaration)
|
|
43
|
+
[35mevent[39m - Bundless [90museStatusColumns.tsx[39m to [90mdist/creek-table/hooks/useStatusColumns.js[39m (with declaration)
|
|
44
44
|
[35mevent[39m - Bundless [90mtype.ts[39m to [90mdist/creek-table/type.js[39m (with declaration)
|
|
45
45
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/index.js[39m (with declaration)
|
|
46
|
-
[35mevent[39m - Bundless [90mSearchTable.tsx[39m to [90mdist/creek-table/SearchTable.js[39m (with declaration)
|
|
47
|
-
[35mevent[39m - Bundless [90mzh_CN.ts[39m to [90mdist/locales/zh_CN.js[39m (with declaration)
|
|
48
46
|
[35mevent[39m - Bundless [90men_US.ts[39m to [90mdist/locales/en_US.js[39m (with declaration)
|
|
49
|
-
[35mevent[39m - Bundless [
|
|
50
|
-
[35mevent[39m - Bundless [
|
|
51
|
-
[35mevent[39m - Bundless [
|
|
47
|
+
[35mevent[39m - Bundless [90mzh_CN.ts[39m to [90mdist/locales/zh_CN.js[39m (with declaration)
|
|
48
|
+
[35mevent[39m - Bundless [90mSearchTable.tsx[39m to [90mdist/creek-table/SearchTable.js[39m (with declaration)
|
|
49
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-table/index.js[39m (with declaration)
|
|
50
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-layout/ActionRender/index.js[39m (with declaration)
|
|
52
51
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-keep-alive/index.js[39m (with declaration)
|
|
52
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-layout/index.js[39m (with declaration)
|
|
53
53
|
[35mevent[39m - Generate declaration files...
|
|
54
|
-
[35mevent[39m - Transformed successfully in
|
|
54
|
+
[35mevent[39m - Transformed successfully in 6590 ms (45 files)
|
|
@@ -30,16 +30,21 @@ var import_react_router_dom = require("react-router-dom");
|
|
|
30
30
|
var import_react2 = require("@creekjs/i18n/react");
|
|
31
31
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
32
|
var CreekKeepAlive = (props) => {
|
|
33
|
-
const { exclude = [], getTabTitle, tabBarStyle, maxTabCount = 20 } = props;
|
|
33
|
+
const { exclude = [], getTabTitle, tabBarStyle, maxTabCount = 20, routes = [] } = props;
|
|
34
34
|
const t = (0, import_react2.useT)();
|
|
35
|
-
const outlet = (0, import_react_router_dom.useOutlet)();
|
|
36
35
|
const location = (0, import_react_router_dom.useLocation)();
|
|
37
36
|
const navigate = (0, import_react_router_dom.useNavigate)();
|
|
38
37
|
const [tabItems, setTabItems] = (0, import_react.useState)([]);
|
|
39
38
|
const [activeKey, setActiveKey] = (0, import_react.useState)("");
|
|
40
|
-
const [
|
|
41
|
-
const
|
|
42
|
-
|
|
39
|
+
const [cachedElements, setCachedElements] = (0, import_react.useState)({});
|
|
40
|
+
const resolveElement = (path) => {
|
|
41
|
+
if (!(routes == null ? void 0 : routes.length))
|
|
42
|
+
return null;
|
|
43
|
+
const matches = (0, import_react_router_dom.matchRoutes)(routes, path);
|
|
44
|
+
if (!(matches == null ? void 0 : matches.length))
|
|
45
|
+
return null;
|
|
46
|
+
return matches[matches.length - 1].route.element ?? null;
|
|
47
|
+
};
|
|
43
48
|
const isPathExcluded = (path) => {
|
|
44
49
|
return exclude.some((item) => {
|
|
45
50
|
if ((0, import_lodash.isString)(item)) {
|
|
@@ -53,20 +58,18 @@ var CreekKeepAlive = (props) => {
|
|
|
53
58
|
};
|
|
54
59
|
(0, import_react.useEffect)(() => {
|
|
55
60
|
const currentPath = location.pathname;
|
|
61
|
+
if (isPathExcluded(currentPath))
|
|
62
|
+
return;
|
|
63
|
+
const element = resolveElement(currentPath);
|
|
64
|
+
if (!element)
|
|
65
|
+
return;
|
|
66
|
+
if (!cachedElements[currentPath]) {
|
|
67
|
+
setCachedElements((prev) => ({ ...prev, [currentPath]: element }));
|
|
68
|
+
}
|
|
56
69
|
setActiveKey(currentPath);
|
|
57
|
-
setCachedPages((prev) => {
|
|
58
|
-
if (prev[currentPath]) {
|
|
59
|
-
return prev;
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
...prev,
|
|
63
|
-
[currentPath]: outletRef.current
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
70
|
setTabItems((prev) => {
|
|
67
71
|
if (prev.find((i) => i.key === currentPath)) {
|
|
68
|
-
|
|
69
|
-
return updated;
|
|
72
|
+
return prev.map((i) => ({ ...i, closable: prev.length > 1 }));
|
|
70
73
|
}
|
|
71
74
|
const title = (getTabTitle == null ? void 0 : getTabTitle(currentPath)) || currentPath;
|
|
72
75
|
const newItems = [...prev, { key: currentPath, label: title, closable: prev.length > 0 }];
|
|
@@ -77,19 +80,25 @@ var CreekKeepAlive = (props) => {
|
|
|
77
80
|
const indexToRemove = newItems.findIndex((item) => item.closable && item.key !== currentPath);
|
|
78
81
|
if (indexToRemove !== -1) {
|
|
79
82
|
const itemToRemove = newItems[indexToRemove];
|
|
80
|
-
|
|
83
|
+
setCachedElements((prev2) => {
|
|
84
|
+
const next = { ...prev2 };
|
|
85
|
+
delete next[itemToRemove.key];
|
|
86
|
+
return next;
|
|
87
|
+
});
|
|
81
88
|
newItems.splice(indexToRemove, 1);
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
return newItems;
|
|
85
92
|
});
|
|
86
|
-
}, [location.pathname, getTabTitle, maxTabCount]);
|
|
87
|
-
(0, import_react.useEffect)(() => {
|
|
88
|
-
}, []);
|
|
93
|
+
}, [location.pathname, getTabTitle, maxTabCount, cachedElements]);
|
|
89
94
|
const closeTab = (0, import_ahooks.useMemoizedFn)((targetKey) => {
|
|
90
95
|
const targetIndex = tabItems.findIndex((item) => item.key === targetKey);
|
|
91
96
|
const newTabItems = tabItems.filter((item) => item.key !== targetKey);
|
|
92
|
-
|
|
97
|
+
setCachedElements((prev) => {
|
|
98
|
+
const next = { ...prev };
|
|
99
|
+
delete next[targetKey];
|
|
100
|
+
return next;
|
|
101
|
+
});
|
|
93
102
|
setTabItems(newTabItems);
|
|
94
103
|
if (targetKey === activeKey) {
|
|
95
104
|
if (newTabItems.length > 0) {
|
|
@@ -105,14 +114,14 @@ var CreekKeepAlive = (props) => {
|
|
|
105
114
|
return;
|
|
106
115
|
const newTabItems = [{ ...currentTab, closable: false }];
|
|
107
116
|
setTabItems(newTabItems);
|
|
108
|
-
const keepKeys = newTabItems.map((i) => i.key);
|
|
109
|
-
|
|
110
|
-
const
|
|
117
|
+
const keepKeys = new Set(newTabItems.map((i) => i.key));
|
|
118
|
+
setCachedElements((prev) => {
|
|
119
|
+
const next = {};
|
|
111
120
|
keepKeys.forEach((k) => {
|
|
112
121
|
if (prev[k])
|
|
113
|
-
|
|
122
|
+
next[k] = prev[k];
|
|
114
123
|
});
|
|
115
|
-
return
|
|
124
|
+
return next;
|
|
116
125
|
});
|
|
117
126
|
if (activeKey !== currentKey) {
|
|
118
127
|
navigate(currentKey);
|
|
@@ -121,11 +130,17 @@ var CreekKeepAlive = (props) => {
|
|
|
121
130
|
const closeRightTabs = (0, import_ahooks.useMemoizedFn)((currentKey) => {
|
|
122
131
|
const currentIndex = tabItems.findIndex((i) => i.key === currentKey);
|
|
123
132
|
const rightItems = tabItems.slice(currentIndex + 1);
|
|
124
|
-
const rightKeys = rightItems.map((i) => i.key);
|
|
125
|
-
const newTabItems = tabItems.filter((i) => !rightKeys.
|
|
133
|
+
const rightKeys = new Set(rightItems.map((i) => i.key));
|
|
134
|
+
const newTabItems = tabItems.filter((i) => !rightKeys.has(i.key));
|
|
126
135
|
setTabItems(newTabItems);
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
setCachedElements((prev) => {
|
|
137
|
+
const next = { ...prev };
|
|
138
|
+
rightKeys.forEach((key) => {
|
|
139
|
+
delete next[key];
|
|
140
|
+
});
|
|
141
|
+
return next;
|
|
142
|
+
});
|
|
143
|
+
if (rightKeys.has(activeKey)) {
|
|
129
144
|
navigate(currentKey);
|
|
130
145
|
}
|
|
131
146
|
});
|
|
@@ -170,7 +185,7 @@ var CreekKeepAlive = (props) => {
|
|
|
170
185
|
items: tabItems.map((item) => ({
|
|
171
186
|
...item,
|
|
172
187
|
label: renderTabLabel(item),
|
|
173
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { height: "100%", display: activeKey === item.key ? "block" : "none" }, children:
|
|
188
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { height: "100%", display: activeKey === item.key ? "block" : "none" }, children: cachedElements[item.key] ?? null }, item.key)
|
|
174
189
|
}))
|
|
175
190
|
}
|
|
176
191
|
) });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/creek-keep-alive/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useMemoizedFn } from 'ahooks';\nimport { Dropdown, MenuProps, Tabs } from 'antd';\nimport { isRegExp, isString
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8B;AAC9B,kBAA0C;AAC1C,
|
|
6
|
-
"names": ["import_react"]
|
|
4
|
+
"sourcesContent": ["import { useMemoizedFn } from 'ahooks';\nimport { Dropdown, MenuProps, Tabs } from 'antd';\nimport { isRegExp, isString } from 'lodash';\nimport React, { useEffect, useState } from 'react';\nimport { matchRoutes, useLocation, useNavigate } from 'react-router-dom';\n\nimport { useT } from '@creekjs/i18n/react';\n\nexport interface CreekKeepAliveProps {\n /**\n * 不需要缓存的路径\n */\n exclude?: (string | RegExp)[];\n /**\n * 自定义Tab标题获取方法\n */\n getTabTitle?: (pathname: string) => React.ReactNode;\n /**\n * Tabs的样式\n */\n tabBarStyle?: React.CSSProperties;\n /**\n * 最大缓存数量,默认为 20\n */\n maxTabCount?: number;\n /**\n * 路由配置(含 element),用于解析每个路径对应的页面组件\n */\n routes?: any[];\n}\n\ninterface TabItem {\n key: string;\n label: React.ReactNode;\n closable?: boolean;\n}\n\nexport const CreekKeepAlive: React.FC<CreekKeepAliveProps> = (props) => {\n const { exclude = [], getTabTitle, tabBarStyle, maxTabCount = 20, routes = [] } = props;\n\n const t = useT();\n const location = useLocation();\n const navigate = useNavigate();\n\n const [tabItems, setTabItems] = useState<TabItem[]>([]);\n const [activeKey, setActiveKey] = useState<string>('');\n\n // 缓存每个路径对应的 React element,保证同一页面始终复用同一个 element 引用\n // 这样 React reconciler 不会卸载/重新挂载组件,从而实现 keep-alive\n // 使用 state 以便缓存变化时触发重新渲染\n const [cachedElements, setCachedElements] = useState<Record<string, React.ReactNode>>({});\n\n // 根据路由配置,解析指定路径对应的叶子路由 element\n const resolveElement = (path: string): React.ReactNode | null => {\n if (!routes?.length) return null;\n const matches = matchRoutes(routes, path);\n if (!matches?.length) return null;\n // 取最后一个 match(叶子路由),即实际页面组件\n return matches[matches.length - 1].route.element ?? null;\n };\n\n // 判断是否不需要缓存\n const isPathExcluded = (path: string) => {\n return exclude.some((item) => {\n if (isString(item)) {\n return item === path;\n }\n if (isRegExp(item)) {\n return item.test(path);\n }\n return false;\n });\n };\n\n // 初始化或路由变化时更新\n useEffect(() => {\n const currentPath = location.pathname;\n\n // 不需要缓存的路径,不创建 tab\n if (isPathExcluded(currentPath)) return;\n\n // 如果路由配置中没有对应的 element(如纯 redirect 路由),不创建 tab\n const element = resolveElement(currentPath);\n if (!element) return;\n\n // 缓存当前路径的 element(仅首次缓存,后续复用同一个 element 引用)\n if (!cachedElements[currentPath]) {\n setCachedElements((prev) => ({ ...prev, [currentPath]: element }));\n }\n\n setActiveKey(currentPath);\n\n // 更新 Tab 列表\n setTabItems((prev) => {\n if (prev.find((i) => i.key === currentPath)) {\n // 更新现有 tab 的 closable 状态(只有最后一个 tab 时不可关闭)\n return prev.map((i) => ({ ...i, closable: prev.length > 1 }));\n }\n const title = getTabTitle?.(currentPath) || currentPath;\n const newItems = [...prev, { key: currentPath, label: title, closable: prev.length > 0 }];\n\n // 只有1个 tab 时不可关闭\n if (newItems.length === 1) {\n newItems[0].closable = false;\n }\n\n // 超过最大数量限制,移除最早的可关闭 tab\n if (newItems.length > maxTabCount) {\n const indexToRemove = newItems.findIndex((item) => item.closable && item.key !== currentPath);\n if (indexToRemove !== -1) {\n const itemToRemove = newItems[indexToRemove];\n setCachedElements((prev) => {\n const next = { ...prev };\n delete next[itemToRemove.key];\n return next;\n });\n newItems.splice(indexToRemove, 1);\n }\n }\n return newItems;\n });\n }, [location.pathname, getTabTitle, maxTabCount, cachedElements]);\n\n const closeTab = useMemoizedFn((targetKey: string) => {\n const targetIndex = tabItems.findIndex((item) => item.key === targetKey);\n const newTabItems = tabItems.filter((item) => item.key !== targetKey);\n\n // 移除缓存,组件将卸载\n setCachedElements((prev) => {\n const next = { ...prev };\n delete next[targetKey];\n return next;\n });\n setTabItems(newTabItems);\n\n // 如果关闭的是当前页,跳转到临近页\n if (targetKey === activeKey) {\n if (newTabItems.length > 0) {\n const nextIndex = targetIndex >= newTabItems.length ? newTabItems.length - 1 : targetIndex;\n const nextKey = newTabItems[nextIndex].key;\n navigate(nextKey);\n }\n }\n });\n\n const closeOtherTabs = useMemoizedFn((currentKey: string) => {\n const currentTab = tabItems.find((item) => item.key === currentKey);\n if (!currentTab) return;\n const newTabItems = [{ ...currentTab, closable: false }];\n setTabItems(newTabItems);\n\n // 仅保留当前 tab 的缓存\n const keepKeys = new Set(newTabItems.map((i) => i.key));\n setCachedElements((prev) => {\n const next: Record<string, React.ReactNode> = {};\n keepKeys.forEach((k) => {\n if (prev[k]) next[k] = prev[k];\n });\n return next;\n });\n\n if (activeKey !== currentKey) {\n navigate(currentKey);\n }\n });\n\n const closeRightTabs = useMemoizedFn((currentKey: string) => {\n const currentIndex = tabItems.findIndex((i) => i.key === currentKey);\n const rightItems = tabItems.slice(currentIndex + 1);\n const rightKeys = new Set(rightItems.map((i) => i.key));\n\n const newTabItems = tabItems.filter((i) => !rightKeys.has(i.key));\n setTabItems(newTabItems);\n\n // 移除右侧 tab 的缓存\n setCachedElements((prev) => {\n const next = { ...prev };\n rightKeys.forEach((key) => { delete next[key]; });\n return next;\n });\n\n if (rightKeys.has(activeKey)) {\n navigate(currentKey);\n }\n });\n\n const handleTabEdit = (targetKey: React.MouseEvent | React.KeyboardEvent | string, action: 'add' | 'remove') => {\n if (action === 'remove' && isString(targetKey)) {\n closeTab(targetKey);\n }\n };\n\n const handleTabClick = (key: string) => {\n navigate(key);\n };\n\n const renderTabLabel = (item: TabItem) => {\n const menuItems: MenuProps['items'] = [\n {\n key: 'close',\n label: t('creek-keep-alive.index.guanBiDangQian', '关闭当前'),\n disabled: tabItems.length <= 1,\n onClick: () => closeTab(item.key),\n },\n {\n key: 'closeOthers',\n label: t('creek-keep-alive.index.guanBiQiTa', '关闭其他'),\n onClick: () => closeOtherTabs(item.key),\n },\n {\n key: 'closeRight',\n label: t('creek-keep-alive.index.guanBiYouCe', '关闭右侧'),\n onClick: () => closeRightTabs(item.key),\n },\n ];\n\n return (\n <Dropdown menu={{ items: menuItems }} trigger={['contextMenu']}>\n <span>{item.label}</span>\n </Dropdown>\n );\n };\n\n return (\n <div className=\"creek-keep-alive\">\n <Tabs\n activeKey={activeKey}\n type=\"editable-card\"\n hideAdd\n onChange={handleTabClick}\n onEdit={handleTabEdit}\n tabBarStyle={{ margin: 0, ...tabBarStyle }}\n items={tabItems.map((item) => ({\n ...item,\n label: renderTabLabel(item),\n children: (\n <div key={item.key} style={{ height: '100%', display: activeKey === item.key ? 'block' : 'none' }}>\n {cachedElements[item.key] ?? null}\n </div>\n ),\n }))}\n />\n </div>\n );\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8B;AAC9B,kBAA0C;AAC1C,oBAAmC;AAC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|
|
|
47
47
|
const { styles } = useStyles();
|
|
48
48
|
const { name, avatar, menu } = props;
|
|
49
49
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Dropdown, { arrow: true, placement: "bottom", overlayClassName: styles.userInfoDropdownOverlay, menu, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd.Space, { size: 4, align: "center", children: [
|
|
50
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Avatar, { className: styles.avatarContainer, src: avatar, children: name }),
|
|
51
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
50
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Avatar, { className: styles.avatarContainer, src: avatar, children: typeof name === "string" ? name.charAt(0).toUpperCase() : name }),
|
|
51
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Typography.Text, { strong: true, children: name })
|
|
52
52
|
] }) });
|
|
53
53
|
};
|
|
54
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/creek-layout/ActionRender/UserInfo.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Avatar, Dropdown, DropDownProps, Space } from \"antd\";\nimport { createStyles } from \"antd-style\";\n\nconst useStyles = createStyles(({ token}) => ({\n avatarContainer: {\n backgroundColor: token.colorPrimary,\n width: 24,\n height: 24,\n },\n userInfoDropdownOverlay: {\n \".ant-dropdown-menu\": {\n padding: \"8px 0\",\n },\n \".ant-dropdown-menu-item\": {\n \".ant-dropdown-menu-item-icon\": {\n fontSize: \"18px\",\n marginRight: \"8px\",\n },\n },\n },\n}));\n\nexport interface UserInfoProps {\n name?: React.ReactNode;\n avatar?: string;\n menu?: DropDownProps['menu'];\n}\n\nexport const UserInfo = (props: UserInfoProps) => {\n const { styles } = useStyles();\n const { name, avatar, menu } = props;\n\n return (\n <Dropdown arrow placement=\"bottom\" overlayClassName={styles.userInfoDropdownOverlay} menu={menu}>\n <Space size={4} align=\"center\">\n <Avatar className={styles.avatarContainer} src={avatar}>\n {name}\n </Avatar>\n <
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Avatar, Dropdown, DropDownProps, Space, Typography } from \"antd\";\nimport { createStyles } from \"antd-style\";\n\nconst useStyles = createStyles(({ token}) => ({\n avatarContainer: {\n backgroundColor: token.colorPrimary,\n width: 24,\n height: 24,\n },\n userInfoDropdownOverlay: {\n \".ant-dropdown-menu\": {\n padding: \"8px 0\",\n },\n \".ant-dropdown-menu-item\": {\n \".ant-dropdown-menu-item-icon\": {\n fontSize: \"18px\",\n marginRight: \"8px\",\n },\n },\n },\n}));\n\nexport interface UserInfoProps {\n name?: React.ReactNode;\n avatar?: string;\n menu?: DropDownProps['menu'];\n}\n\nexport const UserInfo = (props: UserInfoProps) => {\n const { styles } = useStyles();\n const { name, avatar, menu } = props;\n\n return (\n <Dropdown arrow placement=\"bottom\" overlayClassName={styles.userInfoDropdownOverlay} menu={menu}>\n <Space size={4} align=\"center\">\n <Avatar className={styles.avatarContainer} src={avatar}>\n {typeof name === 'string' ? name.charAt(0).toUpperCase() : name}\n </Avatar>\n <Typography.Text strong>{name}</Typography.Text>\n </Space>\n </Dropdown>\n );\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmE;AACnE,wBAA6B;AAiCvB;AA/BN,IAAM,gBAAY,gCAAa,CAAC,EAAE,MAAK,OAAO;AAAA,EAC5C,iBAAiB;AAAA,IACf,iBAAiB,MAAM;AAAA,IACvB,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAAA,EACA,yBAAyB;AAAA,IACvB,sBAAsB;AAAA,MACpB,SAAS;AAAA,IACX;AAAA,IACA,2BAA2B;AAAA,MACzB,gCAAgC;AAAA,QAC9B,UAAU;AAAA,QACV,aAAa;AAAA,MACf;AAAA,IACF;AAAA,EACF;AACF,EAAE;AAQK,IAAM,WAAW,CAAC,UAAyB;AAChD,QAAM,EAAE,OAAO,IAAI,UAAU;AAC7B,QAAM,EAAE,MAAM,QAAQ,KAAK,IAAI;AAE/B,SACE,4CAAC,wBAAS,OAAK,MAAC,WAAU,UAAS,kBAAkB,OAAO,yBAAyB,MACnF,uDAAC,qBAAM,MAAM,GAAG,OAAM,UACpB;AAAA,gDAAC,sBAAO,WAAW,OAAO,iBAAiB,KAAK,QAC7C,iBAAO,SAAS,WAAW,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,MAC7D;AAAA,IACA,4CAAC,uBAAW,MAAX,EAAgB,QAAM,MAAE,gBAAK;AAAA,KAChC,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/creek-layout/ActionRender/index.tsx"],
|
|
4
|
-
"sourcesContent": ["export { FullScreen } from './FullScreen';\nexport { UserInfo } from './UserInfo';\nexport { LayoutSettings } from './LayoutSettings';\n\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA2B;AAC3B,
|
|
4
|
+
"sourcesContent": ["export { FullScreen } from './FullScreen';\nexport { UserInfo, type UserInfoProps } from './UserInfo';\nexport { LayoutSettings } from './LayoutSettings';\n\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA2B;AAC3B,sBAA6C;AAC7C,4BAA+B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ProLayoutProps } from '@ant-design/pro-components';
|
|
3
3
|
import { CreekKeepAliveProps } from '../creek-keep-alive';
|
|
4
|
-
|
|
4
|
+
import { UserInfoProps } from './ActionRender';
|
|
5
|
+
export type CreekLayoutProps = ProLayoutProps & {
|
|
5
6
|
runtimeConfig: ProLayoutProps;
|
|
6
7
|
userConfig?: ProLayoutProps;
|
|
7
8
|
navigate?: (path?: string | number) => void;
|
|
@@ -16,6 +17,15 @@ export type LayoutProps = ProLayoutProps & {
|
|
|
16
17
|
};
|
|
17
18
|
keepAlive?: boolean | CreekKeepAliveProps;
|
|
18
19
|
extraActions?: React.ReactNode[];
|
|
20
|
+
clientRoutes?: any[];
|
|
21
|
+
iconFontCNs?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* 用户信息区域,支持传入配置对象(名称、头像、下拉菜单)或自定义渲染函数
|
|
24
|
+
* - 传对象:自动使用 UserInfo 组件渲染
|
|
25
|
+
* - 传函数:返回 ReactNode 直接渲染,返回 UserInfoProps 对象则使用 UserInfo 组件渲染
|
|
26
|
+
*/
|
|
27
|
+
renderUser?: UserInfoProps | (() => React.ReactNode | UserInfoProps);
|
|
19
28
|
};
|
|
20
|
-
export declare const CreekLayout: (props:
|
|
29
|
+
export declare const CreekLayout: (props: CreekLayoutProps) => import("react/jsx-runtime").JSX.Element;
|
|
21
30
|
export * from './Exception';
|
|
31
|
+
export { UserInfo, type UserInfoProps } from './ActionRender';
|
|
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/creek-layout/index.tsx
|
|
31
31
|
var creek_layout_exports = {};
|
|
32
32
|
__export(creek_layout_exports, {
|
|
33
|
-
CreekLayout: () => CreekLayout
|
|
33
|
+
CreekLayout: () => CreekLayout,
|
|
34
|
+
UserInfo: () => import_ActionRender2.UserInfo
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(creek_layout_exports);
|
|
36
37
|
var import_pro_components = require("@ant-design/pro-components");
|
|
@@ -48,6 +49,7 @@ var import_CollapseButton = require("./CollapseButton");
|
|
|
48
49
|
var import_Exception = require("./Exception");
|
|
49
50
|
var import_useLayoutSettingsStore = require("./useLayoutSettingsStore");
|
|
50
51
|
__reExport(creek_layout_exports, require("./Exception"), module.exports);
|
|
52
|
+
var import_ActionRender2 = require("./ActionRender");
|
|
51
53
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
52
54
|
var MenuName = ({ name, path }) => {
|
|
53
55
|
const t = (0, import_react2.useT)();
|
|
@@ -68,6 +70,9 @@ var CreekLayout = (props) => {
|
|
|
68
70
|
showThemeColor = true,
|
|
69
71
|
keepAlive = false,
|
|
70
72
|
extraActions = [],
|
|
73
|
+
clientRoutes,
|
|
74
|
+
iconFontCNs,
|
|
75
|
+
renderUser,
|
|
71
76
|
...more
|
|
72
77
|
} = props;
|
|
73
78
|
const { useToken } = import_antd.theme;
|
|
@@ -124,6 +129,12 @@ var CreekLayout = (props) => {
|
|
|
124
129
|
return hasI18n ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuName, { name: title, path: pathname }) : title;
|
|
125
130
|
});
|
|
126
131
|
const actions = [...extraActions];
|
|
132
|
+
if (renderUser) {
|
|
133
|
+
let result = typeof renderUser === "function" ? renderUser() : renderUser;
|
|
134
|
+
const isUserInfoProps = (val) => val !== null && typeof val === "object" && ("name" in val || "avatar" in val || "menu" in val);
|
|
135
|
+
const userInfoNode = isUserInfoProps(result) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ActionRender.UserInfo, { ...result }) : result;
|
|
136
|
+
actions.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: userInfoNode }, "user-info"));
|
|
137
|
+
}
|
|
127
138
|
if (actualShowFullScreen) {
|
|
128
139
|
actions.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ActionRender.FullScreen, {}, "full-screen"));
|
|
129
140
|
}
|
|
@@ -175,7 +186,7 @@ var CreekLayout = (props) => {
|
|
|
175
186
|
...more,
|
|
176
187
|
children: [
|
|
177
188
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_scrollbar.GlobalScrollbarStyle, {}),
|
|
178
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Exception.Exception, { children: actualKeepAlive ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_creek_keep_alive.CreekKeepAlive, { getTabTitle, ...keepAliveProps }) : children })
|
|
189
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Exception.Exception, { children: actualKeepAlive ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_creek_keep_alive.CreekKeepAlive, { getTabTitle, routes: clientRoutes ?? (route == null ? void 0 : route.routes), ...keepAliveProps }) : children })
|
|
179
190
|
]
|
|
180
191
|
}
|
|
181
192
|
);
|
|
@@ -184,6 +195,7 @@ var CreekLayout = (props) => {
|
|
|
184
195
|
// Annotate the CommonJS export names for ESM import in node:
|
|
185
196
|
0 && (module.exports = {
|
|
186
197
|
CreekLayout,
|
|
198
|
+
UserInfo,
|
|
187
199
|
...require("./Exception")
|
|
188
200
|
});
|
|
189
201
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/creek-layout/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { MenuDataItem, ProLayout, ProLayoutProps } from '@ant-design/pro-components';\nimport { useMemoizedFn } from 'ahooks';\nimport { theme } from 'antd';\nimport _ from 'lodash';\nimport { useContext } from 'react';\n\nimport classnames from 'classnames';\n\nimport { IntlContext, useT } from '@creekjs/i18n/react';\n\nimport { CreekKeepAlive, CreekKeepAliveProps } from '../creek-keep-alive';\nimport { CreekLocaleButton } from '../creek-locale-button';\nimport { GlobalScrollbarStyle } from '../creek-style/scrollbar';\nimport { FullScreen, LayoutSettings } from './ActionRender';\nimport { CollapsedButton, useCollapsedStore } from './CollapseButton';\nimport { Exception } from './Exception';\nimport { useLayoutSettingsStore } from './useLayoutSettingsStore';\n\nexport type
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAwD;AACxD,oBAA8B;AAC9B,kBAAsB;AACtB,oBAAc;AACd,mBAA2B;AAE3B,wBAAuB;AAEvB,IAAAA,gBAAkC;AAElC,8BAAoD;AACpD,iCAAkC;AAClC,uBAAqC;AACrC,
|
|
6
|
-
"names": ["import_react", "_", "classnames", "collapsed"]
|
|
4
|
+
"sourcesContent": ["import { MenuDataItem, ProLayout, ProLayoutProps } from '@ant-design/pro-components';\nimport { useMemoizedFn } from 'ahooks';\nimport { theme } from 'antd';\nimport _ from 'lodash';\nimport { useContext } from 'react';\n\nimport classnames from 'classnames';\n\nimport { IntlContext, useT } from '@creekjs/i18n/react';\n\nimport { CreekKeepAlive, CreekKeepAliveProps } from '../creek-keep-alive';\nimport { CreekLocaleButton } from '../creek-locale-button';\nimport { GlobalScrollbarStyle } from '../creek-style/scrollbar';\nimport { FullScreen, LayoutSettings, UserInfo, UserInfoProps } from './ActionRender';\nimport { CollapsedButton, useCollapsedStore } from './CollapseButton';\nimport { Exception } from './Exception';\nimport { useLayoutSettingsStore } from './useLayoutSettingsStore';\n\nexport type CreekLayoutProps = ProLayoutProps & {\n runtimeConfig: ProLayoutProps;\n userConfig?: ProLayoutProps;\n navigate?: (path?: string | number) => void;\n showFullScreen?: boolean;\n showLocaleButton?: boolean;\n showSettingsButton?: boolean;\n showThemeColor?: boolean;\n initialInfo?: {\n initialState: any;\n loading: boolean;\n setInitialState: () => void;\n };\n keepAlive?: boolean | CreekKeepAliveProps;\n extraActions?: React.ReactNode[];\n clientRoutes?: any[];\n iconFontCNs?: string[];\n /**\n * 用户信息区域,支持传入配置对象(名称、头像、下拉菜单)或自定义渲染函数\n * - 传对象:自动使用 UserInfo 组件渲染\n * - 传函数:返回 ReactNode 直接渲染,返回 UserInfoProps 对象则使用 UserInfo 组件渲染\n */\n renderUser?: UserInfoProps | (() => React.ReactNode | UserInfoProps);\n};\n\nconst MenuName = ({ name, path }: { name?: string; path?: string }) => {\n const t = useT();\n const key = !path || path === '/' ? 'menu.home' : `menu${path.replace(/\\//g, '.')}`;\n return t(key, name);\n};\n\nexport const CreekLayout = (props: CreekLayoutProps) => {\n const {\n route,\n userConfig,\n runtimeConfig,\n children,\n location,\n navigate,\n showFullScreen = false,\n showLocaleButton = false,\n showSettingsButton = false,\n showThemeColor = true,\n keepAlive = false,\n extraActions = [],\n clientRoutes,\n iconFontCNs,\n renderUser,\n ...more\n } = props;\n\n const { useToken } = theme;\n const { token } = useToken();\n\n const { collapsed } = useCollapsedStore();\n const settingsStore = useLayoutSettingsStore();\n\n const actualShowFullScreen = showFullScreen && (settingsStore.showFullScreen ?? true);\n const actualShowLocaleButton = showLocaleButton && (settingsStore.showLocaleButton ?? true);\n const colorPrimary = settingsStore.colorPrimary || token.colorPrimary;\n const actualKeepAlive = keepAlive && (settingsStore.keepAlive ?? true);\n\n const _userConfig = { ...userConfig, ...runtimeConfig };\n\n const intlContext = useContext(IntlContext);\n const hasI18n = !!intlContext && actualShowLocaleButton;\n\n const menuDataRender = useMemoizedFn((menuData: MenuDataItem[]) => {\n // 根据当前是否开启了国际化(上下文是否存在)以及用户配置来判断是否包裹菜单翻译\n const isLocaleEnabled = hasI18n;\n\n const mapMenu = (items: MenuDataItem[]): MenuDataItem[] => {\n return items.map((item) => {\n return {\n ...item,\n name: (isLocaleEnabled ? <MenuName name={item.name} path={item.path} /> : item.name) as string,\n children: item.children ? mapMenu(item.children) : undefined,\n };\n });\n };\n return mapMenu(menuData);\n });\n\n const menuItemRender: ProLayoutProps['menuItemRender'] = useMemoizedFn((itemProps, defaultDom) => {\n return (\n <span\n onClick={() => {\n if (navigate) {\n navigate(itemProps.path);\n }\n }}\n >\n {defaultDom}\n </span>\n );\n });\n\n const getTabTitle = useMemoizedFn((pathname: string): string | React.ReactNode => {\n const routes = (route?.routes ?? []) as MenuDataItem[];\n\n const findTitle = (items: MenuDataItem[]): string | undefined => {\n for (const item of items) {\n if (item.path === pathname) return item.name ?? item.title;\n if (item.children) {\n const found = findTitle(item.children);\n if (found) return found;\n }\n }\n };\n\n const title = findTitle(routes) ?? pathname;\n\n return hasI18n ? <MenuName name={title} path={pathname} /> : title;\n });\n\n const actions: React.ReactNode[] = [...extraActions];\n\n if (renderUser) {\n let result = typeof renderUser === 'function' ? renderUser() : renderUser;\n const isUserInfoProps = (val: unknown): val is UserInfoProps =>\n val !== null && typeof val === 'object' && ('name' in val || 'avatar' in val || 'menu' in val);\n const userInfoNode = isUserInfoProps(result) ? <UserInfo {...result} /> : result;\n actions.push(<span key=\"user-info\">{userInfoNode}</span>);\n }\n\n if (actualShowFullScreen) {\n actions.push(<FullScreen key=\"full-screen\" />);\n }\n\n if (actualShowLocaleButton) {\n actions.push(<CreekLocaleButton key=\"locale-button\" />);\n }\n\n if (showSettingsButton) {\n actions.push(<LayoutSettings key=\"settings\" defaultShowFullScreen={showFullScreen} defaultShowLocaleButton={showLocaleButton} defaultShowThemeColor={showThemeColor} defaultKeepAlive={_.isBoolean(keepAlive) ? keepAlive : true} />);\n }\n\n const keepAliveProps = _.isBoolean(keepAlive) ? {} : keepAlive;\n\n const layoutContent = (\n <ProLayout\n className={classnames('creek-layout-container', _userConfig?.className)}\n route={route}\n title={_userConfig?.title}\n siderWidth={200}\n location={location}\n menuDataRender={menuDataRender}\n menuItemRender={menuItemRender}\n actionsRender={() => actions}\n token={{\n header: {\n colorBgHeader: '#fff',\n colorHeaderTitle: 'rgba(0, 0, 0, 0.80);',\n colorTextMenuSelected: colorPrimary,\n heightLayoutHeader: 48,\n },\n sider: {\n colorMenuBackground: '#f7f8fa',\n colorBgMenuItemSelected: 'transparent',\n colorTextMenuActive: colorPrimary,\n colorTextMenuSelected: colorPrimary,\n colorTextMenuItemHover: colorPrimary,\n colorTextMenu: '#333',\n },\n pageContainer: {\n paddingBlockPageContainerContent: 0,\n paddingInlinePageContainerContent: 0,\n colorBgPageContainer: 'linear-gradient(180deg, #F7F9FF 0%, #FFF 45.59%);',\n },\n }}\n fixSiderbar\n fixedHeader\n collapsed={collapsed}\n collapsedButtonRender={(collapsed) => {\n return <CollapsedButton collapsed={collapsed} />;\n }}\n {...more}\n >\n <GlobalScrollbarStyle />\n <Exception>{actualKeepAlive ? <CreekKeepAlive getTabTitle={getTabTitle} routes={clientRoutes ?? route?.routes} {...keepAliveProps} /> : children}</Exception>\n </ProLayout>\n );\n\n return layoutContent;\n};\n\nexport * from './Exception';\nexport { UserInfo, type UserInfoProps } from './ActionRender';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAwD;AACxD,oBAA8B;AAC9B,kBAAsB;AACtB,oBAAc;AACd,mBAA2B;AAE3B,wBAAuB;AAEvB,IAAAA,gBAAkC;AAElC,8BAAoD;AACpD,iCAAkC;AAClC,uBAAqC;AACrC,0BAAoE;AACpE,4BAAmD;AACnD,uBAA0B;AAC1B,oCAAuC;AA4LvC,iCAAc,wBA5Md;AA6MA,IAAAC,uBAA6C;AAhHV;AAlDnC,IAAM,WAAW,CAAC,EAAE,MAAM,KAAK,MAAwC;AACrE,QAAM,QAAI,oBAAK;AACf,QAAM,MAAM,CAAC,QAAQ,SAAS,MAAM,cAAc,OAAO,KAAK,QAAQ,OAAO,GAAG;AAChF,SAAO,EAAE,KAAK,IAAI;AACpB;AAEO,IAAM,cAAc,CAAC,UAA4B;AACtD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,IACjB,YAAY;AAAA,IACZ,eAAe,CAAC;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IAC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;AAAA,UACN,eAAe;AAAA,UACf,kBAAkB;AAAA,UAClB,uBAAuB;AAAA,UACvB,oBAAoB;AAAA,QACtB;AAAA,QACA,OAAO;AAAA,UACL,qBAAqB;AAAA,UACrB,yBAAyB;AAAA,UACzB,qBAAqB;AAAA,UACrB,uBAAuB;AAAA,UACvB,wBAAwB;AAAA,UACxB,eAAe;AAAA,QACjB;AAAA,QACA,eAAe;AAAA,UACb,kCAAkC;AAAA,UAClC,mCAAmC;AAAA,UACnC,sBAAsB;AAAA,QACxB;AAAA,MACF;AAAA,MACA,aAAW;AAAA,MACX,aAAW;AAAA,MACX;AAAA,MACA,uBAAuB,CAACC,eAAc;AACpC,eAAO,4CAAC,yCAAgB,WAAWA,YAAW;AAAA,MAChD;AAAA,MACC,GAAG;AAAA,MAEJ;AAAA,oDAAC,yCAAqB;AAAA,QACtB,4CAAC,8BAAW,4BAAkB,4CAAC,0CAAe,aAA0B,QAAQ,iBAAgB,+BAAO,SAAS,GAAG,gBAAgB,IAAK,UAAS;AAAA;AAAA;AAAA,EACnJ;AAGF,SAAO;AACT;",
|
|
6
|
+
"names": ["import_react", "import_ActionRender", "_", "classnames", "collapsed"]
|
|
7
7
|
}
|
|
@@ -24,6 +24,18 @@ __export(useTableScrollHeight_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(useTableScrollHeight_exports);
|
|
25
25
|
var import_ahooks = require("ahooks");
|
|
26
26
|
var import_react = require("react");
|
|
27
|
+
var getScrollParent = (element) => {
|
|
28
|
+
let parent = element.parentElement;
|
|
29
|
+
while (parent) {
|
|
30
|
+
const style = window.getComputedStyle(parent);
|
|
31
|
+
const overflowY = style.overflowY;
|
|
32
|
+
if (overflowY === "auto" || overflowY === "scroll") {
|
|
33
|
+
return parent;
|
|
34
|
+
}
|
|
35
|
+
parent = parent.parentElement;
|
|
36
|
+
}
|
|
37
|
+
return window;
|
|
38
|
+
};
|
|
27
39
|
var useTableScrollHeight = (prefixCls, tableRef, pageFixedBottom = true, offsetBottom = 0) => {
|
|
28
40
|
const [scrollY, setScrollY] = (0, import_react.useState)(void 0);
|
|
29
41
|
const [tableHeight, setTableHeight] = (0, import_react.useState)(void 0);
|
|
@@ -64,16 +76,24 @@ var useTableScrollHeight = (prefixCls, tableRef, pageFixedBottom = true, offsetB
|
|
|
64
76
|
}
|
|
65
77
|
const windowHeight = window.innerHeight;
|
|
66
78
|
let height = windowHeight - top - currentContentPadding - currentCardContentPadding - offsetBottom;
|
|
67
|
-
|
|
79
|
+
const scrollParent = getScrollParent(tableEl);
|
|
80
|
+
let parentTop = 0;
|
|
81
|
+
if (scrollParent instanceof HTMLElement) {
|
|
82
|
+
parentTop = scrollParent.getBoundingClientRect().top;
|
|
83
|
+
}
|
|
84
|
+
const tableTopRelativeToParent = tableEl.getBoundingClientRect().top - parentTop;
|
|
85
|
+
let currentTableHeight = windowHeight - tableTopRelativeToParent - offsetBottom;
|
|
68
86
|
const pagination = tableEl.querySelector(`.${prefixCls}-pagination`);
|
|
69
87
|
if (pagination) {
|
|
70
88
|
const paginationHeight = pagination.clientHeight;
|
|
71
89
|
const styles = window.getComputedStyle(pagination);
|
|
72
90
|
const totalPaginationMargin = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
|
|
73
91
|
height = height - paginationHeight - totalPaginationMargin;
|
|
92
|
+
currentTableHeight = currentTableHeight - paginationHeight - totalPaginationMargin;
|
|
74
93
|
setTableHeight(0);
|
|
75
94
|
} else {
|
|
76
95
|
height = height - 40;
|
|
96
|
+
currentTableHeight = currentTableHeight - 40;
|
|
77
97
|
setTableHeight(currentTableHeight);
|
|
78
98
|
}
|
|
79
99
|
let currentHasScroll = false;
|
|
@@ -97,6 +117,7 @@ var useTableScrollHeight = (prefixCls, tableRef, pageFixedBottom = true, offsetB
|
|
|
97
117
|
return () => observer.disconnect();
|
|
98
118
|
}, [tableRef, pageFixedBottom, prefixCls]);
|
|
99
119
|
(0, import_ahooks.useEventListener)("resize", calcHeight);
|
|
120
|
+
(0, import_ahooks.useEventListener)("scroll", calcHeight, { target: window });
|
|
100
121
|
return {
|
|
101
122
|
scrollY,
|
|
102
123
|
tableHeight,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/creek-table/hooks/useTableScrollHeight.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useDebounceFn, useEventListener } from 'ahooks';\nimport { useEffect, useState } from 'react';\n\nexport const useTableScrollHeight = (prefixCls: string, tableRef: React.RefObject<HTMLDivElement>, pageFixedBottom: boolean = true, offsetBottom: number = 0) => {\n const [scrollY, setScrollY] = useState<number | undefined>(undefined);\n const [tableHeight, setTableHeight] = useState<number | undefined>(undefined);\n const [tableContainerHeight, setTableContainerHeight] = useState<number | undefined>(0);\n const [hasScroll, setHasScroll] = useState<boolean>(false);\n\n const { run: calcHeight } = useDebounceFn(\n () => {\n if (!pageFixedBottom || !tableRef.current) return;\n\n const tableEl = tableRef.current;\n\n // 如果元素不可见(例如在 display: none 的 tab 中),不进行计算,防止计算出错误的高度\n if (tableEl.offsetParent === null) return;\n\n const tableHeader = tableEl.querySelector(`.${prefixCls}-table-thead`);\n const tableBody = tableEl.querySelector(`.${prefixCls}-table-tbody`);\n\n // 尝试动态获取 layout content padding\n // Ant Design Pro Layout 的 content 容器通常有 class 包含 'pro-layout-content'\n // 例如:ant-pro-layout-content, my-prefix-pro-layout-content\n let currentContentPadding = 0; // 默认使用传入的\n\n const layoutContentEl = tableEl.closest(`div[class*=\"pro-layout-content\"]`);\n if (layoutContentEl) {\n const style = window.getComputedStyle(layoutContentEl);\n // 我们主要关心底部的 padding,因为它影响到底部留白\n const paddingBottom = parseFloat(style.paddingBottom);\n if (!isNaN(paddingBottom)) {\n currentContentPadding = paddingBottom;\n }\n }\n\n // 尝试动态获取 layout content padding\n // Ant Design Pro Layout 的 content 容器通常有 class 包含 'pro-layout-content'\n // 例如:ant-pro-layout-content, my-prefix-pro-layout-content\n let currentCardContentPadding = 0; // 默认使用传入的\n\n const cardContentEl = tableEl.querySelector(`.${prefixCls}-pro-card-body`);\n if (cardContentEl) {\n const style = window.getComputedStyle(cardContentEl);\n // 我们主要关心底部的 padding,因为它影响到底部留白\n const paddingBottom = parseFloat(style.paddingBottom);\n if (!isNaN(paddingBottom)) {\n currentCardContentPadding = paddingBottom;\n }\n }\n\n let top = 0;\n if (tableHeader) {\n top = tableHeader.getBoundingClientRect().bottom;\n } else if (tableBody) {\n top = tableBody.getBoundingClientRect().top;\n }\n\n const windowHeight = window.innerHeight;\n\n let height = windowHeight - top - currentContentPadding - currentCardContentPadding - offsetBottom;\n let
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgD;AAChD,mBAAoC;
|
|
4
|
+
"sourcesContent": ["import { useDebounceFn, useEventListener } from 'ahooks';\nimport { useEffect, useState } from 'react';\n\n/**\n * 获取最近的可滚动父容器\n */\nconst getScrollParent = (element: HTMLElement): HTMLElement | Window => {\n let parent: HTMLElement | null = element.parentElement;\n while (parent) {\n const style = window.getComputedStyle(parent);\n const overflowY = style.overflowY;\n if (overflowY === 'auto' || overflowY === 'scroll') {\n return parent;\n }\n parent = parent.parentElement;\n }\n return window;\n};\n\nexport const useTableScrollHeight = (prefixCls: string, tableRef: React.RefObject<HTMLDivElement>, pageFixedBottom: boolean = true, offsetBottom: number = 0) => {\n const [scrollY, setScrollY] = useState<number | undefined>(undefined);\n const [tableHeight, setTableHeight] = useState<number | undefined>(undefined);\n const [tableContainerHeight, setTableContainerHeight] = useState<number | undefined>(0);\n const [hasScroll, setHasScroll] = useState<boolean>(false);\n\n const { run: calcHeight } = useDebounceFn(\n () => {\n if (!pageFixedBottom || !tableRef.current) return;\n\n const tableEl = tableRef.current;\n\n // 如果元素不可见(例如在 display: none 的 tab 中),不进行计算,防止计算出错误的高度\n if (tableEl.offsetParent === null) return;\n\n const tableHeader = tableEl.querySelector(`.${prefixCls}-table-thead`);\n const tableBody = tableEl.querySelector(`.${prefixCls}-table-tbody`);\n\n // 尝试动态获取 layout content padding\n // Ant Design Pro Layout 的 content 容器通常有 class 包含 'pro-layout-content'\n // 例如:ant-pro-layout-content, my-prefix-pro-layout-content\n let currentContentPadding = 0; // 默认使用传入的\n\n const layoutContentEl = tableEl.closest(`div[class*=\"pro-layout-content\"]`);\n if (layoutContentEl) {\n const style = window.getComputedStyle(layoutContentEl);\n // 我们主要关心底部的 padding,因为它影响到底部留白\n const paddingBottom = parseFloat(style.paddingBottom);\n if (!isNaN(paddingBottom)) {\n currentContentPadding = paddingBottom;\n }\n }\n\n // 尝试动态获取 layout content padding\n // Ant Design Pro Layout 的 content 容器通常有 class 包含 'pro-layout-content'\n // 例如:ant-pro-layout-content, my-prefix-pro-layout-content\n let currentCardContentPadding = 0; // 默认使用传入的\n\n const cardContentEl = tableEl.querySelector(`.${prefixCls}-pro-card-body`);\n if (cardContentEl) {\n const style = window.getComputedStyle(cardContentEl);\n // 我们主要关心底部的 padding,因为它影响到底部留白\n const paddingBottom = parseFloat(style.paddingBottom);\n if (!isNaN(paddingBottom)) {\n currentCardContentPadding = paddingBottom;\n }\n }\n\n let top = 0;\n if (tableHeader) {\n top = tableHeader.getBoundingClientRect().bottom;\n } else if (tableBody) {\n top = tableBody.getBoundingClientRect().top;\n }\n\n const windowHeight = window.innerHeight;\n\n let height = windowHeight - top - currentContentPadding - currentCardContentPadding - offsetBottom;\n\n // 计算表格容器高度:相对于滚动父容器的位置,而非视口位置\n // 这样即使表格上方有其他内容,高度计算也不会受页面滚动影响\n const scrollParent = getScrollParent(tableEl);\n let parentTop = 0;\n if (scrollParent instanceof HTMLElement) {\n parentTop = scrollParent.getBoundingClientRect().top;\n }\n const tableTopRelativeToParent = tableEl.getBoundingClientRect().top - parentTop;\n let currentTableHeight = windowHeight - tableTopRelativeToParent - offsetBottom;\n\n const pagination = tableEl.querySelector(`.${prefixCls}-pagination`);\n\n if (pagination) {\n const paginationHeight = pagination.clientHeight;\n\n const styles = window.getComputedStyle(pagination);\n const totalPaginationMargin = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);\n\n height = height - paginationHeight - totalPaginationMargin;\n currentTableHeight = currentTableHeight - paginationHeight - totalPaginationMargin;\n setTableHeight(0);\n } else {\n // 如果没有找到分页,预留一个高度(假设分页高度为 24px + margin 16px = 40px)\n // 这样可以避免初始加载时高度过大,导致出现滚动条,然后分页出现后高度又变小\n height = height - 40;\n currentTableHeight = currentTableHeight - 40;\n\n setTableHeight(currentTableHeight);\n }\n\n let currentHasScroll = false;\n if (tableBody) {\n currentHasScroll = tableBody.scrollHeight > height;\n }\n setHasScroll(currentHasScroll);\n\n // Minimum height to avoid crashes or ugly rendering\n setScrollY(height);\n\n if (tableHeader) {\n setTableContainerHeight(height + tableHeader?.clientHeight);\n }\n },\n { wait: 16,leading: true },\n );\n\n useEffect(() => {\n // Initial calculation\n calcHeight();\n\n // Observer for DOM changes that might affect position\n const observer = new MutationObserver(calcHeight);\n if (tableRef.current) {\n observer.observe(tableRef.current, { childList: true, subtree: true });\n }\n return () => observer.disconnect();\n }, [tableRef, pageFixedBottom, prefixCls]);\n\n useEventListener('resize', calcHeight);\n // 监听滚动事件,确保页面滚动时也能正确计算高度\n useEventListener('scroll', calcHeight, { target: window });\n\n return {\n scrollY,\n tableHeight,\n tableContainerHeight,\n hasScroll,\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgD;AAChD,mBAAoC;AAKpC,IAAM,kBAAkB,CAAC,YAA+C;AACtE,MAAI,SAA6B,QAAQ;AACzC,SAAO,QAAQ;AACb,UAAM,QAAQ,OAAO,iBAAiB,MAAM;AAC5C,UAAM,YAAY,MAAM;AACxB,QAAI,cAAc,UAAU,cAAc,UAAU;AAClD,aAAO;AAAA,IACT;AACA,aAAS,OAAO;AAAA,EAClB;AACA,SAAO;AACT;AAEO,IAAM,uBAAuB,CA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
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useMemoizedFn } from 'ahooks';
|
|
2
2
|
import { Dropdown, MenuProps, Tabs } from 'antd';
|
|
3
|
-
import { isRegExp, isString
|
|
4
|
-
import React, { useEffect,
|
|
5
|
-
import { useLocation, useNavigate
|
|
3
|
+
import { isRegExp, isString } from 'lodash';
|
|
4
|
+
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import { matchRoutes, useLocation, useNavigate } from 'react-router-dom';
|
|
6
6
|
|
|
7
7
|
import { useT } from '@creekjs/i18n/react';
|
|
8
8
|
|
|
@@ -23,6 +23,10 @@ export interface CreekKeepAliveProps {
|
|
|
23
23
|
* 最大缓存数量,默认为 20
|
|
24
24
|
*/
|
|
25
25
|
maxTabCount?: number;
|
|
26
|
+
/**
|
|
27
|
+
* 路由配置(含 element),用于解析每个路径对应的页面组件
|
|
28
|
+
*/
|
|
29
|
+
routes?: any[];
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
interface TabItem {
|
|
@@ -32,20 +36,28 @@ interface TabItem {
|
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
export const CreekKeepAlive: React.FC<CreekKeepAliveProps> = (props) => {
|
|
35
|
-
const { exclude = [], getTabTitle, tabBarStyle, maxTabCount = 20 } = props;
|
|
39
|
+
const { exclude = [], getTabTitle, tabBarStyle, maxTabCount = 20, routes = [] } = props;
|
|
36
40
|
|
|
37
41
|
const t = useT();
|
|
38
|
-
const outlet = useOutlet();
|
|
39
42
|
const location = useLocation();
|
|
40
43
|
const navigate = useNavigate();
|
|
41
44
|
|
|
42
45
|
const [tabItems, setTabItems] = useState<TabItem[]>([]);
|
|
43
46
|
const [activeKey, setActiveKey] = useState<string>('');
|
|
44
|
-
const [cachedPages, setCachedPages] = useState<Record<string, React.ReactNode>>({});
|
|
45
47
|
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
// 缓存每个路径对应的 React element,保证同一页面始终复用同一个 element 引用
|
|
49
|
+
// 这样 React reconciler 不会卸载/重新挂载组件,从而实现 keep-alive
|
|
50
|
+
// 使用 state 以便缓存变化时触发重新渲染
|
|
51
|
+
const [cachedElements, setCachedElements] = useState<Record<string, React.ReactNode>>({});
|
|
52
|
+
|
|
53
|
+
// 根据路由配置,解析指定路径对应的叶子路由 element
|
|
54
|
+
const resolveElement = (path: string): React.ReactNode | null => {
|
|
55
|
+
if (!routes?.length) return null;
|
|
56
|
+
const matches = matchRoutes(routes, path);
|
|
57
|
+
if (!matches?.length) return null;
|
|
58
|
+
// 取最后一个 match(叶子路由),即实际页面组件
|
|
59
|
+
return matches[matches.length - 1].route.element ?? null;
|
|
60
|
+
};
|
|
49
61
|
|
|
50
62
|
// 判断是否不需要缓存
|
|
51
63
|
const isPathExcluded = (path: string) => {
|
|
@@ -63,75 +75,67 @@ export const CreekKeepAlive: React.FC<CreekKeepAliveProps> = (props) => {
|
|
|
63
75
|
// 初始化或路由变化时更新
|
|
64
76
|
useEffect(() => {
|
|
65
77
|
const currentPath = location.pathname;
|
|
66
|
-
setActiveKey(currentPath);
|
|
67
78
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
// 不需要缓存的路径,不创建 tab
|
|
80
|
+
if (isPathExcluded(currentPath)) return;
|
|
81
|
+
|
|
82
|
+
// 如果路由配置中没有对应的 element(如纯 redirect 路由),不创建 tab
|
|
83
|
+
const element = resolveElement(currentPath);
|
|
84
|
+
if (!element) return;
|
|
85
|
+
|
|
86
|
+
// 缓存当前路径的 element(仅首次缓存,后续复用同一个 element 引用)
|
|
87
|
+
if (!cachedElements[currentPath]) {
|
|
88
|
+
setCachedElements((prev) => ({ ...prev, [currentPath]: element }));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setActiveKey(currentPath);
|
|
78
92
|
|
|
79
93
|
// 更新 Tab 列表
|
|
80
94
|
setTabItems((prev) => {
|
|
81
95
|
if (prev.find((i) => i.key === currentPath)) {
|
|
82
96
|
// 更新现有 tab 的 closable 状态(只有最后一个 tab 时不可关闭)
|
|
83
|
-
|
|
84
|
-
return updated;
|
|
97
|
+
return prev.map((i) => ({ ...i, closable: prev.length > 1 }));
|
|
85
98
|
}
|
|
86
99
|
const title = getTabTitle?.(currentPath) || currentPath;
|
|
87
100
|
const newItems = [...prev, { key: currentPath, label: title, closable: prev.length > 0 }];
|
|
88
101
|
|
|
89
|
-
//
|
|
102
|
+
// 只有1个 tab 时不可关闭
|
|
90
103
|
if (newItems.length === 1) {
|
|
91
104
|
newItems[0].closable = false;
|
|
92
105
|
}
|
|
93
106
|
|
|
94
|
-
//
|
|
107
|
+
// 超过最大数量限制,移除最早的可关闭 tab
|
|
95
108
|
if (newItems.length > maxTabCount) {
|
|
96
|
-
// 找到第一个可以关闭的 Tab(非首页、非当前页)
|
|
97
|
-
// 这里策略是移除最早加入的那个可关闭 Tab。prev[0] 是最早的。
|
|
98
|
-
// 但要注意不要移除当前页(currentPath),虽然 currentPath 是刚加进去的,但在极端情况下(比如 max=1)
|
|
99
|
-
// 简单策略:移除第一个 closable 且 key !== currentPath 的 item
|
|
100
109
|
const indexToRemove = newItems.findIndex((item) => item.closable && item.key !== currentPath);
|
|
101
110
|
if (indexToRemove !== -1) {
|
|
102
111
|
const itemToRemove = newItems[indexToRemove];
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
setCachedElements((prev) => {
|
|
113
|
+
const next = { ...prev };
|
|
114
|
+
delete next[itemToRemove.key];
|
|
115
|
+
return next;
|
|
116
|
+
});
|
|
105
117
|
newItems.splice(indexToRemove, 1);
|
|
106
118
|
}
|
|
107
119
|
}
|
|
108
120
|
return newItems;
|
|
109
121
|
});
|
|
110
|
-
}, [location.pathname, getTabTitle, maxTabCount]);
|
|
111
|
-
|
|
112
|
-
// 清理不需要缓存的页面
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
// 监听路由离开
|
|
115
|
-
// 这里比较 tricky,因为 useEffect 拿到的 activeKey 已经是新的了
|
|
116
|
-
// 我们需要知道"上一个"路径
|
|
117
|
-
// 简化处理:每次 render 时,检查 pages 里哪些是不需要缓存且不处于 active 状态的,将其移除?
|
|
118
|
-
// 但如果在 setState 里做会导致死循环。
|
|
119
|
-
// 另一种策略:不缓存 = 离开时销毁。
|
|
120
|
-
// 我们可以在 pages 渲染时控制。
|
|
121
|
-
}, []);
|
|
122
|
+
}, [location.pathname, getTabTitle, maxTabCount, cachedElements]);
|
|
122
123
|
|
|
123
124
|
const closeTab = useMemoizedFn((targetKey: string) => {
|
|
124
125
|
const targetIndex = tabItems.findIndex((item) => item.key === targetKey);
|
|
125
126
|
const newTabItems = tabItems.filter((item) => item.key !== targetKey);
|
|
126
127
|
|
|
127
|
-
//
|
|
128
|
-
|
|
128
|
+
// 移除缓存,组件将卸载
|
|
129
|
+
setCachedElements((prev) => {
|
|
130
|
+
const next = { ...prev };
|
|
131
|
+
delete next[targetKey];
|
|
132
|
+
return next;
|
|
133
|
+
});
|
|
129
134
|
setTabItems(newTabItems);
|
|
130
135
|
|
|
131
136
|
// 如果关闭的是当前页,跳转到临近页
|
|
132
137
|
if (targetKey === activeKey) {
|
|
133
138
|
if (newTabItems.length > 0) {
|
|
134
|
-
// 尝试跳到右边,没有则左边
|
|
135
139
|
const nextIndex = targetIndex >= newTabItems.length ? newTabItems.length - 1 : targetIndex;
|
|
136
140
|
const nextKey = newTabItems[nextIndex].key;
|
|
137
141
|
navigate(nextKey);
|
|
@@ -145,13 +149,14 @@ export const CreekKeepAlive: React.FC<CreekKeepAliveProps> = (props) => {
|
|
|
145
149
|
const newTabItems = [{ ...currentTab, closable: false }];
|
|
146
150
|
setTabItems(newTabItems);
|
|
147
151
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
// 仅保留当前 tab 的缓存
|
|
153
|
+
const keepKeys = new Set(newTabItems.map((i) => i.key));
|
|
154
|
+
setCachedElements((prev) => {
|
|
155
|
+
const next: Record<string, React.ReactNode> = {};
|
|
151
156
|
keepKeys.forEach((k) => {
|
|
152
|
-
if (prev[k])
|
|
157
|
+
if (prev[k]) next[k] = prev[k];
|
|
153
158
|
});
|
|
154
|
-
return
|
|
159
|
+
return next;
|
|
155
160
|
});
|
|
156
161
|
|
|
157
162
|
if (activeKey !== currentKey) {
|
|
@@ -162,14 +167,19 @@ export const CreekKeepAlive: React.FC<CreekKeepAliveProps> = (props) => {
|
|
|
162
167
|
const closeRightTabs = useMemoizedFn((currentKey: string) => {
|
|
163
168
|
const currentIndex = tabItems.findIndex((i) => i.key === currentKey);
|
|
164
169
|
const rightItems = tabItems.slice(currentIndex + 1);
|
|
165
|
-
const rightKeys = rightItems.map((i) => i.key);
|
|
170
|
+
const rightKeys = new Set(rightItems.map((i) => i.key));
|
|
166
171
|
|
|
167
|
-
const newTabItems = tabItems.filter((i) => !rightKeys.
|
|
172
|
+
const newTabItems = tabItems.filter((i) => !rightKeys.has(i.key));
|
|
168
173
|
setTabItems(newTabItems);
|
|
169
174
|
|
|
170
|
-
|
|
175
|
+
// 移除右侧 tab 的缓存
|
|
176
|
+
setCachedElements((prev) => {
|
|
177
|
+
const next = { ...prev };
|
|
178
|
+
rightKeys.forEach((key) => { delete next[key]; });
|
|
179
|
+
return next;
|
|
180
|
+
});
|
|
171
181
|
|
|
172
|
-
if (rightKeys.
|
|
182
|
+
if (rightKeys.has(activeKey)) {
|
|
173
183
|
navigate(currentKey);
|
|
174
184
|
}
|
|
175
185
|
});
|
|
@@ -225,12 +235,7 @@ export const CreekKeepAlive: React.FC<CreekKeepAliveProps> = (props) => {
|
|
|
225
235
|
label: renderTabLabel(item),
|
|
226
236
|
children: (
|
|
227
237
|
<div key={item.key} style={{ height: '100%', display: activeKey === item.key ? 'block' : 'none' }}>
|
|
228
|
-
{
|
|
229
|
-
{activeKey === item.key
|
|
230
|
-
? outlet
|
|
231
|
-
: !isPathExcluded(item.key)
|
|
232
|
-
? cachedPages[item.key]
|
|
233
|
-
: null}
|
|
238
|
+
{cachedElements[item.key] ?? null}
|
|
234
239
|
</div>
|
|
235
240
|
),
|
|
236
241
|
}))}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Avatar, Dropdown, DropDownProps, Space } from "antd";
|
|
1
|
+
import { Avatar, Dropdown, DropDownProps, Space, Typography } from "antd";
|
|
2
2
|
import { createStyles } from "antd-style";
|
|
3
3
|
|
|
4
4
|
const useStyles = createStyles(({ token}) => ({
|
|
@@ -34,9 +34,9 @@ export const UserInfo = (props: UserInfoProps) => {
|
|
|
34
34
|
<Dropdown arrow placement="bottom" overlayClassName={styles.userInfoDropdownOverlay} menu={menu}>
|
|
35
35
|
<Space size={4} align="center">
|
|
36
36
|
<Avatar className={styles.avatarContainer} src={avatar}>
|
|
37
|
-
{name}
|
|
37
|
+
{typeof name === 'string' ? name.charAt(0).toUpperCase() : name}
|
|
38
38
|
</Avatar>
|
|
39
|
-
<
|
|
39
|
+
<Typography.Text strong>{name}</Typography.Text>
|
|
40
40
|
</Space>
|
|
41
41
|
</Dropdown>
|
|
42
42
|
);
|
|
@@ -11,12 +11,12 @@ import { IntlContext, useT } from '@creekjs/i18n/react';
|
|
|
11
11
|
import { CreekKeepAlive, CreekKeepAliveProps } from '../creek-keep-alive';
|
|
12
12
|
import { CreekLocaleButton } from '../creek-locale-button';
|
|
13
13
|
import { GlobalScrollbarStyle } from '../creek-style/scrollbar';
|
|
14
|
-
import { FullScreen, LayoutSettings } from './ActionRender';
|
|
14
|
+
import { FullScreen, LayoutSettings, UserInfo, UserInfoProps } from './ActionRender';
|
|
15
15
|
import { CollapsedButton, useCollapsedStore } from './CollapseButton';
|
|
16
16
|
import { Exception } from './Exception';
|
|
17
17
|
import { useLayoutSettingsStore } from './useLayoutSettingsStore';
|
|
18
18
|
|
|
19
|
-
export type
|
|
19
|
+
export type CreekLayoutProps = ProLayoutProps & {
|
|
20
20
|
runtimeConfig: ProLayoutProps;
|
|
21
21
|
userConfig?: ProLayoutProps;
|
|
22
22
|
navigate?: (path?: string | number) => void;
|
|
@@ -31,6 +31,14 @@ export type LayoutProps = ProLayoutProps & {
|
|
|
31
31
|
};
|
|
32
32
|
keepAlive?: boolean | CreekKeepAliveProps;
|
|
33
33
|
extraActions?: React.ReactNode[];
|
|
34
|
+
clientRoutes?: any[];
|
|
35
|
+
iconFontCNs?: string[];
|
|
36
|
+
/**
|
|
37
|
+
* 用户信息区域,支持传入配置对象(名称、头像、下拉菜单)或自定义渲染函数
|
|
38
|
+
* - 传对象:自动使用 UserInfo 组件渲染
|
|
39
|
+
* - 传函数:返回 ReactNode 直接渲染,返回 UserInfoProps 对象则使用 UserInfo 组件渲染
|
|
40
|
+
*/
|
|
41
|
+
renderUser?: UserInfoProps | (() => React.ReactNode | UserInfoProps);
|
|
34
42
|
};
|
|
35
43
|
|
|
36
44
|
const MenuName = ({ name, path }: { name?: string; path?: string }) => {
|
|
@@ -39,7 +47,7 @@ const MenuName = ({ name, path }: { name?: string; path?: string }) => {
|
|
|
39
47
|
return t(key, name);
|
|
40
48
|
};
|
|
41
49
|
|
|
42
|
-
export const CreekLayout = (props:
|
|
50
|
+
export const CreekLayout = (props: CreekLayoutProps) => {
|
|
43
51
|
const {
|
|
44
52
|
route,
|
|
45
53
|
userConfig,
|
|
@@ -53,6 +61,9 @@ export const CreekLayout = (props: LayoutProps) => {
|
|
|
53
61
|
showThemeColor = true,
|
|
54
62
|
keepAlive = false,
|
|
55
63
|
extraActions = [],
|
|
64
|
+
clientRoutes,
|
|
65
|
+
iconFontCNs,
|
|
66
|
+
renderUser,
|
|
56
67
|
...more
|
|
57
68
|
} = props;
|
|
58
69
|
|
|
@@ -122,6 +133,14 @@ export const CreekLayout = (props: LayoutProps) => {
|
|
|
122
133
|
|
|
123
134
|
const actions: React.ReactNode[] = [...extraActions];
|
|
124
135
|
|
|
136
|
+
if (renderUser) {
|
|
137
|
+
let result = typeof renderUser === 'function' ? renderUser() : renderUser;
|
|
138
|
+
const isUserInfoProps = (val: unknown): val is UserInfoProps =>
|
|
139
|
+
val !== null && typeof val === 'object' && ('name' in val || 'avatar' in val || 'menu' in val);
|
|
140
|
+
const userInfoNode = isUserInfoProps(result) ? <UserInfo {...result} /> : result;
|
|
141
|
+
actions.push(<span key="user-info">{userInfoNode}</span>);
|
|
142
|
+
}
|
|
143
|
+
|
|
125
144
|
if (actualShowFullScreen) {
|
|
126
145
|
actions.push(<FullScreen key="full-screen" />);
|
|
127
146
|
}
|
|
@@ -176,7 +195,7 @@ export const CreekLayout = (props: LayoutProps) => {
|
|
|
176
195
|
{...more}
|
|
177
196
|
>
|
|
178
197
|
<GlobalScrollbarStyle />
|
|
179
|
-
<Exception>{actualKeepAlive ? <CreekKeepAlive getTabTitle={getTabTitle} {...keepAliveProps} /> : children}</Exception>
|
|
198
|
+
<Exception>{actualKeepAlive ? <CreekKeepAlive getTabTitle={getTabTitle} routes={clientRoutes ?? route?.routes} {...keepAliveProps} /> : children}</Exception>
|
|
180
199
|
</ProLayout>
|
|
181
200
|
);
|
|
182
201
|
|
|
@@ -184,3 +203,4 @@ export const CreekLayout = (props: LayoutProps) => {
|
|
|
184
203
|
};
|
|
185
204
|
|
|
186
205
|
export * from './Exception';
|
|
206
|
+
export { UserInfo, type UserInfoProps } from './ActionRender';
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { useDebounceFn, useEventListener } from 'ahooks';
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 获取最近的可滚动父容器
|
|
6
|
+
*/
|
|
7
|
+
const getScrollParent = (element: HTMLElement): HTMLElement | Window => {
|
|
8
|
+
let parent: HTMLElement | null = element.parentElement;
|
|
9
|
+
while (parent) {
|
|
10
|
+
const style = window.getComputedStyle(parent);
|
|
11
|
+
const overflowY = style.overflowY;
|
|
12
|
+
if (overflowY === 'auto' || overflowY === 'scroll') {
|
|
13
|
+
return parent;
|
|
14
|
+
}
|
|
15
|
+
parent = parent.parentElement;
|
|
16
|
+
}
|
|
17
|
+
return window;
|
|
18
|
+
};
|
|
19
|
+
|
|
4
20
|
export const useTableScrollHeight = (prefixCls: string, tableRef: React.RefObject<HTMLDivElement>, pageFixedBottom: boolean = true, offsetBottom: number = 0) => {
|
|
5
21
|
const [scrollY, setScrollY] = useState<number | undefined>(undefined);
|
|
6
22
|
const [tableHeight, setTableHeight] = useState<number | undefined>(undefined);
|
|
@@ -59,7 +75,16 @@ export const useTableScrollHeight = (prefixCls: string, tableRef: React.RefObjec
|
|
|
59
75
|
const windowHeight = window.innerHeight;
|
|
60
76
|
|
|
61
77
|
let height = windowHeight - top - currentContentPadding - currentCardContentPadding - offsetBottom;
|
|
62
|
-
|
|
78
|
+
|
|
79
|
+
// 计算表格容器高度:相对于滚动父容器的位置,而非视口位置
|
|
80
|
+
// 这样即使表格上方有其他内容,高度计算也不会受页面滚动影响
|
|
81
|
+
const scrollParent = getScrollParent(tableEl);
|
|
82
|
+
let parentTop = 0;
|
|
83
|
+
if (scrollParent instanceof HTMLElement) {
|
|
84
|
+
parentTop = scrollParent.getBoundingClientRect().top;
|
|
85
|
+
}
|
|
86
|
+
const tableTopRelativeToParent = tableEl.getBoundingClientRect().top - parentTop;
|
|
87
|
+
let currentTableHeight = windowHeight - tableTopRelativeToParent - offsetBottom;
|
|
63
88
|
|
|
64
89
|
const pagination = tableEl.querySelector(`.${prefixCls}-pagination`);
|
|
65
90
|
|
|
@@ -70,11 +95,13 @@ export const useTableScrollHeight = (prefixCls: string, tableRef: React.RefObjec
|
|
|
70
95
|
const totalPaginationMargin = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);
|
|
71
96
|
|
|
72
97
|
height = height - paginationHeight - totalPaginationMargin;
|
|
98
|
+
currentTableHeight = currentTableHeight - paginationHeight - totalPaginationMargin;
|
|
73
99
|
setTableHeight(0);
|
|
74
100
|
} else {
|
|
75
101
|
// 如果没有找到分页,预留一个高度(假设分页高度为 24px + margin 16px = 40px)
|
|
76
102
|
// 这样可以避免初始加载时高度过大,导致出现滚动条,然后分页出现后高度又变小
|
|
77
103
|
height = height - 40;
|
|
104
|
+
currentTableHeight = currentTableHeight - 40;
|
|
78
105
|
|
|
79
106
|
setTableHeight(currentTableHeight);
|
|
80
107
|
}
|
|
@@ -108,6 +135,8 @@ export const useTableScrollHeight = (prefixCls: string, tableRef: React.RefObjec
|
|
|
108
135
|
}, [tableRef, pageFixedBottom, prefixCls]);
|
|
109
136
|
|
|
110
137
|
useEventListener('resize', calcHeight);
|
|
138
|
+
// 监听滚动事件,确保页面滚动时也能正确计算高度
|
|
139
|
+
useEventListener('scroll', calcHeight, { target: window });
|
|
111
140
|
|
|
112
141
|
return {
|
|
113
142
|
scrollY,
|