Commit b8cea721 by 李伟康

兼容智能名片登录

1 parent d0b067e9
// login/index/components/LoginBox.js // login/index/components/LoginBox.js
import USERAPI from '~/api/usersApi/index' import USERAPI from '~/api/usersApi/index'
import { import {
selectAccountLogin, checkLoginUserInfo,
setLoginInfo, setLoginInfo,
loginModal loginModal
} from '~/login/lib/index' } from '~/login/lib/index'
...@@ -176,7 +176,7 @@ Component({ ...@@ -176,7 +176,7 @@ Component({
}) => { }) => {
this.setBtnLoading(false) this.setBtnLoading(false)
if (code == '0') { if (code == '0') {
if (loginType == 1) this.checkLoginUserInfo(data) if (loginType == 1) checkLoginUserInfo(data)
else { else {
const { const {
autoLogin autoLogin
...@@ -220,7 +220,7 @@ Component({ ...@@ -220,7 +220,7 @@ Component({
data, data,
message message
}) => { }) => {
if (code == '0') this.checkLoginUserInfo(data) if (code == '0') checkLoginUserInfo(data)
else { else {
wx.$api.showToast(message || '系统异常') wx.$api.showToast(message || '系统异常')
this.init() this.init()
...@@ -235,24 +235,6 @@ Component({ ...@@ -235,24 +235,6 @@ Component({
this.init() 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状态 */ /**设置登录按钮loading状态 */
setBtnLoading(loading = true) { setBtnLoading(loading = true) {
thisPage.setData({ thisPage.setData({
......
import { setSessionId, setUserInfo } from '~/utils/cache/storageApi' import {
setSessionId,
setUserInfo
} from '~/utils/cache/storageApi'
import USERAPI from '~/api/usersApi/index' import USERAPI from '~/api/usersApi/index'
const setRouteData = targetPath => { const setRouteData = targetPath => {
let [url, query] = targetPath.split('?'), let [url, query] = targetPath.split('?'),
...@@ -15,11 +18,18 @@ const setRouteData = targetPath => { ...@@ -15,11 +18,18 @@ const setRouteData = targetPath => {
} }
} }
/**选择账号登录 */ /**选择账号登录 */
const selectAccountLogin = ({ id, sessionId }) => { const selectAccountLogin = ({
id,
sessionId
}) => {
USERAPI.selectAccountLogin({ USERAPI.selectAccountLogin({
id, id,
sessionId sessionId
}).then(({ code, data, message }) => { }).then(({
code,
data,
message
}) => {
if (code == '0') { if (code == '0') {
console.log(data) console.log(data)
setLoginInfo(data.loginUserInfoList[0], data.sessionId) setLoginInfo(data.loginUserInfoList[0], data.sessionId)
...@@ -28,7 +38,7 @@ const selectAccountLogin = ({ id, sessionId }) => { ...@@ -28,7 +38,7 @@ const selectAccountLogin = ({ id, sessionId }) => {
} }
/**设置登录信息 */ /**设置登录信息 */
const setLoginInfo = (userInfo, sessionId) => { const setLoginInfo = (userInfo, sessionId) => {
if(!userInfo) { if (!userInfo) {
wx.$api.showToast('仅支持服务商类型账户登录') wx.$api.showToast('仅支持服务商类型账户登录')
return return
} }
...@@ -39,14 +49,23 @@ const setLoginInfo = (userInfo, sessionId) => { ...@@ -39,14 +49,23 @@ const setLoginInfo = (userInfo, sessionId) => {
/**成功跳转 */ /**成功跳转 */
const loginSuccess = () => { const loginSuccess = () => {
const { const {
options: { targetPath } options: {
targetPath
}
} = wx.$router.getPageInstance() } = wx.$router.getPageInstance()
if (targetPath) { if (targetPath) {
const { url, obj } = setRouteData(targetPath) const {
url,
obj
} = setRouteData(targetPath)
wx.$router.reLaunch(url, obj) wx.$router.reLaunch(url, obj)
} else wx.$router.go('pages.index') } else wx.$router.go('pages.index')
} }
const loginModal = async ({ message, confirmText, cancelText }) => { const loginModal = async ({
message,
confirmText,
cancelText
}) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
wx.showModal({ wx.showModal({
content: message || '网络异常', content: message || '网络异常',
...@@ -60,7 +79,27 @@ const loginModal = async ({ message, confirmText, cancelText }) => { ...@@ -60,7 +79,27 @@ 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 = { module.exports = {
checkLoginUserInfo,
selectAccountLogin, selectAccountLogin,
loginSuccess, loginSuccess,
setRouteData, setRouteData,
......
import { import {
checkLoginUserInfo,
setRouteData, setRouteData,
setLoginInfo, setLoginInfo,
loginModal loginModal
...@@ -35,7 +36,16 @@ Page({ ...@@ -35,7 +36,16 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { 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()
}, },
/** /**
...@@ -128,5 +138,30 @@ Page({ ...@@ -128,5 +138,30 @@ Page({
}) })
} else wx.$router.reLaunch('login.index', obj) } else wx.$router.reLaunch('login.index', obj)
} 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 \ 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!