|
@@ -1,8 +1,278 @@
|
|
|
-import { FC } from "@tarojs/taro";
|
|
|
-import { PageSwiper } from "../../components/PageSwiper";
|
|
|
+import { Swiper, SwiperItem, View, Image, Video } from "@tarojs/components";
|
|
|
+import Taro, { FC, pxTransform, useDidShow } from "@tarojs/taro";
|
|
|
+import classNames from "classnames";
|
|
|
+import { useEffect, useRef, useState } from "react";
|
|
|
+import TitleImg1 from "./images/tab2@2x-min.png";
|
|
|
+import TitleImg2 from "./images/tab1@2x-min.png";
|
|
|
+import TitleImg3 from "./images/tab3@2x-min.png";
|
|
|
+import LabelImg1 from "./images/Group35@2x-min.png";
|
|
|
+import LabelImg2 from "./images/Group37@2x-min.png";
|
|
|
+import LabelImg3 from "./images/Group36@2x-min.png";
|
|
|
+import LogoImg from "./images/LOGO@2x-min.png";
|
|
|
+import FootPageImg from "./images/Group23@2x-min.png";
|
|
|
+import baseStore from "../../store/base";
|
|
|
+import { getSceneUrl, login } from "../../utils";
|
|
|
+import { VisitCard } from "../../pages/home/components/VisitCard";
|
|
|
+import { VideoWrap } from "../../components/Video";
|
|
|
+import { AtIcon } from "taro-ui";
|
|
|
+import "./index.scss";
|
|
|
+
|
|
|
+const LIST = [
|
|
|
+ {
|
|
|
+ title: TitleImg1,
|
|
|
+ img: "https://houseoss.4dkankan.com/project/wx-csbwg-public/images/pic-or-2%402x-min.jpg",
|
|
|
+ label: LabelImg1,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: TitleImg2,
|
|
|
+ img: "https://houseoss.4dkankan.com/project/wx-csbwg-public/images/pic-or%402x-min.jpg",
|
|
|
+ label: LabelImg2,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: TitleImg3,
|
|
|
+ img: "https://houseoss.4dkankan.com/project/wx-csbwg-public/images/pic-or-3%402x-min.jpg",
|
|
|
+ label: LabelImg3,
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+const system = Taro.getSystemInfoSync();
|
|
|
+const getPX = (num: number) => num / (750 / system.windowWidth);
|
|
|
+const swipeOffsetX = getPX(390);
|
|
|
+const damping = 50 / swipeOffsetX;
|
|
|
+const rotateDamping = 20 / swipeOffsetX;
|
|
|
+
|
|
|
+const POS_MAP = {
|
|
|
+ 0: [50, 100, 200],
|
|
|
+ 1: [0, 50, 100],
|
|
|
+ 2: [-100, 0, 50],
|
|
|
+};
|
|
|
+
|
|
|
+const ROTATEY_MAP = {
|
|
|
+ 0: [0, -20, -40],
|
|
|
+ 1: [20, 0, -20],
|
|
|
+ 2: [40, 20, 0],
|
|
|
+};
|
|
|
|
|
|
const BannerPage: FC = () => {
|
|
|
- return <PageSwiper />;
|
|
|
+ const [loaded, setLoaded] = useState(false);
|
|
|
+ const [loading, setLoading] = useState(true);
|
|
|
+ // 背景视频是否报错
|
|
|
+ const [videoError, setVideoError] = useState(false);
|
|
|
+ const [XSZCVideoVisible, setXSZCVideoVisible] = useState(false);
|
|
|
+ const [BWGVideoVisible, setBWGVideoVisible] = useState(false);
|
|
|
+ const [active, setActive] = useState(1);
|
|
|
+ const [moveX, setMoveX] = useState(0);
|
|
|
+ const [bgPos, setBgPos] = useState([...POS_MAP[1]]);
|
|
|
+ const [bgRotateY, setBgRotateY] = useState([...ROTATEY_MAP[1]]);
|
|
|
+ const moving = useRef(false);
|
|
|
+ const isFirstMove = useRef(true);
|
|
|
+ const [visitVisible, setVisitVisible] = useState(false);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ console.log("mount", Taro.getSystemInfoSync());
|
|
|
+
|
|
|
+ return () => {
|
|
|
+ console.log("unmount");
|
|
|
+ };
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const handleClick = (idx: number) => {
|
|
|
+ if (idx !== active) return;
|
|
|
+
|
|
|
+ switch (idx) {
|
|
|
+ case 0:
|
|
|
+ Taro.navigateTo({
|
|
|
+ url: "/pages/home/index",
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ setXSZCVideoVisible(true);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ setBWGVideoVisible(true);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const goUnityPage = async () => {
|
|
|
+ const userInfo = baseStore.userInfo;
|
|
|
+
|
|
|
+ if (!userInfo) {
|
|
|
+ await login();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userInfo.invite === 0) {
|
|
|
+ setVisitVisible(true);
|
|
|
+ setXSZCVideoVisible(false);
|
|
|
+ } else {
|
|
|
+ Taro.navigateTo({
|
|
|
+ url: "/pages/iframe/index?url=" + encodeURIComponent(getSceneUrl()),
|
|
|
+ });
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ setXSZCVideoVisible(false);
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleBgLoaded = () => {
|
|
|
+ setLoaded(true);
|
|
|
+ setTimeout(() => {
|
|
|
+ setLoading(false);
|
|
|
+ }, 1000);
|
|
|
+ };
|
|
|
+
|
|
|
+ return (
|
|
|
+ <View className={classNames("page-swiper", { "is-error": videoError })}>
|
|
|
+ <View
|
|
|
+ className={classNames("ld-page", { hide: loaded })}
|
|
|
+ style={{ zIndex: loading ? 999 : -1 }}
|
|
|
+ >
|
|
|
+ <AtIcon
|
|
|
+ className="ld-page__icon"
|
|
|
+ value="loading"
|
|
|
+ color="#589498"
|
|
|
+ size={40}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+
|
|
|
+ <Image
|
|
|
+ className="page-swiper__title"
|
|
|
+ src={LIST[active].title}
|
|
|
+ mode="heightFix"
|
|
|
+ />
|
|
|
+
|
|
|
+ <Swiper
|
|
|
+ className="banner"
|
|
|
+ current={active}
|
|
|
+ display-multiple-items={1}
|
|
|
+ nextMargin={pxTransform(180)}
|
|
|
+ previousMargin={pxTransform(180)}
|
|
|
+ onTransition={({ detail: { dx } }) => {
|
|
|
+ moving.current = true;
|
|
|
+ setMoveX(dx - (isFirstMove.current ? swipeOffsetX : 0));
|
|
|
+ }}
|
|
|
+ onAnimationFinish={({ detail: { current } }) => {
|
|
|
+ moving.current = false;
|
|
|
+ isFirstMove.current = false;
|
|
|
+ setActive(current);
|
|
|
+ setBgPos([...POS_MAP[current]]);
|
|
|
+ setBgRotateY([...ROTATEY_MAP[current]]);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {LIST.map((item, idx) => {
|
|
|
+ const isActive = active === idx;
|
|
|
+ const bgPosition = moving.current
|
|
|
+ ? Math.min(Math.max(bgPos[idx] - moveX * damping, 0), 100)
|
|
|
+ : bgPos[idx];
|
|
|
+ const rotateY = moving.current
|
|
|
+ ? Math.min(
|
|
|
+ Math.max(bgRotateY[idx] + moveX * rotateDamping, -20),
|
|
|
+ 20
|
|
|
+ )
|
|
|
+ : bgRotateY[idx];
|
|
|
+
|
|
|
+ return (
|
|
|
+ <SwiperItem key={idx} className="banner-swiper-item">
|
|
|
+ <View
|
|
|
+ className={classNames("banner-item", {
|
|
|
+ active: isActive,
|
|
|
+ })}
|
|
|
+ style={{
|
|
|
+ transform: `rotateY(${rotateY}deg)`,
|
|
|
+ }}
|
|
|
+ onClick={handleClick.bind(undefined, idx)}
|
|
|
+ >
|
|
|
+ {!isActive && (
|
|
|
+ <Image
|
|
|
+ className="banner-item__label"
|
|
|
+ src={item.label}
|
|
|
+ mode="widthFix"
|
|
|
+ style={{
|
|
|
+ right: idx <= active ? 0 : "unset",
|
|
|
+ left: idx > active ? 0 : "unset",
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ <View
|
|
|
+ className="banner-item__img"
|
|
|
+ style={{
|
|
|
+ backgroundImage: `url(${item.img})`,
|
|
|
+ backgroundPosition: `${bgPosition}%`,
|
|
|
+ }}
|
|
|
+ ></View>
|
|
|
+ </View>
|
|
|
+ </SwiperItem>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </Swiper>
|
|
|
+
|
|
|
+ <View className="page-swiper-footer">
|
|
|
+ <Image
|
|
|
+ className="page-swiper-footer__logo"
|
|
|
+ src={LogoImg}
|
|
|
+ mode="heightFix"
|
|
|
+ />
|
|
|
+ <View className="page-swiper-footer__text">
|
|
|
+ 让慈善之光照进心灵,照亮生活,照耀社会
|
|
|
+ </View>
|
|
|
+ <Image
|
|
|
+ className="page-swiper-footer__tips"
|
|
|
+ src={FootPageImg}
|
|
|
+ mode="heightFix"
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+
|
|
|
+ {!videoError && (
|
|
|
+ <Video
|
|
|
+ className="page-swiper__bg"
|
|
|
+ src="https://houseoss.4dkankan.com/project/wx-csbwg-public/videos/bg%403x.mp4"
|
|
|
+ autoplay
|
|
|
+ muted
|
|
|
+ loop
|
|
|
+ controls={false}
|
|
|
+ enableProgressGesture={false}
|
|
|
+ objectFit="cover"
|
|
|
+ onLoadedMetaData={handleBgLoaded}
|
|
|
+ onError={() => {
|
|
|
+ setVideoError(true);
|
|
|
+ handleBgLoaded();
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+
|
|
|
+ <VisitCard
|
|
|
+ isOpened={visitVisible}
|
|
|
+ onClose={() => setVisitVisible(false)}
|
|
|
+ />
|
|
|
+
|
|
|
+ {XSZCVideoVisible && (
|
|
|
+ <VideoWrap
|
|
|
+ autoplay
|
|
|
+ controls={false}
|
|
|
+ src="https://houseoss.4dkankan.com/project/wx-csbwg-public/videos/xszc.mp4"
|
|
|
+ onEnded={goUnityPage}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+
|
|
|
+ {BWGVideoVisible && (
|
|
|
+ <VideoWrap
|
|
|
+ autoplay
|
|
|
+ controls={false}
|
|
|
+ objectFit="cover"
|
|
|
+ src="https://houseoss.4dkankan.com/project/wx-csbwg-public/videos/bwg.mp4"
|
|
|
+ onEnded={() => {
|
|
|
+ Taro.navigateTo({
|
|
|
+ url: "/subModule/pages/museum/index",
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ setBWGVideoVisible(false);
|
|
|
+ }, 1000);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </View>
|
|
|
+ );
|
|
|
};
|
|
|
|
|
|
export default BannerPage;
|