张延森 преди 4 години
родител
ревизия
1fa300d30b
променени са 3 файла, в които са добавени 12 реда и са изтрити 8 реда
  1. 3
    6
      src/layout/IsLogin.jsx
  2. 8
    1
      src/layout/index.scss
  3. 1
    1
      src/reducers/user.js

+ 3
- 6
src/layout/IsLogin.jsx Целия файл

@@ -1,16 +1,13 @@
1
-import React from "react";
1
+import React, { useState, useEffect } from "react";
2 2
 import { View, ScrollView } from "@tarojs/components";
3 3
 import "./index.scss";
4 4
 import useUser from "../store/user";
5 5
 
6 6
 const IsLogin = ({ children }) => {
7 7
   const { user } = useUser();
8
-  console.log(user, "user");
9 8
 
10
-  return user && user.userId
11
-    ? children
12
-    : <View style={{textAlign:'center', marginTop: '200px', fontSize: '0.7em', color: '#888'}}>您暂无权限访问当前页面</View>
13
-  ;
9
+  return user && user.userId ? children :
10
+    (<View className="no-rights">您暂无权限访问当前页面</View>)
14 11
 };
15 12
 
16 13
 export default IsLogin;

+ 8
- 1
src/layout/index.scss Целия файл

@@ -2,4 +2,11 @@
2 2
     
3 3
     height: calc(100vh - 173.33px)
4 4
     
5
-}
5
+}
6
+
7
+.no-rights {
8
+    text-align: center;
9
+    margin-top: 200px;
10
+    font-size: 0.7em;
11
+    color: #888;
12
+}

+ 1
- 1
src/reducers/user.js Целия файл

@@ -6,7 +6,7 @@ export default function user(state = INITIAL_STATE, action) {
6 6
     case 'setUser':
7 7
       return {
8 8
         ...state,
9
-        user: action.payload
9
+        ...action.payload || {}
10 10
       }
11 11
       default:
12 12
         return state