mrxy-yk 1.12.13 → 1.13.0

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.
@@ -0,0 +1,24 @@
1
+ import { StorageCookieSetOptions } from './type';
2
+ export declare class StorageCookie {
3
+ /**
4
+ * 获取cookie
5
+ * @param key
6
+ * @param encrypt
7
+ */
8
+ static get(key: string, encrypt?: boolean): string;
9
+ /**
10
+ * 设置cookie
11
+ * @param options
12
+ */
13
+ static set(options: StorageCookieSetOptions): void;
14
+ static set(key: string, value: string, expires?: string | Date | number, path?: string, domain?: string): void;
15
+ /**
16
+ * 获取所有cookie
17
+ */
18
+ static getAll(): Record<string, string>;
19
+ /**
20
+ * 删除cookie
21
+ * @param key
22
+ */
23
+ static remove(key: string): void;
24
+ }
@@ -0,0 +1,68 @@
1
+ import { EncryptConfig } from "../../config/index.js";
2
+ //#region src/utils/storage/StorageCookie.ts
3
+ var StorageCookie = class {
4
+ /**
5
+ * 获取cookie
6
+ * @param key
7
+ * @param encrypt
8
+ */
9
+ static get(key, encrypt = true) {
10
+ const str = this.getAll()[key];
11
+ if (encrypt) return str ? EncryptConfig.decryptMethod(str) : void 0;
12
+ return str;
13
+ }
14
+ static set(...args) {
15
+ let key;
16
+ let value;
17
+ let expires;
18
+ let path;
19
+ let domain;
20
+ let encrypt = true;
21
+ if (typeof args[0] === "object") {
22
+ const options = args[0];
23
+ key = options.key;
24
+ value = options.value;
25
+ expires = options.expires;
26
+ path = options.path || "/";
27
+ domain = options.domain;
28
+ encrypt = options.encrypt;
29
+ } else {
30
+ key = args[0];
31
+ value = args[1];
32
+ expires = args[2];
33
+ path = args[3] || "/";
34
+ domain = args[4];
35
+ }
36
+ if (encrypt) value = EncryptConfig.encryptMethod(value);
37
+ let cookieStr = `${key}=${value};path=${path}`;
38
+ if (expires) {
39
+ let date = /* @__PURE__ */ new Date();
40
+ if (typeof expires === "number") date.setTime(date.getTime() + expires * 864e5);
41
+ else date = new Date(expires);
42
+ cookieStr += ";expires=" + date.toUTCString();
43
+ }
44
+ if (domain) cookieStr += ";domain=" + domain;
45
+ document.cookie = cookieStr;
46
+ }
47
+ /**
48
+ * 获取所有cookie
49
+ */
50
+ static getAll() {
51
+ const cookieArr = document.cookie.split(";");
52
+ const cookieObj = {};
53
+ cookieArr.forEach((item) => {
54
+ const m = item.split("=");
55
+ cookieObj[m[0].trim()] = m[1];
56
+ });
57
+ return cookieObj;
58
+ }
59
+ /**
60
+ * 删除cookie
61
+ * @param key
62
+ */
63
+ static remove(key) {
64
+ this.set(key, "", -1);
65
+ }
66
+ };
67
+ //#endregion
68
+ export { StorageCookie };
@@ -1,3 +1,4 @@
1
+ import { StorageCookie } from './StorageCookie.ts';
1
2
  declare class LocalStorage {
2
3
  dataset: Map<string, string>;
3
4
  getItem(key: string): string;
@@ -15,14 +16,16 @@ export declare class StorageUtil {
15
16
  /**
16
17
  * 获取localStorage的值 - 解密
17
18
  * @param key
19
+ * @param encrypt
18
20
  */
19
- get(key: string): any;
21
+ get(key: string, encrypt?: boolean): any;
20
22
  /**
21
23
  * 设置localStorage的值 - 加密
22
24
  * @param key
23
25
  * @param value
26
+ * @param encrypt
24
27
  */
25
- set(key: string, value: any): void;
28
+ set(key: string, value: any, encrypt?: boolean): void;
26
29
  remove: (key: string) => void;
27
30
  clear: () => void;
28
31
  };
@@ -30,40 +33,19 @@ export declare class StorageUtil {
30
33
  /**
31
34
  * 获取sessionStorage的值 - 解密
32
35
  * @param key
36
+ * @param encrypt
33
37
  */
34
- get(key: string): any;
38
+ get(key: string, encrypt?: boolean): any;
35
39
  /**
36
40
  * 设置sessionStorage的值 - 加密
37
41
  * @param key
38
42
  * @param value
43
+ * @param encrypt
39
44
  */
40
- set(key: string, value: any): void;
45
+ set(key: string, value: any, encrypt?: boolean): void;
41
46
  remove: (key: string) => void;
42
47
  clear: () => void;
43
48
  };
44
- static cookie: {
45
- /**
46
- * 获取cookie
47
- * @param key
48
- */
49
- get(key: string): string;
50
- /**
51
- * 设置cookie
52
- * @param key
53
- * @param value
54
- * @param expires 日期字符串|日期对象|天数
55
- * @param path
56
- */
57
- set(key: string, value: string, expires?: string | Date | number, path?: string): void;
58
- /**
59
- * 获取所有cookie
60
- */
61
- getAll(): Record<string, string>;
62
- /**
63
- * 删除cookie
64
- * @param key
65
- */
66
- remove(key: string): void;
67
- };
49
+ static cookie: typeof StorageCookie;
68
50
  }
