Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
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
najiu-frontend
najiu-admin-template
Commits
e5f37885
Commit
e5f37885
authored
Jun 29, 2021
by
无木
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: multi windows token sharing
修复同时打开多个窗口时令牌没能同步共享的问题 fixed: #761
parent
d7b84c78
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
4 deletions
+44
-4
CHANGELOG.zh_CN.md
CHANGELOG.zh_CN.md
+1
-0
user.ts
mock/sys/user.ts
+14
-0
user.ts
src/api/sys/user.ts
+5
-0
user.ts
src/store/modules/user.ts
+9
-2
index.ts
src/utils/auth/index.ts
+5
-0
persistent.ts
src/utils/cache/persistent.ts
+10
-2
No files found.
CHANGELOG.zh_CN.md
View file @
e5f37885
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
-
**Table**
修复为 table 提供 rowSelection.onChange 时,无法手动变更 table 的选中项的问题
-
**Table**
修复为 table 提供 rowSelection.onChange 时,无法手动变更 table 的选中项的问题
-
**Icon**
修复 SvgIcon 缺少部分样式的问题
-
**Icon**
修复 SvgIcon 缺少部分样式的问题
-
**LockScreen**
修复锁屏功能可以通过刷新页面或复制 URL 打开新的浏览器标签来跳过锁定状态的问题
-
**LockScreen**
修复锁屏功能可以通过刷新页面或复制 URL 打开新的浏览器标签来跳过锁定状态的问题
-
修复多个窗口同时打开页面时,
`Token`
不会同步的问题
## 2.5.2(2021-06-27)
## 2.5.2(2021-06-27)
...
...
mock/sys/user.ts
View file @
e5f37885
...
@@ -95,4 +95,18 @@ export default [
...
@@ -95,4 +95,18 @@ export default [
return
resultSuccess
(
codeList
);
return
resultSuccess
(
codeList
);
},
},
},
},
{
url
:
'
/basic-api/logout
'
,
timeout
:
200
,
method
:
'
get
'
,
response
:
(
request
:
requestParams
)
=>
{
const
token
=
getRequestToken
(
request
);
if
(
!
token
)
return
resultError
(
'
Invalid token
'
);
const
checkUser
=
createFakeUserList
().
find
((
item
)
=>
item
.
token
===
token
);
if
(
!
checkUser
)
{
return
resultError
(
'
Invalid token!
'
);
}
return
resultSuccess
(
undefined
,
{
message
:
'
Token has been destroyed
'
});
},
},
]
as
MockMethod
[];
]
as
MockMethod
[];
src/api/sys/user.ts
View file @
e5f37885
...
@@ -5,6 +5,7 @@ import { ErrorMessageMode } from '/#/axios';
...
@@ -5,6 +5,7 @@ import { ErrorMessageMode } from '/#/axios';
enum
Api
{
enum
Api
{
Login
=
'
/login
'
,
Login
=
'
/login
'
,
Logout
=
'
/logout
'
,
GetUserInfo
=
'
/getUserInfo
'
,
GetUserInfo
=
'
/getUserInfo
'
,
GetPermCode
=
'
/getPermCode
'
,
GetPermCode
=
'
/getPermCode
'
,
}
}
...
@@ -34,3 +35,7 @@ export function getUserInfo() {
...
@@ -34,3 +35,7 @@ export function getUserInfo() {
export
function
getPermCode
()
{
export
function
getPermCode
()
{
return
defHttp
.
get
<
string
[]
>
({
url
:
Api
.
GetPermCode
});
return
defHttp
.
get
<
string
[]
>
({
url
:
Api
.
GetPermCode
});
}
}
export
function
doLogout
()
{
return
defHttp
.
get
({
url
:
Api
.
Logout
});
}
src/store/modules/user.ts
View file @
e5f37885
...
@@ -7,7 +7,7 @@ import { PageEnum } from '/@/enums/pageEnum';
...
@@ -7,7 +7,7 @@ import { PageEnum } from '/@/enums/pageEnum';
import
{
ROLES_KEY
,
TOKEN_KEY
,
USER_INFO_KEY
}
from
'
/@/enums/cacheEnum
'
;
import
{
ROLES_KEY
,
TOKEN_KEY
,
USER_INFO_KEY
}
from
'
/@/enums/cacheEnum
'
;
import
{
getAuthCache
,
setAuthCache
}
from
'
/@/utils/auth
'
;
import
{
getAuthCache
,
setAuthCache
}
from
'
/@/utils/auth
'
;
import
{
GetUserInfoModel
,
LoginParams
}
from
'
/@/api/sys/model/userModel
'
;
import
{
GetUserInfoModel
,
LoginParams
}
from
'
/@/api/sys/model/userModel
'
;
import
{
getUserInfo
,
loginApi
}
from
'
/@/api/sys/user
'
;
import
{
doLogout
,
getUserInfo
,
loginApi
}
from
'
/@/api/sys/user
'
;
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
useMessage
}
from
'
/@/hooks/web/useMessage
'
;
import
{
useMessage
}
from
'
/@/hooks/web/useMessage
'
;
import
{
router
}
from
'
/@/router
'
;
import
{
router
}
from
'
/@/router
'
;
...
@@ -105,7 +105,14 @@ export const useUserStore = defineStore({
...
@@ -105,7 +105,14 @@ export const useUserStore = defineStore({
/**
/**
* @description: logout
* @description: logout
*/
*/
logout
(
goLogin
=
false
)
{
async
logout
(
goLogin
=
false
)
{
try
{
await
doLogout
();
}
catch
{
console
.
log
(
'
注销Token失败
'
);
}
this
.
setToken
(
undefined
);
this
.
setSessionTimeout
(
false
);
goLogin
&&
router
.
push
(
PageEnum
.
BASE_LOGIN
);
goLogin
&&
router
.
push
(
PageEnum
.
BASE_LOGIN
);
},
},
...
...
src/utils/auth/index.ts
View file @
e5f37885
...
@@ -19,3 +19,8 @@ export function setAuthCache(key: BasicKeys, value) {
...
@@ -19,3 +19,8 @@ export function setAuthCache(key: BasicKeys, value) {
const
fn
=
isLocal
?
Persistent
.
setLocal
:
Persistent
.
setSession
;
const
fn
=
isLocal
?
Persistent
.
setLocal
:
Persistent
.
setSession
;
return
fn
(
key
,
value
,
true
);
return
fn
(
key
,
value
,
true
);
}
}
export
function
clearAuthCache
(
immediate
=
true
)
{
const
fn
=
isLocal
?
Persistent
.
clearLocal
:
Persistent
.
clearSession
;
return
fn
(
immediate
);
}
src/utils/cache/persistent.ts
View file @
e5f37885
...
@@ -16,6 +16,7 @@ import {
...
@@ -16,6 +16,7 @@ import {
}
from
'
/@/enums/cacheEnum
'
;
}
from
'
/@/enums/cacheEnum
'
;
import
{
DEFAULT_CACHE_TIME
}
from
'
/@/settings/encryptionSetting
'
;
import
{
DEFAULT_CACHE_TIME
}
from
'
/@/settings/encryptionSetting
'
;
import
{
toRaw
}
from
'
vue
'
;
import
{
toRaw
}
from
'
vue
'
;
import
{
pick
}
from
'
lodash-es
'
;
interface
BasicStore
{
interface
BasicStore
{
[
TOKEN_KEY
]:
string
|
number
|
null
|
undefined
;
[
TOKEN_KEY
]:
string
|
number
|
null
|
undefined
;
...
@@ -96,8 +97,15 @@ export class Persistent {
...
@@ -96,8 +97,15 @@ export class Persistent {
}
}
window
.
addEventListener
(
'
beforeunload
'
,
function
()
{
window
.
addEventListener
(
'
beforeunload
'
,
function
()
{
ls
.
set
(
APP_LOCAL_CACHE_KEY
,
localMemory
.
getCache
);
// TOKEN_KEY 在登录或注销时已经写入到storage了,此处为了解决同时打开多个窗口时token不同步的问题
ss
.
set
(
APP_SESSION_CACHE_KEY
,
sessionMemory
.
getCache
);
ls
.
set
(
APP_LOCAL_CACHE_KEY
,
{
...
localMemory
.
getCache
,
...
pick
(
ls
.
get
(
APP_LOCAL_CACHE_KEY
),
[
TOKEN_KEY
,
USER_INFO_KEY
]),
});
ss
.
set
(
APP_SESSION_CACHE_KEY
,
{
...
sessionMemory
.
getCache
,
...
pick
(
sessionMemory
.
getCache
,
[
TOKEN_KEY
,
USER_INFO_KEY
]),
});
});
});
function
storageChange
(
e
:
any
)
{
function
storageChange
(
e
:
any
)
{
...
...
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