Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
ka-op-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
QA
ka-op-ui
Commits
7e2db21b
Commit
7e2db21b
authored
Dec 30, 2019
by
智勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除前端token
parent
499dffb7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
36 deletions
+17
-36
permission.js
src/permission.js
+12
-18
user.js
src/store/modules/user.js
+2
-9
auth.js
src/utils/auth.js
+1
-1
request.js
src/utils/request.js
+2
-8
No files found.
src/permission.js
View file @
7e2db21b
...
...
@@ -3,43 +3,37 @@ import store from './store'
import
NProgress
from
'
nprogress
'
// progress bar
import
'
nprogress/nprogress.css
'
// progress bar style
import
{
Message
}
from
'
element-ui
'
import
{
getToken
}
from
'
@/utils/auth
'
// getToken from cookie
NProgress
.
configure
({
showSpinner
:
false
})
// NProgress configuration
const
whiteList
=
[
'
/login
'
]
// 不重定向白名单
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
NProgress
.
start
()
if
(
getToken
())
{
if
(
to
.
path
===
'
/login
'
)
{
next
({
path
:
'
/
'
})
NProgress
.
done
()
// if current page is dashboard will not trigger afterEach hook, so manually handle it
}
else
{
if
(
whiteList
.
indexOf
(
to
.
path
)
!==
-
1
)
{
next
()
}
else
{
if
(
sessionStorage
.
getItem
(
'
qahome_env
'
))
{
if
(
store
.
getters
.
roles
.
length
===
0
)
{
store
.
dispatch
(
'
GetInfo
'
).
then
(
res
=>
{
// 拉取用户信息
store
.
dispatch
(
'
GetInfo
'
).
then
(
res
=>
{
next
()
}).
catch
(()
=>
{
}).
catch
((
err
)
=>
{
store
.
dispatch
(
'
FedLogOut
'
).
then
(()
=>
{
// Message.error(err || 'Verification failed, please login again')
next
({
path
:
'
/
'
})
Message
.
warning
(
err
||
'
请登录...
'
)
next
(
`/login?redirect=
${
to
.
path
}
`
)
NProgress
.
done
()
})
})
}
else
{
next
()
}
}
}
else
{
if
(
whiteList
.
indexOf
(
to
.
path
)
!==
-
1
)
{
next
()
}
else
{
Message
.
warning
(
'
请登录...
'
)
next
(
`/login?redirect=
${
to
.
path
}
`
)
// 否则全部重定向到登录页
next
(
`/login?redirect=
${
to
.
path
}
`
)
NProgress
.
done
()
}
}
})
router
.
afterEach
(()
=>
{
NProgress
.
done
()
// 结束Progress
NProgress
.
done
()
})
src/store/modules/user.js
View file @
7e2db21b
import
{
login
,
logout
,
getInfo
}
from
'
@/api/login
'
import
{
getToken
,
setToken
,
removeToken
}
from
'
@/utils/auth
'
const
user
=
{
state
:
{
token
:
getToken
(),
name
:
''
,
avatar
:
''
,
roles
:
[]
...
...
@@ -26,10 +24,7 @@ const user = {
Login
({
commit
},
userInfo
)
{
const
username
=
userInfo
.
username
.
trim
()
return
new
Promise
((
resolve
,
reject
)
=>
{
login
(
username
,
userInfo
.
password
).
then
(
response
=>
{
const
data
=
response
.
data
setToken
(
data
)
commit
(
'
SET_TOKEN
'
,
data
)
login
(
username
,
userInfo
.
password
).
then
(()
=>
{
resolve
()
}).
catch
(
error
=>
{
reject
(
error
)
...
...
@@ -43,7 +38,7 @@ const user = {
getInfo
().
then
(
response
=>
{
const
data
=
response
.
data
data
.
roles
=
data
.
rank
.
indexOf
(
'
CHANNEL
'
)
!==
-
1
?
[
'
channel
'
]
:
[
'
admin
'
]
if
(
data
.
roles
&&
data
.
roles
.
length
>
0
)
{
// 验证返回的roles是否是一个非空数组
if
(
data
.
roles
&&
data
.
roles
.
length
>
0
)
{
commit
(
'
SET_ROLES
'
,
data
.
roles
)
}
else
{
reject
(
'
getInfo: roles must be a non-null array !
'
)
...
...
@@ -62,7 +57,6 @@ const user = {
logout
(
state
.
token
).
then
(()
=>
{
commit
(
'
SET_TOKEN
'
,
''
)
commit
(
'
SET_ROLES
'
,
[])
removeToken
()
resolve
()
}).
catch
(
error
=>
{
reject
(
error
)
...
...
@@ -74,7 +68,6 @@ const user = {
FedLogOut
({
commit
})
{
return
new
Promise
(
resolve
=>
{
commit
(
'
SET_TOKEN
'
,
''
)
removeToken
()
resolve
()
})
}
...
...
src/utils/auth.js
View file @
7e2db21b
...
...
@@ -7,7 +7,7 @@ export function getToken() {
}
export
function
setToken
(
token
)
{
return
Cookies
.
set
(
TokenKey
,
token
)
return
Cookies
.
set
(
TokenKey
,
token
,
{
expires
:
7
,
path
:
''
}
)
}
export
function
removeToken
()
{
...
...
src/utils/request.js
View file @
7e2db21b
import
axios
from
'
axios
'
import
{
Message
}
from
'
element-ui
'
import
store
from
'
../store
'
import
{
getToken
}
from
'
@/utils/auth
'
import
{
MessageBox
}
from
'
element-ui
'
// 创建axios实例
...
...
@@ -13,12 +12,7 @@ const service = axios.create({
// request拦截器
service
.
interceptors
.
request
.
use
(
config
=>
{
if
(
store
.
getters
.
token
)
{
config
.
headers
[
'
SESSION
'
]
=
getToken
()
// 让每个请求携带自定义token 请根据实际情况自行修改
}
const
url
=
store
.
getters
.
env
===
'
qaapi
'
?
process
.
env
.
qaapi
:
process
.
env
.
BASE_API
.
replace
(
'
namespace
'
,
store
.
getters
.
env
)
// if (config.url.indexOf('yapi') === -1) {
// }
config
.
url
=
url
+
config
.
url
config
.
headers
[
'
cluster
'
]
=
'
qa
'
return
config
...
...
@@ -41,7 +35,7 @@ service.interceptors.response.use(
if
((
typeof
res
.
code
===
'
number
'
&&
res
.
code
!==
200000
)
||
(
typeof
res
.
code
===
'
string
'
&&
res
.
code
!==
'
0000
'
))
{
// 500003:Token 过期了;
if
(
res
.
code
===
500003
||
res
.
code
===
50000
6
)
{
if
(
res
.
code
===
500003
||
res
.
code
===
50000
7
)
{
MessageBox
.
confirm
(
'
你已被登出,可以取消继续留在该页面,或者重新登录
'
,
'
确定登出
'
,
{
confirmButtonText
:
'
重新登录
'
,
cancelButtonText
:
'
取消
'
,
...
...
@@ -56,7 +50,7 @@ service.interceptors.response.use(
Message
({
message
:
res
.
message
,
type
:
'
error
'
,
duration
:
5
*
1000
duration
:
3
*
1000
})
}
return
Promise
.
reject
(
res
.
message
||
'
responseInterceptorsError
'
)
...
...
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