@ledvance/ui-biz-bundle 1.1.61 → 1.1.63

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.
@@ -1,8 +1,8 @@
1
- import React, { memo, useCallback } from "react";
1
+ import React, { memo, useCallback, useMemo } from "react";
2
2
  import { FlatList, Image, ScrollView, StyleSheet, Text, View } from 'react-native'
3
3
  import Page from "@ledvance/base/src/components/Page";
4
4
  import { useDeviceInfo, useSystemTimeFormate } from "@ledvance/base/src/models/modules/NativePropsSlice";
5
- import { useNavigation, useRoute } from '@react-navigation/core'
5
+ import { useNavigation } from '@react-navigation/core'
6
6
  import I18n from "@ledvance/base/src/i18n";
7
7
  import res from "@ledvance/base/src/res";
8
8
  import { ui_biz_routerKey } from "../../navigation/Routers";
@@ -15,6 +15,10 @@ import Card from "@ledvance/base/src/components/Card";
15
15
  import { convertMinutesTo12HourFormat, loopText } from "@ledvance/base/src/utils/common";
16
16
  import { cloneDeep } from "lodash";
17
17
  import dayjs from "dayjs";
18
+ import { ApplyForItem } from "@ledvance/ui-biz-bundle/src/newModules/timeSchedule/Interface";
19
+ import { useParams } from "@ledvance/base/src/hooks/Hooks";
20
+ import Tag from "@ledvance/base/src/components/Tag";
21
+ import InfoText from "@ledvance/base/src/components/InfoText";
18
22
 
19
23
  const { convertX: cx } = Utils.RatioUtils
20
24
  const MAX_NUM = 10
@@ -28,30 +32,37 @@ export interface FixedTimePageParams {
28
32
  }
29
33
  isPlug?: boolean
30
34
  showTags?: boolean
31
- applyDps: {
32
- label: string
33
- value: string
34
- }[]
35
- isSupportColor: boolean
36
- isSupportTemperature: boolean
37
- isSupportBrightness: boolean
35
+ applyForList: ApplyForItem[]
36
+ isSupportColor?: boolean
37
+ isSupportTemperature?: boolean
38
+ isSupportBrightness?: boolean
38
39
  }
39
40
 
