Commit 6b03bbe2 authored by 潘永坪's avatar 潘永坪

登录和支付优化

parent a2db5f84
<template>
<view>
</view>
<view> </view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
},
onLoad(){
let _this=this
uni.getProvider({
service: 'oauth',
success(proRes){
uni.login({
provider:proRes.provider[0],
success: function (res) {
if(res.code){
let source=''
if(proRes.provider[0]=='weixin'){
source=3
}else if(proRes.provider[0]=='alipay'){
source=4
}
let data={
code:res.code,
source,//微信小程序3,支付宝小程序4
}
_this.$request('wechat/wx/getUserInfoByCode',data).then(res => {
if(res.code=='00'){
let openid=res.data.openid
uni.setStorageSync('openid',openid)
let userId=res.data.userId||''
let datas={openid,source,userId}
_this.$request('wechatUser/login/findWxUserAndLogin',datas).then((res)=>{//通过openid获取token
if(res.code=='00'){
let token=res.data.token||''
uni.setStorageSync('token',token)
let createUserId=res.data.personId||''
uni.setStorageSync('createUserId',createUserId)
let userId=res.data.userId||''
uni.setStorageSync('userId',userId)
let enterOptions=uni.getStorageSync('enterOptions')
let queryTotal=''
for(let key in enterOptions.query){
queryTotal+='&'+key+'='+enterOptions.query[key]
}
queryTotal=queryTotal.substr(1)
if(token){
uni.redirectTo({
url:'/'+enterOptions.path+'?'+queryTotal
})
// uni.navigateBack({
// delta:1
// })
}
}else{
uni.showToast({
title:res.message+'请退出并重新登录',
icon:'none'
})
}
}).catch((err)=>{
uni.showToast({
title:'登录失败,请退出并重新登录',
icon:'none'
})
})
}else{
uni.showToast({
title:res.message='请退出并重新登录',
icon:'none'
})
}
}).catch((err)=>{
uni.showToast({
title:'登录失败,请退出并重新登录',
icon:'none'
})
})
}
}
})
}
})
},
}
</script>
export default {
data() {
return {}
},
onLoad() {
this.login()
},
methods:{
//---登录
login(){
let _this = this
uni.getProvider({
service: 'oauth',
success(proRes) {
uni.login({
provider: proRes.provider[0],
success: function(res) {
if (res.code) {
let source = ''
if (proRes.provider[0] == 'weixin') {
source = 3
} else if (proRes.provider[0] == 'alipay') {
source = 4
}
let data = {
code: res.code,
source //微信小程序3,支付宝小程序4
}
_this.$request('wechat/wx/getUserInfoByCode', data).then(res => {
if (res.code == '00') {
let openid = res.data.openid
uni.setStorageSync('openid', openid)
let userId = res.data.userId || ''
let datas = { openid, source, userId }
_this.$request('wechatUser/login/findWxUserAndLogin', datas).then(res => {
//通过openid获取token
if (res.code == '00') {
let token = res.data.token || ''
uni.setStorageSync('token', token)
let createUserId = res.data.personId || ''
uni.setStorageSync('createUserId', createUserId)
let userId = res.data.userId || ''
uni.setStorageSync('userId', userId)
let enterOptions = uni.getStorageSync('enterOptions')
let queryTotal = ''
for (let key in enterOptions.query) {
queryTotal += '&' + key + '=' + enterOptions.query[key]
}
queryTotal = queryTotal.substr(1)
if (token) {
uni.redirectTo({
url: '/' + enterOptions.path + '?' + queryTotal
})
// uni.navigateBack({
// delta:1
// })
}
} else {
uni.showToast({
title: res.message + '请退出并重新登录',
icon: 'none'
})
}
})
.catch(err => {
uni.showToast({
title: '登录失败,请退出并重新登录',
icon: 'none'
})
let timer = setTimeout(() => {
_this.login()
}, 2000)
this.$once('hook:beforeDestroy', () => {
clearTimeout(timer)
})
})
} else {
uni.showToast({
title: res.message + '请退出并重新登录',
icon: 'none'
})
}
})
.catch(err => {
uni.showToast({
title: '登录失败,请退出并重新登录',
icon: 'none'
})
let timer = setTimeout(() => {
_this.login()
}, 2000)
this.$once('hook:beforeDestroy', () => {
clearTimeout(timer)
})
})
}
}
})
}
})
}
}
}
<style>
</script>
</style>
<style></style>
......@@ -160,9 +160,12 @@ export default {
title: '登录失败',
icon: 'none'
})
setTimeout(() => {
let timer=setTimeout(()=>{
_this.login()
}, 2000)
},2000)
this.$once('hook:beforeDestroy', () => {
clearTimeout(timer)
})
})
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment