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
217537d0
Commit
217537d0
authored
Aug 09, 2021
by
liwenhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add:清cookie
parent
f603c787
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
40 deletions
+41
-40
main.js
src/main.js
+14
-10
login.js
src/store/modules/login.js
+19
-20
request.js
src/utils/request.js
+1
-1
util.js
src/utils/util.js
+7
-9
No files found.
src/main.js
View file @
217537d0
...
@@ -8,9 +8,9 @@ import "element-plus/lib/theme-chalk/index.css";
...
@@ -8,9 +8,9 @@ import "element-plus/lib/theme-chalk/index.css";
import
"dayjs/locale/zh-cn"
;
import
"dayjs/locale/zh-cn"
;
import
locale
from
"element-plus/lib/locale/lang/zh-cn"
;
import
locale
from
"element-plus/lib/locale/lang/zh-cn"
;
//
import { fetchCurrentUser } from "./service/user";
import
{
fetchCurrentUser
}
from
"./service/user"
;
import
{
checkPathAuth
}
from
"./utils/authUtil"
;
import
{
checkPathAuth
}
from
"./utils/authUtil"
;
import
{
redirectToLogin
}
from
"./utils/util"
;
import
{
redirectToLogin
,
getCookie
}
from
"./utils/util"
;
// 处理路由权限
// 处理路由权限
router
.
beforeResolve
(
async
(
to
,
from
,
next
)
=>
{
router
.
beforeResolve
(
async
(
to
,
from
,
next
)
=>
{
...
@@ -25,14 +25,18 @@ router.beforeResolve(async (to, from, next) => {
...
@@ -25,14 +25,18 @@ router.beforeResolve(async (to, from, next) => {
}
}
if
(
!
store
.
state
.
permissions
)
{
if
(
!
store
.
state
.
permissions
)
{
this
.
$message
(
'您暂无权限'
);
this
.
$message
(
'您暂无权限'
);
// const { status, user } = await fetchCurrentUser();
let
isDefault
=
window
.
localStorage
.
getItem
(
'isDefault'
);
// if (status === 'success') {
if
(
isDefault
==
2
)
{
// store.commit('updateUserInfo', user);
user
.
email
=
getCookie
(
'username'
);
// await store.dispatch('updateUserPermission', { email: user.email })
}
// } else {
const
{
status
,
user
}
=
await
fetchCurrentUser
();
// redirectToLogin();
if
(
status
===
'success'
)
{
// return false;
store
.
commit
(
'updateUserInfo'
,
user
);
// }
await
store
.
dispatch
(
'updateUserPermission'
,
{
email
:
user
.
email
})
}
else
{
redirectToLogin
();
return
false
;
}
}
}
...
...
src/store/modules/login.js
View file @
217537d0
...
@@ -18,38 +18,37 @@ export default {
...
@@ -18,38 +18,37 @@ export default {
}
}
let
res
=
flag
?
await
yd_login
(
payload
)
:
await
j_login
(
params
)
let
res
=
flag
?
await
yd_login
(
payload
)
:
await
j_login
(
params
)
let
storage
=
window
.
localStorage
;
let
storage
=
window
.
localStorage
;
if
(
!
getCookie
(
'username'
))
{
//
if(!getCookie('username')) {
if
(
res
.
userInfo
&&
flag
)
{
if
(
res
.
userInfo
&&
flag
)
{
storage
[
'YD_PANDORA_auth'
]
=
JSON
.
stringify
(
res
.
auth
||
{})
if
(
!
storage
.
getItem
(
'YD_PANDORA_auth'
))
storage
[
'YD_PANDORA_auth'
]
=
JSON
.
stringify
(
res
.
auth
||
{})
storage
[
'YD_PANDORA_JWT_TOKEN'
]
=
(
res
.
type
+
' '
+
res
.
token
)
||
''
if
(
!
storage
.
getItem
(
'YD_PANDORA_JWT_TOKEN'
))
storage
[
'YD_PANDORA_JWT_TOKEN'
]
=
(
res
.
type
+
' '
+
res
.
token
)
||
''
storage
[
'YD_PANDORA_user'
]
=
JSON
.
stringify
(
res
.
userInfo
||
{})
if
(
!
storage
.
getItem
(
'YD_PANDORA_user'
))
storage
[
'YD_PANDORA_user'
]
=
JSON
.
stringify
(
res
.
userInfo
||
{})
setCookie
(
'uid'
,
res
.
userInfo
&&
res
.
userInfo
.
id
,
16
)
if
(
!
getCookie
(
'uid'
))
setCookie
(
'uid'
,
res
.
userInfo
&&
res
.
userInfo
.
id
,
16
)
setCookie
(
'YD_PANDORA_UID'
,
res
.
userInfo
&&
res
.
userInfo
.
id
,
16
)
if
(
!
getCookie
(
'YD_PANDORA_UID'
))
setCookie
(
'YD_PANDORA_UID'
,
res
.
userInfo
&&
res
.
userInfo
.
id
,
16
)
setCookie
(
'userid'
,
res
.
userInfo
&&
res
.
userInfo
.
id
,
16
)
if
(
!
getCookie
(
'userid'
))
setCookie
(
'userid'
,
res
.
userInfo
&&
res
.
userInfo
.
id
,
16
)
setCookie
(
'username'
,
res
.
userInfo
&&
res
.
userInfo
.
email
,
16
)
if
(
!
getCookie
(
'username'
))
setCookie
(
'username'
,
res
.
userInfo
&&
res
.
userInfo
.
email
,
16
)
setCookie
(
'nickname'
,
res
.
userInfo
&&
res
.
userInfo
.
displayName
,
16
)
if
(
!
getCookie
(
'nickname'
))
setCookie
(
'nickname'
,
res
.
userInfo
&&
res
.
userInfo
.
displayName
,
16
)
setCookie
(
'YD_PANDORA_JWT_TOKEN'
,
(
res
.
type
+
' '
+
res
.
token
)
||
''
,
16
)
if
(
!
getCookie
(
'YD_PANDORA_JWT_TOKEN'
))
setCookie
(
'YD_PANDORA_JWT_TOKEN'
,
(
res
.
type
+
' '
+
res
.
token
)
||
''
,
16
)
storage
[
'isDefault'
]
=
1
;
storage
[
'isDefault'
]
=
1
;
return
true
return
true
}
else
if
(
+
res
.
code
===
0
){
}
else
if
(
+
res
.
code
===
0
){
storage
[
'isDefault'
]
=
2
;
storage
[
'isDefault'
]
=
2
;
setCookie
(
'username'
,
payload
.
email
,
16
);
if
(
!
getCookie
(
'username'
))
setCookie
(
'username'
,
payload
.
email
,
16
);
return
true
return
true
}
else
{
}
else
{
ElMessage
.
error
(
res
);
ElMessage
.
error
(
res
);
}
}
}
//
}
},
},
logout
()
{
logout
()
{
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
(
async
(
resolve
)
=>
{
window
.
localStorage
.
clear
();
window
.
localStorage
.
clear
();
delCookie
(
'username'
)
await
delCookie
(
'username'
)
delCookie
(
'uid'
)
await
delCookie
(
'uid'
)
delCookie
(
'YD_PANDORA_JWT_TOKEN'
)
await
delCookie
(
'YD_PANDORA_JWT_TOKEN'
)
delCookie
(
'nickname'
)
await
delCookie
(
'nickname'
)
delCookie
(
'userid'
)
await
delCookie
(
'userid'
)
delCookie
(
'YD_PANDORA_UID'
)
await
delCookie
(
'YD_PANDORA_UID'
)
// Cookies.remove('username','', { path: 'http://dev.yidian-inc.com' }) // removed!
redirectToLogin
()
redirectToLogin
()
resolve
()
resolve
()
});
});
...
...
src/utils/request.js
View file @
217537d0
...
@@ -38,7 +38,7 @@ const getDefaultParams = () => {
...
@@ -38,7 +38,7 @@ const getDefaultParams = () => {
}
}
};
};
const
getDefaultHeaders
=
(
config
)
=>
{
const
getDefaultHeaders
=
config
=>
{
const
{
method
}
=
config
;
const
{
method
}
=
config
;
if
(
method
.
toLowerCase
()
===
"post"
)
{
if
(
method
.
toLowerCase
()
===
"post"
)
{
return
{
return
{
...
...
src/utils/util.js
View file @
217537d0
/* eslint-disable */
import
router
from
"@/router"
;
import
router
from
"@/router"
;
// export async function handleUserLogin() {
// export async function handleUserLogin() {
// const { status, user } = await fetchCurrentUser();
// const { status, user } = await fetchCurrentUser();
...
@@ -38,11 +37,11 @@ export function isYdUser(email) {
...
@@ -38,11 +37,11 @@ export function isYdUser(email) {
return
email
.
match
(
/yidian-inc/
)
||
false
return
email
.
match
(
/yidian-inc/
)
||
false
}
}
export
function
setCookie
(
cname
,
cvalue
,
exdays
)
{
export
function
setCookie
(
name
,
value
)
{
var
d
=
new
Date
();
var
hour
=
8
;
d
.
setTime
(
d
.
getTime
()
+
(
exdays
*
24
*
60
*
60
*
1000
));
var
exp
=
new
Date
();
var
expires
=
"expires="
+
d
.
toUTCString
();
exp
.
setTime
(
exp
.
getTime
()
+
hour
*
60
*
60
*
1000
);
document
.
cookie
=
cname
+
"="
+
cvalue
+
"; "
+
expires
;
document
.
cookie
=
name
+
"="
+
escape
(
value
)
+
";expires="
+
exp
.
toGMTString
()
+
";path=/"
;
}
}
//获取cookie
//获取cookie
...
@@ -62,7 +61,6 @@ export function getCookie(NameOfCookie) {
...
@@ -62,7 +61,6 @@ export function getCookie(NameOfCookie) {
export
function
delCookie
(
name
)
{
export
function
delCookie
(
name
)
{
var
exp
=
new
Date
();
var
exp
=
new
Date
();
exp
.
setTime
(
exp
.
getTime
()
-
1
);
exp
.
setTime
(
exp
.
getTime
()
-
1
);
var
cval
=
getCookie
(
name
);
var
cval
=
getCookie
(
name
);
if
(
cval
!=
null
)
if
(
cval
!=
null
)
document
.
cookie
=
name
+
"="
+
cval
+
";expires="
+
exp
.
toGMTString
()
+
";path=/"
;
document
.
cookie
=
name
+
"="
+
cval
+
";expires="
+
exp
.
toGMTString
();
}
}
\ No newline at end of file
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