Browse Source

no message

feature/v1.5
xpz2018 4 years ago
parent
commit
3acbcd9464
2 changed files with 45 additions and 23 deletions
  1. 57
      api/user.js
  2. 11
      pages/login/index.wxml

57
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('登录失败,请稍后再试')
}

11
pages/login/index.wxml

@ -1,5 +1,6 @@
<!--pages/login/index.wxml-->
<view class="flex flex-center" style="width:100%;height:320rpx;margin-top:120rpx">
<view class="flex flex-center flex-column" style="height:100vh;width:750rpx">
<view class="flex flex-center" style="width:100%;height:320rpx;">
<image style="width:407rpx;height:160rpx" src="/assets/image/icon_logo.png"></image>
</view>
@ -54,11 +55,11 @@
</view>
<view style="margin-top:20rpx;padding:40rpx 80rpx">
<van-button block type="info" loading="{{loging}}" loading-text="提交..." disabled="{{!metaData.userName}}"
<van-button block type="info" custom-style="width:600rpx" loading="{{loging}}" loading-text="提交..." disabled="{{!metaData.userName}}"
bind:click="submitForm" wx:if="{{ metaData }}">确定</van-button>
<van-button block type="info" loading="{{loging}}" loading-text="登录中..." disabled="{{loginEnable}}"
<van-button block type="info" custom-style="width:600rpx" loading="{{loging}}" loading-text="登录中..." disabled="{{loginEnable}}"
bind:click="registAccount" wx:elif="{{ regist }}">登录</van-button>
<van-button block type="info" loading="{{loging}}" loading-text="登录中..." open-type="getUserInfo"
<van-button block type="info" custom-style="width:600rpx" loading="{{loging}}" loading-text="登录中..." open-type="getUserInfo"
bind:getuserinfo="onGotUserInfo" wx:else>同意</van-button>
<!-- <van-button block type="info" loading="{{loging}}" loading-text="登录中..."
bind:click="onGetUserProfile" wx:else>同意</van-button> -->
@ -67,5 +68,5 @@
<view class="flex flex-center" style="margin-top:10rpx;font-size:24rpx;color:#008AFF;text-align: center">
<text class="cuIcon-infofill md-icon">仅限纸通宝工厂客户使用</text>
</view>
</view>
<van-dialog id="van-dialog" />
Loading…
Cancel
Save