@lambo-design/shared 1.0.0-beta.315 → 1.0.0-beta.317
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/nstyles/third/ag.less +17 -1
- package/package.json +1 -1
- package/styles/image/layout-header-bg-cuiwei.png +0 -0
- package/utils/excel.js +32 -7
- package/utils/storage.js +198 -198
- package/utils/type.js +102 -102
package/nstyles/third/ag.less
CHANGED
|
@@ -207,4 +207,20 @@
|
|
|
207
207
|
|
|
208
208
|
.column-highlight {
|
|
209
209
|
background: var(--ag-selected-row-background-color);
|
|
210
|
-
}
|
|
210
|
+
}
|
|
211
|
+
.heard-highlight {
|
|
212
|
+
background: var(--ag-selected-row-background-color) !important;
|
|
213
|
+
border-bottom: 2px solid rgb(120, 180, 99) !important;
|
|
214
|
+
color: #000 !important;
|
|
215
|
+
}
|
|
216
|
+
.cellClick-highlight {
|
|
217
|
+
background: rgb(120, 180, 99) !important;
|
|
218
|
+
font-weight: 700 !important;
|
|
219
|
+
color: #000 !important;
|
|
220
|
+
}
|
|
221
|
+
.cellClick-index-highlight {
|
|
222
|
+
border-left: 2px solid rgb(120, 180, 99) !important;
|
|
223
|
+
background: var(--ag-selected-row-background-color) !important;
|
|
224
|
+
font-weight: 700 !important;
|
|
225
|
+
color: #000 !important;
|
|
226
|
+
}
|
package/package.json
CHANGED
|
Binary file
|
package/utils/excel.js
CHANGED
|
@@ -85,6 +85,14 @@ let bodyStyle = {
|
|
|
85
85
|
alignment: {vertical: "center"}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* 表格底部扩展行样式
|
|
90
|
+
* @type {alignment: {vertical: string}}
|
|
91
|
+
*/
|
|
92
|
+
let footerStyle = {
|
|
93
|
+
alignment: {vertical: "center"}
|
|
94
|
+
}
|
|
95
|
+
|
|
88
96
|
/**
|
|
89
97
|
* 过滤掉filterData中titleRules、typeRules相关的列
|
|
90
98
|
* @param filterData
|
|
@@ -304,7 +312,7 @@ export const enums_to_value = (enums,jsonData)=>{
|
|
|
304
312
|
}
|
|
305
313
|
}
|
|
306
314
|
|
|
307
|
-
function auto_width(ws, data) {
|
|
315
|
+
function auto_width(ws, data, startRow=0) {
|
|
308
316
|
/*set worksheet max width per col*/
|
|
309
317
|
const colWidth = data.map(row => row.map(val => {
|
|
310
318
|
/*if null/undefined*/
|
|
@@ -320,7 +328,12 @@ function auto_width(ws, data) {
|
|
|
320
328
|
}))
|
|
321
329
|
/*start in the first row*/
|
|
322
330
|
let result = colWidth[0];
|
|
323
|
-
|
|
331
|
+
if (startRow > 0) {
|
|
332
|
+
// 排除header中title和search数据
|
|
333
|
+
result = colWidth[startRow];
|
|
334
|
+
}
|
|
335
|
+
// 计算列宽时,查询条件行数据不参与计算
|
|
336
|
+
for (let i = startRow > 0 ? startRow : 1; i < colWidth.length; i++) {
|
|
324
337
|
for (let j = 0; j < colWidth[i].length; j++) {
|
|
325
338
|
if (result[j]['wch'] < colWidth[i][j]['wch']) {
|
|
326
339
|
result[j]['wch'] = colWidth[i][j]['wch'] > 7 ? colWidth[i][j]['wch'] : 7;
|
|
@@ -451,7 +464,7 @@ function merge_content({ws, tableData, spanColumnKeys, startRow}) {
|
|
|
451
464
|
ws['!merges'] = ws['!merges'].concat(mergeData)
|
|
452
465
|
}
|
|
453
466
|
|
|
454
|
-
function add_style({ws, title, startRow}) {
|
|
467
|
+
function add_style({ws, title, startRow, footerRow}) {
|
|
455
468
|
|
|
456
469
|
// 补充空白数据
|
|
457
470
|
let rangs = ws['!ref'].split(":");
|
|
@@ -475,9 +488,16 @@ function add_style({ws, title, startRow}) {
|
|
|
475
488
|
})
|
|
476
489
|
|
|
477
490
|
let titleReg = new RegExp("^[A-Z]1$", "im");
|
|
478
|
-
let titleExtReg = new RegExp("^[A-Z][
|
|
491
|
+
let titleExtReg = new RegExp("^[A-Z][1-" + parseInt(startRow>0?startRow:2) + "]$", "im");
|
|
479
492
|
let headReg = new RegExp("^[A-Z]+[" + parseInt(startRow + 1) + "-" + parseInt(startRow + title.length) + "]$", "im");
|
|
480
493
|
let bodyReg = new RegExp("^[A-Z]+([" + parseInt(startRow + title.length) + "-9]|[1-9]\\d+)$", "im");
|
|
494
|
+
let footerExtReg = null
|
|
495
|
+
|
|
496
|
+
if (footerRow === 1) {
|
|
497
|
+
// 底部扩展最后一行正则表达式 该行样式需要无边框
|
|
498
|
+
footerExtReg = new RegExp("^[A-Z]" + rowSum + "$", "im");
|
|
499
|
+
}
|
|
500
|
+
|
|
481
501
|
Object.keys(ws).forEach(item => {
|
|
482
502
|
if(titleReg.test(item)&&startRow>0){
|
|
483
503
|
/**
|
|
@@ -494,6 +514,11 @@ function add_style({ws, title, startRow}) {
|
|
|
494
514
|
* 加载表头样式:蓝色背景,水平垂直居中,边框
|
|
495
515
|
*/
|
|
496
516
|
ws[item].s = headStyle
|
|
517
|
+
} else if (footerExtReg && footerExtReg.test(item)) {
|
|
518
|
+
/**
|
|
519
|
+
* 加载表尾样式:无边框,垂直居中
|
|
520
|
+
*/
|
|
521
|
+
ws[item].s = footerStyle
|
|
497
522
|
} else if (bodyReg.test(item)) {
|
|
498
523
|
/**
|
|
499
524
|
* 表体样式: 垂直居中,边框
|
|
@@ -561,7 +586,8 @@ export const export_array_to_excel = ({key, data, title, header = [], footer = [
|
|
|
561
586
|
|
|
562
587
|
const ws = XLSX.utils.aoa_to_sheet(arr);
|
|
563
588
|
if (autoWidth) {
|
|
564
|
-
|
|
589
|
+
// 计算列宽时,查询条件行数据不参与计算
|
|
590
|
+
auto_width(ws, arr, header.length);
|
|
565
591
|
}
|
|
566
592
|
// 合并表头
|
|
567
593
|
if (!ws['!merges']) ws['!merges'] = [];
|
|
@@ -569,9 +595,8 @@ export const export_array_to_excel = ({key, data, title, header = [], footer = [
|
|
|
569
595
|
merge_cell({ws, data:title, startRow: header.length})
|
|
570
596
|
}
|
|
571
597
|
merge_cell({ws,data:header,startRow: 0 })
|
|
572
|
-
console.log(data)
|
|
573
598
|
merge_content(ws, data, spanColumns, title.length + header.length)
|
|
574
|
-
add_style({ws, title, startRow: header.length})
|
|
599
|
+
add_style({ws, title, startRow: header.length, footerRow: footer.length})
|
|
575
600
|
XLSX.utils.book_append_sheet(wb, ws, '');
|
|
576
601
|
if(format === 'csv'){
|
|
577
602
|
XLSX.writeFile(wb, filename + '.' + format,{
|
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
|
+
}
|