Commit b779454c by 李伟康

修改登录

1 parent 4a82636a
import api from '~/utils/request/request' import api from '~/utils/request/request'
const { appId } = wx.getAccountInfoSync().miniProgram const {
appId
} = wx.getAccountInfoSync().miniProgram
class UsersApi { class UsersApi {
/**调用后台接口获取用户信息 */ /**调用后台接口获取用户信息js_code换取sessionId */
async wxCodeLogin() {
const {
code
} = await this.getWxCode()
return await api.post({
method: 'scrm.api.sso.wechat.applets.jscode.login',
appId,
code
},
true
)
}
async login() { async login() {
return this.getWxCode().then(({ code }) => {
return api.post(
{
method: 'scrm.api.sso.weapp.jscode.login',
appId,
code
},
true
)
})
} }
/**调用接口获取登录凭证(code)。通过凭证进而换取用户登录态信息,包括用户在当前小程序的唯一标识(openid)、微信开放平台帐号下的唯一标识(unionid,若当前小程序已绑定到微信开放平台帐号)及本次登录的会话密钥(session_key)等。用户数据的加解密通讯需要依赖会话密钥完成。 */ /**调用接口获取登录凭证(code)。通过凭证进而换取用户登录态信息,包括用户在当前小程序的唯一标识(openid)、微信开放平台帐号下的唯一标识(unionid,若当前小程序已绑定到微信开放平台帐号)及本次登录的会话密钥(session_key)等。用户数据的加解密通讯需要依赖会话密钥完成。 */
getWxCode() { getWxCode() {
...@@ -23,39 +28,55 @@ class UsersApi { ...@@ -23,39 +28,55 @@ class UsersApi {
}) })
}) })
} }
/**授权手机号 */ /**授权手机号登录 */
async authUserPhone(detail, sessionId) { async authUserPhone(detail, loginToken) {
if (!sessionId) { if (!loginToken) {
wx.$api.showToast('缺少sessionId') wx.$api.showToast('缺少loginToken')
Promise.reject() Promise.reject()
return
} }
if (detail.errMsg && detail.errMsg == 'getPhoneNumber:fail user deny') Promise.reject() if (detail.errMsg && detail.errMsg == 'getPhoneNumber:fail user deny') Promise.reject()
delete detail.errMsg delete detail.errMsg
if (detail.iv && detail.encryptedData) { if (detail.iv && detail.encryptedData) {
wx.$api.showLoading() detail.loginToken = loginToken
detail.sessionId = sessionId return api.post({
return api.post( method: 'scrm.api.sso.wechat.applets.auth.phone',
{ ...detail,
method: 'scrm.api.sso.weapp.auth.phone', platformEntrance: 'BUSINESS_ASSISTANT', // 平台标识:生意助手-BUSINESS_ASSISTANT,门店助手-STORE_ASSISTANT
...detail
}, },
true true
) )
} else Promise.reject() } else Promise.reject()
} }
/**更新客户手机号 */ /**账号密码登录 */
updataCustomerPhone() { accountLogin(data = {}) {
let customerId = wx.$storage.get('srcm_shopmall_customer_id'), return api.post({
merchantId = wx.$storage.get('srcm_shopmall_merchant_id') method: 'scrm.api.sso.wechat.applets.password.login',
api ...data,
.post({ platformEntrance: 'BUSINESS_ASSISTANT',
method: 'scrm.api.sso.weapp.mark.phone', },
customerId, true
merchantId )
}) }
.then(() => { /** 手机号获取短信验证码 */
wx.removeStorageSync('srcm_shopmall_customer_id') getSmsCode(mobile) {
}) return api.post({
method: 'scrm.api.sso.wechat.applets.sms.get.code',
mobile
},
true
)
}
/** 手机号短信验证码登录 */
phoneSmsLogin(data = {}) {
return api.post({
method: 'scrm.api.sso.wechat.applets.sms.login',
...data,
source: 'MINIAPP',
platformEntrance: 'BUSINESS_ASSISTANT'
},
true
)
} }
} }
export default UsersApi export default UsersApi
\ No newline at end of file \ No newline at end of file
...@@ -19,10 +19,10 @@ Component({ ...@@ -19,10 +19,10 @@ Component({
*/ */
data: { data: {
formData: { formData: {
phone: '', phone: '13714966184',
code: '', code: '8888',
account: '', account: 'admin',
password: '' password: '123456789'
}, },
phoneReady: false, phoneReady: false,
countDown: null countDown: null
...@@ -55,16 +55,28 @@ Component({ ...@@ -55,16 +55,28 @@ Component({
}) })
this.checkFormData() this.checkFormData()
}, },
getSms() { getSmsCode() {
const { const {
phoneReady, phoneReady,
formData,
count count
} = this.data } = this.data
if (!phoneReady || count) return if (!phoneReady || count) return
this.setData({ USERAPI.getSmsCode(formData.phone).then(({
count: countDown code,
message
}) => {
if (code == '0') {
this.setData({
count: countDown
})
this.countDown()
} else {
wx.$api.showToast(message || '发送验证码失败')
}
}).catch(err => {
wx.$api.showToast(err || '发送验证码失败')
}) })
this.countDown()
}, },
countDown() { countDown() {
setTimeout(() => { setTimeout(() => {
...@@ -101,17 +113,40 @@ Component({ ...@@ -101,17 +113,40 @@ Component({
}) })
}, },
login() { login() {
const {
formData,
loginType
} = this.data,
target = {
1: 'phoneSmsLogin',
2: 'accountLogin'
} [loginType],
obj = loginType == 1 ? {
mobile : formData.phone,
code : formData.code
} : {
userName: formData.account,
password: formData.password
}
this.setBtnLoading() this.setBtnLoading()
setTimeout(() => { USERAPI[target](obj).then(res => {
console.log(res)
this.setBtnLoading(false)
}).catch(err => {
this.setBtnLoading(false) this.setBtnLoading(false)
}, 5e3) })
}, },
wxLogin({detail}) { wxLogin({
if(!detail.code) return detail
}) {
if (!detail.code) return
this.setBtnLoading() this.setBtnLoading()
setTimeout(() => { USERAPI.authUserPhone(detail, this.loginToken).then(res => {
console.log(res)
this.setBtnLoading(false) this.setBtnLoading(false)
}, 5e3) }).catch(err => {
this.setBtnLoading(false)
})
}, },
setBtnLoading(loading = true) { setBtnLoading(loading = true) {
thisPage.setData({ thisPage.setData({
...@@ -125,8 +160,10 @@ Component({ ...@@ -125,8 +160,10 @@ Component({
lifetimes: { lifetimes: {
attached: function () { attached: function () {
// 在组件实例进入页面节点树时执行 // 在组件实例进入页面节点树时执行
USERAPI.login().then(res => { USERAPI.wxCodeLogin().then(({
console.log(res) data
}) => {
this.loginToken = data
}) })
thisPage = wx.$router.getPageInstance() thisPage = wx.$router.getPageInstance()
}, },
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
<input-icon show="{{formData.phone}}" bindtap="clear" data-name="phone" /> <input-icon show="{{formData.phone}}" bindtap="clear" data-name="phone" />
</view> </view>
<view class="input"> <view class="input">
<input type="number" placeholder="填写验证码" placeholder-class="placeholder" bindinput="input" data-name="code" value="{{formData.code}}" maxlength="6" /> <input type="number" placeholder="填写验证码" placeholder-class="placeholder" bindinput="input" data-name="code" value="{{formData.code}}" maxlength="4" />
<input-icon show="{{formData.code}}" bindtap="clear" data-name="code" /> <input-icon show="{{formData.code}}" bindtap="clear" data-name="code" />
<view class="sms text-center {{count?'sms-disabled':''}} {{phoneReady?'':'sms-disabled'}} " bindtap="getSms">{{ <view class="sms text-center {{count?'sms-disabled':''}} {{phoneReady?'':'sms-disabled'}} " bindtap="getSmsCode">{{
count? count + 's':'获取验证码' count? count + 's':'获取验证码'
}}</view> }}</view>
<block wx:if="{{smsError}}"> <block wx:if="{{smsError}}">
......
...@@ -5,8 +5,7 @@ Page({ ...@@ -5,8 +5,7 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
loginType: 0, loginType: 0
agree: true
}, },
/** /**
...@@ -31,7 +30,6 @@ Page({ ...@@ -31,7 +30,6 @@ Page({
wx.hideLoading() wx.hideLoading()
} }
}) })
this.checkLoginBtn()
}, },
/** /**
...@@ -60,23 +58,22 @@ Page({ ...@@ -60,23 +58,22 @@ Page({
// onShareAppMessage() { // onShareAppMessage() {
// }, // },
checkLoginBtn(flag = false) { checkLoginBtn(disabled = false) {
const { const {
agree,
loginType loginType
} = this.data } = this.data
if (loginType == 0) flag = true if (loginType == 0) disabled = true
else { else {
const { const {
formData, formData,
phoneReady phoneReady
} = this.selectComponent('#box').data } = this.selectComponent('#box').data
flag = loginType == 1 ? disabled = loginType == 1 ?
phoneReady && formData.code : phoneReady && formData.code :
formData.account && formData.password formData.account && formData.password
} }
this.setData({ this.setData({
disabled: !agree || !flag disabled: !disabled
}) })
}, },
}) })
\ No newline at end of file \ No newline at end of file
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
"navigation-bar": "/components/NavigationBar/NavigationBar", "navigation-bar": "/components/NavigationBar/NavigationBar",
"mask": "./components/Mask/Mask", "mask": "./components/Mask/Mask",
"box": "./components/Box/Box", "box": "./components/Box/Box",
"type-list": "./components/TypeList/TypeList", "type-list": "./components/TypeList/TypeList"
"protocol": "./components/Protocol/Protocol"
}, },
"navigationStyle": "custom" "navigationStyle": "custom"
} }
\ No newline at end of file \ No newline at end of file
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
<navigation-bar navStyle="background-color: rgba(0,0,0,0)">生意助手</navigation-bar> <navigation-bar navStyle="background-color: rgba(0,0,0,0)">生意助手</navigation-bar>
<box loginType="{{loginType}}" disabled="{{disabled}}" id="box" /> <box loginType="{{loginType}}" disabled="{{disabled}}" id="box" />
<type-list loginType="{{loginType}}" /> <type-list loginType="{{loginType}}" />
<protocol agree="{{agree}}" /> <!-- <protocol agree="{{agree}}" /> -->
</view> </view>
\ No newline at end of file \ No newline at end of file
...@@ -25,6 +25,7 @@ Page({ ...@@ -25,6 +25,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
wx.$api.showLoading()
const { const {
sessionId, sessionId,
} = wx.$storage.get(), { } = wx.$storage.get(), {
......
<view class="layout"> <view class="layout">
<image class="icon" src="https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/COVER_LIVE.gif"></image> <!-- <image class="icon" src="https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/COVER_LIVE.gif"></image> -->
</view> </view>
\ No newline at end of file \ No newline at end of file
...@@ -6,7 +6,7 @@ const target = ['ip', 'dev', 'uat', 'prod'] ...@@ -6,7 +6,7 @@ const target = ['ip', 'dev', 'uat', 'prod']
2测试 2测试
3生产 3生产
*/ */
const index = 3 const index = 0
const secretKey = { const secretKey = {
ip: {}, ip: {},
dev: { dev: {
...@@ -32,7 +32,7 @@ const secretKey = { ...@@ -32,7 +32,7 @@ const secretKey = {
const domain = { const domain = {
// ip: 'http://192.168.2.94:8558', // ip: 'http://192.168.2.94:8558',
// ip: 'http://192.168.2.3:8315', // ip: 'http://192.168.2.3:8315',
ip: 'http://192.168.3.181:8394', ip: 'http://192.168.1.170:8315',
/**登录: 192.168.2.3:8315 /**登录: 192.168.2.3:8315
商城: 192.168.2.3:8558 */ 商城: 192.168.2.3:8558 */
dev: 'https://scrm.dev.glsx.com.cn', dev: 'https://scrm.dev.glsx.com.cn',
......
...@@ -2,14 +2,12 @@ import { ...@@ -2,14 +2,12 @@ import {
secretKey, secretKey,
pathEnum, pathEnum,
domain, domain,
index,
sign sign
} from './http.js' } from './http.js'
// import util from '../util' // import util from '../util'
import { import {
getSessionId getSessionId
} from '~/utils/cache/storageApi' } from '~/utils/cache/storageApi'
let INTERRUPT = false
/**接口 */ /**接口 */
class Request { class Request {
get(params, returnAll = false) { get(params, returnAll = false) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!