张延森 3 years ago
parent
commit
0f963ded47
2 changed files with 13 additions and 14 deletions
  1. 12
    13
      src/router/index.js
  2. 1
    1
      src/utils/wx.js

+ 12
- 13
src/router/index.js View File

37
 
37
 
38
   // 未登录
38
   // 未登录
39
   if (!person.personId) {
39
   if (!person.personId) {
40
-    getUserInfo().then(userinfo => {
41
-      if (!userinfo || !userinfo.openid) {
42
-        redirect(true)
43
-        return
44
-      }
45
-
46
-      login(userinfo).then(res => {
47
-        const { user, token } = res;
48
-        setPerson(user)
49
-        setToken(token)
40
+    try {
41
+      getUserInfo().then(userinfo => {
42
+        login(userinfo).then(res => {
43
+          const { user, token } = res;
44
+          setPerson(user)
45
+          setToken(token)
46
+        })
47
+      }).catch(() => {
48
+        return redirect(true)
50
       })
49
       })
51
-    }).catch(() => {
52
-      redirect(true)
53
-    })
50
+    } catch (error) {
51
+      return redirect(true)
52
+    }
54
   }
53
   }
55
 
54
 
56
   // 未登录的正常进行页面加载, 不需要进行页面控制
55
   // 未登录的正常进行页面加载, 不需要进行页面控制

+ 1
- 1
src/utils/wx.js View File

73
   const queryCode = getCode();
73
   const queryCode = getCode();
74
   localStorage.setItem('wxcode', queryCode)
74
   localStorage.setItem('wxcode', queryCode)
75
 
75
 
76
-  if (!queryCode || queryCode === originCode || force) {
76
+  if (force || !queryCode || queryCode === originCode) {
77
     const local = encodeURIComponent(location.origin + location.pathname)
77
     const local = encodeURIComponent(location.origin + location.pathname)
78
     const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd3bab568bc42d1de&redirect_uri=${local}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect`
78
     const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd3bab568bc42d1de&redirect_uri=${local}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect`
79
     window.location.href = url
79
     window.location.href = url