@ledvance/base 1.1.38 → 1.1.40

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.1.38",
7
+ "version": "1.1.40",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@reduxjs/toolkit": "^1.8.6",
@@ -34,4 +34,5 @@ export declare const openDownloadFile: (filePath: string) => Promise<unknown>;
34
34
  export declare const queryDpIds: (dpIds: string, deviceId: string) => Promise<unknown>;
35
35
  export declare const formatNumber: (num: number, fixed: number) => string;
36
36
  export declare const getTimeZone: () => string;
37
+ export declare const getSystemTimeFormat: () => Promise<number>;
37
38
  export {};
package/src/api/native.ts CHANGED
@@ -19,6 +19,7 @@ interface LDVDevicePanelManager {
19
19
  getFeature: (deviceId: string, featureId: string, callback: (res: NativeResult<string>) => void) => void
20
20
  putFeature: (deviceId: string, featureId: string, value: any, callback: (res: NativeResult<string>) => void) => void
21
21
  getGroupDevices: (tyGroupId: number) => Promise<NativeResult<string>>
22
+ getSystemTimeFormat: () => Promise<number>
22
23
  }
23
24
 
24
25
  export interface DeviceInfo {
@@ -298,4 +299,13 @@ export const formatNumber: (num: number, fixed: number) => string = (num, fixed)
298
299
 
299
300
  export const getTimeZone: () => string = () => {
300
301
  return Platform.OS === 'android' ? devicePanel.getTimeZone() || '' : Intl.DateTimeFormat().resolvedOptions().timeZone
302
+ }
303
+
304
+ // 获取手机系统设置的12小时制还是24小时制
305
+ export const getSystemTimeFormat = async (): Promise<number> => {
306
+ try {
307
+ return await devicePanel.getSystemTimeFormat()
308
+ } catch (_) {
309
+ return 24
310
+ }
301
311
  }
@@ -11,16 +11,17 @@ interface Prop {
11
11
  colorAlpha: number
12
12
  enable: boolean
13
13
  setEnable: any
14
+ showSwitch?:boolean
14
15
  }
15
16
 
16
17
  const LdvSwitch = (props: Prop) => {
17
- const {title, color, colorAlpha, enable, setEnable} = props
18
+ const {title, color, colorAlpha, enable, setEnable, showSwitch = true} = props
18
19
  return (
19
20
  <View style={styles.titleBGView}>
20
21
  <Text style={styles.title}>{title}</Text>
21
22
  <View style={[styles.colorBlock, {backgroundColor: color, opacity: colorAlpha}]}/>
22
23
  <Spacer style={{flex: 1}} height={0} width={0}/>
23
- <SwitchButton value={enable} onValueChange={setEnable}/>
24
+ {showSwitch && <SwitchButton value={enable} onValueChange={setEnable}/>}
24
25
  </View>
25
26
  )
26
27
  }
@@ -0,0 +1,62 @@
1
+ import dayjs from 'dayjs';
2
+ export function findConflicts(schedule, object) {
3
+ const conflicts: any = [];
4
+ schedule.forEach(item => {
5
+ item.weeks = getLoopsForTheOnceItem(item);
6
+ });
7
+ object.weeks = getLoopsForTheOnceItem(object);
8
+ const objectStart = object.isSleep
9
+ ? object.time[0] * 60 + object.time[1]
10
+ : object.time[0] * 60 + object.time[1] - object.fade;
11
+ const objectEnd = object.isSleep
12
+ ? objectStart + object.fade
13
+ : object.time[0] * 60 + object.time[1];
14
+ for (let i = 0; i < schedule.length; i++) {
15
+ const { enable, weeks, time, fade, isSleep } = schedule[i];
16
+ if (enable === 0) continue;
17
+
18
+ const start = isSleep ? time[0] * 60 + time[1] : time[0] * 60 + time[1] - fade;
19
+ const end = isSleep ? start + fade : time[0] * 60 + time[1];
20
+
21
+ let conflict = false;
22
+ for (let j = 0; j < 7; j++) {
23
+ if (weeks[j] && start < 0 && object.weeks[j - 1 < 0 ? 6 : j - 1]) {
24
+ if (objectEnd - 24 * 60 > start) {
25
+ conflict = true;
26
+ break;
27
+ }
28
+ }
29
+ if (object.weeks[j] && weeks[j]) {
30
+ if (objectStart < end && objectEnd > start) {
31
+ conflict = true;
32
+ break;
33
+ }
34
+ }
35
+ if (weeks[j] && end > 24 * 60 && object.weeks[j + 1 > 6 ? 0 : j + 1]) {
36
+ if (end - 24 * 60 > objectStart) {
37
+ conflict = true;
38
+ break;
39
+ }
40
+ }
41
+ }
42
+
43
+ if (conflict) {
44
+ conflicts.push(schedule[i]);
45
+ }
46
+ }
47
+
48
+ return conflicts;
49
+ }
50
+ // once
51
+ function isLoopsEqualToOnce(loops) {
52
+ return loops.every(item => item === 0 || item === '0');
53
+ }
54
+
55
+ function getLoopsForTheOnceItem(item) {
56
+ let newLoops = [...item.loops];
57
+ if (isLoopsEqualToOnce(newLoops)) {
58
+ const now = dayjs();
59
+ newLoops[now.day()] = 1;
60
+ }
61
+ return newLoops;
62
+ }