张延森 3 years ago
parent
commit
eb3f86fd66
2 changed files with 11 additions and 5 deletions
  1. 5
    2
      src/main.js
  2. 6
    3
      src/util/initial.js

+ 5
- 2
src/main.js View File

58
 redirect()
58
 redirect()
59
 
59
 
60
 Login().then(e => {
60
 Login().then(e => {
61
-
62
-
63
   new Vue({
61
   new Vue({
64
     router,
62
     router,
65
     store,
63
     store,
66
     render: h => h(App),
64
     render: h => h(App),
67
   }).$mount('#app')
65
   }).$mount('#app')
66
+}).catch(e => {
67
+  console.error(e)
68
+  // alert('系统错误, 请刷新重试')
68
 
69
 
70
+  // 重试一次
71
+  redirect(true)
69
 })
72
 })

+ 6
- 3
src/util/initial.js View File

64
 // Vue.use(Vuex)
64
 // Vue.use(Vuex)
65
 
65
 
66
 export function Login () {
66
 export function Login () {
67
-  console.log(store);
67
+  const code = process.env.NODE_ENV === 'development' ? '123' : getCode()
68
 
68
 
69
-  return UserLogin('123',).then(e => {
69
+  return UserLogin(code).then(e => {
70
     console.log(e);
70
     console.log(e);
71
     let userInfo = {
71
     let userInfo = {
72
       token: e.token,
72
       token: e.token,
155
   if (process.env.NODE_ENV === 'development') return;
155
   if (process.env.NODE_ENV === 'development') return;
156
 
156
 
157
   const originCode = localStorage.getItem('wxcode');
157
   const originCode = localStorage.getItem('wxcode');
158
+  const wxfirst = localStorage.getItem('wxfirst') === null;
158
   const queryCode = getCode();
159
   const queryCode = getCode();
160
+ 
159
   localStorage.setItem('wxcode', queryCode)
161
   localStorage.setItem('wxcode', queryCode)
162
+  localStorage.setItem('wxfirst', 'not');
160
 
163
 
161
-  if (force || !queryCode || queryCode === originCode) {
164
+  if (force || wxfirst || !queryCode || queryCode === originCode) {
162
 
165
 
163
     const local = encodeURIComponent(location.origin + location.pathname)
166
     const local = encodeURIComponent(location.origin + location.pathname)
164
     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`
167
     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`