Commit 1f3ca374 by 李伟康

feat(auth): 实现扫码登录功能并优化登录流程

新增 loginApi 模块,支持通过企业微信扫码登录;
调整登录页面逻辑,动态获取登录链接及企业信息;
重构 http 请求模块,增加 shukeRequest 方法以支持新接口;
更新环境配置,添加 shukeDomain 域名映射;
优化 loading 页面逻辑,简化用户登录后的跳转判断。
1 parent 53eb1073
......@@ -10,6 +10,7 @@ import sceneMarketApi from './sceneMarketApi'
import interceptionApi from './interceptionApi'
import popupApi from './popupApi'
import usedCarApi from './usedCar'
import loginApi from './loginApi'
module.exports = {
commonApi,
......@@ -23,5 +24,6 @@ module.exports = {
interceptionApi,
popupApi,
evaluationApi,
usedCarApi
usedCarApi,
loginApi
}
import http from '../request/http'
import { env } from '../../env'
module.exports = {
getLoginUrl () {
return http.uni_request({ url: `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=ww-ai-market-config&env=${env}` })
},
getCorpInfo () {
return http.shukeRequest('linkwechat-api/auth/findAgentId')
},
login (data) {
return http.shukeRequest('linkwechat-api/auth/qrLogin', data, 'GET', true)
}
}
\ No newline at end of file
import sign from './sign.js'
import { secretKey, pathEnum, domain, djDomain, merchantDomain, djSecretKey } from '../../env'
import { secretKey, pathEnum, domain, djDomain, merchantDomain, djSecretKey, shukeDomain } from '../../env'
const HOST = {
scrm: domain,
dj: djDomain,
......@@ -7,13 +7,13 @@ const HOST = {
ip: 'http://192.168.1.125:8080'
}
class Request {
get(params, returnAll = false, hostType) {
get (params, returnAll = false, hostType) {
return this.request('GET', params, returnAll, hostType)
}
post(params, returnAll = false, hostType) {
post (params, returnAll = false, hostType) {
return this.request('POST', params, returnAll, hostType)
}
fetch(method, data, returnAll = true, hostType) {
fetch (method, data, returnAll = true, hostType) {
return this.post(
{
method,
......@@ -23,11 +23,11 @@ class Request {
hostType
)
}
request(RequestMethods, params, returnAll, hostType = 'dj') {
request (RequestMethods, params, returnAll, hostType = 'dj') {
return new Promise((resolve, reject) => {
let _this = this
uni.getNetworkType({
success(res) {
success (res) {
if (res.networkType == 'none') {
uni.hideLoading()
uni.showToast({
......@@ -40,11 +40,11 @@ class Request {
let header =
RequestMethods === 'POST'
? {
'content-type': 'application/x-www-form-urlencoded'
}
'content-type': 'application/x-www-form-urlencoded'
}
: {
'Cache-Control': 'no-cache'
}
'Cache-Control': 'no-cache'
}
let projectName = params.projectName
if (!projectName) projectName = _this.getRopProject(params.method)
const path = pathEnum[projectName]
......@@ -56,7 +56,7 @@ class Request {
header,
dataType: 'json',
responseType: 'text',
success(response) {
success (response) {
/**业务代码 */
let { data, statusCode } = response
if (!data || statusCode != 200) {
......@@ -92,7 +92,7 @@ class Request {
}
}
},
fail(error) {
fail (error) {
uni.hideLoading()
console.error(`${params.method}接口异常:`, error)
uni.showToast({
......@@ -101,7 +101,7 @@ class Request {
})
reject(error)
},
complete() {
complete () {
uni.stopPullDownRefresh()
}
})
......@@ -109,7 +109,7 @@ class Request {
})
})
}
getData(params, hostType = 'scrm') {
getData (params, hostType = 'scrm') {
let projectName = params.projectName
if (!projectName) projectName = this.getRopProject(params.method)
else delete params.projectName
......@@ -141,11 +141,11 @@ class Request {
params.appKey = appKey
return sign(params, secret, noSignAttr)
}
getRopProject(method) {
getRopProject (method) {
const projectName = method.split('.')[2]
return projectName
}
uni_request({ url, method = 'GET', data = {}, header = {}, dataType = 'json', responseType = 'text' }) {
uni_request ({ url, method = 'GET', data = {}, header = {}, dataType = 'json', responseType = 'text' }) {
return new Promise(resolve => {
uni.request({
url,
......@@ -154,12 +154,55 @@ class Request {
header,
dataType,
responseType,
success(response) {
success (response) {
resolve(response.data)
}
})
})
}
shukeRequest (url, data = {}, method = 'GET', returnAll = false) {
let header =
method === 'POST'
? {
'content-type': 'application/x-www-form-urlencoded'
}
: {
'Cache-Control': 'no-cache',
'Content-Type': 'application/json'
}
return new Promise(resolve => {
uni.getNetworkType({
success (res) {
if (res.networkType == 'none') {
uni.hideLoading()
uni.showToast({
title: '网络异常',
icon: 'none'
})
reject('网络异常')
return
}
uni.request({
url: `${shukeDomain}/${url}`,
data,
method,
header,
dataType: 'json',
responseType: 'text',
success (response) {
console.log(response)
let { data, statusCode } = response
if (returnAll) {
resolve(data)
return
}
resolve(data.data)
}
})
}
})
})
}
}
export default new Request()
const target = ['ip', 'dev', 'uat', 'prod', 'beta']
const index = 4
const index = 1
/**
*
0本地
......@@ -77,6 +77,13 @@ const merchantDomain = {
pet: ''
}[target[index]]
const shukeDomain = {
ip: 'http://wescrm.test.glshuke.com',
dev: 'http://wescrm.test.glshuke.com',
beta: 'http://wescrm.test.glshuke.com', //
uat: 'http://wescrm.test.glshuke.com', //
}[target[index]]
const djSecretKey = {
ip: { appKey: '48e5e13229b82c1b4e6e8c96151f0637', secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b' },
dev: {
......@@ -178,5 +185,6 @@ module.exports = {
merchantDomain,
djSecretKey,
signSecretKey,
evaluationDomain
evaluationDomain,
shukeDomain
}
......@@ -10,23 +10,13 @@ export default {
},
mounted () {
uni.showLoading({
mask: true
})
mask: true
})
let userInfo = uni.$storage.get('userInfo')
if (userInfo && userInfo.sceneType != undefined && userInfo.sceneType != null) {
uni.$api.userApi.getListSelectAccount().then(res => {
uni.hideLoading()
setTimeout(() => {
if (res.code == 0) {
uni.reLaunch({
url: '/pages/equity/index'
})
}
else this.toLogin()
}, 500)
}).catch(() => [
this.toLogin()
])
if (userInfo) {
uni.reLaunch({
url: '/pages/equity/index'
})
} else this.toLogin()
},
methods: {
......
......@@ -91,10 +91,12 @@
@click="copyText"
></view>
</view> -->
<web-view
:src="loginUrl"
@message="handlerMessage"
/>
<template v-if="loginUrl">
<web-view
:src="loginUrl"
@message="login"
/>
</template>
</view>
</template>
<script type="text/ecmascript-6">
......@@ -112,7 +114,7 @@ export default {
mobile: 0,
code: 0
},
loginUrl: 'https://scrm.dev.glsx.com.cn/dj-scrm-wx-work-lwk/#/',
loginUrl: '',
};
},
watch: {
......@@ -131,170 +133,47 @@ export default {
deep: true
}
},
onLoad (options) {
this.loginUrl = `${this.loginUrl}?corpId=wwa55ffac1225eb25e&agentId=1000016&customLogin=1`
uni.$signHttp = new Request(uni.signHttpConfig) //重新登录重置请求参数
if (options.mobile) this.mobile = options.mobile
const noSignInUuid = uni.$storage.get('noSignInUuid')
if (noSignInUuid) this.autoLogin(noSignInUuid)
const {
deviceId
} = uni.getDeviceInfo()
this.deviceId = deviceId
async onLoad (options) {
this.init()
plus.navigator.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0')
},
methods: {
autoLoginByMobile () {
let { mobile, code } = this
if (code && mobile && code.length == 4 && phoneRex.test(mobile)) this.login()
},
handlerMessage ({ detail }) {
let { code } = detail.data[0]
uni.showLoading({
mask: true
})
setTimeout(() => {
uni.reLaunch({
url: '/pages/equity/index',
})
}, 2e3)
console.log(code, '=================')
},
copyText () {
uni.setClipboardData({
data: this.deviceId,
success: function () {
uni.showToast({
title: '复制成功',
icon: 'success'
});
}
});
},
async autoLogin (noSignInUuid) {
uni.showLoading({
mask: true
});
const { data } = await uni.$api.userApi.autoLogin({ noSignInUuid })
uni.hideLoading();
if (data) this.jump(data, true)
},
/**获取验证码 */
async getSmsCode () {
const { mobile, count } = this;
try {
if (!mobile) throw '请输入手机号';
if (!phoneRex.test(mobile)) throw '请输入正确的手机号';
if (count) throw '验证码发送过于频繁,请稍后再试';
uni.showLoading({
mask: true
});
const { code, message } = await uni.$api.userApi.getSmsCode({ mobile });
uni.hideLoading();
if (code == '0') {
uni.$logger.local.info(`${mobile}发送验证码成功`)
uni.showToast({
title: '验证码已发送',
icon: 'none',
});
this.countDown(60);
} else throw message || '发送验证码失败';
} catch (error) {
uni.$logger.local.info(`${mobile}发送验证码失败,失败原因:${error}`)
uni.hideLoading();
uni.showToast({
title: error,
icon: 'none',
});
}
},
/**验证码倒计时 */
countDown (countDown) {
if (countDown) this.count = countDown;
setTimeout(() => {
let { count } = this;
this.count = --count;
if (count > 0) this.countDown();
else this.count = null;
}, 1e3);
},
login: uni.$throttle(async function () {
const { mobile, code: smsCode, noSignIn, readingStatus } = this;
async login ({ detail }) {
try {
if (!mobile) throw '请输入手机号'
if (!phoneRex.test(mobile)) throw '请输入正确的手机号';
if (!smsCode) throw '请输入验证码'
if (!readingStatus) throw '请阅读用户隐私协议'
let params = {
mobile,
code: smsCode
}
if (noSignIn) params.noSignIn = noSignIn
let { code: authCode } = detail.data[0]
uni.showLoading({
title: '登录中...',
mask: true
});
const { code, data, message } = await uni.$api.userApi.smsLogin(params);
console.log(code, data, message);
uni.hideLoading();
if (code == 0) {
this.jump(data, noSignIn);
uni.$logger.local.info(`${mobile}登录`)
}
else {
uni.showModal({
title: '温馨提示',
content: message,
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF',
});
uni.$logger.local.info(`${mobile}登录失败,失败原因:${message}`)
}
})
const { data, msg, code } = await uni.$api.loginApi.login({
authCode
})
uni.hideLoading()
if (data) {
uni.$storage.set('userInfo', data)
uni.reLaunch({
url: '/pages/equity/index'
})
} else throw msg
} catch (error) {
uni.$logger.local.info(`${mobile}登录失败,失败原因:${error}`)
uni.hideLoading();
uni.showToast({
if (error) uni.showToast({
title: error,
icon: 'none',
});
icon: 'none'
})
this.loginUrl = ''
setTimeout(() => {
this.init()
}, 1.5e3)
}
}, 200),
// 获取登录账号下园区店列表
getAccountLoginList (loginUserInfoList) {
let stepIndex = loginUserInfoList?.length == 1 ? 1 : 0
uni.navigateTo({
url: `/pages/common/accountItems?stepIndex=${stepIndex}`
})
},
jumpUrl () {
let url = 'https://img01.glsx.com.cn/weapp/resource/saas/app/privacy.html'
uni.navigateTo({
url: `/pages/common/webview?url=${url}`
async init () {
uni.showLoading({
mask: true
})
},
jump (data, noSignIn) {
let {
loginUserInfoList,
noSignInUuid,
sessionId,
} = data;
if (loginUserInfoList.length) {
uni.$storage.set('sessionId', sessionId);
if (noSignInUuid && noSignIn) uni.$storage.set('noSignInUuid', noSignInUuid)
this.getAccountLoginList(loginUserInfoList)
} else uni.reLaunch({
url: '/pages/common/nothing'
});
},
input (e, key) {
setTimeout(() => {
let { value } = e.detail,
numbers = value.match(/\d+/g)
console.log(numbers)
this[key] = numbers ? numbers.join('') : ''
this.dateKey[key] = Date.now()
}, 0)
const { corpId, agentId } = await uni.$api.loginApi.getCorpInfo(),
{ loginUrl } = await uni.$api.loginApi.getLoginUrl()
uni.hideLoading()
this.loginUrl = `${loginUrl}?corpId=${corpId}&agentId=${agentId}&customLogin=1`
},
},
};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!