登录调整
Showing
4 changed files
with
33 additions
and
30 deletions
| ... | @@ -13,7 +13,6 @@ export default { | ... | @@ -13,7 +13,6 @@ export default { |
| 13 | firstload = true | 13 | firstload = true |
| 14 | 14 | ||
| 15 | this.globalData.baseUrl_api = config.baseUrl_api; | 15 | this.globalData.baseUrl_api = config.baseUrl_api; |
| 16 | |||
| 17 | let userName = uni.getStorageSync('userName') | 16 | let userName = uni.getStorageSync('userName') |
| 18 | if (userName) { | 17 | if (userName) { |
| 19 | this.globalData.isLogin = true; | 18 | this.globalData.isLogin = true; | ... | ... |
| ... | @@ -90,15 +90,21 @@ function loginByPhone(phonenumber, code) { | ... | @@ -90,15 +90,21 @@ function loginByPhone(phonenumber, code) { |
| 90 | 90 | ||
| 91 | // 获取用户详细信息 | 91 | // 获取用户详细信息 |
| 92 | function getInfo() { | 92 | function getInfo() { |
| 93 | let app | ||
| 93 | return request({ | 94 | return request({ |
| 94 | url: `${config.baseUrl_api}/getInfoForPc`, | 95 | url: `${config.baseUrl_api}/getInfoForPc`, |
| 95 | method: 'get' | 96 | method: 'get' |
| 96 | }).then(res => { | 97 | }).then(res => { |
| 97 | const app = getApp() | 98 | app = getApp() |
| 98 | const user = res.data.user | 99 | const user = res.data.user |
| 99 | uni.setStorageSync('userName', user.userName) | 100 | uni.setStorageSync('userName', user.userName) |
| 100 | uni.setStorageSync('perId', aes.encrypt(user.userId)) | 101 | uni.setStorageSync('perId', aes.encrypt(user.userId)) |
| 101 | app.globalData.userInfo = user | 102 | app.globalData.userInfo = user |
| 103 | }).catch(() => { | ||
| 104 | app = getApp() | ||
| 105 | uni.removeStorageSync('token') | ||
| 106 | uni.removeStorageSync('userName') | ||
| 107 | app.globalData.isLogin = false | ||
| 102 | }) | 108 | }) |
| 103 | } | 109 | } |
| 104 | 110 | ... | ... |
| 1 | // import config from '@/config.js' | 1 | // import config from '@/config.js' |
| 2 | import { | 2 | import _ from 'lodash' |
| 3 | h5LoginAuto | ||
| 4 | } from './login' | ||
| 5 | 3 | ||
| 6 | const excludeUrls = ['pages/index/login', 'pages/index/register'] | 4 | const excludeUrls = ['getMemberCountInfo', 'getInfoForPc'] |
| 7 | 5 | ||
| 8 | // 获取Token | 6 | // 获取Token |
| 9 | function getToken() { | 7 | function getToken() { |
| ... | @@ -65,10 +63,9 @@ const request = function(req) { | ... | @@ -65,10 +63,9 @@ const request = function(req) { |
| 65 | switch (res.statusCode) { | 63 | switch (res.statusCode) { |
| 66 | case 200: | 64 | case 200: |
| 67 | const data = res.data || {} | 65 | const data = res.data || {} |
| 68 | if (!data || data.code === 0 || data.code === 200 || data.pageData?.code === | 66 | if (!data || data.code === 0 || data.code === 200 || data.pageData?.code === 200) { |
| 69 | 200) { | ||
| 70 | resolve(data) | 67 | resolve(data) |
| 71 | } else if (req.url.indexOf('getMemberCountInfo') > -1) { | 68 | } else if (_.some(excludeUrls, (url) => req.url.indexOf(url) > -1)) { |
| 72 | resolve(data) | 69 | resolve(data) |
| 73 | } else { | 70 | } else { |
| 74 | if (data.msg) { | 71 | if (data.msg) { |
| ... | @@ -80,26 +77,27 @@ const request = function(req) { | ... | @@ -80,26 +77,27 @@ const request = function(req) { |
| 80 | } | 77 | } |
| 81 | 78 | ||
| 82 | // 登录超时 | 79 | // 登录超时 |
| 83 | if (data.code === 60002 || data.code === 60001) { | 80 | // if (data.code === 60002 || data.code === 60001) { |
| 84 | uni.redirectTo({ | 81 | // uni.redirectTo({ |
| 85 | url: '/pages/index/login' | 82 | // url: '/pages/index/login' |
| 86 | }) | 83 | // }) |
| 87 | } else if (data.code === 401) { | 84 | // } else if (data.code === 401) { |
| 88 | h5LoginAuto() | 85 | // h5LoginAuto() |
| 89 | .then(() => { | 86 | // .then(() => { |
| 90 | uni.hideLoading() | 87 | // uni.hideLoading() |
| 91 | uni.redirectTo({ | 88 | // uni.redirectTo({ |
| 92 | url: getCurrentPages()[getCurrentPages() | 89 | // url: getCurrentPages()[getCurrentPages() |
| 93 | .length - 1].$page.fullPath | 90 | // .length - 1].$page.fullPath |
| 94 | }) | 91 | // }) |
| 95 | }) | 92 | // }) |
| 96 | .catch(() => { | 93 | // .catch(() => { |
| 97 | uni.showToast({ | 94 | // debugger |
| 98 | title: '服务异常,请稍后重试', | 95 | // uni.showToast({ |
| 99 | icon: 'none' | 96 | // title: '服务异常,请稍后重试', |
| 100 | }) | 97 | // icon: 'none' |
| 101 | }) | 98 | // }) |
| 102 | } | 99 | // }) |
| 100 | // } | ||
| 103 | 101 | ||
| 104 | reject(res) | 102 | reject(res) |
| 105 | } | 103 | } | ... | ... |
-
Please register or sign in to post a comment