yuang-framework-ui-common 1.0.16 → 1.0.18

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.
@@ -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 (Date.now() > data.expires) {
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 expires 过期时间,单位:秒
28
+ * @param expiresIn 过期时间,单位:秒
21
29
  */
22
- const setSessionStorageItem = (key, value, expires) => {
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
- expires: Date.now() + expires * 1000
39
+ expiresIn: Date.now() + expiresIn * 1000
26
40
  };
27
41
  sessionStorage.setItem(key, JSON.stringify(data));
28
42
  }
@@ -36,7 +50,13 @@ const getSessionStorageItem = (key) => {
36
50
  return null;
37
51
  }
38
52
  const value = sessionStorage.getItem(key);
53
+ if(!value) {
54
+ return null;
55
+ }
39
56
  const data = JSON.parse(value);
57
+ if(!data || !data.value) {
58
+ return null;
59
+ }
40
60
  return data.value;
41
61
  }
42
62
 
@@ -55,24 +75,39 @@ const removeSessionStorageItem = (key) => {
55
75
  */
56
76
  const isLocalStorageExpired = (key) => {
57
77
  const value = localStorage.getItem(key);
78
+ if (!value) {
79
+ return false;
80
+ }
58
81
  const data = JSON.parse(value);
59
- if (Date.now() > data.expires) {
82
+ if (!data || !data.expiresIn) {
83
+ return false;
84
+ }
85
+ if (data.expiresIn == 0) {
86
+ return false;
87
+ }
88
+ if (Date.now() > data.expiresIn) {
60
89
  localStorage.removeItem(key);
61
- return true; // 已过期
90
+ return true;
62
91
  }
63
- return false; // 未过期
92
+ return false;
64
93
  }
65
94
 
66
95
  /**
67
96
  * 设置local存储数据
68
97
  * @param key
69
98
  * @param value
70
- * @param expires 过期时间,单位:秒
99
+ * @param expiresIn 过期时间,单位:秒
71
100
  */
72
- const setLocalStorageItem = (key, value, expires) => {
101
+ const setLocalStorageItem = (key, value, expiresIn) => {
102
+ if(!key) {
103
+ console.error('参数[key]为空')
104
+ return;
105
+ }
106
+ expiresIn = expiresIn || 0;
107
+
73
108
  const data = {
74
109
  value: value,
75
- expires: Date.now() + expires * 1000
110
+ expiresIn: Date.now() + expiresIn * 1000
76
111
  };
77
112
  localStorage.setItem(key, JSON.stringify(data));
78
113
  }
@@ -86,7 +121,13 @@ const getLocalStorageItem = (key) => {
86
121
  return null;
87
122
  }
88
123
  const value = localStorage.getItem(key);
124
+ if(!value) {
125
+ return null;
126
+ }
89
127
  const data = JSON.parse(value);
128
+ if(!data || !data.value) {
129
+ return null;
130
+ }
90
131
  return data.value;
91
132
  }
92
133
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
package/lib/.DS_Store DELETED
Binary file
package/src/.DS_Store DELETED
Binary file