Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bigDataSystem
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
张伯涛
bigDataSystem
Commits
1e3c7ff8
Commit
1e3c7ff8
authored
Dec 20, 2024
by
chenjiahao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将前台所有页面加入白名单;修改登录逻辑
parent
582db30f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
23 deletions
+70
-23
pageEnum.ts
src/enums/pageEnum.ts
+8
-0
permissionGuard.ts
src/router/guard/permissionGuard.ts
+43
-10
user.ts
src/store/modules/user.ts
+16
-9
LoginForm.vue
src/views/AAAFont/Login/LoginForm.vue
+1
-0
index.vue
src/views/AAAFont/index.vue
+2
-4
No files found.
src/enums/pageEnum.ts
View file @
1e3c7ff8
export
enum
PageEnum
{
export
enum
PageEnum
{
// basic login path
// basic login path
BASE_LOGIN
=
'/login'
,
BASE_LOGIN
=
'/login'
,
// 前台登录页面
FONT_LOGIN
=
'/aaaFont/Login'
,
// 前台注册页面
FONT_REGISTER
=
'/aaaFont/register'
,
// 首页
HOME
=
'/aaaFont/font'
,
// font path
FONT
=
'/aaaFont'
,
// basic home path
// basic home path
BASE_HOME
=
'/dashboard'
,
BASE_HOME
=
'/dashboard'
,
// error page path
// error page path
...
...
src/router/guard/permissionGuard.ts
View file @
1e3c7ff8
...
@@ -6,14 +6,47 @@ import { PageEnum } from '@/enums/pageEnum';
...
@@ -6,14 +6,47 @@ import { PageEnum } from '@/enums/pageEnum';
import
{
useUserStoreWithOut
}
from
'@/store/modules/user'
;
import
{
useUserStoreWithOut
}
from
'@/store/modules/user'
;
import
{
PAGE_NOT_FOUND_ROUTE
}
from
'@/router/routes/basic'
;
import
{
PAGE_NOT_FOUND_ROUTE
}
from
'@/router/routes/basic'
;
import
{
PCFontRoute
}
from
'@/router/routes'
;
// import { RootRoute } from '@/router/routes';
// import { RootRoute } from '@/router/routes';
const
LOGIN_PATH
=
PageEnum
.
BASE_LOGIN
;
const
LOGIN_PATH
=
PageEnum
.
BASE_LOGIN
;
const
FONT
=
PageEnum
.
FONT
;
const
FONT_LOGIN
=
PageEnum
.
FONT_LOGIN
;
const
FONT_REGISTER
=
PageEnum
.
FONT_REGISTER
;
const
HOME
=
PageEnum
.
HOME
;
function
collectChildPaths
(
routes
,
prefix
)
{
let
paths
=
[];
function
traverseRoutes
(
routeConfig
)
{
if
(
routeConfig
.
path
.
startsWith
(
prefix
))
{
paths
.
push
(
routeConfig
.
path
);
// 如果有children属性,则递归遍历
if
(
Array
.
isArray
(
routeConfig
.
children
))
{
routeConfig
.
children
.
forEach
(
traverseRoutes
);
}
}
}
routes
.
forEach
(
traverseRoutes
);
return
paths
;
}
// 所有前台页面
const
allSubPaths
=
collectChildPaths
([
PCFontRoute
],
'/aaaFont'
);
// const ROOT_PATH = RootRoute.path;
// const ROOT_PATH = RootRoute.path;
const
whitePathList
:
PageEnum
[]
=
[
LOGIN_PATH
];
const
whitePathList
:
PageEnum
[]
=
[
LOGIN_PATH
,
FONT
,
FONT_LOGIN
,
FONT_REGISTER
,
HOME
,
...
allSubPaths
,
];
export
function
createPermissionGuard
(
router
:
Router
)
{
export
function
createPermissionGuard
(
router
:
Router
)
{
const
userStore
=
useUserStoreWithOut
();
const
userStore
=
useUserStoreWithOut
();
...
@@ -22,9 +55,9 @@ export function createPermissionGuard(router: Router) {
...
@@ -22,9 +55,9 @@ export function createPermissionGuard(router: Router) {
router
.
beforeEach
(
async
(
to
,
from
,
next
)
=>
{
router
.
beforeEach
(
async
(
to
,
from
,
next
)
=>
{
if
(
if
(
from
.
path
===
ROOT_PATH
&&
from
.
path
===
ROOT_PATH
&&
to
.
path
===
PageEnum
.
BASE_
HOME
&&
to
.
path
===
PageEnum
.
HOME
&&
userStore
.
getUserInfo
.
homePath
&&
userStore
.
getUserInfo
.
homePath
&&
userStore
.
getUserInfo
.
homePath
!==
PageEnum
.
BASE_
HOME
userStore
.
getUserInfo
.
homePath
!==
PageEnum
.
HOME
)
{
)
{
next
(
userStore
.
getUserInfo
.
homePath
);
next
(
userStore
.
getUserInfo
.
homePath
);
return
;
return
;
...
@@ -59,15 +92,15 @@ export function createPermissionGuard(router: Router) {
...
@@ -59,15 +92,15 @@ export function createPermissionGuard(router: Router) {
// redirect login page
// redirect login page
const
redirectData
:
{
path
:
string
;
replace
:
boolean
;
query
?:
Recordable
<
string
>
}
=
{
const
redirectData
:
{
path
:
string
;
replace
:
boolean
;
query
?:
Recordable
<
string
>
}
=
{
path
:
LOGIN_PATH
,
path
:
HOME
,
replace
:
true
,
replace
:
true
,
};
};
if
(
to
.
fullPath
)
{
//
if (to.fullPath) {
redirectData
.
query
=
{
//
redirectData.query = {
...
redirectData
.
query
,
//
...redirectData.query,
redirect
:
to
.
fullPath
,
//
redirect: to.fullPath,
};
//
};
}
//
}
next
(
redirectData
);
next
(
redirectData
);
return
;
return
;
}
}
...
...
src/store/modules/user.ts
View file @
1e3c7ff8
...
@@ -86,25 +86,26 @@ export const useUserStore = defineStore({
...
@@ -86,25 +86,26 @@ export const useUserStore = defineStore({
async
login
(
async
login
(
params
:
LoginParams
&
{
params
:
LoginParams
&
{
goHome
?:
boolean
;
goHome
?:
boolean
;
goFont
?:
boolean
;
mode
?:
ErrorMessageMode
;
mode
?:
ErrorMessageMode
;
},
},
):
Promise
<
any
|
null
>
{
):
Promise
<
any
|
null
>
{
try
{
try
{
const
{
goHome
=
true
,
mode
,
...
loginParams
}
=
params
;
const
{
goHome
=
true
,
goFont
=
false
,
mode
,
...
loginParams
}
=
params
;
// 1、调用登录接口
// 1、调用登录接口
const
data
=
await
loginApi
(
loginParams
,
mode
);
const
data
=
await
loginApi
(
loginParams
,
mode
);
const
token
=
data
.
data
;
const
token
=
data
.
data
;
// 2、设置 token,并存储本地缓存。
// 2、设置 token,并存储本地缓存。
this
.
setToken
(
token
);
this
.
setToken
(
token
);
return
this
.
afterLoginAction
(
goHome
);
return
this
.
afterLoginAction
(
goHome
,
goFont
);
}
catch
(
error
)
{
}
catch
(
error
)
{
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
}
}
},
},
async
afterLoginAction
(
goHome
?:
boolean
):
Promise
<
any
|
null
>
{
async
afterLoginAction
(
goHome
?:
boolean
,
goFont
?:
boolean
):
Promise
<
any
|
null
>
{
if
(
!
this
.
getToken
)
return
null
;
if
(
!
this
.
getToken
)
return
null
;
// 3、获取用户信息
// 3、获取用户信息
const
userInfo
=
await
this
.
getUserInfoAction
();
const
userInfo
=
await
this
.
getUserInfoAction
(
goFont
);
console
.
log
(
'userInfo'
,
userInfo
);
console
.
log
(
'userInfo'
,
userInfo
);
const
sessionTimeout
=
this
.
sessionTimeout
;
const
sessionTimeout
=
this
.
sessionTimeout
;
if
(
sessionTimeout
)
{
if
(
sessionTimeout
)
{
...
@@ -122,11 +123,11 @@ export const useUserStore = defineStore({
...
@@ -122,11 +123,11 @@ export const useUserStore = defineStore({
permissionStore
.
setDynamicAddedRoute
(
true
);
permissionStore
.
setDynamicAddedRoute
(
true
);
}
}
goHome
&&
(
await
router
.
replace
(
userInfo
?.
homePath
||
PageEnum
.
BASE_
HOME
));
goHome
&&
(
await
router
.
replace
(
userInfo
?.
homePath
||
PageEnum
.
HOME
));
}
}
return
userInfo
;
return
userInfo
;
},
},
async
getUserInfoAction
():
Promise
<
UserInfo
|
null
>
{
async
getUserInfoAction
(
goFont
=
false
):
Promise
<
UserInfo
|
null
>
{
if
(
!
this
.
getToken
)
return
null
;
if
(
!
this
.
getToken
)
return
null
;
let
userInfo
;
let
userInfo
;
let
type
=
localStorage
.
getItem
(
'type'
);
let
type
=
localStorage
.
getItem
(
'type'
);
...
@@ -211,7 +212,11 @@ export const useUserStore = defineStore({
...
@@ -211,7 +212,11 @@ export const useUserStore = defineStore({
const
firstChild
=
await
this
.
getFirstChild
(
userInfo
.
data
.
menus
[
0
]);
const
firstChild
=
await
this
.
getFirstChild
(
userInfo
.
data
.
menus
[
0
]);
console
.
log
(
'firstChild'
,
firstChild
);
console
.
log
(
'firstChild'
,
firstChild
);
// 登陆后进入的第一个页面
// 登陆后进入的第一个页面
userInfo
.
data
.
homePath
=
firstChild
;
if
(
goFont
)
{
userInfo
.
data
.
homePath
=
PageEnum
.
HOME
;
}
else
{
userInfo
.
data
.
homePath
=
firstChild
;
}
localStorage
.
setItem
(
'firstChild'
,
firstChild
);
localStorage
.
setItem
(
'firstChild'
,
firstChild
);
// 设置用户信息,并存储本地缓存
// 设置用户信息,并存储本地缓存
this
.
setUserInfo
(
userInfo
.
data
);
this
.
setUserInfo
(
userInfo
.
data
);
...
@@ -240,8 +245,10 @@ export const useUserStore = defineStore({
...
@@ -240,8 +245,10 @@ export const useUserStore = defineStore({
this
.
setSessionTimeout
(
false
);
this
.
setSessionTimeout
(
false
);
this
.
setUserInfo
(
null
);
this
.
setUserInfo
(
null
);
if
(
goLogin
)
{
if
(
goLogin
)
{
// 直接回登陆页
// // 直接回登陆页
router
.
replace
(
PageEnum
.
BASE_LOGIN
);
// router.replace(PageEnum.BASE_LOGIN);
// 直接回首页
router
.
replace
(
PageEnum
.
HOME
);
}
else
{
}
else
{
// 回登陆页带上当前路由地址
// 回登陆页带上当前路由地址
router
.
replace
({
router
.
replace
({
...
...
src/views/AAAFont/Login/LoginForm.vue
View file @
1e3c7ff8
...
@@ -168,6 +168,7 @@
...
@@ -168,6 +168,7 @@
const
userInfo
=
await
userStore
.
login
({
const
userInfo
=
await
userStore
.
login
({
password
:
data
.
password
,
password
:
data
.
password
,
username
:
data
.
account
,
username
:
data
.
account
,
goFont
:
true
,
mode
:
'none'
,
//不要默认的错误提示
mode
:
'none'
,
//不要默认的错误提示
});
});
console
.
log
(
'userInfo'
,
userInfo
);
console
.
log
(
'userInfo'
,
userInfo
);
...
...
src/views/AAAFont/index.vue
View file @
1e3c7ff8
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
</el-menu>
</el-menu>
</div>
</div>
<div
class=
"right-div"
>
<div
class=
"right-div"
>
<div
v-if=
"isLogin"
<div
v-if=
"
!
isLogin"
><el-button
plain
class=
"long_btn"
@
click=
"login"
>
登录
</el-button>
><el-button
plain
class=
"long_btn"
@
click=
"login"
>
登录
</el-button>
<el-button
<el-button
class=
"long_btn"
class=
"long_btn"
...
@@ -147,9 +147,7 @@
...
@@ -147,9 +147,7 @@
},
},
mounted
()
{
mounted
()
{
console
.
log
(
getToken
());
console
.
log
(
getToken
());
if
(
getToken
())
{
this
.
isLogin
=
!!
getToken
();
this
.
isLogin
=
false
;
}
// window.addEventListener('.el-main', this.handleScroll)
// window.addEventListener('.el-main', this.handleScroll)
},
},
methods
:
{
methods
:
{
...
...
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