Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
scrm-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 15f3a866
authored
Nov 08, 2023
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改登录验证逻辑
1 parent
c63e6734
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
60 deletions
src/config/index.js
src/layout/components/SubMenuItem.vue
src/store/modules/app.js
src/views/Login.vue
src/config/index.js
View file @
15f3a86
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
* @Author: limin
* @Author: limin
* @Date: 2021-06-07 14:12:32
* @Date: 2021-06-07 14:12:32
* @LastEditors: limin
* @LastEditors: limin
* @LastEditTime: 2023-1
0-07 10:01:47
* @LastEditTime: 2023-1
1-08 15:32:46
*/
*/
// 根据环境引入不同配置 process.env.VUE_APP_ENV
// 根据环境引入不同配置 process.env.VUE_APP_ENV
let
cfg
=
require
(
'./conf.js'
)
let
cfg
=
require
(
'./conf.js'
)
...
@@ -25,7 +25,7 @@ export const fetchConfig = (isEnv = sw) => {
...
@@ -25,7 +25,7 @@ export const fetchConfig = (isEnv = sw) => {
if
((
_config
&&
!
_constRoutes
.
includes
(
_pathname
))
||
_pathname
===
_login_path
||
(
_pathname
===
'/'
&&
_login_path
===
'/login'
))
{
if
((
_config
&&
!
_constRoutes
.
includes
(
_pathname
))
||
_pathname
===
_login_path
||
(
_pathname
===
'/'
&&
_login_path
===
'/login'
))
{
return
Promise
.
resolve
(
_config
)
return
Promise
.
resolve
(
_config
)
}
}
return
new
Http
({
headers
:
{
refererurl
:
_pathname
},
request
:
{
timeout
:
30000
}
}).
get
(
'https://oss-config.
test
.glsx.com.cn/mock/6136bea6ceeb5a5c2bec6950/base/config'
)
return
new
Http
({
headers
:
{
refererurl
:
_pathname
},
request
:
{
timeout
:
30000
}
}).
get
(
'https://oss-config.
dev
.glsx.com.cn/mock/6136bea6ceeb5a5c2bec6950/base/config'
)
}
}
export
const
config
=
{
export
const
config
=
{
install
(
vue
,
cfg
)
{
install
(
vue
,
cfg
)
{
...
...
src/layout/components/SubMenuItem.vue
View file @
15f3a86
...
@@ -26,9 +26,6 @@ export default {
...
@@ -26,9 +26,6 @@ export default {
this
.
$router
.
push
(
path
)
this
.
$router
.
push
(
path
)
}
}
}
}
},
mounted
(){
console
.
log
(
this
.
menuItems
);
}
}
}
}
</
script
>
</
script
>
...
...
src/store/modules/app.js
View file @
15f3a86
...
@@ -126,6 +126,7 @@ function getMenuItem(moduleName, menus) {
...
@@ -126,6 +126,7 @@ function getMenuItem(moduleName, menus) {
const
flattenMenus
=
utils
.
array
.
flattenDeep
(
menus
)
const
flattenMenus
=
utils
.
array
.
flattenDeep
(
menus
)
for
(
let
i
=
0
,
j
=
flattenMenus
.
length
;
i
<
j
;
i
++
)
{
for
(
let
i
=
0
,
j
=
flattenMenus
.
length
;
i
<
j
;
i
++
)
{
const
menu
=
flattenMenus
[
i
]
const
menu
=
flattenMenus
[
i
]
if
(
menu
.
path
===
'^'
)
continue
const
route
=
__gen
(
moduleName
,
menu
)
const
route
=
__gen
(
moduleName
,
menu
)
router
.
addRoute
(
route
)
router
.
addRoute
(
route
)
}
}
...
@@ -134,7 +135,7 @@ function getMenuItem(moduleName, menus) {
...
@@ -134,7 +135,7 @@ function getMenuItem(moduleName, menus) {
/**
/**
* 生成动态路由参数
* 生成动态路由参数
*/
*/
function
__gen
(
moduleName
,
menu
)
{
/*
function __gen(moduleName, menu) {
let { path, meta = {}, id, title, url, children, hidden = false } = menu
let { path, meta = {}, id, title, url, children, hidden = false } = menu
let _path = ''
let _path = ''
let redirect = ''
let redirect = ''
...
@@ -166,6 +167,28 @@ function __gen(moduleName, menu) {
...
@@ -166,6 +167,28 @@ function __gen(moduleName, menu) {
meta: { ...meta, id, title, name, url, path: _path, hidden }
meta: { ...meta, id, title, name, url, path: _path, hidden }
}
}
return route
return route
}*/
function
__gen
(
moduleName
,
menu
)
{
let
{
path
,
meta
=
{},
id
,
title
,
url
,
hidden
=
false
}
=
menu
let
_path
=
_get_path_
(
moduleName
,
path
)
//路由path生成name 如 home/home/index =>HomeHomeIndex
//排除 以:开头 比如 home/home/index/:id 参数:id 不参与生成规则
//name 主要用于 子系统内部 params传参 如 this.$router.push({name:'HomeHomeIndex',params:{id:123}})
const
name
=
_path
.
split
(
'/'
).
reduce
((
t
,
n
)
=>
{
if
(
!
n
.
startsWith
(
':'
))
{
t
+=
n
.
charAt
(
0
).
toUpperCase
()
+
n
.
slice
(
1
)
}
return
t
},
''
)
menu
.
path
=
_path
const
route
=
{
path
:
_path
,
component
:
Layout
,
name
,
meta
:
{
...
meta
,
id
,
title
,
name
,
url
,
path
:
_path
,
hidden
}
}
return
route
}
}
/**
/**
...
@@ -181,8 +204,8 @@ function getDefaultPath(menu) {
...
@@ -181,8 +204,8 @@ function getDefaultPath(menu) {
/**
/**
* 递归获取无实际路径的菜单下的第一个子菜单的路径
* 递归获取无实际路径的菜单下的第一个子菜单的路径
* @param {*} menus
* @param {*} menus
* @returns
* @returns
*/
*/
function
_loop
(
menus
)
{
function
_loop
(
menus
)
{
const
{
path
}
=
menus
.
noHidden
()[
0
]
const
{
path
}
=
menus
.
noHidden
()[
0
]
...
...
src/views/Login.vue
View file @
15f3a86
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
<span
class=
"title"
>
请选择登录商户号
</span>
<span
class=
"title"
>
请选择登录商户号
</span>
<GLScroll
class=
"login-merchants-scroll"
>
<GLScroll
class=
"login-merchants-scroll"
>
<div
class=
"item-wrap"
>
<div
class=
"item-wrap"
>
<div
class=
"merchant-item"
v-for=
"merchant in merchants"
:key=
"merchant.merchantId"
@
click
.
stop=
"loginChoose(merchant
.merchantId
)"
>
<div
class=
"merchant-item"
v-for=
"merchant in merchants"
:key=
"merchant.merchantId"
@
click
.
stop=
"loginChoose(merchant)"
>
<i
class=
"i i-dot"
></i>
<i
class=
"i i-dot"
></i>
<div
class=
"merchant-info"
>
<div
class=
"merchant-info"
>
<div
class=
"merchant-item-name"
>
{{
merchant
.
merchantName
}}
</div>
<div
class=
"merchant-item-name"
>
{{
merchant
.
merchantName
}}
</div>
...
@@ -73,7 +73,7 @@
...
@@ -73,7 +73,7 @@
</div>
</div>
</div>
</div>
</div>
</div>
<LoginSMSCodeCheck
:visible
.
sync=
"smsCodeDialogVisible"
:checkProps=
"smsCheckProps"
@
onSuccess=
"afterVerify"
></LoginSMSCodeCheck>
<LoginSMSCodeCheck
:visible
.
sync=
"smsCodeDialogVisible"
:checkProps=
"smsCheckProps"
@
onSuccess=
"afterVerify
Phone
"
></LoginSMSCodeCheck>
</div>
</div>
</
template
>
</
template
>
...
@@ -124,12 +124,10 @@ export default {
...
@@ -124,12 +124,10 @@ export default {
rules
:
RULES
,
rules
:
RULES
,
//手机号验证组件所需参数
//手机号验证组件所需参数
smsCheckProps
:
{
smsCheckProps
:
{
sessionId
:
''
,
mobile
:
'13800138000'
mobile
:
'13800138000'
},
},
//登录成功后,短信验证前保存的登录数据
isPrivacyChecked
:
true
,
loginSuccessData
:
{},
chooseMerchant
:
null
isPrivacyChecked
:
true
}
}
},
},
watch
:
{
watch
:
{
...
@@ -178,10 +176,8 @@ export default {
...
@@ -178,10 +176,8 @@ export default {
const loginData = Object.assign({ loginSource, productCode }, this.loginForm, { password: md5(this.loginForm.password).toLowerCase() })
const loginData = Object.assign({ loginSource, productCode }, this.loginForm, { password: md5(this.loginForm.password).toLowerCase() })
let { code, data, message } = await api.app.login(loginData)
let { code, data, message } = await api.app.login(loginData)
if (code === response.code_success_value) {
if (code === response.code_success_value) {
//将登录成功信息存起来。当短信验证完后,需要用来走后面的流程
this.loginSuccessData = data
//调接口判断是否要验证短信验证码
//调接口判断是否要验证短信验证码
this.
verifyPhone
(data)
this.
checkMutilMerchants
(data)
} else {
} else {
this.error(message)
this.error(message)
}
}
...
@@ -189,28 +185,27 @@ export default {
...
@@ -189,28 +185,27 @@ export default {
})
})
}, 500),
}, 500),
/**
/**
*
验证完短信,
判断是否绑定多个商户。如果有多个,则打开选择界面
* 判断是否绑定多个商户。如果有多个,则打开选择界面
* 如果只有一个,
则直接获取权限信息
* 如果只有一个,
直接判断是否要验证短信验证码
*/
*/
afterVerify(
) {
checkMutilMerchants(data
) {
const { loginList: merchants, loginToken } =
this.loginSuccessD
ata
const { loginList: merchants, loginToken } =
d
ata
if (merchants.length > 1) {
if (merchants.length > 1) {
this.loginForm.loginToken = loginToken
this.loginForm.loginToken = loginToken
this.merchants =
merchants
this.merchants =
Object.freeze(merchants)
this.doAnimate()
this.doAnimate()
this.isHasMutilMerchants = true
this.isHasMutilMerchants = true
} else {
} else {
this.
_permission
(merchants[0])
this.
verifyPhone
(merchants[0])
}
}
},
},
/**
/**
* 获取商户下的菜单信息
* 获取商户下的菜单信息
*/
*/
async _permission(merchant) {
async _permission(merchant) {
let { response, track } = this.$config
try {
try {
merchant.pw = md5(this.loginForm.password)
let { response, track } = this.$config
const { code, message, menus, sessionData } = await this.permission(
merchant
)
const { code, message, menus, sessionData } = await this.permission(
Object.assign({ pw: md5(this.loginForm.password) }, merchant)
)
if (code == response.code_success_value) {
if (code == response.code_success_value) {
const { defaultPath } = await this.login(menus)
const { defaultPath } = await this.login(menus)
this.isLogin = false
this.isLogin = false
...
@@ -237,12 +232,51 @@ export default {
...
@@ -237,12 +232,51 @@ export default {
* 1.获取选择的商户信息
* 1.获取选择的商户信息
* 2.获取菜单信息并登录
* 2.获取菜单信息并登录
*/
*/
loginChoose: utils.debounce(async function (merchantId) {
loginChoose: utils.debounce(async function (merchant) {
const { response, loginSource } = this.$config
this.verifyPhone(merchant)
const { userName: loginAccount, loginToken } = this.loginForm
const { code, message, data } = await api.app.choose({ merchantId, loginAccount, loginToken, loginSource })
~[() => this.error(message), () => this._permission(data)][+(code === response.code_success_value)].call()
}, 2000),
}, 2000),
/**
* 登录成功,验证本账号是否需要短信验证登录
* 如果不需要验证,直接调取是否选择门店方法
* 如果需要验证,弹出验证窗口
*/
async verifyPhone(merchant) {
try {
let { response } = this.$config
const loginAccount = this.loginForm.userName
const { merchantId, userType } = merchant
const { code, message, data: mobile } = await api.app.verifyPhone({ loginAccount, merchantId, userType })
if (code == response.code_success_value) {
if (mobile) {
this.chooseMerchant = Object.freeze(merchant)
this.smsCodeDialogVisible = true
Object.assign(this.smsCheckProps, { mobile })
} else {
this._permission(merchant)
}
} else {
this.error(message)
}
} catch (error) {
this.error(error.message, ERROR_TYPE.MESSAGE)
}
},
async afterVerifyPhone() {
//如果是多商户,需要重新登录 并获取菜单信息
if (this.isHasMutilMerchants) {
const { response, loginSource } = this.$config
const { userName: loginAccount, loginToken } = this.loginForm
const { code, message, data: merchant } = await api.app.choose({ merchantId: this.chooseMerchant.merchantId, loginAccount, loginToken, loginSource })
~[() => this.error(message), () => this._permission(merchant)][+(code === response.code_success_value)].call()
} else {
//如果是单商户,直接获取菜单信息
this._permission(this.chooseMerchant)
}
},
storeConfig() {
utils.storage.setSession(constants.SCRM_BASE_CONFIG, this.$config)
},
async getCode() {
async getCode() {
this.loginForm.code = ''
this.loginForm.code = ''
sessionStorage.clear()
sessionStorage.clear()
...
@@ -276,35 +310,6 @@ export default {
...
@@ -276,35 +310,6 @@ export default {
this.getCode()
this.getCode()
this.isHasMutilMerchants = false
this.isHasMutilMerchants = false
},
},
/**
* 登录成功,验证本账号是否需要短信验证登录
* 如果不需要验证,直接调取是否选择门店方法
* 如果需要验证,弹出验证窗口
*/
async verifyPhone() {
const loginData = this.loginSuccessData
let { response } = this.$config
try {
const loginAccount = this.loginForm.userName
const sessionId = loginData.loginList[0]?.sessionId
const { code, message, data: mobile } = await api.app.verifyPhone({ loginAccount, sessionId })
if (code == response.code_success_value) {
if (mobile) {
this.smsCodeDialogVisible = true
Object.assign(this.smsCheckProps, { sessionId, mobile })
} else {
this.afterVerify()
}
} else {
this.error(message)
}
} catch (error) {
this.error(error.message, ERROR_TYPE.MESSAGE)
}
},
storeConfig() {
utils.storage.setSession(constants.SCRM_BASE_CONFIG, this.$config)
},
...mapActions('app', ['login']),
...mapActions('app', ['login']),
...mapActions('auth', ['permission', 'setSession']),
...mapActions('auth', ['permission', 'setSession']),
...mapActions('track', ['setTracker'])
...mapActions('track', ['setTracker'])
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment