Yansen 2 jaren geleden
bovenliggende
commit
c6cbfee85f

+ 7
- 7
src/layouts/AuthLayout/components/Container.jsx Bestand weergeven

@@ -7,18 +7,18 @@ import Footer from './Footer';
7 7
 const { Content } = Layout;
8 8
 
9 9
 export default (props) => {  
10
-  const containerRef = useRef();
11
-  const [minHeight, setMinHeight] = useState(0);
12
-  const contentStyle = useMemo(() => ({ minHeight: `${minHeight}px` }), [minHeight]);
10
+  const [footerHeight, setFooterHeight] = useState(0);
11
+
12
+  // 24 是 marginTop 的值
13
+  const contentStyle = useMemo(() => ({ height: footerHeight > 0 ? `calc(100% - ${footerHeight + 24}px)` : '100%' }), [footerHeight]);
13 14
   
14 15
   useEffect(() => {
15
-    const containerHeight = containerRef.current.offsetHeight;
16 16
     const footerHeight = (document.querySelector('.ant-layout-footer') || {}).offsetHeight || 0;
17
-    setMinHeight(containerHeight - footerHeight);
18
-  }, []);
17
+    setFooterHeight(footerHeight);
18
+  });
19 19
 
20 20
   return (
21
-    <div className='layout-container' ref={containerRef}>
21
+    <div className='layout-container'>
22 22
       <Content style={contentStyle}>
23 23
         {/* <PageTransition location={props.location}> */}
24 24
           <Outlet />

+ 2
- 2
src/layouts/AuthLayout/index.jsx Bestand weergeven

@@ -33,9 +33,9 @@ export default (props) => {
33 33
           noLayout
34 34
             ? <Outlet />
35 35
             : (
36
-              <Layout style={{ minHeight: '100vh' }}>
36
+              <Layout style={{ height: '100vh' }}>
37 37
                 <Header theme={theme} menus={splitMenus} location={location} />
38
-                <Layout>
38
+                <Layout style={{ height: 'calc(100vh - var(--header-height))' }}>
39 39
                   { !noSiderBar && <SiderBar theme={theme} menus={siderMenus} location={location} /> }
40 40
                   <Container location={location} noFooter={noFooter} />
41 41
                 </Layout>

+ 1
- 0
src/layouts/AuthLayout/style.less Bestand weergeven

@@ -94,6 +94,7 @@
94 94
 }
95 95
 
96 96
 .layout-container {
97
+  height: 100%;
97 98
   flex: 1;
98 99
 
99 100
   overflow-y: auto;

+ 0
- 127
src/pages/sample/home/components/Banner.jsx Bestand weergeven

@@ -1,127 +0,0 @@
1
-import { Row, Col, Card, Statistic, Carousel } from "antd";
2
-import {
3
-  ArrowDownOutlined,
4
-  ArrowUpOutlined,
5
-  LikeOutlined,
6
-} from "@ant-design/icons";
7
-import React, { useState } from "react";
8
-import { getBannerList } from "@/services/rotationChart";
9
-
10
-import { useRef } from "react";
11
-import { useEffect } from "react";
12
-import moment from "moment";
13
-import VideoPlay from "./VideoPlay.jsx";
14
-import { floatDivide } from "@/utils";
15
-
16
-const contentStyle = {
17
-  height: "760px",
18
-  margin: "0 auto",
19
-  width: "100%",
20
-  // color: "#fff",
21
-  // lineHeight: "160px",
22
-  // textAlign: "center",
23
-  // background: "#364d79",
24
-};
25
-
26
-export default (props) => {
27
-  const [autoPlay, setAutoPlay] = useState(true);
28
-  const [current, setCurrent] = useState(0);
29
-  const [mouse, setMouse] = useState(false);
30
-  const [mediaList, setMediaList] = useState([]);
31
-
32
-  const ref = useRef();
33
-
34
-  const mouseRef = useRef(false);
35
-  const isVideoRef = useRef(false);
36
-  const isVideoPlayRef = useRef(false);
37
-  useEffect(() => {
38
-    getBannerList().then((res) => {
39
-   
40
-
41
-      setMediaList(
42
-        res?.records?.map((x) => {
43
-          if (x.type === "2") {
44
-            return {
45
-              ...x,
46
-              type: "video",
47
-              url: x.video,
48
-            };
49
-          } else {
50
-            return {
51
-              ...x,
52
-              type: "image",
53
-              url: x.image,
54
-            };
55
-          }
56
-        })
57
-      );
58
-    });
59
-    handNext();
60
-  }, []);
61
-
62
-  const handNext = () => {
63
-    setTimeout(() => {
64
-
65
-      if (!mouseRef.current && !isVideoRef.current && !isVideoPlayRef.current) {
66
-        ref.current?.next();
67
-      }
68
-      handNext();
69
-    }, 3000);
70
-  };
71
-
72
-  const onMouseEnter = () => {
73
-   
74
-    mouseRef.current = true;
75
-  };
76
-  const onMouseLeave = () => {
77
-    mouseRef.current = false;
78
-  };
79
-
80
-  return (
81
-    <>
82
-      <div
83
-        onMouseEnter={onMouseEnter}
84
-        onMouseLeave={onMouseLeave}
85
-        style={{ height: 800 }}
86
-      >
87
-        <Carousel
88
-          ref={ref}
89
-          afterChange={(cur) => {
90
-            setCurrent(cur);
91
-          }}
92
-        >
93
-          {mediaList?.map((x, index) => {
94
-            if (x.type === "image") {
95
-              return (
96
-                <div className="abc" key={index}>
97
-                  <div style={{ overflow: "hidden" }}>
98
-                    <img src={x.url} style={contentStyle}></img>
99
-                  </div>
100
-                </div>
101
-              );
102
-            }
103
-            if (x.type === "video") {
104
-
105
-              return (
106
-                <div key={index}>
107
-                  <VideoPlay
108
-                    url={x.url}
109
-                    isVideoPlayRef={isVideoPlayRef}
110
-                    index={index}
111
-                    current={current}
112
-                    contentStyle={contentStyle}
113
-                  ></VideoPlay>
114
-                </div>
115
-              );
116
-            }
117
-          })}
118
-        </Carousel>
119
-      </div>
120
-
121
-      {/* <div>
122
-
123
-        <video autoPlay src={video2} ></video>
124
-      </div> */}
125
-    </>
126
-  );
127
-};

+ 10
- 14
src/pages/sample/home/components/VideoPlay.jsx Bestand weergeven

@@ -13,7 +13,7 @@ import { useEffect } from "react";
13 13
 
14 14
 // https://image.baidu.com/search/albumsdetail?tn=albumsdetail&word=%E5%9F%8E%E5%B8%82%E5%BB%BA%E7%AD%91%E6%91%84%E5%BD%B1%E4%B8%93%E9%A2%98&fr=searchindex_album%20&album_tab=%E5%BB%BA%E7%AD%91&album_id=7&rn=30
15 15
 const VideoPlay = (props) => {
16
-  const { url, index, current, isVideoPlayRef, contentStyle } = props;
16
+  const { url, index, current, isVideoPlayRef, style } = props;
17 17
 
18 18
   const ref = useRef();
19 19
 
@@ -37,19 +37,15 @@ const VideoPlay = (props) => {
37 37
   useEffect(() => {}, []);
38 38
 
39 39
   return (
40
-    <>
41
-      <div style={contentStyle}>
42
-        <video
43
-          ref={ref}
44
-          autoPlay={false}
45
-          src={url}
46
-          onEnded={() => {
47
-            isVideoPlayRef.current = false;
48
-          }}
49
-          style={{ width: "100%", height: "100%", objectFit: "fill" }}
50
-        ></video>
51
-      </div>
52
-    </>
40
+    <video
41
+      ref={ref}
42
+      autoPlay={false}
43
+      src={url}
44
+      onEnded={() => {
45
+        isVideoPlayRef.current = false;
46
+      }}
47
+      style={style}
48
+    ></video>
53 49
   );
54 50
 };
55 51
 export default VideoPlay;

+ 101
- 13
src/pages/sample/home/index.jsx Bestand weergeven

@@ -1,19 +1,107 @@
1
-import React from 'react';
2
-import { Row, Col, Card, Space, Statistic } from 'antd';
3
-import Container from '@/components/page/Container';
4
-import Banner from './components/Banner';
1
+import { Carousel } from "antd";
2
+import React, { useState, useRef, useEffect, useMemo } from "react";
3
+import { getBannerList } from "@/services/rotationChart";
4
+
5
+import VideoPlay from "./components/VideoPlay";
6
+
7
+const height = "100%";
8
+const contentStyle = {
9
+  height,
10
+  margin: "0 auto",
11
+  width: "100%",
12
+};
5 13
 
6 14
 export default (props) => {
15
+  const [height, setHeight] = useState('100%');
16
+  const [current, setCurrent] = useState(0);
17
+  const [mouse, setMouse] = useState(false);
18
+  const [mediaList, setMediaList] = useState([]);
7 19
 
8
-  const chartStyle = {
9
-    height: '360px',
20
+  const ref = useRef();
21
+  const boxRef = useRef();
22
+  const mouseRef = useRef(false);
23
+  const isVideoRef = useRef(false);
24
+  const isVideoPlayRef = useRef(false);
25
+
26
+  const itemStyle = useMemo(() => ({
27
+    height,
28
+    overflow: 'hidden',
10 29
     width: '100%',
11
-  }
30
+    objectFit: 'fill',
31
+  }), [height]);
12 32
 
13
-  return (
14
-    <Container>
15
-      <Banner />
33
+  useEffect(() => {
34
+    getBannerList().then((res) => {
35
+      setMediaList(
36
+        res?.records?.map((x) => {
37
+          if (x.type === "2") {
38
+            return {
39
+              ...x,
40
+              type: "video",
41
+              url: x.video,
42
+            };
43
+          } else {
44
+            return {
45
+              ...x,
46
+              type: "image",
47
+              url: x.image,
48
+            };
49
+          }
50
+        })
51
+      );
52
+    });
53
+    handNext();
16 54
 
17
-    </Container>
18
-  )
19
-}
55
+    
56
+    const boxHeight = boxRef.current.offsetHeight;
57
+    setHeight(boxHeight ? `${boxHeight}px` : '100%');
58
+  }, []);
59
+
60
+  const handNext = () => {
61
+    setTimeout(() => {
62
+      if (!mouseRef.current && !isVideoRef.current && !isVideoPlayRef.current) {
63
+        ref.current?.next();
64
+      }
65
+      handNext();
66
+    }, 3000);
67
+  };
68
+
69
+  const onMouseEnter = () => {
70
+   
71
+    mouseRef.current = true;
72
+  };
73
+  const onMouseLeave = () => {
74
+    mouseRef.current = false;
75
+  };
76
+
77
+  return (
78
+    <div
79
+      onMouseEnter={onMouseEnter}
80
+      onMouseLeave={onMouseLeave}
81
+      style={{ height, overflow: "hidden" }}
82
+      ref={boxRef}
83
+    >
84
+      <Carousel
85
+        ref={ref}
86
+        afterChange={(cur) => {
87
+          setCurrent(cur);
88
+        }}
89
+      >
90
+          {mediaList?.map((x, index) => (
91
+            <div key={index}>
92
+              { x.type === "image" && <img src={x.url} style={itemStyle}></img> }
93
+              { x.type === "video" && (
94
+                <VideoPlay
95
+                  url={x.url}
96
+                  isVideoPlayRef={isVideoPlayRef}
97
+                  index={index}
98
+                  current={current}
99
+                  style={itemStyle}
100
+                />
101
+              )}
102
+            </div>
103
+          ))}
104
+      </Carousel>
105
+    </div>
106
+  );
107
+};

+ 3
- 1
src/routes/routes.jsx Bestand weergeven

@@ -429,7 +429,7 @@ export const defaultRoutes = [
429 429
     children: [
430 430
       {
431 431
         index: true,
432
-        element: <Home />,
432
+        element: <Navigate to="home" replace />,
433 433
       },
434 434
       {
435 435
         path: "home",
@@ -437,6 +437,8 @@ export const defaultRoutes = [
437 437
         meta: {
438 438
           title: "首页",
439 439
           icon: <DesktopOutlined />,
440
+          noSiderBar: true,
441
+          noFooter: true,
440 442
         },
441 443
       },
442 444
       {