69
51
  export {};
@@ -1,4 +1,5 @@
1
1
  import { EncryptConfig } from "../../config/index.js";
2
+ import { StorageCookie } from "./StorageCookie.js";
2
3
  //#region src/utils/storage/index.ts
3
4
  var LocalStorage = class {
4
5
  dataset = /* @__PURE__ */ new Map();
@@ -35,18 +36,21 @@ var StorageUtil = class StorageUtil {
35
36
  /**
36
37
  * 获取localStorage的值 - 解密
37
38
  * @param key
39
+ * @param encrypt
38
40
  */
39
- get(key) {
41
+ get(key, encrypt = true) {
40
42
  const str = StorageUtil.localStorage.getItem(key);
41
- if (str) return JSON.parse(EncryptConfig.decryptMethod(str));
43
+ if (str) return encrypt ? JSON.parse(EncryptConfig.decryptMethod(str)) : JSON.parse(str);
42
44
  },
43
45
  /**
44
46
  * 设置localStorage的值 - 加密
45
47
  * @param key
46
48
  * @param value
49
+ * @param encrypt
47
50
  */
48
- set(key, value) {
49
- StorageUtil.localStorage.setItem(key, EncryptConfig.encryptMethod(JSON.stringify(value)));
51
+ set(key, value, encrypt = true) {
52
+ const _value = encrypt ? EncryptConfig.encryptMethod(JSON.stringify(value)) : JSON.stringify(value);
53
+ StorageUtil.localStorage.setItem(key, _value);
50
54
  },
51
55
  remove: (key) => {
52
56
  StorageUtil.localStorage.removeItem(key);
@@ -59,18 +63,21 @@ var StorageUtil = class StorageUtil {
59
63
  /**
60
64
  * 获取sessionStorage的值 - 解密
61
65
  * @param key
66
+ * @param encrypt
62
67
  */
63
- get(key) {
68
+ get(key, encrypt = true) {
64
69
  const str = StorageUtil.sessionStorage.getItem(key);
65
- if (str) return JSON.parse(EncryptConfig.decryptMethod(str));
70
+ if (str) return encrypt ? JSON.parse(EncryptConfig.decryptMethod(str)) : JSON.parse(str);
66
71
  },
67
72
  /**
68
73
  * 设置sessionStorage的值 - 加密
69
74
  * @param key
70
75
  * @param value
76
+ * @param encrypt
71
77
  */
72
- set(key, value) {
73
- StorageUtil.sessionStorage.setItem(key, EncryptConfig.encryptMethod(JSON.stringify(value)));
78
+ set(key, value, encrypt = true) {
79
+ const _value = encrypt ? EncryptConfig.encryptMethod(JSON.stringify(value)) : JSON.stringify(value);
80
+ StorageUtil.sessionStorage.setItem(key, _value);
74
81
  },
75
82
  remove: (key) => {
76
83
  StorageUtil.sessionStorage.removeItem(key);
@@ -79,52 +86,7 @@ var StorageUtil = class StorageUtil {
79
86
  StorageUtil.sessionStorage.clear();
80
87
  }
81
88
  };
82
- static cookie = {
83
- /**
84
- * 获取cookie
85
- * @param key
86
- */
87
- get(key) {
88
- const str = this.getAll()[key];
89
- return str ? EncryptConfig.decryptMethod(str) : void 0;
90
- },
91
- /**
92
- * 设置cookie
93
- * @param key
94
- * @param value
95
- * @param expires 日期字符串|日期对象|天数
96
- * @param path
97
- */
98
- set(key, value, expires, path = "/") {
99
- let cookieStr = `${key}=${EncryptConfig.encryptMethod(value)};path=${path}`;
100
- if (expires) {
101
- let date = /* @__PURE__ */ new Date();
102
- if (typeof expires === "number") date.setTime(date.getTime() + expires * 864e5);
103
- else date = new Date(expires);
104
- cookieStr += ";expires=" + date.toUTCString();
105
- }
106
- document.cookie = cookieStr;
107
- },
108
- /**
109
- * 获取所有cookie
110
- */
111
- getAll() {
112
- const cookieArr = document.cookie.split(";");
113
- const cookieObj = {};
114
- cookieArr.forEach((item) => {
115
- const m = item.split("=");
116
- cookieObj[m[0].trim()] = m[1];
117
- });
118
- return cookieObj;
119
- },
120
- /**
121
- * 删除cookie
122
- * @param key
123
- */
124
- remove(key) {
125
- this.set(key, "", -1);
126
- }
127
- };
89
+ static cookie = StorageCookie;
128
90
  };
129
91
  StorageUtil.init();
130
92
  //#endregion
@@ -0,0 +1,14 @@
1
+ export type StorageCookieSetOptions = {
2
+ // 键
3
+ key: string
4
+ // 值
5
+ value: string
6
+ // 过期时间
7
+ expires?: string | Date | number
8
+ // 路径
9
+ path?: string
10
+ // 域名
11
+ domain?: string
12
+ // 是否加密
13
+ encrypt?: boolean
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mrxy-yk",
3
- "version": "1.12.13",
3
+ "version": "1.13.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "A collection of Vue 3 components and utilities",
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "mrxy-yk",
4
- "version": "1.12.13",
4
+ "version": "1.13.0",
5
5
  "js-types-syntax": "typescript",
6
6
  "contributions": {
7
7
  "html": {