@ray-js/lamp-schedule-core 1.0.0-beta-1

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.
Files changed (246) hide show
  1. package/README.md +565 -0
  2. package/lib/config/dpCodes.d.ts +27 -0
  3. package/lib/config/dpCodes.js +30 -0
  4. package/lib/config/index.d.ts +2 -0
  5. package/lib/config/index.js +2 -0
  6. package/lib/config/rhythms/defaultValue.d.ts +18 -0
  7. package/lib/config/rhythms/defaultValue.js +72 -0
  8. package/lib/config/rhythms/index.d.ts +10 -0
  9. package/lib/config/rhythms/index.js +35 -0
  10. package/lib/conflict/ConflictResolver.d.ts +2 -0
  11. package/lib/conflict/ConflictResolver.js +284 -0
  12. package/lib/conflict/__test__/ConflictResolver.test.d.ts +1 -0
  13. package/lib/conflict/__test__/ConflictResolver.test.js +183 -0
  14. package/lib/conflict/__test__/index.test.d.ts +1 -0
  15. package/lib/conflict/__test__/index.test.js +385 -0
  16. package/lib/conflict/__test__/scheduleDataManager.test.d.ts +1 -0
  17. package/lib/conflict/__test__/scheduleDataManager.test.js +170 -0
  18. package/lib/conflict/__test__/transform.test.d.ts +1 -0
  19. package/lib/conflict/__test__/transform.test.js +454 -0
  20. package/lib/conflict/__test__/updateDeviceDp.d.ts +1 -0
  21. package/lib/conflict/__test__/updateDeviceDp.js +114 -0
  22. package/lib/conflict/index.d.ts +42 -0
  23. package/lib/conflict/index.js +103 -0
  24. package/lib/conflict/scheduleDataManager.d.ts +12 -0
  25. package/lib/conflict/scheduleDataManager.js +79 -0
  26. package/lib/conflict/transform.d.ts +71 -0
  27. package/lib/conflict/transform.js +251 -0
  28. package/lib/conflict/type.d.ts +55 -0
  29. package/lib/conflict/type.js +17 -0
  30. package/lib/conflict/updateDeviceDp.d.ts +1 -0
  31. package/lib/conflict/updateDeviceDp.js +41 -0
  32. package/lib/constant/index.d.ts +5 -0
  33. package/lib/constant/index.js +5 -0
  34. package/lib/context/index.d.ts +3 -0
  35. package/lib/context/index.js +3 -0
  36. package/lib/context/rhythms/actions.d.ts +20 -0
  37. package/lib/context/rhythms/actions.js +52 -0
  38. package/lib/context/rhythms/index.d.ts +5 -0
  39. package/lib/context/rhythms/index.js +51 -0
  40. package/lib/context/rhythms/reducer.d.ts +24 -0
  41. package/lib/context/rhythms/reducer.js +38 -0
  42. package/lib/context/schedule/actions.d.ts +7 -0
  43. package/lib/context/schedule/actions.js +51 -0
  44. package/lib/context/schedule/context.d.ts +6 -0
  45. package/lib/context/schedule/context.js +52 -0
  46. package/lib/context/schedule/index.d.ts +1 -0
  47. package/lib/context/schedule/index.js +1 -0
  48. package/lib/context/schedule/reducer.d.ts +16 -0
  49. package/lib/context/schedule/reducer.js +104 -0
  50. package/lib/context/schedule/type.d.ts +41 -0
  51. package/lib/context/schedule/type.js +11 -0
  52. package/lib/context/timer/actions.d.ts +8 -0
  53. package/lib/context/timer/actions.js +52 -0
  54. package/lib/context/timer/context.d.ts +10 -0
  55. package/lib/context/timer/context.js +53 -0
  56. package/lib/context/timer/index.d.ts +1 -0
  57. package/lib/context/timer/index.js +1 -0
  58. package/lib/context/timer/reducer.d.ts +15 -0
  59. package/lib/context/timer/reducer.js +70 -0
  60. package/lib/context/timer/type.d.ts +46 -0
  61. package/lib/context/timer/type.js +24 -0
  62. package/lib/dpParser/README.md +63 -0
  63. package/lib/dpParser/__test__/cycle.test.d.ts +1 -0
  64. package/lib/dpParser/__test__/cycle.test.js +258 -0
  65. package/lib/dpParser/__test__/random.test.d.ts +1 -0
  66. package/lib/dpParser/__test__/random.test.js +211 -0
  67. package/lib/dpParser/__test__/rhythms.test.d.ts +1 -0
  68. package/lib/dpParser/__test__/rhythms.test.js +71 -0
  69. package/lib/dpParser/__test__/rtcTimer.test.d.ts +1 -0
  70. package/lib/dpParser/__test__/rtcTimer.test.js +235 -0
  71. package/lib/dpParser/__test__/sleep.test.d.ts +1 -0
  72. package/lib/dpParser/__test__/sleep.test.js +71 -0
  73. package/lib/dpParser/__test__/sleepCommon.test.d.ts +1 -0
  74. package/lib/dpParser/__test__/sleepCommon.test.js +197 -0
  75. package/lib/dpParser/__test__/timerReport.test.d.ts +1 -0
  76. package/lib/dpParser/__test__/timerReport.test.js +100 -0
  77. package/lib/dpParser/__test__/wakeup.test.d.ts +1 -0
  78. package/lib/dpParser/__test__/wakeup.test.js +69 -0
  79. package/lib/dpParser/__test__/wakeupCommon.test.d.ts +1 -0
  80. package/lib/dpParser/__test__/wakeupCommon.test.js +131 -0
  81. package/lib/dpParser/cycle/index.d.ts +15 -0
  82. package/lib/dpParser/cycle/index.js +134 -0
  83. package/lib/dpParser/index.d.ts +23 -0
  84. package/lib/dpParser/index.js +43 -0
  85. package/lib/dpParser/random/index.d.ts +15 -0
  86. package/lib/dpParser/random/index.js +127 -0
  87. package/lib/dpParser/rhythms.d.ts +41 -0
  88. package/lib/dpParser/rhythms.js +116 -0
  89. package/lib/dpParser/rtcTimer.d.ts +17 -0
  90. package/lib/dpParser/rtcTimer.js +300 -0
  91. package/lib/dpParser/sleep/index.d.ts +9 -0
  92. package/lib/dpParser/sleep/index.js +29 -0
  93. package/lib/dpParser/sleep/sleepCommon.d.ts +11 -0
  94. package/lib/dpParser/sleep/sleepCommon.js +117 -0
  95. package/lib/dpParser/sleep/sleepSigmesh.d.ts +0 -0
  96. package/lib/dpParser/sleep/sleepSigmesh.js +101 -0
  97. package/lib/dpParser/timerReport.d.ts +11 -0
  98. package/lib/dpParser/timerReport.js +43 -0
  99. package/lib/dpParser/utils.d.ts +27 -0
  100. package/lib/dpParser/utils.js +53 -0
  101. package/lib/dpParser/wakeup/index.d.ts +10 -0
  102. package/lib/dpParser/wakeup/index.js +34 -0
  103. package/lib/dpParser/wakeup/wakeupCommon.d.ts +11 -0
  104. package/lib/dpParser/wakeup/wakeupCommon.js +106 -0
  105. package/lib/dpParser/wakeup/wakeupSigmesh.d.ts +15 -0
  106. package/lib/dpParser/wakeup/wakeupSigmesh.js +86 -0
  107. package/lib/hooks/__test__/useCommon.test.d.ts +1 -0
  108. package/lib/hooks/__test__/useCommon.test.js +72 -0
  109. package/lib/hooks/__test__/useCountdownDp.test.d.ts +1 -0
  110. package/lib/hooks/__test__/useCountdownDp.test.js +82 -0
  111. package/lib/hooks/__test__/useCycleDp.test.d.ts +1 -0
  112. package/lib/hooks/__test__/useCycleDp.test.js +92 -0
  113. package/lib/hooks/__test__/useRandomDp.test.d.ts +1 -0
  114. package/lib/hooks/__test__/useRandomDp.test.js +88 -0
  115. package/lib/hooks/__test__/useRhythmsDp.test.d.ts +1 -0
  116. package/lib/hooks/__test__/useRhythmsDp.test.js +81 -0
  117. package/lib/hooks/__test__/useSleepDp.test.d.ts +1 -0
  118. package/lib/hooks/__test__/useSleepDp.test.js +127 -0
  119. package/lib/hooks/__test__/useTimeFlush.test.d.ts +1 -0
  120. package/lib/hooks/__test__/useTimeFlush.test.js +109 -0
  121. package/lib/hooks/__test__/useTimerDp.test.d.ts +1 -0
  122. package/lib/hooks/__test__/useTimerDp.test.js +79 -0
  123. package/lib/hooks/__test__/useTimerOperate.test.d.ts +1 -0
  124. package/lib/hooks/__test__/useTimerOperate.test.js +286 -0
  125. package/lib/hooks/__test__/useTimerOperateCloud.test.d.ts +1 -0
  126. package/lib/hooks/__test__/useTimerOperateCloud.test.js +190 -0
  127. package/lib/hooks/__test__/useTimerOperateLocal.test.d.ts +1 -0
  128. package/lib/hooks/__test__/useTimerOperateLocal.test.js +216 -0
  129. package/lib/hooks/__test__/useTimerReportDp.test.d.ts +1 -0
  130. package/lib/hooks/__test__/useTimerReportDp.test.js +93 -0
  131. package/lib/hooks/__test__/useTimerSupport.test.d.ts +1 -0
  132. package/lib/hooks/__test__/useTimerSupport.test.js +110 -0
  133. package/lib/hooks/__test__/useWakeUpDp.test.d.ts +1 -0
  134. package/lib/hooks/__test__/useWakeUpDp.test.js +129 -0
  135. package/lib/hooks/useBaseLightDp.d.ts +21 -0
  136. package/lib/hooks/useBaseLightDp.js +165 -0
  137. package/lib/hooks/useCommon.d.ts +29 -0
  138. package/lib/hooks/useCommon.js +59 -0
  139. package/lib/hooks/useCommonSupport.d.ts +25 -0
  140. package/lib/hooks/useCommonSupport.js +241 -0
  141. package/lib/hooks/useCountdownDp.d.ts +13 -0
  142. package/lib/hooks/useCountdownDp.js +28 -0
  143. package/lib/hooks/useCountdownSupport.d.ts +9 -0
  144. package/lib/hooks/useCountdownSupport.js +13 -0
  145. package/lib/hooks/useCycleDp.d.ts +7 -0
  146. package/lib/hooks/useCycleDp.js +21 -0
  147. package/lib/hooks/useCycleSupport.d.ts +12 -0
  148. package/lib/hooks/useCycleSupport.js +16 -0
  149. package/lib/hooks/useRandomDp.d.ts +7 -0
  150. package/lib/hooks/useRandomDp.js +21 -0
  151. package/lib/hooks/useRandomSupport.d.ts +12 -0
  152. package/lib/hooks/useRandomSupport.js +16 -0
  153. package/lib/hooks/useRhythmsDp.d.ts +7 -0
  154. package/lib/hooks/useRhythmsDp.js +23 -0
  155. package/lib/hooks/useSleepDp.d.ts +6 -0
  156. package/lib/hooks/useSleepDp.js +21 -0
  157. package/lib/hooks/useSleepSupport.d.ts +8 -0
  158. package/lib/hooks/useSleepSupport.js +13 -0
  159. package/lib/hooks/useTimeFlush.d.ts +8 -0
  160. package/lib/hooks/useTimeFlush.js +31 -0
  161. package/lib/hooks/useTimerDp.d.ts +5 -0
  162. package/lib/hooks/useTimerDp.js +25 -0
  163. package/lib/hooks/useTimerFlushList.d.ts +11 -0
  164. package/lib/hooks/useTimerFlushList.js +53 -0
  165. package/lib/hooks/useTimerOperate.d.ts +68 -0
  166. package/lib/hooks/useTimerOperate.js +403 -0
  167. package/lib/hooks/useTimerOperateCloud.d.ts +31 -0
  168. package/lib/hooks/useTimerOperateCloud.js +233 -0
  169. package/lib/hooks/useTimerOperateLocal.d.ts +40 -0
  170. package/lib/hooks/useTimerOperateLocal.js +310 -0
  171. package/lib/hooks/useTimerReportDp.d.ts +15 -0
  172. package/lib/hooks/useTimerReportDp.js +48 -0
  173. package/lib/hooks/useTimerSupport.d.ts +13 -0
  174. package/lib/hooks/useTimerSupport.js +38 -0
  175. package/lib/hooks/useWakeUpDp.d.ts +6 -0
  176. package/lib/hooks/useWakeUpDp.js +21 -0
  177. package/lib/hooks/useWakeUpSupport.d.ts +8 -0
  178. package/lib/hooks/useWakeUpSupport.js +13 -0
  179. package/lib/hooks/useWakeupDp.d.ts +6 -0
  180. package/lib/hooks/useWakeupDp.js +21 -0
  181. package/lib/hooks/useWakeupSupport.d.ts +8 -0
  182. package/lib/hooks/useWakeupSupport.js +13 -0
  183. package/lib/i18n/index.d.ts +142 -0
  184. package/lib/i18n/index.js +7 -0
  185. package/lib/i18n/rhythms.d.ts +73 -0
  186. package/lib/i18n/rhythms.js +72 -0
  187. package/lib/i18n/strings.d.ts +73 -0
  188. package/lib/i18n/strings.js +6 -0
  189. package/lib/index.d.ts +51 -0
  190. package/lib/index.js +64 -0
  191. package/lib/types/countdown.d.ts +3 -0
  192. package/lib/types/countdown.js +1 -0
  193. package/lib/types/cycle.d.ts +22 -0
  194. package/lib/types/cycle.js +1 -0
  195. package/lib/types/global.d.ts +9 -0
  196. package/lib/types/index.d.ts +331 -0
  197. package/lib/types/index.js +76 -0
  198. package/lib/types/random.d.ts +20 -0
  199. package/lib/types/random.js +1 -0
  200. package/lib/types/rhythms.d.ts +79 -0
  201. package/lib/types/rhythms.js +15 -0
  202. package/lib/types/sleep.d.ts +36 -0
  203. package/lib/types/sleep.js +1 -0
  204. package/lib/types/timer.d.ts +107 -0
  205. package/lib/types/timer.js +1 -0
  206. package/lib/types/wakeup.d.ts +38 -0
  207. package/lib/types/wakeup.js +1 -0
  208. package/lib/utils/ScheduleCache.d.ts +19 -0
  209. package/lib/utils/ScheduleCache.js +39 -0
  210. package/lib/utils/ScheduleCloudProperty.d.ts +75 -0
  211. package/lib/utils/ScheduleCloudProperty.js +220 -0
  212. package/lib/utils/ScheduleDataSync.d.ts +82 -0
  213. package/lib/utils/ScheduleDataSync.js +127 -0
  214. package/lib/utils/ScheduleEmit.d.ts +67 -0
  215. package/lib/utils/ScheduleEmit.js +61 -0
  216. package/lib/utils/ScheduleLogger.d.ts +19 -0
  217. package/lib/utils/ScheduleLogger.js +71 -0
  218. package/lib/utils/ScheduleSupport.d.ts +131 -0
  219. package/lib/utils/ScheduleSupport.js +373 -0
  220. package/lib/utils/ScheduleUtils.d.ts +12 -0
  221. package/lib/utils/ScheduleUtils.js +51 -0
  222. package/lib/utils/__test__/ScheduleCloudProperty.test.d.ts +1 -0
  223. package/lib/utils/__test__/ScheduleCloudProperty.test.js +320 -0
  224. package/lib/utils/__test__/ScheduleSupport.test.d.ts +1 -0
  225. package/lib/utils/__test__/ScheduleSupport.test.js +211 -0
  226. package/lib/utils/__test__/ScheduleUtils.test.d.ts +1 -0
  227. package/lib/utils/__test__/ScheduleUtils.test.js +119 -0
  228. package/lib/utils/__test__/common.test.d.ts +1 -0
  229. package/lib/utils/__test__/common.test.js +147 -0
  230. package/lib/utils/__test__/storage.test.d.ts +1 -0
  231. package/lib/utils/__test__/storage.test.js +98 -0
  232. package/lib/utils/__test__/time.test.d.ts +1 -0
  233. package/lib/utils/__test__/time.test.js +146 -0
  234. package/lib/utils/common.d.ts +23 -0
  235. package/lib/utils/common.js +109 -0
  236. package/lib/utils/dpState.d.ts +5 -0
  237. package/lib/utils/dpState.js +27 -0
  238. package/lib/utils/getCachedSystemInfo.d.ts +39 -0
  239. package/lib/utils/getCachedSystemInfo.js +20 -0
  240. package/lib/utils/isInIDE.d.ts +1 -0
  241. package/lib/utils/isInIDE.js +5 -0
  242. package/lib/utils/storage.d.ts +5 -0
  243. package/lib/utils/storage.js +32 -0
  244. package/lib/utils/time.d.ts +40 -0
  245. package/lib/utils/time.js +84 -0
  246. package/package.json +78 -0
