192 lines
5.1 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { PlusOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons';
import { history } from '@umijs/max';
import { Button, Card, Divider, Space } from 'antd';
import { MyPageContainer } from './MyPageContainer';
import { usePageTabs } from './usePageTabs';
/**
* 标签页使用示例组件
* 展示如何使用MyPageContainer的多标签页功能
*/
export function TabsExample() {
const tabsApi = usePageTabs({
tabKey: 'tabs-example',
tabLabel: '标签页示例',
});
const handleAddTab = (key: string, label: string, path: string) => {
tabsApi.addTab({
key,
label,
path,
closable: true,
});
history.push(path);
};
const handleAddTabNext = (key: string, label: string, path: string) => {
tabsApi.addTabNext({
key,
label,
path,
closable: true,
});
history.push(path);
};
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>
<Button
icon={<UserOutlined />}
onClick={() =>
handleAddTab('user-profile', '用户详情', '/users/profile')
}
>
</Button>
<Button
icon={<SettingOutlined />}
onClick={() => handleAddTab('settings', '系统设置', '/settings')}
>
</Button>
</Space>
<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>
<Divider />
<Space wrap>
<Button onClick={() => tabsApi.closeOtherTabs()}></Button>
<Button onClick={() => tabsApi.closeLeftTabs()}></Button>
<Button onClick={() => tabsApi.closeRightTabs()}></Button>
<Button onClick={() => tabsApi.refreshTab()}></Button>
</Space>
</Card>
<Card title="功能说明">
<div style={{ lineHeight: '1.8' }}>
<h4>🎯 </h4>
<ul>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
</ul>
<h4>🖱 </h4>
<ul>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
<li>
<strong></strong>
</li>
</ul>
<h4>💻 使</h4>
<pre
style={{
background: '#f5f5f5',
padding: '12px',
borderRadius: '4px',
}}
>
{`// 1. 在页面组件中使用
import { MyPageContainer, usePageTabs } from '@/common';
function YourPage() {
usePageTabs({
tabKey: 'your-page',
tabLabel: '页面标题'
});
return (
<MyPageContainer
enableTabs
tabKey="your-page"
tabLabel="页面标题"
>
{/* 页面内容 */}
</MyPageContainer>
);
}`}
</pre>
</div>
</Card>
</MyPageContainer>
);
}