@lambo-design/shared 1.0.0-beta.95 → 1.0.0-beta.97

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.
@@ -326,7 +326,7 @@
326
326
  @table-cell-white-space : normal;
327
327
  @table-cell-padding-left : 9px;
328
328
  @table-cell-padding-right : 9px;
329
- @table-header-text-align : center;
329
+ @table-header-text-align : left;
330
330
  @table-data-text-align : left;
331
331
 
332
332
 
@@ -254,7 +254,7 @@ export default {
254
254
  --table-cell-white-space: normal;
255
255
  --table-cell-padding-left: 9px;
256
256
  --table-cell-padding-right: 9px;
257
- --table-header-text-align: center;
257
+ --table-header-text-align: left;
258
258
  --table-data-text-align: left;
259
259
  --select-dropdown-max-height: 400px;
260
260
  --tab-card-bg: #f8f8f9;
@@ -250,11 +250,11 @@ export default {
250
250
  --table-header-font-weight: bold;
251
251
  --table-header-padding-horizontal: 8px;
252
252
  --table-header-padding-vertical: 0;
253
- --table-cell-height: 48px;
253
+ --table-cell-height: 38px;
254
254
  --table-cell-white-space: normal;
255
255
  --table-cell-padding-left: 9px;
256
256
  --table-cell-padding-right: 9px;
257
- --table-header-text-align: center;
257
+ --table-header-text-align: left;
258
258
  --table-data-text-align: left;
259
259
  --select-dropdown-max-height: 400px;
260
260
  --tab-card-bg: #f8f8f9;
@@ -327,7 +327,7 @@ export default {
327
327
  --vxe-table-tree-node-line-color: #909399;
328
328
  --vxe-table-tree-node-line-style: dotted;
329
329
  --vxe-table-header-font-weight: bold;
330
- --vxe-table-row-height-default: 48px;
330
+ --vxe-table-row-height-default: 38px;
331
331
  --vxe-table-row-height-medium: 44px;
332
332
  --vxe-table-row-height-small: 40px;
333
333
  --vxe-table-row-height-mini: 36px;
@@ -254,7 +254,7 @@ export default {
254
254
  --table-cell-white-space: normal;
255
255
  --table-cell-padding-left: 9px;
256
256
  --table-cell-padding-right: 9px;
257
- --table-header-text-align: center;
257
+ --table-header-text-align: left;
258
258
  --table-data-text-align: left;
259
259
  --select-dropdown-max-height: 400px;
260
260
  --tab-card-bg: #f8f8f9;
@@ -254,7 +254,7 @@ export default {
254
254
  --table-cell-white-space: normal;
255
255
  --table-cell-padding-left: 9px;
256
256
  --table-cell-padding-right: 9px;
257
- --table-header-text-align: center;
257
+ --table-header-text-align: left;
258
258
  --table-data-text-align: left;
259
259
  --select-dropdown-max-height: 400px;
260
260
  --tab-card-bg: #f8f8f9;
@@ -254,7 +254,7 @@ export default {
254
254
  --table-cell-white-space: normal;
255
255
  --table-cell-padding-left: 9px;
256
256
  --table-cell-padding-right: 9px;
257
- --table-header-text-align: center;
257
+ --table-header-text-align: left;
258
258
  --table-data-text-align: left;
259
259
  --select-dropdown-max-height: 400px;
260
260
  --tab-card-bg: #f8f8f9;
@@ -254,7 +254,7 @@ export default {
254
254
  --table-cell-white-space: normal;
255
255
  --table-cell-padding-left: 9px;
256
256
  --table-cell-padding-right: 9px;
257
- --table-header-text-align: center;
257
+ --table-header-text-align: left;
258
258
  --table-data-text-align: left;
259
259
  --select-dropdown-max-height: 400px;
260
260
  --tab-card-bg: #f8f8f9;
@@ -254,7 +254,7 @@ export default {
254
254
  --table-cell-white-space: normal;
255
255
  --table-cell-padding-left: 9px;
256
256
  --table-cell-padding-right: 9px;
257
- --table-header-text-align: center;
257
+ --table-header-text-align: left;
258
258
  --table-data-text-align: left;
259
259
  --select-dropdown-max-height: 400px;
260
260
  --tab-card-bg: #f8f8f9;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambo-design/shared",
3
- "version": "1.0.0-beta.95",
3
+ "version": "1.0.0-beta.97",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -1,20 +1,20 @@
1
- export const builtInDictKeys = [
2
- 'SEX_ENUM',
3
- 'WHETHER_ENUM'
4
- ]
5
-
6
- export const builtInDictMap = {
7
- 'SEX_ENUM' : { '0': '女', '1': '男' },
8
- 'WHETHER_ENUM' : { '0': '否', '1': '是' }
9
- }
10
-
11
- export const builtInDictList = {
12
- 'SEX_ENUM' : [
13
- { K: '0', V: '女' },
14
- { K: '1', V: '男' },
15
- ],
16
- 'WHETHER_ENUM' : [
17
- { K: '0', V: '否' },
18
- { K: '1', V: '是' },
19
- ]
20
- }
1
+ export const builtInDictKeys = [
2
+ 'SEX_ENUM',
3
+ 'WHETHER_ENUM'
4
+ ]
5
+
6
+ export const builtInDictMap = {
7
+ 'SEX_ENUM' : { '0': '女', '1': '男' },
8
+ 'WHETHER_ENUM' : { '0': '否', '1': '是' }
9
+ }
10
+
11
+ export const builtInDictList = {
12
+ 'SEX_ENUM' : [
13
+ { K: '0', V: '女' },
14
+ { K: '1', V: '男' },
15
+ ],
16
+ 'WHETHER_ENUM' : [
17
+ { K: '0', V: '否' },
18
+ { K: '1', V: '是' },
19
+ ]
20
+ }
@@ -1,75 +1,75 @@
1
- import config from '../../config/config'
2
- import ajax from '../ajax'
3
- import { builtInDictKeys, builtInDictMap, builtInDictList} from './built-in-dict'
4
- import { setSessionStorage, getSessionStorage} from "../platform";
5
-
6
- export async function getAllDict(dictIdArray) {
7
- if (dictIdArray.length > 0) {
8
- try {
9
- const { data } = await ajax.get(`${config.upmsServerContext}/manage/acDict/getDictsForMulti`, { params: { dictIds : dictIdArray.join(",") } })
10
- let result = {}
11
- if (data.code == 1) {
12
- let dictList = data.data;
13
- for (let key in dictList) {
14
- let dicts = dictList[key]
15
- result[key] = {};
16
- if (dicts.length > 0) {
17
- result[key]['enumList'] = dicts
18
- setSessionStorage(key + '_LIST', dicts)
19
- let dictMap = {}
20
- for(let dict of dicts) {
21
- dictMap[dict.K] = dict.V;
22
- }
23
- result[key]['enumData'] = dictMap
24
- setSessionStorage(key + '_MAP', dictMap)
25
- } else if (builtInDictKeys.includes(key)) {
26
- let dicts = builtInDictList[key]
27
- result[key]['enumList'] = dicts
28
- setSessionStorage(key + '_LIST', dicts)
29
- let dictMap = {}
30
- for(let dict of dicts) {
31
- dictMap[dict.K] = dict.V;
32
- }
33
- result[key]['enumData'] = dictMap
34
- setSessionStorage(key + '_MAP', dictMap)
35
- }
36
- }
37
- }
38
- return result
39
- } catch (error) {
40
- console.error(`getDictsForMulti error dictId=${dictIdArray}`, error)
41
- }
42
- }
43
- }
44
-
45
- export async function getDictList(dictId) {
46
- if (builtInDictKeys.includes(dictId)) {
47
- return builtInDictList[dictId]
48
- }
49
- const dictValue = getSessionStorage(dictId + '_LIST')
50
- if (!!dictValue) {
51
- return dictValue
52
- }
53
- let data = await getAllDict([dictId]);
54
- return data[dictId];
55
- }
56
-
57
- export async function getDictMap(dictId) {
58
- if (builtInDictKeys.includes(dictId)) {
59
- return builtInDictMap[dictId]
60
- }
61
- const dictValue = getSessionStorage(dictId + '_MAP')
62
- if (!!dictValue) {
63
- return dictValue
64
- }
65
-
66
- try {
67
- const { data } = await ajax.get(`${config.upmsServerContext}/manage/acDict/getDictsMap`, { params: { dictId : dictId } })
68
- if (data.code == 1) {
69
- setSessionStorage(dictId + '_MAP', data.data)
70
- }
71
- return data.data
72
- } catch (error) {
73
- console.error(`getDictsMap error dictId=${dictId}`, error)
74
- }
75
- }
1
+ import config from '../../config/config'
2
+ import ajax from '../ajax'
3
+ import { builtInDictKeys, builtInDictMap, builtInDictList} from './built-in-dict'
4
+ import { setSessionStorage, getSessionStorage} from "../platform";
5
+
6
+ export async function getAllDict(dictIdArray) {
7
+ if (dictIdArray.length > 0) {
8
+ try {
9
+ const { data } = await ajax.get(`${config.upmsServerContext}/manage/acDict/getDictsForMulti`, { params: { dictIds : dictIdArray.join(",") } })
10
+ let result = {}
11
+ if (data.code == 1) {
12
+ let dictList = data.data;
13
+ for (let key in dictList) {
14
+ let dicts = dictList[key]
15
+ result[key] = {};
16
+ if (dicts.length > 0) {
17
+ result[key]['enumList'] = dicts
18
+ setSessionStorage(key + '_LIST', dicts)
19
+ let dictMap = {}
20
+ for(let dict of dicts) {
21
+ dictMap[dict.K] = dict.V;
22
+ }
23
+ result[key]['enumData'] = dictMap
24
+ setSessionStorage(key + '_MAP', dictMap)
25
+ } else if (builtInDictKeys.includes(key)) {
26
+ let dicts = builtInDictList[key]
27
+ result[key]['enumList'] = dicts
28
+ setSessionStorage(key + '_LIST', dicts)
29
+ let dictMap = {}
30
+ for(let dict of dicts) {
31
+ dictMap[dict.K] = dict.V;
32
+ }
33
+ result[key]['enumData'] = dictMap
34
+ setSessionStorage(key + '_MAP', dictMap)
35
+ }
36
+ }
37
+ }
38
+ return result
39
+ } catch (error) {
40
+ console.error(`getDictsForMulti error dictId=${dictIdArray}`, error)
41
+ }
42
+ }
43
+ }
44
+
45
+ export async function getDictList(dictId) {
46
+ if (builtInDictKeys.includes(dictId)) {
47
+ return builtInDictList[dictId]
48
+ }
49
+ const dictValue = getSessionStorage(dictId + '_LIST')
50
+ if (!!dictValue) {
51
+ return dictValue
52
+ }
53
+ let data = await getAllDict([dictId]);
54
+ return data[dictId];
55
+ }
56
+
57
+ export async function getDictMap(dictId) {
58
+ if (builtInDictKeys.includes(dictId)) {
59
+ return builtInDictMap[dictId]
60
+ }
61
+ const dictValue = getSessionStorage(dictId + '_MAP')
62
+ if (!!dictValue) {
63
+ return dictValue
64
+ }
65
+
66
+ try {
67
+ const { data } = await ajax.get(`${config.upmsServerContext}/manage/acDict/getDictsMap`, { params: { dictId : dictId } })
68
+ if (data.code == 1) {
69
+ setSessionStorage(dictId + '_MAP', data.data)
70
+ }
71
+ return data.data
72
+ } catch (error) {
73
+ console.error(`getDictsMap error dictId=${dictId}`, error)
74
+ }
75
+ }
package/utils/storage.js CHANGED
@@ -1,198 +1,198 @@
1
- /*
2
- * Copyright 2019 WeBank
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- /* \
19
- |*|
20
- |*| :: cookies.js ::
21
- |*|
22
- |*| A complete cookies reader/writer framework with full unicode support.
23
- |*|
24
- |*| https://developer.mozilla.org/en-US/docs/DOM/document.cookie
25
- |*|
26
- |*| This framework is released under the GNU Public License, version 3 or later.
27
- |*| http://www.gnu.org/licenses/gpl-3.0-standalone.html
28
- |*|
29
- |*| Syntaxes:
30
- |*|
31
- |*| * docCookies.setItem(name, value[, end[, path[, domain[, secure]]]])
32
- |*| * docCookies.getItem(name)
33
- |*| * docCookies.removeItem(name[, path], domain)
34
- |*| * docCookies.hasItem(name)
35
- |*| * docCookies.keys()
36
- |*|
37
- \ */
38
-
39
- let docCookies = {
40
- getItem: function(sKey) {
41
- return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
42
- },
43
- setItem: function(sKey, sValue, vEnd, sPath, sDomain, bSecure) {
44
- if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
45
- return false;
46
- }
47
- let sExpires = '';
48
- if (vEnd) {
49
- switch (vEnd.constructor) {
50
- case Number:
51
- sExpires = vEnd === Infinity ? '; expires=Fri, 31 Dec 9999 23:59:59 GMT' : '; max-age=' + vEnd;
52
- break;
53
- case String:
54
- sExpires = '; expires=' + vEnd;
55
- break;
56
- case Date:
57
- sExpires = '; expires=' + vEnd.toUTCString();
58
- break;
59
- }
60
- }
61
- document.cookie = encodeURIComponent(sKey) + '=' + encodeURIComponent(sValue) + sExpires + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '') + (bSecure ? '; secure' : '');
62
- return true;
63
- },
64
- removeItem: function(sKey, sPath, sDomain) {
65
- if (!sKey || !this.hasItem(sKey)) {
66
- return false;
67
- }
68
- document.cookie = encodeURIComponent(sKey) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT' + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '');
69
- return true;
70
- },
71
- hasItem: function(sKey) {
72
- return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
73
- },
74
- keys: /* optional method: you can safely remove it! */ function() {
75
- let aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, '').split(/\s*(?:\=[^;]*)?;\s*/);
76
- for (let nIdx = 0; nIdx < aKeys.length; nIdx++) {
77
- aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);
78
- }
79
- return aKeys;
80
- },
81
- };
82
-
83
- /**
84
- * 操作cookie、sessionStorage、localStorage、缓存
85
- */
86
-
87
- const
88
- SESSION = 'session';
89
-
90
- const LOCAL = 'local';
91
-
92
- const COOKIE = 'cookie';
93
-
94
- export default {
95
- set: function(key, value, category = SESSION, expired) {
96
- let { storage, isWebStorage = true } = this._map(category);
97
-
98
- if (isWebStorage) {
99
- storageManager.set(key, value, storage);
100
- } else {
101
- cookieManager.set(key, value, expired);
102
- }
103
- },
104
- get: function(key, category = SESSION) {
105
- let { storage, isWebStorage = true } = this._map(category);
106
-
107
- if (isWebStorage) {
108
- return storageManager.get(key, storage);
109
- } else {
110
- return cookieManager.get(key);
111
- }
112
- },
113
- clear: function(category = SESSION) {
114
- let { storage, isWebStorage = true } = this._map(category);
115
-
116
- if (isWebStorage) {
117
- storageManager.clear(storage);
118
- } else {
119
- cookieManager.clear();
120
- }
121
- },
122
- remove: function(key, category = SESSION) {
123
- let { storage, isWebStorage = true } = this._map(category);
124
-
125
- if (isWebStorage) {
126
- storageManager.remove(key, storage);
127
- } else {
128
- cookieManager.remove(key);
129
- }
130
- },
131
- _map: function(category) {
132
- let isWebStorage = true; let storage;
133
-
134
- switch (true) {
135
- case category === SESSION:
136
- storage = 'sessionStorage';
137
- break;
138
- case category === LOCAL:
139
- storage = 'localStorage';
140
- break;
141
- case category === COOKIE:
142
- storage = 'cookie';
143
- isWebStorage = false;
144
- break;
145
- default:
146
- storage = 'sessionStorage';
147
- }
148
-
149
- return { isWebStorage, storage };
150
- },
151
- };
152
-
153
- let isProd = process.env.NODE_ENV === 'production';
154
-
155
- export const storageManager = {
156
- set: function(key, value, storage) {
157
- try {
158
- window[storage].setItem(key, JSON.stringify(value));
159
- } catch (e) {
160
- !isProd && console.error(e);
161
- }
162
- },
163
- get: function(key, storage) {
164
- try {
165
- if (window[storage].getItem(key)) {
166
- return JSON.parse(window[storage].getItem(key));
167
- } else {
168
- return window[storage].getItem(key);
169
- }
170
- } catch (e) {
171
- !isProd && console.error(e, key);
172
- }
173
- },
174
- clear: function(storage) {
175
- window[storage].clear();
176
- },
177
- remove: function(key, storage) {
178
- window[storage].removeItem(key);
179
- },
180
- };
181
-
182
- export const cookieManager = {
183
- set: function(key, value, expired) {
184
- if (expired) docCookies.setItem(key, value, expired);
185
- else docCookies.setItem(key, value);
186
- },
187
- get: function(key) {
188
- return docCookies.getItem(key);
189
- },
190
- clear: function() {
191
- docCookies.keys().forEach((key) => {
192
- docCookies.removeItem(key);
193
- });
194
- },
195
- remove: function(key) {
196
- docCookies.removeItem(key);
197
- },
198
- };
1
+ /*
2
+ * Copyright 2019 WeBank
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ /* \
19
+ |*|
20
+ |*| :: cookies.js ::
21
+ |*|
22
+ |*| A complete cookies reader/writer framework with full unicode support.
23
+ |*|
24
+ |*| https://developer.mozilla.org/en-US/docs/DOM/document.cookie
25
+ |*|
26
+ |*| This framework is released under the GNU Public License, version 3 or later.
27
+ |*| http://www.gnu.org/licenses/gpl-3.0-standalone.html
28
+ |*|
29
+ |*| Syntaxes:
30
+ |*|
31
+ |*| * docCookies.setItem(name, value[, end[, path[, domain[, secure]]]])
32
+ |*| * docCookies.getItem(name)
33
+ |*| * docCookies.removeItem(name[, path], domain)
34
+ |*| * docCookies.hasItem(name)
35
+ |*| * docCookies.keys()
36
+ |*|
37
+ \ */
38
+
39
+ let docCookies = {
40
+ getItem: function(sKey) {
41
+ return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
42
+ },
43
+ setItem: function(sKey, sValue, vEnd, sPath, sDomain, bSecure) {
44
+ if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) {
45
+ return false;
46
+ }
47
+ let sExpires = '';
48
+ if (vEnd) {
49
+ switch (vEnd.constructor) {
50
+ case Number:
51
+ sExpires = vEnd === Infinity ? '; expires=Fri, 31 Dec 9999 23:59:59 GMT' : '; max-age=' + vEnd;
52
+ break;
53
+ case String:
54
+ sExpires = '; expires=' + vEnd;
55
+ break;
56
+ case Date:
57
+ sExpires = '; expires=' + vEnd.toUTCString();
58
+ break;
59
+ }
60
+ }
61
+ document.cookie = encodeURIComponent(sKey) + '=' + encodeURIComponent(sValue) + sExpires + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '') + (bSecure ? '; secure' : '');
62
+ return true;
63
+ },
64
+ removeItem: function(sKey, sPath, sDomain) {
65
+ if (!sKey || !this.hasItem(sKey)) {
66
+ return false;
67
+ }
68
+ document.cookie = encodeURIComponent(sKey) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT' + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '');
69
+ return true;
70
+ },
71
+ hasItem: function(sKey) {
72
+ return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
73
+ },
74
+ keys: /* optional method: you can safely remove it! */ function() {
75
+ let aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, '').split(/\s*(?:\=[^;]*)?;\s*/);
76
+ for (let nIdx = 0; nIdx < aKeys.length; nIdx++) {
77
+ aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);
78
+ }
79
+ return aKeys;
80
+ },
81
+ };
82
+
83
+ /**
84
+ * 操作cookie、sessionStorage、localStorage、缓存
85
+ */
86
+
87
+ const
88
+ SESSION = 'session';
89
+
90
+ const LOCAL = 'local';
91
+
92
+ const COOKIE = 'cookie';
93
+
94
+ export default {
95
+ set: function(key, value, category = SESSION, expired) {
96
+ let { storage, isWebStorage = true } = this._map(category);
97
+
98
+ if (isWebStorage) {
99
+ storageManager.set(key, value, storage);
100
+ } else {
101
+ cookieManager.set(key, value, expired);
102
+ }
103
+ },
104
+ get: function(key, category = SESSION) {
105
+ let { storage, isWebStorage = true } = this._map(category);
106
+
107
+ if (isWebStorage) {
108
+ return storageManager.get(key, storage);
109
+ } else {
110
+ return cookieManager.get(key);
111
+ }
112
+ },
113
+ clear: function(category = SESSION) {
114
+ let { storage, isWebStorage = true } = this._map(category);
115
+
116
+ if (isWebStorage) {
117
+ storageManager.clear(storage);
118
+ } else {
119
+ cookieManager.clear();
120
+ }
121
+ },
122
+ remove: function(key, category = SESSION) {
123
+ let { storage, isWebStorage = true } = this._map(category);
124
+
125
+ if (isWebStorage) {
126
+ storageManager.remove(key, storage);
127
+ } else {
128
+ cookieManager.remove(key);
129
+ }
130
+ },
131
+ _map: function(category) {
132
+ let isWebStorage = true; let storage;
133
+
134
+ switch (true) {
135
+ case category === SESSION:
136
+ storage = 'sessionStorage';
137
+ break;
138
+ case category === LOCAL:
139
+ storage = 'localStorage';
140
+ break;
141
+ case category === COOKIE:
142
+ storage = 'cookie';
143
+ isWebStorage = false;
144
+ break;
145
+ default:
146
+ storage = 'sessionStorage';
147
+ }
148
+
149
+ return { isWebStorage, storage };
150
+ },
151
+ };
152
+
153
+ let isProd = process.env.NODE_ENV === 'production';
154
+
155
+ export const storageManager = {
156
+ set: function(key, value, storage) {
157
+ try {
158
+ window[storage].setItem(key, JSON.stringify(value));
159
+ } catch (e) {
160
+ !isProd && console.error(e);
161
+ }
162
+ },
163
+ get: function(key, storage) {
164
+ try {
165
+ if (window[storage].getItem(key)) {
166
+ return JSON.parse(window[storage].getItem(key));
167
+ } else {
168
+ return window[storage].getItem(key);
169
+ }
170
+ } catch (e) {
171
+ !isProd && console.error(e, key);
172
+ }
173
+ },
174
+ clear: function(storage) {
175
+ window[storage].clear();
176
+ },
177
+ remove: function(key, storage) {
178
+ window[storage].removeItem(key);
179
+ },
180
+ };
181
+
182
+ export const cookieManager = {
183
+ set: function(key, value, expired) {
184
+ if (expired) docCookies.setItem(key, value, expired);
185
+ else docCookies.setItem(key, value);
186
+ },
187
+ get: function(key) {
188
+ return docCookies.getItem(key);
189
+ },
190
+ clear: function() {
191
+ docCookies.keys().forEach((key) => {
192
+ docCookies.removeItem(key);
193
+ });
194
+ },
195
+ remove: function(key) {
196
+ docCookies.removeItem(key);
197
+ },
198
+ };
package/utils/type.js CHANGED
@@ -1,102 +1,102 @@
1
- /*
2
- * Copyright 2019 WeBank
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- */
17
-
18
- const objectToString = Object.prototype.toString;
19
- const OBJECT_STRING = '[object Object]';
20
-
21
- /**
22
- * 是否是普通对象
23
- * @param {any} obj
24
- * @return {Boolean}
25
- */
26
- export function isPlainObject(obj) {
27
- return objectToString.call(obj) === OBJECT_STRING;
28
- }
29
-
30
- /**
31
- * 是否是数字
32
- * @param {any} value
33
- * @return {Boolean}
34
- */
35
- export function isNumber(value) {
36
- return typeof value === 'number';
37
- }
38
-
39
- /**
40
- * 是否是日期
41
- * @param {any} value
42
- * @return {Boolean}
43
- */
44
- export function isDate(value) {
45
- return objectToString.call(value) === '[object Date]';
46
- }
47
-
48
- /**
49
- * 是否是函数
50
- * @param {any} value
51
- * @return {Boolean}
52
- */
53
- export function isFunction(value) {
54
- return typeof value === 'function';
55
- }
56
-
57
- /**
58
- * 是否是函数
59
- * @param {any} value
60
- * @return {Boolean}
61
- */
62
- export function isObject(value) {
63
- let type = typeof value;
64
- return !!value && (type == 'object' || type == 'function');
65
- }
66
-
67
- /**
68
- * 是否是数组
69
- * @param {any} value
70
- * @return {Boolean}
71
- */
72
- export function isArray(value) {
73
- return Array.isArray(value);
74
- }
75
-
76
- /**
77
- * 是否像对象
78
- * @param {any} value
79
- * @return {Boolean}
80
- */
81
- export function isObjectLike(value) {
82
- return !!value && typeof value == 'object';
83
- }
84
-
85
- /**
86
- * 是否是字符串
87
- * @param {any} value
88
- * @return {Boolean}
89
- */
90
- export function isString(value) {
91
- return typeof value == 'string' ||
92
- (!isArray(value) && isObjectLike(value) && objectToString.call(value) == '[object String]');
93
- }
94
-
95
- /**
96
- * 是否是空的
97
- * @param {any} value
98
- * @return {Boolean}
99
- */
100
- export function isNull(value) {
101
- return value === undefined || value === null || value === '';
102
- }
1
+ /*
2
+ * Copyright 2019 WeBank
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ const objectToString = Object.prototype.toString;
19
+ const OBJECT_STRING = '[object Object]';
20
+
21
+ /**
22
+ * 是否是普通对象
23
+ * @param {any} obj
24
+ * @return {Boolean}
25
+ */
26
+ export function isPlainObject(obj) {
27
+ return objectToString.call(obj) === OBJECT_STRING;
28
+ }
29
+
30
+ /**
31
+ * 是否是数字
32
+ * @param {any} value
33
+ * @return {Boolean}
34
+ */
35
+ export function isNumber(value) {
36
+ return typeof value === 'number';
37
+ }
38
+
39
+ /**
40
+ * 是否是日期
41
+ * @param {any} value
42
+ * @return {Boolean}
43
+ */
44
+ export function isDate(value) {
45
+ return objectToString.call(value) === '[object Date]';
46
+ }
47
+
48
+ /**
49
+ * 是否是函数
50
+ * @param {any} value
51
+ * @return {Boolean}
52
+ */
53
+ export function isFunction(value) {
54
+ return typeof value === 'function';
55
+ }
56
+
57
+ /**
58
+ * 是否是函数
59
+ * @param {any} value
60
+ * @return {Boolean}
61
+ */
62
+ export function isObject(value) {
63
+ let type = typeof value;
64
+ return !!value && (type == 'object' || type == 'function');
65
+ }
66
+
67
+ /**
68
+ * 是否是数组
69
+ * @param {any} value
70
+ * @return {Boolean}
71
+ */
72
+ export function isArray(value) {
73
+ return Array.isArray(value);
74
+ }
75
+
76
+ /**
77
+ * 是否像对象
78
+ * @param {any} value
79
+ * @return {Boolean}
80
+ */
81
+ export function isObjectLike(value) {
82
+ return !!value && typeof value == 'object';
83
+ }
84
+
85
+ /**
86
+ * 是否是字符串
87
+ * @param {any} value
88
+ * @return {Boolean}
89
+ */
90
+ export function isString(value) {
91
+ return typeof value == 'string' ||
92
+ (!isArray(value) && isObjectLike(value) && objectToString.call(value) == '[object String]');
93
+ }
94
+
95
+ /**
96
+ * 是否是空的
97
+ * @param {any} value
98
+ * @return {Boolean}
99
+ */
100
+ export function isNull(value) {
101
+ return value === undefined || value === null || value === '';
102
+ }