home.tsx 3.88 KB
Newer Older
1 2
import * as React from "react";
// import { Component } from "react";
3 4
import { withTranslation, WithTranslation } from "react-i18next";

5 6 7 8 9 10 11 12
import {
  Header,
  Footer,
  SideMenu,
  Carouseee,
  ProductCollection,
  Bussiness,
} from "../../components";
13
import { connect } from "react-redux";
14
import styles from "./home.module.css";
15 16 17 18 19 20 21
import {
  // fetchRecommendProductSuccessActionCreator,
  // fetchRecommendProductStartActionCreator,
  // fetchRecommendProductFailActionCreator,
  giveMeDataActionCreator
} from "../../redux/recommendProducts/recommendProductActions";
//0D1F49DD13B9C757
22 23 24 25
import { productList1, productList2, productList3 } from "./mockups";
import sideImage1 from "../../assets/images/sider_2019_02-04-2.png";
import sideImage2 from "../../assets/images/sider_2019_02-04.png";
import sideImage3 from "../../assets/images/sider_2019_12-09.png";
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
import { Row, Col, Typography, Spin } from "antd";
import axios from "axios";
import { RootState } from "../../redux/store";

const mapStateToProps = (state: RootState) => {
  return {
    loading: state.recommendProduct.loading,
    error: state.recommendProduct.error,
    productList: state.recommendProduct.productList,
  };
};
const mapDispatchProps = (dispatch) => {
  return {
    // fetchStart: () => {
    //   dispatch(fetchRecommendProductStartActionCreator());
    // },
    // fetchSuccess: (data) => {
    //   dispatch(fetchRecommendProductSuccessActionCreator(data));
    // },
    // fetchFail: (error) => {
    //   dispatch(fetchRecommendProductFailActionCreator(error));
    // },
    giveMeData:()=>{
      dispatch(giveMeDataActionCreator())
    }
  };
};
type PropsType = WithTranslation &
  ReturnType<typeof mapDispatchProps> &
  ReturnType<typeof mapStateToProps>;
export class HomePageComponent extends React.Component<PropsType> {
   componentDidMount() {
  this.props.giveMeData()
  

  }
62 63

  render() {
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    const { t } = this.props;

    const { productList, loading, error } = this.props;
    console.log("productList", productList);
    // if (!productList.length) return null;
    if (loading) {
      return (
        <Spin
          size="large"
          style={{
            marginTop: 200,
            marginBottom: 200,
            marginLeft: "auto",
            marginRight: "auto",
            width: "100%",
          }}
        />
      );
    }
    if (error) {
      return <div>网站出错:{error}</div>;
    }
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    return (
      <>
        <Header />
        {/* 页面内容 */}
        <div className={styles["page-content"]}>
          <Row style={{ marginTop: 20 }}>
            <Col span={6}>
              <div>
                <SideMenu />
              </div>
            </Col>
            <Col span={18}>
              <div>
                <Carouseee />
              </div>
            </Col>
          </Row>
103
          {/* {productList.map} */}
104 105 106
          <ProductCollection
            title={
              <Typography.Title level={3} type="warning">
mayi's avatar
mayi committed
107
                {t("home_page.hot_recommended")}
108 109 110
              </Typography.Title>
            }
            sideImage={sideImage1}
111
            products={productList[0].touristRoutes}
112 113 114 115
          />
          <ProductCollection
            title={
              <Typography.Title level={3} type="danger">
116
                {t("home_page.new_arrival")}
117 118 119
              </Typography.Title>
            }
            sideImage={sideImage2}
120
            products={productList[1].touristRoutes}
121 122 123 124
          />
          <ProductCollection
            title={
              <Typography.Title level={3} type="success">
125
                {t("home_page.hot_recommended")}
126 127 128
              </Typography.Title>
            }
            sideImage={sideImage3}
129
            products={productList[2].touristRoutes}
130 131 132 133 134 135 136 137 138 139
          />
          <Bussiness />
        </div>

        <Footer />
      </>
    );
  }
}

140 141 142 143
export const HomePage = connect(
  mapStateToProps,
  mapDispatchProps
)(withTranslation()(HomePageComponent));