@ledvance/ui-biz-bundle 1.1.56 → 1.1.58
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 +2 -1
- package/src/modules/biorhythm/Router.ts +34 -0
- package/src/modules/fixedTime/Router.ts +26 -0
- package/src/modules/flags/FlagInfo.tsx +25 -25
- package/src/modules/flags/FlagPage.tsx +1 -1
- package/src/modules/flags/Router.ts +25 -0
- package/src/modules/history/Router.ts +16 -0
- package/src/modules/mood/FantasyRouter.ts +35 -0
- package/src/modules/mood/MixMood/Router.ts +44 -0
- package/src/modules/mood/Router.ts +53 -0
- package/src/modules/music/Router.ts +16 -0
- package/src/modules/powerOnBehavior/Router.ts +16 -0
- package/src/modules/randomTime/Router.ts +25 -0
- package/src/modules/sleepWakeup/Router.ts +25 -0
- package/src/modules/timeSchedule/Router.ts +25 -0
- package/src/modules/timer/Router.ts +16 -0
- package/src/navigation/Routers.d.ts +0 -7
- package/src/navigation/Routers.ts +15 -304
- package/src/newModules/childLock/ChildLockPage.tsx +97 -0
- package/src/newModules/childLock/Router.ts +16 -0
- package/src/newModules/energyConsumption/EnergyConsumptionActions.ts +23 -0
- package/src/newModules/energyConsumption/EnergyConsumptionChart.tsx +84 -0
- package/src/newModules/energyConsumption/EnergyConsumptionDetail.tsx +321 -0
- package/src/newModules/energyConsumption/EnergyConsumptionPage.tsx +392 -0
- package/src/newModules/energyConsumption/Router.ts +34 -0
- package/src/newModules/energyConsumption/co2Data.ts +23655 -0
- package/src/newModules/energyConsumption/component/BarChart.tsx +93 -0
- package/src/newModules/energyConsumption/component/EnergyModal.tsx +282 -0
- package/src/newModules/energyConsumption/component/Overview.tsx +116 -0
- package/src/newModules/fixedTime/FixedTimeActions.ts +234 -0
- package/src/newModules/fixedTime/FixedTimeDetailPage.tsx +341 -0
- package/src/newModules/fixedTime/FixedTimePage.tsx +231 -0
- package/src/newModules/fixedTime/Router.ts +25 -0
- package/src/newModules/lightMode/LightModePage.tsx +204 -0
- package/src/newModules/lightMode/Router.ts +16 -0
- package/src/newModules/mood/AddMoodPage.tsx +178 -0
- package/src/newModules/mood/DynamicMoodEditorPage.tsx +653 -0
- package/src/newModules/mood/Interface.ts +219 -0
- package/src/newModules/mood/MixDynamicMoodEditor.tsx +781 -0
- package/src/newModules/mood/MoodActions.ts +235 -0
- package/src/newModules/mood/MoodInfo.ts +2151 -0
- package/src/newModules/mood/MoodItem.tsx +148 -0
- package/src/newModules/mood/MoodPage.tsx +385 -0
- package/src/newModules/mood/MoodParse.ts +442 -0
- package/src/newModules/mood/RecommendMoodItem.tsx +68 -0
- package/src/newModules/mood/Router.ts +53 -0
- package/src/newModules/mood/StaticMoodEditorPage.tsx +343 -0
- package/src/newModules/mood/tools.ts +12 -0
- package/src/newModules/overchargeSwitch/OverchargeSwitchPage.tsx +96 -0
- package/src/newModules/overchargeSwitch/Router.ts +16 -0
- package/src/newModules/powerOnBehavior/LightBehaviorPage.tsx +266 -0
- package/src/newModules/powerOnBehavior/PlugBehaviorPage.tsx +173 -0
- package/src/newModules/powerOnBehavior/PowerOnBehaviorActions.ts +106 -0
- package/src/newModules/powerOnBehavior/Router.ts +16 -0
- package/src/newModules/randomTime/RandomTimeActions.ts +232 -0
- package/src/newModules/randomTime/RandomTimeDetailPage.tsx +322 -0
- package/src/newModules/randomTime/RandomTimePage.tsx +230 -0
- package/src/newModules/randomTime/Router.ts +25 -0
- package/src/newModules/randomTime/Summary.tsx +116 -0
- package/src/newModules/swithInching/Router.ts +16 -0
- package/src/newModules/swithInching/SwithInching.tsx +231 -0
- package/src/newModules/swithInching/SwithInchingAction.ts +55 -0
- package/src/newModules/swithInching/pickerView.tsx +91 -0
- package/src/newModules/timeSchedule/Interface.ts +111 -0
- package/src/newModules/timeSchedule/Router.ts +25 -0
- package/src/newModules/timeSchedule/TimeScheduleActions.ts +53 -0
- package/src/newModules/timeSchedule/TimeScheduleDetailPage.tsx +662 -0
- package/src/newModules/timeSchedule/TimeSchedulePage.tsx +222 -0
- package/src/newModules/timeSchedule/components/ManuaSettings.tsx +259 -0
- package/src/newModules/timeSchedule/components/ScheduleCard.tsx +109 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import React, { useCallback } from 'react'
|
|
2
|
+
import { FlatList, Image, ScrollView, StyleSheet, Text, View } from 'react-native'
|
|
3
|
+
import Page from '@ledvance/base/src/components/Page'
|
|
4
|
+
import { useDeviceInfo, useSystemTimeFormate } from '@ledvance/base/src/models/modules/NativePropsSlice'
|
|
5
|
+
import { useNavigation, useRoute } from '@react-navigation/core'
|
|
6
|
+
import I18n from '@ledvance/base/src/i18n'
|
|
7
|
+
import res from '@ledvance/base/src/res'
|
|
8
|
+
import { ui_biz_routerKey } from '../../navigation/Routers'
|
|
9
|
+
import { useReactive, useUpdateEffect } from 'ahooks'
|
|
10
|
+
import Spacer from '@ledvance/base/src/components/Spacer'
|
|
11
|
+
import TextButton from '@ledvance/base/src/components/TextButton'
|
|
12
|
+
import { SwitchButton, Utils } from 'tuya-panel-kit'
|
|
13
|
+
import { RandomTimerUiItem, useRandomTime } from './RandomTimeActions'
|
|
14
|
+
import Card from '@ledvance/base/src/components/Card'
|
|
15
|
+
import { convertMinutesTo12HourFormat, loopText } from '@ledvance/base/src/utils/common'
|
|
16
|
+
import { cloneDeep } from 'lodash'
|
|
17
|
+
import dayjs from 'dayjs'
|
|
18
|
+
|
|
19
|
+
const { convertX: cx } = Utils.RatioUtils
|
|
20
|
+
const { parseTimer } = Utils.TimeUtils
|
|
21
|
+
const MAX_NUM = 10
|
|
22
|
+
|
|
23
|
+
export interface RandomTimePageParams {
|
|
24
|
+
randomTimeDpCode: string
|
|
25
|
+
conflictDps: {
|
|
26
|
+
fixedTimeDp?: string
|
|
27
|
+
biorhythmDp?: string
|
|
28
|
+
sleepWakeUpDp?: string
|
|
29
|
+
}
|
|
30
|
+
isPlug?: boolean
|
|
31
|
+
showTags?: boolean
|
|
32
|
+
applyDps: {
|
|
33
|
+
label: string
|
|
34
|
+
value: string
|
|
35
|
+
}[]
|
|
36
|
+
isSupportColor: boolean
|
|
37
|
+
isSupportTemperature: boolean
|
|
38
|
+
isSupportBrightness: boolean
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const RandomTimePage = () => {
|
|
42
|
+
const navigation = useNavigation()
|
|
43
|
+
const devInfo = useDeviceInfo()
|
|
44
|
+
const params = useRoute().params as RandomTimePageParams
|
|
45
|
+
const is24Hour = useSystemTimeFormate()
|
|
46
|
+
const [randomTime, setRandomTime] = useRandomTime(params.randomTimeDpCode, params.isPlug)
|
|
47
|
+
const state = useReactive({
|
|
48
|
+
loading: false,
|
|
49
|
+
randomTimeList: cloneDeep(randomTime),
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
useUpdateEffect(() => {
|
|
53
|
+
state.randomTimeList = cloneDeep(randomTime)
|
|
54
|
+
}, [randomTime])
|
|
55
|
+
|
|
56
|
+
const navigateToEdit = useCallback((mode: 'add' | 'edit', scheduleItem?: RandomTimerUiItem) => {
|
|
57
|
+
navigation.navigate(ui_biz_routerKey.ui_biz_random_time_edit_new, {
|
|
58
|
+
...params,
|
|
59
|
+
mode,
|
|
60
|
+
scheduleItem: cloneDeep(scheduleItem),
|
|
61
|
+
onPost,
|
|
62
|
+
})
|
|
63
|
+
}, [])
|
|
64
|
+
|
|
65
|
+
const showMaxNumTip = useCallback(() => {
|
|
66
|
+
return state.randomTimeList.length >= MAX_NUM
|
|
67
|
+
}, [state.randomTimeList.length])
|
|
68
|
+
|
|
69
|
+
const onPost = useCallback(async (mode: 'add' | 'edit' | 'del', randomTime: RandomTimerUiItem) => {
|
|
70
|
+
const cloneRandomTime = cloneDeep(state.randomTimeList)
|
|
71
|
+
const idx = state.randomTimeList.findIndex(f => f.index === randomTime.index)
|
|
72
|
+
if (mode === 'edit') {
|
|
73
|
+
cloneRandomTime.splice(idx, 1, randomTime)
|
|
74
|
+
}
|
|
75
|
+
if (mode === 'del') cloneRandomTime.splice(idx, 1)
|
|
76
|
+
const newRandomTimeList = mode === 'add' ? [...state.randomTimeList, randomTime] : cloneRandomTime
|
|
77
|
+
return setRandomTime(newRandomTimeList)
|
|
78
|
+
}, [state.randomTimeList])
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Page
|
|
82
|
+
backText={devInfo.name}
|
|
83
|
+
headlineText={I18n.getLang('randomtimecycle_sockets_headline_text')}
|
|
84
|
+
headlineIcon={!showMaxNumTip() ? res.device_panel_schedule_add : undefined}
|
|
85
|
+
onBackClick={navigation.goBack}
|
|
86
|
+
loading={state.loading}
|
|
87
|
+
onHeadlineIconClick={() => {
|
|
88
|
+
navigateToEdit('add', newRandomTime())
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
{state.randomTimeList.length > 0 ?
|
|
92
|
+
<ScrollView nestedScrollEnabled={true}>
|
|
93
|
+
<Text style={{
|
|
94
|
+
color: '#000',
|
|
95
|
+
marginLeft: cx(24),
|
|
96
|
+
}}>{I18n.getLang('timeschedule_overview_description_text')}</Text>
|
|
97
|
+
<Spacer height={cx(10)} />
|
|
98
|
+
{showMaxNumTip() && <View style={{ marginHorizontal: cx(24), flexDirection: 'row' }}>
|
|
99
|
+
<Image style={{ width: cx(16), height: cx(16), tintColor: '#ff9500' }} source={res.ic_warning_amber} />
|
|
100
|
+
<Text>{I18n.getLang('randomtimecycle_warning_max_number_text')}</Text>
|
|
101
|
+
</View>}
|
|
102
|
+
<FlatList
|
|
103
|
+
data={state.randomTimeList}
|
|
104
|
+
renderItem={({ item }) => (
|
|
105
|
+
<RandomTimeCard
|
|
106
|
+
is24Hour={is24Hour}
|
|
107
|
+
randomTime={item}
|
|
108
|
+
onSwitch={async (v) => {
|
|
109
|
+
state.loading = true
|
|
110
|
+
await onPost('edit', {
|
|
111
|
+
...item,
|
|
112
|
+
enable: v,
|
|
113
|
+
})
|
|
114
|
+
state.loading = false
|
|
115
|
+
}}
|
|
116
|
+
onPress={() => {
|
|
117
|
+
navigateToEdit('edit', item)
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
keyExtractor={(item: any) => `${item?.index}`}
|
|
122
|
+
ItemSeparatorComponent={() => <Spacer />}
|
|
123
|
+
ListHeaderComponent={<Spacer height={cx(10)} />}
|
|
124
|
+
ListFooterComponent={<Spacer />}
|
|
125
|
+
/>
|
|
126
|
+
</ScrollView> :
|
|
127
|
+
<View style={{ flex: 1, marginTop: cx(60), alignItems: 'center' }}>
|
|
128
|
+
<Image
|
|
129
|
+
style={{ width: cx(225), height: cx(198) }}
|
|
130
|
+
source={{ uri: res.ldv_timer_empty }}
|
|
131
|
+
resizeMode="contain" />
|
|
132
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
133
|
+
<Image
|
|
134
|
+
source={{ uri: res.device_panel_schedule_alert }}
|
|
135
|
+
style={{ width: cx(16), height: cx(16) }}
|
|
136
|
+
/>
|
|
137
|
+
<Text style={{ color: '#000', fontSize: cx(12) }}>
|
|
138
|
+
{I18n.getLang('randomtimecycle_empty_information_text')}
|
|
139
|
+
</Text>
|
|
140
|
+
</View>
|
|
141
|
+
<Spacer />
|
|
142
|
+
<TextButton
|
|
143
|
+
text={I18n.getLang('randomtimecycle_empty_bttn_text')}
|
|
144
|
+
style={{
|
|
145
|
+
backgroundColor: '#f60',
|
|
146
|
+
borderRadius: cx(6),
|
|
147
|
+
paddingVertical: cx(12),
|
|
148
|
+
paddingHorizontal: cx(24),
|
|
149
|
+
}}
|
|
150
|
+
textStyle={{ color: '#fff' }}
|
|
151
|
+
onPress={() => {
|
|
152
|
+
navigateToEdit('add', newRandomTime())
|
|
153
|
+
}} />
|
|
154
|
+
</View>
|
|
155
|
+
}
|
|
156
|
+
</Page>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const RandomTimeCard = (props: {
|
|
161
|
+
is24Hour: boolean
|
|
162
|
+
randomTime: RandomTimerUiItem,
|
|
163
|
+
onSwitch: (enable: boolean) => void,
|
|
164
|
+
onPress: () => void
|
|
165
|
+
}) => {
|
|
166
|
+
const { is24Hour, randomTime, onSwitch, onPress } = props
|
|
167
|
+
return (
|
|
168
|
+
<Card style={styles.randomTimingCard} onPress={onPress}>
|
|
169
|
+
<Spacer height={cx(16)} />
|
|
170
|
+
<View style={styles.switchLine}>
|
|
171
|
+
<Text style={styles.time}>
|
|
172
|
+
{`${convertMinutesTo12HourFormat(randomTime.startTime, is24Hour)} - ${convertMinutesTo12HourFormat(randomTime.endTime, is24Hour)}`}</Text>
|
|
173
|
+
<SwitchButton
|
|
174
|
+
style={styles.switchBtn}
|
|
175
|
+
value={randomTime.enable}
|
|
176
|
+
thumbStyle={{ elevation: 0 }}
|
|
177
|
+
onValueChange={onSwitch} />
|
|
178
|
+
</View>
|
|
179
|
+
<Text style={styles.loopText}>{loopText(randomTime.weeks, parseTimer(randomTime.startTime * 60))}</Text>
|
|
180
|
+
<Spacer height={cx(5)} />
|
|
181
|
+
<Text style={styles.loopText}>{randomTime.name}</Text>
|
|
182
|
+
<Spacer />
|
|
183
|
+
</Card>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const newRandomTime = () => {
|
|
188
|
+
const startTime = dayjs().hour() * 60 + dayjs().minute()
|
|
189
|
+
return {
|
|
190
|
+
name: '',
|
|
191
|
+
enable: true,
|
|
192
|
+
weeks: [0, 0, 0, 0, 0, 0, 0],
|
|
193
|
+
startTime: startTime,
|
|
194
|
+
endTime: startTime + 60,
|
|
195
|
+
channel: 1,
|
|
196
|
+
color: {
|
|
197
|
+
h: 0,
|
|
198
|
+
s: 100,
|
|
199
|
+
v: 100,
|
|
200
|
+
brightness: 100,
|
|
201
|
+
temperature: 0,
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const styles = StyleSheet.create({
|
|
207
|
+
randomTimingCard: {
|
|
208
|
+
marginHorizontal: cx(24),
|
|
209
|
+
paddingHorizontal: cx(16),
|
|
210
|
+
},
|
|
211
|
+
switchLine: {
|
|
212
|
+
flexDirection: 'row',
|
|
213
|
+
alignItems: 'center',
|
|
214
|
+
},
|
|
215
|
+
time: {
|
|
216
|
+
flex: 1,
|
|
217
|
+
color: '#000',
|
|
218
|
+
fontSize: cx(16),
|
|
219
|
+
fontWeight: 'bold',
|
|
220
|
+
fontFamily: 'helvetica_neue_lt_std_bd',
|
|
221
|
+
},
|
|
222
|
+
switchBtn: {},
|
|
223
|
+
loopText: {
|
|
224
|
+
color: '#000',
|
|
225
|
+
fontSize: cx(14),
|
|
226
|
+
fontFamily: 'helvetica_neue_lt_std_roman',
|
|
227
|
+
},
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
export default RandomTimePage
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {NavigationRoute} from "tuya-panel-kit";
|
|
2
|
+
import NewRandomTimePage from "./RandomTimePage";
|
|
3
|
+
import NewRandomTimeDetailPage from "./RandomTimeDetailPage";
|
|
4
|
+
import {ui_biz_routerKey} from "../../navigation/Routers";
|
|
5
|
+
|
|
6
|
+
const NewRandomTimePageRouters: NavigationRoute[] = [
|
|
7
|
+
{
|
|
8
|
+
name: ui_biz_routerKey.ui_biz_random_time_new,
|
|
9
|
+
component: NewRandomTimePage,
|
|
10
|
+
options: {
|
|
11
|
+
hideTopbar: true,
|
|
12
|
+
showOfflineView: false,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: ui_biz_routerKey.ui_biz_random_time_edit_new,
|
|
17
|
+
component: NewRandomTimeDetailPage,
|
|
18
|
+
options: {
|
|
19
|
+
hideTopbar: true,
|
|
20
|
+
showOfflineView: false,
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
export default NewRandomTimePageRouters
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React, { ReactElement, memo } from "react";
|
|
2
|
+
import { Text, ViewStyle, View, StyleSheet } from 'react-native'
|
|
3
|
+
import res from "@ledvance/base/src/res"
|
|
4
|
+
import I18n from "@ledvance/base/src/i18n";
|
|
5
|
+
import { Utils } from "tuya-panel-kit";
|
|
6
|
+
import Spacer from "@ledvance/base/src/components/Spacer";
|
|
7
|
+
import InfoText from "@ledvance/base/src/components/InfoText";
|
|
8
|
+
|
|
9
|
+
const { convertX: cx } = Utils.RatioUtils;
|
|
10
|
+
|
|
11
|
+
interface SummaryProps {
|
|
12
|
+
style?: ViewStyle
|
|
13
|
+
frequency?: string | ReactElement
|
|
14
|
+
time?: string | ReactElement
|
|
15
|
+
actions?: ReactElement
|
|
16
|
+
hideActions?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const Summary = (props: SummaryProps) => {
|
|
20
|
+
return (
|
|
21
|
+
<View style={styles.cardContainer}>
|
|
22
|
+
<Text style={styles.itemTitle}>{I18n.getLang('add_randomtimecycle_subheadline_text')}</Text>
|
|
23
|
+
<Spacer height={cx(10)} />
|
|
24
|
+
<View style={{}}>
|
|
25
|
+
<View style={styles.summaryContainer}>
|
|
26
|
+
<InfoText
|
|
27
|
+
icon={res.summary_icon1}
|
|
28
|
+
text={I18n.getLang('feature_summary_frequency_headline')}
|
|
29
|
+
iconStyle={styles.summaryImg}
|
|
30
|
+
textStyle={styles.leftTitle}
|
|
31
|
+
style={styles.summaryLeft}
|
|
32
|
+
/>
|
|
33
|
+
<View style={styles.summaryRight}>
|
|
34
|
+
<View style={styles.rightWrap}>
|
|
35
|
+
<Text style={styles.rightItem}>{props.frequency}</Text>
|
|
36
|
+
</View>
|
|
37
|
+
</View>
|
|
38
|
+
</View>
|
|
39
|
+
<View style={styles.summaryContainer}>
|
|
40
|
+
<InfoText
|
|
41
|
+
icon={res.summary_icon2}
|
|
42
|
+
text={I18n.getLang('feature_summary_time_headline')}
|
|
43
|
+
iconStyle={styles.summaryImg}
|
|
44
|
+
textStyle={styles.leftTitle}
|
|
45
|
+
style={styles.summaryLeft}
|
|
46
|
+
/>
|
|
47
|
+
<View style={styles.summaryRight}>
|
|
48
|
+
<View style={styles.rightWrap}>
|
|
49
|
+
<Text style={styles.rightItem}>{props.time}</Text>
|
|
50
|
+
</View>
|
|
51
|
+
</View>
|
|
52
|
+
</View>
|
|
53
|
+
{!props.hideActions && <View style={[styles.summaryContainer, { alignItems: 'flex-start' }]}>
|
|
54
|
+
<InfoText
|
|
55
|
+
icon={res.summary_icon3}
|
|
56
|
+
text={I18n.getLang('motion_detection_add_time_schedule_actions_text1')}
|
|
57
|
+
iconStyle={styles.summaryImg}
|
|
58
|
+
textStyle={styles.leftTitle}
|
|
59
|
+
style={styles.summaryLeft}
|
|
60
|
+
/>
|
|
61
|
+
<View style={styles.summaryRight}>
|
|
62
|
+
{props.actions}
|
|
63
|
+
</View>
|
|
64
|
+
</View>}
|
|
65
|
+
</View>
|
|
66
|
+
</View>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const styles = StyleSheet.create({
|
|
71
|
+
cardContainer: {
|
|
72
|
+
marginHorizontal: cx(24),
|
|
73
|
+
},
|
|
74
|
+
itemTitle: {
|
|
75
|
+
color: '#000',
|
|
76
|
+
fontSize: cx(16),
|
|
77
|
+
fontWeight: 'bold',
|
|
78
|
+
fontFamily: 'helvetica_neue_lt_std_bd',
|
|
79
|
+
},
|
|
80
|
+
summaryContainer: {
|
|
81
|
+
flex: 1,
|
|
82
|
+
flexDirection: 'row',
|
|
83
|
+
marginBottom: cx(10),
|
|
84
|
+
},
|
|
85
|
+
summaryLeft: {
|
|
86
|
+
flexDirection: 'row',
|
|
87
|
+
alignItems: 'center',
|
|
88
|
+
minWidth: cx(100)
|
|
89
|
+
},
|
|
90
|
+
summaryImg: {
|
|
91
|
+
width: cx(12),
|
|
92
|
+
height: cx(12),
|
|
93
|
+
marginRight: cx(6)
|
|
94
|
+
},
|
|
95
|
+
leftTitle: {
|
|
96
|
+
fontSize: cx(14),
|
|
97
|
+
color: '#000'
|
|
98
|
+
},
|
|
99
|
+
summaryRight: {
|
|
100
|
+
flex: 1,
|
|
101
|
+
flexDirection: 'column',
|
|
102
|
+
marginLeft: cx(15),
|
|
103
|
+
marginTop: cx(5)
|
|
104
|
+
},
|
|
105
|
+
rightWrap: {
|
|
106
|
+
borderRadius: cx(16),
|
|
107
|
+
paddingHorizontal: cx(12),
|
|
108
|
+
alignSelf: 'flex-start',
|
|
109
|
+
backgroundColor: '#cbcbcb',
|
|
110
|
+
},
|
|
111
|
+
rightItem: {
|
|
112
|
+
color: '#000',
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
export default memo(Summary)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {NavigationRoute} from "tuya-panel-kit";
|
|
2
|
+
import SwitchInching from "./SwithInching";
|
|
3
|
+
import {ui_biz_routerKey} from "../../navigation/Routers";
|
|
4
|
+
|
|
5
|
+
const SwitchInchingPageRouters: NavigationRoute[] = [
|
|
6
|
+
{
|
|
7
|
+
name: ui_biz_routerKey.ui_biz_switch_inching,
|
|
8
|
+
component: SwitchInching,
|
|
9
|
+
options:{
|
|
10
|
+
hideTopbar: true,
|
|
11
|
+
showOfflineView: false,
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
export default SwitchInchingPageRouters
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
3
|
+
import Page from "@ledvance/base/src/components/Page";
|
|
4
|
+
import { useDeviceInfo } from "@ledvance/base/src/models/modules/NativePropsSlice";
|
|
5
|
+
import { useNavigation } from '@react-navigation/native'
|
|
6
|
+
import { SwitchButton, Utils, Dialog } from "tuya-panel-kit";
|
|
7
|
+
import LdvPickerView from "./pickerView";
|
|
8
|
+
import I18n from '@ledvance/base/src/i18n'
|
|
9
|
+
import { useReactive, useUpdateEffect } from "ahooks";
|
|
10
|
+
import {SwitchInchingPageParams, useCountdown1, useSwitchInching} from "./SwithInchingAction";
|
|
11
|
+
import {useRandomTime} from "../randomTime/RandomTimeActions";
|
|
12
|
+
import {useFixedTime} from "../fixedTime/FixedTimeActions";
|
|
13
|
+
import {useParams} from "@ledvance/base/src/hooks/Hooks";
|
|
14
|
+
|
|
15
|
+
const { convertX: cx } = Utils.RatioUtils
|
|
16
|
+
|
|
17
|
+
interface SwitchInchingState {
|
|
18
|
+
enable: boolean,
|
|
19
|
+
minute: string,
|
|
20
|
+
second: string,
|
|
21
|
+
flag: Symbol | number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const SwitchInching = () => {
|
|
25
|
+
const params = useParams<SwitchInchingPageParams>()
|
|
26
|
+
const deviceInfo = useDeviceInfo()
|
|
27
|
+
const navigation = useNavigation()
|
|
28
|
+
const [switchInching, setSwitchInching] = useSwitchInching(params.switchInchingCode)
|
|
29
|
+
const [randomTimePlan, setRandomTimePlan] = useRandomTime(params.cycleTimeCode, true)
|
|
30
|
+
const [fixedTimePlan, setFixedTimePlan] = useFixedTime(params.randomTimeCode, true)
|
|
31
|
+
const [countdown1, setCountDown1] = useCountdown1(params.countdownCode)
|
|
32
|
+
const randomEnable = !!randomTimePlan.filter(item => item.enable).length
|
|
33
|
+
const fixedEnable = !!fixedTimePlan.filter(item => item.enable).length
|
|
34
|
+
const timerEnable = !!countdown1
|
|
35
|
+
const state = useReactive<SwitchInchingState>({
|
|
36
|
+
enable: false,
|
|
37
|
+
minute: '00',
|
|
38
|
+
second: '00',
|
|
39
|
+
flag: 1
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
state.enable = switchInching.enable
|
|
44
|
+
state.minute = formateValue('minute')
|
|
45
|
+
state.second = formateValue('second')
|
|
46
|
+
}, [JSON.stringify(switchInching)])
|
|
47
|
+
|
|
48
|
+
const showDialog = (run: () => void) => {
|
|
49
|
+
Dialog.confirm({
|
|
50
|
+
title: I18n.getLang('conflict_dialog_save_item_inching_titel'),
|
|
51
|
+
subTitle: I18n.getLang('conflict_dialog_save_item_inching_description'),
|
|
52
|
+
cancelText: I18n.getLang('conflict_dialog_save_item_inching_answer_no_text'),
|
|
53
|
+
confirmText: I18n.getLang('conflict_dialog_save_item_inching_answer_yes_text'),
|
|
54
|
+
onConfirm: (_, { close }) => {
|
|
55
|
+
close();
|
|
56
|
+
setSwitchInching({ ...switchInching, enable: false })
|
|
57
|
+
TurnOffFn()
|
|
58
|
+
run()
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const TurnOffFn = () => {
|
|
64
|
+
if (randomEnable) {
|
|
65
|
+
const randomTimeList = randomTimePlan.map(item => {
|
|
66
|
+
if (item.enable) {
|
|
67
|
+
return {
|
|
68
|
+
...item,
|
|
69
|
+
enable: false
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
return item
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
setRandomTimePlan(randomTimeList)
|
|
76
|
+
}
|
|
77
|
+
if (fixedEnable) {
|
|
78
|
+
const fixedTimeList = fixedTimePlan.map(item => {
|
|
79
|
+
if (item.enable) {
|
|
80
|
+
return {
|
|
81
|
+
...item,
|
|
82
|
+
enable: false
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
return item
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
setFixedTimePlan(fixedTimeList)
|
|
89
|
+
}
|
|
90
|
+
if (timerEnable) {
|
|
91
|
+
setCountDown1(0)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
const requestSwitchInching = () => {
|
|
97
|
+
const run = () => {
|
|
98
|
+
const enable = state.enable
|
|
99
|
+
const time = Number(state.minute) * 60 + Number(state.second)
|
|
100
|
+
setSwitchInching({ enable, time })
|
|
101
|
+
}
|
|
102
|
+
if (state.enable && (randomEnable || fixedEnable || timerEnable)) {
|
|
103
|
+
return showDialog(run)
|
|
104
|
+
}
|
|
105
|
+
run()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (state.flag !== 1) {
|
|
110
|
+
requestSwitchInching()
|
|
111
|
+
}
|
|
112
|
+
}, [state.flag])
|
|
113
|
+
|
|
114
|
+
useUpdateEffect(() => {
|
|
115
|
+
if (!!!Number(state.minute) && Number(state.second) < 2) {
|
|
116
|
+
state.second = '02'
|
|
117
|
+
}
|
|
118
|
+
if (Number(state.minute) === 60) {
|
|
119
|
+
state.second = '00'
|
|
120
|
+
}
|
|
121
|
+
}, [state.minute, state.second])
|
|
122
|
+
|
|
123
|
+
const formateValue = (type: string) => {
|
|
124
|
+
const m = parseInt(String((switchInching?.time || 0) / 60))
|
|
125
|
+
if (type === 'minute') {
|
|
126
|
+
return m.toString().padStart(2, '0')
|
|
127
|
+
} else {
|
|
128
|
+
const s = switchInching.time - 60 * m
|
|
129
|
+
const v: string = s === 0 ? '00' : s < 10 ? '0' + s : String(s)
|
|
130
|
+
return v
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<Page
|
|
136
|
+
backText={deviceInfo.name}
|
|
137
|
+
onBackClick={navigation.goBack}
|
|
138
|
+
headlineText={I18n.getLang('socket_settings_switch_off_firstbox_text')}
|
|
139
|
+
>
|
|
140
|
+
<View style={styles.switchContainer}>
|
|
141
|
+
<View style={styles.switchCardContainer}>
|
|
142
|
+
<Text style={styles.switchCardTitle}>
|
|
143
|
+
{I18n.getLang('socket_settings_switch_off_firstbox_text')}
|
|
144
|
+
</Text>
|
|
145
|
+
<SwitchButton
|
|
146
|
+
value={switchInching.enable}
|
|
147
|
+
onValueChange={v => {
|
|
148
|
+
state.enable = v;
|
|
149
|
+
state.flag = Symbol();
|
|
150
|
+
}}
|
|
151
|
+
/>
|
|
152
|
+
</View>
|
|
153
|
+
<Text style={styles.switchDescription}>
|
|
154
|
+
{I18n.getLang('switchinching_overview_description_text')}
|
|
155
|
+
</Text>
|
|
156
|
+
</View>
|
|
157
|
+
<Text style={styles.secondTopic}>
|
|
158
|
+
{I18n.getLang('socket_settings_switch_off_secondtopic')}
|
|
159
|
+
</Text>
|
|
160
|
+
<View style={styles.pickContainer}>
|
|
161
|
+
{switchInching.enable && <View style={styles.disabledCover} />}
|
|
162
|
+
<LdvPickerView
|
|
163
|
+
hour={state.minute}
|
|
164
|
+
minute={state.second}
|
|
165
|
+
unit={[
|
|
166
|
+
I18n.getLang('socket_settings_switch_off_min'),
|
|
167
|
+
I18n.getLang('socket_settings_switch_off_s'),
|
|
168
|
+
]}
|
|
169
|
+
setHour={m => {
|
|
170
|
+
state.minute = m;
|
|
171
|
+
}}
|
|
172
|
+
setMinute={s => {
|
|
173
|
+
state.second = s;
|
|
174
|
+
}}
|
|
175
|
+
/>
|
|
176
|
+
</View>
|
|
177
|
+
</Page>
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const styles = StyleSheet.create({
|
|
182
|
+
switchContainer: {
|
|
183
|
+
backgroundColor: '#F6F6F6',
|
|
184
|
+
marginHorizontal: cx(24),
|
|
185
|
+
padding: cx(10),
|
|
186
|
+
borderRadius: cx(6),
|
|
187
|
+
flexDirection: 'column',
|
|
188
|
+
},
|
|
189
|
+
switchCardContainer: {
|
|
190
|
+
paddingVertical: cx(4),
|
|
191
|
+
paddingHorizontal: cx(10),
|
|
192
|
+
backgroundColor: '#FFFFFF',
|
|
193
|
+
flexDirection: 'row',
|
|
194
|
+
justifyContent: 'center',
|
|
195
|
+
alignItems: 'center',
|
|
196
|
+
borderRadius: cx(6),
|
|
197
|
+
},
|
|
198
|
+
switchCardTitle: {
|
|
199
|
+
color: '#000',
|
|
200
|
+
fontSize: cx(14),
|
|
201
|
+
flex: 1,
|
|
202
|
+
fontWeight: '400',
|
|
203
|
+
},
|
|
204
|
+
switchDescription: {
|
|
205
|
+
color: '#000',
|
|
206
|
+
flexWrap: 'wrap',
|
|
207
|
+
fontSize: cx(12),
|
|
208
|
+
marginTop: cx(4),
|
|
209
|
+
},
|
|
210
|
+
secondTopic: {
|
|
211
|
+
color: '#000',
|
|
212
|
+
flexWrap: 'wrap',
|
|
213
|
+
fontSize: cx(14),
|
|
214
|
+
marginTop: cx(30),
|
|
215
|
+
marginHorizontal: cx(24),
|
|
216
|
+
},
|
|
217
|
+
pickContainer: {
|
|
218
|
+
position: 'relative',
|
|
219
|
+
marginVertical: cx(24),
|
|
220
|
+
marginHorizontal: cx(24),
|
|
221
|
+
},
|
|
222
|
+
disabledCover: {
|
|
223
|
+
position: 'absolute',
|
|
224
|
+
width: '100%',
|
|
225
|
+
height: '100%',
|
|
226
|
+
left: 0,
|
|
227
|
+
top: 0,
|
|
228
|
+
zIndex: 999,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
export default SwitchInching;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {Buffer} from 'buffer'
|
|
2
|
+
import {Result} from "@ledvance/base/src/models/modules/Result"
|
|
3
|
+
import {useDp} from "@ledvance/base/src/models/modules/NativePropsSlice";
|
|
4
|
+
|
|
5
|
+
export interface SwitchInchingPageParams {
|
|
6
|
+
switchInchingCode: string
|
|
7
|
+
countdownCode: string
|
|
8
|
+
cycleTimeCode: string
|
|
9
|
+
randomTimeCode: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface SwitchInchingModel {
|
|
13
|
+
enable: boolean,
|
|
14
|
+
time: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function format(number: string, code: number) {
|
|
18
|
+
const l = number.length; //获取要格式化数字的长度,如二进制1的话长度为1
|
|
19
|
+
if (l < code) { //补全位数 0000,这里我要显示4位
|
|
20
|
+
for (let i = 0; i < code - l; i++) {
|
|
21
|
+
number = "0" + number; //不够的就在前面补0
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type SwitchInchingResult = (switchInchingCode: string) => [SwitchInchingModel, (v: SwitchInchingModel) => Promise<Result<any>>]
|
|
28
|
+
|
|
29
|
+
export function useCountdown1(countdownCode: string): [number, (countdown1: number) => Promise<Result<any>>] {
|
|
30
|
+
return useDp(countdownCode);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useSwitchInchingHex(switchInchingCode: string): [string, (switchInching: string) => Promise<Result<any>>] {
|
|
34
|
+
return useDp(switchInchingCode)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const useSwitchInching: SwitchInchingResult = (switchInchingCode: string) => {
|
|
38
|
+
const [hex, setHex] = useSwitchInchingHex(switchInchingCode)
|
|
39
|
+
const inching = Buffer.from(hex, 'base64')
|
|
40
|
+
const enable = !!inching[0]
|
|
41
|
+
const time = inching[1] * 256 + inching[2]
|
|
42
|
+
const setSwitchInching = ({enable, time}) => {
|
|
43
|
+
const enableHex = enable ? '01' : '00'
|
|
44
|
+
const timeHex = format(time?.toString(16), 4)
|
|
45
|
+
const inchingString = enableHex + timeHex
|
|
46
|
+
const inchingHex = hexToBase64(inchingString)
|
|
47
|
+
return setHex(inchingHex)
|
|
48
|
+
}
|
|
49
|
+
return [{enable, time}, setSwitchInching]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const hexToBase64 = (hex: string) => {
|
|
53
|
+
const buffer = Buffer.from(hex, 'hex');
|
|
54
|
+
return buffer.toString('base64');
|
|
55
|
+
}
|