imatrix-ui 2.8.3 → 2.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/super-ui.css +1 -1
- package/lib/super-ui.umd.min.js +3 -3
- package/package.json +1 -1
- package/src/utils/auth-api.js +105 -0
- package/src/utils/auth.js +34 -42
- package/src/views/dsc-component/Sidebar/Item.vue +3 -3
package/package.json
CHANGED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import Cookies from 'js-cookie'
|
|
2
|
+
|
|
3
|
+
const jwtKey = 'JWT'
|
|
4
|
+
const currentUserNameKey = 'USERNAME'
|
|
5
|
+
const currentUserInfoKey = 'CURRENT_USER'
|
|
6
|
+
|
|
7
|
+
function getToken() {
|
|
8
|
+
return Cookies.get(jwtKey)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function setToken(token) {
|
|
12
|
+
Cookies.set(jwtKey, token, {
|
|
13
|
+
path: '/'
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function removeToken() {
|
|
18
|
+
Cookies.remove(jwtKey, {
|
|
19
|
+
path: '/'
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getUsername() {
|
|
24
|
+
return getCookieCache(currentUserNameKey)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function setUsername(username) {
|
|
28
|
+
setSessionCache(currentUserNameKey, username)
|
|
29
|
+
setCookieCache(currentUserNameKey, username)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function removeUsername() {
|
|
33
|
+
removeSessionCache(currentUserNameKey)
|
|
34
|
+
removeCookieCache(currentUserNameKey)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getCurrentUser() {
|
|
38
|
+
const userJson = getCookieCache(currentUserInfoKey)
|
|
39
|
+
if (userJson) {
|
|
40
|
+
return JSON.parse(userJson)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function setCurrentUser(userInfo) {
|
|
45
|
+
if (userInfo) {
|
|
46
|
+
if (userInfo.password) {
|
|
47
|
+
userInfo.password = null
|
|
48
|
+
}
|
|
49
|
+
const userinfoStr = JSON.stringify(userInfo)
|
|
50
|
+
setSessionCache(currentUserInfoKey, userinfoStr)
|
|
51
|
+
setCookieCache(currentUserInfoKey, userinfoStr)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function removeCurrentUser() {
|
|
56
|
+
removeSessionCache(currentUserInfoKey)
|
|
57
|
+
removeCookieCache(currentUserInfoKey)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getCookieCache(key) {
|
|
61
|
+
const value = Cookies.get(key)
|
|
62
|
+
return value
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function setCookieCache(key, value) {
|
|
66
|
+
Cookies.set(key, value, {
|
|
67
|
+
path: '/'
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function removeCookieCache(key) {
|
|
72
|
+
Cookies.remove(key, {
|
|
73
|
+
path: '/'
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function getSessionCache(key) {
|
|
78
|
+
const value = sessionStorage.getItem(key)
|
|
79
|
+
return value
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function setSessionCache(key, value) {
|
|
83
|
+
return sessionStorage.setItem(key, value)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function removeSessionCache(key) {
|
|
87
|
+
sessionStorage.removeItem(key)
|
|
88
|
+
}
|
|
89
|
+
export default {
|
|
90
|
+
getToken,
|
|
91
|
+
setToken,
|
|
92
|
+
removeToken,
|
|
93
|
+
getUsername,
|
|
94
|
+
setUsername,
|
|
95
|
+
removeUsername,
|
|
96
|
+
getCurrentUser,
|
|
97
|
+
setCurrentUser,
|
|
98
|
+
removeCurrentUser,
|
|
99
|
+
getCookieCache,
|
|
100
|
+
setCookieCache,
|
|
101
|
+
removeCookieCache,
|
|
102
|
+
getSessionCache,
|
|
103
|
+
setSessionCache,
|
|
104
|
+
removeSessionCache
|
|
105
|
+
}
|
package/src/utils/auth.js
CHANGED
|
@@ -1,69 +1,61 @@
|
|
|
1
|
-
import
|
|
2
|
-
import Cookies from 'js-cookie'
|
|
3
|
-
import Vue from 'vue'
|
|
4
|
-
|
|
5
|
-
const jwtKey = 'JWT'
|
|
6
|
-
const currentUserNameKey = 'USERNAME'
|
|
7
|
-
const currentUserInfoKey = 'CURRENT_USER'
|
|
1
|
+
import authApi from './auth-api'
|
|
8
2
|
|
|
9
3
|
export function getToken() {
|
|
10
|
-
|
|
11
|
-
// console.log('auth-sessionStorage.getToken=', jwt)
|
|
12
|
-
if (!jwt) {
|
|
13
|
-
jwt = Cookies.get(jwtKey)
|
|
14
|
-
// console.log('auth-Cookies.getToken=', jwt)
|
|
15
|
-
}
|
|
16
|
-
return jwt
|
|
4
|
+
return authApi.getToken()
|
|
17
5
|
}
|
|
18
6
|
|
|
19
7
|
export function setToken(token) {
|
|
20
|
-
|
|
21
|
-
// 如果是开发模式,需要设置cookie。不设置expires,就是session cookie,表示关闭浏览器,cookie即失效
|
|
22
|
-
// console.log('auth-Cookies.setToken=', token)
|
|
23
|
-
// 必须是“/”否则无法移除token
|
|
24
|
-
Cookies.set(jwtKey, token, { path: '/' })
|
|
25
|
-
} else {
|
|
26
|
-
// console.log('auth-sessionStorage.setToken=', token)
|
|
27
|
-
return sessionStorage.setItem(jwtKey, token)
|
|
28
|
-
}
|
|
8
|
+
authApi.setToken(token)
|
|
29
9
|
}
|
|
30
10
|
|
|
31
11
|
export function removeToken() {
|
|
32
|
-
|
|
33
|
-
// console.log('auth-sessionStorage.removeToken=', getToken())
|
|
34
|
-
// 必须和setToken中的path“/”一致,否则无法移除token
|
|
35
|
-
Cookies.remove(jwtKey, { path: '/' })
|
|
36
|
-
// console.log('auth-Cookies.removeToken=', getToken())
|
|
12
|
+
authApi.removeToken()
|
|
37
13
|
}
|
|
38
14
|
|
|
39
15
|
export function getUsername() {
|
|
40
|
-
return
|
|
16
|
+
return authApi.getUsername()
|
|
41
17
|
}
|
|
42
18
|
|
|
43
19
|
export function setUsername(username) {
|
|
44
|
-
|
|
20
|
+
authApi.setUsername(username)
|
|
45
21
|
}
|
|
46
22
|
|
|
47
23
|
export function removeUsername() {
|
|
48
|
-
|
|
24
|
+
authApi.removeUsername()
|
|
49
25
|
}
|
|
50
26
|
|
|
51
27
|
export function getCurrentUser() {
|
|
52
|
-
|
|
53
|
-
if (userJson) {
|
|
54
|
-
return JSON.parse(userJson)
|
|
55
|
-
}
|
|
28
|
+
return authApi.getCurrentUser()
|
|
56
29
|
}
|
|
57
30
|
|
|
58
31
|
export function setCurrentUser(userInfo) {
|
|
59
|
-
|
|
60
|
-
if (userInfo.password) {
|
|
61
|
-
userInfo.password = null
|
|
62
|
-
}
|
|
63
|
-
sessionStorage.setItem(currentUserInfoKey, JSON.stringify(userInfo))
|
|
64
|
-
}
|
|
32
|
+
authApi.setCurrentUser(userInfo)
|
|
65
33
|
}
|
|
66
34
|
|
|
67
35
|
export function removeCurrentUser() {
|
|
68
|
-
|
|
36
|
+
authApi.removeCurrentUser()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getCookieCache(key) {
|
|
40
|
+
return authApi.getCookieCache(key)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function setCookieCache(key, value) {
|
|
44
|
+
authApi.setCookieCache(key, value)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function removeCookieCache(key) {
|
|
48
|
+
authApi.removeCookieCache(key)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getSessionCache(key) {
|
|
52
|
+
return authApi.getSessionCache(key)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function setSessionCache(key, value) {
|
|
56
|
+
return authApi.setSessionCache(key, value)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function removeSessionCache(key) {
|
|
60
|
+
authApi.removeSessionCache(key)
|
|
69
61
|
}
|
|
@@ -29,13 +29,13 @@ export default {
|
|
|
29
29
|
if (icon.indexOf('fa-') === 0) {
|
|
30
30
|
// 表示以“fa-”开头,使用font-awesome中的图标
|
|
31
31
|
icon = 'fa ' + icon
|
|
32
|
-
vnodes.push(<div style='display: inline-block;'><i class={icon}/></div>)
|
|
32
|
+
vnodes.push(<div style='display: inline-block;overflow:hidden;'><i class={icon}/></div>)
|
|
33
33
|
} else if (icon.indexOf('svg-') === 0) {
|
|
34
34
|
icon = icon.substring(icon.indexOf('svg-') + 4)
|
|
35
|
-
vnodes.push(<div style='display: inline-block;'><svg-icon icon-class={icon}/></div>)
|
|
35
|
+
vnodes.push(<div style='display: inline-block;overflow:hidden;'><svg-icon icon-class={icon}/></div>)
|
|
36
36
|
} else {
|
|
37
37
|
icon += ' svg-icon'
|
|
38
|
-
vnodes.push(<div style='display: inline-block;'><i class={icon}/></div>)
|
|
38
|
+
vnodes.push(<div style='display: inline-block;overflow:hidden;'><i class={icon}/></div>)
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|