用户登录&退出 #1

Merged
luochao merged 1 commits from lc into caolc 2 years ago
  1. 25
      api/oil-identity.js
  2. 39
      pages/login/boforeLogin/boforeLogin.vue
  3. 60
      pages/login/posLogin/posLogin.vue
  4. 26
      pages/setup/setup.vue
  5. 24
      utils/request.js

@ -1,17 +1,24 @@
import request from '@/utils/request' import request from '@/utils/request'
const service_name ='oil-identity' const service_name ='xkhl-identity'
const group_name ='weChatCloudAuthorization' const group_name ='unionAuth'
const Customer_name = 'oilCustomerChannelRelation' const Customer_name = 'oilCustomerChannelRelation'
const WchatLogin_name ='weChatCloudAuthorization' const WchatLogin_name ='weChatCloudAuthorization'
export default{ export default{
// 新登录接口 手机密码登录 // 新登录接口 手机密码登录
loginByPhonePwd (data) { loginByPhonePwd (data) {
return request({ return request({
url: `/${service_name}/${group_name}/loginByPhonePwd`, url: `/${service_name}/${group_name}/loginPwd`,
method: 'post', method: 'post',
data:data data:data
}) })
}, },
// 新登录接口 手机密码登录
logout () {
return request({
url: `/${service_name}/${group_name}/logout`,
method: 'get',
})
},
// 获取用户信息 // 获取用户信息
sendCode(code){ sendCode(code){
return request({ return request({
@ -37,7 +44,7 @@ export default{
url: `/${service_name}/${group_name}/verifyCodeLogin`, url: `/${service_name}/${group_name}/verifyCodeLogin`,
method: 'post', method: 'post',
data:data, data:data,
}) })
}, },
//切换油站 //切换油站
@ -46,7 +53,7 @@ export default{
url: `/xkhl-identity/unionAuth/changeSiteLogin`, url: `/xkhl-identity/unionAuth/changeSiteLogin`,
method: 'post', method: 'post',
data:data, data:data,
}) })
}, },
//微信一键登录 new //微信一键登录 new
@ -55,7 +62,7 @@ export default{
url: `/xkhl-identity/unionAuth/loginPersonal`, url: `/xkhl-identity/unionAuth/loginPersonal`,
method: 'post', method: 'post',
data:data, data:data,
}) })
}, },
//首次登录绑定手机号 绑定微信手机号 new //首次登录绑定手机号 绑定微信手机号 new
@ -64,7 +71,7 @@ export default{
url: `/xkhl-identity/unionAuth/bindLoginByPhonePersonal`, url: `/xkhl-identity/unionAuth/bindLoginByPhonePersonal`,
method: 'post', method: 'post',
data:data, data:data,
}) })
}, },
//首次登录绑定手机号 当用户拒绝获取微信手机号时走此接口,判断用户是否存在,不存在提示注册,存在就发送验证码登录 new //首次登录绑定手机号 当用户拒绝获取微信手机号时走此接口,判断用户是否存在,不存在提示注册,存在就发送验证码登录 new
@ -73,7 +80,7 @@ export default{
url: `/${service_name}/${WchatLogin_name}/bindWeChatSendVerifyCode`, url: `/${service_name}/${WchatLogin_name}/bindWeChatSendVerifyCode`,
method: 'post', method: 'post',
data:data, data:data,
}) })
}, },
// 首次登录绑定手机号 当用户拒绝获取微信手机号时走此接kou 手机号存在账户时,调用此接口登录 个人通道 // 首次登录绑定手机号 当用户拒绝获取微信手机号时走此接kou 手机号存在账户时,调用此接口登录 个人通道
@ -82,7 +89,7 @@ export default{
url: `/${service_name}/${WchatLogin_name}/bindWeChatLoginByVerifyCodePersonal`, url: `/${service_name}/${WchatLogin_name}/bindWeChatLoginByVerifyCodePersonal`,
method: 'post', method: 'post',
data:data, data:data,
}) })
}, },
bindLoginByPhone (data) { bindLoginByPhone (data) {

@ -25,7 +25,7 @@
</view> </view>
</view> --> </view> -->
</view> </view>
</view> </view>
<view class="margin text-center"> <view class="margin text-center">
<button class="cu-btn round bg-main-oil lg text-lg" open-type="getPhoneNumber" <button class="cu-btn round bg-main-oil lg text-lg" open-type="getPhoneNumber"
@ -84,11 +84,11 @@
if (res.code === 20000) { if (res.code === 20000) {
this.sessionKey = res.data.sessionKey this.sessionKey = res.data.sessionKey
uni.setStorageSync('openid', res.data.openId) uni.setStorageSync('openid', res.data.openId)
uni.setStorageSync('unionid', res.data.unionId) uni.setStorageSync('unionid', res.data.unionId)
if(_that.outType !== '1'){ if(_that.outType !== '1'){
this.autoLogin() this.autoLogin()
return return
} }
} else if (res.code == 1002) { } else if (res.code == 1002) {
uni.showModal({ uni.showModal({
title: '微信登录失败提醒', title: '微信登录失败提醒',
@ -96,7 +96,7 @@
}) })
} else { } else {
// console.log('res', res.code) // console.log('res', res.code)
} }
}).catch(err => { }).catch(err => {
uni.reLaunch({ uni.reLaunch({
url: '/BagAuth/pages/login/boforeLogin/boforeLogin', url: '/BagAuth/pages/login/boforeLogin/boforeLogin',
@ -126,7 +126,7 @@
title: '您已拒绝授权手机号' title: '您已拒绝授权手机号'
}) })
} }
}, },
bindLoginByPhone(data, url) { // bindLoginByPhone(data, url) { //
if (this.count < 1) { if (this.count < 1) {
oilIdentityApi.bindLoginByPhonePersonal(data, url).then(res => { oilIdentityApi.bindLoginByPhonePersonal(data, url).then(res => {
@ -134,10 +134,10 @@
this.loginSuccess(res) this.loginSuccess(res)
} }
}) })
} }
}, },
loginSuccess(res) {// loginSuccess(res) {//
if (res.data.authTokenDTO.loginFlag) { if (res.data.authTokenDTO.loginFlag) {
this.setStored(res) this.setStored(res)
} }
}, },
@ -158,17 +158,22 @@
let data={ let data={
unionId:uni.getStorageSync('unionid'), unionId:uni.getStorageSync('unionid'),
openId:uni.getStorageSync('openid') openId:uni.getStorageSync('openid')
} }
console.log(data,'这里是自动登录data') console.log(data,'这里是自动登录data')
oilIdentityApi.loginPersonal(data).then(res => { // oilIdentityApi.loginPersonal(data).then(res => { //
console.log(res,'这里是自动登录res') console.log(res,'这里是自动登录res')
if (res.data.authTokenDTO.loginFlag == true) { if (res.data.authTokenDTO.loginFlag == true) {
this.setStored(res) this.setStored(res)
} }else {
uni.showToast({
icon: 'none',
title: res.data.msg
})
}
}) })
}, },
// //
setStored(res){ setStored(res){
let user = res.data.authTokenDTO.loginUser, let user = res.data.authTokenDTO.loginUser,
unionId = uni.getStorageSync('unionid'), unionId = uni.getStorageSync('unionid'),
openId = uni.getStorageSync('openid'), openId = uni.getStorageSync('openid'),
@ -182,7 +187,7 @@
} }
}) })
}, 1000); }, 1000);
uni.setStorageSync('user', user) uni.setStorageSync('user', user)
uni.setStorage({ uni.setStorage({
key: 'Authorization', key: 'Authorization',
data: res.data.authTokenDTO.accessToken, data: res.data.authTokenDTO.accessToken,
@ -229,20 +234,20 @@
console.log(err) console.log(err)
} }
}) })
} else { } else {
uni.showToast({ uni.showToast({
title: '未绑定油站请联系客服', title: '未绑定油站请联系客服',
icon: 'none', icon: 'none',
duration: 1500 duration: 1500
}) })
} }
}) })
}, },
nextStep() { nextStep() {
if (this.oilSiteNo) { if (this.oilSiteNo) {
cloudSiteApi.verifyOilSite({ cloudSiteApi.verifyOilSite({
oilSiteCode: this.oilSiteNo oilSiteCode: this.oilSiteNo
}).then(res => { }).then(res => {
if (res.code === 20000) { if (res.code === 20000) {
//--------------------------------- //---------------------------------
// address: "" // address: ""
@ -320,7 +325,7 @@
this.toMain(nickName); this.toMain(nickName);
}, },
toMain(userName) { toMain(userName) {
// this.login(userName) // this.login(userName)
/** /**
* 强制登录时使用reLaunch方式跳转过来 * 强制登录时使用reLaunch方式跳转过来
* 返回首页也使用reLaunch方式 * 返回首页也使用reLaunch方式

@ -13,7 +13,7 @@
<view class="bg-white margin padding radius shadow-warp"> <view class="bg-white margin padding radius shadow-warp">
<view class="cu-form-group"> <view class="cu-form-group">
<view class="title mini-label text-black">手机号</view> <view class="title mini-label text-black">手机号</view>
<input type="number" v-model="auth.phone" placeholder="请输入手机号" name="input" @blur="bulrInput" /> <input type="number" v-model="auth.phone" placeholder="请输入手机号" name="input" />
</view> </view>
<view class="cu-form-group padding-top-sm" v-if="showRandom"> <view class="cu-form-group padding-top-sm" v-if="showRandom">
<view class="title text-black mini-label">验证码</view> <view class="title text-black mini-label">验证码</view>
@ -75,11 +75,11 @@
</view> </view>
</view> </view>
<view class="cu-modal" :class="checkList"> <view class="cu-modal" :class="checkList">
<view class="cu-dialog"> <view class="cu-dialog">
<view class="cu-bar bg-red justify-end"> <view class="cu-bar bg-red justify-end">
<view class="content " > <view class="content " >
{{ titleText }} {{ titleText }}
</view> </view>
<view class="action" @tap="hidecheckList"> <view class="action" @tap="hidecheckList">
<text class="cuIcon-close text-white"></text> <text class="cuIcon-close text-white"></text>
</view> </view>
@ -130,7 +130,7 @@
frozen: false, // frozen: false, //
oliList:[ oliList:[
{ {
} }
] ]
} }
@ -146,7 +146,7 @@
icon:'none' icon:'none'
}) })
console.log('-------------') console.log('-------------')
return return
}else{ }else{
console.log(this.auth.phone) console.log(this.auth.phone)
console.log('+++++++++++++') console.log('+++++++++++++')
@ -155,15 +155,15 @@
uni.setStorageSync('oliList',res.data) uni.setStorageSync('oliList',res.data)
this.oliList = res.data this.oliList = res.data
this.checkUser = true this.checkUser = true
// this.checkList = 'show' // this.checkList = 'show'
this.titleText = '油站时间' this.titleText = '油站时间'
}else{ }else{
let _that= this let _that= this
_that.auth.phone = '' _that.auth.phone = ''
//console.log(this.auth.phone) //console.log(this.auth.phone)
this.errMsg =res.msg this.errMsg =res.msg
this.checkUser = false this.checkUser = false
this.checkList = 'show' this.checkList = 'show'
this.titleText = '提示' this.titleText = '提示'
} }
}) })
@ -179,35 +179,35 @@
} }
}) })
if(this.checkType == 0 ){ if(this.checkType == 0 ){
}else{ }else{
} }
}, },
checkOli(n){ checkOli(n){
// if(!this.checkUser){ // if(!this.checkUser){
// this.checkList = 'show' // this.checkList = 'show'
// return // return
// } // }
this.checkType = n this.checkType = n
if(n == 0 ){ if(n == 0 ){
this.loginRandom( ) this.loginRandom( )
//console.log('') //console.log('')
}else{ }else{
if(!this.auth.phone){ if(!this.auth.phone){
uni.showToast({ uni.showToast({
title:'请输入手机号', title:'请输入手机号',
icon:"none" icon:"none"
}) })
return return
} }
if(!this.auth.password){ if(!this.auth.password){
uni.showToast({ uni.showToast({
title:'请输入密码', title:'请输入密码',
icon:"none" icon:"none"
}) })
return return
} }
this.loginPwd( ) this.loginPwd( )
} }
}, },
@ -221,7 +221,7 @@
}, },
// //
getByPhone(){ getByPhone(){
}, },
navToQr() { navToQr() {
uni.setClipboardData({ uni.setClipboardData({
@ -317,8 +317,8 @@
// //console.log(err) // //console.log(err)
// } // }
// }); // });
// }, // },
loginPwd(channelId) { loginPwd(channelId) {
uni.login({ uni.login({
provider: 'weixin', provider: 'weixin',
success: loginRes => { success: loginRes => {
@ -335,7 +335,7 @@
code: code, code: code,
unionId:res.data.unionId, unionId:res.data.unionId,
openId:res.data.openId openId:res.data.openId
} }
uni.setStorage({ uni.setStorage({
key: 'device', key: 'device',
data: res.data.openId, data: res.data.openId,
@ -360,7 +360,7 @@
}) })
//console.log('oilSiteCode', this.oilSiteNo) //console.log('oilSiteCode', this.oilSiteNo)
if (res.code === 20000) { if (res.code === 20000) {
uni.reLaunch({ uni.reLaunch({
url: '/pages/index/index', url: '/pages/index/index',
fail: (err) => { fail: (err) => {
@ -379,7 +379,7 @@
//console.log('Authorization', res.data.authTokenDTO.accessToken) //console.log('Authorization', res.data.authTokenDTO.accessToken)
} }
}) })
uni.setStorageSync('userMenu', res.data.authTokenDTO.loginUser.roleMenus) uni.setStorageSync('userMenu', res.data.authTokenDTO.loginUser.roleMenus)
//console.log( 'userMenu',res.data.authTokenDTO.loginUser.roleMenus) //console.log( 'userMenu',res.data.authTokenDTO.loginUser.roleMenus)
uni.setStorageSync('loginUser', { uni.setStorageSync('loginUser', {
@ -403,7 +403,7 @@
const code = loginRes.code const code = loginRes.code
//console.log(code) //console.log(code)
oilIdentityApi.sendCode(code).then((res)=>{ oilIdentityApi.sendCode(code).then((res)=>{
oilIdentityApi.loginPersonal().then(res => { oilIdentityApi.loginPersonal().then(res => {
if (res.code === 20000) { if (res.code === 20000) {
uni.reLaunch({ uni.reLaunch({
@ -456,7 +456,7 @@
}) })
}) })
}, },
fail: err => { fail: err => {
//console.log(err) //console.log(err)
@ -532,7 +532,7 @@
unionId:res.data.unionId, //code unionId:res.data.unionId, //code
channelId:channelId, //channelId channelId:channelId, //channelId
verifyCodeToken: this.auth.verifyCodeToken ,// verifyCodeToken: this.auth.verifyCodeToken ,//
openId:res.data.openId openId:res.data.openId
} }
//console.log('device') //console.log('device')
//console.log(res.data.openId) //console.log(res.data.openId)
@ -579,7 +579,7 @@
//console.log('Authorization', res.data.authTokenDTO.accessToken) //console.log('Authorization', res.data.authTokenDTO.accessToken)
} }
}) })
uni.setStorageSync('userMenu', res.data.authTokenDTO.loginUser.roleMenus) uni.setStorageSync('userMenu', res.data.authTokenDTO.loginUser.roleMenus)
uni.setStorageSync('loginUser', { uni.setStorageSync('loginUser', {
id: res.data.authTokenDTO.loginUser.id, id: res.data.authTokenDTO.loginUser.id,
@ -589,8 +589,8 @@
} }
}) })
}) })
}, },
fail: err => { fail: err => {
//console.log(err) //console.log(err)
@ -658,7 +658,7 @@
} }
.page-content { .page-content {
min-height: 100%; min-height: 100%;
position: relative; position: relative;
} }
.logo { .logo {

@ -76,6 +76,7 @@
<script> <script>
import cloudSiteApi from '@/api/cloud-site.js' import cloudSiteApi from '@/api/cloud-site.js'
import oilIdentityApi from "@/api/oil-identity";
export default { export default {
data() { data() {
return { return {
@ -98,13 +99,22 @@
} }
}) })
}, },
async loginOut() { loginOut() {
// await cloudSiteApi.logout(); oilIdentityApi.logout().then(res => {
uni.clearStorage() if (res.code===20000){
uni.reLaunch({ uni.showToast({
url: '/pages/login/boforeLogin/boforeLogin?type=1' // title: '退出登录成功',
}) icon: 'success',
duration: 2000
});
setTimeout(()=>{
uni.clearStorage()
uni.reLaunch({
url: '/pages/login/boforeLogin/boforeLogin?type=1'
})
},2000)
}
})
}, },
getInfo() { getInfo() {
this.userInfo = uni.getStorageSync('loginUser') this.userInfo = uni.getStorageSync('loginUser')
@ -179,4 +189,4 @@
.bg-img .cu-list.menu>.cu-item::after { .bg-img .cu-list.menu>.cu-item::after {
border-bottom: 0; border-bottom: 0;
} }
</style> </style>

@ -5,17 +5,17 @@ import utils from '@/utils/encode'
// const env = 'test'// 仅用于测试、 // const env = 'test'// 仅用于测试、
// const env = 'production' // const env = 'production'
//42 洛超 /29 孙志华 /40 阿浩 //42 洛超 /29 孙志华 /40 阿浩
// 测试日日顺时需要连阿浩 // 测试日日顺时需要连阿浩
const testUrl = 'http://192.168.26:38080' const testUrl = 'http://192.168.26:38080'
// const productionUrl = 'https://www.51xingka.net/oilApp' // 生产,加密 old // const productionUrl = 'https://www.51xingka.net/oilApp' // 生产,加密 old
// const productionUrl = 'https://www.xingoil.com/adminapi' // 生产,加密 new // const productionUrl = 'https://www.xingoil.com/adminapi' // 生产,加密 new
// const productionUrl = 'https://www.xingoil.com/adminapi' // 生产,加密 new // const productionUrl = 'https://www.xingoil.com/adminapi' // 生产,加密 new
const productionUrl = 'http://uat.xingoil.com/adminapi' const productionUrl = 'http://uat.xingoil.com/adminapi'
// const env = process.env.NODE_ENV // 环境 // const env = process.env.NODE_ENV // 环境
const service = axios.create({ const service = axios.create({
baseURL: env=='production'?productionUrl:testUrl, // baseURL: env=='production'?productionUrl:testUrl, //
// baseURL: testUrl, // // baseURL: testUrl, //
timeout: 5000 timeout: 5000
}) })
@ -33,13 +33,13 @@ service.interceptors.request.use(
title: '加载中...', title: '加载中...',
mask:true mask:true
}) })
// } // }
const token = uni.getStorageSync('Authorization') const token = uni.getStorageSync('Authorization')
const openid = uni.getStorageSync('device') const openid = uni.getStorageSync('device')
const openId = uni.getStorageSync('openid') const openId = uni.getStorageSync('openid')
const unionId = uni.getStorageSync('unionid') const unionId = uni.getStorageSync('unionid')
const accountSources = 'LOGIN_MP_WECHAT' const accountSources = 'LOGIN_MP_WECHAT'
// console.log(unionId) // console.log(unionId)
// 原本为 openid // 原本为 openid
config.headers['Authorization'] = token config.headers['Authorization'] = token
@ -89,7 +89,7 @@ service.interceptors.response.use(
const res = response.data const res = response.data
// const env = process.env.NODE_ENV // const env = process.env.NODE_ENV
// const env = 'production' // 测试中的生茶 // const env = 'production' // 测试中的生茶
if (env === 'production') { if (env === 'production') {
// 生产环境,进行加密解密,不输出日志 // 生产环境,进行加密解密,不输出日志
if (res.encrypt == 1) { if (res.encrypt == 1) {
@ -117,7 +117,7 @@ service.interceptors.response.use(
title: res.msg, title: res.msg,
icon: "none" icon: "none"
}) })
} }
if (res.msg === '登录已过期!') { if (res.msg === '登录已过期!') {
outTimer = setTimeout(() => { outTimer = setTimeout(() => {
uni.showModal({ uni.showModal({
@ -181,7 +181,7 @@ service.interceptors.response.use(
} }
}) })
} }
if (res.code != 20000 && res.msg != '令牌为空,不允许操作' && res.code != 42077 && res.code != 42011 &&res.msg != '您的ip已经更改,请重新登录' && res.msg != '登录与操作设备不同') { if (res.code != 20000 && res.msg != '令牌为空,不允许操作' && res.code != 42077 && res.code != 42011 &&res.msg != '您的ip已经更改,请重新登录' && res.msg != '登录与操作设备不同') {
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
@ -196,7 +196,7 @@ service.interceptors.response.use(
// console.log(err) // console.log(err)
// } // }
// }) // })
} }
} }
return res return res
}, },
@ -212,7 +212,7 @@ service.interceptors.response.use(
}) })
} else { } else {
uni.showToast({ uni.showToast({
title: '请求失败!', title: res.msg?res.msg:'请求失败!',
icon: "none" icon: "none"
}) })
} }

Loading…
Cancel
Save