@ledvance/ui-biz-bundle 1.1.67 → 1.1.69

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.
Files changed (240) hide show
  1. package/.babelrc +31 -31
  2. package/.eslintignore +5 -5
  3. package/.eslintrc.js +27 -27
  4. package/.prettierrc.js +1 -1
  5. package/.versionrc +5 -5
  6. package/package.json +74 -74
  7. package/rn-cli.config.js +8 -8
  8. package/src/hooks/DeviceDpStateHooks.d.ts +14 -14
  9. package/src/hooks/DeviceDpStateHooks.ts +50 -50
  10. package/src/modules/biorhythm/BiorhythmActions.d.ts +8 -8
  11. package/src/modules/biorhythm/BiorhythmActions.ts +324 -324
  12. package/src/modules/biorhythm/BiorhythmBean.d.ts +58 -58
  13. package/src/modules/biorhythm/BiorhythmBean.ts +230 -230
  14. package/src/modules/biorhythm/BiorhythmEditPage.d.ts +14 -14
  15. package/src/modules/biorhythm/BiorhythmEditPage.tsx +324 -324
  16. package/src/modules/biorhythm/BiorhythmPage.d.ts +10 -10
  17. package/src/modules/biorhythm/BiorhythmPage.tsx +796 -796
  18. package/src/modules/biorhythm/IconSelect.d.ts +2 -2
  19. package/src/modules/biorhythm/IconSelect.tsx +81 -81
  20. package/src/modules/biorhythm/Router.ts +34 -34
  21. package/src/modules/biorhythm/circular/ItemIcon.d.ts +22 -22
  22. package/src/modules/biorhythm/circular/ItemIcon.tsx +172 -172
  23. package/src/modules/biorhythm/circular/Progress.d.ts +24 -24
  24. package/src/modules/biorhythm/circular/Progress.tsx +411 -411
  25. package/src/modules/biorhythm/circular/TimeCircular.d.ts +11 -11
  26. package/src/modules/biorhythm/circular/TimeCircular.tsx +70 -70
  27. package/src/modules/biorhythm/iconListData.d.ts +7 -7
  28. package/src/modules/biorhythm/iconListData.ts +29 -29
  29. package/src/modules/biorhythm/pIdList.d.ts +2 -2
  30. package/src/modules/biorhythm/pIdList.ts +35 -35
  31. package/src/modules/biorhythm/res/BiologicalRes.d.ts +43 -43
  32. package/src/modules/biorhythm/res/BiologicalRes.ts +41 -41
  33. package/src/modules/config/ldvConfig.d.ts +2 -2
  34. package/src/modules/config/ldvConfig.tsx +18 -18
  35. package/src/modules/fixedTime/FixedTimeActions.ts +173 -173
  36. package/src/modules/fixedTime/FixedTimeDetailPage.tsx +372 -372
  37. package/src/modules/fixedTime/FixedTimePage.tsx +213 -213
  38. package/src/modules/fixedTime/Router.ts +26 -26
  39. package/src/modules/flags/FlagActions.ts +267 -267
  40. package/src/modules/flags/FlagEditPage.tsx +441 -441
  41. package/src/modules/flags/FlagInfo.tsx +563 -563
  42. package/src/modules/flags/FlagItem.tsx +90 -90
  43. package/src/modules/flags/FlagPage.tsx +277 -277
  44. package/src/modules/flags/Router.ts +25 -25
  45. package/src/modules/history/HistoryPage.d.ts +2 -2
  46. package/src/modules/history/HistoryPage.tsx +261 -261
  47. package/src/modules/history/Router.ts +16 -16
  48. package/src/modules/history/SwitchHistoryPageActions.d.ts +14 -14
  49. package/src/modules/history/SwitchHistoryPageActions.ts +76 -76
  50. package/src/modules/mood/AddMoodPage.d.ts +10 -10
  51. package/src/modules/mood/AddMoodPage.tsx +792 -792
  52. package/src/modules/mood/DynamicMoodEditorPage.d.ts +6 -6
  53. package/src/modules/mood/DynamicMoodEditorPage.tsx +561 -561
  54. package/src/modules/mood/FantasyMood.tsx +176 -176
  55. package/src/modules/mood/FantasyMoodEditPage.tsx +582 -582
  56. package/src/modules/mood/FantasyMoodItem.tsx +104 -104
  57. package/src/modules/mood/FantasyRouter.ts +35 -35
  58. package/src/modules/mood/MixMood/AddMixMoodPage.tsx +247 -247
  59. package/src/modules/mood/MixMood/MixMoodActions.ts +128 -128
  60. package/src/modules/mood/MixMood/MixMoodEditPage.tsx +721 -721
  61. package/src/modules/mood/MixMood/MixMoodItem.tsx +134 -134
  62. package/src/modules/mood/MixMood/MixMoodPage.tsx +326 -326
  63. package/src/modules/mood/MixMood/MixSceneBeans.ts +364 -364
  64. package/src/modules/mood/MixMood/RecommendMixMoodItem.tsx +69 -69
  65. package/src/modules/mood/MixMood/Router.ts +44 -44
  66. package/src/modules/mood/MoodItem.d.ts +11 -11
  67. package/src/modules/mood/MoodItem.tsx +114 -114
  68. package/src/modules/mood/MoodPage.d.ts +16 -16
  69. package/src/modules/mood/MoodPage.tsx +296 -296
  70. package/src/modules/mood/RecommendMoodItem.d.ts +13 -13
  71. package/src/modules/mood/RecommendMoodItem.tsx +74 -74
  72. package/src/modules/mood/Router.ts +53 -53
  73. package/src/modules/mood/StaticMoodEditorPage.d.ts +16 -16
  74. package/src/modules/mood/StaticMoodEditorPage.tsx +320 -320
  75. package/src/modules/mood/tools.d.ts +3 -3
  76. package/src/modules/mood/tools.ts +11 -11
  77. package/src/modules/music/MusicDataBean.d.ts +47 -47
  78. package/src/modules/music/MusicDataBean.ts +167 -167
  79. package/src/modules/music/MusicManager.d.ts +27 -27
  80. package/src/modules/music/MusicManager.ts +207 -207
  81. package/src/modules/music/MusicPage.d.ts +10 -10
  82. package/src/modules/music/MusicPage.tsx +347 -347
  83. package/src/modules/music/MusicPageActions.d.ts +35 -35
  84. package/src/modules/music/MusicPageActions.ts +317 -317
  85. package/src/modules/music/Router.ts +16 -16
  86. package/src/modules/music/SelecetGenre.d.ts +7 -7
  87. package/src/modules/music/SelecetGenre.tsx +63 -63
  88. package/src/modules/music/color.d.ts +2 -2
  89. package/src/modules/music/color.ts +73 -73
  90. package/src/modules/music/res/index.d.ts +10 -10
  91. package/src/modules/music/res/index.ts +9 -9
  92. package/src/modules/powerOnBehavior/PowerOnBehaviorActions.ts +11 -11
  93. package/src/modules/powerOnBehavior/PowerOnBehaviorPage.tsx +173 -173
  94. package/src/modules/powerOnBehavior/Router.ts +16 -16
  95. package/src/modules/randomTime/RandomTimeActions.ts +160 -160
  96. package/src/modules/randomTime/RandomTimeDetailPage.tsx +337 -337
  97. package/src/modules/randomTime/RandomTimePage.tsx +214 -214
  98. package/src/modules/randomTime/Router.ts +25 -25
  99. package/src/modules/randomTime/Summary.tsx +122 -122
  100. package/src/modules/scene/SceneAction.d.ts +13 -13
  101. package/src/modules/scene/SceneAction.ts +473 -473
  102. package/src/modules/scene/SceneDetailPage.d.ts +1 -1
  103. package/src/modules/scene/SceneDetailPage.tsx +421 -421
  104. package/src/modules/scene/SceneInfo.d.ts +72 -72
  105. package/src/modules/scene/SceneInfo.ts +1059 -1059
  106. package/src/modules/scene/ScenePage.d.ts +7 -7
  107. package/src/modules/scene/ScenePage.tsx +147 -147
  108. package/src/modules/select/SelectPage.d.ts +12 -12
  109. package/src/modules/select/SelectPage.tsx +137 -137
  110. package/src/modules/sleepWakeup/DeviceState.d.ts +9 -9
  111. package/src/modules/sleepWakeup/DeviceState.tsx +99 -99
  112. package/src/modules/sleepWakeup/LdvScheduleItem.d.ts +15 -15
  113. package/src/modules/sleepWakeup/LdvScheduleItem.tsx +176 -176
  114. package/src/modules/sleepWakeup/Router.ts +25 -25
  115. package/src/modules/sleepWakeup/SleepWakeUpActions.d.ts +2 -2
  116. package/src/modules/sleepWakeup/SleepWakeUpActions.ts +180 -180
  117. package/src/modules/sleepWakeup/SleepWakeUpDetailPage.d.ts +2 -2
  118. package/src/modules/sleepWakeup/SleepWakeUpDetailPage.tsx +616 -616
  119. package/src/modules/sleepWakeup/SleepWakeUpPage.d.ts +13 -13
  120. package/src/modules/sleepWakeup/SleepWakeUpPage.tsx +424 -424
  121. package/src/modules/sleepWakeup/utils.d.ts +44 -44
  122. package/src/modules/sleepWakeup/utils.ts +253 -253
  123. package/src/modules/timeSchedule/DeviceState.d.ts +17 -17
  124. package/src/modules/timeSchedule/DeviceState.tsx +94 -94
  125. package/src/modules/timeSchedule/LdvScheduleItem.d.ts +15 -15
  126. package/src/modules/timeSchedule/LdvScheduleItem.tsx +130 -130
  127. package/src/modules/timeSchedule/ManualSetting.d.ts +14 -14
  128. package/src/modules/timeSchedule/ManualSetting.tsx +219 -219
  129. package/src/modules/timeSchedule/MoodSetting.d.ts +11 -11
  130. package/src/modules/timeSchedule/MoodSetting.tsx +228 -228
  131. package/src/modules/timeSchedule/Router.ts +25 -25
  132. package/src/modules/timeSchedule/ScheduleScene.d.ts +6 -6
  133. package/src/modules/timeSchedule/ScheduleScene.tsx +144 -144
  134. package/src/modules/timeSchedule/SingleLightView.d.ts +12 -12
  135. package/src/modules/timeSchedule/SingleLightView.tsx +175 -175
  136. package/src/modules/timeSchedule/TimeScheduleBean.d.ts +14 -14
  137. package/src/modules/timeSchedule/TimeScheduleBean.ts +18 -18
  138. package/src/modules/timeSchedule/TimeScheduleEditpage.d.ts +6 -6
  139. package/src/modules/timeSchedule/TimeScheduleEditpage.tsx +765 -765
  140. package/src/modules/timeSchedule/TimeSchedulePage.d.ts +13 -13
  141. package/src/modules/timeSchedule/TimeSchedulePage.tsx +358 -358
  142. package/src/modules/timeSchedule/components/ColorList.ts +23 -23
  143. package/src/modules/timeSchedule/components/LampSwitchCard.tsx +106 -106
  144. package/src/modules/timeSchedule/mix/MixLightActions.d.ts +3 -3
  145. package/src/modules/timeSchedule/mix/MixLightActions.ts +49 -49
  146. package/src/modules/timeSchedule/mix/MixLightBean.d.ts +10 -10
  147. package/src/modules/timeSchedule/mix/MixLightBean.ts +9 -9
  148. package/src/modules/timeSchedule/mix/MixLightView.d.ts +7 -7
  149. package/src/modules/timeSchedule/mix/MixLightView.tsx +197 -197
  150. package/src/modules/timeSchedule/utils.d.ts +1 -1
  151. package/src/modules/timeSchedule/utils.ts +6 -6
  152. package/src/modules/timer/Router.ts +16 -16
  153. package/src/modules/timer/TimerPage.d.ts +11 -11
  154. package/src/modules/timer/TimerPage.tsx +384 -384
  155. package/src/modules/timer/TimerPageAction.d.ts +22 -22
  156. package/src/modules/timer/TimerPageAction.ts +131 -131
  157. package/src/navigation/Routers.d.ts +15 -15
  158. package/src/navigation/Routers.ts +46 -44
  159. package/src/navigation/tools.d.ts +9 -9
  160. package/src/navigation/tools.ts +21 -21
  161. package/src/newModules/biorhythm/BiorhythmActions.ts +374 -374
  162. package/src/newModules/biorhythm/BiorhythmBean.ts +230 -230
  163. package/src/newModules/biorhythm/BiorhythmEditPage.tsx +267 -267
  164. package/src/newModules/biorhythm/BiorhythmPage.tsx +642 -642
  165. package/src/newModules/biorhythm/IconSelect.tsx +84 -84
  166. package/src/newModules/biorhythm/Router.ts +33 -33
  167. package/src/newModules/biorhythm/circular/ItemIcon.d.ts +22 -22
  168. package/src/newModules/biorhythm/circular/ItemIcon.tsx +172 -172
  169. package/src/newModules/biorhythm/circular/Progress.d.ts +24 -24
  170. package/src/newModules/biorhythm/circular/Progress.tsx +371 -371
  171. package/src/newModules/biorhythm/circular/TimeCircular.d.ts +11 -11
  172. package/src/newModules/biorhythm/circular/TimeCircular.tsx +64 -64
  173. package/src/newModules/biorhythm/iconListData.ts +29 -29
  174. package/src/newModules/biorhythm/pIdList.ts +35 -35
  175. package/src/newModules/biorhythm/res/BiologicalRes.d.ts +43 -43
  176. package/src/newModules/biorhythm/res/BiologicalRes.ts +41 -41
  177. package/src/newModules/childLock/ChildLockPage.tsx +97 -97
  178. package/src/newModules/childLock/Router.ts +16 -16
  179. package/src/newModules/energyConsumption/EnergyConsumptionActions.ts +23 -23
  180. package/src/newModules/energyConsumption/EnergyConsumptionChart.tsx +84 -84
  181. package/src/newModules/energyConsumption/EnergyConsumptionDetail.tsx +322 -322
  182. package/src/newModules/energyConsumption/EnergyConsumptionPage.tsx +393 -393
  183. package/src/newModules/energyConsumption/Router.ts +34 -34
  184. package/src/newModules/energyConsumption/co2Data.ts +23655 -23655
  185. package/src/newModules/energyConsumption/component/BarChart.tsx +93 -93
  186. package/src/newModules/energyConsumption/component/EnergyModal.tsx +284 -284
  187. package/src/newModules/energyConsumption/component/Overview.tsx +118 -118
  188. package/src/newModules/fixedTime/FixedTimeActions.ts +241 -241
  189. package/src/newModules/fixedTime/FixedTimeDetailPage.tsx +345 -345
  190. package/src/newModules/fixedTime/FixedTimePage.tsx +302 -302
  191. package/src/newModules/fixedTime/Router.ts +25 -25
  192. package/src/newModules/lightMode/LightModePage.tsx +204 -204
  193. package/src/newModules/lightMode/Router.ts +16 -16
  194. package/src/newModules/mood/AddMoodPage.tsx +194 -194
  195. package/src/newModules/mood/DynamicMoodEditorPage.tsx +650 -650
  196. package/src/newModules/mood/Interface.ts +220 -220
  197. package/src/newModules/mood/MixDynamicMoodEditor.tsx +786 -786
  198. package/src/newModules/mood/MoodActions.ts +232 -232
  199. package/src/newModules/mood/MoodInfo.ts +2151 -2151
  200. package/src/newModules/mood/MoodItem.tsx +160 -160
  201. package/src/newModules/mood/MoodPage.tsx +386 -386
  202. package/src/newModules/mood/MoodParse.ts +443 -443
  203. package/src/newModules/mood/RecommendMoodItem.tsx +81 -81
  204. package/src/newModules/mood/Router.ts +43 -43
  205. package/src/newModules/mood/StaticMoodEditorPage.tsx +290 -290
  206. package/src/newModules/overchargeSwitch/OverchargeSwitchPage.tsx +96 -96
  207. package/src/newModules/overchargeSwitch/Router.ts +16 -16
  208. package/src/newModules/powerOnBehavior/LightBehaviorPage.tsx +266 -266
  209. package/src/newModules/powerOnBehavior/PlugBehaviorPage.tsx +173 -173
  210. package/src/newModules/powerOnBehavior/PowerOnBehaviorActions.ts +106 -106
  211. package/src/newModules/powerOnBehavior/Router.ts +27 -27
  212. package/src/newModules/randomTime/RandomTimeActions.ts +238 -238
  213. package/src/newModules/randomTime/RandomTimeDetailPage.tsx +325 -325
  214. package/src/newModules/randomTime/RandomTimePage.tsx +299 -299
  215. package/src/newModules/randomTime/Router.ts +25 -25
  216. package/src/newModules/randomTime/Summary.tsx +116 -116
  217. package/src/newModules/remoteControl/RemoteControlActions.ts +5 -5
  218. package/src/newModules/remoteControl/RemoteControlPage.tsx +51 -51
  219. package/src/newModules/remoteControl/Router.ts +15 -15
  220. package/src/newModules/select/Route.ts +16 -16
  221. package/src/newModules/select/SelectPage.d.ts +12 -12
  222. package/src/newModules/select/SelectPage.tsx +137 -137
  223. package/src/newModules/sleepWakeUp/Interface.ts +69 -69
  224. package/src/newModules/sleepWakeUp/Router.ts +24 -24
  225. package/src/newModules/sleepWakeUp/SleepWakeUpActions.ts +317 -317
  226. package/src/newModules/sleepWakeUp/SleepWakeUpDetailPage.tsx +661 -661
  227. package/src/newModules/sleepWakeUp/SleepWakeUpPage.tsx +455 -455
  228. package/src/newModules/sleepWakeUp/utils.ts +253 -253
  229. package/src/newModules/swithInching/Router.ts +16 -16
  230. package/src/newModules/swithInching/SwithInching.tsx +231 -231
  231. package/src/newModules/swithInching/SwithInchingAction.ts +55 -55
  232. package/src/newModules/swithInching/pickerView.tsx +91 -91
  233. package/src/newModules/timeSchedule/Interface.ts +142 -142
  234. package/src/newModules/timeSchedule/Router.ts +25 -25
  235. package/src/newModules/timeSchedule/TimeScheduleActions.ts +53 -53
  236. package/src/newModules/timeSchedule/TimeScheduleDetailPage.tsx +648 -648
  237. package/src/newModules/timeSchedule/TimeSchedulePage.tsx +253 -253
  238. package/src/newModules/timeSchedule/components/ManuaSettings.tsx +460 -460
  239. package/src/newModules/timeSchedule/components/ScheduleCard.tsx +125 -125
  240. package/tsconfig.json +50 -50
