Browse Source

优化登录逻辑,改进用户登录流程,调整二维码扫码逻辑并集成状态管理

master
parent
commit
932affebad
  1. 47
      sub/common/waiting.vue

47
sub/common/waiting.vue

@ -8,23 +8,18 @@
:fade="true" :fade="true"
duration="200" duration="200"
></u--image> ></u--image>
<button <button class="login" @click="login">授权登录</button>
class="login"
@click="login"
>
授权登录
</button>
</view> </view>
</template> </template>
<script> <script>
import { getAccessToken, getOpenId } from '@/utils/auth' import { getAccessToken, getOpenId } from '@/utils/auth'
import { qrLogin } from '@/api/login' import { qrLogin } from '@/api/login'
export default { export default {
data() { data() {
return { return {
scene: '', scene: ''
} }
}, },
methods: { methods: {
@ -33,30 +28,36 @@
uni uni
.showModal({ .showModal({
content: '链接失效,请重新扫码', content: '链接失效,请重新扫码',
showCancel: false, showCancel: false
}) })
.then(() => { .then(() => {
uni.exitMiniProgram({ uni.exitMiniProgram({
success: res => { success: res => {
console.log(res) console.log(res)
}, }
}) })
}) })
} else { } else {
uni.showLoading({ uni.showLoading({
title: '登陆中。。。', title: '登陆中。。。'
}) })
uni.login({ uni.login({
success: res => { success: async res => {
console.log('微信code', res.code) const data = {
type: 34,
code: res.code,
state: 'default',
userType: 3
}
await this.$store.dispatch('Login', data)
qrLogin({ qrLogin({
code: this.scene, code: this.scene,
openid: res.code, openid: getAccessToken()
}).then(res => { }).then(res => {
setTimeout(() => { setTimeout(() => {
uni.hideLoading() uni.hideLoading()
uni.switchTab({ uni.switchTab({
url: '/pages/index', url: '/pages/index'
}) })
}, 3000) }, 3000)
}) })
@ -65,22 +66,22 @@
uni.showToast({ uni.showToast({
title: err, title: err,
duration: 2000, duration: 2000,
icon: 'none', icon: 'none'
}) })
}, }
}) })
} }
}, }
}, },
onLoad(query) { onLoad(query) {
// scene 使 decodeURIComponent scene // scene 使 decodeURIComponent scene
this.scene = decodeURIComponent(query.scene) this.scene = decodeURIComponent(query.scene)
},
} }
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.waiting { .waiting {
height: 100vh; height: 100vh;
display: flex; display: flex;
flex-flow: column nowrap; flex-flow: column nowrap;
@ -110,5 +111,5 @@
font-weight: 500; font-weight: 500;
line-height: normal; line-height: normal;
} }
} }
</style> </style>

Loading…
Cancel
Save