Browse Source

优化登录流程,移除openid检查,调整微信登录逻辑,清除token和openid

master
parent
commit
80ab7585a4
  1. 9
      App.vue
  2. 37
      pages/login.vue
  3. 2
      utils/auth.js

9
App.vue

@ -1,11 +1,18 @@
<script> <script>
import config from './config.js' import config from './config.js'
import { getAccessToken, setOpenId, getOpenId } from '@/utils/auth' import {
getAccessToken,
setOpenId,
getOpenId,
removeToken,
removeOpenId
} from '@/utils/auth'
export default { export default {
data() { data() {
return {} return {}
}, },
async onLaunch(options) { async onLaunch(options) {
removeToken()
await this.initApp() await this.initApp()
}, },
onShow() { onShow() {

37
pages/login.vue

@ -34,18 +34,10 @@ export default {
await uni.hideTabBar({ await uni.hideTabBar({
animation: false animation: false
}) })
if (!getOpenId()) {
// openid
this.getWxOpenId().then(() => {
this.checkLogin()
})
} else {
// //
this.checkLogin() this.checkLogin()
}
}, },
checkLogin() { checkLogin() {
console.log('accessToken', getAccessToken())
if (!getAccessToken()) { if (!getAccessToken()) {
// token // token
this.login() this.login()
@ -53,26 +45,14 @@ export default {
this.loginSuccess() this.loginSuccess()
} }
}, },
getWxOpenId() { login() {
return new Promise((resolve, reject) => {
uni.login({ uni.login({
success: res => { success: res => {
// code openId console.log('微信code', res.code)
// code 使5 // code
// code openId
setOpenId(res.code)
resolve()
},
fail: err => {
reject()
}
})
})
},
login() {
const data = { const data = {
type: 34, type: 34,
code: getOpenId(), code: res.code,
state: 'default', state: 'default',
userType: this.getUserType() userType: this.getUserType()
} }
@ -80,6 +60,15 @@ export default {
this.loginSuccess() this.loginSuccess()
}) })
}, },
fail: err => {
uni.showToast({
title: err,
duration: 2000,
icon: 'none'
})
}
})
},
getUserType() { getUserType() {
// //
if (this.inviteId) return 2 if (this.inviteId) return 2

2
utils/auth.js

@ -17,6 +17,7 @@ export function setToken(token) {
} }
export function removeToken() { export function removeToken() {
console.log('removeToken');
uni.removeStorageSync(AccessTokenKey) uni.removeStorageSync(AccessTokenKey)
uni.removeStorageSync(RefreshTokenKey) uni.removeStorageSync(RefreshTokenKey)
} }
@ -30,5 +31,6 @@ export function getOpenId() {
} }
export function removeOpenId() { export function removeOpenId() {
console.log('removeOpenId');
uni.removeStorageSync(OpenIdKey) uni.removeStorageSync(OpenIdKey)
} }
Loading…
Cancel
Save