Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
op-web-service
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
bp
op-web-service
Commits
a72f3958
Commit
a72f3958
authored
Aug 10, 2021
by
pengyunqian
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'cmsLogin' of
https://git.yidian-inc.com:8021/bp/op-web-service
into cmsLogin
parents
07bf8f8c
0b933bff
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
18 deletions
+26
-18
main.js
src/main.js
+16
-10
login.js
src/store/modules/login.js
+2
-0
authUtil.js
src/utils/authUtil.js
+8
-8
No files found.
src/main.js
View file @
a72f3958
...
...
@@ -15,34 +15,40 @@ import { ElMessage } from "element-plus";
// 处理路由权限
router
.
beforeResolve
(
async
(
to
,
from
,
next
)
=>
{
if
(
!
to
.
meta
.
requireAuth
)
{
next
();
return
true
;
}
let
isDefault
=
window
.
localStorage
.
getItem
(
'isDefault'
);
let
isDefault
=
window
.
localStorage
.
getItem
(
"isDefault"
);
if
(
!
store
.
state
.
permissions
&&
isDefault
==
1
)
{
const
{
status
,
user
}
=
await
fetchCurrentUser
();
if
(
status
===
'success'
)
{
store
.
commit
(
'updateUserInfo'
,
user
);
console
.
log
(
'updateUserInfo====='
,
user
)
await
store
.
dispatch
(
'updateUserPermission'
,
{
email
:
user
.
email
})
if
(
status
===
"success"
)
{
store
.
commit
(
"updateUserInfo"
,
user
);
console
.
log
(
"updateUserInfo====="
,
user
);
await
store
.
dispatch
(
"updateUserPermission"
,
{
email
:
user
.
email
});
}
else
{
redirectToLogin
();
return
ElMessage
(
"您没有权限"
);
}
}
// .......
if
(
isDefault
===
"2"
)
{
await
store
.
dispatch
(
"updateUserPermission"
,
{
email
:
localStorage
.
getItem
(
"_user_email"
)
});
}
if
(
!
checkPathAuth
(
to
.
path
))
{
redirectToLogin
();
return
ElMessage
(
"您没有权限"
);
redirectToLogin
();
return
ElMessage
(
"您没有权限"
);
// router.push({name: 'Forbidden'})
}
else
{
next
();
return
true
;
}
})
})
;
createApp
(
App
)
.
use
(
router
)
...
...
src/store/modules/login.js
View file @
a72f3958
...
...
@@ -32,6 +32,8 @@ export default {
storage
[
'isDefault'
]
=
1
;
return
true
}
else
if
(
+
res
.
code
===
0
){
// TODO: refactor to pass directly
localStorage
.
setItem
(
"_user_email"
,
payload
.
email
)
storage
[
'isDefault'
]
=
2
;
if
(
!
getCookie
(
'username'
))
setCookie
(
'username'
,
payload
.
email
,
16
);
return
true
...
...
src/utils/authUtil.js
View file @
a72f3958
// 包含权限相关的工具方法,注意要在vue的生命周期中调用这些方法,否则会有获取不到权限的问题
import
store
from
'../store'
import
{
PATH_PERMISSION_NAME
}
from
'../config/pageconfig'
import
store
from
"../store"
;
import
{
PATH_PERMISSION_NAME
}
from
"../config/pageconfig"
;
function
getPermissionObj
()
{
function
getPermissionObj
()
{
// 支持到二级权限
const
permissions
=
store
.
state
.
permissions
||
[];
const
permissions
=
store
.
state
.
user
.
permissions
||
[];
const
authObj
=
{};
permissions
.
forEach
(
ele
=>
{
authObj
[
ele
.
name
]
=
{};
if
(
ele
.
sub_permissions
)
{
ele
.
sub_permissions
.
forEach
(
sp
=>
{
authObj
[
ele
.
name
][
sp
.
name
]
=
true
;
})
})
;
}
})
})
;
return
authObj
;
}
...
...
@@ -23,11 +23,11 @@ function getPermissionObj () {
* @param {*} path
* @returns
*/
export
function
checkPathAuth
(
path
)
{
export
function
checkPathAuth
(
path
)
{
const
authObj
=
getPermissionObj
();
if
(
path
in
PATH_PERMISSION_NAME
)
{
const
authArr
=
PATH_PERMISSION_NAME
[
path
].
split
(
'.'
);
const
authArr
=
PATH_PERMISSION_NAME
[
path
].
split
(
"."
);
const
[
p
,
subP
]
=
authArr
;
if
(
p
&&
subP
)
{
return
!!
authObj
[
p
][
subP
];
...
...
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