|
|
|
@ -6,7 +6,7 @@ |
|
|
|
</view> |
|
|
|
<view class="fixed-btn"> |
|
|
|
<button class="btn1" hover-class="lf-opacity" @click="toPhoneLogin">手机号登录</button> |
|
|
|
<button class="btn2" hover-class="lf-opacity" @click="wxLogin">微信授权登录</button> |
|
|
|
<button class="btn2" hover-class="lf-opacity" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信授权登录</button> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</template> |
|
|
|
@ -43,9 +43,10 @@ |
|
|
|
} |
|
|
|
|
|
|
|
if (token) { |
|
|
|
wx.switchTab({ |
|
|
|
url: '/pages/user/personal/personal' |
|
|
|
}); |
|
|
|
// uni.switchTab({ |
|
|
|
// url: '/pages/user/personal/personal' |
|
|
|
// }); |
|
|
|
this.$url('/pages/user/my/center', {type: 'launch'}) |
|
|
|
} else { |
|
|
|
// #ifdef MP-WEIXIN |
|
|
|
this.wxLogin(); |
|
|
|
@ -87,6 +88,7 @@ |
|
|
|
// } |
|
|
|
// }); |
|
|
|
}, |
|
|
|
// 小程序静默登录 |
|
|
|
wxLogin(){ |
|
|
|
uni.showLoading({ |
|
|
|
title: '正在自动登录', |
|
|
|
@ -102,18 +104,8 @@ |
|
|
|
} |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
// uni.getUserProfile({ |
|
|
|
// desc: '我们将获取到的信息用于展示', |
|
|
|
// lang: 'zh_CN', |
|
|
|
// complete: result => { |
|
|
|
// console.log(result); |
|
|
|
// if(result.errMsg == 'getUserProfile:ok'){ |
|
|
|
// console.log("获取成功!"); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// }) |
|
|
|
}, |
|
|
|
// 通过code自动登录 |
|
|
|
autoLogin(code) { |
|
|
|
this.$http.post({ |
|
|
|
api: 'api/oauth/miniprogram/login', |
|
|
|
@ -136,32 +128,33 @@ |
|
|
|
|
|
|
|
if (res.data.access_token) { |
|
|
|
console.log('已经返回给我了token'); |
|
|
|
wx.hideLoading(); |
|
|
|
uni.hideLoading(); |
|
|
|
var access_token = res.data.token_type + ' ' + res.data.access_token; |
|
|
|
var expires_in = res.data.expires_in || 315360000; |
|
|
|
this.$cookieStorage.set("user_token", access_token, expires_in); |
|
|
|
|
|
|
|
if (this.url) { |
|
|
|
wx.redirectTo({ |
|
|
|
uni.redirectTo({ |
|
|
|
url: "/" + this.url, |
|
|
|
fail: () => { |
|
|
|
wx.switchTab({ |
|
|
|
url: "/" + this.url |
|
|
|
}); |
|
|
|
} |
|
|
|
// fail: () => { |
|
|
|
// uni.switchTab({ |
|
|
|
// url: "/" + this.url |
|
|
|
// }); |
|
|
|
// } |
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
wx.switchTab({ |
|
|
|
url: '/pages/user/personal/personal' |
|
|
|
}); |
|
|
|
// uni.switchTab({ |
|
|
|
// url: '/pages/user/personal/personal' |
|
|
|
// }); |
|
|
|
this.$url('/pages/user/my/center', {type: 'launch'}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
wx.hideLoading(); |
|
|
|
uni.hideLoading(); |
|
|
|
} |
|
|
|
}).catch(rej => { |
|
|
|
wx.hideLoading(); |
|
|
|
wx.showModal({ |
|
|
|
uni.hideLoading(); |
|
|
|
uni.showModal({ |
|
|
|
content: '请求失败,请重试', |
|
|
|
showCancel: false, |
|
|
|
success: res => { |
|
|
|
@ -172,8 +165,119 @@ |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
// 获取用户手机号 |
|
|
|
getPhoneNumber(e) { |
|
|
|
if (e.detail.encryptedData) { |
|
|
|
uni.login({ |
|
|
|
success: res => { |
|
|
|
if (res.code) { |
|
|
|
this.setData({ |
|
|
|
code: res.code |
|
|
|
}); |
|
|
|
this.phone(e); |
|
|
|
} else { |
|
|
|
uni.showModal({ |
|
|
|
content: " 获取code失败", |
|
|
|
showCancel: false |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
this.toPhoneLogin(); |
|
|
|
} |
|
|
|
}, |
|
|
|
// 通过手机号登录注册 |
|
|
|
phone(e) { |
|
|
|
uni.showLoading({ |
|
|
|
title: '正在登录', |
|
|
|
mask: true |
|
|
|
}); |
|
|
|
this.$http.post({ |
|
|
|
api: 'api/oauth/miniprogram/mobile', |
|
|
|
data: { |
|
|
|
open_type: 'miniprogram', |
|
|
|
code: this.code, |
|
|
|
encryptedData: e.detail.encryptedData, |
|
|
|
iv: e.detail.iv, |
|
|
|
open_id: this.open_id, |
|
|
|
shop_id: this.$cookieStorage.get('shop_id') || '', |
|
|
|
agent_code: this.$cookieStorage.get('coupon_agent_code') || this.$cookieStorage.get('agent_code') || '', |
|
|
|
clerk_id: this.$cookieStorage.get('clerk_id') || '', |
|
|
|
agent_code_time: this.$cookieStorage.get('agent_code_time') || '', |
|
|
|
shop_id_time: this.$cookieStorage.get('shop_id_time') || '' |
|
|
|
} |
|
|
|
}).then(res => { |
|
|
|
if (res.statusCode == 200) { |
|
|
|
res = res.data; |
|
|
|
|
|
|
|
if (res.data.access_token) { |
|
|
|
var access_token = res.data.token_type + ' ' + res.data.access_token; |
|
|
|
var expires_in = res.data.expires_in || 315360000; // debugger; |
|
|
|
|
|
|
|
this.$cookieStorage.set("user_token", access_token, expires_in); // this.$cookieStorage.set("user_token",access_token,expires_in); |
|
|
|
// uni.setStorageSync("user_token",access_token); |
|
|
|
|
|
|
|
if (this.url) { |
|
|
|
// var path = ['pages/entity/store/store', 'pages/index/index/index', |
|
|
|
// 'pages/index/classification/classification', 'pages/store/tabCart/tabCart', 'pages/user/personal/personal', |
|
|
|
// 'pages/travels/index/index', 'pages/user/collar/collar' |
|
|
|
// ]; |
|
|
|
// var pathIndex = path.indexOf(this.url); |
|
|
|
|
|
|
|
// if (pathIndex == -1) { |
|
|
|
// uni.redirectTo({ |
|
|
|
// url: "/" + this.url |
|
|
|
// }); |
|
|
|
// } else { |
|
|
|
// uni.switchTab({ |
|
|
|
// url: "/" + this.url |
|
|
|
// }); |
|
|
|
// } |
|
|
|
this.$url("/" + this.url, {type: 'redirect'}); |
|
|
|
} else { |
|
|
|
// uni.switchTab({ |
|
|
|
// url: '/pages/user/personal/personal' |
|
|
|
// }); |
|
|
|
this.$url('/pages/user/my/center', {type: 'launch'}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
uni.showModal({ |
|
|
|
content: res.message || '请求失败,请重试', |
|
|
|
showCancel: false |
|
|
|
}); |
|
|
|
} |
|
|
|
} else { |
|
|
|
uni.showModal({ |
|
|
|
content: '请求失败,请重试', |
|
|
|
showCancel: false |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
uni.hideLoading(); |
|
|
|
}).catch(rej => { |
|
|
|
uni.hideLoading(); |
|
|
|
uni.showModal({ |
|
|
|
content: '请求失败,请重试', |
|
|
|
showCancel: false |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
// 跳转到手机号验证码登录 |
|
|
|
toPhoneLogin(){ |
|
|
|
this.$url('/pages/user/loginType/loginType'); |
|
|
|
if (this.url) { |
|
|
|
// uni.navigateTo({ |
|
|
|
// url: '/pages/user/loginType/loginType?url=' + encodeURIComponent(this.url) + '&open_id=' + this.open_id |
|
|
|
// }); |
|
|
|
this.$url('/pages/user/loginType/loginType?url=' + encodeURIComponent(this.url) + '&open_id=' + this.open_id); |
|
|
|
} else { |
|
|
|
// wx.navigateTo({ |
|
|
|
// url: '/pages/user/loginType/loginType?open_id=' + this.open_id |
|
|
|
// }); |
|
|
|
this.$url('/pages/user/loginType/loginType?open_id=' + this.open_id); |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
setData: function(obj) { |
|
|
|
let that = this; |
|
|
|
|