40
41
  const FixedTimePage = () => {
41
42
  const navigation = useNavigation()
42
43
  const devInfo = useDeviceInfo()
43
- const params = useRoute().params as FixedTimePageParams
44
+ const params = useParams<FixedTimePageParams>()
44
45
  const is24Hour = useSystemTimeFormate()
45
46
  const [fixedTime, setFixedTime] = useFixedTime(params.fixedTimeDpCode, params.isPlug)
46
47
  const state = useReactive({
47
48
  loading: false,
48
- fixedTimeList: cloneDeep(fixedTime)
49
+ originList: cloneDeep(fixedTime),
50
+ fixedTimeList: cloneDeep(fixedTime),
51
+ checkTags: params.applyForList.map(v => ({ ...v, enable: false }))
49
52
  })
50
53
 
51
54
  useUpdateEffect(() => {
52
- state.fixedTimeList = cloneDeep(fixedTime)
55
+ state.originList = cloneDeep(fixedTime)
53
56
  }, [fixedTime])
54
57
 
58
+ useUpdateEffect(() => {
59
+ const isAll = state.checkTags.every(tag => tag.enable) || state.checkTags.every(tag => !tag.enable)
60
+ const checkedList = state.originList.filter(item => {
61
+ return isAll || state.checkTags[item.channel || 0]?.enable
62
+ })
63
+ state.fixedTimeList = cloneDeep(checkedList)
64
+ }, [JSON.stringify(state.checkTags), JSON.stringify(state.originList)])
65
+
55
66
  const navigateToEdit = useCallback((mode: 'add' | 'edit', scheduleItem: FixedTimerUiItem) => {
56
67
  navigation.navigate(ui_biz_routerKey.ui_biz_fixed_time_edit_new, {
57
68
  ...params,
@@ -62,19 +73,43 @@ const FixedTimePage = () => {
62
73
  }, [])
63
74
 
64
75
  const showMaxNumTip = useCallback(() => {
65
- return state.fixedTimeList.length >= MAX_NUM
66
- }, [state.fixedTimeList.length])
76
+ return state.originList.length >= MAX_NUM
77
+ }, [state.originList.length])
67
78
 
68
79
  const onPost = useCallback(async (mode: 'add' | 'edit' | 'del', fixedTime: FixedTimerUiItem) => {
69
- const cloneFixedTimeList = cloneDeep(state.fixedTimeList)
70
- const idx = state.fixedTimeList.findIndex(f => f.index === fixedTime.index)
80
+ console.log(fixedTime, '< --- fixedTimeeeeee')
81
+ const cloneFixedTimeList = cloneDeep(state.originList)
82
+ const idx = state.originList.findIndex(f => f.index === fixedTime.index)
83
+ console.log(idx, '< --- idxxxxx')
71
84
  if (mode === 'edit') {
72
85
  cloneFixedTimeList.splice(idx, 1, fixedTime)
73
86
  }
74
87
  if (mode === 'del') cloneFixedTimeList.splice(idx, 1)
75
- const newFixedTimeList = mode === 'add' ? [...state.fixedTimeList, fixedTime] : cloneFixedTimeList
76
- return setFixedTime(newFixedTimeList)
77
- }, [state.fixedTimeList])
88
+ const newFixedTimeList = mode === 'add' ? [...state.originList, fixedTime] : cloneFixedTimeList
89
+ const res = await setFixedTime(newFixedTimeList)
90
+ console.log(res, '< ---== resss')
91
+ if (res.success) {
92
+ state.originList = cloneDeep(newFixedTimeList)
93
+ }
94
+ return res
95
+ }, [state.originList])
96
+
97
+ const showTags = useMemo(() => (
98
+ <View style={styles.categoryList}>
99
+ {state.checkTags.map((tag, idx) => (
100
+ <Tag
101
+ key={tag.key}
102
+ text={tag.key}
103
+ checked={tag.enable}
104
+ onCheckedChange={(v) => {
105
+ state.checkTags[idx].enable = v
106
+ state.checkTags = cloneDeep(state.checkTags)
107
+ }}
108
+ style={{ marginRight: cx(5), marginBottom: cx(5) }}
109
+ />
110
+ ))}
111
+ </View>
112
+ ), [state.checkTags])
78
113
 
79
114
  return (
80
115
  <Page
@@ -87,71 +122,76 @@ const FixedTimePage = () => {
87
122
  navigateToEdit('add', newFixedTime())
88
123
  }}
89
124
  >
90
- {state.fixedTimeList.length > 0 ?
91
- <ScrollView nestedScrollEnabled={true}>
92
- <Text style={{
93
- color: '#000',
94
- marginLeft: cx(24),
95
- }}>{I18n.getLang('timeschedule_overview_description_text')}</Text>
96
- <Spacer height={cx(10)} />
97
- {showMaxNumTip() && <View style={{ marginHorizontal: cx(24), flexDirection: 'row' }}>
98
- <Image style={{ width: cx(16), height: cx(16), tintColor: '#ff9500' }} source={res.ic_warning_amber} />
99
- <Text>{I18n.getLang('fixedtimecycle_warning_max_number_text')}</Text>
100
- </View>}
101
- <FlatList
102
- data={state.fixedTimeList}
103
- renderItem={({ item }) => (
104
- <FixedTimeCard
105
- is24Hour={is24Hour}
106
- fixedTime={item}
107
- onSwitch={async (v) => {
108
- state.loading = true
109
- await onPost('edit', {
110
- ...item,
111
- enable: v
112
- })
113
- state.loading = false
114
- }}
115
- onPress={() => {
116
- navigateToEdit('edit', item)
117
- }}
118
- />
119
- )}
120
- keyExtractor={(item: any) => `${item?.index}`}
121
- ItemSeparatorComponent={() => <Spacer />}
122
- ListHeaderComponent={<Spacer height={cx(10)} />}
123
- ListFooterComponent={<Spacer />}
124
- />
125
- </ScrollView> :
126
- <View style={{ flex: 1, marginTop: cx(60), alignItems: 'center' }}>
127
- <Image
128
- style={{ width: cx(225), height: cx(198) }}
129
- source={{ uri: res.ldv_timer_empty }}
130
- resizeMode="contain" />
131
- <View style={{ flexDirection: 'row', alignItems: 'center' }}>
125
+ <ScrollView nestedScrollEnabled={true}>
126
+ <Text style={{
127
+ color: '#000',
128
+ marginLeft: cx(24),
129
+ fontSize: cx(12)
130
+ }}>{I18n.getLang('timeschedule_overview_description_text')}</Text>
131
+ <Spacer height={cx(10)} />
132
+ {showMaxNumTip() && <InfoText
133
+ style={{ marginHorizontal: cx(24), marginBottom: cx(5) }}
134
+ icon={res.ic_warning_amber}
135
+ iconStyle={{ width: cx(16), height: cx(16) }}
136
+ contentColor="#FF9500"
137
+ text={I18n.getLang('fixedtimecycle_warning_max_number_text')}
138
+ textStyle={{ fontSize: cx(12) }}
139
+ />}
140
+ {params.showTags && !!state.originList.length && showTags}
141
+ {state.fixedTimeList.length > 0 ? <FlatList
142
+ data={state.fixedTimeList}
143
+ renderItem={({ item }) => (
144
+ <FixedTimeCard
145
+ is24Hour={is24Hour}
146
+ fixedTime={item}
147
+ showTags={params.showTags}
148
+ tags={params.applyForList}
149
+ onSwitch={async (v) => {
150
+ state.loading = true
151
+ await onPost('edit', {
152
+ ...item,
153
+ enable: v
154
+ })
155
+ state.loading = false
156
+ }}
157
+ onPress={() => {
158
+ navigateToEdit('edit', item)
159
+ }}
160
+ />
161
+ )}
162
+ keyExtractor={(item: any) => `${item?.index}`}
163
+ ItemSeparatorComponent={() => <Spacer />}
164
+ ListHeaderComponent={<Spacer height={cx(10)} />}
165
+ ListFooterComponent={<Spacer />}
166
+ /> :
167
+ <View style={{ flex: 1, marginTop: cx(60), alignItems: 'center', marginHorizontal: cx(24) }}>
132
168
  <Image
133
- source={{ uri: res.device_panel_schedule_alert }}
134
- style={{ width: cx(16), height: cx(16) }}
169
+ style={{ width: cx(225), height: cx(198) }}
170
+ source={{ uri: res.ldv_timer_empty }}
171
+ resizeMode="contain" />
172
+ <InfoText
173
+ icon={res.device_panel_schedule_alert}
174
+ text={I18n.getLang(!state.originList.length ? 'fixedTimeCycle_information_text' : 'fixedTimeCycle_empty_filtering_information_text')}
175
+ style={{ width: 'auto', alignItems: 'center' }}
176
+ textStyle={{ color: '#000', fontSize: cx(12), flex: undefined }}
177
+ iconStyle={{ width: cx(16), height: cx(16), tintColor: '#000' }}
135
178
  />
136
- <Text style={{ color: '#000', fontSize: cx(12) }}>
137
- {I18n.getLang('fixedTimeCycle_information_text')}
138
- </Text>
139
- </View>
140
- <Spacer />
141
- <TextButton
142
- text={I18n.getLang('fixedTimeCycle_bttn_text')}
143
- style={{
144
- backgroundColor: '#f60',
145
- borderRadius: cx(6),
146
- paddingVertical: cx(12),
147
- paddingHorizontal: cx(24),
148
- }}
149
- textStyle={{ color: '#fff' }}
150
- onPress={() => {
151
- navigateToEdit('add', newFixedTime())
152
- }} />
153
- </View>
154
- }
179
+ <Spacer />
180
+ {!state.originList.length && <TextButton
181
+ text={I18n.getLang('fixedTimeCycle_bttn_text')}
182
+ style={{
183
+ backgroundColor: '#f60',
184
+ borderRadius: cx(6),
185
+ paddingVertical: cx(12),
186
+ paddingHorizontal: cx(24),
187
+ }}
188
+ textStyle={{ color: '#fff' }}
189
+ onPress={() => {
190
+ navigateToEdit('add', newFixedTime())
191
+ }} />}
192
+ </View>}
193
+ </ScrollView>
194
+
155
195
  </Page>