@@ -0,0 +1,119 @@
1
+ import { getDpCodeByDpId, getDpIdByDpCode } from '../ScheduleUtils';
2
+ import { getScheduleCache } from '../ScheduleCache';
3
+
4
+ // 模拟依赖
5
+ jest.mock('../ScheduleCache', () => ({
6
+ getScheduleCache: jest.fn()
7
+ }));
8
+ describe('ScheduleUtils', () => {
9
+ const mockDevInfo = {
10
+ devId: 'test-device-id',
11
+ schema: [{
12
+ id: 1,
13
+ code: 'switch_led'
14
+ }, {
15
+ id: 2,
16
+ code: 'bright_value'
17
+ }, {
18
+ id: 3,
19
+ code: 'colour_data'
20
+ }]
21
+ };
22
+ const mockGroupInfo = {
23
+ groupId: 'test-group-id',
24
+ schema: [{
25
+ id: 1,
26
+ code: 'switch_led'
27
+ }, {
28
+ id: 2,
29
+ code: 'bright_value'
30
+ }]
31
+ };
32
+ beforeEach(() => {
33
+ jest.clearAllMocks();
34
+ });
35
+ describe('getDpCodeByDpId', () => {
36
+ it('应该根据DP ID返回对应的DP Code(设备信息)', () => {
37
+ // 模拟设备信息
38
+ getScheduleCache.mockImplementation(key => {
39
+ if (key === 'devInfo') return mockDevInfo;
40
+ if (key === 'groupInfo') return null;
41
+ return null;
42
+ });
43
+ expect(getDpCodeByDpId(1)).toBe('switch_led');
44
+ expect(getDpCodeByDpId(2)).toBe('bright_value');
45
+ expect(getDpCodeByDpId(3)).toBe('colour_data');
46
+ expect(getDpCodeByDpId(4)).toBeNull(); // 不存在的DP ID
47
+
48
+ // 验证调用了getScheduleCache
49
+ expect(getScheduleCache).toHaveBeenCalledWith('devInfo');
50
+ expect(getScheduleCache).toHaveBeenCalledWith('groupInfo');
51
+ });
52
+ it('应该根据DP ID返回对应的DP Code(群组信息)', () => {
53
+ // 模拟没有设备信息,只有群组信息
54
+ getScheduleCache.mockImplementation(key => {
55
+ if (key === 'devInfo') return null;
56
+ if (key === 'groupInfo') return mockGroupInfo;
57
+ return null;
58
+ });
59
+ expect(getDpCodeByDpId(1)).toBe('switch_led');
60
+ expect(getDpCodeByDpId(2)).toBe('bright_value');
61
+ expect(getDpCodeByDpId(3)).toBeNull(); // 群组中不存在的DP ID
62
+
63
+ // 验证调用了getScheduleCache
64
+ expect(getScheduleCache).toHaveBeenCalledWith('devInfo');
65
+ expect(getScheduleCache).toHaveBeenCalledWith('groupInfo');
66
+ });
67
+ it('当没有设备信息和群组信息时应该返回null', () => {
68
+ // 模拟没有设备信息和群组信息
69
+ getScheduleCache.mockReturnValue(null);
70
+ expect(getDpCodeByDpId(1)).toBeNull();
71
+
72
+ // 验证调用了getScheduleCache
73
+ expect(getScheduleCache).toHaveBeenCalledWith('devInfo');
74
+ expect(getScheduleCache).toHaveBeenCalledWith('groupInfo');
75
+ });
76
+ });
77
+ describe('getDpIdByDpCode', () => {
78
+ it('应该根据DP Code返回对应的DP ID(设备信息)', () => {
79
+ // 模拟设备信息
80
+ getScheduleCache.mockImplementation(key => {
81
+ if (key === 'devInfo') return mockDevInfo;
82
+ if (key === 'groupInfo') return null;
83
+ return null;
84
+ });
85
+ expect(getDpIdByDpCode('switch_led')).toBe(1);
86
+ expect(getDpIdByDpCode('bright_value')).toBe(2);
87
+ expect(getDpIdByDpCode('colour_data')).toBe(3);
88
+ expect(getDpIdByDpCode('non_existent')).toBeNull(); // 不存在的DP Code
89
+
90
+ // 验证调用了getScheduleCache
91
+ expect(getScheduleCache).toHaveBeenCalledWith('devInfo');
92
+ expect(getScheduleCache).toHaveBeenCalledWith('groupInfo');
93
+ });
94
+ it('应该根据DP Code返回对应的DP ID(群组信息)', () => {
95
+ // 模拟没有设备信息,只有群组信息
96
+ getScheduleCache.mockImplementation(key => {
97
+ if (key === 'devInfo') return null;
98
+ if (key === 'groupInfo') return mockGroupInfo;
99
+ return null;
100
+ });
101
+ expect(getDpIdByDpCode('switch_led')).toBe(1);
102
+ expect(getDpIdByDpCode('bright_value')).toBe(2);
103
+ expect(getDpIdByDpCode('colour_data')).toBeNull(); // 群组中不存在的DP Code
104
+
105
+ // 验证调用了getScheduleCache
106
+ expect(getScheduleCache).toHaveBeenCalledWith('devInfo');
107
+ expect(getScheduleCache).toHaveBeenCalledWith('groupInfo');
108
+ });
109
+ it('当没有设备信息和群组信息时应该返回null', () => {
110
+ // 模拟没有设备信息和群组信息
111
+ getScheduleCache.mockReturnValue(null);
112
+ expect(getDpIdByDpCode('switch_led')).toBeNull();
113
+
114
+ // 验证调用了getScheduleCache
115
+ expect(getScheduleCache).toHaveBeenCalledWith('devInfo');
116
+ expect(getScheduleCache).toHaveBeenCalledWith('groupInfo');
117
+ });
118
+ });
119
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,147 @@
1
+ import { isNum, findMinMissingNum, getSafeAreaPadding, timeStrToMinutes, minutesToTimeStr } from '../common';
2
+ import { getCachedSystemInfo } from '../getCachedSystemInfo';
3
+
4
+ // 模拟依赖
5
+ jest.mock('../getCachedSystemInfo', () => ({
6
+ getCachedSystemInfo: jest.fn()
7
+ }));
8
+ describe('common', () => {
9
+ describe('isNum', () => {
10
+ it('应该正确判断数字', () => {
11
+ expect(isNum(0)).toBe(true);
12
+ expect(isNum(1)).toBe(true);
13
+ expect(isNum(-1)).toBe(true);
14
+ expect(isNum(1.5)).toBe(true);
15
+ expect(isNum(Number.MAX_SAFE_INTEGER)).toBe(true);
16
+ expect(isNum(Number.MIN_SAFE_INTEGER)).toBe(true);
17
+ });
18
+ it('应该正确判断非数字', () => {
19
+ expect(isNum(null)).toBe(false);
20
+ expect(isNum(undefined)).toBe(false);
21
+ expect(isNum('1')).toBe(false);
22
+ expect(isNum('abc')).toBe(false);
23
+ expect(isNum({})).toBe(false);
24
+ expect(isNum([])).toBe(false);
25
+ expect(isNum(NaN)).toBe(false);
26
+ expect(isNum(Infinity)).toBe(false);
27
+ expect(isNum(-Infinity)).toBe(false);
28
+ });
29
+ });
30
+ describe('findMinMissingNum', () => {
31
+ it('应该找到数组中缺失的最小正整数', () => {
32
+ expect(findMinMissingNum([1, 2, 3, 4, 5])).toBe(6);
33
+ expect(findMinMissingNum([2, 3, 4, 5])).toBe(1);
34
+ expect(findMinMissingNum([1, 3, 4, 5])).toBe(2);
35
+ expect(findMinMissingNum([1, 2, 4, 5])).toBe(3);
36
+ expect(findMinMissingNum([1, 2, 3, 5])).toBe(4);
37
+ expect(findMinMissingNum([6, 7, 8, 9, 10])).toBe(1);
38
+ expect(findMinMissingNum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])).toBe(null); // 超出范围,返回 null
39
+ });
40
+ it('应该处理空数组', () => {
41
+ expect(findMinMissingNum([])).toBe(1);
42
+ });
43
+ it('应该处理包含重复元素的数组', () => {
44
+ expect(findMinMissingNum([1, 1, 2, 2, 3])).toBe(4);
45
+ });
46
+ it('应该处理包含负数和0的数组', () => {
47
+ expect(findMinMissingNum([-3, -2, -1, 0, 1, 2])).toBe(3);
48
+ });
49
+ it('应该限制返回值在1-10范围内', () => {
50
+ // 所有1-10的数字都存在,应该返回 null
51
+ expect(findMinMissingNum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])).toBe(null);
52
+ });
53
+ });
54
+ describe('getSafeAreaPadding', () => {
55
+ beforeEach(() => {
56
+ jest.clearAllMocks();
57
+ });
58
+ it('应该返回默认安全区域填充', () => {
59
+ // 模拟getCachedSystemInfo返回null
60
+ getCachedSystemInfo.mockReturnValue(null);
61
+ const result = getSafeAreaPadding();
62
+ expect(result).toEqual({
63
+ bottomHeight: 667,
64
+ bottomPadding: 20,
65
+ safeHeight: 667,
66
+ topPadding: 24
67
+ });
68
+ });
69
+ it('应该返回系统信息中的安全区域填充', () => {
70
+ // 模拟getCachedSystemInfo返回带有safeArea的系统信息
71
+
72
+ getCachedSystemInfo.mockReturnValue({
73
+ safeArea: {
74
+ top: 44,
75
+ right: 375,
76
+ bottom: 812,
77
+ left: 0,
78
+ width: 375,
79
+ height: 768
80
+ },
81
+ screenHeight: 812,
82
+ statusBarHeight: 44,
83
+ screenWidth: 375
84
+ });
85
+ const result = getSafeAreaPadding();
86
+ expect(result).toEqual({
87
+ bottomHeight: 812,
88
+ bottomPadding: 0,
89
+ safeHeight: 768,
90
+ topPadding: 44
91
+ });
92
+ });
93
+ it('应该处理safeArea不完整的情况', () => {
94
+ // 模拟getCachedSystemInfo返回不完整的safeArea
95
+
96
+ getCachedSystemInfo.mockReturnValue({
97
+ safeArea: {
98
+ top: 44,
99
+ // 缺少right
100
+ bottom: 812,
101
+ left: 0,
102
+ width: 375,
103
+ height: 768
104
+ },
105
+ screenHeight: 812,
106
+ statusBarHeight: 44,
107
+ screenWidth: 375
108
+ });
109
+ const result = getSafeAreaPadding();
110
+ expect(result).toEqual({
111
+ bottomHeight: 812,
112
+ bottomPadding: 0,
113
+ safeHeight: 768,
114
+ topPadding: 44
115
+ });
116
+ });
117
+ });
118
+ describe('timeStrToMinutes', () => {
119
+ it('应该将HH:mm格式的时间字符串转换为分钟数', () => {
120
+ expect(timeStrToMinutes('00:00')).toBe(0);
121
+ expect(timeStrToMinutes('01:00')).toBe(60);
122
+ expect(timeStrToMinutes('00:30')).toBe(30);
123
+ expect(timeStrToMinutes('01:30')).toBe(90);
124
+ expect(timeStrToMinutes('23:59')).toBe(1439);
125
+ });
126
+ it('应该处理格式不正确的时间字符串', () => {
127
+ expect(timeStrToMinutes('0:0')).toBe(0);
128
+ expect(timeStrToMinutes('1:0')).toBe(60);
129
+ expect(timeStrToMinutes('0:3')).toBe(3);
130
+ expect(timeStrToMinutes('1:3')).toBe(63);
131
+ });
132
+ it('应该处理非法输入', () => {
133
+ expect(timeStrToMinutes('')).toBe(0);
134
+ expect(timeStrToMinutes('invalid')).toBe(0);
135
+ expect(timeStrToMinutes('24:00')).toBe(0); // 超出有效范围
136
+ expect(timeStrToMinutes('23:60')).toBe(0); // 超出有效范围
137
+ expect(timeStrToMinutes('-1:00')).toBe(0); // 负数
138
+ });
139
+ });
140
+ describe('minutesToTimeStr', () => {
141
+ it('should convert minutes to time string', () => {
142
+ expect(minutesToTimeStr(90)).toBe('01:30');
143
+ expect(minutesToTimeStr(0)).toBe('00:00');
144
+ expect(minutesToTimeStr(undefined)).toBe('00:00');
145
+ });
146
+ });
147
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,98 @@
1
+ import { SmartStorageAbility } from '@ray-js/panel-sdk';
2
+ import { initStorage, getStorageIns } from '../storage';
3
+ import { scheduleLogger } from '../ScheduleLogger';
4
+
5
+ // Mock SmartStorageAbility
6
+ jest.mock('@ray-js/panel-sdk', () => ({
7
+ SmartStorageAbility: jest.fn().mockImplementation(() => ({
8
+ init: jest.fn()
9
+ }))
10
+ }));
11
+
12
+ // Mock ScheduleLogger
13
+ jest.mock('../ScheduleLogger', () => ({
14
+ scheduleLogger: {
15
+ debug: jest.fn(),
16
+ error: jest.fn(),
17
+ warn: jest.fn()
18
+ }
19
+ }));
20
+ describe('Storage Utils', () => {
21
+ beforeEach(() => {
22
+ // 清除所有模拟函数的调用记录
23
+ jest.clearAllMocks();
24
+ // 重置全局缓存
25
+ globalThis.__GCaches__ = {
26
+ SmartStorageAbility: {
27
+ get: jest.fn(),
28
+ set: jest.fn(),
29
+ remove: jest.fn(),
30
+ clear: jest.fn()
31
+ }
32
+ };
33
+ // 重置 storage 实例
34
+ getStorageIns.__storage = null;
35
+ });
36
+ describe('initStorage', () => {
37
+ it('应该成功初始化 storage', async () => {
38
+ const mockStorage = {
39
+ someMethod: jest.fn()
40
+ };
41
+ const mockInit = jest.fn().mockResolvedValue(mockStorage);
42
+ SmartStorageAbility.mockImplementation(() => ({
43
+ init: mockInit
44
+ }));
45
+ const result = await initStorage('test-device-id', 'test-group-id');
46
+ expect(result).toBe(true);
47
+ expect(mockInit).toHaveBeenCalledWith({
48
+ deviceId: 'test-device-id',
49
+ groupId: 'test-group-id'
50
+ });
51
+ expect(scheduleLogger.debug).toHaveBeenCalledWith('initStorage success:', mockStorage);
52
+ });
53
+ it('应该在初始化失败时返回 false', async () => {
54
+ const mockError = new Error('初始化失败');
55
+ const mockInit = jest.fn().mockRejectedValue(mockError);
56
+ SmartStorageAbility.mockImplementation(() => ({
57
+ init: mockInit
58
+ }));
59
+ const result = await initStorage('test-device-id', 'test-group-id');
60
+ expect(result).toBe(false);
61
+ expect(scheduleLogger.error).toHaveBeenCalledWith('initStorage failed:', mockError);
62
+ });
63
+ });
64
+ describe('getStorageIns', () => {
65
+ it('应该返回已初始化的 storage 实例', async () => {
66
+ const mockStorage = {
67
+ someMethod: jest.fn()
68
+ };
69
+ const mockInit = jest.fn().mockResolvedValue(mockStorage);
70
+ SmartStorageAbility.mockImplementation(() => ({
71
+ init: mockInit
72
+ }));
73
+ await initStorage('test-device-id', 'test-group-id');
74
+ const storage = getStorageIns();
75
+ expect(storage).toBe(mockStorage);
76
+ expect(scheduleLogger.warn).not.toHaveBeenCalled();
77
+ });
78
+ it('应该在 storage 未初始化时发出警告', async () => {
79
+ jest.resetModules();
80
+ jest.doMock('../ScheduleLogger', () => ({
81
+ scheduleLogger: {
82
+ debug: jest.fn(),
83
+ error: jest.fn(),
84
+ warn: jest.fn()
85
+ }
86
+ }));
87
+ const {
88
+ getStorageIns
89
+ } = await import('../storage');
90
+ const {
91
+ scheduleLogger
92
+ } = await import('../ScheduleLogger');
93
+ const storage = getStorageIns();
94
+ expect(storage).toBeNull();
95
+ expect(scheduleLogger.warn).toHaveBeenCalledWith('storage ins is null');
96
+ });
97
+ });
98
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,146 @@
1
+ import { getTimeFormatStrByHourMins, getTimerStrByMinutes, getTimeNumByTimeStr, getPreOffsetTime, getPreOffsetTimeByHourMins, getBackwardOffsetTime, getBackwardOffsetTimeByHourMins } from '../time';
2
+ describe('time', () => {
3
+ describe('getTimeFormatStrByHourMins', () => {
4
+ it('应该将小时和分钟转换为HH:mm格式字符串', () => {
5
+ expect(getTimeFormatStrByHourMins(0, 0)).toBe('00:00');
6
+ expect(getTimeFormatStrByHourMins(1, 0)).toBe('01:00');
7
+ expect(getTimeFormatStrByHourMins(0, 1)).toBe('00:01');
8
+ expect(getTimeFormatStrByHourMins(1, 1)).toBe('01:01');
9
+ expect(getTimeFormatStrByHourMins(12, 30)).toBe('12:30');
10
+ expect(getTimeFormatStrByHourMins(23, 59)).toBe('23:59');
11
+ });
12
+ it('应该处理超出范围的小时和分钟', () => {
13
+ expect(getTimeFormatStrByHourMins(24, 0)).toBe('00:00'); // 24小时应该转换为00
14
+ expect(getTimeFormatStrByHourMins(25, 0)).toBe('01:00'); // 25小时应该转换为01
15
+ expect(getTimeFormatStrByHourMins(0, 60)).toBe('01:00'); // 60分钟应该转换为1小时
16
+ expect(getTimeFormatStrByHourMins(0, 61)).toBe('01:01'); // 61分钟应该转换为1小时1分钟
17
+ expect(getTimeFormatStrByHourMins(23, 60)).toBe('00:00'); // 23小时60分钟应该转换为0小时0分钟
18
+ });
19
+ it('应该处理负数', () => {
20
+ expect(getTimeFormatStrByHourMins(-1, 0)).toBe('23:00'); // -1小时应该转换为23小时
21
+ expect(getTimeFormatStrByHourMins(0, -1)).toBe('23:59'); // -1分钟应该转换为23小时59分钟
22
+ expect(getTimeFormatStrByHourMins(-1, -1)).toBe('22:59'); // -1小时-1分钟应该转换为22小时59分钟
23
+ });
24
+ });
25
+ describe('getTimerStrByMinutes', () => {
26
+ it('应该将分钟数转换为HH:mm格式字符串', () => {
27
+ expect(getTimerStrByMinutes(0)).toBe('00:00');
28
+ expect(getTimerStrByMinutes(1)).toBe('00:01');
29
+ expect(getTimerStrByMinutes(60)).toBe('01:00');
30
+ expect(getTimerStrByMinutes(61)).toBe('01:01');
31
+ expect(getTimerStrByMinutes(90)).toBe('01:30');
32
+ expect(getTimerStrByMinutes(1439)).toBe('23:59'); // 一天的最后一分钟
33
+ });
34
+ it('应该处理超出一天的分钟数', () => {
35
+ expect(getTimerStrByMinutes(1440)).toBe('00:00'); // 一天的分钟数
36
+ expect(getTimerStrByMinutes(1441)).toBe('00:01'); // 一天加1分钟
37
+ expect(getTimerStrByMinutes(1500)).toBe('01:00'); // 一天加60分钟
38
+ expect(getTimerStrByMinutes(2880)).toBe('00:00'); // 两天的分钟数
39
+ });
40
+ });
41
+ describe('getTimeNumByTimeStr', () => {
42
+ it('应该将HH:mm格式字符串转换为分钟数', () => {
43
+ expect(getTimeNumByTimeStr('00:00')).toBe(0);
44
+ expect(getTimeNumByTimeStr('00:01')).toBe(1);
45
+ expect(getTimeNumByTimeStr('01:00')).toBe(60);
46
+ expect(getTimeNumByTimeStr('01:01')).toBe(61);
47
+ expect(getTimeNumByTimeStr('01:30')).toBe(90);
48
+ expect(getTimeNumByTimeStr('23:59')).toBe(1439);
49
+ });
50
+ it('应该处理格式不正确的时间字符串', () => {
51
+ expect(getTimeNumByTimeStr('0:0')).toBe(0);
52
+ expect(getTimeNumByTimeStr('0:1')).toBe(1);
53
+ expect(getTimeNumByTimeStr('1:0')).toBe(60);
54
+ expect(getTimeNumByTimeStr('1:1')).toBe(61);
55
+ expect(getTimeNumByTimeStr('1:30')).toBe(90);
56
+ expect(getTimeNumByTimeStr('23:59')).toBe(1439);
57
+ });
58
+ it('应该处理非法输入', () => {
59
+ expect(getTimeNumByTimeStr('')).toBe(0);
60
+ expect(getTimeNumByTimeStr('invalid')).toBe(0);
61
+ expect(getTimeNumByTimeStr('24:00')).toBe(0); // 超出有效范围
62
+ expect(getTimeNumByTimeStr('23:60')).toBe(0); // 超出有效范围
63
+ expect(getTimeNumByTimeStr('-1:00')).toBe(0); // 负数
64
+ });
65
+ });
66
+ describe('getPreOffsetTime', () => {
67
+ it('应该根据偏移量计算向前偏移的时间', () => {
68
+ expect(getPreOffsetTime('00:00', 0)).toBe('00:00'); // 无偏移
69
+ expect(getPreOffsetTime('00:00', 1)).toBe('23:59'); // 偏移1分钟
70
+ expect(getPreOffsetTime('00:00', 60)).toBe('23:00'); // 偏移1小时
71
+ expect(getPreOffsetTime('00:00', 90)).toBe('22:30'); // 偏移1小时30分钟
72
+ expect(getPreOffsetTime('12:30', 30)).toBe('12:00'); // 偏移30分钟
73
+ expect(getPreOffsetTime('12:30', 90)).toBe('11:00'); // 偏移1小时30分钟
74
+ });
75
+ it('应该处理大偏移量', () => {
76
+ expect(getPreOffsetTime('00:00', 1440)).toBe('00:00'); // 偏移1天
77
+ expect(getPreOffsetTime('00:00', 1441)).toBe('23:59'); // 偏移1天1分钟
78
+ expect(getPreOffsetTime('00:00', 2880)).toBe('00:00'); // 偏移2天
79
+ });
80
+ it('应该处理负偏移量(实际是向后偏移)', () => {
81
+ expect(getPreOffsetTime('00:00', -1)).toBe('00:01'); // 向后偏移1分钟
82
+ expect(getPreOffsetTime('00:00', -60)).toBe('01:00'); // 向后偏移1小时
83
+ expect(getPreOffsetTime('23:59', -1)).toBe('00:00'); // 向后偏移1分钟
84
+ });
85
+ });
86
+ describe('getPreOffsetTimeByHourMins', () => {
87
+ it('应该根据小时、分钟和偏移量计算向前偏移的时间', () => {
88
+ expect(getPreOffsetTimeByHourMins(0, 0, 0)).toBe('00:00'); // 无偏移
89
+ expect(getPreOffsetTimeByHourMins(0, 0, 1)).toBe('23:59'); // 偏移1分钟
90
+ expect(getPreOffsetTimeByHourMins(0, 0, 60)).toBe('23:00'); // 偏移1小时
91
+ expect(getPreOffsetTimeByHourMins(0, 0, 90)).toBe('22:30'); // 偏移1小时30分钟
92
+ expect(getPreOffsetTimeByHourMins(12, 30, 30)).toBe('12:00'); // 偏移30分钟
93
+ expect(getPreOffsetTimeByHourMins(12, 30, 90)).toBe('11:00'); // 偏移1小时30分钟
94
+ });
95
+ it('应该处理大偏移量', () => {
96
+ expect(getPreOffsetTimeByHourMins(0, 0, 1440)).toBe('00:00'); // 偏移1天
97
+ expect(getPreOffsetTimeByHourMins(0, 0, 1441)).toBe('23:59'); // 偏移1天1分钟
98
+ expect(getPreOffsetTimeByHourMins(0, 0, 2880)).toBe('00:00'); // 偏移2天
99
+ });
100
+ it('应该处理负偏移量(实际是向后偏移)', () => {
101
+ expect(getPreOffsetTimeByHourMins(0, 0, -1)).toBe('00:01'); // 向后偏移1分钟
102
+ expect(getPreOffsetTimeByHourMins(0, 0, -60)).toBe('01:00'); // 向后偏移1小时
103
+ expect(getPreOffsetTimeByHourMins(23, 59, -1)).toBe('00:00'); // 向后偏移1分钟
104
+ });
105
+ });
106
+ describe('getBackwardOffsetTime', () => {
107
+ it('应该根据偏移量计算向后偏移的时间', () => {
108
+ expect(getBackwardOffsetTime('00:00', 0)).toBe('00:00'); // 无偏移
109
+ expect(getBackwardOffsetTime('00:00', 1)).toBe('00:01'); // 偏移1分钟
110
+ expect(getBackwardOffsetTime('00:00', 60)).toBe('01:00'); // 偏移1小时
111
+ expect(getBackwardOffsetTime('00:00', 90)).toBe('01:30'); // 偏移1小时30分钟
112
+ expect(getBackwardOffsetTime('23:30', 30)).toBe('00:00'); // 偏移30分钟
113
+ expect(getBackwardOffsetTime('23:00', 90)).toBe('00:30'); // 偏移1小时30分钟
114
+ });
115
+ it('应该处理大偏移量', () => {
116
+ expect(getBackwardOffsetTime('00:00', 1440)).toBe('00:00'); // 偏移1天
117
+ expect(getBackwardOffsetTime('00:00', 1441)).toBe('00:01'); // 偏移1天1分钟
118
+ expect(getBackwardOffsetTime('00:00', 2880)).toBe('00:00'); // 偏移2天
119
+ });
120
+ it('应该处理负偏移量(实际是向前偏移)', () => {
121
+ expect(getBackwardOffsetTime('00:00', -1)).toBe('23:59'); // 向前偏移1分钟
122
+ expect(getBackwardOffsetTime('00:00', -60)).toBe('23:00'); // 向前偏移1小时
123
+ expect(getBackwardOffsetTime('00:01', -1)).toBe('00:00'); // 向前偏移1分钟
124
+ });
125
+ });
126
+ describe('getBackwardOffsetTimeByHourMins', () => {
127
+ it('应该根据小时、分钟和偏移量计算向后偏移的时间', () => {
128
+ expect(getBackwardOffsetTimeByHourMins(0, 0, 0)).toBe('00:00'); // 无偏移
129
+ expect(getBackwardOffsetTimeByHourMins(0, 0, 1)).toBe('00:01'); // 偏移1分钟
130
+ expect(getBackwardOffsetTimeByHourMins(0, 0, 60)).toBe('01:00'); // 偏移1小时
131
+ expect(getBackwardOffsetTimeByHourMins(0, 0, 90)).toBe('01:30'); // 偏移1小时30分钟
132
+ expect(getBackwardOffsetTimeByHourMins(23, 30, 30)).toBe('00:00'); // 偏移30分钟
133
+ expect(getBackwardOffsetTimeByHourMins(23, 0, 90)).toBe('00:30'); // 偏移1小时30分钟
134
+ });
135
+ it('应该处理大偏移量', () => {
136
+ expect(getBackwardOffsetTimeByHourMins(0, 0, 1440)).toBe('00:00'); // 偏移1天
137
+ expect(getBackwardOffsetTimeByHourMins(0, 0, 1441)).toBe('00:01'); // 偏移1天1分钟
138
+ expect(getBackwardOffsetTimeByHourMins(0, 0, 2880)).toBe('00:00'); // 偏移2天
139
+ });
140
+ it('应该处理负偏移量(实际是向前偏移)', () => {
141
+ expect(getBackwardOffsetTimeByHourMins(0, 0, -1)).toBe('23:59'); // 向前偏移1分钟
142
+ expect(getBackwardOffsetTimeByHourMins(0, 0, -60)).toBe('23:00'); // 向前偏移1小时
143
+ expect(getBackwardOffsetTimeByHourMins(0, 1, -1)).toBe('00:00'); // 向前偏移1分钟
144
+ });
145
+ });
146
+ });
@@ -0,0 +1,23 @@
1
+ export declare const isIOS: () => boolean;
2
+ export declare const isNum: (val: unknown) => boolean;
3
+ /**
4
+ * 查找数组中缺失的最小正整数
5
+ * 函数的搜索范围限定为1到10之间如果在这个范围内所有数字都存在,则返回11
6
+ *
7
+ * @param arr 整数数组,可能包含正数、负数和零
8
+ * @returns 返回缺失的最小正整数,如果不存在,则返回 null
9
+ */
10
+ export declare const findMinMissingNum: (arr: number[] | string[]) => number;
11
+ export declare const getSafeAreaPadding: () => {
12
+ bottomPadding: number;
13
+ topPadding: number;
14
+ safeHeight: number;
15
+ bottomHeight: number;
16
+ };
17
+ export declare const timeStrToMinutes: (timeStr: string) => number;
18
+ /**
19
+ * 将分钟数转换为时间字符串
20
+ * @param minutes 分钟数
21
+ * @returns 时间字符串,格式为 HH:mm
22
+ */
23
+ export declare const minutesToTimeStr: (minutes: number) => string;
@@ -0,0 +1,109 @@
1
+ import "core-js/modules/esnext.iterator.map.js";
2
+ import { getCachedSystemInfo } from './getCachedSystemInfo';
3
+
4
+ // 判断是否是iOS系统
5
+ export const isIOS = () => {
6
+ var _getCachedSystemInfo;
7
+ return ((_getCachedSystemInfo = getCachedSystemInfo()) === null || _getCachedSystemInfo === void 0 || (_getCachedSystemInfo = _getCachedSystemInfo.platform) === null || _getCachedSystemInfo === void 0 ? void 0 : _getCachedSystemInfo.toLocaleLowerCase()) === 'ios';
8
+ };
9
+ export const isNum = val => {
10
+ if (val === null || val === undefined) return false;
11
+ const num = Number(val);
12
+ return typeof val === 'number' && !isNaN(num) && isFinite(num);
13
+ };
14
+
15
+ /**
16
+ * 查找数组中缺失的最小正整数
17
+ * 函数的搜索范围限定为1到10之间如果在这个范围内所有数字都存在,则返回11
18
+ *
19
+ * @param arr 整数数组,可能包含正数、负数和零
20
+ * @returns 返回缺失的最小正整数,如果不存在,则返回 null
21
+ */
22
+ export const findMinMissingNum = arr => {
23
+ // 创建一个Set来存储数组中的元素,以实现快速查找
24
+ const numSet = new Set(arr.map(i => +i));
25
+
26
+ // 从 1 到 10 查找第一个不存在的数字
27
+ for (let i = 1; i <= 10; i++) {
28
+ // 如果当前数字不在Set中,则返回该数字
29
+ if (!numSet.has(i)) {
30
+ return i;
31
+ }
32
+ }
33
+
34
+ // 如果 1-10 都存在则返回 null
35
+ return null;
36
+ };
37
+
38
+ /**
39
+ * 获取屏幕安全区域
40
+ * @returns {
41
+ * bottomPadding: number; // 底部距离的安全 padding 距离,单位:px
42
+ * topPadding: number; // 顶部距离的安全 padding 距离,单位:px
43
+ * safeHeight: number;
44
+ * }
45
+ */
46
+ let safePadding = null;
47
+ export const getSafeAreaPadding = () => {
48
+ if (safePadding) {
49
+ return safePadding;
50
+ }
51
+ try {
52
+ const systemInfo = getCachedSystemInfo();
53
+ const {
54
+ safeArea,
55
+ screenHeight,
56
+ statusBarHeight
57
+ } = systemInfo;
58
+ const bottomPadding = screenHeight - safeArea.bottom;
59
+ const _isIos = isIOS();
60
+ safePadding = {
61
+ bottomPadding,
62
+ topPadding: statusBarHeight,
63
+ safeHeight: _isIos ? safeArea.bottom : screenHeight - statusBarHeight,
64
+ bottomHeight: safeArea.bottom
65
+ };
66
+ return safePadding;
67
+ } catch (err) {
68
+ return {
69
+ bottomPadding: 20,
70
+ topPadding: 24,
71
+ safeHeight: 667,
72
+ bottomHeight: 667
73
+ };
74
+ }
75
+ };
76
+
77
+ // 将时间字符串转换为分钟数
78
+ export const timeStrToMinutes = timeStr => {
79
+ try {
80
+ if (!timeStr || typeof timeStr !== 'string') {
81
+ return 0;
82
+ }
83
+ const parts = timeStr.split(':');
84
+ if (parts.length !== 2) {
85
+ return 0;
86
+ }
87
+ const hours = parseInt(parts[0], 10);
88
+ const minutes = parseInt(parts[1], 10);
89
+
90
+ // 验证时间范围
91
+ if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours >= 24 || minutes < 0 || minutes >= 60) {
92
+ return 0;
93
+ }
94
+ return hours * 60 + minutes;
95
+ } catch (error) {
96
+ return 0;
97
+ }
98
+ };
99
+
100
+ /**
101
+ * 将分钟数转换为时间字符串
102
+ * @param minutes 分钟数
103
+ * @returns 时间字符串,格式为 HH:mm
104
+ */
105
+ export const minutesToTimeStr = minutes => {
106
+ if (!minutes && minutes !== 0) return '00:00';
107
+ const hours = Math.floor(minutes / 60);
108
+ return `${hours.toString().padStart(2, '0')}:${(minutes % 60).toString().padStart(2, '0')}`;
109
+ };
@@ -0,0 +1,5 @@
1
+ export declare const getDpState: (dpCode: string) => any;
2
+ export declare const setDpState: (dpCode: string, dpValue: any) => void;
3
+ export declare const clearDpState: () => void;
4
+ export declare const getAllDpState: () => {};
5
+ export declare const initDpState: (dpState?: Record<string, any>) => void;