@@ -1,642 +1,642 @@
1
- import React, { useCallback, useEffect, useMemo } from 'react'
2
- import { FlatList, Image, Linking, ScrollView, Switch, Text, TouchableOpacity, View } from 'react-native'
3
- import { useNavigation } from '@react-navigation/native'
4
- import { useDebounceFn, useReactive, useUpdateEffect } from 'ahooks'
5
- import {
6
- BiorhythmBean,
7
- BiorhythmGradientType,
8
- colorTemperatureValue,
9
- getDefBiorhythmUIState,
10
- Plan,
11
- } from './BiorhythmBean'
12
- import { Modal, Utils } from 'tuya-panel-kit'
13
- import { cloneDeep, sortBy } from 'lodash'
14
- import iconList from './iconListData'
15
- import pIdList from './pIdList'
16
- import {
17
- useDeviceId,
18
- useDeviceInfo,
19
- useSystemTimeFormate,
20
- } from '@ledvance/base/src/models/modules/NativePropsSlice'
21
- import I18n from '@ledvance/base/src/i18n'
22
- import res from '@ledvance/base/src/res'
23
- import { ui_biz_routerKey } from "../../navigation/Routers";
24
- import BiologicalRes from './res/BiologicalRes'
25
- import { cctToColor } from '@ledvance/base/src/utils/cctUtils'
26
- import { setDataSource } from '@ledvance/base/src/components/weekSelect'
27
- import { BiorhythmEditPageParams } from './BiorhythmEditPage'
28
- import { useBiorhythm, userOperation } from './BiorhythmActions'
29
- import { convertMinutesTo12HourFormat, showDialog as showCommonDialog } from '@ledvance/base/src/utils/common'
30
- import TimeCircular from './circular/TimeCircular'
31
- import Page from '@ledvance/base/src/components/Page'
32
- import Card from '@ledvance/base/src/components/Card'
33
- import Spacer from '@ledvance/base/src/components/Spacer'
34
- import DeleteButton from '@ledvance/base/src/components/DeleteButton'
35
- import { useParams } from '@ledvance/base/src/hooks/Hooks'
36
-
37
- const cx = Utils.RatioUtils.convertX
38
- const width = Utils.RatioUtils.width
39
-
40
- interface UIState extends BiorhythmBean {
41
- showGradientTypeSelectModal: boolean;
42
- flag: symbol;
43
- weekString: string,
44
- timeSchedule: any[]
45
- loading: boolean
46
- }
47
-
48
- export interface BiorhythmPageParams {
49
- biorhythmDpCode: string
50
- conflictDps: {
51
- randomTimeDpCode?: string
52
- fixedTimeDpCode?: string
53
- sleepDpCode?: string
54
- wakeUpDpCode?: string
55
- }
56
- isSupportTemperature: boolean
57
- isSupportBrightness: boolean
58
- isMixLight?: boolean
59
- }
60
-
61
- const BiorhythmPage = () => {
62
- const params = useParams<BiorhythmPageParams>()
63
- const navigation = useNavigation()
64
- const [biorhythm, setBiorhythm] = useBiorhythm(params.biorhythmDpCode)
65
- const deviceId = useDeviceId()
66
- const deviceInfo = useDeviceInfo()
67
- const { productId } = deviceInfo
68
- const is24Hour = useSystemTimeFormate()
69
- const devicesJudge = pIdList.some(val => val === productId)
70
- // const [sleepList, setSleepList] = useSleepPlan({ sleep_mode: params.sleepPlanDp })
71
- // const [wakeUpList, setWakeUpList] = useWakeUpPlan({ wakeup_mode: params.wakeUpPlanDp })
72
- // const sleepWakeUpStatus = [...sleepList, ...wakeUpList].some(ele => ele.enable)
73
- const state = useReactive<UIState>({
74
- ...biorhythm,
75
- showGradientTypeSelectModal: false,
76
- flag: Symbol(),
77
- weekString: '',
78
- timeSchedule: [],
79
- loading: false
80
- })
81
-
82
- const showGradientTypeSelectModal = useCallback((show: boolean) => {
83
- state.showGradientTypeSelectModal = show
84
- }, [])
85
-
86
- const onPlanEdited = useCallback((isAdd: boolean, newPlan: Plan) => {
87
- if (isAdd) {
88
- state.planList.push(newPlan)
89
- state.planList = sortBy(state.planList, p => p.time)
90
- } else {
91
- state.planList = state.planList.map(plan => (plan.index === newPlan.index ? newPlan : plan))
92
- }
93
- state.flag = Symbol()
94
- }, [])
95
-
96
- const onPlanDelete = useCallback((id: number) => {
97
- state.planList = state.planList.filter(plan => plan.index !== id)
98
- state.flag = Symbol()
99
- }, [])
100
-
101
- const requestSetBiorhythm = useCallback(async (pushFeature: boolean = true) => {
102
- state.loading = true
103
- const planList = state.planList?.map(item => { return { ...item, icon: `${item.icon}` } })
104
- .sort((a, b) => a.time - b.time);
105
- await userOperation(deviceId, false)
106
- const res = await setBiorhythm(cloneDeep({ ...state, planList }), pushFeature)
107
- state.loading = false
108
- if (res.success) {
109
- console.log('设置生物节律 OK')
110
- }
111
- }, [])
112
-
113
- useUpdateEffect(() => {
114
- if (state.planList?.length === 0) {
115
- const data = getDefBiorhythmUIState()
116
- data.planList = data.planList?.map(item => {
117
- return { ...item, icon: `${item.icon}` }
118
- })
119
- setBiorhythm(cloneDeep(data)).then()
120
- }
121
- }, [state.planList])
122
-
123
- const setTimer = value => {
124
- switch (value) {
125
- case 'Sunrise':
126
- return I18n.getLang('bio_ryhthm_default_field_text')
127
- case 'Wake Up':
128
- return I18n.getLang('bio_ryhthm_default_field_text2')
129
- case 'Sunlight':
130
- return I18n.getLang('bio_ryhthm_default_field_text3')
131
- case 'Comfortable':
132
- return I18n.getLang('bio_ryhthm_default_field_text4')
133
- case 'Night light':
134
- return I18n.getLang('bio_ryhthm_default_field_text5')
135
- default:
136
- return value
137
- }
138
- }
139
-
140
- const minimumEnable = useCallback((plan: Plan) => {
141
- let enable = false
142
- state.planList.filter(p => p.index !== plan.index).forEach(item => {
143
- const diff = Math.abs(plan.time - item.time)
144
- if (diff < 15) enable = true
145
- })
146
- return enable
147
- }, [state.planList])
148
-
149
- const nameRepeat = useCallback((plan: Plan) => {
150
- return !!state.planList.filter(p => p.index !== plan.index).find(p => p.name === plan.name)
151
- }, [state.planList])
152
-
153
- const showDeleteBtn = useMemo(() => {
154
- return state.planList?.length > 1
155
- }, [state.planList?.length])
156
-
157
- const { run } = useDebounceFn(requestSetBiorhythm, { wait: 300 })
158
-
159
- useUpdateEffect(() => {
160
- run()
161
- }, [state.flag])
162
-
163
- const replaceImg = (img) => {
164
- const item = iconList?.find(val => val.id === Number(img))
165
- switch (img) {
166
- case 'rhythm_icon1':
167
- case '31':
168
- return { icon: BiologicalRes.biorhythom_Icon1, iconId: 1 }
169
- case 'rhythm_icon2':
170
- case '33':
171
- return { icon: BiologicalRes.biorhythom_Icon5, iconId: 5 }
172
- case 'rhythm_icon3':
173
- case '35':
174
- return { icon: BiologicalRes.biorhythom_Icon2, iconId: 2 }
175
- case 'rhythm_icon4':
176
- case '32':
177
- return { icon: BiologicalRes.biorhythom_Icon9, iconId: 9 }
178
- case 'rhythm_icon12':
179
- case '39':
180
- return { icon: BiologicalRes.biorhythom_Icon3, iconId: 3 }
181
- default:
182
- return { icon: item?.icon, iconId: item?.id }
183
- }
184
- }
185
-
186
- useEffect(() =>{
187
- const weeks: string[] = setDataSource(
188
- biorhythm.repeatPeriod.map(item => {
189
- return item?.enabled ? 1 : 0
190
- })).filter(item => item.enabled)
191
- .map(item => item.title)
192
-
193
- if (weeks.length > 0) {
194
- if (weeks.length === 7) {
195
- state.weekString = I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4')
196
- } else {
197
- state.weekString = I18n.formatValue('timeschedule_add_schedule_text', weeks.join(', '))
198
- }
199
- } else {
200
- state.weekString = I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text2')
201
- }
202
- }, [JSON.stringify(biorhythm.repeatPeriod)])
203
-
204
- useUpdateEffect(() => {
205
- console.log('Redux 生物节律数据更新', biorhythm)
206
- const planList = biorhythm.planList?.map(item => {
207
- return {
208
- ...item,
209
- icon: replaceImg(item?.iconId || item?.icon)?.icon,
210
- iconId: replaceImg(item?.iconId || item?.icon)?.iconId,
211
- }
212
- })
213
- state.enable = biorhythm.enable
214
- state.gradient = biorhythm.gradient
215
- state.repeatPeriod = biorhythm.repeatPeriod
216
- state.planList = planList
217
-
218
- }, [JSON.stringify(biorhythm)])
219
-
220
-
221
- const setImg = (id) => {
222
- const imgIcon = iconList?.find(val => val?.id === Number(id))?.icon
223
- return imgIcon || ''
224
- }
225
-
226
- const openLink = () => {
227
- const url = I18n.getLang('biorhythm_product_link') // 需要打开的链接
228
- Linking.openURL(url).catch((error) => console.error('无法打开链接:', error))
229
- }
230
-
231
- const sunHomeText = string => {
232
- const text = string.split('SUN@HOME')
233
- return text?.length === 1 && <Text style={{ fontSize: cx(14) }}>{text[0]}</Text> ||
234
- <Text style={{
235
- fontSize: cx(14),
236
- flexDirection: 'row',
237
- }}>
238
- <Text>{text[0]}</Text>
239
- <Text onPress={openLink}
240
- style={{
241
- fontFamily: 'helvetica_neue_lt_std_roman',
242
- color: '#ff6600',
243
- textDecorationLine: 'underline',
244
- flexWrap: 'wrap',
245
- }}>SUN@HOME</Text>
246
- <Text>{text[1]}</Text>
247
- </Text>
248
- }
249
-
250
- const randomIcon = () => {
251
- const iconIdList = state.planList?.map(item => {
252
- return item.iconId
253
- })
254
- const allIcon = iconList?.map(item => {
255
- return item.id
256
- })
257
- const availableChart = allIcon.filter((element) => !iconIdList.includes(element))
258
- const randomIndex = Math.floor(Math.random() * availableChart.length)
259
- return availableChart[randomIndex]
260
- }
261
-
262
- return (
263
- <>
264
- <Page
265
- backText={deviceInfo.name}
266
- onBackClick={navigation.goBack}
267
- headlineText={I18n.getLang('add_new_trigger_time_system_back_text')}
268
- headlineContent={<Switch
269
- value={state.enable}
270
- thumbColor={'#f60'}
271
- trackColor={{ false: '#00000026', true: '#ff660036' }}
272
- onValueChange={async enable => {
273
- state.loading = true
274
- state.enable = enable
275
- requestSetBiorhythm(false)
276
- }}
277
- />}
278
- loading={state.loading}
279
- >
280
- <ScrollView nestedScrollEnabled={true} style={{ position: 'relative' }}>
281
- <View style={{ marginHorizontal: cx(24) }}>
282
- {sunHomeText(I18n.getLang(devicesJudge ? 'bio_ryhthm_default_description_text' : 'bio_ryhthm_non_sun_home_products_description_text'))}
283
- </View>
284
- <View style={{ height: cx(10) }} />
285
- <View
286
- style={{
287
- flexDirection: 'row',
288
- justifyContent: 'space-between',
289
- marginHorizontal: cx(24),
290
- }}
291
- >
292
- {state.repeatPeriod.map(period => {
293
- return (
294
- <TouchableOpacity
295
- key={period.title}
296
- onPress={() => {
297
- const periodNum = state.repeatPeriod.filter(p => p.enabled)?.length
298
- if (periodNum === 1 && period.enabled) return
299
- period.enabled = !period.enabled
300
- requestSetBiorhythm(false)
301
- }}
302
- >
303
- <View
304
- style={{
305
- width: cx(40),
306
- height: cx(40),
307
- justifyContent: 'center',
308
- alignItems: 'center',
309
- borderRadius: cx(20),
310
- backgroundColor: period.enabled ? '#ffe0d4' : '#fff',
311
- borderWidth: cx(1),
312
- borderColor: '#f60',
313
- }}
314
- >
315
- <Text
316
- style={{
317
- color: '#FF6600',
318
- textAlign: 'center',
319
- }}
320
- >
321
- {period.title}
322
- </Text>
323
- </View>
324
- </TouchableOpacity>
325
- )
326
- })}
327
- </View>
328
- <View style={{ marginHorizontal: cx(24), marginTop: cx(20) }}>
329
- <Text>{state.weekString}</Text>
330
- </View>
331
- <View style={{ marginHorizontal: cx(24), marginTop: cx(16) }}>
332
- <Text>
333
- {I18n.getLang('bio_ryhthm_default_selectionfield_topic_text')}
334
- </Text>
335
- <TouchableOpacity
336
- onPress={() => {
337
- showGradientTypeSelectModal(true)
338
- }}
339
- >
340
- <View
341
- style={{
342
- flexDirection: 'row',
343
- borderRadius: cx(4),
344
- backgroundColor: '#f6f6f6',
345
- alignItems: 'center',
346
- flex: 1,
347
- height: cx(44),
348
- borderBottomWidth: cx(1),
349
- borderBottomColor: '#cbcbcb',
350
- }}
351
- >
352
- <Text style={{
353
- fontSize: cx(16),
354
- color: '#000',
355
- fontFamily: 'helvetica_neue_lt_std_roman',
356
- paddingLeft: cx(16),
357
- }}>
358
- {
359
- I18n.getLang(
360
- state.gradient === BiorhythmGradientType.DirectGradient
361
- ? 'add_new_dynamic_mood_color_changing_mode_value2'
362
- : 'add_new_dynamic_mood_color_changing_mode_value',
363
- )
364
- }
365
-
366
- </Text>
367
- </View>
368
- </TouchableOpacity>
369
- </View>
370
- <View style={{ height: cx(20) }} />
371
- <TimeCircular
372
- planEdit={true}
373
- planList={state.planList}
374
- onPanMoved={(id, time) => {
375
- state.planList = state.planList.map(plan => {
376
- return {
377
- ...plan,
378
- time: plan.index === id ? time : plan.time,
379
- }
380
- })
381
- state.flag = Symbol()
382
- }}
383
- replaceStatus={devicesJudge}
384
- gradient={state.gradient === BiorhythmGradientType.DirectGradient}
385
- isSupportTemperature={!params.isSupportTemperature} />
386
- <View
387
- style={{
388
- flexDirection: 'row',
389
- justifyContent: 'space-between',
390
- marginHorizontal: cx(24),
391
- marginBottom: cx(-8),
392
- marginTop: cx(26),
393
- }}>
394
- {state.planList.length === 8 && <View
395
- style={{ marginVertical: cx(10), flexDirection: 'row', alignItems: 'center', width: width - cx(48) }}>
396
- <Image style={{ width: cx(16), height: cx(16), tintColor: '#ff9500' }} source={res.ic_warning_amber} />
397
- <Text
398
- style={{
399
- flexWrap: 'wrap',
400
- fontSize: cx(12),
401
- }}>{I18n.getLang('add_new_trigger_time_warning_max_number_text')}</Text>
402
- </View>}
403
- {state.planList.length < 8 &&
404
- <>
405
- <Text
406
- style={{
407
- fontSize: cx(16),
408
- fontWeight: 'bold',
409
- color: 'rgb(0,0,0)',
410
- }}>{I18n.getLang('bio_ryhthm_default_subheadline_text')}</Text>
411
- <TouchableOpacity
412
- onPress={() => {
413
- const ids: number[] = state.planList.map(p => p.index)
414
- const newPlan: Plan = {
415
- index: Math.max(...ids) + 1,
416
- icon: res.rhythm_icon1,
417
- time: 0,
418
- name: '',
419
- colorTemperature: 0,
420
- brightness: 100,
421
- action: [
422
- {
423
- uri: 'model/attribute/set/LightCtrl/ColorTemperature',
424
- startValue: `${colorTemperatureValue(0)}`,
425
- },
426
- {
427
- uri: 'model/attribute/set/LightCtrl/Brightness',
428
- startValue: '100',
429
- },
430
- ],
431
- enable: true,
432
- iconId: randomIcon(),
433
- }
434
- const editPageParams: BiorhythmEditPageParams = {
435
- planData: newPlan,
436
- isAdd: true,
437
- onPlanEdited,
438
- onPlanDelete,
439
- minimumEnable,
440
- nameRepeat,
441
- iconIdList: state.planList?.map(item => {
442
- return item.iconId
443
- }),
444
- isMixRGBWLamp: !!params.isMixLight,
445
- isSupportTemperature: params.isSupportTemperature,
446
- isSupportBrightness: params.isSupportBrightness,
447
- showDeleteBtn
448
- }
449
- navigation.navigate(ui_biz_routerKey.bi_biz_biological_edit, editPageParams)
450
- }}>
451
- <Image source={BiologicalRes.biorhythom_add} style={{ height: cx(24), width: cx(24) }} />
452
- </TouchableOpacity>
453
- </>
454
- }
455
- </View>
456
- <FlatList
457
- data={state.planList}
458
- style={{
459
- flex: 1,
460
- marginTop: cx(12),
461
- }}
462
- nestedScrollEnabled={true}
463
- ListHeaderComponent={() => (<Spacer height={cx(16)} />)}
464
- ItemSeparatorComponent={() => (<Spacer height={cx(16)} />)}
465
- renderItem={({ item }) => {
466
- const type = typeof item?.icon === 'string'
467
- const bgColor = item?.brightness === 0 ? '#000' : !params.isSupportTemperature && cctToColor(1) || cctToColor(item.colorTemperature.toFixed(), item?.brightness)
468
- return (
469
- <Card
470
- style={{ marginHorizontal: cx(24) }}
471
- onPress={() => {
472
- const editPageParams: BiorhythmEditPageParams = {
473
- planData: {
474
- ...item,
475
- name: setTimer(item?.name)
476
- },
477
- isAdd: false,
478
- onPlanEdited,
479
- onPlanDelete,
480
- minimumEnable,
481
- nameRepeat,
482
- iconIdList: state.planList?.map(item => {
483
- return item.iconId
484
- }),
485
- isMixRGBWLamp: !!params.isMixLight,
486
- isSupportTemperature: params.isSupportTemperature,
487
- isSupportBrightness: params.isSupportBrightness,
488
- showDeleteBtn
489
- }
490
- navigation.navigate(ui_biz_routerKey.bi_biz_biological_edit, editPageParams)
491
- }}
492
- >
493
- <View
494
- style={{
495
- flex: 1,
496
- flexDirection: 'column',
497
- }}
498
- >
499
- <View style={{ flex: 1, flexDirection: 'row', justifyContent: 'space-between', marginTop: cx(16) }}>
500
- <View style={{ flexDirection: 'row', justifyContent: 'center', alignItems: 'center' }}>
501
- <Image
502
- source={setImg(item?.iconId) || type && { uri: item?.icon } || item?.icon}
503
- style={{
504
- width: cx(24),
505
- height: cx(24),
506
- marginStart: cx(10),
507
- marginRight: cx(6),
508
- tintColor: '#474e5d',
509
- }}
510
- />
511
- <Text
512
- style={{
513
- fontSize: cx(16),
514
- color: '#000',
515
- fontFamily: 'helvetica_neue_lt_std_roman',
516
- }}
517
- >
518
- {convertMinutesTo12HourFormat(item.time, is24Hour)}
519
- </Text>
520
- </View>
521
- <Switch
522
- value={item.enable}
523
- thumbColor={'#f60'}
524
- trackColor={{ false: '#00000026', true: '#ff660036' }}
525
- onValueChange={e => {
526
- item.enable = e
527
- requestSetBiorhythm()
528
- }}
529
- style={{ marginRight: cx(10) }}
530
- />
531
- </View>
532
- <View style={{ flex: 1, flexDirection: 'row', justifyContent: 'space-between' }}>
533
- <Text
534
- style={{
535
- fontSize: cx(12),
536
- color: '#666',
537
- fontFamily: 'helvetica_neue_lt_std_roman',
538
- paddingLeft: cx(20),
539
- }}
540
- >
541
- {setTimer(item?.name)}
542
- </Text>
543
- </View>
544
- <View
545
- style={{
546
- width: cx(295),
547
- height: cx(24),
548
- backgroundColor: bgColor,
549
- marginLeft: cx(20),
550
- marginTop: cx(5),
551
- marginBottom: cx(24),
552
- borderRadius: cx(8),
553
- }} />
554
- </View>
555
- </Card>
556
- )
557
- }}
558
- keyExtractor={item => `${item.index}`}
559
- ListFooterComponent={() => {
560
- return (
561
- <View style={{ marginHorizontal: cx(24) }}>
562
- <Spacer />
563
- <DeleteButton
564
- text={I18n.getLang('bio_ryhthm_default_button_reset_text')}
565
- textStyle={{
566
- fontSize: cx(16),
567
- color: '#fff',
568
- fontFamily: 'helvetica_neue_lt_std_roman',
569
- }}
570
- onPress={() => {
571
- showCommonDialog({
572
- method: 'confirm',
573
- title: I18n.getLang('bio_ryhthm_reset_description_text'),
574
- onConfirm: (_, { close }) => {
575
- const defBiorhythmUIState = getDefBiorhythmUIState()
576
- state.enable = defBiorhythmUIState.enable
577
- state.gradient = defBiorhythmUIState.gradient
578
- state.repeatPeriod = defBiorhythmUIState.repeatPeriod
579
- state.planList = defBiorhythmUIState.planList
580
- requestSetBiorhythm()
581
- close()
582
- }
583
- })
584
- }}
585
- />
586
- <Spacer />
587
- </View>
588
- )
589
- }}
590
- />
591
- {!state.enable && (
592
- <View
593
- style={{
594
- backgroundColor: 'rgba(0,0,0,.5)',
595
- width: '100%',
596
- height: '100%',
597
- position: 'absolute',
598
- top: 0,
599
- zIndex: 999,
600
- }}
601
- />
602
- )}
603
- </ScrollView>
604
- </Page>
605
- <Modal.List
606
- type={'radio'}
607
- visible={state.showGradientTypeSelectModal}
608
- value={state.gradient}
609
- dataSource={[
610
- {
611
- title: I18n.getLang('add_new_dynamic_mood_color_changing_mode_value'),
612
- key: BiorhythmGradientType.EntireGradient.toString(),
613
- value: BiorhythmGradientType.EntireGradient,
614
- },
615
- {
616
- title: I18n.getLang('add_new_dynamic_mood_color_changing_mode_value2'),
617
- key: BiorhythmGradientType.DirectGradient.toString(),
618
- value: BiorhythmGradientType.DirectGradient,
619
- },
620
- ]}
621
- title={I18n.getLang('add_new_dynamic_mood_color_changing_mode_headline')}
622
- onMaskPress={() => {
623
- showGradientTypeSelectModal(false)
624
- }}
625
- onCancel={() => {
626
- showGradientTypeSelectModal(false)
627
- }}
628
- cancelText={I18n.getLang('auto_scan_system_cancel')}
629
- confirmText={I18n.getLang('auto_scan_system_wifi_confirm')}
630
- onConfirm={(item: BiorhythmGradientType) => {
631
- state.gradient = item
632
- requestSetBiorhythm()
633
- showGradientTypeSelectModal(false)
634
- }}
635
- />
636
- </>
637
- )
638
- }
639
-
640
- export default BiorhythmPage
641
-
642
-
1
+ import React, { useCallback, useEffect, useMemo } from 'react'
2
+ import { FlatList, Image, Linking, ScrollView, Switch, Text, TouchableOpacity, View } from 'react-native'
3
+ import { useNavigation } from '@react-navigation/native'
4
+ import { useDebounceFn, useReactive, useUpdateEffect } from 'ahooks'
5
+ import {
6
+ BiorhythmBean,
7
+ BiorhythmGradientType,
8
+ colorTemperatureValue,
9
+ getDefBiorhythmUIState,
10
+ Plan,
11
+ } from './BiorhythmBean'
12
+ import { Modal, Utils } from 'tuya-panel-kit'
13
+ import { cloneDeep, sortBy } from 'lodash'
14
+ import iconList from './iconListData'
15
+ import pIdList from './pIdList'
16
+ import {
17
+ useDeviceId,
18
+ useDeviceInfo,
19
+ useSystemTimeFormate,
20
+ } from '@ledvance/base/src/models/modules/NativePropsSlice'
21
+ import I18n from '@ledvance/base/src/i18n'
22
+ import res from '@ledvance/base/src/res'
23
+ import { ui_biz_routerKey } from "../../navigation/Routers";
24
+ import BiologicalRes from './res/BiologicalRes'
25
+ import { cctToColor } from '@ledvance/base/src/utils/cctUtils'
26
+ import { setDataSource } from '@ledvance/base/src/components/weekSelect'
27
+ import { BiorhythmEditPageParams } from './BiorhythmEditPage'
28
+ import { useBiorhythm, userOperation } from './BiorhythmActions'
29
+ import { convertMinutesTo12HourFormat, showDialog as showCommonDialog } from '@ledvance/base/src/utils/common'
30
+ import TimeCircular from './circular/TimeCircular'
31
+ import Page from '@ledvance/base/src/components/Page'
32
+ import Card from '@ledvance/base/src/components/Card'
33
+ import Spacer from '@ledvance/base/src/components/Spacer'
34
+ import DeleteButton from '@ledvance/base/src/components/DeleteButton'
35
+ import { useParams } from '@ledvance/base/src/hooks/Hooks'
36
+
37
+ const cx = Utils.RatioUtils.convertX
38
+ const width = Utils.RatioUtils.width
39
+
40
+ interface UIState extends BiorhythmBean {
41
+ showGradientTypeSelectModal: boolean;
42
+ flag: symbol;
43
+ weekString: string,
44
+ timeSchedule: any[]
45
+ loading: boolean
46
+ }
47
+
48
+ export interface BiorhythmPageParams {
49
+ biorhythmDpCode: string
50
+ conflictDps: {
51
+ randomTimeDpCode?: string
52
+ fixedTimeDpCode?: string
53
+ sleepDpCode?: string
54
+ wakeUpDpCode?: string
55
+ }
56
+ isSupportTemperature: boolean
57
+ isSupportBrightness: boolean
58
+ isMixLight?: boolean
59
+ }
60
+
61
+ const BiorhythmPage = () => {
62
+ const params = useParams<BiorhythmPageParams>()
63
+ const navigation = useNavigation()
64
+ const [biorhythm, setBiorhythm] = useBiorhythm(params.biorhythmDpCode)
65
+ const deviceId = useDeviceId()
66
+ const deviceInfo = useDeviceInfo()
67
+ const { productId } = deviceInfo
68
+ const is24Hour = useSystemTimeFormate()
69
+ const devicesJudge = pIdList.some(val => val === productId)
70
+ // const [sleepList, setSleepList] = useSleepPlan({ sleep_mode: params.sleepPlanDp })
71
+ // const [wakeUpList, setWakeUpList] = useWakeUpPlan({ wakeup_mode: params.wakeUpPlanDp })
72
+ // const sleepWakeUpStatus = [...sleepList, ...wakeUpList].some(ele => ele.enable)
73
+ const state = useReactive<UIState>({
74
+ ...biorhythm,
75
+ showGradientTypeSelectModal: false,
76
+ flag: Symbol(),
77
+ weekString: '',
78
+ timeSchedule: [],
79
+ loading: false
80
+ })
81
+
82
+ const showGradientTypeSelectModal = useCallback((show: boolean) => {
83
+ state.showGradientTypeSelectModal = show
84
+ }, [])
85
+
86
+ const onPlanEdited = useCallback((isAdd: boolean, newPlan: Plan) => {
87
+ if (isAdd) {
88
+ state.planList.push(newPlan)
89
+ state.planList = sortBy(state.planList, p => p.time)
90
+ } else {
91
+ state.planList = state.planList.map(plan => (plan.index === newPlan.index ? newPlan : plan))
92
+ }
93
+ state.flag = Symbol()
94
+ }, [])
95
+
96
+ const onPlanDelete = useCallback((id: number) => {
97
+ state.planList = state.planList.filter(plan => plan.index !== id)
98
+ state.flag = Symbol()
99
+ }, [])
100
+
101
+ const requestSetBiorhythm = useCallback(async (pushFeature: boolean = true) => {
102
+ state.loading = true
103
+ const planList = state.planList?.map(item => { return { ...item, icon: `${item.icon}` } })
104
+ .sort((a, b) => a.time - b.time);
105
+ await userOperation(deviceId, false)
106
+ const res = await setBiorhythm(cloneDeep({ ...state, planList }), pushFeature)
107
+ state.loading = false
108
+ if (res.success) {
109
+ console.log('设置生物节律 OK')
110
+ }
111
+ }, [])
112
+
113
+ useUpdateEffect(() => {
114
+ if (state.planList?.length === 0) {
115
+ const data = getDefBiorhythmUIState()
116
+ data.planList = data.planList?.map(item => {
117
+ return { ...item, icon: `${item.icon}` }
118
+ })
119
+ setBiorhythm(cloneDeep(data)).then()
120
+ }
121
+ }, [state.planList])
122
+
123
+ const setTimer = value => {
124
+ switch (value) {
125
+ case 'Sunrise':
126
+ return I18n.getLang('bio_ryhthm_default_field_text')
127
+ case 'Wake Up':
128
+ return I18n.getLang('bio_ryhthm_default_field_text2')
129
+ case 'Sunlight':
130
+ return I18n.getLang('bio_ryhthm_default_field_text3')
131
+ case 'Comfortable':
132
+ return I18n.getLang('bio_ryhthm_default_field_text4')
133
+ case 'Night light':
134
+ return I18n.getLang('bio_ryhthm_default_field_text5')
135
+ default:
136
+ return value
137
+ }
138
+ }
139
+
140
+ const minimumEnable = useCallback((plan: Plan) => {
141
+ let enable = false
142
+ state.planList.filter(p => p.index !== plan.index).forEach(item => {
143
+ const diff = Math.abs(plan.time - item.time)
144
+ if (diff < 15) enable = true
145
+ })
146
+ return enable
147
+ }, [state.planList])
148
+
149
+ const nameRepeat = useCallback((plan: Plan) => {
150
+ return !!state.planList.filter(p => p.index !== plan.index).find(p => p.name === plan.name)
151
+ }, [state.planList])
152
+
153
+ const showDeleteBtn = useMemo(() => {
154
+ return state.planList?.length > 1
155
+ }, [state.planList?.length])
156
+
157
+ const { run } = useDebounceFn(requestSetBiorhythm, { wait: 300 })
158
+
159
+ useUpdateEffect(() => {
160
+ run()
161
+ }, [state.flag])
162
+
163
+ const replaceImg = (img) => {
164
+ const item = iconList?.find(val => val.id === Number(img))
165
+ switch (img) {
166
+ case 'rhythm_icon1':
167
+ case '31':
168
+ return { icon: BiologicalRes.biorhythom_Icon1, iconId: 1 }
169
+ case 'rhythm_icon2':
170
+ case '33':
171
+ return { icon: BiologicalRes.biorhythom_Icon5, iconId: 5 }
172
+ case 'rhythm_icon3':
173
+ case '35':
174
+ return { icon: BiologicalRes.biorhythom_Icon2, iconId: 2 }
175
+ case 'rhythm_icon4':
176
+ case '32':
177
+ return { icon: BiologicalRes.biorhythom_Icon9, iconId: 9 }
178
+ case 'rhythm_icon12':
179
+ case '39':
180
+ return { icon: BiologicalRes.biorhythom_Icon3, iconId: 3 }
181
+ default:
182
+ return { icon: item?.icon, iconId: item?.id }
183
+ }
184
+ }
185
+
186
+ useEffect(() =>{
187
+ const weeks: string[] = setDataSource(
188
+ biorhythm.repeatPeriod.map(item => {
189
+ return item?.enabled ? 1 : 0
190
+ })).filter(item => item.enabled)
191
+ .map(item => item.title)
192
+
193
+ if (weeks.length > 0) {
194
+ if (weeks.length === 7) {
195
+ state.weekString = I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text4')
196
+ } else {
197
+ state.weekString = I18n.formatValue('timeschedule_add_schedule_text', weeks.join(', '))
198
+ }
199
+ } else {
200
+ state.weekString = I18n.getLang('motion_detection_time_schedule_notifications_field_weekdays_text2')
201
+ }
202
+ }, [JSON.stringify(biorhythm.repeatPeriod)])
203
+
204
+ useUpdateEffect(() => {
205
+ console.log('Redux 生物节律数据更新', biorhythm)
206
+ const planList = biorhythm.planList?.map(item => {
207
+ return {
208
+ ...item,
209
+ icon: replaceImg(item?.iconId || item?.icon)?.icon,
210
+ iconId: replaceImg(item?.iconId || item?.icon)?.iconId,
211
+ }
212
+ })
213
+ state.enable = biorhythm.enable
214
+ state.gradient = biorhythm.gradient
215
+ state.repeatPeriod = biorhythm.repeatPeriod
216
+ state.planList = planList
217
+
218
+ }, [JSON.stringify(biorhythm)])
219
+
220
+
221
+ const setImg = (id) => {
222
+ const imgIcon = iconList?.find(val => val?.id === Number(id))?.icon
223
+ return imgIcon || ''
224
+ }
225
+
226
+ const openLink = () => {
227
+ const url = I18n.getLang('biorhythm_product_link') // 需要打开的链接
228
+ Linking.openURL(url).catch((error) => console.error('无法打开链接:', error))
229
+ }
230
+
231
+ const sunHomeText = string => {
232
+ const text = string.split('SUN@HOME')
233
+ return text?.length === 1 && <Text style={{ fontSize: cx(14) }}>{text[0]}</Text> ||
234
+ <Text style={{
235
+ fontSize: cx(14),
236
+ flexDirection: 'row',
237
+ }}>
238
+ <Text>{text[0]}</Text>
239
+ <Text onPress={openLink}
240
+ style={{
241
+ fontFamily: 'helvetica_neue_lt_std_roman',
242
+ color: '#ff6600',
243
+ textDecorationLine: 'underline',
244
+ flexWrap: 'wrap',
245
+ }}>SUN@HOME</Text>
246
+ <Text>{text[1]}</Text>
247
+ </Text>
248
+ }
249
+
250
+ const randomIcon = () => {
251
+ const iconIdList = state.planList?.map(item => {
252
+ return item.iconId
253
+ })
254
+ const allIcon = iconList?.map(item => {
255
+ return item.id
256
+ })
257
+ const availableChart = allIcon.filter((element) => !iconIdList.includes(element))
258
+ const randomIndex = Math.floor(Math.random() * availableChart.length)
259
+ return availableChart[randomIndex]
260
+ }
261
+
262
+ return (
263
+ <>
264
+ <Page
265
+ backText={deviceInfo.name}
266
+ onBackClick={navigation.goBack}
267
+ headlineText={I18n.getLang('add_new_trigger_time_system_back_text')}
268
+ headlineContent={<Switch
269
+ value={state.enable}
270
+ thumbColor={'#f60'}
271
+ trackColor={{ false: '#00000026', true: '#ff660036' }}
272
+ onValueChange={async enable => {
273
+ state.loading = true
274
+ state.enable = enable
275
+ requestSetBiorhythm(false)
276
+ }}
277
+ />}
278
+ loading={state.loading}
279
+ >
280
+ <ScrollView nestedScrollEnabled={true} style={{ position: 'relative' }}>
281
+ <View style={{ marginHorizontal: cx(24) }}>
282
+ {sunHomeText(I18n.getLang(devicesJudge ? 'bio_ryhthm_default_description_text' : 'bio_ryhthm_non_sun_home_products_description_text'))}
283
+ </View>
284
+ <View style={{ height: cx(10) }} />
285
+ <View
286
+ style={{
287
+ flexDirection: 'row',
288
+ justifyContent: 'space-between',
289
+ marginHorizontal: cx(24),
290
+ }}
291
+ >
292
+ {state.repeatPeriod.map(period => {
293
+ return (
294
+ <TouchableOpacity
295
+ key={period.title}
296
+ onPress={() => {
297
+ const periodNum = state.repeatPeriod.filter(p => p.enabled)?.length
298
+ if (periodNum === 1 && period.enabled) return
299
+ period.enabled = !period.enabled
300
+ requestSetBiorhythm(false)
301
+ }}
302
+ >
303
+ <View
304
+ style={{
305
+ width: cx(40),
306
+ height: cx(40),
307
+ justifyContent: 'center',
308
+ alignItems: 'center',
309
+ borderRadius: cx(20),
310
+ backgroundColor: period.enabled ? '#ffe0d4' : '#fff',
311
+ borderWidth: cx(1),
312
+ borderColor: '#f60',
313
+ }}
314
+ >
315
+ <Text
316
+ style={{
317
+ color: '#FF6600',
318
+ textAlign: 'center',
319
+ }}
320
+ >
321
+ {period.title}
322
+ </Text>
323
+ </View>
324
+ </TouchableOpacity>
325
+ )
326
+ })}
327
+ </View>
328
+ <View style={{ marginHorizontal: cx(24), marginTop: cx(20) }}>
329
+ <Text>{state.weekString}</Text>
330
+ </View>
331
+ <View style={{ marginHorizontal: cx(24), marginTop: cx(16) }}>
332
+ <Text>
333
+ {I18n.getLang('bio_ryhthm_default_selectionfield_topic_text')}
334
+ </Text>
335
+ <TouchableOpacity
336
+ onPress={() => {
337
+ showGradientTypeSelectModal(true)
338
+ }}
339
+ >
340
+ <View
341
+ style={{
342
+ flexDirection: 'row',
343
+ borderRadius: cx(4),
344
+ backgroundColor: '#f6f6f6',
345
+ alignItems: 'center',
346
+ flex: 1,
347
+ height: cx(44),
348
+ borderBottomWidth: cx(1),
349
+ borderBottomColor: '#cbcbcb',
350
+ }}
351
+ >
352
+ <Text style={{
353
+ fontSize: cx(16),
354
+ color: '#000',
355
+ fontFamily: 'helvetica_neue_lt_std_roman',
356
+ paddingLeft: cx(16),
357
+ }}>
358
+ {
359
+ I18n.getLang(
360
+ state.gradient === BiorhythmGradientType.DirectGradient
361
+ ? 'add_new_dynamic_mood_color_changing_mode_value2'
362
+ : 'add_new_dynamic_mood_color_changing_mode_value',
363
+ )
364
+ }
365
+
366
+ </Text>
367
+ </View>
368
+ </TouchableOpacity>
369
+ </View>
370
+ <View style={{ height: cx(20) }} />
371
+ <TimeCircular
372
+ planEdit={true}
373
+ planList={state.planList}
374
+ onPanMoved={(id, time) => {
375
+ state.planList = state.planList.map(plan => {
376
+ return {
377
+ ...plan,
378
+ time: plan.index === id ? time : plan.time,
379
+ }
380
+ })
381
+ state.flag = Symbol()
382
+ }}
383
+ replaceStatus={devicesJudge}
384
+ gradient={state.gradient === BiorhythmGradientType.DirectGradient}
385
+ isSupportTemperature={!params.isSupportTemperature} />
386
+ <View
387
+ style={{
388
+ flexDirection: 'row',
389
+ justifyContent: 'space-between',
390
+ marginHorizontal: cx(24),
391
+ marginBottom: cx(-8),
392
+ marginTop: cx(26),
393
+ }}>
394
+ {state.planList.length === 8 && <View
395
+ style={{ marginVertical: cx(10), flexDirection: 'row', alignItems: 'center', width: width - cx(48) }}>
396
+ <Image style={{ width: cx(16), height: cx(16), tintColor: '#ff9500' }} source={res.ic_warning_amber} />
397
+ <Text
398
+ style={{
399
+ flexWrap: 'wrap',
400
+ fontSize: cx(12),
401
+ }}>{I18n.getLang('add_new_trigger_time_warning_max_number_text')}</Text>
402
+ </View>}
403
+ {state.planList.length < 8 &&
404
+ <>
405
+ <Text
406
+ style={{
407
+ fontSize: cx(16),
408
+ fontWeight: 'bold',
409
+ color: 'rgb(0,0,0)',
410
+ }}>{I18n.getLang('bio_ryhthm_default_subheadline_text')}</Text>
411
+ <TouchableOpacity
412
+ onPress={() => {
413
+ const ids: number[] = state.planList.map(p => p.index)
414
+ const newPlan: Plan = {
415
+ index: Math.max(...ids) + 1,
416
+ icon: res.rhythm_icon1,
417
+ time: 0,
418
+ name: '',
419
+ colorTemperature: 0,
420
+ brightness: 100,
421
+ action: [
422
+ {
423
+ uri: 'model/attribute/set/LightCtrl/ColorTemperature',
424
+ startValue: `${colorTemperatureValue(0)}`,
425
+ },
426
+ {
427
+ uri: 'model/attribute/set/LightCtrl/Brightness',
428
+ startValue: '100',
429
+ },
430
+ ],
431
+ enable: true,
432
+ iconId: randomIcon(),
433
+ }
434
+ const editPageParams: BiorhythmEditPageParams = {
435
+ planData: newPlan,
436
+ isAdd: true,
437
+ onPlanEdited,
438
+ onPlanDelete,
439
+ minimumEnable,
440
+ nameRepeat,
441
+ iconIdList: state.planList?.map(item => {
442
+ return item.iconId
443
+ }),
444
+ isMixRGBWLamp: !!params.isMixLight,
445
+ isSupportTemperature: params.isSupportTemperature,
446
+ isSupportBrightness: params.isSupportBrightness,
447
+ showDeleteBtn
448
+ }
449
+ navigation.navigate(ui_biz_routerKey.bi_biz_biological_edit, editPageParams)
450
+ }}>
451
+ <Image source={BiologicalRes.biorhythom_add} style={{ height: cx(24), width: cx(24) }} />
452
+ </TouchableOpacity>
453
+ </>
454
+ }
455
+ </View>
456
+ <FlatList
457
+ data={state.planList}
458
+ style={{
459
+ flex: 1,
460
+ marginTop: cx(12),
461
+ }}
462
+ nestedScrollEnabled={true}
463
+ ListHeaderComponent={() => (<Spacer height={cx(16)} />)}
464
+ ItemSeparatorComponent={() => (<Spacer height={cx(16)} />)}
465
+ renderItem={({ item }) => {
466
+ const type = typeof item?.icon === 'string'
467
+ const bgColor = item?.brightness === 0 ? '#000' : !params.isSupportTemperature && cctToColor(1) || cctToColor(item.colorTemperature.toFixed(), item?.brightness)
468
+ return (
469
+ <Card
470
+ style={{ marginHorizontal: cx(24) }}
471
+ onPress={() => {
472
+ const editPageParams: BiorhythmEditPageParams = {
473
+ planData: {
474
+ ...item,
475
+ name: setTimer(item?.name)
476
+ },
477
+ isAdd: false,
478
+ onPlanEdited,
479
+ onPlanDelete,
480
+ minimumEnable,
481
+ nameRepeat,
482
+ iconIdList: state.planList?.map(item => {
483
+ return item.iconId
484
+ }),
485
+ isMixRGBWLamp: !!params.isMixLight,
486
+ isSupportTemperature: params.isSupportTemperature,
487
+ isSupportBrightness: params.isSupportBrightness,
488
+ showDeleteBtn
489
+ }
490
+ navigation.navigate(ui_biz_routerKey.bi_biz_biological_edit, editPageParams)
491
+ }}
492
+ >
493
+ <View
494
+ style={{
495
+ flex: 1,
496
+ flexDirection: 'column',
497
+ }}
498
+ >
499
+ <View style={{ flex: 1, flexDirection: 'row', justifyContent: 'space-between', marginTop: cx(16) }}>
500
+ <View style={{ flexDirection: 'row', justifyContent: 'center', alignItems: 'center' }}>
501
+ <Image
502
+ source={setImg(item?.iconId) || type && { uri: item?.icon } || item?.icon}
503
+ style={{
504
+ width: cx(24),
505
+ height: cx(24),
506
+ marginStart: cx(10),
507
+ marginRight: cx(6),
508
+ tintColor: '#474e5d',
509
+ }}
510
+ />
511
+ <Text
512
+ style={{
513
+ fontSize: cx(16),
514
+ color: '#000',
515
+ fontFamily: 'helvetica_neue_lt_std_roman',
516
+ }}
517
+ >
518
+ {convertMinutesTo12HourFormat(item.time, is24Hour)}
519
+ </Text>
520
+ </View>
521
+ <Switch
522
+ value={item.enable}
523
+ thumbColor={'#f60'}
524
+ trackColor={{ false: '#00000026', true: '#ff660036' }}
525
+ onValueChange={e => {
526
+ item.enable = e
527
+ requestSetBiorhythm()
528
+ }}
529
+ style={{ marginRight: cx(10) }}
530
+ />
531
+ </View>
532
+ <View style={{ flex: 1, flexDirection: 'row', justifyContent: 'space-between' }}>
533
+ <Text
534
+ style={{
535
+ fontSize: cx(12),
536
+ color: '#666',
537
+ fontFamily: 'helvetica_neue_lt_std_roman',
538
+ paddingLeft: cx(20),
539
+ }}
540
+ >
541
+ {setTimer(item?.name)}
542
+ </Text>
543
+ </View>
544
+ <View
545
+ style={{
546
+ width: cx(295),
547
+ height: cx(24),
548
+ backgroundColor: bgColor,
549
+ marginLeft: cx(20),
550
+ marginTop: cx(5),
551
+ marginBottom: cx(24),
552
+ borderRadius: cx(8),
553
+ }} />
554
+ </View>
555
+ </Card>
556
+ )
557
+ }}
558
+ keyExtractor={item => `${item.index}`}
559
+ ListFooterComponent={() => {
560
+ return (
561
+ <View style={{ marginHorizontal: cx(24) }}>
562
+ <Spacer />
563
+ <DeleteButton
564
+ text={I18n.getLang('bio_ryhthm_default_button_reset_text')}
565
+ textStyle={{
566
+ fontSize: cx(16),
567
+ color: '#fff',
568
+ fontFamily: 'helvetica_neue_lt_std_roman',
569
+ }}
570
+ onPress={() => {
571
+ showCommonDialog({
572
+ method: 'confirm',
573
+ title: I18n.getLang('bio_ryhthm_reset_description_text'),
574
+ onConfirm: (_, { close }) => {
575
+ const defBiorhythmUIState = getDefBiorhythmUIState()
576
+ state.enable = defBiorhythmUIState.enable
577
+ state.gradient = defBiorhythmUIState.gradient
578
+ state.repeatPeriod = defBiorhythmUIState.repeatPeriod
579
+ state.planList = defBiorhythmUIState.planList
580
+ requestSetBiorhythm()
581
+ close()
582
+ }
583
+ })
584
+ }}
585
+ />
586
+ <Spacer />
587
+ </View>
588
+ )
589
+ }}
590
+ />
591
+ {!state.enable && (
592
+ <View
593
+ style={{
594
+ backgroundColor: 'rgba(0,0,0,.5)',
595
+ width: '100%',
596
+ height: '100%',
597
+ position: 'absolute',
598
+ top: 0,
599
+ zIndex: 999,
600
+ }}
601
+ />
602
+ )}
603
+ </ScrollView>
604
+ </Page>
605
+ <Modal.List
606
+ type={'radio'}
607
+ visible={state.showGradientTypeSelectModal}
608
+ value={state.gradient}
609
+ dataSource={[
610
+ {
611
+ title: I18n.getLang('add_new_dynamic_mood_color_changing_mode_value'),
612
+ key: BiorhythmGradientType.EntireGradient.toString(),
613
+ value: BiorhythmGradientType.EntireGradient,
614
+ },
615
+ {
616
+ title: I18n.getLang('add_new_dynamic_mood_color_changing_mode_value2'),
617
+ key: BiorhythmGradientType.DirectGradient.toString(),
618
+ value: BiorhythmGradientType.DirectGradient,
619
+ },
620
+ ]}
621
+ title={I18n.getLang('add_new_dynamic_mood_color_changing_mode_headline')}
622
+ onMaskPress={() => {
623
+ showGradientTypeSelectModal(false)
624
+ }}
625
+ onCancel={() => {
626
+ showGradientTypeSelectModal(false)
627
+ }}
628
+ cancelText={I18n.getLang('auto_scan_system_cancel')}
629
+ confirmText={I18n.getLang('auto_scan_system_wifi_confirm')}
630
+ onConfirm={(item: BiorhythmGradientType) => {
631
+ state.gradient = item
632
+ requestSetBiorhythm()
633
+ showGradientTypeSelectModal(false)
634
+ }}
635
+ />
636
+ </>
637
+ )
638
+ }
639
+
640
+ export default BiorhythmPage
641
+
642
+