Commit b779454c by 李伟康

修改登录

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