提交 4412fe1c authored 作者: haodaking's avatar haodaking

fix:修复登录失败的问题

上级 4e5fe158
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
}, },
"plugins": { "plugins": {
"tencentvideo": { "tencentvideo": {
"version": "2.0.2", "version": "2.0.5",
"provider": "wxa75efa648b60994b" "provider": "wxa75efa648b60994b"
} }
}, },
......
...@@ -27,37 +27,47 @@ Page({ ...@@ -27,37 +27,47 @@ Page({
}, },
// 获取用户code // 获取用户code
getCode(callback) { getCode(callback) {
return new Promise((resolve, reject) => {
wx.login({ wx.login({
success(res) { success(res) {
if (res.code) { if (res.code) {
callback && callback(res.code) callback && callback(res.code)
resolve(res.code)
} else { } else {
wx.showToast({ title: `登录失败!${res.errMsg}`, icon: 'none' }) wx.showToast({ title: `登录失败!${res.errMsg}`, icon: 'none' })
reject(res)
} }
}, },
fail(res) { fail(res) {
wx.showToast({ title: `登录失败!${res.errMsg}`, icon: 'none' }) wx.showToast({ title: `登录失败!${res.errMsg}`, icon: 'none' })
reject(res)
} }
}) })
})
}, },
// 获取用户信息 // 获取用户信息
getUserInfo(callback) { getUserInfo(callback) {
return new Promise((resolve, reject) => {
wx.getUserProfile({ wx.getUserProfile({
desc: '登录注册', desc: '登录注册',
success(res) { success(res) {
callback && callback(res) callback && callback(res)
resolve(res)
}, },
fail(res) { fail(res) {
wx.showToast({ title: `获取用户信息失败!`, icon: 'none' }) wx.showToast({ title: `获取用户信息失败!`, icon: 'none' })
reject(res)
} }
}) })
})
}, },
// 微信登录 // 微信登录
wechatLogin() { wechatLogin() {
// 获取用户信息
this.getUserInfo(user => {
// 获取code // 获取code
this.getCode(code => { const p1 = this.getCode()
// 获取用户信息
const p2 = this.getUserInfo()
Promise.all([p1, p2]).then(([code, user]) => {
const { encryptedData, iv } = user const { encryptedData, iv } = user
api.wechatLogin({ encryptedData, iv, code, identity: 'classes-mini' }).then(response => { api.wechatLogin({ encryptedData, iv, code, identity: 'classes-mini' }).then(response => {
if (response.code === 0) { if (response.code === 0) {
...@@ -70,7 +80,6 @@ Page({ ...@@ -70,7 +80,6 @@ Page({
} }
}) })
}) })
})
}, },
// 手机号登录 // 手机号登录
phoneLogin() { phoneLogin() {
......
<main-page> <!-- <main-page> -->
<view class="container"> <view class="container">
<image src="../../assets/images/bg.png" mode="aspectFill" class="bg"></image> <image src="../../assets/images/bg.png" mode="aspectFill" class="bg"></image>
<view class="top"> <view class="top">
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
</view> </view>
</view> </view>
</view> </view>
</main-page> <!-- </main-page> -->
<!-- 绑定相关 --> <!-- 绑定相关 -->
<dialog title="{{ type === 1 ? '绑定账号' : '绑定手机号' }}" model:show="{{ show }}"> <dialog title="{{ type === 1 ? '绑定账号' : '绑定手机号' }}" model:show="{{ show }}">
<!-- 绑定账号 --> <!-- 绑定账号 -->
......
...@@ -26,17 +26,19 @@ ...@@ -26,17 +26,19 @@
"disablePlugins": [], "disablePlugins": [],
"outputPath": "" "outputPath": ""
}, },
"bundle": false, "useIsolateContext": false,
"useIsolateContext": true,
"useCompilerModule": true,
"userConfirmedUseCompilerModuleSwitch": false,
"userConfirmedBundleSwitch": false, "userConfirmedBundleSwitch": false,
"packNpmManually": false, "packNpmManually": false,
"packNpmRelationList": [], "packNpmRelationList": [],
"minifyWXSS": true "minifyWXSS": true,
"disableUseStrict": false,
"minifyWXML": true,
"showES6CompileOption": false,
"useCompilerPlugins": false,
"ignoreUploadUnusedFiles": true
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "2.12.2", "libVersion": "2.21.3",
"appid": "wx81555c44ed2d7653", "appid": "wx81555c44ed2d7653",
"projectname": "learnOnline-enterprise", "projectname": "learnOnline-enterprise",
"isGameTourist": false, "isGameTourist": false,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论