Browse Source

feat: 登录

master
zeb 4 years ago
parent
commit
b755a6369e
  1. 84
      app.js
  2. 3
      app.json
  3. 54
      pages/auth/auth.js

84
app.js

@ -6,30 +6,30 @@ App({
let token = wx.getStorageSync('access_token')
let userInfo = wx.getStorageSync('userInfo')
if(token&&userInfo)return;
wx.login({
success (res) {
if (res.code) {
//发起网络请求
$api.getUserAuth(res.code).then(data=>{
if(data.access_token){
wx.setStorage({
key:"access_token",
data:data.access_token
})
that.queryUsreInfo();
}else if(data.code==2){
that.registerBind(res.code)
}else{
// wx.login({
// success (res) {
// if (res.code) {
// //发起网络请求
// $api.getUserAuth(res.code).then(data=>{
// if(data.access_token){
// wx.setStorage({
// key:"access_token",
// data:data.access_token
// })
// that.queryUsreInfo();
// }else if(data.code==2){
// that.registerBind(res.code)
// }else{
}
}).catch(err=>{
console.log('err',err)
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
// }
// }).catch(err=>{
// console.log('err',err)
// })
// } else {
// console.log('登录失败!' + res.errMsg)
// }
// }
// })
@ -66,25 +66,25 @@ App({
})
}
},
registerBind(code){
let that = this;
let params = {
state:'MINI',
code,
phone:'15198094357',
phoneCode:'',
nickName:'',
avatar:'',
legalName:''
};
$api.registerBind(params).then(data=>{
wx.setStorage({
key:"access_token",
data:data.access_token
})
that.queryUsreInfo();
})
},
// registerBind(code){
// let that = this;
// let params = {
// state:'MINI',
// code,
// phone:'15198094357',
// phoneCode:'',
// nickName:'',
// avatar:'',
// legalName:''
// };
// $api.registerBind(params).then(data=>{
// wx.setStorage({
// key:"access_token",
// data:data.access_token
// })
// that.queryUsreInfo();
// })
// },
queryUsreInfo(){
$api.getUserInfo().then(res=>{
if(res.code===0){

3
app.json

@ -1,5 +1,6 @@
{
"pages": [
"pages/auth/auth",
"pages/index/index",
"pages/calendar/calendar",
"pages/look/look",
@ -10,7 +11,7 @@
"pages/look-detail/look-detail",
"pages/history/history",
"pages/air-report/air-report",
"pages/auth/auth",
"pages/feasibility-study/feasibility-study",
"pages/periodic-report/periodic-report",
"pages/special-research/special-research",

54
pages/auth/auth.js

@ -41,13 +41,7 @@ Page({
success: (eve) => {
console.log(eve)
att = eve;
}
})
wx.getUserProfile({
desc: '用户展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (resT) => {
console.log(resT)
$api.Login('POST', 'social/token', { code: 'MINI@' + att.code }).then(res => {
$api.Login('POST', 'social/token?' + 'code=MINI@' + eve.code).then(res => {
console.log(res);
if(res.code == 2){
wx.showToast({
@ -58,21 +52,35 @@ Page({
})
that.setData({
code:att.code,
user:resT.userInfo,
is_login:false,
})
} else {
wx.setStorage({
'access_token': res.access_token
})
wx.switchTab({
url:'/pages/index/index'
})
}
})
},
fail: (res) => {
wx.showToast({
title: '授权失败,请重试。',
icon: 'none',
mask: true,
duration: 1500,
})
}
})
// wx.getUserProfile({
// desc: '用户展示用户信息',
// success: (resT) => {
// console.log(resT)
// },
// fail: (res) => {
// wx.showToast({
// title: '授权失败,请重试。',
// icon: 'none',
// mask: true,
// duration: 1500,
// })
// }
// })
},
// 一键注册 获取手机号
getphonenumberFun(e){
@ -91,14 +99,24 @@ Page({
}
console.log(e)
console.log(user)
$api.AJAX('POST', 'social/register-bind', {
state:'MINI',
phone:'15608615712',
encryptedData:e.detail.encryptedData,
iv: e.detail.iv,
code: code,
nickName:user.nickName,
avatar:user.avatarUrl,
}, false).then(res => {
if(res.code == 1) {
wx.showToast({
title: res.msg,
icon: 'none',
mask: true,
duration: 1500,
})
return
}
wx.showToast({
title: '注册成功',
icon: 'none',

Loading…
Cancel
Save