@lambo-design/shared 1.0.0-beta.236 → 1.0.0-beta.239
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/config/config.js +51 -51
- package/config/env.js +4 -4
- package/config/index.js +7 -7
- package/config/themes/atrovirens/atrovirens.less +667 -667
- package/config/themes/atrovirens/var.less +674 -674
- package/config/themes/blue/blue.less +669 -669
- package/config/themes/blue/var.less +677 -677
- package/config/themes/blue-white/blue-white.less +669 -669
- package/config/themes/blue-white/var.less +676 -676
- package/config/themes/blue-white-tight/blue-white-tight.less +672 -672
- package/config/themes/blue-white-tight/var.less +677 -677
- package/config/themes/danqing/danqing.css +4 -4
- package/config/themes/danqing/danqing.css.map +1 -1
- package/config/themes/danqing/danqing.less +668 -668
- package/config/themes/danqing/danqing.wxss +572 -572
- package/config/themes/danqing/var.less +679 -679
- package/config/themes/deep/deep.less +669 -669
- package/config/themes/deep/var.less +677 -677
- package/config/themes/default/default.less +671 -671
- package/config/themes/default/var.less +677 -677
- package/config/themes/eap/eap.less +671 -671
- package/config/themes/eap/var.less +677 -677
- package/config/themes/gold/gold.less +671 -671
- package/config/themes/gold/var.less +677 -677
- package/config/themes/index.js +28 -28
- package/config/themes/lime/lime.less +671 -671
- package/config/themes/lime/var.less +678 -678
- package/config/themes/orange/orange.less +671 -671
- package/config/themes/orange/var.less +678 -678
- package/config/themes/red/red.less +671 -671
- package/config/themes/red/var.less +677 -677
- package/config/themes/theme-atrovirens.js +558 -558
- package/config/themes/theme-blue.js +558 -558
- package/config/themes/theme-bw.js +558 -558
- package/config/themes/theme-bwt.js +559 -559
- package/config/themes/theme-danqing.js +558 -558
- package/config/themes/theme-deep.js +558 -558
- package/config/themes/theme-default.js +558 -558
- package/config/themes/theme-eap.js +558 -558
- package/config/themes/theme-gold.js +558 -558
- package/config/themes/theme-lime.js +558 -558
- package/config/themes/theme-orange.js +559 -559
- package/config/themes/theme-red.js +558 -558
- package/config/themes/theme-white.js +557 -557
- package/config/themes/white/var.less +675 -675
- package/config/themes/white/white.less +668 -668
- package/directives/index.js +23 -23
- package/directives/module/draggable.js +56 -56
- package/directives/module/permission.js +49 -49
- package/directives/module/print.js +1 -1
- package/directives/module/vue-print-nb/README.md +63 -63
- package/directives/module/vue-print-nb/print.js +94 -94
- package/directives/module/vue-print-nb/printarea.js +532 -532
- package/index.js +10 -10
- package/nstyles/common.less +197 -197
- package/nstyles/components/404.less +46 -46
- package/nstyles/components/button.less +34 -34
- package/nstyles/components/date-picker.less +37 -37
- package/nstyles/components/drawer.less +20 -20
- package/nstyles/components/dropdown.less +18 -18
- package/nstyles/components/excel-flow.less +72 -72
- package/nstyles/components/form.less +313 -303
- package/nstyles/components/index.less +23 -23
- package/nstyles/components/layout/collect.less +10 -10
- package/nstyles/components/layout/detail-view.less +107 -107
- package/nstyles/components/layout/full-screen.less +7 -7
- package/nstyles/components/layout/index.less +7 -7
- package/nstyles/components/layout/other-menu.less +142 -142
- package/nstyles/components/layout/page-view.less +101 -101
- package/nstyles/components/layout/sider-trigger.less +41 -41
- package/nstyles/components/layout/tags-nav.less +113 -113
- package/nstyles/components/modal.less +85 -85
- package/nstyles/components/n-button.less +131 -131
- package/nstyles/components/n-image-preview.less +131 -131
- package/nstyles/components/n-model/index.less +19 -19
- package/nstyles/components/n-model/report-index.less +43 -43
- package/nstyles/components/n-panel.less +40 -40
- package/nstyles/components/n-picker.less +37 -37
- package/nstyles/components/n-sign.less +17 -17
- package/nstyles/components/n-tooltip.less +10 -10
- package/nstyles/components/panel.less +31 -31
- package/nstyles/components/select.less +3 -3
- package/nstyles/components/sign.less +27 -27
- package/nstyles/components/table.less +315 -315
- package/nstyles/components/tree.less +158 -158
- package/nstyles/components/upload.less +164 -164
- package/nstyles/index.less +5 -5
- package/nstyles/reset.less +65 -65
- package/nstyles/third/ag.less +174 -174
- package/nstyles/third/index.less +11 -11
- package/nstyles/third/view-design.less +366 -366
- package/nstyles/variables/base.less +143 -143
- package/nstyles/variables/index.less +4 -4
- package/nstyles/variables/theme/default/button.less +7 -7
- package/nstyles/variables/theme/default/common.less +57 -57
- package/nstyles/variables/theme/default/index.less +7 -7
- package/nstyles/variables/theme/default/layout.less +40 -40
- package/nstyles/variables/theme/default/table.less +37 -37
- package/nstyles/variables/theme/default/tag.less +3 -3
- package/nstyles/variables/theme/default/upload.less +3 -3
- package/nstyles/variables/theme/index.less +13 -13
- package/nstyles/variables/theme/small/button.less +7 -7
- package/nstyles/variables/theme/small/common.less +39 -39
- package/nstyles/variables/theme/small/index.less +5 -5
- package/nstyles/variables/theme/small/layout.less +21 -21
- package/nstyles/variables/theme/small/table.less +17 -17
- package/nstyles/variables/theme/small/tag.less +3 -3
- package/package.json +1 -1
- package/plugin/index.js +12 -12
- package/plugin/module/date-format.js +30 -30
- package/plugin/module/loading.js +26 -26
- package/plugin/module/warn-handler.js +11 -11
- package/styles/variables.less +21 -21
- package/utils/ajax/cacheconf.js +19 -19
- package/utils/ajax/content-type.js +30 -30
- package/utils/ajax/index.js +12 -12
- package/utils/ajax/interceptors.js +97 -97
- package/utils/assist.js +147 -147
- package/utils/base64.js +126 -126
- package/utils/blob.js +47 -47
- package/utils/bus.js +3 -3
- package/utils/crypto/index.js +48 -48
- package/utils/crypto/md5.js +152 -152
- package/utils/crypto/sm3.js +235 -235
- package/utils/date.js +381 -381
- package/utils/dict/built-in-dict.js +20 -20
- package/utils/dict/index.js +167 -167
- package/utils/dom.js +38 -38
- package/utils/event.js +72 -72
- package/utils/excel.js +655 -655
- package/utils/file.js +19 -19
- package/utils/form/validate.js +29 -29
- package/utils/half-year.js +68 -68
- package/utils/index.js +41 -41
- package/utils/json.js +29 -29
- package/utils/lodop.js +165 -165
- package/utils/menu/before-close.js +17 -17
- package/utils/menu/index.js +395 -395
- package/utils/mime_type.js +67 -67
- package/utils/modelerUtil.js +227 -227
- package/utils/n/api.js +22 -22
- package/utils/n/date.js +57 -57
- package/utils/n/index.js +9 -9
- package/utils/n/is-type.js +176 -176
- package/utils/n/number.js +144 -144
- package/utils/n/permission-cache.js +11 -11
- package/utils/n/reuqest/axiosN.js +17 -17
- package/utils/n/reuqest/content-type.js +19 -19
- package/utils/n/reuqest/interceptors.js +95 -95
- package/utils/n/reuqest/url-params.js +12 -12
- package/utils/n/storage.js +51 -51
- package/utils/n/token.js +51 -51
- package/utils/n/user-cache.js +11 -11
- package/utils/n/user.js +34 -34
- package/utils/n/uuid.js +16 -16
- package/utils/n-generator-routers.js +208 -208
- package/utils/n-router.js +205 -205
- package/utils/n-theme.js +30 -30
- package/utils/number.js +180 -180
- package/utils/oss.js +57 -57
- package/utils/platform.js +1334 -1334
- package/utils/quarter.js +58 -58
- package/utils/storage.js +198 -198
- package/utils/style.js +24 -24
- package/utils/theme.js +138 -138
- package/utils/transfer-queue.js +7 -7
- package/utils/transform.js +179 -0
- package/utils/type.js +102 -102
- package/utils/util.js +795 -795
- package/utils/validator.js +181 -181
- package/utils/vxetable/index.js +25 -25
- package/utils/zoomScroll.js +9 -9
package/utils/quarter.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
// 获取季度汉字
|
|
2
|
-
export function quarter2Chinese(quarterNum) {
|
|
3
|
-
let quarterList = ['一', '二', '三', '四']
|
|
4
|
-
return quarterNum ? quarterList[quarterNum - 1] : ''
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
// 获取季度
|
|
8
|
-
export function getQuarter(date) {
|
|
9
|
-
if (!date || date.length < 6) {
|
|
10
|
-
return ''
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const year = date.substring(0, 4)
|
|
14
|
-
const month = date.substring(4, 6)
|
|
15
|
-
const quarter = getQuarterNum(parseInt(month))
|
|
16
|
-
return `${year}Q${quarter}`
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getQuarterNum(month) {
|
|
20
|
-
if (typeof month === 'string') {
|
|
21
|
-
if (isNaN(parseInt(month))) return 0
|
|
22
|
-
month = parseInt(month)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return Math.ceil(month / 3)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function formatQuarter(quarter) {
|
|
29
|
-
if (!quarter || quarter.length < 6) {
|
|
30
|
-
return quarter
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const year = quarter.substring(0, 4)
|
|
34
|
-
const quarterNum = parseInt(quarter.substring(5))
|
|
35
|
-
return `${year}第${quarter2Chinese(quarterNum)}季度`
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function getQuarterBeginMonth(quarter) {
|
|
39
|
-
if (!quarter || quarter.length < 6) {
|
|
40
|
-
return quarter
|
|
41
|
-
}
|
|
42
|
-
const year = quarter.substring(0, 4)
|
|
43
|
-
const quarterNum = parseInt(quarter.substring(5))
|
|
44
|
-
const beginMonth = quarterNum * 3 - 2
|
|
45
|
-
const monthStr = beginMonth < 10 ? `0${beginMonth}` : `${beginMonth}`
|
|
46
|
-
return `${year}${monthStr}`
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function getQuarterEndMonth(quarter) {
|
|
50
|
-
if (!quarter || quarter.length < 6) {
|
|
51
|
-
return quarter
|
|
52
|
-
}
|
|
53
|
-
const year = quarter.substring(0, 4)
|
|
54
|
-
const quarterNum = parseInt(quarter.substring(5))
|
|
55
|
-
const endMonth = quarterNum * 3
|
|
56
|
-
const monthStr = endMonth < 10 ? `0${endMonth}` : `${endMonth}`
|
|
57
|
-
return `${year}${monthStr}`
|
|
58
|
-
}
|
|
1
|
+
// 获取季度汉字
|
|
2
|
+
export function quarter2Chinese(quarterNum) {
|
|
3
|
+
let quarterList = ['一', '二', '三', '四']
|
|
4
|
+
return quarterNum ? quarterList[quarterNum - 1] : ''
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// 获取季度
|
|
8
|
+
export function getQuarter(date) {
|
|
9
|
+
if (!date || date.length < 6) {
|
|
10
|
+
return ''
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const year = date.substring(0, 4)
|
|
14
|
+
const month = date.substring(4, 6)
|
|
15
|
+
const quarter = getQuarterNum(parseInt(month))
|
|
16
|
+
return `${year}Q${quarter}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getQuarterNum(month) {
|
|
20
|
+
if (typeof month === 'string') {
|
|
21
|
+
if (isNaN(parseInt(month))) return 0
|
|
22
|
+
month = parseInt(month)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return Math.ceil(month / 3)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function formatQuarter(quarter) {
|
|
29
|
+
if (!quarter || quarter.length < 6) {
|
|
30
|
+
return quarter
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const year = quarter.substring(0, 4)
|
|
34
|
+
const quarterNum = parseInt(quarter.substring(5))
|
|
35
|
+
return `${year}第${quarter2Chinese(quarterNum)}季度`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getQuarterBeginMonth(quarter) {
|
|
39
|
+
if (!quarter || quarter.length < 6) {
|
|
40
|
+
return quarter
|
|
41
|
+
}
|
|
42
|
+
const year = quarter.substring(0, 4)
|
|
43
|
+
const quarterNum = parseInt(quarter.substring(5))
|
|
44
|
+
const beginMonth = quarterNum * 3 - 2
|
|
45
|
+
const monthStr = beginMonth < 10 ? `0${beginMonth}` : `${beginMonth}`
|
|
46
|
+
return `${year}${monthStr}`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getQuarterEndMonth(quarter) {
|
|
50
|
+
if (!quarter || quarter.length < 6) {
|
|
51
|
+
return quarter
|
|
52
|
+
}
|
|
53
|
+
const year = quarter.substring(0, 4)
|
|
54
|
+
const quarterNum = parseInt(quarter.substring(5))
|
|
55
|
+
const endMonth = quarterNum * 3
|
|
56
|
+
const monthStr = endMonth < 10 ? `0${endMonth}` : `${endMonth}`
|
|
57
|
+
return `${year}${monthStr}`
|
|
58
|
+
}
|
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/style.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g
|
|
2
|
-
const MOZ_HACK_REGEXP = /^moz([A-Z])/
|
|
3
|
-
|
|
4
|
-
function camelCase(name) {
|
|
5
|
-
return name
|
|
6
|
-
.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
|
|
7
|
-
return offset ? letter.toUpperCase() : letter
|
|
8
|
-
})
|
|
9
|
-
.replace(MOZ_HACK_REGEXP, 'Moz$1')
|
|
10
|
-
}
|
|
11
|
-
// getStyle
|
|
12
|
-
export function getStyle(element, styleName) {
|
|
13
|
-
if (!element || !styleName) return null
|
|
14
|
-
styleName = camelCase(styleName)
|
|
15
|
-
if (styleName === 'float') {
|
|
16
|
-
styleName = 'cssFloat'
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
const computed = document.defaultView.getComputedStyle(element, '')
|
|
20
|
-
return element.style[styleName] || computed ? computed[styleName] : null
|
|
21
|
-
} catch (e) {
|
|
22
|
-
return element.style[styleName]
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g
|
|
2
|
+
const MOZ_HACK_REGEXP = /^moz([A-Z])/
|
|
3
|
+
|
|
4
|
+
function camelCase(name) {
|
|
5
|
+
return name
|
|
6
|
+
.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
|
|
7
|
+
return offset ? letter.toUpperCase() : letter
|
|
8
|
+
})
|
|
9
|
+
.replace(MOZ_HACK_REGEXP, 'Moz$1')
|
|
10
|
+
}
|
|
11
|
+
// getStyle
|
|
12
|
+
export function getStyle(element, styleName) {
|
|
13
|
+
if (!element || !styleName) return null
|
|
14
|
+
styleName = camelCase(styleName)
|
|
15
|
+
if (styleName === 'float') {
|
|
16
|
+
styleName = 'cssFloat'
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const computed = document.defaultView.getComputedStyle(element, '')
|
|
20
|
+
return element.style[styleName] || computed ? computed[styleName] : null
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return element.style[styleName]
|
|
23
|
+
}
|
|
24
|
+
}
|