zhouxiantao
8 days ago 03193b2a27a2c23e10f3a2f298de9c1142116780
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * @author 韩天尊
 * @time 2024-01-15
 * @version 1.0.0
 * @description 页面头部组件
 */
import React from 'react';
import { useNavigate } from 'react-router-dom';
 
interface PageHeaderProps {
    title: string;
    showBack?: boolean;
    onBack?: () => void;
}
 
const PageHeader: React.FC<PageHeaderProps> = ({ title, showBack = true, onBack }) => {
    const navigate = useNavigate();
 
    const handleBack = () => {
        if (onBack) {
            onBack();
        } else {
            navigate(-1);
        }
    };
 
    return (
        <div className="page-header">
            {showBack && (
                <button className="back-btn" onClick={handleBack}>
                    <i className="fas fa-arrow-left"></i>
                </button>
            )}
            <h2>{title}</h2>
        </div>
    );
};
 
export default PageHeader;