yuang-framework-ui-common 1.0.16 → 1.0.17
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/utils/storageUtils.ts +42 -13
- package/package.json +1 -1
- package/lib/.DS_Store +0 -0
- package/src/.DS_Store +0 -0
@@ -1,28 +1,42 @@
|
|
1
|
-
|
2
1
|
/**
|
3
2
|
* 判断session存储数据是否过期
|
4
3
|
* @param key
|
5
4
|
*/
|
6
5
|
const isSessionStorageExpired = (key) => {
|
7
6
|
const value = sessionStorage.getItem(key);
|
7
|
+
if (!value) {
|
8
|
+
return false;
|
9
|
+
}
|
8
10
|
const data = JSON.parse(value);
|
9
|
-
if (
|
11
|
+
if (!data || !data.expiresIn) {
|
12
|
+
return false;
|
13
|
+
}
|
14
|
+
if (data.expiresIn == 0) {
|
15
|
+
return false;
|
16
|
+
}
|
17
|
+
if (Date.now() > data.expiresIn) {
|
10
18
|
sessionStorage.removeItem(key);
|
11
|
-
return true;
|
19
|
+
return true;
|
12
20
|
}
|
13
|
-
return false;
|
21
|
+
return false;
|
14
22
|
}
|
15
23
|
|
16
24
|
/**
|
17
25
|
* 设置session存储数据
|
18
26
|
* @param key
|
19
27
|
* @param value
|
20
|
-
* @param
|
28
|
+
* @param expiresIn 过期时间,单位:秒
|
21
29
|
*/
|
22
|
-
const setSessionStorageItem = (key, value,
|
30
|
+
const setSessionStorageItem = (key, value, expiresIn) => {
|
31
|
+
if(!key) {
|
32
|
+
console.error('参数[key]为空')
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
expiresIn = expiresIn || 0;
|
36
|
+
|
23
37
|
const data = {
|
24
38
|
value: value,
|
25
|
-
|
39
|
+
expiresIn: Date.now() + expiresIn * 1000
|
26
40
|
};
|
27
41
|
sessionStorage.setItem(key, JSON.stringify(data));
|
28
42
|
}
|
@@ -55,24 +69,39 @@ const removeSessionStorageItem = (key) => {
|
|
55
69
|
*/
|
56
70
|
const isLocalStorageExpired = (key) => {
|
57
71
|
const value = localStorage.getItem(key);
|
72
|
+
if (!value) {
|
73
|
+
return false;
|
74
|
+
}
|
58
75
|
const data = JSON.parse(value);
|
59
|
-
if (
|
76
|
+
if (!data || !data.expiresIn) {
|
77
|
+
return false;
|
78
|
+
}
|
79
|
+
if (data.expiresIn == 0) {
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
if (Date.now() > data.expiresIn) {
|
60
83
|
localStorage.removeItem(key);
|
61
|
-
return true;
|
84
|
+
return true;
|
62
85
|
}
|
63
|
-
return false;
|
86
|
+
return false;
|
64
87
|
}
|
65
88
|
|
66
89
|
/**
|
67
90
|
* 设置local存储数据
|
68
91
|
* @param key
|
69
92
|
* @param value
|
70
|
-
* @param
|
93
|
+
* @param expiresIn 过期时间,单位:秒
|
71
94
|
*/
|
72
|
-
const setLocalStorageItem = (key, value,
|
95
|
+
const setLocalStorageItem = (key, value, expiresIn) => {
|
96
|
+
if(!key) {
|
97
|
+
console.error('参数[key]为空')
|
98
|
+
return;
|
99
|
+
}
|
100
|
+
expiresIn = expiresIn || 0;
|
101
|
+
|
73
102
|
const data = {
|
74
103
|
value: value,
|
75
|
-
|
104
|
+
expiresIn: Date.now() + expiresIn * 1000
|
76
105
|
};
|
77
106
|
localStorage.setItem(key, JSON.stringify(data));
|
78
107
|
}
|
package/package.json
CHANGED
package/lib/.DS_Store
DELETED
Binary file
|
package/src/.DS_Store
DELETED
Binary file
|