@tmsfe/tms-core 0.0.21 → 0.0.22

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.
@@ -1,4 +1,4 @@
1
- import { o as rpxToPx, s as syncApi, p as stringUtils, t as timeUtils, q as ipxHelper } from './ipxHelper-c5ab3693.js';
1
+ import { o as rpxToPx, p as storage, s as syncApi, q as stringUtils, t as timeUtils, u as ipxHelper } from './storage-094c6ddb.js';
2
2
  import { m as md5, s as serialize } from './objUtils-154b94db.js';
3
3
 
4
4
  /**
@@ -231,6 +231,7 @@ const api = {
231
231
  getEnvInfo,
232
232
  isAppPageExist,
233
233
  getHomePage,
234
+ storage,
234
235
  ...asyncFuncs,
235
236
  ...objFuncs,
236
237
  ...syncApi,
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { R as Request, g as getLogManager, a as getRealtimeLogManager } from './request-f8a4745b.js';
2
2
  import { g as getEnvInfo, a as getAuthInfo, s as setAuthInfo, i as isAppPageExist, b as getHomePage, c as setEnvInfo, d as setAppPagePaths } from './env-c7da70e1.js';
3
- import { s as syncApi, r as roundStr, f as formatPlate, a as subStr, h as hidePhoneCenter, i as isValidPhone, b as isValidPlate, c as isValidAuthCode, d as formatTime, e as formatTimeStr, g as formatTimeWithDetails, j as dateToString, k as ipxInit, l as isIPX, m as getIpxClass, n as getIpxConfig, o as rpxToPx } from './ipxHelper-c5ab3693.js';
3
+ import { s as syncApi, r as roundStr, f as formatPlate, a as subStr, h as hidePhoneCenter, i as isValidPhone, b as isValidPlate, c as isValidAuthCode, d as formatTime, e as formatTimeStr, g as formatTimeWithDetails, j as dateToString, k as ipxInit, l as isIPX, m as getIpxClass, n as getIpxConfig, o as rpxToPx, p as storage } from './storage-094c6ddb.js';
4
4
  import { m as md5, s as serialize } from './objUtils-154b94db.js';
5
5
  import { callCloudFunc } from './cloudService.js';
6
6
 
@@ -1757,6 +1757,7 @@ const api = {
1757
1757
 
1758
1758
  /** rpx转px */
1759
1759
  rpxToPx,
1760
+ storage,
1760
1761
  ...syncApi
1761
1762
  };
1762
1763
 
@@ -540,4 +540,112 @@ var ipxHelper = /*#__PURE__*/Object.freeze({
540
540
  getIpxConfig: getIpxConfig
541
541
  });
542
542
 
