Your Name 4 年之前
父節點
當前提交
2adceb639d
共有 3 個文件被更改,包括 35 次插入66 次删除
  1. 12
    36
      src/layouts/BasicLayout.jsx
  2. 2
    0
      src/layouts/BlankLayout.jsx
  3. 21
    30
      src/layouts/SecurityLayout.jsx

+ 12
- 36
src/layouts/BasicLayout.jsx 查看文件

@@ -35,45 +35,21 @@ const menuDataRender = (menuList) =>
35 35
     return Authorized.check(item.authority, localItem, null);
36 36
   });
37 37
 
38
-const copyright = `${(new Date()).getFullYear()} 云致科技`
39
-
40
-const defaultFooterDom = (
41
-  <DefaultFooter
42
-    copyright="2019 蚂蚁金服体验技术部出品"
43
-    links={[
44
-      // {
45
-      //   key: 'Ant Design Pro',
46
-      //   title: 'Ant Design Pro',
47
-      //   href: 'https://pro.ant.design',
48
-      //   blankTarget: true,
49
-      // },
50
-    ]}
51
-  />
52
-);
53
-
54 38
 const footerRender = () => {
55
-  if (!isAntDesignPro()) {
56
-    return defaultFooterDom;
57
-  }
39
+  const copyright = `${(new Date()).getFullYear()} 云致科技`
58 40
 
59 41
   return (
60
-    <>
61
-      {defaultFooterDom}
62
-      <div
63
-        style={{
64
-          padding: '0px 24px 24px',
65
-          textAlign: 'center',
66
-        }}
67
-      >
68
-        <a href="https://www.netlify.com" target="_blank" rel="noopener noreferrer">
69
-          <img
70
-            src="https://www.netlify.com/img/global/badges/netlify-color-bg.svg"
71
-            width="82px"
72
-            alt="netlify logo"
73
-          />
74
-        </a>
75
-      </div>
76
-    </>
42
+    <DefaultFooter
43
+      copyright={copyright}
44
+      links={[
45
+        // {
46
+        //   key: 'Ant Design Pro',
47
+        //   title: 'Ant Design Pro',
48
+        //   href: 'https://pro.ant.design',
49
+        //   blankTarget: true,
50
+        // },
51
+      ]}
52
+    />
77 53
   );
78 54
 };
79 55
 

+ 2
- 0
src/layouts/BlankLayout.jsx 查看文件

@@ -2,6 +2,8 @@ import React, { useState, useEffect } from 'react';
2 2
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
3 3
 
4 4
 const Layout = ({ history, children }) => {
5
+  console.log('-------->', history)
6
+
5 7
   return (
6 8
     <>{children}</>
7 9
   );

+ 21
- 30
src/layouts/SecurityLayout.jsx 查看文件

@@ -1,47 +1,38 @@
1
-import React from 'react';
1
+import React, { useState, useEffect } from 'react';
2 2
 import { connect } from 'dva';
3 3
 import { PageLoading } from '@ant-design/pro-layout';
4 4
 import { Redirect } from 'umi';
5 5
 import { stringify } from 'querystring';
6 6
 
7
-class SecurityLayout extends React.Component {
8
-  state = {
9
-    isReady: false,
10
-  };
7
+const SecurityLayout = (props) => {
8
+  const [isReady, setIsReady] = useState(false)
11 9
 
12
-  componentDidMount() {
13
-    this.setState({
14
-      isReady: true,
10
+  useEffect(() => {
11
+    setIsReady(true)
12
+    props.dispatch({
13
+      type: 'user/fetchCurrent',
15 14
     });
16
-    const { dispatch } = this.props;
15
+  }, [])
17 16
 
18
-    if (dispatch) {
19
-      dispatch({
20
-        type: 'user/fetchCurrent',
21
-      });
22
-    }
23
-  }
17
+  const { children, loading, currentUser, history } = props;
24 18
 
25
-  render() {
26
-    const { isReady } = this.state;
27
-    const { children, loading, currentUser } = this.props; // You can replace it to your authentication rule (such as check token exists)
28
-    // 你可以把它替换成你自己的登录认证规则(比如判断 token 是否存在)
19
+  console.log('--------->', history)
29 20
 
30
-    const isLogin = currentUser && currentUser.userId;
31
-    const queryString = stringify({
32
-      redirect: window.location.href,
33
-    });
21
+  const isLogin = currentUser && currentUser.userId;
34 22
 
35
-    if ((!isLogin && loading) || !isReady) {
36
-      return <PageLoading />;
37
-    }
23
+  const queryString = stringify({
24
+    redirect: window.location.href,
25
+  });
38 26
 
39
-    if (!isLogin && window.location.pathname !== '/user/login') {
40
-      return <Redirect to={`/user/login?${queryString}`} />;
41
-    }
27
+  if (loading || !isReady) {
28
+    return <PageLoading />;
29
+  }
42 30
 
43
-    return children;
31
+  if (!isLogin) {
32
+    return <Redirect to={`/user/login?${queryString}`} />;
44 33
   }
34
+
35
+  return children;
45 36
 }
46 37
 
47 38
 export default connect(({ user, loading }) => ({