@zcrkey/js-utils 0.0.5 → 0.0.7
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/README.md +9 -0
- package/dist/cjs/color.d.ts +195 -0
- package/dist/cjs/color.js +353 -0
- package/{src/eventCenter.ts → dist/cjs/eventCenter.js} +120 -112
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +54 -0
- package/dist/cjs/obj.js +37 -0
- package/{src/storage.ts → dist/cjs/storage.js} +118 -101
- package/dist/cjs/tree.js +145 -0
- package/dist/{util.d.ts → cjs/util.d.ts} +3 -3
- package/{src/util.ts → dist/cjs/util.js} +173 -257
- package/dist/esm/color.d.ts +195 -0
- package/dist/esm/color.js +500 -0
- package/dist/esm/eventCenter.d.ts +59 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/obj.d.ts +12 -0
- package/dist/{objUtil.js → esm/obj.js} +6 -6
- package/dist/esm/storage.d.ts +44 -0
- package/dist/esm/tree.d.ts +48 -0
- package/dist/esm/util.d.ts +209 -0
- package/dist/{util.js → esm/util.js} +129 -129
- package/dist/{index.umd.js → umd/index.umd.js} +1 -1
- package/package.json +15 -4
- package/.dumi/global.less +0 -1396
- package/.dumirc.ts +0 -36
- package/.fatherrc.ts +0 -14
- package/.husky/commit-msg +0 -4
- package/.husky/pre-commit +0 -4
- package/.prettierignore +0 -2
- package/.stylelintrc +0 -10
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -5
- package/docs/api/eventCenter/index.md +0 -34
- package/docs/api/index.md +0 -5
- package/docs/api/storage/index.md +0 -9
- package/docs/api/storage/local.tsx +0 -91
- package/docs/api/storage/session.tsx +0 -85
- package/docs/api/treeUtil/index.md +0 -5
- package/docs/api/treeUtil/index.tsx +0 -266
- package/docs/api/util/index.md +0 -6
- package/docs/api/util/index.tsx +0 -405
- package/docs/api/util/is.tsx +0 -196
- package/docs/guide.md +0 -24
- package/src/index.ts +0 -8
- package/src/objUtil.ts +0 -20
- package/src/treeUtil.ts +0 -164
- package/tsconfig.json +0 -18
- /package/dist/{eventCenter.d.ts → cjs/eventCenter.d.ts} +0 -0
- /package/dist/{objUtil.d.ts → cjs/obj.d.ts} +0 -0
- /package/dist/{storage.d.ts → cjs/storage.d.ts} +0 -0
- /package/dist/{treeUtil.d.ts → cjs/tree.d.ts} +0 -0
- /package/dist/{eventCenter.js → esm/eventCenter.js} +0 -0
- /package/dist/{storage.js → esm/storage.js} +0 -0
- /package/dist/{treeUtil.js → esm/tree.js} +0 -0
|
@@ -1,112 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/eventCenter.ts
|
|
20
|
+
var eventCenter_exports = {};
|
|
21
|
+
__export(eventCenter_exports, {
|
|
22
|
+
default: () => CrEventCenter
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(eventCenter_exports);
|
|
25
|
+
var CrEventCenter = class {
|
|
26
|
+
/**
|
|
27
|
+
* 新增订阅
|
|
28
|
+
*
|
|
29
|
+
* @param {*} key 名称
|
|
30
|
+
* @param {*} listener 执行函数
|
|
31
|
+
* @returns 订阅信息
|
|
32
|
+
* @example
|
|
33
|
+
this.subscription = CrEventCenter.on('名称', (参数) => {});
|
|
34
|
+
*/
|
|
35
|
+
static on(key, listener) {
|
|
36
|
+
const subscriber = this.subscribers.find((item) => item.key == key);
|
|
37
|
+
if (subscriber) {
|
|
38
|
+
subscriber.listeners.push(listener);
|
|
39
|
+
} else {
|
|
40
|
+
this.subscribers.push({
|
|
41
|
+
key,
|
|
42
|
+
listeners: [listener]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
let subscription = {
|
|
46
|
+
key,
|
|
47
|
+
listener,
|
|
48
|
+
remove: () => {
|
|
49
|
+
this.off(subscription);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return subscription;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 移除订阅
|
|
56
|
+
*
|
|
57
|
+
* @param {*} subscription
|
|
58
|
+
* @param {*} type 'all'
|
|
59
|
+
* @example
|
|
60
|
+
CrEventCenter.off(this.subscription);
|
|
61
|
+
*/
|
|
62
|
+
static off(subscription, type) {
|
|
63
|
+
const index = this.subscribers.findIndex(
|
|
64
|
+
(item) => item.key == subscription.key
|
|
65
|
+
);
|
|
66
|
+
if (index > -1) {
|
|
67
|
+
if (type == "all") {
|
|
68
|
+
this.subscribers.splice(index, 1);
|
|
69
|
+
} else {
|
|
70
|
+
const subscriber = this.subscribers[index];
|
|
71
|
+
const _index = subscriber.listeners.findIndex(
|
|
72
|
+
(item) => item == subscription.listener
|
|
73
|
+
);
|
|
74
|
+
if (_index > -1) {
|
|
75
|
+
subscriber.listeners.splice(_index, 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 派发事件
|
|
82
|
+
*
|
|
83
|
+
* @param {*} key 名称
|
|
84
|
+
* @param {*} args 其余参数
|
|
85
|
+
* @example
|
|
86
|
+
CrEventCenter.emit('名称', 参数数据);
|
|
87
|
+
*/
|
|
88
|
+
static emit(key, ...args) {
|
|
89
|
+
const subscriber = this.subscribers.find((item) => item.key == key);
|
|
90
|
+
if (subscriber && subscriber.listeners && subscriber.listeners.length > 0) {
|
|
91
|
+
subscriber.listeners.forEach((listener) => {
|
|
92
|
+
listener(...args);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 查找事件
|
|
98
|
+
*
|
|
99
|
+
* @param {*} key 名称
|
|
100
|
+
* @example
|
|
101
|
+
let subscriber = CrEventCenter.find('名称');
|
|
102
|
+
*/
|
|
103
|
+
static find(key) {
|
|
104
|
+
return this.subscribers.find((item) => item.key == key);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 清理所有事件
|
|
108
|
+
*
|
|
109
|
+
* @memberof CrEventCenter
|
|
110
|
+
* @example
|
|
111
|
+
CrEventCenter.clear();
|
|
112
|
+
*/
|
|
113
|
+
static clear() {
|
|
114
|
+
this.subscribers.length = 0;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* 储存订阅者
|
|
119
|
+
*/
|
|
120
|
+
CrEventCenter.subscribers = [];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type * from './eventCenter';
|
|
2
|
+
export { default as CrEventCenter } from './eventCenter';
|
|
3
|
+
export type * from './obj';
|
|
4
|
+
export { default as CrObjUtil } from './obj';
|
|
5
|
+
export { default as CrStorage } from './storage';
|
|
6
|
+
export type * from './tree';
|
|
7
|
+
export { default as CrTreeUtil } from './tree';
|
|
8
|
+
export { default as CrUtil } from './util';
|
|
9
|
+
export { default as CrColorUtil } from './color';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
CrColorUtil: () => import_color.default,
|
|
33
|
+
CrEventCenter: () => import_eventCenter.default,
|
|
34
|
+
CrObjUtil: () => import_obj.default,
|
|
35
|
+
CrStorage: () => import_storage.default,
|
|
36
|
+
CrTreeUtil: () => import_tree.default,
|
|
37
|
+
CrUtil: () => import_util.default
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
|
+
var import_eventCenter = __toESM(require("./eventCenter"));
|
|
41
|
+
var import_obj = __toESM(require("./obj"));
|
|
42
|
+
var import_storage = __toESM(require("./storage"));
|
|
43
|
+
var import_tree = __toESM(require("./tree"));
|
|
44
|
+
var import_util = __toESM(require("./util"));
|
|
45
|
+
var import_color = __toESM(require("./color"));
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
CrColorUtil,
|
|
49
|
+
CrEventCenter,
|
|
50
|
+
CrObjUtil,
|
|
51
|
+
CrStorage,
|
|
52
|
+
CrTreeUtil,
|
|
53
|
+
CrUtil
|
|
54
|
+
});
|
package/dist/cjs/obj.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/obj.ts
|
|
20
|
+
var obj_exports = {};
|
|
21
|
+
__export(obj_exports, {
|
|
22
|
+
default: () => CrObjUtil
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(obj_exports);
|
|
25
|
+
var import_lodash = require("lodash");
|
|
26
|
+
var CrObjUtil = class {
|
|
27
|
+
/**
|
|
28
|
+
* 根据字段路径获取对象值
|
|
29
|
+
* @param obj { 'a': [{ 'b': { 'c': 3 } }] }
|
|
30
|
+
* @param path 'a[0].b.c' | ['a', '0', 'b', 'c']
|
|
31
|
+
* @param defaultValue 找不到时返回的默认值
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
static getValueByPath(obj, propertyPath, defaultValue) {
|
|
35
|
+
return (0, import_lodash.get)(obj, propertyPath, defaultValue);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -1,101 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/storage.ts
|
|
20
|
+
var storage_exports = {};
|
|
21
|
+
__export(storage_exports, {
|
|
22
|
+
default: () => CrStorage
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(storage_exports);
|
|
25
|
+
var CrStorage = class {
|
|
26
|
+
/**
|
|
27
|
+
* 设置本地存储
|
|
28
|
+
* @param key
|
|
29
|
+
* @param data
|
|
30
|
+
*/
|
|
31
|
+
static setLocalItem(key, data) {
|
|
32
|
+
try {
|
|
33
|
+
localStorage.setItem(key, JSON.stringify(data));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.warn(`setLocalItem:${key}:${error}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 获取本地存储
|
|
40
|
+
* @param key
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
static getLocalItem(key) {
|
|
44
|
+
const str = localStorage.getItem(key);
|
|
45
|
+
if (str) {
|
|
46
|
+
if (str === "undefined") {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(str);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.warn(`getLocalItem:${key}:${error}`);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 清除某个本地存储
|
|
61
|
+
* @param key
|
|
62
|
+
*/
|
|
63
|
+
static removeLocalItem(key) {
|
|
64
|
+
localStorage.removeItem(key);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 清除所有本地存储
|
|
68
|
+
*/
|
|
69
|
+
static clearLocal() {
|
|
70
|
+
localStorage.clear();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 设置会话存储
|
|
74
|
+
* @param key
|
|
75
|
+
* @param data
|
|
76
|
+
*/
|
|
77
|
+
static setSessionItem(key, data) {
|
|
78
|
+
try {
|
|
79
|
+
sessionStorage.setItem(key, JSON.stringify(data));
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.warn(`setSessionItem:${key}:${error}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 获取会话存储
|
|
86
|
+
* @param key
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
static getSessionItem(key) {
|
|
90
|
+
const str = sessionStorage.getItem(key);
|
|
91
|
+
if (str) {
|
|
92
|
+
if (str === "undefined") {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return JSON.parse(str);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.warn(`getSessionItem:${key}:${error}`);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 清除某个会话存储
|
|
107
|
+
* @param key
|
|
108
|
+
*/
|
|
109
|
+
static removeSessionItem(key) {
|
|
110
|
+
sessionStorage.removeItem(key);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 清除所有会话存储
|
|
114
|
+
*/
|
|
115
|
+
static clearSession() {
|
|
116
|
+
sessionStorage.clear();
|
|
117
|
+
}
|
|
118
|
+
};
|