Browse Source

授权登录修改

master
DX 2 weeks ago
parent
commit
b3f0d90b16
  1. 45
      sub/common/waiting.vue

45
sub/common/waiting.vue

@ -8,18 +8,23 @@
:fade="true" :fade="true"
duration="200" duration="200"
></u--image> ></u--image>
<button class="login" @click="login">授权登录</button> <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: {
@ -28,42 +33,54 @@ export default {
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({
success: res => {
console.log('微信code', res.code)
qrLogin({ qrLogin({
code: this.scene, code: this.scene,
openid: getOpenId() openid: res.code,
}).then(res => { }).then(res => {
setTimeout(() => { setTimeout(() => {
uni.hideLoading() uni.hideLoading()
uni.switchTab({ uni.switchTab({
url: '/pages/index' url: '/pages/index',
}) })
}, 3000) }, 3000)
}) })
},
fail: err => {
uni.showToast({
title: err,
duration: 2000,
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;
@ -93,5 +110,5 @@ export default {
font-weight: 500; font-weight: 500;
line-height: normal; line-height: normal;
} }
} }
</style> </style>

Loading…
Cancel
Save