diff --git a/api/user.js b/api/user.js index 4fa7c52..8cc77ac 100644 --- a/api/user.js +++ b/api/user.js @@ -34,18 +34,20 @@ const deleteEmploye = (params) => mPost(`/uec/remove/employees`, params, config) const editEmploye = (params) => mPost(`/uec/save/self-department-member`, params, config) // **************************************************************************************************************************************** // /authorize/by-wechat-applet小程序登录 -function loginWechat(form) { +function loginWechat(form, loading) { let promise = new Promise(function (resolve, reject) { if (!form.encryptedData) { util.showToast('授权被拒绝,获取微信用户失败') reject('授权被拒绝,获取微信用户失败') return } - wx.showLoading({ title: '登录中', mask: true }) + if(loading) { + wx.showLoading({ title: '登录中', mask: true }) + } var tempToken = storage.get('tmpAuthToken') if(!util.isEmpty(tempToken)){ form.tmpAuthToken = tempToken - unionWechat(form, resolve, reject) + unionWechat(form, resolve, reject, loading) } else { wx.login({ success: res => { @@ -60,22 +62,28 @@ function loginWechat(form) { form.tmpAuthToken = result.data.data.tmpAuthToken storage.put('tmpAuthToken', form.tmpAuthToken, 98) // 微信登录,获取unionId - unionWechat(form, resolve, reject) + unionWechat(form, resolve, reject, loading) } else { - wx.hideLoading() + if(loading) { + wx.hideLoading() + } util.showToast('登录失败,请稍后再试') reject('登录失败,请稍后再试') } }, fail: function (err) { - wx.hideLoading() + if(loading) { + wx.hideLoading() + } util.showToast('登录失败,请稍后再试') reject('登录失败,请稍后再试') } }) }, fail: function (err) { - wx.hideLoading() + if(loading) { + wx.hideLoading() + } util.showToast('登录失败,请稍后再试') reject('登录失败,请稍后再试') } @@ -84,9 +92,8 @@ function loginWechat(form) { }) return promise } - // POST ​/uec​/authorize​/by-wechat-applet 通过小程序的方式进行认证 -function unionWechat(form, resolve, reject) { +function unionWechat(form, resolve, reject, loading) { wx.request({ header: { 'X-APP-ID': app.xAppId }, url: config.baseUrl + '/uec/authorize/by-wechat-applet', @@ -101,7 +108,9 @@ function unionWechat(form, resolve, reject) { } }, fail: function () { - wx.hideLoading() + if(loading) { + wx.hideLoading() + } wx.showToast({ title: '获取用户信息,请稍后再试', icon: "none" }) reject('请求错误!') } @@ -118,7 +127,9 @@ function gotPhoneNumber(form, resolve, reject) { method: 'POST', success: function (result) { // 绑定手机号码,进行登录 - wx.hideLoading() + if(loading) { + wx.hideLoading() + } if (result.data.code != 0) { wx.showToast({ title: '登录失败,请稍后再试', icon: "none" }) reject('登录失败,请稍后再试') @@ -128,21 +139,25 @@ function gotPhoneNumber(form, resolve, reject) { resolve(result.data) }, fail: function (res) { - wx.hideLoading() + if(loading) { + wx.hideLoading() + } wx.showToast({ title: '登录失败,请稍后再试', icon: "none" }) reject('登录失败,请稍后再试') } }) } -function phoneWechat(form) { +function phoneWechat(form, loading) { let promise = new Promise(function (resolve, reject) { if (!form.encryptedData) { wx.showToast({ title: '授权被拒绝,登录失败', icon: "none" }) reject('授权被拒绝,登录失败') return } - wx.showLoading({ title: '登录中', mask: true }) + if(loading) { + wx.showLoading({ title: '登录中', mask: true }) + } // 没有获取到openId,获取之后进行登录 wx.login({ success: res => { @@ -156,22 +171,28 @@ function phoneWechat(form) { if (result.data.code == 0) { form.tmpAuthToken = result.data.data.tmpAuthToken // 获取手机号码 - gotPhoneNumber(form, resolve, reject) + gotPhoneNumber(form, resolve, reject, loading) } else { - wx.hideLoading() + if(loading) { + wx.hideLoading() + } wx.showToast({ title: '登录失败,请稍后再试', icon: "none" }) reject('登录失败,请稍后再试') } }, fail: function (res) { - wx.hideLoading() + if(loading) { + wx.hideLoading() + } wx.showToast({ title: '登录失败,请稍后再试', icon: "none" }) reject('登录失败,请稍后再试') } }) }, fail: function (res) { - wx.hideLoading() + if(loading) { + wx.hideLoading() + } wx.showToast({ title: '登录失败,请稍后再试', icon: "none" }) reject('登录失败,请稍后再试') } diff --git a/pages/login/index.wxml b/pages/login/index.wxml index b338078..9595e82 100644 --- a/pages/login/index.wxml +++ b/pages/login/index.wxml @@ -1,5 +1,6 @@ - + + @@ -54,11 +55,11 @@ - 确定 - 登录 - 同意 @@ -67,5 +68,5 @@ 仅限纸通宝工厂客户使用 - + \ No newline at end of file