@ledvance/base 1.3.67 → 1.3.71

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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/base",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.3.67",
7
+ "version": "1.3.71",
8
8
  "scripts": {
9
9
  "prepublishOnly": "python update-localazy.py"
10
10
  },
@@ -8,6 +8,10 @@ const { withTheme } = Utils.ThemeUtils
8
8
 
9
9
  const repeatPeriod = [
10
10
  {
11
+ index: 1,
12
+ title: I18n.getLang('timeschedule_add_schedule_weekday7_text'),
13
+ enabled: false,
14
+ }, {
11
15
  index: 2,
12
16
  title: I18n.getLang('timeschedule_add_schedule_weekday1_text'),
13
17
  enabled: false,
@@ -31,18 +35,14 @@ const repeatPeriod = [
31
35
  index: 7,
32
36
  title: I18n.getLang('timeschedule_add_schedule_weekday6_text'),
33
37
  enabled: false,
34
- }, {
35
- index: 1,
36
- title: I18n.getLang('timeschedule_add_schedule_weekday7_text'),
37
- enabled: false,
38
38
  },
39
39
  ]
40
40
 
41
- export const setDataSource = (loop: number[] | string[] | string) => {
42
- return repeatPeriod.map(item => {
41
+ export const setDataSource = (loop) => {
42
+ return repeatPeriod.map((item, index) => {
43
43
  return {
44
44
  ...item,
45
- enabled: [1, '1'].includes(loop[item.index - 1]),
45
+ enabled: loop[index] === 1,
46
46
  }
47
47
  })
48
48
  }
@@ -10,7 +10,7 @@ import {
10
10
  NativeProps,
11
11
  setGroupDevices,
12
12
  setGroupNativeProps,
13
- setNativeProps, setNewPalette,
13
+ setNativeProps,
14
14
  setSystemTimeFormat,
15
15
  setTimeZone,
16
16
  UAGroupInfo,
@@ -26,7 +26,6 @@ interface Props {
26
26
  ldvDevInfo: LdvDevInfo
27
27
  uaGroupInfo: UAGroupInfoProps
28
28
  colorScheme?: string
29
- newPalette?: boolean
30
29
  }
31
30
 
32
31
  interface LdvDevInfo extends DeviceInfo {
@@ -131,8 +130,6 @@ const composeLayout = (component: React.ComponentType) => {
131
130
  getTimeZone().then(timeZone => {
132
131
  dispatch(setTimeZone(timeZone))
133
132
  })
134
-
135
- dispatch(setNewPalette(!!props.newPalette || true))
136
133
  }
137
134
 
138
135
  initReduxDeviceNativeProps(ldvDevInfo: LdvDevInfo) {
@@ -19,49 +19,17 @@ export const loopsText = [
19
19
  I18n.getLang('timeschedule_add_schedule_weekday6_text'),
20
20
  ]
21
21
 
22
- /**
23
- * 根据循环设置和时间生成循环文本描述
24
- * @param {number[]|string[]} loop - 表示每周哪几天启用的数组,1表示启用,0表示不启用
25
- * @param {string} time - 可选的时间字符串,格式为 "HH:MM"
26
- * @returns {string} 格式化后的循环文本
27
- */
28
- export const loopText = (loop: number[] | string[], time: string = ''): string => {
29
- // 判断是否为今天(如果提供了时间)
30
- let isToday = true;
22
+ export const loopText = (loop, time = '') => {
23
+ let isToday = true
31
24
  if (time) {
32
- const [hours, minutes] = time.split(':').map(Number);
33
- const currentTime = dayjs();
34
- const targetTime = dayjs().set('hour', hours).set('minute', minutes);
35
- isToday = !targetTime.isBefore(currentTime);
25
+ const currentTime = dayjs()
26
+ const targetTime = dayjs().set('hour', parseInt(time.split(':')[0])).set('minute', parseInt(time.split(':')[1]));
27
+ const isBeforeCurrentTime = targetTime.isBefore(currentTime)
28
+ isToday = !isBeforeCurrentTime
36
29
  }
37
-
38
- // 将循环数组转换为带有启用状态的对象数组
39
- const weekdaysWithStatus = loopsText.map((title, index) => ({
40
- title,
41
- enable: Number(loop[index]) === 1
42
- }));
43
-
44
- // 将周日移到数组末尾(如果需要按周一到周日的顺序显示)
45
- const first = weekdaysWithStatus.shift();
46
- first && weekdaysWithStatus.push(first);
47
-
48
- // 获取已启用的星期几
49
- const enabledWeekdays = weekdaysWithStatus
50
- .filter(item => item.enable)
51
- .map(item => item.title);
52
-
53
- // 根据启用的天数返回不同的文本
54
- switch (enabledWeekdays.length) {
55
- case 0:
56
- return I18n.getLang(isToday
57
- ? 'motion_detection_time_schedule_notifications_field_weekdays_text2'
58
- : 'motion_detection_time_schedule_notifications_field_weekdays_text3');
59
- case 7:
60
- return I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4');
61
- default:
62
- return enabledWeekdays.join(' ');
63
- }
64
- };
30
+ const loopStrArray = loopsText.filter((_item, index) => Number(loop[index]) === 1)
31
+ return loopStrArray.length === 0 ? (I18n.getLang(isToday ? 'motion_detection_time_schedule_notifications_field_weekdays_text2' : 'motion_detection_time_schedule_notifications_field_weekdays_text3')) : loopStrArray.length === 7 ? I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4') : loopStrArray.join(' ')
32
+ }
65
33
 
66
34
  const tommorrow = () => {
67
35
  const text = I18n.getLang('feature_summary_frequency_txt_2').split(' ')
@@ -189,61 +189,3 @@ export function abbreviateMonths(str: string) {
189
189
  export function overDays(date: string, days: number): boolean {
190
190
  return dayjs().diff(dayjs(date), 'days') >= days
191
191
  }
192
-
193
-
194
- /**
195
- * 通用重试函数,支持指数退避算法
196
- * @param fn 需要重试的异步函数
197
- * @param options 重试选项
198
- * @returns 异步函数的结果
199
- */
200
- export async function retryWithBackoff<T>(
201
- fn: () => Promise<T>,
202
- options: {
203
- maxRetries?: number; // 最大重试次数
204
- initialDelay?: number; // 初始延迟时间(毫秒)
205
- maxDelay?: number; // 最大延迟时间(毫秒)
206
- backoffFactor?: number; // 退避因子
207
- shouldRetry?: (error: any) => boolean; // 自定义判断是否应该重试的函数
208
- } = {}
209
- ): Promise<T> {
210
- const {
211
- maxRetries = 3,
212
- initialDelay = 1000,
213
- maxDelay = 30000,
214
- backoffFactor = 2,
215
- shouldRetry = () => true
216
- } = options;
217
-
218
- let retries = 0;
219
- let delay = initialDelay;
220
-
221
- const execute = async (): Promise<T> => {
222
- try {
223
- return await fn();
224
- } catch (error) {
225
- if (retries >= maxRetries || !shouldRetry(error)) {
226
- throw error;
227
- }
228
-
229
- retries++;
230
-
231
- // 计算下一次重试的延迟时间(指数退避)
232
- delay = Math.min(delay * backoffFactor, maxDelay);
233
-
234
- // 添加一些随机性,避免多个请求同时重试
235
- const jitter = delay * 0.2 * Math.random();
236
- const actualDelay = delay + jitter;
237
-
238
- console.log(`请求失败,${retries}/${maxRetries} 次重试,等待 ${Math.round(actualDelay)}ms...`, error);
239
-
240
- // 等待延迟时间
241
- await new Promise(resolve => setTimeout(resolve, actualDelay));
242
-
243
- // 递归重试
244
- return execute();
245
- }
246
- };
247
-
248
- return execute();
249
- }