@lambo-design/shared 1.0.0-beta.285 → 1.0.0-beta.287

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 CHANGED
@@ -1,3 +1,5 @@
1
+ import { t } from '@lambo-design/core/src/locale';
2
+
1
3
  let config = {
2
4
  title: 'LamboDesign',
3
5
  serverContext: '/',
@@ -12,7 +14,7 @@ let config = {
12
14
  "query": {},
13
15
  "meta": {
14
16
  "hideInMenu": true,
15
- "title": "首页",
17
+ "title": t('config.home'),
16
18
  "icon": "md-home",
17
19
  "appId": "home"
18
20
  },
@@ -28,7 +30,7 @@ let config = {
28
30
  immServerContext: '/imarket-manage-server',
29
31
  mobileWidth:375,
30
32
  mobileHeight:667,
31
- errorMessage: '数据请求出错,请稍后尝试',
33
+ errorMessage: t('config.error-message'),
32
34
  nHomeRouteName: "home",
33
35
  showMenus:false,
34
36
  ecagiLamboPagingTableAppId: '',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambo-design/shared",
3
- "version": "1.0.0-beta.285",
3
+ "version": "1.0.0-beta.287",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -0,0 +1,139 @@
1
+ let enUSData = {
2
+ 'config': {
3
+ 'home': 'Home',
4
+ 'error-message': 'Request error,Try again later!',
5
+ 'default-menu': 'Default Menu',
6
+ },
7
+ 'pro-layout':{
8
+ 'common': {
9
+ 'systemName' : 'Backend management system'
10
+ },
11
+ 'header': {
12
+ 'collect' : 'Collect',
13
+ 'document': 'Document',
14
+ 'fullscreen': 'Fullscreen',
15
+ 'quit-fullscreen': 'Exit Fullscreen',
16
+ 'language': 'Language',
17
+ 'notice-more': 'View More',
18
+ 'notice-read': 'Mark All Notice',
19
+ 'notice-no-data': 'No Unread Notice',
20
+ 'search-menu': 'Search Menu',
21
+ 'search-loading': 'Loading',
22
+ 'search-type-menu': 'Menu',
23
+ 'search-type-notice': 'Notice',
24
+ 'search-type-message': 'Message',
25
+ 'search-more': 'More',
26
+ 'search-no-data': 'No Data',
27
+ 'todo-more': 'View More',
28
+ 'todo-no-data': 'No Task',
29
+ 'user-welcome': 'Welcome',
30
+ 'user-change-theme': 'Switch Theme',
31
+ 'user-custom-theme': 'Custom Theme',
32
+ 'user-person-center': 'Personal Center',
33
+ 'user-notice': 'Notice',
34
+ 'user-logout': 'Logout',
35
+ 'user-default-name': 'Admin',
36
+ 'theme': 'Theme',
37
+ 'theme-default': 'Default',
38
+ },
39
+ 'side': {
40
+ 'history': 'History',
41
+ 'collect': 'Collect',
42
+ 'history-menu': 'History Menu',
43
+ 'collect-menu': 'Collect Menu',
44
+ 'search-menu': 'Search Menu',
45
+ 'search-loading': 'Loading',
46
+ 'search-no-data': 'No Data'
47
+ },
48
+ 'tabs': {
49
+ 'close-all': 'Close All',
50
+ 'close-others': 'Close Others'
51
+ },
52
+ 'content': {
53
+
54
+ },
55
+ 'footer': {
56
+
57
+ },
58
+ },
59
+ 'login-form': {
60
+ 'box': {
61
+ 'form-user-name': 'Please enter your username',
62
+ 'form-user-pas': 'Please enter the password',
63
+ 'form-user-valid-code': 'Please enter the verification code',
64
+ 'form-user-sms-code': 'Please check the text message and enter the verification code',
65
+ 'form-user-mail-code': 'Please check the email and enter the verification code',
66
+ 'form-remember': 'Remember account',
67
+ 'form-forget': 'Forgot Password?',
68
+ 'form-login': 'Login',
69
+ 'form-rule-user-name': 'The account cannot be empty',
70
+ 'form-rule-user-pas': 'The password cannot be empty',
71
+ 'form-rule-valid-code': 'The verification code cannot be empty',
72
+ 'form-rule-click-login': 'Please click to proceed with login verification',
73
+ 'form-rule-click-valid': 'Click to verify'
74
+ },
75
+ 'other': {
76
+ 'get-valid-code': 'Get verification code',
77
+ 'get-valid-code-later': 's retrieve it again later',
78
+ 'send-success': 'Sent successfully',
79
+ 'captcha-method-image': 'Image',
80
+ 'captcha-method-sms': 'Text message',
81
+ 'captcha-method-mail': 'Email',
82
+ 'captcha-method-slide-image': 'Slide the image',
83
+ 'check-valid-code': 'Verifying...',
84
+ 'check-success': 'Verification successful',
85
+ 'check-fail': 'Verification failed, please try again later!',
86
+ }
87
+ },
88
+ 'login-page': {
89
+ 'box': {
90
+ 'welcome-login' : 'Welcome to login'
91
+ },
92
+ 'forget-pas': {
93
+ 'return': 'Return',
94
+ 'form-user-name': 'Account',
95
+ 'next-step': 'Next step',
96
+ 'get-back-way': 'Recovery method',
97
+ 'choose-get-back-way': 'Please select the recovery method',
98
+ 'get-back-way-mail': 'Email address',
99
+ 'get-back-way-sms': 'Phone number',
100
+ 'input-mail': 'Please enter your email address',
101
+ 'input-phone': 'Please enter your phone number',
102
+ 'new-pas': 'New login password',
103
+ 'confirm-new-pas': 'Confirm new login password',
104
+ 'reset-success': 'Reset successful!',
105
+ 'redirect-later': 's automatically return to the login page',
106
+ 'redirect': 'ֱDirect jump',
107
+ 'step-title-1':'Confirm the account',
108
+ 'step-title-2':'Recovery method',
109
+ 'step-title-3':'Safety Certification',
110
+ 'step-title-4':'Change password',
111
+ 'step-title-5':'Modification completed',
112
+ 'rule-new-pas': 'The new password cannot be empty',
113
+ 'rule-pas-1': 'The password length must be greater than',
114
+ 'rule-pas-2': 'The password length must be less than',
115
+ 'rule-pas-3': 'The password must contain uppercase letters',
116
+ 'rule-pas-4': 'The password must contain lowercase letters',
117
+ 'rule-pas-5': 'The password must contain numbers',
118
+ 'rule-pas-6': 'The password must contain special characters',
119
+ 'rule-pas-7': 'Confirm password cannot be empty',
120
+ 'rule-pas-8': 'The passwords entered twice do not match',
121
+ 'rule-pas-9': 'Please enter a valid email address',
122
+ 'rule-pas-10': 'Please enter a valid mobile phone number',
123
+ 'rule-not-1': 'Include',
124
+ 'rule-not-2': 'capital letters',
125
+ 'rule-not-3': '、lowercase letters',
126
+ 'rule-not-4': '、number',
127
+ 'rule-not-5': '、special characters',
128
+ 'rule-not-6': ',length',
129
+ 'rule-not-7': ' ',
130
+ 'rule-not-8': 'Password changed successfully',
131
+ }
132
+ },
133
+ 'slide-verify': {
134
+ 'common': {
135
+ 'right': 'Swipe right'
136
+ }
137
+ }
138
+ }
139
+ export default enUSData;
@@ -0,0 +1,139 @@
1
+ let zhCNData = {
2
+ 'config': {
3
+ 'home': '首页',
4
+ 'error-message': '数据请求出错,请稍后尝试',
5
+ 'default-menu': '默认菜单'
6
+ },
7
+ 'pro-layout':{
8
+ 'common': {
9
+ 'systemName' : '后台管理系统'
10
+ },
11
+ 'header': {
12
+ 'collect' : '收藏',
13
+ 'document': '说明',
14
+ 'fullscreen': '全屏',
15
+ 'quit-fullscreen': '退出全屏',
16
+ 'language': '语音',
17
+ 'notice-more': '查看更多',
18
+ 'notice-read': '一键已读',
19
+ 'notice-no-data': '暂无未读通知',
20
+ 'search-menu': '搜索菜单',
21
+ 'search-loading': '加载中',
22
+ 'search-type-menu': '菜单',
23
+ 'search-type-notice': '公告',
24
+ 'search-type-message': '消息',
25
+ 'search-more': '更多',
26
+ 'search-no-data': '暂无数据',
27
+ 'todo-more': '查看更多',
28
+ 'todo-no-data': '暂无代办',
29
+ 'user-welcome': '欢迎',
30
+ 'user-change-theme': '切换主题',
31
+ 'user-custom-theme': '自定义主题',
32
+ 'user-person-center': '个人中心',
33
+ 'user-notice': '通知公告',
34
+ 'user-logout': '退出登陆',
35
+ 'user-default-name': '管理员',
36
+ 'theme': '主题',
37
+ 'theme-default': '默认'
38
+ },
39
+ 'side': {
40
+ 'history': '历史',
41
+ 'collect': '收藏',
42
+ 'history-menu': '历史菜单',
43
+ 'collect-menu': '收藏菜单',
44
+ 'search-menu': '搜索菜单',
45
+ 'search-loading': '加载中',
46
+ 'search-no-data': '暂无数据'
47
+ },
48
+ 'tabs': {
49
+ 'close-all': '关闭所有',
50
+ 'close-others': '关闭其他'
51
+ },
52
+ 'content': {
53
+
54
+ },
55
+ 'footer': {
56
+
57
+ },
58
+ },
59
+ 'login-form': {
60
+ 'box': {
61
+ 'form-user-name': '请输入用户名',
62
+ 'form-user-pas': '请输入密码',
63
+ 'form-user-valid-code': '请输入验证码',
64
+ 'form-user-sms-code': '请查收短信并输入验证码',
65
+ 'form-user-mail-code': '请查收邮件并输入验证码',
66
+ 'form-remember': '记住用户名',
67
+ 'form-forget': '忘记密码?',
68
+ 'form-login': '登陆',
69
+ 'form-rule-user-name': '账号不能为空',
70
+ 'form-rule-user-pas': '密码不能为空',
71
+ 'form-rule-valid-code': '验证码不能为空',
72
+ 'form-rule-click-login': '请点击验证进行登录验证',
73
+ 'form-rule-click-valid': '点击验证'
74
+ },
75
+ 'other': {
76
+ 'get-valid-code': '获取验证码',
77
+ 'get-valid-code-later': 's后再次获取',
78
+ 'send-success': '发送成功',
79
+ 'captcha-method-image': '图片',
80
+ 'captcha-method-sms': '短信',
81
+ 'captcha-method-mail': '邮箱',
82
+ 'captcha-method-slide-image': '滑动图片',
83
+ 'check-valid-code': '验证中...',
84
+ 'check-success': '验证成功',
85
+ 'check-fail': '验证失败,请稍后重试!',
86
+ }
87
+ },
88
+ 'login-page': {
89
+ 'box': {
90
+ 'welcome-login' : '欢迎登录'
91
+ },
92
+ 'forget-pas': {
93
+ 'return': '返回',
94
+ 'form-user-name': '账号',
95
+ 'next-step': '下一步',
96
+ 'get-back-way': '找回方式',
97
+ 'choose-get-back-way': '请选择找回方式',
98
+ 'get-back-way-mail': '邮箱地址',
99
+ 'get-back-way-sms': '手机号码',
100
+ 'input-mail': '请输入邮箱地址',
101
+ 'input-phone': '请输入手机号码',
102
+ 'new-pas': '新登录密码',
103
+ 'confirm-new-pas': '确认新登录密码',
104
+ 'reset-success': '重置成功!',
105
+ 'redirect-later': '秒后自动回到登录页',
106
+ 'redirect': '直接跳转',
107
+ 'step-title-1':'确认账号',
108
+ 'step-title-2':'找回方式',
109
+ 'step-title-3':'安全认证',
110
+ 'step-title-4':'修改密码',
111
+ 'step-title-5':'修改完成',
112
+ 'rule-new-pas': '新密码不能为空',
113
+ 'rule-pas-1': '密码长度必须大于',
114
+ 'rule-pas-2': '密码长度必须小于',
115
+ 'rule-pas-3': '密码必须含有大写字母',
116
+ 'rule-pas-4': '密码必须含有小写字母',
117
+ 'rule-pas-5': '密码必须含有数字',
118
+ 'rule-pas-6': '密码必须特殊字符',
119
+ 'rule-pas-7': '确认密码不能为空',
120
+ 'rule-pas-8': '两次输入密码不一致',
121
+ 'rule-pas-9': '请输入有效的电子邮箱地址',
122
+ 'rule-pas-10': '请输入有效的手机号码',
123
+ 'rule-not-1': '包含',
124
+ 'rule-not-2': '大写',
125
+ 'rule-not-3': '、小写',
126
+ 'rule-not-4': '、数字',
127
+ 'rule-not-5': '、特殊字符',
128
+ 'rule-not-6': ',长度',
129
+ 'rule-not-7': '位',
130
+ 'rule-not-8': '密码修改成功',
131
+ }
132
+ },
133
+ 'slide-verify': {
134
+ 'common': {
135
+ 'right': '右滑'
136
+ }
137
+ }
138
+ }
139
+ export default zhCNData;
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
+ }