@ledvance/ui-biz-bundle 1.0.50 → 1.0.52
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
|
@@ -10,13 +10,13 @@ import TextField from "@ledvance/base/src/components/TextField";
|
|
|
10
10
|
import LdvTopName from "@ledvance/base/src/components/ldvTopName";
|
|
11
11
|
import LdvPickerView from "@ledvance/base/src/components/ldvPickerView";
|
|
12
12
|
import LdvWeekView from '@ledvance/base/src/components/weekSelect'
|
|
13
|
-
import { loopText, toFixed } from "@ledvance/base/src/utils/common";
|
|
13
|
+
import { loopText, showDialog, toFixed } from "@ledvance/base/src/utils/common";
|
|
14
14
|
import DeviceState from "./DeviceState";
|
|
15
15
|
import Spacer from "@ledvance/base/src/components/Spacer";
|
|
16
16
|
import DeleteButton from "@ledvance/base/src/components/DeleteButton";
|
|
17
17
|
import { SleepWakeUpPageRouteParams } from "./SleepWakeUpPage";
|
|
18
18
|
import LdvSwitch from "@ledvance/base/src/components/ldvSwitch";
|
|
19
|
-
import { cloneDeep } from "lodash";
|
|
19
|
+
import { cloneDeep, isEqual } from "lodash";
|
|
20
20
|
import dayjs from "dayjs";
|
|
21
21
|
|
|
22
22
|
const { convertX: cx } = Utils.RatioUtils;
|
|
@@ -76,6 +76,7 @@ const SleepWakeUpDetailPage = () => {
|
|
|
76
76
|
|
|
77
77
|
useEffect(() => {
|
|
78
78
|
if (props.mode === 'edit' && scheduleItem) {
|
|
79
|
+
console.log(scheduleItem, '< -- scheduleItem')
|
|
79
80
|
state.hour = scheduleItem.time[0].toString().padStart(2, '0')
|
|
80
81
|
state.minute = scheduleItem.time[1].toString().padStart(2, '0')
|
|
81
82
|
state.name = scheduleItem.name
|
|
@@ -142,8 +143,8 @@ const SleepWakeUpDetailPage = () => {
|
|
|
142
143
|
state.duration = (Number(state.durationHour) * 60) + Number(min)
|
|
143
144
|
}, [state.durationHour, state.durationMinute])
|
|
144
145
|
|
|
145
|
-
const
|
|
146
|
-
|
|
146
|
+
const getNewItem = () =>{
|
|
147
|
+
return {
|
|
147
148
|
enable: 1,
|
|
148
149
|
loops: state.loop,
|
|
149
150
|
time: [parseInt(state.hour), parseInt(state.minute)],
|
|
@@ -156,6 +157,10 @@ const SleepWakeUpDetailPage = () => {
|
|
|
156
157
|
isSleep: props.isSleep,
|
|
157
158
|
fade: props.isSleep ? state.fadeOut : state.fadeIn
|
|
158
159
|
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const postActions = async () => {
|
|
163
|
+
const baseItemData: any = getNewItem()
|
|
159
164
|
if (props.mode === 'edit') baseItemData.index = scheduleItem.index
|
|
160
165
|
|
|
161
166
|
if (props.isMixRGBWLamp) {
|
|
@@ -263,14 +268,27 @@ const SleepWakeUpDetailPage = () => {
|
|
|
263
268
|
}
|
|
264
269
|
}
|
|
265
270
|
|
|
271
|
+
const showBackDialog = () =>{
|
|
272
|
+
const newItem:any = {
|
|
273
|
+
...getNewItem(),
|
|
274
|
+
index: props.scheduleItem.index,
|
|
275
|
+
enable: props.scheduleItem.enable
|
|
276
|
+
}
|
|
277
|
+
if(!props.isSleep){
|
|
278
|
+
newItem.duration = state.durationStatus && state.duration || 0
|
|
279
|
+
}
|
|
280
|
+
return props.mode === 'edit' && !isEqual(props.scheduleItem, newItem)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
266
285
|
return (
|
|
267
286
|
<Page
|
|
268
287
|
backText={I18n.getLang('add_sleepschedule_one_source_system_back_text')}
|
|
269
|
-
|
|
288
|
+
showBackDialog={showBackDialog()}
|
|
289
|
+
backDialogTitle={I18n.getLang('cancel_dialog_leave_unsaved_titel')}
|
|
290
|
+
backDialogContent={I18n.getLang(props.isSleep ? 'cancel_dialog_leave_unsaved_sleepschedule_note' : 'cancel_dialog_leave_unsaved_wakeupschedule_note')}
|
|
270
291
|
rightButtonIcon={showSubmit() ? res.ic_check : res.ic_uncheck}
|
|
271
|
-
onBackClick={() => {
|
|
272
|
-
navigation.goBack()
|
|
273
|
-
}}
|
|
274
292
|
rightButtonIconClick={showSubmit() && postActions || undefined}
|
|
275
293
|
>
|
|
276
294
|
<ScrollView
|
|
@@ -16,7 +16,7 @@ import { useDeviceId } from '@ledvance/base/src/models/modules/NativePropsSlice'
|
|
|
16
16
|
import res from '@ledvance/base/src/res'
|
|
17
17
|
import { useReactive } from 'ahooks'
|
|
18
18
|
import { dpItem, TimeSchedulePageRouteParams } from './TimeSchedulePage'
|
|
19
|
-
import { cloneDeep, differenceBy } from 'lodash'
|
|
19
|
+
import { cloneDeep, differenceBy, isEqual } from 'lodash'
|
|
20
20
|
import DeviceState from './DeviceState'
|
|
21
21
|
import { getHexByHSV, getHSVByHex } from '@ledvance/base/src/utils'
|
|
22
22
|
import { Buffer } from 'buffer'
|
|
@@ -428,20 +428,27 @@ const TimeScheduleEditPage = () => {
|
|
|
428
428
|
return dps.length > 1 && !props.isMixRGBWLamp
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
-
// console.log(scheduleItem, '< --- scheduleItem')
|
|
432
431
|
return (
|
|
433
432
|
<Page
|
|
434
433
|
backText={I18n.getLang('motion_detection_add_time_schedule_system_back_text')}
|
|
435
434
|
onBackClick={navigation.goBack}
|
|
436
435
|
rightButtonIcon={saveEnable() ? res.ic_check : res.ic_uncheck}
|
|
437
436
|
rightButtonIconClick={() => saveAction()}
|
|
438
|
-
rightButtonDisabled={
|
|
439
|
-
|
|
437
|
+
rightButtonDisabled={
|
|
438
|
+
state.loading ||
|
|
439
|
+
(scheduleItem?.aliasName === state.name &&
|
|
440
|
+
JSON.stringify(scheduleItem?.time) === JSON.stringify([state.hour, state.minute].join(':')) &&
|
|
441
|
+
JSON.stringify(scheduleItem?.loops) === JSON.stringify(state.loop.join('')) &&
|
|
442
|
+
scheduleItem?.isAppPush === state.isNotification &&
|
|
443
|
+
isEqual(scheduleItem?.dps, getSendDps()))
|
|
444
|
+
}
|
|
445
|
+
showBackDialog={true}
|
|
446
|
+
backDialogTitle={I18n.getLang('cancel_dialog_leave_unsaved_titel')}
|
|
447
|
+
backDialogContent={I18n.getLang('cancel_dialog_leave_unsaved_timeschedule_note')}>
|
|
440
448
|
<ScrollView
|
|
441
449
|
nestedScrollEnabled={true}
|
|
442
450
|
showsHorizontalScrollIndicator={false}
|
|
443
|
-
showsVerticalScrollIndicator={false}
|
|
444
|
-
>
|
|
451
|
+
showsVerticalScrollIndicator={false}>
|
|
445
452
|
<LdvTopName
|
|
446
453
|
title={I18n.getLang(props.mode === 'add' ? 'motion_detection_add_time_schedule_headline_text' : 'edit_timeschedule_headline_text')}/>
|
|
447
454
|
<View style={styles.content}>
|
|
@@ -85,7 +85,7 @@ const TimerPage = () => {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const onStartPress = () => {
|
|
88
|
+
const onStartPress = async () => {
|
|
89
89
|
let mCountdown = 0
|
|
90
90
|
const hour = parseInt(state.hour)
|
|
91
91
|
const minute = parseInt(state.minute)
|
|
@@ -100,12 +100,11 @@ const TimerPage = () => {
|
|
|
100
100
|
.add(Number(minute), 'm')
|
|
101
101
|
.format('YYYY-MM-DD HH:mm:ss');
|
|
102
102
|
if (!state.selectedSkill.length || mCountdown === 0) return
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
103
|
+
for(let skill of state.selectedSkill){
|
|
104
|
+
const timer = countdowns.find(timer => timer.dpId === skill.dpId)
|
|
105
|
+
await getProgressByDp(skill.dpId)[1](mCountdown, time)
|
|
106
|
+
await timer?.countdown[1](mCountdown)
|
|
107
|
+
}
|
|
109
108
|
state.selectedSkill = []
|
|
110
109
|
}
|
|
111
110
|
|
|
@@ -161,9 +160,9 @@ const TimerPage = () => {
|
|
|
161
160
|
);
|
|
162
161
|
};
|
|
163
162
|
|
|
164
|
-
console.log(progress, '< --- progress')
|
|
165
|
-
console.log(countdowns, 'countdowns')
|
|
166
|
-
console.log(runningTimer(), '< --- runningTimer')
|
|
163
|
+
// console.log(progress, '< --- progress')
|
|
164
|
+
// console.log(countdowns, 'countdowns')
|
|
165
|
+
// console.log(runningTimer(), '< --- runningTimer')
|
|
167
166
|
return (
|
|
168
167
|
<Page
|
|
169
168
|
backText={devInfo.name}
|
|
@@ -6,86 +6,102 @@ import dayjs from "dayjs"
|
|
|
6
6
|
import { NativeApi } from "@ledvance/base/src/api/native"
|
|
7
7
|
import { useEffect, useState } from "react"
|
|
8
8
|
|
|
9
|
-
export const useCountdowns= (dps: dpItem[]) =>{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})
|
|
9
|
+
export const useCountdowns = (dps: dpItem[]) => {
|
|
10
|
+
return dps.map(dp => {
|
|
11
|
+
return ({
|
|
12
|
+
countdown: useDp<number, (value: number) => Promise<Result<any>>>(dp.dpId),
|
|
13
|
+
enable: useDp<boolean, (value: boolean) => Promise<Result<any>>>(dp.enableDp),
|
|
14
|
+
...dp
|
|
16
15
|
})
|
|
16
|
+
})
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
const useFormateProgress
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const useFormateProgress: (dp: dpItem, func: Function) => [number, (time: number, t: any) => Promise<any>] = (dp, cancelTimer) => {
|
|
21
|
+
const [progress, setProgress] = useCountDownAHook({
|
|
22
|
+
interval: 1000,
|
|
23
|
+
onEnd: () => cancelTimer(dp.dpId),
|
|
24
|
+
})
|
|
25
|
+
const [countdown] = useDp<number, (value: number) => Promise<Result<any>>>(dp.dpId)
|
|
26
|
+
const devId = useDeviceId()
|
|
27
|
+
const [cloudProgressNumber, setCloudProgressNumber] = useState(0)
|
|
28
|
+
const [progressNumber, setProgressNumber] = useState(0)
|
|
29
|
+
const [cloudData, setCloudData] = useState<any>()
|
|
30
|
+
const getCloudJson = () => {
|
|
31
|
+
NativeApi.getJson(devId, dp.cloudKey).then(res => {
|
|
32
|
+
NativeApi.log(`${JSON.stringify(res)} < --- cloud Json`)
|
|
33
|
+
console.log(res, '< -- cloud Json')
|
|
34
|
+
if (res.success && res.data) {
|
|
35
|
+
const result = JSON.parse(res.data)
|
|
36
|
+
setCloudData(result)
|
|
37
|
+
setCloudProgressNumber(result.progressAllNumber)
|
|
38
|
+
if (countdown > 0) setProgress(Date.now() + countdown * 1000)
|
|
39
|
+
}
|
|
24
40
|
})
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const [cloudData, setCloudData] = useState<any>()
|
|
30
|
-
const getCloudJson = () =>{
|
|
31
|
-
NativeApi.getJson(devId, dp.cloudKey).then(res =>{
|
|
32
|
-
if(res.success && res.data){
|
|
33
|
-
const result = JSON.parse(res.data)
|
|
34
|
-
setCloudData(result)
|
|
35
|
-
setCloudProgressNumber(result.progressAllNumber)
|
|
36
|
-
if(countdown > 0) setProgress(Date.now() + countdown * 1000)
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
useEffect(() =>{
|
|
41
|
-
getCloudJson()
|
|
42
|
-
}, [])
|
|
41
|
+
}
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
getCloudJson()
|
|
44
|
+
}, [])
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
useUpdateEffect(() =>{
|
|
55
|
-
if(countdown === 0 && cloudData){
|
|
56
|
-
setProgress(0)
|
|
57
|
-
setProgressNumber(0)
|
|
58
|
-
setCloudData('')
|
|
59
|
-
NativeApi.putJson(devId, dp.cloudKey, JSON.stringify({ [getKey('Status', dp.dpId)]: false, [getKey('StartTime', dp.dpId)]: '', progressAllNumber: 0 }))
|
|
60
|
-
}
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (cloudProgressNumber > 0) {
|
|
48
|
+
const currentTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
49
|
+
const remainingTime = Number(cloudData && dayjs(cloudData[getKey('StartTime', dp.dpId)] || 0).diff(currentTime))
|
|
50
|
+
const time = (cloudData && cloudData[getKey('Status', dp.dpId)] && remainingTime >= -1000) ? remainingTime : Number(progress.toString().slice(0, -3) + "000")
|
|
51
|
+
const conversion = (time / 1000) / cloudProgressNumber * 100
|
|
52
|
+
setProgressNumber(!isNaN(conversion) ? conversion : 0)
|
|
53
|
+
}
|
|
54
|
+
}, [progress])
|
|
61
55
|
|
|
62
|
-
if(countdown === 0 && !cloudData){
|
|
63
|
-
setProgress(0)
|
|
64
|
-
setProgressNumber(0)
|
|
65
|
-
}
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
useUpdateEffect(() => {
|
|
58
|
+
if (countdown === 0 && cloudData) {
|
|
59
|
+
setProgress(0)
|
|
60
|
+
setProgressNumber(0)
|
|
61
|
+
setCloudProgressNumber(0)
|
|
62
|
+
setCloudData('')
|
|
63
|
+
if(cloudData.progressAllNumber === 0){
|
|
64
|
+
NativeApi.putJson(devId, dp.cloudKey, JSON.stringify({ [getKey('Status', dp.dpId)]: false, [getKey('StartTime', dp.dpId)]: '', progressAllNumber: 0 })).then(res => {
|
|
65
|
+
NativeApi.log(`${JSON.stringify(res)}, off time`)
|
|
66
|
+
console.log(res, 'off timer')
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
}
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
if (countdown === 0 && !cloudData) {
|
|
72
|
+
setProgress(0)
|
|
73
|
+
setProgressNumber(0)
|
|
74
|
+
setCloudProgressNumber(0)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
setProgress(Date.now() + time * 1000)
|
|
80
|
-
NativeApi.putJson(devId, dp.cloudKey, JSON.stringify({ [getKey('Status', dp.dpId)]: true, [getKey('StartTime', dp.dpId)]: t, progressAllNumber: time }));
|
|
77
|
+
if (countdown > 0 && !cloudData) {
|
|
78
|
+
getCloudJson()
|
|
81
79
|
}
|
|
80
|
+
NativeApi.log(`${countdown}, < --- countdown`)
|
|
81
|
+
}, [countdown, cloudData])
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
const getKey = (suffix: string, dpId: string) => {
|
|
85
|
+
const key = dpId + suffix
|
|
86
|
+
return key
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const startTimer = async (time: number, t) => {
|
|
90
|
+
const res = await NativeApi.putJson(devId, dp.cloudKey, JSON.stringify({ [getKey('Status', dp.dpId)]: true, [getKey('StartTime', dp.dpId)]: t, progressAllNumber: time }))
|
|
91
|
+
NativeApi.log(`${JSON.stringify(res)}, on timer`)
|
|
92
|
+
console.log(res, '< -- on timer')
|
|
82
93
|
|
|
83
|
-
|
|
94
|
+
setCloudProgressNumber(time)
|
|
95
|
+
setProgress(Date.now() + time * 1000)
|
|
96
|
+
}
|
|
97
|
+
NativeApi.log(`${progressNumber}< --- progressNumber`)
|
|
98
|
+
console.log(progressNumber, '< --- progressNumber')
|
|
99
|
+
return [progressNumber, startTimer]
|
|
84
100
|
}
|
|
85
101
|
|
|
86
|
-
export const useProgress = (dps: dpItem[], cancelTimer) =>{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
export const useProgress = (dps: dpItem[], cancelTimer) => {
|
|
103
|
+
return dps.map(dp => ({
|
|
104
|
+
progressHook: useFormateProgress(dp, cancelTimer),
|
|
105
|
+
...dp
|
|
106
|
+
}))
|
|
91
107
|
}
|