张延森 2 years ago
parent
commit
de89ca0b06

+ 1
- 0
package.json View File

@@ -64,6 +64,7 @@
64 64
     "react-copy-to-clipboard": "^5.0.1",
65 65
     "react-dom": "^16.8.6",
66 66
     "react-helmet": "^5.2.1",
67
+    "react-transition-group": "^4.4.2",
67 68
     "react-zmage": "^0.8.5-beta.37",
68 69
     "redux": "^4.0.1",
69 70
     "umi": "^2.13.0",

+ 26
- 0
src/components/PageTransition/index.jsx View File

@@ -0,0 +1,26 @@
1
+import withRouter from 'umi/withRouter';
2
+import { CSSTransition, SwitchTransition } from 'react-transition-group';
3
+import styles from './style.less';
4
+
5
+export default withRouter((props) => {
6
+  const currentURL = props.location.pathname + props.location.search
7
+
8
+  return (
9
+    <SwitchTransition>
10
+      <CSSTransition
11
+        key={currentURL}
12
+        addEndListener={(node, done) => node.addEventListener("transitionend", done, false)}
13
+        classNames={{
14
+          enter: styles['page-fade-enter'],
15
+          enterActive: styles['page-fade-enter-active'],
16
+          exit: styles['page-fade-exit'],
17
+          exitActive: styles['page-fade-exit-active']
18
+        }}
19
+      >
20
+        <div>
21
+          {props.children}
22
+        </div>
23
+      </CSSTransition>
24
+    </SwitchTransition>
25
+  );
26
+})

+ 21
- 0
src/components/PageTransition/style.less View File

@@ -0,0 +1,21 @@
1
+
2
+.page-fade-enter {
3
+  opacity: 0;
4
+  transform: translateY(20%);
5
+}
6
+.page-fade-enter-active {
7
+  opacity: 1;
8
+  transform: translateY(0%);
9
+}
10
+.page-fade-exit {
11
+  opacity: 1;
12
+  transform: translateY(0%);
13
+}
14
+.page-fade-exit-active {
15
+  opacity: 0;
16
+  transform: translateY(20%);
17
+}
18
+.page-fade-enter-active,
19
+.page-fade-exit-active {
20
+  transition: opacity 500ms, transform 500ms;
21
+}

+ 0
- 39
src/components/RouterEvent/index.jsx View File

@@ -1,39 +0,0 @@
1
-import { Component, Fragment } from "react";
2
-import withRouter from 'umi/withRouter';
3
-import Prompt from 'umi/prompt';
4
-
5
-class RouterEvent extends Component {
6
-  state = {
7
-    location: {}
8
-  }
9
-
10
-  componentDidMount() {
11
-    console.log('-----props------->', this.props)
12
-
13
-    this.props.onEnter();
14
-    this.setState({ location: this.props.location });
15
-  }
16
-
17
-  componentDidUpdate() {
18
-    const originURL = this.props.location.pathname + this.props.location.search
19
-    const currentURL = this.state.location.pathname + this.state.location.search
20
-
21
-    if (originURL != currentURL) {
22
-      this.props.onEnter();
23
-      this.setState({ location: this.props.location });
24
-    }
25
-  }
26
-
27
-  render() {
28
-    const onLeave = this.props.onLeave;
29
-
30
-    return (
31
-      <div>
32
-        <Prompt message={() => { onLeave(); return true; }} />
33
-        {this.props.children}
34
-      </div>
35
-    );
36
-  }
37
-}
38
-
39
-export default withRouter(RouterEvent)

+ 5
- 5
src/layouts/BlankLayout.jsx View File

@@ -1,11 +1,11 @@
1 1
 import React from 'react';
2
-import RouterEvent from '@/components/RouterEvent';
2
+import PageTransition from '@/components/PageTransition';
3 3
 
4
-const Layout = ({ children }) => {
4
+const Layout = (props) => {
5 5
   return (
6
-    <RouterEvent onEnter={() => console.log('------onEnter--------')} onLeave={() => console.log('------onLeave--------')}>
7
-      <>{children}</>
8
-    </RouterEvent>
6
+    <PageTransition>
7
+      {props.children}
8
+    </PageTransition>
9 9
   );
10 10
 };
11 11