156
196
  )
157
197
  }
@@ -159,10 +199,12 @@ const FixedTimePage = () => {
159
199
  const FixedTimeCard = memo((props: {
160
200
  is24Hour: boolean
161
201
  fixedTime: FixedTimerUiItem,
202
+ tags: ApplyForItem[]
203
+ showTags?: boolean,
162
204
  onSwitch: (enable: boolean) => void,
163
205
  onPress: () => void
164
206
  }) => {
165
- const { is24Hour, fixedTime, onSwitch, onPress } = props
207
+ const { is24Hour, fixedTime, tags, showTags, onSwitch, onPress } = props
166
208
  return (
167
209
  <Card style={styles.randomTimingCard} onPress={onPress}>
168
210
  <Spacer height={cx(16)} />
@@ -178,7 +220,14 @@ const FixedTimeCard = memo((props: {
178
220
  <Text style={styles.loopText}>{loopText(fixedTime.weeks)}</Text>
179
221
  <Spacer height={cx(5)} />
180
222
  <Text style={styles.loopText}>{fixedTime.name}</Text>
181
- <Spacer />
223
+ <Spacer height={cx(showTags ? 5 : 20)} />
224
+ {showTags && <View style={styles.tagContainer}>
225
+ <View style={styles.tag}>
226
+ <Text style={styles.tagTitle}>
227
+ {tags[fixedTime.channel || 0]?.key}
228
+ </Text>
229
+ </View>
230
+ </View>}
182
231
  </Card>
183
232
  )
184
233
  })
@@ -193,7 +242,7 @@ const newFixedTime = () => {
193
242
  endTime: startTime + 60,
194
243
  closeTime: 1,
195
244
  openTime: 1,
196
- channel: 1,
245
+ channel: 0,
197
246
  color: {
198
247
  h: 0,
199
248
  s: 100,
@@ -226,6 +275,30 @@ const styles = StyleSheet.create({
226
275
  fontSize: cx(14),
227
276
  fontFamily: 'helvetica_neue_lt_std_roman',
228
277
  },
278
+ categoryList: {
279
+ display: 'flex',
280
+ flexDirection: 'row',
281
+ flexWrap: 'wrap',
282
+ marginHorizontal: cx(24),
283
+ alignSelf: 'flex-start'
284
+ },
285
+ tagContainer: {
286
+ flexDirection: 'row',
287
+ marginBottom: cx(15)
288
+ },
289
+ tag: {
290
+ borderRadius: cx(16),
291
+ height: cx(16),
292
+ backgroundColor: '#E6E7E8',
293
+ marginRight: cx(10),
294
+ paddingHorizontal: cx(12)
295
+ },
296
+ tagTitle: {
297
+ fontSize: cx(10),
298
+ textAlign: 'center',
299
+ fontFamily: 'PingFangSC-Medium',
300
+ color: '#000'
301
+ },
229
302
  })
230
303
 
231
304
  export default FixedTimePage
@@ -7,7 +7,6 @@ import { padStart } from "lodash";
7
7
  import { hex2Int, spliceByStep } from "@ledvance/base/src/utils/common";
8
8
  import I18n from "@ledvance/base/src/i18n";
9
9
  import { parseJSON } from "@tuya/tuya-panel-lamp-sdk/lib/utils";
10
- import { useUpdateEffect } from "ahooks";
11
10
  import { Buffer } from "buffer";
12
11
  const { to16 } = Utils
13
12
 
@@ -21,6 +20,7 @@ export interface RandomTimerData {
21
20
 
22
21
  export interface RandomTimer {
23
22
  enable: boolean;
23
+ channel?: number;
24
24
  weeks: number[];
25
25
  startTime: number;
26
26
  endTime: number;
@@ -52,9 +52,9 @@ export interface PlugRandomTimerItem extends PlugRandomTimer {
52
52
  }
53
53
 
54
54
  let randomTimer
55
- type UseFixedTimeType = (dpKey: string, isPlug?: boolean) => [RandomTimerUiItem[], (randomTimeList: RandomTimerUiItem[], manualEdit?: boolean) => Promise<{ success: boolean }>]
55
+ type UseFixedTimeType = (dpKey: string, isPlug?: boolean, disableFeature?: boolean) => [RandomTimerUiItem[], (randomTimeList: RandomTimerUiItem[], manualEdit?: boolean) => Promise<{ success: boolean }>]
56
56
 
57
- export const useRandomTime: UseFixedTimeType = (dpKey, isPlug) => {
57
+ export const useRandomTime: UseFixedTimeType = (dpKey: string, isPlug?: boolean, disableFeature?: boolean) => {
58
58
  const deviceId = useDeviceId()
59
59
  const [randomTimeDp, setRandomTimeDp]: [string, (v: string) => Promise<Result<any>>] = useDp(dpKey)
60
60
  const [randomTimeUiList, setRandomTimeUiList] = useState<RandomTimerUiItem[]>([])
@@ -69,53 +69,55 @@ export const useRandomTime: UseFixedTimeType = (dpKey, isPlug) => {
69
69
 
70
70
  // 获取云端数据
71
71
  useEffect(() => {
72
+ // 不获取名称
73
+ if(disableFeature) {
74
+ setRandomTimeUiList(formatterFn())
75
+ return
76
+ }
72
77
  randomTimer = setTimeout(() => {
73
- getFeatureFn()
74
- }, 400)
75
- return () => clearTimeout(randomTimer)
76
- }, [])
78
+ getFeature(deviceId, isPlug ? plug_randomFeatureId : randomFeatureId).then(res => {
79
+ if (res?.result) {
80
+ // 首次进入同步云端数据 (云端无数据)
81
+ if (!res.data) {
82
+ const cloudData = formatterFn()
83
+ setRandomTimeFn(cloudData).then()
84
+ } else {
85
+ const featureData = parseJSON(res.data)
86
+ if (randomTimeList.length) {
87
+ const uiPlan = randomTimeList?.map((item, idx: number) => {
88
+ const dp = randomTimeToHex(item, isPlug, true)
89
+ const random = featureData[idx]
90
+ const featureItem = random?.v && (isPlug ? parseJSON(random?.v)?.dp : random?.v)?.includes(dp) ? (isPlug ? parseJSON(random) : random) : featureData.find(feature => (isPlug ? parseJSON(feature?.v)?.dp : feature?.v).includes(dp))
91
+ return {
92
+ ...item,
93
+ index: idx,
94
+ name: featureItem ? featureItem?.n : `${I18n.getLang('randomtimecycle_sockets_headline_text')} ${idx + 1}`
95
+ }
96
+ })
97
+ setRandomTimeUiList(uiPlan)
98
+ } else {
99
+ setRandomTimeUiList([])
100
+ }
101
+
102
+ }
103
+ }
104
+ })
105
+ }, 250)
77
106
 
78
- useUpdateEffect(() =>{
79
- randomTimer = setTimeout(() => {
80
- getFeatureFn()
81
- }, 100)
82
107
  return () => clearTimeout(randomTimer)
83
108
  }, [randomTimeDp])
84
109
 
85
- const getFeatureFn = () => {
86
- getFeature(deviceId, isPlug ? plug_randomFeatureId : randomFeatureId).then(res => {
87
- if (res?.result) {
88
- // 首次进入同步云端数据 (云端无数据)
89
- if (!res.data) {
90
- const cloudData = formatterFn()
91
- setRandomTimeFn(cloudData).then()
92
- } else {
93
- const featureData = parseJSON(res.data)
94
- if (randomTimeList.length) {
95
- const uiPlan = randomTimeList?.map((item, idx: number) => {
96
- const featureItem = featureData.find(feature => (isPlug ? parseJSON(feature?.v)?.dp : feature?.v) === randomTimeToHex(item, isPlug))
97
- return {
98
- ...item,
99
- index: idx,
100
- name: featureItem ? featureItem?.n : `${I18n.getLang('randomtimecycle_sockets_headline_text')} ${idx + 1}`
101
- }
102
- })
103
- setRandomTimeUiList(uiPlan)
104
- } else {
105
- setRandomTimeUiList([])
106
- }
107
-
108
- }
110
+ const setRandomTimeFn = async (randomTimeList: RandomTimerUiItem[]) => {
111
+ const randomData = randomTimeList.map(item => {
112
+ const randomHex = randomTimeToHex(item, isPlug)
113
+ return {
114
+ n: item?.name || '',
115
+ v: isPlug ? JSON.stringify({dp: randomHex}) : randomHex
109
116
  }
110
117
  })
111
- }
112
-
113
- const setRandomTimeFn = async (randomTimeList: RandomTimerUiItem[]) => {
114
- const randomData = randomTimeList.map(item => ({
115
- n: item?.name || '',
116
- v: isPlug ? JSON.stringify({dp: randomTimeToHex(item, isPlug)}) : randomTimeToHex(item, isPlug)
117
- }))
118
+ console.log(randomData, '< --- randomData')
118
119
  const cloudStatus = await putFeatureFn(deviceId, isPlug ? plug_randomFeatureId : randomFeatureId, JSON.stringify(randomData))
120
+ console.log(cloudStatus, '< --- cloudStatus')
119
121
  if (cloudStatus) {
120
122
  const randomTimerData = {
121
123
  version: 0,
@@ -157,7 +159,7 @@ const putFeatureFn = async (devId, featureId, data) => {
157
159
  }
158
160
 
159
161
  const randomTimeDp2Obj = (randomDp: string, isPlug?: boolean) => {
160
- if (randomDp?.length <= 4) return
162
+ if (!randomDp || randomDp?.length <= 6) return
161
163
  if(isPlug){
162
164
  randomDp = Buffer.from(randomDp, 'base64').toString('hex')
163
165
  }
@@ -166,7 +168,11 @@ const randomTimeDp2Obj = (randomDp: string, isPlug?: boolean) => {
166
168
  const s = isPlug ? 0 : 4
167
169
  const n = isPlug ? 12 : 24
168
170
  const nodes = spliceByStep(randomDp.slice(s), n).map(plan => {
169
- const enable = plan.slice(0, 2) === '01'
171
+ const powerInfo = padStart(parseInt(`${plan.slice(0, 2)}`, 16).toString(2), 8, '0');
172
+ const powerBits = powerInfo.split('');
173
+ const enable = !!Number(powerBits[powerBits.length - 1]);
174
+ // 通道号
175
+ const channel = parseInt(powerBits.slice(1, powerBits.length - 1).join(''), 2);
170
176
  const weeks = parseInt(plan.slice(2, 4), 16).toString(2).padStart(8, '0')
171
177
  .split('')
172
178
  .reverse()
@@ -174,7 +180,7 @@ const randomTimeDp2Obj = (randomDp: string, isPlug?: boolean) => {
174
180
  const startTime = hex2Int(plan.slice(4, 8))
175
181
  const endTime = hex2Int(plan.slice(8, 12))
176
182
  const common = {
177
- enable, weeks, startTime, endTime
183
+ enable, channel, weeks, startTime, endTime
178
184
  }
179
185
  if (isPlug) {
180
186
  return common
@@ -210,9 +216,11 @@ const randomTimeObj2Dp = (randomTimerData: RandomTimerData, isPlug?: boolean) =>
210
216
  }
211
217
 
212
218
 
213
- const randomTimeToHex = (randomTime: RandomTimer, isPlug?: boolean) => {
214
- const { weeks, startTime, endTime, enable } = randomTime
215
- const enableStr = enable ? '01' : '00'
219
+ const randomTimeToHex = (randomTime: RandomTimer, isPlug?: boolean, isFeatureData?: boolean) => {
220
+ const { weeks, startTime, endTime, channel, enable } = randomTime
221
+ const channelStr = padStart((channel ?? 0).toString(2), 7, '0');
222
+ const powerChannel = parseInt(`${channelStr}${enable ? 1 : 0}`, 2);
223
+ const powerChannelStr = to16(powerChannel, 2);
216
224
  const weeksValue: string = padStart([...weeks].reverse().join(''), 8, '0');
217
225
  const weeksStr = to16(parseInt(weeksValue, 2), 2);
218
226
  const startTimeStr = to16(startTime, 4);
@@ -227,6 +235,6 @@ const randomTimeToHex = (randomTime: RandomTimer, isPlug?: boolean) => {
227
235
  const temperatureStr = to16(temperature);
228
236
  colorHex = hueStr + saturationStr + valueStr + brightnessStr + temperatureStr
229
237
  }
230
- return enableStr + weeksStr + startTimeStr + endTimeStr + colorHex
238
+ return (isFeatureData ? '' : powerChannelStr) + weeksStr + startTimeStr + endTimeStr + colorHex
231
239
  }
232
240
 
@@ -36,8 +36,6 @@ const RandomTimeDetailPage = () => {
36
36
  const state = useReactive({
37
37
  loading: false,
38
38
  isColorMode: false,
39
- selectedSkill: params.applyDps.length === 1 ? params.applyDps : [],
40
- skillList: params.applyDps.length === 1 ? [] : params.applyDps,
41
39
  randomTime: cloneDeep(params.scheduleItem)
42
40
  })
43
41
 
@@ -49,20 +47,20 @@ const RandomTimeDetailPage = () => {
49
47
  }
50
48
  }, [])
51
49
 
52
- const showClearIcon = useMemo(() => (
53
- false
54
- ), [state.skillList])
50
+ const checkItemChanged = useMemo(() =>{
51
+ return isEqual(state.randomTime, params.scheduleItem)
52
+ }, [params.scheduleItem, JSON.stringify(state.randomTime)])
55
53
 
56
54
  const canSubmit = useMemo(() => {
57
- return state.randomTime.name?.length > 0 && state.randomTime.name?.length < 33 && !isEqual(params.scheduleItem, state.randomTime)
58
- }, [JSON.stringify(state.randomTime)])
55
+ return state.randomTime.name?.length > 0 && state.randomTime.name?.length < 33 && !checkItemChanged && state.randomTime.channel !== undefined
56
+ }, [JSON.stringify(state.randomTime), checkItemChanged])
59
57
 
60
58
  return (
61
59
  <Page
62
60
  backText={I18n.getLang('randomtimecycle_sockets_headline_text')}
63
61
  rightButtonIcon={canSubmit ? res.ic_check : res.ic_uncheck}
64
62
  loading={state.loading}
65
- showBackDialog={canSubmit}
63
+ showBackDialog={!checkItemChanged}
66
64
  backDialogTitle={I18n.getLang('cancel_dialog_leave_unsaved_titel')}
67
65
  backDialogContent={I18n.getLang('cancel_dialog_delete_item_randomtimecycle_description')}
68
66
  headlineText={I18n.getLang(params.mode === 'add' ? 'add_fixedtimecycle_headline_text' : 'edit_fixedtimecycle_headline_text')}
@@ -138,25 +136,31 @@ const RandomTimeDetailPage = () => {
138
136
  <View style={styles.cardContainer}>
139
137
  <Text style={styles.itemTitle}>{I18n.getLang('timeschedule_add_schedule_subheadline_text')}</Text>
140
138
  <Spacer height={cx(10)} />
141
- <View style={styles.applyContent}>
142
- {state.selectedSkill.length === 0 ?
139
+ <View style={[styles.applyContent, { paddingTop: state.randomTime.channel === undefined ? 0 : cx(10) }]}>
140
+ {state.randomTime.channel === undefined ?
143
141
  <Text>{I18n.getLang('timer_ceiling_fan_selectionfield_no_components_text')}</Text> :
144
- state.selectedSkill.map((skill: any) => (
145
- <View style={[styles.applyItem, { marginBottom: cx(10), borderRadius: 4 }]} key={skill.label}>
146
- <Text style={{ color: '#000' }}>{skill.label}</Text>
147
- {showClearIcon && <TouchableOpacity
148
- onPress={() => { }}
149
- style={{ paddingHorizontal: cx(5) }}>
150
- <Image style={{ width: cx(16), height: cx(16) }} source={res.ic_arrows_nav_clear} />
151
- </TouchableOpacity>}
152
- </View>
153
- ))
142
+ <View style={[styles.applyItem, { marginBottom: cx(10), borderRadius: 4 }]}>
143
+ <Text style={{ color: '#000', fontSize: cx(12) }}>{params.applyForList[state.randomTime.channel]?.key}</Text>
144
+ {params.applyForList.length > 1 && <TouchableOpacity
145
+ onPress={() => {
146
+ state.randomTime.channel = undefined
147
+ }}
148
+ style={{ paddingHorizontal: cx(5) }}>
149
+ <Image style={{ width: cx(16), height: cx(16) }} source={res.ic_arrows_nav_clear} />
150
+ </TouchableOpacity>}
151
+ </View>
154
152
  }
155
153
  </View>
156
- {state.skillList.map((item: any) => {
154
+ {params.applyForList.map((item, index) => {
155
+ if (state.randomTime.channel === index) return null
157
156
  return (
158
- <TouchableOpacity style={styles.applyItem} key={item.label} onPress={() => { }}>
159
- <Text style={{ color: '#000' }}>{item.label}</Text>
157
+ <TouchableOpacity
158
+ style={styles.applyItem}
159
+ key={item.key}
160
+ onPress={() => {
161
+ state.randomTime.channel = index
162
+ }}>
163
+ <Text style={{ color: '#000', fontSize: cx(12) }}>{item.key}</Text>
160
164
  <Image style={{ width: cx(16), height: cx(16) }} source={res.device_panel_timer_add} />
161
165
  </TouchableOpacity>
162
166
  )
@@ -177,9 +181,9 @@ const RandomTimeDetailPage = () => {
177
181
  showSwitch={false}
178
182
  />
179
183
  <LampAdjustView
180
- isSupportColor={params.isSupportColor}
181
- isSupportBrightness={params.isSupportBrightness}
182
- isSupportTemperature={params.isSupportTemperature}
184
+ isSupportColor={!!params.isSupportColor}
185
+ isSupportBrightness={!!params.isSupportBrightness}
186
+ isSupportTemperature={!!params.isSupportTemperature}
183
187
  isColorMode={state.isColorMode}
184
188
  reserveSV={true}
185
189
  setIsColorMode={(v) => state.isColorMode = v}
@@ -226,11 +230,11 @@ const RandomTimeDetailPage = () => {
226
230
  onPress={() => {
227
231
  showDialog({
228
232
  method: 'confirm',
229
- title: I18n.getLang('cancel_dialog_delete_item_fixedtimecycle_titel'),
233
+ title: I18n.getLang('cancel_dialog_delete_item_randomtimecycle_titel'),
230
234
  subTitle: I18n.getLang('cancel_dialog_delete_item_fixedtimecycle_description'),
231
235
  onConfirm: async (_, { close }) => {
232
- state.loading = true
233
236
  close()
237
+ state.loading = true
234
238
  const res = await params.onPost('del', state.randomTime)
235
239
  state.loading = false
236
240
  if (res.success) {
@@ -319,4 +323,4 @@ const styles = StyleSheet.create({
319
323
  }
320
324
  })
321
325
 
322
- export default RandomTimeDetailPage
326
+ export default RandomTimeDetailPage