Header.tsx 3.83 KB
Newer Older
mayi's avatar
mayi committed
1
//函数式组件
2
import * as React from "react";
3
// import { Component } from "react";
4 5
import logo from "../../assets/logo.svg";
import styles from "./Header.module.css";
mayi's avatar
mayi committed
6

7 8
import { Layout, Typography, Input, Menu, Button, Dropdown } from "antd";
import { GlobalOutlined } from "@ant-design/icons";
9 10 11
import { useSelector } from "../../redux/hooks";
import { useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
12 13
import {
  useHistory,
14 15 16
  // useParams,
  // useLocation,
  // useRouteMatch,
17
} from "react-router-dom";
18 19 20 21
import {
  changeLanguageActionCreator,
  addLanguageActionCreator,
} from "../../redux/language/languageActions";
22 23
export const Header: React.FC = () => {
  const history = useHistory();
24 25 26
  // const params = useParams();
  // const location = useLocation();
  // const match = useRouteMatch();
mayi's avatar
mayi committed
27 28
  const languageList = useSelector((state) => state.language.languageList);
  const language = useSelector((state) => state.language.language);
29 30 31 32 33
  const dispatch = useDispatch();
  const { t } = useTranslation();
  const changeLanguage = (e) => {
    if (e.key === "new") {
      // this.props.addLanguage("新语言", "新语言");
mayi's avatar
mayi committed
34
      dispatch(addLanguageActionCreator("新语言", "newLanguage"));
35 36 37 38 39 40
    } else {
      // this.props.changeLanguage(e.key);
      dispatch(changeLanguageActionCreator(e.key));
    }
  };

41 42 43 44 45 46 47 48 49 50
  return (
    <>
      <div className={styles["app-header"]}>
        {/* top-header */}
        <div className={styles["top-header"]}>
          <div className={styles["inner"]}>
            <Typography.Text>让旅游更幸福</Typography.Text>
            <Dropdown.Button
              style={{ marginLeft: 15 }}
              overlay={
51 52 53 54 55
                <Menu onClick={changeLanguage}>
                  {languageList.map((item, index) => (
                    <Menu.Item key={item.code}>{item.name}</Menu.Item>
                  ))}
                  <Menu.Item key={"new"}>{t("header.slogan")}</Menu.Item>
56 57 58 59
                </Menu>
              }
              icon={<GlobalOutlined />}
            >
60
              {language === "zh" ? "中文" : "English"}
61
            </Dropdown.Button>
mayi's avatar
mayi committed
62
            
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
            <Button.Group className={styles["button-group"]}>
              <Button onClick={() => history.push("register")}>注册</Button>
              <Button onClick={() => history.push("signin")}>登陆</Button>
            </Button.Group>
          </div>
        </div>
        <Layout.Header className={styles["main-header"]}>
          <span onClick={() => history.push("/")}>
            <img src={logo} alt="logo" className={styles["App-logo"]} />
            <Typography.Title level={3} className={styles.title}>
              React旅游网
            </Typography.Title>
          </span>

          <Input.Search
            placeholder={"请输入旅游目的地、主题、或关键字"}
            className={styles["search-input"]}
          />
        </Layout.Header>
        <Menu mode={"horizontal"} className={styles["main-menu"]}>
          <Menu.Item key={1}>旅游首页</Menu.Item>
          <Menu.Item key={2}>周末游</Menu.Item>
          <Menu.Item key={3}>跟团游</Menu.Item>
          <Menu.Item key="4"> 自由行 </Menu.Item>
          <Menu.Item key="5"> 私家团 </Menu.Item>
          <Menu.Item key="6"> 邮轮 </Menu.Item>
          <Menu.Item key="7"> 酒店+景点 </Menu.Item>
          <Menu.Item key="8"> 当地玩乐 </Menu.Item>
          <Menu.Item key="9"> 主题游 </Menu.Item>
          <Menu.Item key="10"> 定制游 </Menu.Item>
          <Menu.Item key="11"> 游学 </Menu.Item>
          <Menu.Item key="12"> 签证 </Menu.Item>
          <Menu.Item key="13"> 企业游 </Menu.Item>
          <Menu.Item key="14"> 高端游 </Menu.Item>
          <Menu.Item key="15"> 爱玩户外 </Menu.Item>
          <Menu.Item key="16"> 保险 </Menu.Item>
        </Menu>
      </div>
    </>
  );
};