This commit is contained in:
aixianling
2023-01-03 17:13:48 +08:00
parent 04664e58b3
commit 2c4e83a19b
2 changed files with 11 additions and 8 deletions

View File

@@ -0,0 +1,72 @@
<template>
<section class="weixinLogin">
<u-modal v-model="show" :content="content" confirm-text="去授权" cancel-text="仅浏览" show-cancel-button :show-title="false"
@confirm="handleConfirm" @cancel="handleCancel"/>
</section>
</template>
<script>
import {mapActions, mapState} from "vuex"
export default {
name: "weixinLogin",
props: {
content: {default: "是否要进行微信授权?"},
autoShow: Boolean,
visible: {default: ""}
},
computed: {
...mapState(['user']),
wxCode: v => v.$route.query.code,
},
data() {
return {
show: false
}
},
methods: {
...mapActions(['getWechatToken', 'getCode']),
handleConfirm() {
this.$http.get("/app/appdvcpconfig/getMpAppid", {withoutToken: true}).then(res => {
if (res?.code == 0 && res?.data) {
this.getCode({scope: "snsapi_userinfo", appid: res.data})
}
})
},
handleCancel() {
this.show = false
},
autoLogin() {
if (!this.user.token) this.getWechatToken({code: this.wxCode}).then(() => this.$emit("login")).catch(() => {
setTimeout(() => uni.showModal({
content: "是否要重新加载页面?",
success: res => {
if (!!res?.confirm) {
const redirect = this.$qs.parseUrl(location.href)
delete redirect.query.code
delete redirect.query.state
location.replace(this.$qs.stringifyUrl(redirect))
}
}
}), 500)
})
},
},
watch: {
autoShow: {
immediate: true,
handler(v) {
this.wxCode ? this.autoLogin() : this.show = !!v
}
},
visible(v) {
this.show = !!v
}
}
}
</script>
<style lang="scss" scoped>
.weixinLogin {
}
</style>