|
@@ -47,6 +47,9 @@ export default {
|
|
mounted() {
|
|
mounted() {
|
|
this.initData()
|
|
this.initData()
|
|
},
|
|
},
|
|
|
|
+ beforeDestroy() {
|
|
|
|
+ this.$removeStorage(this.redirectPath, 'login_redicret')
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
// 初始化数据
|
|
// 初始化数据
|
|
initData() {
|
|
initData() {
|
|
@@ -56,6 +59,10 @@ export default {
|
|
this.formData.appId = appId
|
|
this.formData.appId = appId
|
|
this.formData.authUserId = parseInt(authUserId)
|
|
this.formData.authUserId = parseInt(authUserId)
|
|
this.redirectPath = `/${authUserId}/${type}`
|
|
this.redirectPath = `/${authUserId}/${type}`
|
|
|
|
+ // 保存页面路由前缀
|
|
|
|
+ this.$store.commit('app/SET_ROUTE_PREFIX', this.redirectPath)
|
|
|
|
+ // 保存用户AppId
|
|
|
|
+ this.$store.commit('user/SET_AUTH_USER_ID', this.formData.authUserId)
|
|
// 尝试微信授权自动登录
|
|
// 尝试微信授权自动登录
|
|
this.autoLogin()
|
|
this.autoLogin()
|
|
},
|
|
},
|
|
@@ -63,18 +70,29 @@ export default {
|
|
// 绑定并登录
|
|
// 绑定并登录
|
|
async onSubmit() {
|
|
async onSubmit() {
|
|
try {
|
|
try {
|
|
- const res = await this.$http.api.customLogin(this.formData)
|
|
|
|
- this.$store.dispatch('user/login', res.data)
|
|
|
|
- this.$setStorage(this.redirectPath, 'userInfo', res.data)
|
|
|
|
- this.$toast('登录成功')
|
|
|
|
- setTimeout(() => {
|
|
|
|
- this.$router.push(this.redirectPath)
|
|
|
|
- }, 500)
|
|
|
|
|
|
+ const res = await this.$http.api.wechatLoginWithCode(this.formData)
|
|
|
|
+ this.loginSuccess(res)
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.log(error)
|
|
console.log(error)
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ loginSuccess(res) {
|
|
|
|
+ this.$toast('登录成功')
|
|
|
|
+ this.$store.dispatch('user/login', res.data)
|
|
|
|
+ this.$setStorage(this.redirectPath, 'userInfo', res.data)
|
|
|
|
+ // 重定向
|
|
|
|
+ const login_redicret = this.$getStorage(
|
|
|
|
+ this.redirectPath,
|
|
|
|
+ 'login_redicret'
|
|
|
|
+ )
|
|
|
|
+ if (login_redicret && login_redicret !== this.$route.path) {
|
|
|
|
+ this.$router.push(login_redicret)
|
|
|
|
+ } else {
|
|
|
|
+ this.$router.push(this.redirectPath)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
// 发送验证码
|
|
// 发送验证码
|
|
async onSend() {
|
|
async onSend() {
|
|
if (this.sendStatus > 0) return
|
|
if (this.sendStatus > 0) return
|
|
@@ -117,8 +135,7 @@ export default {
|
|
code: this.code,
|
|
code: this.code,
|
|
appId: this.formData.appId,
|
|
appId: this.formData.appId,
|
|
})
|
|
})
|
|
- this.$store.dispatch('user/login', res.data)
|
|
|
|
- this.$router.push(this.path)
|
|
|
|
|
|
+ this.loginSuccess(res)
|
|
} catch (error) {
|
|
} catch (error) {
|
|
// 未绑定微信号
|
|
// 未绑定微信号
|
|
if (error.code === -2) {
|
|
if (error.code === -2) {
|
|
@@ -127,9 +144,10 @@ export default {
|
|
this.formData.openId = error.data.openId
|
|
this.formData.openId = error.data.openId
|
|
this.formData.accessToken = error.data.accessToken
|
|
this.formData.accessToken = error.data.accessToken
|
|
} else {
|
|
} else {
|
|
|
|
+ this.$toast('登陆失败请重试')
|
|
// 其他错误跳转首页
|
|
// 其他错误跳转首页
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- this.$router.push(this.path)
|
|
|
|
|
|
+ this.$router.push(this.redirectPath)
|
|
}, 1000)
|
|
}, 1000)
|
|
}
|
|
}
|
|
}
|
|
}
|