miniprogram_jump.vue
2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<template>
<!-- <div>小程序-授权认证中</div> -->
<div>
<van-empty
:description="loginFail ? tips : '小程序-授权认证中...'"
image="network"
>
<van-button
v-if="loginFail"
type="primary"
class="bottom-button"
to="login"
>
前往登录页
</van-button>
</van-empty>
<van-overlay :show="showOverlay" @click="showOverlay = false">
<div class="wrapper" @click.stop>
<van-loading text-color="#0094ff" vertical type="spinner">
{{ tips }}
</van-loading>
</div>
</van-overlay>
</div>
</template>
<script>
import req from '@/request.js'
import utils from '@/jump.js'
export default {
data() {
return {
code: '',
showOverlay: false,
tips: '',
loginFail: false,
}
},
created() {
if (sessionStorage.getItem('currentUser')) {
this.$router.push({ path: '/home' })
return
}
let _this = this
let code = utils.getParameters('code')
if (!code) {
this.showOverlay = true
this.tips = '无code参数,将跳转至登录页。。。'
setTimeout((e) => {
_this.showOverlay = false
_this.$router.push('/login')
}, 2000)
return
}
this.code = code
this.proxyLogin()
},
methods: {
proxyLogin() {
this.showOverlay = true
this.tips = '小程序授权认证中...'
let _this = this
let url = window.context.auth + '/sso/miniprogram?code=' + _this.code
req
.get(url, null, false)
.then((resp) => {
if (resp.data.state) {
sessionStorage.setItem(
'currentUser',
JSON.stringify(resp.data.value)
)
// sessionStorage.setItem('token', resp.data.value.token)
// sessionStorage.setItem('username', resp.data.value.username)
// sessionStorage.setItem('account', resp.data.value.account)
// sessionStorage.setItem('userId', resp.data.value.userId)
_this.$router.push('/home')
} else {
sessionStorage.setItem('mpOpenid', resp.data.value)
_this.$router.push('/login')
// _this.showOverlay = true
// _this.tips = '未绑定小程序,跳转登录页'
// setTimeout(e => {
// _this.showOverlay = false
// }, 1000)
}
})
.catch((e) => {
this.showOverlay = false
this.loginFail = true
this.tips = e.response.data.message
})
},
},
}
</script>
<style lang="scss" scoped>
.wrapper {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.block {
background-color: #fff;
}
</style>