Browse Source

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

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

211
sub/common/waiting.vue

@ -1,114 +1,115 @@
<template> <template>
<view class="waiting"> <view class="waiting">
<u--image <u--image
src="/static/favicon.png" src="/static/favicon.png"
width="288rpx" width="288rpx"
height="288rpx" height="288rpx"
mode="aspectFit" mode="aspectFit"
:fade="true" :fade="true"
duration="200" duration="200"
></u--image> ></u--image>
<button <button class="login" @click="login">授权登录</button>
class="login" </view>
@click="login"
>
授权登录
</button>
</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: {
login() { login() {
if (!this.scene) { if (!this.scene) {
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 = {
qrLogin({ type: 34,
code: this.scene, code: res.code,
openid: res.code, state: 'default',
}).then(res => { userType: 3
setTimeout(() => { }
uni.hideLoading() await this.$store.dispatch('Login', data)
uni.switchTab({ qrLogin({
url: '/pages/index', code: this.scene,
}) openid: getAccessToken()
}, 3000) }).then(res => {
}) setTimeout(() => {
}, uni.hideLoading()
fail: err => { uni.switchTab({
uni.showToast({ url: '/pages/index'
title: err, })
duration: 2000, }, 3000)
icon: 'none', })
}) },
}, fail: err => {
}) uni.showToast({
} title: err,
}, duration: 2000,
}, icon: 'none'
onLoad(query) { })
// scene 使 decodeURIComponent scene }
this.scene = decodeURIComponent(query.scene) })
}, }
} }
},
onLoad(query) {
// scene 使 decodeURIComponent 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;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background: #17c653; background: #17c653;
gap: 40px; gap: 40px;
.login { .login {
display: flex; display: flex;
padding: var(--Number-12px, 24rpx) var(--Number-40px, 80rpx); padding: var(--Number-12px, 24rpx) var(--Number-40px, 80rpx);
justify-content: center; justify-content: center;
align-items: center; align-items: center;
border-radius: var(--Number-120px, 240rpx); border-radius: var(--Number-120px, 240rpx);
background: var(--LightMode-Light-Light, #fff); background: var(--LightMode-Light-Light, #fff);
box-shadow: 0px 6rpx 8rpx 0px rgba(0, 0, 0, 0.03); box-shadow: 0px 6rpx 8rpx 0px rgba(0, 0, 0, 0.03);
color: var(--LightMode-Success-Success, #17c653); color: var(--LightMode-Success-Success, #17c653);
font-family: 'PingFang SC'; font-family: 'PingFang SC';
font-size: 32rpx; font-size: 32rpx;
font-style: normal; font-style: normal;
font-weight: 500; font-weight: 500;
line-height: normal; line-height: normal;
} }
.title { .title {
font-family: 'PingFang SC'; font-family: 'PingFang SC';
font-size: 32rpx; font-size: 32rpx;
font-style: normal; font-style: normal;
font-weight: 500; font-weight: 500;
line-height: normal; line-height: normal;
} }
} }
</style> </style>

Loading…
Cancel
Save