Commit b8cea721 by 李伟康

兼容智能名片登录

1 parent d0b067e9
// login/index/components/LoginBox.js
import USERAPI from '~/api/usersApi/index'
import {
selectAccountLogin,
checkLoginUserInfo,
setLoginInfo,
loginModal
} from '~/login/lib/index'
......@@ -176,7 +176,7 @@ Component({
}) => {
this.setBtnLoading(false)
if (code == '0') {
if (loginType == 1) this.checkLoginUserInfo(data)
if (loginType == 1) checkLoginUserInfo(data)
else {
const {
autoLogin
......@@ -220,7 +220,7 @@ Component({
data,
message
}) => {
if (code == '0') this.checkLoginUserInfo(data)
if (code == '0') checkLoginUserInfo(data)
else {
wx.$api.showToast(message || '系统异常')
this.init()
......@@ -235,24 +235,6 @@ Component({
this.init()
})
},
/**手机号&微信登录:是否跳转登录列表页 */
checkLoginUserInfo({
loginUserInfoList,
sessionId
}) {
/**多个账号 */
if (loginUserInfoList.length > 1)
wx.$router.go('login.accountItems', {
sessionId,
...thisPage.options
})
/**只有一个账号 */
else
selectAccountLogin({
id: loginUserInfoList[0].uuid,
sessionId
})
},
/**设置登录按钮loading状态 */
setBtnLoading(loading = true) {
thisPage.setData({
......
import { setSessionId, setUserInfo } from '~/utils/cache/storageApi'
import {
setSessionId,
setUserInfo
} from '~/utils/cache/storageApi'
import USERAPI from '~/api/usersApi/index'
const setRouteData = targetPath => {
let [url, query] = targetPath.split('?'),
......@@ -15,11 +18,18 @@ const setRouteData = targetPath => {
}
}
/**选择账号登录 */
const selectAccountLogin = ({ id, sessionId }) => {
const selectAccountLogin = ({
id,
sessionId
}) => {
USERAPI.selectAccountLogin({
id,
sessionId
}).then(({ code, data, message }) => {
}).then(({
code,
data,
message
}) => {
if (code == '0') {
console.log(data)
setLoginInfo(data.loginUserInfoList[0], data.sessionId)
......@@ -28,7 +38,7 @@ const selectAccountLogin = ({ id, sessionId }) => {
}
/**设置登录信息 */
const setLoginInfo = (userInfo, sessionId) => {
if(!userInfo) {
if (!userInfo) {
wx.$api.showToast('仅支持服务商类型账户登录')
return
}
......@@ -39,14 +49,23 @@ const setLoginInfo = (userInfo, sessionId) => {
/**成功跳转 */
const loginSuccess = () => {
const {
options: { targetPath }
options: {
targetPath
}
} = wx.$router.getPageInstance()
if (targetPath) {
const { url, obj } = setRouteData(targetPath)
const {
url,
obj
} = setRouteData(targetPath)
wx.$router.reLaunch(url, obj)
} else wx.$router.go('pages.index')
}
const loginModal = async ({ message, confirmText, cancelText }) => {
const loginModal = async ({
message,
confirmText,
cancelText
}) => {
return new Promise((resolve, reject) => {
wx.showModal({
content: message || '网络异常',
......@@ -60,10 +79,30 @@ const loginModal = async ({ message, confirmText, cancelText }) => {
})
})
}
/**手机号&微信登录:是否跳转登录列表页 */
const checkLoginUserInfo = ({
loginUserInfoList,
sessionId
}) => {
const thisPage = wx.$router.getPageInstance()
/**多个账号 */
if (loginUserInfoList.length > 1)
wx.$router.go('login.accountItems', {
sessionId,
...thisPage.options
})
/**只有一个账号 */
else
selectAccountLogin({
id: loginUserInfoList[0].uuid,
sessionId
})
}
module.exports = {
checkLoginUserInfo,
selectAccountLogin,
loginSuccess,
setRouteData,
setLoginInfo,
loginModal
}
}
\ No newline at end of file
import {
checkLoginUserInfo,
setRouteData,
setLoginInfo,
loginModal
......@@ -35,7 +36,16 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
this.init()
const appEnter = wx.getEnterOptionsSync()
if (appEnter.scene == 1037) {
if (Object.keys(appEnter.referrerInfo).length) {
const {
extraData
} = appEnter.referrerInfo
if (extraData && Object.keys(extraData).length) this.phoneSmsLogin(extraData)
else this.init()
} else this.init()
} else this.init()
},
/**
......@@ -68,10 +78,10 @@ Page({
init() {
wx.nextTick(() => {
const sessionId = getSessionId(),
{
url,
targetPath = url ? decodeURIComponent(url) : ''
} = this.options
{
url,
targetPath = url ? decodeURIComponent(url) : ''
} = this.options
let path = 'pages.index',
obj = {}
if (targetPath) obj.targetPath = targetPath
......@@ -128,5 +138,30 @@ Page({
})
} else wx.$router.reLaunch('login.index', obj)
} else wx.$router.reLaunch('login.index', obj)
},
phoneSmsLogin(extraData) {
console.log(extraData)
USERAPI.phoneSmsLogin({
mobile: extraData.phone,
code: extraData.smscode
}).then(({
code,
data,
message
}) => {
if (code == '0') checkLoginUserInfo(data)
else {
wx.$api.showToast(message || '系统异常')
setTimeout(() => {
wx.$router.reLaunch('login.index')
}, 1e3)
}
})
.catch(err => {
wx.$api.showToast('系统异常')
setTimeout(() => {
wx.$router.reLaunch('login.index')
}, 1e3)
})
}
})
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!