Browse Source

一键登录

master
unknown 11 months ago
parent
commit
e872137c76
  1. 8
      components/searchRow/searchRow.vue
  2. 5
      config/api.js
  3. 32
      pages/indexEntry/enroll/enroll.vue
  4. 47
      pages/indexEntry/enroll/registInfo/registInfo.vue
  5. 8
      pages/mineEntry/personaInfo/personaInfo.vue
  6. 82
      pages/userCenter/login/login.vue
  7. 28
      store/modules/user.js

8
components/searchRow/searchRow.vue

@ -4,11 +4,9 @@
<view class="searchIcon">
<image src="@/static/images/index/searchIcon.png" mode=""></image>
</view>
<view class="inputBox" v-if="disable">
<view class="textColor">{{ placeholder }}</view>
</view>
<view class="inputBox" v-else>
<u-search :placeholder="placeholder" v-model="keyword" :color="'#fff'" placeholderColor="#fff" :bgColor="'transparent'" :showAction="false" @search="$u.debounce(searchFn, 500)" @clear="clearSearchFn"></u-search>
<view class="inputBox">
<u-search :placeholder="placeholder" v-model="keyword" :color="'#fff'" :disabled="disable" placeholderColor="#fff" :bgColor="'transparent'" @change="$u.debounce(searchFn, 2000)" :showAction="false" @search="$u.debounce(searchFn, 500)" @clear="clearSearchFn"></u-search>
</view>
</view>
</view>

5
config/api.js

