Commit 21a85664 authored by 潘永坪's avatar 潘永坪

登录优化

parent 438d3a35
...@@ -45,15 +45,22 @@ export default { ...@@ -45,15 +45,22 @@ export default {
data.companyId=uni.getStorageSync('enterOptions').query.companyId||'' data.companyId=uni.getStorageSync('enterOptions').query.companyId||''
} }
this.$request('wechat/wx/getUserInfoByCode', data).then(res => { this.$request('wechat/wx/getUserInfoByCode', data).then(res => {
if (res.code == '00') { try{
let openid = res.data.openid if (res.code == '00') {
uni.setStorageSync('openid', openid) let openid = res.data.openid
let userId = res.data.userId || '' uni.setStorageSync('openid', openid)
this.login(openid,userId,source) let userId = res.data.userId || ''
} else { this.login(openid,userId,source)
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
}catch(e){
uni.showToast({ uni.showToast({
title: res.message, title: e,
icon: 'none' icon: 'none'
}) })
} }
}).catch(err => { }).catch(err => {
...@@ -75,37 +82,44 @@ export default { ...@@ -75,37 +82,44 @@ export default {
login(openid,userId,source){ login(openid,userId,source){
let datas = {openid,userId,source} let datas = {openid,userId,source}
this.$request('wechatUser/login/findWxUserAndLogin', datas).then(res => { this.$request('wechatUser/login/findWxUserAndLogin', datas).then(res => {
//通过openid获取token try{
if (res.code == '00') { //通过openid获取token
let token = res.data.token || '' if (res.code == '00') {
uni.setStorageSync('token', token) let token = res.data.token || ''
let createUserId = res.data.personId || '' uni.setStorageSync('token', token)
uni.setStorageSync('createUserId', createUserId) let createUserId = res.data.personId || ''
let userId = res.data.userId || '' uni.setStorageSync('createUserId', createUserId)
uni.setStorageSync('userId', userId) let userId = res.data.userId || ''
let enterOptions = uni.getStorageSync('enterOptions') uni.setStorageSync('userId', userId)
let queryTotal = '' let enterOptions = uni.getStorageSync('enterOptions')
for (let key in enterOptions.query) { let queryTotal = ''
queryTotal += '&' + key + '=' + enterOptions.query[key] for (let key in enterOptions.query) {
} queryTotal += '&' + key + '=' + enterOptions.query[key]
queryTotal = queryTotal.substr(1) }
if (token) { queryTotal = queryTotal.substr(1)
uni.reLaunch({ if (token) {
url: '/' + enterOptions.path + '?' + queryTotal uni.reLaunch({
}) url: '/' + enterOptions.path + '?' + queryTotal
//保存当前日期 })
let oldDate=this.$commonjs.today() //保存当前日期
uni.setStorageSync('oldDate', oldDate) let oldDate=this.$commonjs.today()
// uni.navigateBack({ uni.setStorageSync('oldDate', oldDate)
// delta:1 // uni.navigateBack({
// }) // delta:1
} // })
} else { }
uni.showToast({ } else {
title: res.message, uni.showToast({
icon: 'none' title: res.message,
}) icon: 'none'
} })
}
}catch(e){
uni.showToast({
title: e,
icon: 'none'
})
}
}).catch(err => { }).catch(err => {
uni.showToast({ uni.showToast({
title: '登录失败,请退出并重新登录', title: '登录失败,请退出并重新登录',
......
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