//类组件 import * as React from "react"; import { Component } from "react"; import logo from "../../assets/logo.svg"; import styles from "./Header.module.css"; import { withTranslation, WithTranslation } from "react-i18next"; import { connect } from "react-redux"; import { Dispatch } from "redux"; import { changeLanguageActionCreator, addLanguageActionCreator, } from "../../redux/language/languageActions"; import { Layout, Typography, Input, Menu, Button, Dropdown, MenuItemProps, } from "antd"; import { GlobalOutlined } from "@ant-design/icons"; import { withRouter, RouteComponentProps } from "react-router-dom"; import { RootState } from "../../redux/store"; const mapStateToProps = (state: RootState) => { return { language: state.language, languageList: state.languageList, }; }; const mapDispatchToProps =(dispatch:Dispatch) =>{ return{ changeLanguage:(code:'en'|'zh')=>{ const action =changeLanguageActionCreator(code) dispatch(action) }, addLanguage:(name:string,code:string)=>{ const action = addLanguageActionCreator(name,code) dispatch(action) } } } class HeaderComponent extends React.Component< RouteComponentProps & WithTranslation & ReturnType&ReturnType > { changeLanguage = (e) => { if (e.key === "new") { this.props.addLanguage("新语言", "新语言"); } else { this.props.changeLanguage(e.key); } }; render() { const { t } = this.props; console.log(this.props); const { history } = this.props; return ( <>
{/* top-header */}
{t("header.slogan")} {this.props.languageList.map((item, index) => ( {item.name} ))} {t("header.slogan")} } icon={} > {this.props.language === "zh" ? "中文" : "English"}
logo {t("header.title")} 旅游首页 周末游 跟团游 自由行 私家团 邮轮 酒店+景点 当地玩乐 主题游 定制游 游学 签证 企业游 高端游 爱玩户外 保险
); } } export const Header = connect(mapStateToProps,mapDispatchToProps)( withTranslation()(withRouter(HeaderComponent)) );