@zat-design/sisyphus-react 3.13.23 → 3.14.0-beta.1
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/es/ProLayout/components/Layout/Menu/FoldMenu/index.js +8 -4
- package/es/ProLayout/components/Layout/Menu/OpenMenu/index.js +39 -28
- package/es/ProLayout/components/TabsManager/components/TabContextMenu.d.ts +7 -0
- package/es/ProLayout/components/TabsManager/components/TabContextMenu.js +96 -0
- package/es/ProLayout/components/TabsManager/components/TabItem.d.ts +26 -0
- package/es/ProLayout/components/TabsManager/components/TabItem.js +61 -0
- package/es/ProLayout/components/TabsManager/components/TabsContext.d.ts +6 -0
- package/es/ProLayout/components/TabsManager/components/TabsContext.js +5 -0
- package/es/ProLayout/components/TabsManager/hooks/useActiveTab.d.ts +6 -0
- package/es/ProLayout/components/TabsManager/hooks/useActiveTab.js +14 -0
- package/es/ProLayout/components/TabsManager/hooks/useProLayoutTabs.d.ts +18 -0
- package/es/ProLayout/components/TabsManager/hooks/useProLayoutTabs.js +26 -0
- package/es/ProLayout/components/TabsManager/hooks/useTabsCache.d.ts +31 -0
- package/es/ProLayout/components/TabsManager/hooks/useTabsCache.js +93 -0
- package/es/ProLayout/components/TabsManager/hooks/useTabsState.d.ts +5 -0
- package/es/ProLayout/components/TabsManager/hooks/useTabsState.js +357 -0
- package/es/ProLayout/components/TabsManager/index.d.ts +8 -0
- package/es/ProLayout/components/TabsManager/index.js +171 -0
- package/es/ProLayout/components/TabsManager/propTypes.d.ts +74 -0
- package/es/ProLayout/components/TabsManager/propTypes.js +16 -0
- package/es/ProLayout/components/TabsManager/style/index.less +179 -0
- package/es/ProLayout/components/TabsManager/utils/index.d.ts +38 -0
- package/es/ProLayout/components/TabsManager/utils/index.js +106 -0
- package/es/ProLayout/index.d.ts +10 -4
- package/es/ProLayout/index.js +82 -9
- package/es/ProLayout/propTypes.d.ts +139 -1
- package/es/ProLayout/propTypes.js +37 -1
- package/es/ProUpload/components/DragRender.d.ts +1 -0
- package/es/ProUpload/components/DragRender.js +5 -1
- package/es/ProUpload/index.js +4 -2
- package/es/ProUpload/propsType.d.ts +5 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +1 -1
- package/lib/ProLayout/components/Layout/Menu/FoldMenu/index.js +8 -4
- package/lib/ProLayout/components/Layout/Menu/OpenMenu/index.js +39 -28
- package/lib/ProLayout/components/TabsManager/components/TabContextMenu.d.ts +7 -0
- package/lib/ProLayout/components/TabsManager/components/TabContextMenu.js +103 -0
- package/lib/ProLayout/components/TabsManager/components/TabItem.d.ts +26 -0
- package/lib/ProLayout/components/TabsManager/components/TabItem.js +67 -0
- package/lib/ProLayout/components/TabsManager/components/TabsContext.d.ts +6 -0
- package/lib/ProLayout/components/TabsManager/components/TabsContext.js +11 -0
- package/lib/ProLayout/components/TabsManager/hooks/useActiveTab.d.ts +6 -0
- package/lib/ProLayout/components/TabsManager/hooks/useActiveTab.js +20 -0
- package/lib/ProLayout/components/TabsManager/hooks/useProLayoutTabs.d.ts +18 -0
- package/lib/ProLayout/components/TabsManager/hooks/useProLayoutTabs.js +31 -0
- package/lib/ProLayout/components/TabsManager/hooks/useTabsCache.d.ts +31 -0
- package/lib/ProLayout/components/TabsManager/hooks/useTabsCache.js +101 -0
- package/lib/ProLayout/components/TabsManager/hooks/useTabsState.d.ts +5 -0
- package/lib/ProLayout/components/TabsManager/hooks/useTabsState.js +364 -0
- package/lib/ProLayout/components/TabsManager/index.d.ts +8 -0
- package/lib/ProLayout/components/TabsManager/index.js +175 -0
- package/lib/ProLayout/components/TabsManager/propTypes.d.ts +74 -0
- package/lib/ProLayout/components/TabsManager/propTypes.js +22 -0
- package/lib/ProLayout/components/TabsManager/style/index.less +179 -0
- package/lib/ProLayout/components/TabsManager/utils/index.d.ts +38 -0
- package/lib/ProLayout/components/TabsManager/utils/index.js +119 -0
- package/lib/ProLayout/index.d.ts +10 -4
- package/lib/ProLayout/index.js +94 -8
- package/lib/ProLayout/propTypes.d.ts +139 -1
- package/lib/ProLayout/propTypes.js +40 -1
- package/lib/ProUpload/components/DragRender.d.ts +1 -0
- package/lib/ProUpload/components/DragRender.js +5 -1
- package/lib/ProUpload/index.js +4 -2
- package/lib/ProUpload/propsType.d.ts +5 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +9 -2
- package/package.json +1 -1
|
@@ -28,9 +28,12 @@ var FoldMenu = props => {
|
|
|
28
28
|
'pro-layout-menu-tooltip-has-notice': notice,
|
|
29
29
|
'pro-layout-menu-tooltip-nav-open': collapsed
|
|
30
30
|
});
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
var _ref = useContext(LayoutContext) || {
|
|
32
|
+
selectedPath: '',
|
|
33
|
+
onSelected: () => {}
|
|
34
|
+
},
|
|
35
|
+
selectedPath = _ref.selectedPath,
|
|
36
|
+
onSelected = _ref.onSelected;
|
|
34
37
|
return /*#__PURE__*/_jsx("div", {
|
|
35
38
|
className: "pro-layout-menu-fold",
|
|
36
39
|
style: _objectSpread({}, style),
|
|
@@ -54,11 +57,12 @@ var FoldMenu = props => {
|
|
|
54
57
|
return null;
|
|
55
58
|
}
|
|
56
59
|
var selectedMenu = getUrlParams('activeMenu');
|
|
60
|
+
var pathToMatch = selectedPath || selectedMenu || window.location.pathname;
|
|
57
61
|
|
|
58
62
|
// 取第一级
|
|
59
63
|
var currentKeyIdPath = getPathNameKey({
|
|
60
64
|
menus,
|
|
61
|
-
pathName:
|
|
65
|
+
pathName: pathToMatch // 优先匹配上下文路径
|
|
62
66
|
}) || [];
|
|
63
67
|
var cls = classnames({
|
|
64
68
|
active: currentKeyIdPath.includes(id)
|
|
@@ -9,6 +9,7 @@ import { Link as RouterLink } from 'react-router-dom';
|
|
|
9
9
|
import { cloneDeep } from 'lodash';
|
|
10
10
|
import { LayoutContext } from "../../../../index";
|
|
11
11
|
import { getIdsByPathName, findMenuItemByKey } from "../../../../utils";
|
|
12
|
+
import { isLeafMenuItem } from "../../../TabsManager/utils";
|
|
12
13
|
import { Icon } from "../../index";
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
15
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
@@ -39,16 +40,19 @@ var OpenMenu = props => {
|
|
|
39
40
|
router = _useSetState2$.router,
|
|
40
41
|
setState = _useSetState2[1];
|
|
41
42
|
var query = new URLSearchParams(window.location.search);
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
var layoutContext = useContext(LayoutContext);
|
|
44
|
+
var layoutSelectedPath = layoutContext === null || layoutContext === void 0 ? void 0 : layoutContext.selectedPath;
|
|
45
|
+
var layoutOnSelected = layoutContext === null || layoutContext === void 0 ? void 0 : layoutContext.onSelected;
|
|
46
|
+
var layoutTarget = layoutContext === null || layoutContext === void 0 ? void 0 : layoutContext.target;
|
|
45
47
|
var cls = classnames({
|
|
46
48
|
'pro-layout-open-menu': true,
|
|
47
49
|
[`${className}`]: className
|
|
48
50
|
});
|
|
49
51
|
|
|
50
|
-
// 默认激活菜单优先取activeMenu
|
|
51
|
-
|
|
52
|
+
// 默认激活菜单优先取selectedPath或activeMenu,默认取pathName进行匹配
|
|
53
|
+
// 特殊处理:如果layoutSelectedPath是'##EMPTY##',表示有意清空选中状态
|
|
54
|
+
var preferredPath = query.get('activeMenu') || (layoutSelectedPath === '##EMPTY##' ? null : layoutSelectedPath) || window.location.pathname;
|
|
55
|
+
var selectKeyIdPath = preferredPath ? ((_getIdsByPathName = getIdsByPathName(menus, preferredPath)) === null || _getIdsByPathName === void 0 ? void 0 : _getIdsByPathName.map(item => String(item))) || [] : [];
|
|
52
56
|
var itemsTransform = useMemo(() => {
|
|
53
57
|
var result = cloneDeep(menus);
|
|
54
58
|
if (!Array.isArray(result) || !result.length) {
|
|
@@ -105,11 +109,14 @@ var OpenMenu = props => {
|
|
|
105
109
|
return result;
|
|
106
110
|
}, [dataSource]);
|
|
107
111
|
useDeepCompareEffect(() => {
|
|
108
|
-
if (Array.isArray(selectKeyIdPath)
|
|
109
|
-
|
|
110
|
-
selectedKeys: selectKeyIdPath
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
if (Array.isArray(selectKeyIdPath)) {
|
|
113
|
+
var newState = {
|
|
114
|
+
selectedKeys: selectKeyIdPath
|
|
115
|
+
};
|
|
116
|
+
if (selectKeyIdPath.length) {
|
|
117
|
+
newState.openKeys = selectKeyIdPath.slice(0, 2);
|
|
118
|
+
}
|
|
119
|
+
setState(newState);
|
|
113
120
|
}
|
|
114
121
|
}, [menus, selectKeyIdPath]);
|
|
115
122
|
|
|
@@ -141,7 +148,6 @@ var OpenMenu = props => {
|
|
|
141
148
|
});
|
|
142
149
|
},
|
|
143
150
|
onClick: _ref2 => {
|
|
144
|
-
var _item$props, _item$props2;
|
|
145
151
|
var item = _ref2.item,
|
|
146
152
|
keyPath = _ref2.keyPath,
|
|
147
153
|
key = _ref2.key,
|
|
@@ -163,23 +169,28 @@ var OpenMenu = props => {
|
|
|
163
169
|
keyPath: menuKeyPath
|
|
164
170
|
});
|
|
165
171
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
172
|
+
|
|
173
|
+
// 只有最后一级菜单(叶子节点)才设置选中状态和路径
|
|
174
|
+
if (menuItem && isLeafMenuItem(menuItem)) {
|
|
175
|
+
var _item$props, _item$props2;
|
|
176
|
+
setState({
|
|
177
|
+
selectedKeys: keyPath,
|
|
178
|
+
router: item === null || item === void 0 || (_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.router
|
|
179
|
+
});
|
|
180
|
+
layoutOnSelected === null || layoutOnSelected === void 0 || layoutOnSelected({
|
|
181
|
+
selectedPath: item === null || item === void 0 || (_item$props2 = item.props) === null || _item$props2 === void 0 ? void 0 : _item$props2.router
|
|
182
|
+
});
|
|
183
|
+
if (layoutTarget) {
|
|
184
|
+
var _item$props3;
|
|
185
|
+
window.open(item === null || item === void 0 || (_item$props3 = item.props) === null || _item$props3 === void 0 ? void 0 : _item$props3.router, layoutTarget);
|
|
186
|
+
} else {
|
|
187
|
+
setTimeout(() => {
|
|
188
|
+
// 路由变更,且不再demo文档中
|
|
189
|
+
if (!window.location.href.includes('~demos/prolayout')) {
|
|
190
|
+
linkRef.current.click();
|
|
191
|
+
}
|
|
192
|
+
}, 100);
|
|
193
|
+
}
|
|
183
194
|
}
|
|
184
195
|
},
|
|
185
196
|
style: {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TabContextMenuProps } from '../propTypes';
|
|
2
|
+
/**
|
|
3
|
+
* 右键菜单组件 - 兼容Antd 4.x和5.x
|
|
4
|
+
*/
|
|
5
|
+
declare function TabContextMenu({ tabId, children, closable, onClose, onCloseOthers, onCloseRight, onCloseAll, menuItems: customMenuItems, tabMenuClick, tab, tabs, }: TabContextMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export default TabContextMenu;
|
|
7
|
+
export { TabContextMenu };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import "antd/es/dropdown/style";
|
|
2
|
+
import _Dropdown from "antd/es/dropdown";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import { useState, useCallback } from 'react';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* 右键菜单组件 - 兼容Antd 4.x和5.x
|
|
8
|
+
*/
|
|
9
|
+
function TabContextMenu(_ref) {
|
|
10
|
+
var tabId = _ref.tabId,
|
|
11
|
+
children = _ref.children,
|
|
12
|
+
_ref$closable = _ref.closable,
|
|
13
|
+
closable = _ref$closable === void 0 ? true : _ref$closable,
|
|
14
|
+
onClose = _ref.onClose,
|
|
15
|
+
onCloseOthers = _ref.onCloseOthers,
|
|
16
|
+
onCloseRight = _ref.onCloseRight,
|
|
17
|
+
onCloseAll = _ref.onCloseAll,
|
|
18
|
+
customMenuItems = _ref.menuItems,
|
|
19
|
+
tabMenuClick = _ref.tabMenuClick,
|
|
20
|
+
tab = _ref.tab,
|
|
21
|
+
_ref$tabs = _ref.tabs,
|
|
22
|
+
tabs = _ref$tabs === void 0 ? [] : _ref$tabs;
|
|
23
|
+
var _useState = useState(false),
|
|
24
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
25
|
+
visible = _useState2[0],
|
|
26
|
+
setVisible = _useState2[1];
|
|
27
|
+
var handleMenuClick = useCallback(key => {
|
|
28
|
+
setVisible(false);
|
|
29
|
+
|
|
30
|
+
// 优先调用自定义回调
|
|
31
|
+
if (tabMenuClick && tab) {
|
|
32
|
+
tabMenuClick({
|
|
33
|
+
key,
|
|
34
|
+
tab,
|
|
35
|
+
tabs
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 处理默认菜单项
|
|
40
|
+
switch (key) {
|
|
41
|
+
case 'close':
|
|
42
|
+
if (!closable) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
onClose(tabId);
|
|
46
|
+
break;
|
|
47
|
+
case 'closeOthers':
|
|
48
|
+
onCloseOthers(tabId);
|
|
49
|
+
break;
|
|
50
|
+
case 'closeRight':
|
|
51
|
+
onCloseRight(tabId);
|
|
52
|
+
break;
|
|
53
|
+
case 'closeAll':
|
|
54
|
+
onCloseAll();
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}, [tabId, closable, onClose, onCloseOthers, onCloseRight, onCloseAll, tabMenuClick, tab, tabs]);
|
|
58
|
+
|
|
59
|
+
// 默认右键菜单配置 - 统一使用items方式(antd 4.20+都支持)
|
|
60
|
+
var defaultMenuItems = [{
|
|
61
|
+
key: 'close',
|
|
62
|
+
label: '关闭',
|
|
63
|
+
disabled: !closable
|
|
64
|
+
}, {
|
|
65
|
+
key: 'closeOthers',
|
|
66
|
+
label: '关闭其他'
|
|
67
|
+
}, {
|
|
68
|
+
key: 'closeRight',
|
|
69
|
+
label: '关闭右侧标签页'
|
|
70
|
+
}, {
|
|
71
|
+
key: 'closeAll',
|
|
72
|
+
label: '关闭全部'
|
|
73
|
+
}];
|
|
74
|
+
|
|
75
|
+
// 合并自定义菜单项和默认菜单项
|
|
76
|
+
// 如果提供了自定义菜单项,则追加到默认菜单项后面;否则使用默认菜单项
|
|
77
|
+
var menuItems = customMenuItems && customMenuItems.length > 0 ? [...defaultMenuItems, {
|
|
78
|
+
type: 'divider'
|
|
79
|
+
}, ...customMenuItems] : defaultMenuItems;
|
|
80
|
+
return /*#__PURE__*/_jsx(_Dropdown, {
|
|
81
|
+
menu: {
|
|
82
|
+
items: menuItems,
|
|
83
|
+
onClick: _ref2 => {
|
|
84
|
+
var key = _ref2.key;
|
|
85
|
+
return handleMenuClick(key);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
trigger: ['contextMenu'],
|
|
89
|
+
open: visible,
|
|
90
|
+
onOpenChange: setVisible,
|
|
91
|
+
placement: "bottomLeft",
|
|
92
|
+
children: children
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export default TabContextMenu;
|
|
96
|
+
export { TabContextMenu };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TabItem } from '../../../propTypes';
|
|
3
|
+
interface TabItemComponentProps {
|
|
4
|
+
tab: TabItem;
|
|
5
|
+
active: boolean;
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
onCloseOthers: () => void;
|
|
9
|
+
onCloseRight: () => void;
|
|
10
|
+
onCloseAll: () => void;
|
|
11
|
+
/** 所有标签页列表 */
|
|
12
|
+
tabsList?: TabItem[];
|
|
13
|
+
/** 自定义菜单项 */
|
|
14
|
+
menuItems?: import('antd').MenuProps['items'];
|
|
15
|
+
/** 自定义菜单项点击回调 */
|
|
16
|
+
tabMenuClick?: (params: {
|
|
17
|
+
key: string;
|
|
18
|
+
tab: TabItem;
|
|
19
|
+
tabs: TabItem[];
|
|
20
|
+
}) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 单个标签页组件
|
|
24
|
+
*/
|
|
25
|
+
declare const TabItemComponent: React.FC<TabItemComponentProps>;
|
|
26
|
+
export { TabItemComponent };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CloseOutlined } from '@ant-design/icons';
|
|
3
|
+
import { TabContextMenu } from "./TabContextMenu";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* 单个标签页组件
|
|
8
|
+
*/
|
|
9
|
+
var TabItemComponent = _ref => {
|
|
10
|
+
var tab = _ref.tab,
|
|
11
|
+
active = _ref.active,
|
|
12
|
+
onClick = _ref.onClick,
|
|
13
|
+
_onClose = _ref.onClose,
|
|
14
|
+
_onCloseOthers = _ref.onCloseOthers,
|
|
15
|
+
_onCloseRight = _ref.onCloseRight,
|
|
16
|
+
onCloseAll = _ref.onCloseAll,
|
|
17
|
+
_ref$tabsList = _ref.tabsList,
|
|
18
|
+
tabsList = _ref$tabsList === void 0 ? [] : _ref$tabsList,
|
|
19
|
+
menuItems = _ref.menuItems,
|
|
20
|
+
tabMenuClick = _ref.tabMenuClick;
|
|
21
|
+
var handleCloseClick = e => {
|
|
22
|
+
e.stopPropagation();
|
|
23
|
+
_onClose();
|
|
24
|
+
};
|
|
25
|
+
return /*#__PURE__*/_jsx(TabContextMenu, {
|
|
26
|
+
tabId: tab.id,
|
|
27
|
+
closable: tab.closable,
|
|
28
|
+
onClose: () => _onClose(),
|
|
29
|
+
onCloseOthers: () => _onCloseOthers(),
|
|
30
|
+
onCloseRight: () => _onCloseRight(),
|
|
31
|
+
onCloseAll: onCloseAll,
|
|
32
|
+
tab: tab,
|
|
33
|
+
tabs: tabsList,
|
|
34
|
+
menuItems: menuItems,
|
|
35
|
+
tabMenuClick: tabMenuClick,
|
|
36
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
37
|
+
className: `pro-layout-tab-item ${active ? 'active' : ''} ${tab.closable ? 'closable' : ''}`,
|
|
38
|
+
onClick: onClick,
|
|
39
|
+
"data-testid": `tab-${tab.id}`,
|
|
40
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
41
|
+
className: "pro-layout-tab-content",
|
|
42
|
+
children: [tab.icon && /*#__PURE__*/_jsx("span", {
|
|
43
|
+
className: "pro-layout-tab-icon",
|
|
44
|
+
children: typeof tab.icon === 'string' ? /*#__PURE__*/_jsx("i", {
|
|
45
|
+
className: `iconfont ${tab.icon}`
|
|
46
|
+
}) : tab.icon
|
|
47
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
48
|
+
className: "pro-layout-tab-title",
|
|
49
|
+
title: tab.title,
|
|
50
|
+
children: tab.title
|
|
51
|
+
}), tab.closable && /*#__PURE__*/_jsx("span", {
|
|
52
|
+
className: "pro-layout-tab-close",
|
|
53
|
+
onClick: handleCloseClick,
|
|
54
|
+
"data-testid": `tab-close-${tab.id}`,
|
|
55
|
+
children: /*#__PURE__*/_jsx(CloseOutlined, {})
|
|
56
|
+
})]
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
export { TabItemComponent };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { TabsContext } from "../components/TabsContext";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 获取当前激活的 Tab 信息 Hook
|
|
6
|
+
* @returns 当前激活的 Tab 对象,如果没有激活则返回 undefined
|
|
7
|
+
*/
|
|
8
|
+
export var useActiveTab = () => {
|
|
9
|
+
var tabsInstance = useContext(TabsContext);
|
|
10
|
+
return useMemo(() => {
|
|
11
|
+
if (!tabsInstance) return undefined;
|
|
12
|
+
return tabsInstance.getTabInfo().activeTabInfo;
|
|
13
|
+
}, [tabsInstance]);
|
|
14
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ProLayoutTabsInstance } from '../../../propTypes';
|
|
2
|
+
/**
|
|
3
|
+
* @description 获取 ProLayout 标签页实例的 Hook(类似 Form.useForm)
|
|
4
|
+
* @returns [ProLayoutTabsInstance] 标签页实例
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* // 在 ProLayout children 中使用
|
|
8
|
+
* const [layoutTabs] = useProLayoutTabs();
|
|
9
|
+
*
|
|
10
|
+
* // 使用实例方法
|
|
11
|
+
* layoutTabs.addTab({
|
|
12
|
+
* code: 'PolicyInput',
|
|
13
|
+
* name: '投保单录入',
|
|
14
|
+
* extra: { customData: '自定义数据' }
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function useProLayoutTabs(): [ProLayoutTabsInstance];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { TabsContext } from "../components/TabsContext";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description 获取 ProLayout 标签页实例的 Hook(类似 Form.useForm)
|
|
6
|
+
* @returns [ProLayoutTabsInstance] 标签页实例
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // 在 ProLayout children 中使用
|
|
10
|
+
* const [layoutTabs] = useProLayoutTabs();
|
|
11
|
+
*
|
|
12
|
+
* // 使用实例方法
|
|
13
|
+
* layoutTabs.addTab({
|
|
14
|
+
* code: 'PolicyInput',
|
|
15
|
+
* name: '投保单录入',
|
|
16
|
+
* extra: { customData: '自定义数据' }
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function useProLayoutTabs() {
|
|
21
|
+
var context = useContext(TabsContext);
|
|
22
|
+
if (!context) {
|
|
23
|
+
throw new Error('useProLayoutTabs must be used within ProLayout with mode="tabs"');
|
|
24
|
+
}
|
|
25
|
+
return [context];
|
|
26
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TabsState } from '../../../propTypes';
|
|
2
|
+
import { TabsCacheManager } from '../propTypes';
|
|
3
|
+
/**
|
|
4
|
+
* 简化的标签页缓存管理器
|
|
5
|
+
*/
|
|
6
|
+
declare class SimpleTabsCache implements TabsCacheManager {
|
|
7
|
+
private cacheKey;
|
|
8
|
+
private storage;
|
|
9
|
+
constructor(keyPrefix: string, strategy: 'localStorage' | 'sessionStorage');
|
|
10
|
+
/** 保存标签页状态 */
|
|
11
|
+
save(state: TabsState): void;
|
|
12
|
+
/** 恢复标签页状态 */
|
|
13
|
+
restore(): TabsState | null;
|
|
14
|
+
/** 清空缓存 */
|
|
15
|
+
clear(): void;
|
|
16
|
+
}
|
|
17
|
+
interface UseTabsCacheOptions {
|
|
18
|
+
cacheKey: string;
|
|
19
|
+
storage: 'localStorage' | 'sessionStorage';
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 标签页缓存管理Hook
|
|
24
|
+
*/
|
|
25
|
+
export declare const useTabsCache: (options: UseTabsCacheOptions) => {
|
|
26
|
+
saveToCache: (state: TabsState) => void;
|
|
27
|
+
restoreFromCache: () => TabsState | null;
|
|
28
|
+
clearCache: () => void;
|
|
29
|
+
cacheManager: SimpleTabsCache;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import { useCallback, useMemo } from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* 简化的标签页缓存管理器
|
|
6
|
+
*/
|
|
7
|
+
class SimpleTabsCache {
|
|
8
|
+
constructor(keyPrefix, strategy) {
|
|
9
|
+
_defineProperty(this, "cacheKey", void 0);
|
|
10
|
+
_defineProperty(this, "storage", void 0);
|
|
11
|
+
this.cacheKey = `${keyPrefix}_tabs_cache`;
|
|
12
|
+
this.storage = strategy === 'localStorage' ? localStorage : sessionStorage;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** 保存标签页状态 */
|
|
16
|
+
save(state) {
|
|
17
|
+
try {
|
|
18
|
+
var cacheData = _objectSpread(_objectSpread({}, state), {}, {
|
|
19
|
+
timestamp: Date.now()
|
|
20
|
+
});
|
|
21
|
+
this.storage.setItem(this.cacheKey, JSON.stringify(cacheData));
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.warn('标签页缓存保存失败:', error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 恢复标签页状态 */
|
|
28
|
+
restore() {
|
|
29
|
+
try {
|
|
30
|
+
var cached = this.storage.getItem(this.cacheKey);
|
|
31
|
+
if (!cached) return null;
|
|
32
|
+
var cacheData = JSON.parse(cached);
|
|
33
|
+
// 移除时间戳字段
|
|
34
|
+
delete cacheData.timestamp;
|
|
35
|
+
return cacheData;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.warn('标签页缓存恢复失败:', error);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 清空缓存 */
|
|
43
|
+
clear() {
|
|
44
|
+
try {
|
|
45
|
+
this.storage.removeItem(this.cacheKey);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.warn('标签页缓存清空失败:', error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 标签页缓存管理Hook
|
|
53
|
+
*/
|
|
54
|
+
export var useTabsCache = options => {
|
|
55
|
+
var cacheKey = options.cacheKey,
|
|
56
|
+
storage = options.storage,
|
|
57
|
+
_options$enabled = options.enabled,
|
|
58
|
+
enabled = _options$enabled === void 0 ? true : _options$enabled;
|
|
59
|
+
|
|
60
|
+
// 创建缓存管理器实例
|
|
61
|
+
var cacheManager = useMemo(() => {
|
|
62
|
+
if (!enabled) return null;
|
|
63
|
+
return new SimpleTabsCache(cacheKey, storage);
|
|
64
|
+
}, [cacheKey, storage, enabled]);
|
|
65
|
+
|
|
66
|
+
// 保存状态到缓存
|
|
67
|
+
var saveToCache = useCallback(state => {
|
|
68
|
+
if (cacheManager) {
|
|
69
|
+
cacheManager.save(state);
|
|
70
|
+
}
|
|
71
|
+
}, [cacheManager]);
|
|
72
|
+
|
|
73
|
+
// 从缓存恢复状态
|
|
74
|
+
var restoreFromCache = useCallback(() => {
|
|
75
|
+
if (cacheManager) {
|
|
76
|
+
return cacheManager.restore();
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}, [cacheManager]);
|
|
80
|
+
|
|
81
|
+
// 清空缓存
|
|
82
|
+
var clearCache = useCallback(() => {
|
|
83
|
+
if (cacheManager) {
|
|
84
|
+
cacheManager.clear();
|
|
85
|
+
}
|
|
86
|
+
}, [cacheManager]);
|
|
87
|
+
return {
|
|
88
|
+
saveToCache,
|
|
89
|
+
restoreFromCache,
|
|
90
|
+
clearCache,
|
|
91
|
+
cacheManager
|
|
92
|
+
};
|
|
93
|
+
};
|