@ -2,8 +2,8 @@
var http = uni.$u.http
// 隐私政策
// export const getAgreement = (params, config = {}) => http.post('/util/manage/getAgreement.do', params, config)
// 微信小程序的一键登录
export const weixinLogin = (data) => http.post('member/auth/weixin-mini-app-login', data)
// 验证码登录
export const loginSMS = (data) => http.post('member/auth/sms-login', data, { custom: { noToken: true }})
// 登录发验证码
@ -198,3 +198,4 @@ export const getDriveProcessDetails = (params={}) => http.get('app/student-recor

32
pages/indexEntry/enroll/enroll.vue

@ -45,9 +45,10 @@
<view class="row">
<view class="lab">性别</view>
<view class="rightCon">
<u-radio-group v-model="form.sex">
<u-radio shape="circle" label="男" name="1"></u-radio>
<u-radio shape="circle" label="女" name="2" style="margin-left: 54rpx;"></u-radio>
<u-radio-group v-model="form.sex" :labelDisabled="false">
<u-radio shape="circle" label="男" name="1" :labelDisabled="false"></u-radio>
<view class="" style="width: 50rpx;"></view>
<u-radio shape="circle" label="女" name="2" :labelDisabled="false"></u-radio>
</u-radio-group>
</view>
</view>
@ -169,10 +170,24 @@
// bizToken: 'C9C2BC8E-8336-4071-84B3-8170E283E6CA',
// userId: this.userId
// }
const {data: res} = await GetDetectInfoEnhanced({EidToken, userId: this.userId, InfoType: 1})
let obj2 = JSON.parse(res)
const res = await GetDetectInfoEnhanced({EidToken, userId: this.userId, InfoType: 1})
if(res.code!=0) return
let obj = JSON.parse(res.data).Text
if(obj.Comparemsg!=='成功') return
let userInfo = {
address: obj.OcrAddress,
name: obj.OcrName,
idcard: obj.OcrIdCard,
sex: obj.OcrGender=='女'?2:1,
applyStep: 2
}
let info = Object.assign(this.$store.state.user.vuex_userInfo, userInfo)
this.$store.commit('update_vuex_userInfo', info)
console.log('请求结果来了')
console.log(obj2)
console.log(userInfo)
console.log(this.$store.state.user.vuex_userInfo)
uni.hideLoading()
this.$goPage('/pages/indexEntry/enroll/registInfo/registInfo')
// uni.setStorageSync(obj2)
},
async goNext() {
@ -198,7 +213,7 @@
return this.$goPage('/pages/indexEntry/enroll/payment/payment')
}
//
if(this.form.value!==1) {
if(this.form.value!=1) {
for(let key in this.formToast) {
if(!this.form[key]) {
return this.$u.toast(this.formToast[key])
@ -234,6 +249,9 @@
const { token, verifyDone } = res;
console.log('收到核身完成的res:', res);
console.log('核身的token是:', token);
uni.showLoading({
title: '正在加载,请稍后……'
})
_this.GetDetectInfoEnhancedFn(token)
console.log('是否完成核身:', verifyDone);
},

47
pages/indexEntry/enroll/registInfo/registInfo.vue

@ -32,7 +32,7 @@
<view class="rightCon">
<view class="row" @click="showCarClick">
<view class="val">
<mySelect :value="form.car"/>
<mySelect :value="form.trainType"/>
</view>
<view class="arrow">
<u-icon name="arrow-right" size="14" color="#686B73" style="margin-left: 12rpx;" ></u-icon>
@ -274,7 +274,7 @@
import comfigPopup from './comp/comfigPopup'
import searchSchool from './comp/searchSchool'
import oldDrive from './comp/oldDrive'
import { areaTree, applyOnline, schoolClass, } from '@/config/api.js'
import { areaTree, applyOnline, schoolClass, getSchoolDetail } from '@/config/api.js'
export default {
components: { comfigPopup, searchSchool, oldDrive },
data() {
@ -336,6 +336,7 @@
}
this.initUserInfo()
//
uni.$on('upDateCoachItem',(item)=>{
console.log(item)
this.form.coach = item.name
@ -343,27 +344,28 @@
})
this.areaTreeFn()
//
let schoolClass = this.$store.state.school.schoolClass
console.log(schoolClass)
if(schoolClass.id) {
console.log(schoolClass)
this.form.classModel = schoolClass.name
this.form.school = schoolClass.schoolName
this.form.schoolId = schoolClass.schoolId
this.form.car = schoolClass.carType
this.form.trainType = schoolClass.carType
this.form.schoolClassId = schoolClass.id
}
// /
let schoolCoach = this.$store.state.school.schoolCoach
console.log('schoolCoach')
console.log(schoolCoach)
if(schoolCoach.id) {
console.log('schoolCoach')
console.log(schoolCoach)
this.form.coach = schoolCoach.name
this.form.coachId = schoolCoach.id
this.form.school = schoolCoach.schoolName
this.form.schoolId = schoolCoach.schoolId
// this.form.car = schoolClass.carType
}
if(this.form.schoolId) {
this.schoolClassFn()
this.getSchoolDetailFn()
}
},
onPullDownRefresh() {
@ -372,9 +374,10 @@
methods: {
async initUserInfo() {
//
if(!this.realNameNo) {
await this.$store.dispatch('getUserInfo')
}
// if(!this.realNameNo) {
// await this.$store.dispatch('getUserInfo')
// }
console.log(this.vuex_userInfo)
this.form.userId = this.userId
this.form.accountId = this.vuex_userInfo.accountId
this.form.address = this.vuex_userInfo.address
@ -384,6 +387,7 @@
this.form.nationality = this.vuex_userInfo.nationality || '中国'
this.form.cardType = this.vuex_userInfo.cardType || '1'
},
//
async schoolClassFn() {
const {data: res} = await schoolClass({pageNo: 1,pageSize: 100, schoolId: this.form.schoolId})
this.columnsClassModel = [res.list]
@ -466,17 +470,6 @@
})
})
})
// for(let i=0; i<res.length; i++) {
// let obj = {
// id: res[i].id,
// name: res[i].name
// }
// this.cityArr.push(obj)
// console.log(this.cityArr)
// console.log(this.cityArr2)
console.log(this.cityArr3)
// this.showCity = res
},
traverse(arr, result=[]) {
for (var i = 0; i < arr.length; i++) {
@ -516,7 +509,6 @@
let item = val.value[0]
console.log(item)
this.showCar = false
this.form.car = item
this.form.trainType = item
},
showCarClick() {
@ -570,6 +562,13 @@
}
});
},
async getSchoolDetailFn() {
const {data: res} = await getSchoolDetail({id: this.form.schoolId})
this.columnsCar = [res.businessScope.split(',')]
console.log('驾校id')
console.log(res.id)
this.schoolClassFn()
},
changeVal(val) {
console.log(val)
},

8
pages/mineEntry/personaInfo/personaInfo.vue

@ -9,18 +9,18 @@
</view>
</view>
<view class="card">
<view class="card" v-if="vuex_userInfo.schoolName">
<view class="row border">
<view class="lab">我的驾校</view>
<view class="val">{{ vuex_userInfo.schoolName }}</view>
<view class="val">{{ vuex_userInfo.schoolName||'' }}</view>
</view>
<view class="row border">
<view class="lab">我的教练</view>
<view class="val">{{ vuex_userInfo.coachName }}</view>
<view class="val">{{ vuex_userInfo.coachName||'' }}</view>
</view>
<view class="row border">
<view class="lab">所学车型</view>
<view class="val">{{ vuex_userInfo.trainType }}</view>
<view class="val">{{ vuex_userInfo.trainType||'' }}</view>
</view>
<view class="row">
<view class="lab">报名时间</view>

82
pages/userCenter/login/login.vue