543
- export { subStr as a, isValidPlate as b, isValidAuthCode as c, formatTime as d, formatTimeStr as e, formatPlate as f, formatTimeWithDetails as g, hidePhoneCenter as h, isValidPhone as i, dateToString as j, ipxInit as k, isIPX as l, getIpxClass as m, getIpxConfig as n, rpxToPx as o, stringUtils as p, ipxHelper as q, roundStr as r, syncApi as s, timeUtils as t };
543
+ /**
544
+ * 保存数据到localstorage
545
+ * @param key
546
+ * @param data
547
+ * @returns {boolean} true为成功,false为报错
548
+ */
549
+ function setItem(key, data) {
550
+ try {
551
+ wx.setStorageSync(key, data);
552
+ return true;
553
+ } catch {
554
+ return false;
555
+ }
556
+ }
557
+ /**
558
+ * 从localstorage取数据
559
+ * @param key
560
+ * @param defaultValue wx接口报错时返回默认值
561
+ * @returns {null|any}
562
+ */
563
+
564
+
565
+ function getItem(key, defaultValue = null) {
566
+ try {
567
+ const val = wx.getStorageSync(key);
568
+ return val === '' ? defaultValue : val;
569
+ } catch {
570
+ return defaultValue;
571
+ }
572
+ }
573
+ /**
574
+ * 从localstorage中删除
575
+ * @param key
576
+ * @returns {boolean}
577
+ */
578
+
579
+
580
+ function removeItem(key) {
581
+ try {
582
+ wx.removeStorageSync(key);
583
+ return true;
584
+ } catch {
585
+ return false;
586
+ }
587
+ }
588
+
589
+ const cleanQueue = [];
590
+ let cleanTimerId = 0;
591
+
592
+ function cleanTask() {
593
+ while (cleanQueue.length > 0) {
594
+ const {
595
+ key,
596
+ version
597
+ } = cleanQueue.pop();
598
+
599
+ for (let i = version - 1; i > version - 10 && i > 0; i--) {
600
+ removeItem(`${key}_v${i}`);
601
+ }
602
+ }
603
+
604
+ cleanTimerId = 0;
605
+ }
606
+ /**
607
+ * 缓存组件或页面的缓存data
608
+ * @param key
609
+ * @param version 低于该版本号的缓存会被异步清除
610
+ * @param data
611
+ * @returns {boolean}
612
+ */
613
+
614
+
615
+ function setCacheData(key, version, data) {
616
+ // 异步清理旧数据,不要阻塞当前线程
617
+ cleanQueue.push({
618
+ key,
619
+ version
620
+ });
621
+
622
+ if (cleanTimerId === 0) {
623
+ cleanTimerId = setTimeout(cleanTask, 2000);
624
+ }
625
+
626
+ const str = `${key}_v${version}`;
627
+ return setItem(str, data);
628
+ }
629
+ /**
630
+ * 获取组件或页面的缓存data
631
+ * @param key
632
+ * @param version
633
+ * @param defaultData
634
+ * @returns {*|null}
635
+ */
636
+
637
+
638
+ function getCacheData(key, version, defaultData = null) {
639
+ const str = `${key}_v${version}`;
640
+ return getItem(str, defaultData);
641
+ }
642
+
643
+ var storage = /*#__PURE__*/Object.freeze({
644
+ __proto__: null,
645
+ getItem: getItem,
646
+ setItem: setItem,
647
+ setCacheData: setCacheData,
648
+ getCacheData: getCacheData
649
+ });
650
+
651
+ export { subStr as a, isValidPlate as b, isValidAuthCode as c, formatTime as d, formatTimeStr as e, formatPlate as f, formatTimeWithDetails as g, hidePhoneCenter as h, isValidPhone as i, dateToString as j, ipxInit as k, isIPX as l, getIpxClass as m, getIpxConfig as n, rpxToPx as o, storage as p, stringUtils as q, roundStr as r, syncApi as s, timeUtils as t, ipxHelper as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,6 +12,7 @@ import { serialize } from './objUtils';
12
12
  import * as stringUtils from './stringUtils';
13
13
  import * as timeUtils from './timeUtils';
14
14
  import * as ipxHelper from './ipxHelper';
15
+ import * as storage from './storage';
15
16
 
16
17
  let app = null;
17
18
  let initOptions = null;
@@ -212,6 +213,7 @@ const api = {
212
213
  getEnvInfo,
213
214
  isAppPageExist,
214
215
  getHomePage,
216
+ storage,
215
217
  ...asyncFuncs,
216
218
  ...objFuncs,
217
219
  ...syncApi,
package/src/index.js CHANGED
@@ -38,6 +38,7 @@ import {
38
38
  import getLocInstance from './location/index.ts';
39
39
  import LocationBase from './location/base.ts';
40
40
  import { getMpOpenId, getOuterOpenId } from './mpInfo';
41
+ import * as storage from './storage';
41
42
 
42
43
  /**
43
44
  * @public
@@ -180,6 +181,8 @@ const api = {
180
181
  /** rpx转px */
181
182
  rpxToPx,
182
183
 
184
+ storage,
185
+
183
186
  ...syncApi,
184
187
  };
185
188
 
package/src/storage.js ADDED
@@ -0,0 +1,93 @@
1
+ /**
2
+ * 保存数据到localstorage
3
+ * @param key
4
+ * @param data
5
+ * @returns {boolean} true为成功,false为报错
6
+ */
7
+ function setItem(key, data) {
8
+ try {
9
+ wx.setStorageSync(key, data);
10
+ return true;
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ /**
17
+ * 从localstorage取数据
18
+ * @param key
19
+ * @param defaultValue wx接口报错时返回默认值
20
+ * @returns {null|any}
21
+ */
22
+ function getItem(key, defaultValue = null) {
23
+ try {
24
+ const val = wx.getStorageSync(key);
25
+ return val === '' ? defaultValue : val;
26
+ } catch {
27
+ return defaultValue;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * 从localstorage中删除
33
+ * @param key
34
+ * @returns {boolean}
35
+ */
36
+ function removeItem(key) {
37
+ try {
38
+ wx.removeStorageSync(key);
39
+ return true;
40
+ } catch {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ const cleanQueue = [];
46
+ let cleanTimerId = 0;
47
+
48
+ function cleanTask() {
49
+ while (cleanQueue.length > 0) {
50
+ const { key, version } = cleanQueue.pop();
51
+ for (let i = version - 1; i > version - 10 && i > 0; i--) {
52
+ removeItem(`${key}_v${i}`);
53
+ }
54
+ }
55
+ cleanTimerId = 0;
56
+ }
57
+
58
+ /**
59
+ * 缓存组件或页面的缓存data
60
+ * @param key
61
+ * @param version 低于该版本号的缓存会被异步清除
62
+ * @param data
63
+ * @returns {boolean}
64
+ */
65
+ function setCacheData(key, version, data) {
66
+ // 异步清理旧数据,不要阻塞当前线程
67
+ cleanQueue.push({ key, version });
68
+ if (cleanTimerId === 0) {
69
+ cleanTimerId = setTimeout(cleanTask, 2000);
70
+ }
71
+
72
+ const str = `${key}_v${version}`;
73
+ return setItem(str, data);
74
+ }
75
+
76
+ /**
77
+ * 获取组件或页面的缓存data
78
+ * @param key
79
+ * @param version
80
+ * @param defaultData
81
+ * @returns {*|null}
82
+ */
83
+ function getCacheData(key, version, defaultData = null) {
84
+ const str = `${key}_v${version}`;
85
+ return getItem(str, defaultData);
86
+ }
87
+
88
+ export {
89
+ getItem,
90
+ setItem,
91
+ setCacheData,
92
+ getCacheData,
93
+ };