Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
ka-manager-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
QG
ka-manager-ui
Commits
8c4c2acf
Commit
8c4c2acf
authored
Jul 27, 2020
by
suntao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
token 和 username 由vue 放到cookie中
parent
3ea770e0
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
27 deletions
+24
-27
main.js
src/main.js
+1
-2
index.vue
src/modules/home/index.vue
+0
-1
index.js
src/store/index.js
+2
-2
login.js
src/store/modules/login.js
+4
-5
auth.js
src/utils/auth.js
+15
-15
request.js
src/utils/request.js
+2
-2
No files found.
src/main.js
View file @
8c4c2acf
...
@@ -30,8 +30,7 @@ router.beforeEach(({meta, path}, from, next) => {
...
@@ -30,8 +30,7 @@ router.beforeEach(({meta, path}, from, next) => {
if
(
isLogin
&&
(
path
==
'
/login
'
||
path
==
'
/
'
))
{
//已登录过,则跳转到主页
if
(
isLogin
&&
(
path
==
'
/login
'
||
path
==
'
/
'
))
{
//已登录过,则跳转到主页
console
.
log
(
"
isLogin token
"
+
store
.
state
.
login
.
tokens
)
console
.
log
(
"
isLogin token
"
+
store
.
state
.
login
.
tokens
)
// store.dispatch('GetInfo')
store
.
dispatch
(
'
GetInfo
'
)
return
next
({
path
:
'
/home/channels
'
})
return
next
({
path
:
'
/home/channels
'
})
}
}
...
...
src/modules/home/index.vue
View file @
8c4c2acf
...
@@ -128,7 +128,6 @@
...
@@ -128,7 +128,6 @@
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
// username: this.$store.getters.username
username
:
this
.
$store
.
state
.
login
.
username
username
:
this
.
$store
.
state
.
login
.
username
}
}
},
},
...
...
src/store/index.js
View file @
8c4c2acf
...
@@ -18,9 +18,9 @@ Vue.use(Vuex)
...
@@ -18,9 +18,9 @@ Vue.use(Vuex)
const
debug
=
process
.
env
.
NODE_ENV
!==
'
production
'
const
debug
=
process
.
env
.
NODE_ENV
!==
'
production
'
let
persistedState
=
{
let
persistedState
=
{
paths
:
[
'
login.tokens
'
],
paths
:
[
'
login.tokens
'
,
"
login.username
"
],
getState
:
(
key
)
=>
Cookies
.
getJSON
(
key
),
getState
:
(
key
)
=>
Cookies
.
getJSON
(
key
),
setState
:
(
key
,
state
)
=>
Cookies
.
set
(
key
,
state
,
{
expires
:
3
})
//expires->cookie过期时间,单位为天
setState
:
(
key
,
state
)
=>
Cookies
.
set
(
key
,
state
,
{
expires
:
1
})
//expires->cookie过期时间,单位为天
}
}
const
store
=
new
Vuex
.
Store
({
const
store
=
new
Vuex
.
Store
({
...
...
src/store/modules/login.js
View file @
8c4c2acf
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
import
{
LOGIN_IN
,
LOGIN_OUT
,
USER_INFO
}
from
'
../mutation-types
'
import
{
LOGIN_IN
,
LOGIN_OUT
,
USER_INFO
}
from
'
../mutation-types
'
import
tokens
from
'
@/apis/tokens
'
import
tokens
from
'
@/apis/tokens
'
import
{
getUserLoginInfo
}
from
'
@/apis/user
'
import
{
getUserLoginInfo
}
from
'
@/apis/user
'
import
{
getToken
,
setToken
,
removeToken
}
from
'
@/utils/auth
'
//
import {getToken, setToken, removeToken} from '@/utils/auth'
const
login
=
{
const
login
=
{
state
:
{
state
:
{
...
@@ -31,15 +31,14 @@ const login = {
...
@@ -31,15 +31,14 @@ const login = {
},
},
actions
:
{
actions
:
{
login
({
commit
,
state
},
user
)
{
login
({
commit
,
state
},
user
)
{
// tokens.getTokens(user.name, user.pass).then((data) => {
tokens
.
getTokens
(
user
.
username
,
user
.
password
).
then
((
data
)
=>
{
tokens
.
getTokens
(
user
.
username
,
user
.
password
).
then
((
data
)
=>
{
//success
//success
commit
(
LOGIN_IN
,
data
.
data
)
commit
(
LOGIN_IN
,
data
.
data
)
setToken
(
data
.
data
.
toke
)
//
setToken(data.data.toke)
},
(
error
)
=>
{
},
(
error
)
=>
{
//fail
//fail
commit
(
LOGIN_IN
,
''
)
commit
(
LOGIN_IN
,
''
)
removeToken
()
//
removeToken()
})
})
},
},
// 获取用户信息
// 获取用户信息
...
@@ -65,7 +64,7 @@ const login = {
...
@@ -65,7 +64,7 @@ const login = {
},
},
logout
({
commit
})
{
logout
({
commit
})
{
commit
(
LOGIN_OUT
)
commit
(
LOGIN_OUT
)
removeToken
()
//
removeToken()
}
}
}
}
}
}
...
...
src/utils/auth.js
View file @
8c4c2acf
import
Cookies
from
'
js-cookie
'
//
import Cookies from 'js-cookie'
//
import
{
SESSION_ID_KEY
}
from
'
../store/mutation-types
'
//
import {SESSION_ID_KEY} from '../store/mutation-types'
//
export
function
getToken
()
{
//
export function getToken() {
return
Cookies
.
get
(
SESSION_ID_KEY
)
//
return Cookies.get(SESSION_ID_KEY)
}
//
}
//
export
function
setToken
(
token
)
{
//
export function setToken(token) {
return
Cookies
.
set
(
SESSION_ID_KEY
,
token
,
{
expires
:
1
,
path
:
''
})
//
return Cookies.set(SESSION_ID_KEY, token, { expires: 1, path: '' })
}
//
}
//
export
function
removeToken
()
{
//
export function removeToken() {
return
Cookies
.
remove
(
SESSION_ID_KEY
)
//
return Cookies.remove(SESSION_ID_KEY)
}
//
}
src/utils/request.js
View file @
8c4c2acf
...
@@ -3,7 +3,7 @@ import { Message } from 'element-ui'
...
@@ -3,7 +3,7 @@ import { Message } from 'element-ui'
import
store
from
'
../store
'
import
store
from
'
../store
'
import
{
MessageBox
}
from
'
element-ui
'
import
{
MessageBox
}
from
'
element-ui
'
import
{
showLoading
,
hideLoading
}
from
'
./loading
'
import
{
showLoading
,
hideLoading
}
from
'
./loading
'
import
{
getToken
}
from
'
@/utils/auth
'
//
import {getToken} from '@/utils/auth'
// import * as getters from "../store/getters";
// import * as getters from "../store/getters";
...
@@ -21,7 +21,7 @@ service.interceptors.request.use(
...
@@ -21,7 +21,7 @@ service.interceptors.request.use(
const
url
=
process
.
env
.
BASE_API
const
url
=
process
.
env
.
BASE_API
//config.url = config.url
//config.url = config.url
// console.log(this.$store.getters)
// console.log(this.$store.getters)
config
.
headers
[
'
ka_token
'
]
=
getToken
()
config
.
headers
[
'
ka_token
'
]
=
store
.
state
.
login
.
tokens
return
config
return
config
},
},
error
=>
{
error
=>
{
...
...
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