Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qr-consistency-vue3
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘怀志
qr-consistency-vue3
Commits
598cd7de
Commit
598cd7de
authored
Apr 17, 2025
by
qiyaxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
iam系统对接-登录完善
parent
53c55e16
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
5 deletions
+80
-5
.env.development
.env.development
+3
-0
.env.production
.env.production
+4
-1
.env.staging
.env.staging
+4
-1
permission.js
src/permission.js
+53
-3
login.vue
src/views/login.vue
+16
-0
No files found.
.env.development
View file @
598cd7de
...
...
@@ -6,3 +6,6 @@ VITE_APP_ENV = 'development'
# 奇瑞一致性/开发环境
VITE_APP_BASE_API = '/dev-api'
# 奇瑞一致性/开发环境登录路由
VITE_APP_LOGIN_ROUTE = '/login'
.env.production
View file @
598cd7de
...
...
@@ -8,4 +8,7 @@ VITE_APP_ENV = 'production'
VITE_APP_BASE_API = '/prod-api'
# 是否在打包时开启压缩,支持 gzip 和 brotli
VITE_BUILD_COMPRESS = gzip
\ No newline at end of file
VITE_BUILD_COMPRESS = gzip
# 奇瑞一致性/生产环境登录路由
VITE_APP_LOGIN_ROUTE = 'https://iamuat.mychery.com:5443/idp/oauth2/authorize?client_id=FACTS&redirect_uri=http://106.3.99.64:20073/login&response_type=code'
.env.staging
View file @
598cd7de
...
...
@@ -8,4 +8,7 @@ VITE_APP_ENV = 'staging'
VITE_APP_BASE_API = 'http://106.3.99.64:20073/chery-api/'
# 是否在打包时开启压缩,支持 gzip 和 brotli
VITE_BUILD_COMPRESS = gzip
\ No newline at end of file
VITE_BUILD_COMPRESS = gzip
# 奇瑞一致性/生产环境登录路由
VITE_APP_LOGIN_ROUTE = 'https://iamuat.mychery.com:5443/idp/oauth2/authorize?client_id=FACTS&redirect_uri=http://106.3.99.64:20073/login&response_type=code'
src/permission.js
View file @
598cd7de
...
...
@@ -8,6 +8,7 @@ import { isRelogin } from '@/utils/request'
import
useUserStore
from
'@/store/modules/user'
import
useSettingsStore
from
'@/store/modules/settings'
import
usePermissionStore
from
'@/store/modules/permission'
import
axios
from
'axios'
NProgress
.
configure
({
showSpinner
:
false
})
...
...
@@ -17,6 +18,12 @@ const isWhiteList = (path) => {
return
whiteList
.
some
((
pattern
)
=>
isPathMatch
(
pattern
,
path
))
}
// 后端登录接口
const
loginBySSOApi
=
'/auth/loginBySSO'
const
unifiedLoginRoute
=
'/login'
// 登录路由
const
loginRoute
=
import
.
meta
.
env
.
VITE_APP_LOGIN_ROUTE
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
NProgress
.
start
()
if
(
getToken
())
{
...
...
@@ -59,16 +66,59 @@ router.beforeEach((to, from, next) => {
next
()
}
}
}
else
{
}
// //若依系统登录
// else {
// // 没有token
// if (isWhiteList(to.path)) {
// // 在免登录白名单,直接进入
// next()
// } else {
// next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
// NProgress.done()
// }
// }
//iam系统登录
else
{
// 没有token
if
(
isWhiteList
(
to
.
path
))
{
// 在免登录白名单,直接进入
next
()
if
(
to
.
path
===
unifiedLoginRoute
)
{
// 从URL中截取code参数
const
urlParams
=
new
URLSearchParams
(
window
.
location
.
search
)
const
code
=
urlParams
.
get
(
'code'
)
if
(
code
)
{
// 请求后端/auth/loginBySSO接口
axios
.
post
(
loginBySSOApi
,
{
ticket
:
code
})
.
then
((
response
)
=>
{
if
(
response
.
data
.
success
)
{
// 登录成功,跳转到首页
next
({
path
:
'/'
})
}
else
{
ElMessage
.
error
(
'登录失败,请重试'
)
next
()
}
})
.
catch
((
error
)
=>
{
ElMessage
.
error
(
'登录请求出错,请重试'
)
next
()
})
}
else
{
next
()
}
}
else
{
next
()
}
}
else
{
next
(
`/login?redirect=
${
to
.
fullPath
}
`
)
// 否则全部重定向到登录页
// 跳转到IAM登录页面
window
.
location
.
href
=
loginRoute
NProgress
.
done
()
}
}
})
router
.
afterEach
(()
=>
{
...
...
src/views/login.vue
View file @
598cd7de
...
...
@@ -86,6 +86,11 @@ import { getCodeImg } from '@/api/login'
import
Cookies
from
'js-cookie'
import
{
encrypt
,
decrypt
}
from
'@/utils/jsencrypt'
import
useUserStore
from
'@/store/modules/user'
// import { useRoute, useRouter } from 'vue-router'
// import { getCurrentInstance } from 'vue'
// 引入环境变量
const
loginRoute
=
import
.
meta
.
env
.
VITE_APP_LOGIN_ROUTE
const
title
=
import
.
meta
.
env
.
VITE_APP_TITLE
const
userStore
=
useUserStore
()
...
...
@@ -124,6 +129,17 @@ watch(
)
function
handleLogin
()
{
// 不是开发环境
if
(
loginRoute
!==
"/login"
){
// 检查路径中是否有 code 参数,没有就跳转至iam登录页面
const
urlParams
=
new
URLSearchParams
(
window
.
location
.
search
)
const
code
=
urlParams
.
get
(
'code'
)
if
(
!
code
)
{
window
.
location
.
href
=
loginRoute
return
}
}
proxy
.
$refs
.
loginRef
.
validate
((
valid
)
=>
{
if
(
valid
)
{
loading
.
value
=
true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment