192 lines
5.1 KiB
TypeScript
Raw Normal View History

2025-07-31 14:28:57 +08:00
import { PlusOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons';
import { history } from '@umijs/max';
import { Button, Card, Divider, Space } from 'antd';
2025-07-25 16:42:54 +08:00
import { MyPageContainer } from './MyPageContainer';
import { usePageTabs } from './usePageTabs';
/**
* 使
* 使MyPageContainer的多标签页功能
*/
export function TabsExample() {
const tabsApi = usePageTabs({
tabKey: 'tabs-example',
2025-07-31 14:28:57 +08:00
tabLabel: '标签页示例',
2025-07-25 16:42:54 +08:00
});
const handleAddTab = (key: string, label: string, path: string) => {
tabsApi.addTab({
key,
label,
path,
2025-07-31 14:28:57 +08:00
closable: true,
2025-07-25 16:42:54 +08:00
});
history.push(path);
};
const handleAddTabNext = (key: string, label: string, path: string) => {
tabsApi.addTabNext({
key,
label,
path,
closable: true,
});
history.push(path);
};
2025-07-25 16:42:54 +08:00
return (
<MyPageContainer
enableTabs
tabKey="tabs-example"
tabLabel="标签页示例"
title="多标签页功能演示"
>
<Card title="标签页操作示例" style={{ marginBottom: 16 }}>
<Space wrap>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => handleAddTab('user-list', '用户列表', '/users')}
>
</Button>
2025-07-31 14:28:57 +08:00
2025-07-25 16:42:54 +08:00
<Button
icon={<UserOutlined />}
2025-07-31 14:28:57 +08:00
onClick={() =>
handleAddTab('user-profile', '用户详情', '/users/profile')
}
2025-07-25 16:42:54 +08:00
>
</Button>
2025-07-31 14:28:57 +08:00
2025-07-25 16:42:54 +08:00
<Button
icon={<SettingOutlined />}
onClick={() => handleAddTab('settings', '系统设置', '/settings')}
>
</Button>
</Space>
2025-07-31 14:28:57 +08:00
<Divider orientation="left"></Divider>
<Space wrap>
<Button
type="dashed"
icon={<PlusOutlined />}
onClick={() =>
handleAddTabNext('company-1', '机构详情-1', '/company/1')
}
>
-1
</Button>
<Button
type="dashed"
icon={<UserOutlined />}
onClick={() =>
handleAddTabNext('employee-1', '员工详情-1', '/employee/1')
}
>
-1
</Button>
<Button
type="dashed"
icon={<SettingOutlined />}
onClick={() =>
handleAddTabNext('project-1', '项目详情-1', '/project/1')
}
>
-1
</Button>
</Space>
2025-07-25 16:42:54 +08:00
<Divider />
2025-07-31 14:28:57 +08:00
2025-07-25 16:42:54 +08:00
<Space wrap>
2025-07-31 14:28:57 +08:00
<Button onClick={() => tabsApi.closeOtherTabs()}></Button>
<Button onClick={() => tabsApi.closeLeftTabs()}></Button>
<Button onClick={() => tabsApi.closeRightTabs()}></Button>
<Button onClick={() => tabsApi.refreshTab()}></Button>
2025-07-25 16:42:54 +08:00
</Space>
</Card>
2025-07-31 14:28:57 +08:00
2025-07-25 16:42:54 +08:00
<Card title="功能说明">
<div style={{ lineHeight: '1.8' }}>
<h4>🎯 </h4>
<ul>
2025-07-31 14:28:57 +08:00
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
2025-07-31 14:28:57 +08:00
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
2025-07-25 16:42:54 +08:00
</ul>
2025-07-31 14:28:57 +08:00
2025-07-25 16:42:54 +08:00
<h4>🖱 </h4>
<ul>
2025-07-31 14:28:57 +08:00
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
2025-07-25 16:42:54 +08:00
</ul>
2025-07-31 14:28:57 +08:00
2025-07-25 16:42:54 +08:00
<h4>💻 使</h4>
2025-07-31 14:28:57 +08:00
<pre
style={{
background: '#f5f5f5',
padding: '12px',
borderRadius: '4px',
}}
>
{`// 1. 在页面组件中使用
2025-07-25 16:42:54 +08:00
import { MyPageContainer, usePageTabs } from '@/common';
function YourPage() {
usePageTabs({
tabKey: 'your-page',
tabLabel: '页面标题'
});
return (
<MyPageContainer
enableTabs
tabKey="your-page"
tabLabel="页面标题"
>
{/* 页面内容 */}
</MyPageContainer>
);
}`}
</pre>
</div>
</Card>
</MyPageContainer>
);
2025-07-31 14:28:57 +08:00
}