Commit 1f3ca374 by 李伟康

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

新增 loginApi 模块,支持通过企业微信扫码登录;
调整登录页面逻辑,动态获取登录链接及企业信息;
重构 http 请求模块,增加 shukeRequest 方法以支持新接口;
更新环境配置,添加 shukeDomain 域名映射;
优化 loading 页面逻辑,简化用户登录后的跳转判断。
1 parent 53eb1073
...@@ -10,6 +10,7 @@ import sceneMarketApi from './sceneMarketApi' ...@@ -10,6 +10,7 @@ import sceneMarketApi from './sceneMarketApi'
import interceptionApi from './interceptionApi' import interceptionApi from './interceptionApi'
import popupApi from './popupApi' import popupApi from './popupApi'
import usedCarApi from './usedCar' import usedCarApi from './usedCar'
import loginApi from './loginApi'
module.exports = { module.exports = {
commonApi, commonApi,
...@@ -23,5 +24,6 @@ module.exports = { ...@@ -23,5 +24,6 @@ module.exports = {
interceptionApi, interceptionApi,
popupApi, popupApi,
evaluationApi, 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 \ No newline at end of file
import sign from './sign.js' 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 = { const HOST = {
scrm: domain, scrm: domain,
dj: djDomain, dj: djDomain,
...@@ -7,13 +7,13 @@ const HOST = { ...@@ -7,13 +7,13 @@ const HOST = {
ip: 'http://192.168.1.125:8080' ip: 'http://192.168.1.125:8080'
} }
class Request { class Request {
get(params, returnAll = false, hostType) { get (params, returnAll = false, hostType) {
return this.request('GET', params, returnAll, 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) return this.request('POST', params, returnAll, hostType)
} }
fetch(method, data, returnAll = true, hostType) { fetch (method, data, returnAll = true, hostType) {
return this.post( return this.post(
{ {
method, method,
...@@ -23,11 +23,11 @@ class Request { ...@@ -23,11 +23,11 @@ class Request {
hostType hostType
) )
} }
request(RequestMethods, params, returnAll, hostType = 'dj') { request (RequestMethods, params, returnAll, hostType = 'dj') {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let _this = this let _this = this
uni.getNetworkType({ uni.getNetworkType({
success(res) { success (res) {
if (res.networkType == 'none') { if (res.networkType == 'none') {
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
...@@ -40,11 +40,11 @@ class Request { ...@@ -40,11 +40,11 @@ class Request {
let header = let header =
RequestMethods === 'POST' 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 let projectName = params.projectName
if (!projectName) projectName = _this.getRopProject(params.method) if (!projectName) projectName = _this.getRopProject(params.method)
const path = pathEnum[projectName] const path = pathEnum[projectName]
...@@ -56,7 +56,7 @@ class Request { ...@@ -56,7 +56,7 @@ class Request {
header, header,
dataType: 'json', dataType: 'json',
responseType: 'text', responseType: 'text',
success(response) { success (response) {
/**业务代码 */ /**业务代码 */
let { data, statusCode } = response let { data, statusCode } = response
if (!data || statusCode != 200) { if (!data || statusCode != 200) {
...@@ -92,7 +92,7 @@ class Request { ...@@ -92,7 +92,7 @@ class Request {
} }
} }
}, },
fail(error) { fail (error) {
uni.hideLoading() uni.hideLoading()
console.error(`${params.method}接口异常:`, error) console.error(`${params.method}接口异常:`, error)
uni.showToast({ uni.showToast({
...@@ -101,7 +101,7 @@ class Request { ...@@ -101,7 +101,7 @@ class Request {
}) })
reject(error) reject(error)
}, },
complete() { complete () {
uni.stopPullDownRefresh() uni.stopPullDownRefresh()
} }
}) })
...@@ -109,7 +109,7 @@ class Request { ...@@ -109,7 +109,7 @@ class Request {
}) })
}) })
} }
getData(params, hostType = 'scrm') { getData (params, hostType = 'scrm') {
let projectName = params.projectName let projectName = params.projectName
if (!projectName) projectName = this.getRopProject(params.method) if (!projectName) projectName = this.getRopProject(params.method)
else delete params.projectName else delete params.projectName
...@@ -141,11 +141,11 @@ class Request { ...@@ -141,11 +141,11 @@ class Request {
params.appKey = appKey params.appKey = appKey
return sign(params, secret, noSignAttr) return sign(params, secret, noSignAttr)
} }
getRopProject(method) { getRopProject (method) {
const projectName = method.split('.')[2] const projectName = method.split('.')[2]
return projectName 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 => { return new Promise(resolve => {
uni.request({ uni.request({
url, url,
...@@ -154,12 +154,55 @@ class Request { ...@@ -154,12 +154,55 @@ class Request {
header, header,
dataType, dataType,
responseType, responseType,
success(response) { success (response) {
resolve(response.data) 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() export default new Request()
const target = ['ip', 'dev', 'uat', 'prod', 'beta'] const target = ['ip', 'dev', 'uat', 'prod', 'beta']
const index = 4 const index = 1
/** /**
* *
0本地 0本地
...@@ -77,6 +77,13 @@ const merchantDomain = { ...@@ -77,6 +77,13 @@ const merchantDomain = {
pet: '' pet: ''
}[target[index]] }[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 = { const djSecretKey = {
ip: { appKey: '48e5e13229b82c1b4e6e8c96151f0637', secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b' }, ip: { appKey: '48e5e13229b82c1b4e6e8c96151f0637', secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b' },
dev: { dev: {
...@@ -178,5 +185,6 @@ module.exports = { ...@@ -178,5 +185,6 @@ module.exports = {
merchantDomain, merchantDomain,
djSecretKey, djSecretKey,
signSecretKey, signSecretKey,
evaluationDomain evaluationDomain,
shukeDomain
} }
...@@ -10,23 +10,13 @@ export default { ...@@ -10,23 +10,13 @@ export default {
}, },
mounted () { mounted () {
uni.showLoading({ uni.showLoading({
mask: true mask: true
}) })
let userInfo = uni.$storage.get('userInfo') let userInfo = uni.$storage.get('userInfo')
if (userInfo && userInfo.sceneType != undefined && userInfo.sceneType != null) { if (userInfo) {
uni.$api.userApi.getListSelectAccount().then(res => { uni.reLaunch({
uni.hideLoading() url: '/pages/equity/index'
setTimeout(() => { })
if (res.code == 0) {
uni.reLaunch({
url: '/pages/equity/index'
})
}
else this.toLogin()
}, 500)
}).catch(() => [
this.toLogin()
])
} else this.toLogin() } else this.toLogin()
}, },
methods: { methods: {
......
...@@ -91,10 +91,12 @@ ...@@ -91,10 +91,12 @@
@click="copyText" @click="copyText"
></view> ></view>
</view> --> </view> -->
<web-view <template v-if="loginUrl">
:src="loginUrl" <web-view
@message="handlerMessage" :src="loginUrl"
/> @message="login"
/>
</template>
</view> </view>
</template> </template>
<script type="text/ecmascript-6"> <script type="text/ecmascript-6">
...@@ -112,7 +114,7 @@ export default { ...@@ -112,7 +114,7 @@ export default {
mobile: 0, mobile: 0,
code: 0 code: 0
}, },
loginUrl: 'https://scrm.dev.glsx.com.cn/dj-scrm-wx-work-lwk/#/', loginUrl: '',
}; };
}, },
watch: { watch: {
...@@ -131,170 +133,47 @@ export default { ...@@ -131,170 +133,47 @@ export default {
deep: true deep: true
} }
}, },
onLoad (options) { async onLoad (options) {
this.loginUrl = `${this.loginUrl}?corpId=wwa55ffac1225eb25e&agentId=1000016&customLogin=1` this.init()
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
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') 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: { methods: {
autoLoginByMobile () { async login ({ detail }) {
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;
try { try {
if (!mobile) throw '请输入手机号' let { code: authCode } = detail.data[0]
if (!phoneRex.test(mobile)) throw '请输入正确的手机号';
if (!smsCode) throw '请输入验证码'
if (!readingStatus) throw '请阅读用户隐私协议'
let params = {
mobile,
code: smsCode
}
if (noSignIn) params.noSignIn = noSignIn
uni.showLoading({ uni.showLoading({
title: '登录中...',
mask: true mask: true
}); })
const { code, data, message } = await uni.$api.userApi.smsLogin(params); const { data, msg, code } = await uni.$api.loginApi.login({
console.log(code, data, message); authCode
uni.hideLoading(); })
if (code == 0) { uni.hideLoading()
this.jump(data, noSignIn); if (data) {
uni.$logger.local.info(`${mobile}登录`) uni.$storage.set('userInfo', data)
} uni.reLaunch({
else { url: '/pages/equity/index'
uni.showModal({ })
title: '温馨提示', } else throw msg
content: message,
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF',
});
uni.$logger.local.info(`${mobile}登录失败,失败原因:${message}`)
}
} catch (error) { } catch (error) {
uni.$logger.local.info(`${mobile}登录失败,失败原因:${error}`) if (error) uni.showToast({
uni.hideLoading();
uni.showToast({
title: error, 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 () { async init () {
let url = 'https://img01.glsx.com.cn/weapp/resource/saas/app/privacy.html' uni.showLoading({
uni.navigateTo({ mask: true
url: `/pages/common/webview?url=${url}`
}) })
}, const { corpId, agentId } = await uni.$api.loginApi.getCorpInfo(),
jump (data, noSignIn) { { loginUrl } = await uni.$api.loginApi.getLoginUrl()
let { uni.hideLoading()
loginUserInfoList, this.loginUrl = `${loginUrl}?corpId=${corpId}&agentId=${agentId}&customLogin=1`
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)
}, },
}, },
}; };
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!