BUG 22
This commit is contained in:
72
src/project/fengdu/AppVote/component/weixinLogin.vue
Normal file
72
src/project/fengdu/AppVote/component/weixinLogin.vue
Normal 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>
|
||||
Reference in New Issue
Block a user