@ -4,9 +4,7 @@
<image src="../../../static/images/userCenter/loginTitle.png" mode=""></image>
</view>
<view class="btnCon">
<!-- <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机号</button> -->
<view class="btn" @click="loginFn">手机号快捷登录</view>
<!-- <button type="success" size="mini" style="margin-top: 15rpx;" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" text="获取手机号">获取手机号</button> -->
<view class="btn" @click="getPhoneNumber">手机号快捷登录 <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="hide">手机号</button></view>
<view class="btn border" @click="$goPage('/pages/userCenter/login/loginByPhone');">手机号登录/注册</view>
</view>
<view style="margin-top: 40rpx;">
@ -28,6 +26,7 @@
<script>
import { imgUrl } from '@/config/site.config'
import privacyRadion from './comp/privacyRadion.vue'
import { weixinLogin } from '@/config/api.js'
export default {
components: {privacyRadion},
data() {
@ -51,28 +50,51 @@
// });
},
methods: {
getPhoneNumber (e) {
console.log(e.detail.code) //
async getPhoneNumber (e) {
if(!this.isCheck) return this.$u.toast('请勾选产品协议与隐私政策');
let phoneCode = e.detail.code
console.log(e.detail.errMsg) //
console.log(e.detail.errno) //
console.log(e.detail) //
const loginCode = await this.loginFn()
if(!loginCode||!phoneCode) return
console.log('登录验证码')
console.log(loginCode)
let obj = {
phoneCode,
loginCode
}
const {data: res} = await weixinLogin(obj)
this.$store.commit('update_vuex_loginInfo',res)
this.$store.dispatch('getUserInfo')
// this.$goPage('/pages/userCenter/login/face')
uni.switchTab({
url: '/pages/tabbar/index/index'
})
},
loginFn() {
//
uni.login({
provider: 'weixin',
success: loginRes => {
if (loginRes.code) {
//
this.getUserInfo(loginRes.code);
} else {
console.error('微信登录失败');
}
},
fail: err => {
console.error('微信登录失败', err);
}
});
return new Promise((resolve,reject)=>{
uni.login({
provider: 'weixin',
success: loginRes => {
if (loginRes.code) {
//
console.log('loginRes.code')
console.log(loginRes.code)
resolve(loginRes.code)
// this.getUserInfo(loginRes.code);
} else {
console.error('微信登录失败');
}
},
fail: err => {
reject(null)
console.error('微信登录失败', err);
}
});
})
},
getUserInfo(code) {
//
@ -105,16 +127,7 @@
}
});
},
//
// async getPhoneNumber(e) {
// await this.getCode();
// console.log('')
// console.log(e)
// if(!this.decodePhoneParams.code || !e.detail.encryptedData){
// return false;
// }
// },
//
changeRadio(val) {
this.isCheck = val
@ -171,6 +184,17 @@
text-align: center;
line-height: 72rpx;
font-size: 28rpx;
position: relative;
overflow: hidden;
.hide {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: inline-block;
opacity: 0;
}
&.border {
background: rgba(25,137,250,0.1);
border: 2rpx solid #1989FA;

28
store/modules/user.js

@ -1,6 +1,9 @@
import qqmapWx from '../../common/sdk/qqmap-wx-jssdk.min.js'; // 引入
import { httpPrefix } from '../../config/site.config.js';
let apiOk =true
let refreshTokenFn = null
const user = {
state: {
@ -31,7 +34,7 @@ const user = {
state.vuex_loginInfo = {}
state.vuex_userInfo = {}
uni.navigateTo({
url: '/pages/userCenter/login/loginByPhone'
url: '/pages/userCenter/login/login'
})
},
@ -98,27 +101,28 @@ const user = {
commit('update_vuex_userInfo',res.data)
},
// 刷新token
async refreshToken({state, commit}) {
return new Promise(async(resolve, reject)=>{
if(!state.apiOk&&state.refreshTokenFn) {
return state.refreshTokenFn
if(!apiOk&&refreshTokenFn) {
return refreshTokenFn
}
commit('update_apiOk',false)
state.refreshTokenFn = null
apiOk = false
refreshTokenFn = null
const http = uni.$u.http
let config = { header: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, custom: { noToken: true } }
let refreshToken = state.vuex_loginInfo.refreshToken
state.refreshTokenFn = await http.post('member/auth/refresh-token',{refreshToken}, config)
if(state.refreshTokenFn.data||state.refreshTokenFn.data.accessToken) {
commit('update_apiOk',true)
commit('update_vuex_loginInfo',state.refreshTokenFn.data)
refreshTokenFn = await http.post('member/auth/refresh-token',{refreshToken}, config)
if( refreshTokenFn.data|| refreshTokenFn.data.accessToken) {
apiOk = true
commit('update_vuex_loginInfo', refreshTokenFn.data)
uni.$u.http.setConfig((config) => {
config.header.Authorization = 'Bearer ' + state.refreshTokenFn.data.accessToken
config.header.Authorization = 'Bearer ' + refreshTokenFn.data.accessToken
return config
})
resolve(state.refreshTokenFn)
resolve(refreshTokenFn)
}else {
commit('update_apiOk',true)
apiOk = true
commit('goLogin')
reject('刷新token失败了')
}

Loading…
Cancel
Save