@ledvance/ui-biz-bundle 1.1.59 → 1.1.62

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 (122) hide show
  1. package/package.json +1 -1
  2. package/src/modules/biorhythm/BiorhythmPage.tsx +2 -0
  3. package/src/modules/flags/FlagActions.ts +1 -0
  4. package/src/modules/flags/FlagEditPage.tsx +22 -14
  5. package/src/modules/flags/FlagPage.tsx +9 -19
  6. package/src/modules/mood/DynamicMoodEditorPage.tsx +12 -14
  7. package/src/modules/mood/FantasyMoodEditPage.tsx +12 -14
  8. package/src/modules/mood/StaticMoodEditorPage.tsx +12 -13
  9. package/src/modules/timer/TimerPage.tsx +58 -56
  10. package/src/newModules/biorhythm/BiorhythmActions.ts +374 -0
  11. package/src/newModules/biorhythm/BiorhythmBean.ts +230 -0
  12. package/src/newModules/biorhythm/BiorhythmEditPage.tsx +267 -0
  13. package/src/newModules/biorhythm/BiorhythmPage.tsx +638 -0
  14. package/src/newModules/biorhythm/IconSelect.tsx +85 -0
  15. package/src/newModules/biorhythm/Router.ts +34 -0
  16. package/src/newModules/biorhythm/circular/ItemIcon.d.ts +22 -0
  17. package/src/newModules/biorhythm/circular/ItemIcon.tsx +173 -0
  18. package/src/newModules/biorhythm/circular/Progress.d.ts +24 -0
  19. package/src/newModules/biorhythm/circular/Progress.tsx +372 -0
  20. package/src/newModules/biorhythm/circular/TimeCircular.d.ts +11 -0
  21. package/src/newModules/biorhythm/circular/TimeCircular.tsx +64 -0
  22. package/src/newModules/biorhythm/circular/biorhythm_plantimer.png +0 -0
  23. package/src/newModules/biorhythm/circular/rhythm_icon.png +0 -0
  24. package/src/newModules/biorhythm/iconListData.ts +30 -0
  25. package/src/newModules/biorhythm/pIdList.ts +36 -0
  26. package/src/newModules/biorhythm/res/BiologicalRes.d.ts +43 -0
  27. package/src/newModules/biorhythm/res/BiologicalRes.ts +42 -0
  28. package/src/newModules/biorhythm/res/Biological_Rhythm.png +0 -0
  29. package/src/newModules/biorhythm/res/Biological_Rhythm_12.png +0 -0
  30. package/src/newModules/biorhythm/res/Biological_Rhythm_new.png +0 -0
  31. package/src/newModules/biorhythm/res/Biological_Rhythm_new_12.png +0 -0
  32. package/src/newModules/biorhythm/res/iconsMaterialOutlinedAccountGroups.png +0 -0
  33. package/src/newModules/biorhythm/res/iconsMaterialOutlinedAccountGroups@2x.png +0 -0
  34. package/src/newModules/biorhythm/res/iconsMaterialOutlinedAccountGroups@3x.png +0 -0
  35. package/src/newModules/biorhythm/res/iconsMaterialOutlinedArrowsNavAdd.png +0 -0
  36. package/src/newModules/biorhythm/res/iconsMaterialOutlinedArrowsNavAdd@2x.png +0 -0
  37. package/src/newModules/biorhythm/res/iconsMaterialOutlinedArrowsNavAdd@3x.png +0 -0
  38. package/src/newModules/biorhythm/res/iconsMaterialOutlinedArrowsNavArrowForwardIos.png +0 -0
  39. package/src/newModules/biorhythm/res/iconsMaterialOutlinedArrowsNavArrowForwardIos@2x.png +0 -0
  40. package/src/newModules/biorhythm/res/iconsMaterialOutlinedArrowsNavArrowForwardIos@3x.png +0 -0
  41. package/src/newModules/biorhythm/res/iconsMaterialOutlinedBuildingsHome.png +0 -0
  42. package/src/newModules/biorhythm/res/iconsMaterialOutlinedBuildingsHome@2x.png +0 -0
  43. package/src/newModules/biorhythm/res/iconsMaterialOutlinedBuildingsHome@3x.png +0 -0
  44. package/src/newModules/biorhythm/res/iconsMaterialOutlinedEditorFavoriteBorder.png +0 -0
  45. package/src/newModules/biorhythm/res/iconsMaterialOutlinedEditorFavoriteBorder@2x.png +0 -0
  46. package/src/newModules/biorhythm/res/iconsMaterialOutlinedEditorFavoriteBorder@3x.png +0 -0
  47. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherBed.png +0 -0
  48. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherBed@2x.png +0 -0
  49. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherBed@3x.png +0 -0
  50. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherBusinessCenter.png +0 -0
  51. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherBusinessCenter@2x.png +0 -0
  52. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherBusinessCenter@3x.png +0 -0
  53. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherChair.png +0 -0
  54. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherChair@2x.png +0 -0
  55. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherChair@3x.png +0 -0
  56. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherCoffee.png +0 -0
  57. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherCoffee@2x.png +0 -0
  58. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherCoffee@3x.png +0 -0
  59. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherDirectionsCar.png +0 -0
  60. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherDirectionsCar@2x.png +0 -0
  61. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherDirectionsCar@3x.png +0 -0
  62. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherFitnessCenter.png +0 -0
  63. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherFitnessCenter@2x.png +0 -0
  64. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherFitnessCenter@3x.png +0 -0
  65. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherHeadphones.png +0 -0
  66. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherHeadphones@2x.png +0 -0
  67. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherHeadphones@3x.png +0 -0
  68. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherMenuBook.png +0 -0
  69. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherMenuBook@2x.png +0 -0
  70. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherMenuBook@3x.png +0 -0
  71. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherMusicNote.png +0 -0
  72. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherMusicNote@2x.png +0 -0
  73. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherMusicNote@3x.png +0 -0
  74. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherNotificationsNone.png +0 -0
  75. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherNotificationsNone@2x.png +0 -0
  76. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherNotificationsNone@3x.png +0 -0
  77. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherPottedPlant.png +0 -0
  78. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherPottedPlant@2x.png +0 -0
  79. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherPottedPlant@3x.png +0 -0
  80. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherRestaurant.png +0 -0
  81. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherRestaurant@2x.png +0 -0
  82. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherRestaurant@3x.png +0 -0
  83. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherSentimentSatisfied.png +0 -0
  84. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherSentimentSatisfied@2x.png +0 -0
  85. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherSentimentSatisfied@3x.png +0 -0
  86. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherSportsEsports.png +0 -0
  87. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherSportsEsports@2x.png +0 -0
  88. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherSportsEsports@3x.png +0 -0
  89. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherTv.png +0 -0
  90. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherTv@2x.png +0 -0
  91. package/src/newModules/biorhythm/res/iconsMaterialOutlinedOtherTv@3x.png +0 -0
  92. package/src/newModules/biorhythm/res/iconsMaterialOutlinedTimeAccessAlarm.png +0 -0
  93. package/src/newModules/biorhythm/res/iconsMaterialOutlinedTimeAccessAlarm@2x.png +0 -0
  94. package/src/newModules/biorhythm/res/iconsMaterialOutlinedTimeAccessAlarm@3x.png +0 -0
  95. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherBedtime.png +0 -0
  96. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherBedtime@2x.png +0 -0
  97. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherBedtime@3x.png +0 -0
  98. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherPartlyCloudyDay.png +0 -0
  99. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherPartlyCloudyDay@2x.png +0 -0
  100. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherPartlyCloudyDay@3x.png +0 -0
  101. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherStarOutline.png +0 -0
  102. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherStarOutline@2x.png +0 -0
  103. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherStarOutline@3x.png +0 -0
  104. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherWbSunny.png +0 -0
  105. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherWbSunny@2x.png +0 -0
  106. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherWbSunny@3x.png +0 -0
  107. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherWbTwilight.png +0 -0
  108. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherWbTwilight@2x.png +0 -0
  109. package/src/newModules/biorhythm/res/iconsMaterialOutlinedWheatherWbTwilight@3x.png +0 -0
  110. package/src/newModules/energyConsumption/EnergyConsumptionDetail.tsx +84 -83
  111. package/src/newModules/energyConsumption/EnergyConsumptionPage.tsx +133 -132
  112. package/src/newModules/energyConsumption/component/EnergyModal.tsx +119 -117
  113. package/src/newModules/energyConsumption/component/Overview.tsx +38 -36
  114. package/src/newModules/mood/AddMoodPage.tsx +37 -21
  115. package/src/newModules/mood/DynamicMoodEditorPage.tsx +7 -2
  116. package/src/newModules/mood/MixDynamicMoodEditor.tsx +8 -2
  117. package/src/newModules/mood/StaticMoodEditorPage.tsx +9 -2
  118. package/src/newModules/timeSchedule/Interface.ts +1 -0
  119. package/src/newModules/timeSchedule/TimeScheduleDetailPage.tsx +203 -202
  120. package/src/newModules/timeSchedule/TimeSchedulePage.tsx +35 -34
  121. package/src/newModules/timeSchedule/components/ManuaSettings.tsx +11 -10
  122. package/src/newModules/timeSchedule/components/ScheduleCard.tsx +63 -60
@@ -0,0 +1,374 @@
1
+ import {
2
+ BiorhythmBean,
3
+ BiorhythmGradientType,
4
+ BiorhythmGradientTypeMap,
5
+ BiorhythmGradientTypeMap2,
6
+ colorTemperatureValue,
7
+ colorTempPercent,
8
+ getDefRepeatPeriod,
9
+ Period,
10
+ Plan,
11
+ RemoteBiorhythmBean,
12
+ } from './BiorhythmBean'
13
+ import { useCallback, useEffect, useState } from 'react'
14
+ import { NativeResult, Result } from '@ledvance/base/src/models/modules/Result'
15
+ import { useDeviceId, useDp } from '@ledvance/base/src/models/modules/NativePropsSlice'
16
+ import { getFeature, NativeApi, putFeature } from '@ledvance/base/src/api/native'
17
+ import { hex2Int, spliceByStep } from '@ledvance/base/src/utils/common'
18
+ import I18n from '@ledvance/base/src/i18n'
19
+ import BiologicalRes from './res/BiologicalRes'
20
+ import dayjs from 'dayjs'
21
+ import { to16 } from '@tuya/tuya-panel-lamp-sdk/lib/utils'
22
+ import { useUpdateEffect } from 'ahooks'
23
+
24
+ type UseBiorhythmType = (dpKey: string, disabledFeature?: boolean) => [BiorhythmBean, SetBiorhythmType];
25
+ type SetBiorhythmType = (biorhythmObj: BiorhythmBean, pushFeature?: boolean) => Promise<Result<any>>;
26
+ let biorhythmTimer: undefined | number = undefined
27
+
28
+ export const useBiorhythm: UseBiorhythmType = (dpKey: string, disabledFeature?: boolean) => {
29
+ const [dp, setDp] = useDp<string, (v: string) => any>(dpKey)
30
+ const deviceId = useDeviceId()
31
+ const [biorhythmState, setBiorhythmState] = useState(dp2Obj(dp))
32
+
33
+ const getBiorhythm = useCallback(() =>{
34
+ const biorhythm = dp2Obj(dp)
35
+ getRemoteBiorhythm(deviceId, biorhythm).then(res => {
36
+ if (res.success && res.data) {
37
+ setBiorhythmState(dto2Vo({
38
+ ...res.data,
39
+ enable: biorhythm.enable,
40
+ repeatPeriod: biorhythm.repeatPeriod.filter(r => r.enabled).map(r => r.index),
41
+ gradientWay: BiorhythmGradientTypeMap[biorhythm.gradient]
42
+ }))
43
+ }
44
+ })
45
+ }, [dp])
46
+
47
+ useEffect(() => {
48
+ if(disabledFeature) return
49
+ biorhythmTimer = setTimeout(() =>{
50
+ getBiorhythm()
51
+ }, 250)
52
+
53
+ return () =>{
54
+ clearTimeout(biorhythmTimer)
55
+ }
56
+ }, [])
57
+
58
+ useUpdateEffect(() =>{
59
+ getBiorhythm()
60
+ }, [dp])
61
+
62
+ const setBiorhythmFn = async (biorhythmObj: BiorhythmBean, pushFeature: boolean = true) =>{
63
+ const dpValue = obj2Dp(biorhythmObj)
64
+ if(pushFeature){
65
+ const putFeatureRes = await putFeature(deviceId, biorhythmFeatureId, vo2Dto(biorhythmObj))
66
+ if (putFeatureRes.result) {
67
+ return setDp(dpValue)
68
+ }
69
+ }else{
70
+ return setDp(dpValue)
71
+ }
72
+ return { success: false }
73
+ }
74
+ return [biorhythmState, setBiorhythmFn]
75
+ }
76
+
77
+ const biorhythmFeatureId = 'Biorhythm'
78
+
79
+ async function getRemoteBiorhythm(deviceId: string, defBiorhythmState: BiorhythmBean): Promise<Result<RemoteBiorhythmBean>> {
80
+ const res: NativeResult<RemoteBiorhythmBean> = await getFeature(deviceId, biorhythmFeatureId)
81
+ if (!res.data) {
82
+ const defData = vo2Dto(defBiorhythmState)
83
+ const pushRes = await putFeature(deviceId, biorhythmFeatureId, defData)
84
+ if (pushRes.result) {
85
+ return getRemoteBiorhythm(deviceId, defBiorhythmState)
86
+ }
87
+ return {
88
+ success: false,
89
+ msg: pushRes.msg,
90
+ }
91
+ }
92
+ return {
93
+ success: true,
94
+ data: res.data,
95
+ }
96
+ }
97
+
98
+ export const userOperation = async (deviceId: string, value: boolean) => {
99
+ const currentTime = dayjs().format('YYYY-MM-DD')
100
+ const json = JSON.stringify({ status: value, suspendTime: value && currentTime || '' })
101
+ return await NativeApi.putJson(deviceId, 'suspendTime', json)
102
+ }
103
+
104
+ export function dp2Obj(dp: string): BiorhythmBean {
105
+ if (!dp || dp === '0000000000') {
106
+ return dp2Obj('0000007f0501060000000000000001061e00000000141901090000000000646401140000000000503201171e000000000000')
107
+ }
108
+ let dpCopy = dp
109
+ // 版本
110
+ hex2Int(dpCopy.slice(0, 2))
111
+ dpCopy = dpCopy.slice(2)
112
+ // 开关
113
+ const enable = hex2Int(dpCopy.slice(0, 2)) === 1
114
+ dpCopy = dpCopy.slice(2)
115
+ // 模式:00 全程渐变,0F 直接渐变
116
+ const gradient =
117
+ dpCopy.slice(0, 2).toLowerCase() === '00'
118
+ ? BiorhythmGradientType.EntireGradient
119
+ : BiorhythmGradientType.DirectGradient
120
+ dpCopy = dpCopy.slice(2)
121
+ // 重复周期
122
+ const repeatPeriod: Period[] = hex2Int(dpCopy.slice(0, 2))
123
+ .toString(2)
124
+ .padStart(7, '0')
125
+ .split('')
126
+ .reverse()
127
+ .map((p, index) => {
128
+ return {
129
+ index: index === 0 ? 7 : index,
130
+ title: getRepeatPeriodTitleByIndex(index),
131
+ enabled: p === '1',
132
+ }
133
+ })
134
+ dpCopy = dpCopy.slice(2)
135
+ // 节点个数 (每个节点长度18),最多8个节点
136
+ hex2Int(dpCopy.slice(0, 2))
137
+ dpCopy = dpCopy.slice(2)
138
+ // 节点列表
139
+ const planList: Plan[] = dpCopy === '00' ? [] : spliceByStep(dpCopy, 18).map((planHex, index) => {
140
+ let hex = planHex
141
+ // 节点开关
142
+ const enable = hex2Int(hex.slice(0, 2)) === 1
143
+ hex = hex.slice(2)
144
+ // 小时
145
+ const hour = hex2Int(hex.slice(0, 2))
146
+ hex = hex.slice(2)
147
+ // 分钟
148
+ const minute = hex2Int(hex.slice(0, 2))
149
+ hex = hex.slice(2)
150
+ const time = hour * 60 + minute
151
+ // 色调 (色相)
152
+ hex2Int(hex.slice(0, 4))
153
+ hex = hex.slice(4)
154
+ // 饱和度
155
+ hex2Int(hex.slice(0, 2))
156
+ hex = hex.slice(2)
157
+ // 明度
158
+ hex2Int(hex.slice(0, 2))
159
+ hex = hex.slice(2)
160
+ // 亮度
161
+ const brightness = hex2Int(hex.slice(0, 2))
162
+ hex = hex.slice(2)
163
+ // 色温
164
+ const colorTemperature = hex2Int(hex.slice(0, 2))
165
+ return {
166
+ index,
167
+ enable,
168
+ icon: getNodeIconByIndex(index).icon,
169
+ iconId: getNodeIconByIndex(index).iconId,
170
+ time,
171
+ name: getNodeNameByIndex(index),
172
+ colorTemperature,
173
+ brightness,
174
+ action: [
175
+ {
176
+ uri: 'model/attribute/set/LightCtrl/ColorTemperature',
177
+ startValue: `${colorTemperatureValue(colorTemperature)}`,
178
+ },
179
+ {
180
+ uri: 'model/attribute/set/LightCtrl/Brightness',
181
+ startValue: `${brightness}`,
182
+ },
183
+ ],
184
+ }
185
+ })
186
+ return {
187
+ enable: enable,
188
+ gradient: gradient,
189
+ repeatPeriod: repeatPeriod,
190
+ planList: planList,
191
+ }
192
+ }
193
+
194
+ function getNodeNameByIndex(index: number): string {
195
+ switch (index) {
196
+ case 0:
197
+ return I18n.getLang('bio_ryhthm_default_field_text')
198
+ case 1:
199
+ return I18n.getLang('bio_ryhthm_default_field_text2')
200
+ case 2:
201
+ return I18n.getLang('bio_ryhthm_default_field_text3')
202
+ case 3:
203
+ return I18n.getLang('bio_ryhthm_default_field_text4')
204
+ case 4:
205
+ return I18n.getLang('bio_ryhthm_default_field_text5')
206
+ default:
207
+ return `Node ${index + 1}`
208
+ }
209
+ }
210
+
211
+ interface NodeIcon {
212
+ icon: string
213
+ iconId: number
214
+ }
215
+
216
+ function getNodeIconByIndex(index: number): NodeIcon {
217
+ switch (index) {
218
+ case 0:
219
+ return {
220
+ icon: BiologicalRes.rhythm_icon1,
221
+ iconId: 1
222
+ }
223
+ case 1:
224
+ return {
225
+ icon: BiologicalRes.rhythm_icon2,
226
+ iconId: 2
227
+ }
228
+ case 2:
229
+ return {
230
+ icon: BiologicalRes.rhythm_icon3,
231
+ iconId: 9
232
+ }
233
+ case 3:
234
+ return {
235
+ icon: BiologicalRes.rhythm_icon4,
236
+ iconId: 3
237
+ }
238
+ case 4:
239
+ return {
240
+ icon: BiologicalRes.rhythm_icon12,
241
+ iconId: 5
242
+ }
243
+ case 5:
244
+ return {
245
+ icon: BiologicalRes.rhythm_icon1,
246
+ iconId: 1
247
+ }
248
+ case 6:
249
+ return {
250
+ icon: BiologicalRes.rhythm_icon2,
251
+ iconId: 2
252
+ }
253
+ case 7:
254
+ return {
255
+ icon: BiologicalRes.rhythm_icon3,
256
+ iconId: 9
257
+ }
258
+ default:
259
+ return {
260
+ icon: BiologicalRes.rhythm_icon1,
261
+ iconId: 1
262
+ }
263
+ }
264
+ }
265
+
266
+ function getRepeatPeriodTitleByIndex(index: number): string {
267
+ let title = ''
268
+ switch (index) {
269
+ case 0:
270
+ title = I18n.getLang('bio_ryhthm_default_weekday7_text')
271
+ break
272
+ case 1:
273
+ title = I18n.getLang('bio_ryhthm_default_weekday1_text')
274
+ break
275
+ case 2:
276
+ title = I18n.getLang('bio_ryhthm_default_weekday2_text')
277
+ break
278
+ case 3:
279
+ title = I18n.getLang('bio_ryhthm_default_weekday3_text')
280
+ break
281
+ case 4:
282
+ title = I18n.getLang('bio_ryhthm_default_weekday4_text')
283
+ break
284
+ case 5:
285
+ title = I18n.getLang('bio_ryhthm_default_weekday5_text')
286
+ break
287
+ case 6:
288
+ title = I18n.getLang('bio_ryhthm_default_weekday6_text')
289
+ break
290
+ }
291
+ return title
292
+ }
293
+
294
+ function obj2Dp(obj: BiorhythmBean): string {
295
+ const versionHex = '00'
296
+ const enableHex = obj.enable ? '01' : '00'
297
+ const gradientHex = obj.gradient === BiorhythmGradientType.EntireGradient ? '00' : '0F'
298
+ const repeatPeriodHex = parseInt(
299
+ obj.repeatPeriod
300
+ .map(p => (p.enabled ? '1' : '0'))
301
+ .reverse()
302
+ .join(''),
303
+ 2,
304
+ )
305
+ .toString(16)
306
+ .padStart(2, '0')
307
+ const planCountHex = obj.planList.length.toString(16).padStart(2, '0')
308
+ const planListHex = obj.planList
309
+ .map(plan => {
310
+ const enableHex = plan.enable ? '01' : '00'
311
+ const hourHex = to16(Math.trunc(plan.time / 60))
312
+ const minuteHex = to16(plan.time % 60)
313
+ const hsvHex = '00000000'
314
+ const brightnessHex = plan.brightness.toString(16).padStart(2, '0')
315
+ const colorTemperatureHex = plan.colorTemperature.toString(16).padStart(2, '0')
316
+ return enableHex + hourHex + minuteHex + hsvHex + brightnessHex + colorTemperatureHex
317
+ })
318
+ .join('')
319
+ return versionHex + enableHex + gradientHex + repeatPeriodHex + planCountHex + planListHex
320
+ }
321
+
322
+ /**
323
+ * BiorhythmBean 转 RemoteBiorhythmBean
324
+ */
325
+ function vo2Dto(biorhythmBean: BiorhythmBean): RemoteBiorhythmBean {
326
+ return {
327
+ enable: biorhythmBean.enable,
328
+ repeatPeriod: biorhythmBean.repeatPeriod.filter(r => r.enabled).map(r => r.index),
329
+ gradientWay: BiorhythmGradientTypeMap[biorhythmBean.gradient],
330
+ rhythmPlan: biorhythmBean.planList.map(plan => {
331
+ const hour = Math.trunc(plan.time / 60).toString().padStart(2, '0')
332
+ const min = (plan.time % 60).toString().padStart(2, '0')
333
+ return {
334
+ name: plan.name,
335
+ rhythmIcon: plan.icon,
336
+ enable: plan.enable,
337
+ startTime: `${hour}:${min}`,
338
+ sustain: plan.index, // 持续时间涂鸦这边没有,直接用来存ID
339
+ action: plan.action,
340
+ iconId: plan.iconId,
341
+ }
342
+ }),
343
+ }
344
+ }
345
+
346
+ /**
347
+ * RemoteBiorhythmBean 转 BiorhythmBean
348
+ */
349
+ function dto2Vo(remoteBiorhythmBean: RemoteBiorhythmBean): BiorhythmBean {
350
+ return {
351
+ enable: remoteBiorhythmBean.enable,
352
+ repeatPeriod: getDefRepeatPeriod().map(repeatItem => {
353
+ return {
354
+ ...repeatItem,
355
+ enabled: remoteBiorhythmBean.repeatPeriod.includes(repeatItem.index),
356
+ }
357
+ }),
358
+ gradient: BiorhythmGradientTypeMap2[remoteBiorhythmBean.gradientWay],
359
+ planList: remoteBiorhythmBean.rhythmPlan.map(plan => {
360
+ const startTime = plan.startTime.split(':')
361
+ return {
362
+ index: plan.sustain,
363
+ enable: plan.enable,
364
+ icon: plan.rhythmIcon,
365
+ time: Number(startTime[0]) * 60 + Number(startTime[1]),
366
+ name: plan.name,
367
+ colorTemperature: colorTempPercent(parseInt(plan.action[0].startValue)),
368
+ brightness: parseInt(plan.action[1].startValue),
369
+ action: plan.action,
370
+ iconId: plan.iconId,
371
+ }
372
+ }),
373
+ }
374
+ }
@@ -0,0 +1,230 @@
1
+ import I18n from '@ledvance/base/src/i18n'
2
+ import BiologicalRes from './res/BiologicalRes'
3
+
4
+ export enum BiorhythmGradientType {
5
+ // 全程渐变
6
+ EntireGradient,
7
+ // 直接渐变
8
+ DirectGradient,
9
+ }
10
+
11
+ export const BiorhythmGradientTypeMap = {
12
+ [BiorhythmGradientType.EntireGradient]: 'entireGradient',
13
+ [BiorhythmGradientType.DirectGradient]: 'directGradient',
14
+ }
15
+
16
+ export const BiorhythmGradientTypeMap2 = {
17
+ entireGradient: BiorhythmGradientType.EntireGradient,
18
+ directGradient: BiorhythmGradientType.DirectGradient,
19
+ }
20
+
21
+ export interface BiorhythmBean {
22
+ enable: boolean;
23
+ repeatPeriod: Period[];
24
+ gradient: BiorhythmGradientType;
25
+ planList: Plan[];
26
+ }
27
+
28
+ export interface Plan {
29
+ index: number;
30
+ enable: boolean;
31
+ icon: string;
32
+ time: number;
33
+ name: string;
34
+ colorTemperature: number;
35
+ brightness: number;
36
+ action: Action[];
37
+ iconId?: any;
38
+ }
39
+
40
+ export interface Action {
41
+ uri: string;
42
+ startValue: string;
43
+ }
44
+
45
+ export interface Period {
46
+ index: number;
47
+ title: string;
48
+ enabled: boolean;
49
+ }
50
+
51
+ export function colorTemperatureValue(percentageValue) {
52
+ // 38 = (6500 - 2700) / 100
53
+ return 2700 + 38 * percentageValue
54
+ }
55
+
56
+ export function colorTempPercent(colorTemp: number): number {
57
+ return Math.round((colorTemp - 2700) / 38)
58
+ }
59
+
60
+ export function getDefBiorhythmUIState(): BiorhythmBean {
61
+ const icon1 = BiologicalRes.biorhythom_Icon1
62
+ const icon12 = BiologicalRes.biorhythom_Icon3
63
+ const icon2 = BiologicalRes.biorhythom_Icon5
64
+ const icon3 = BiologicalRes.biorhythom_Icon2
65
+ const icon4 = BiologicalRes.biorhythom_Icon9
66
+ return {
67
+ enable: false, // 生物节律默认为关
68
+ repeatPeriod: getDefRepeatPeriod(),
69
+ gradient: BiorhythmGradientType.EntireGradient,
70
+ planList: [
71
+ {
72
+ index: 0,
73
+ icon: icon1,
74
+ time: 360,
75
+ name: I18n.getLang('bio_ryhthm_default_field_text'),
76
+ colorTemperature: 0,
77
+ brightness: 0,
78
+ action: [
79
+ {
80
+ uri: 'model/attribute/set/LightCtrl/ColorTemperature',
81
+ startValue: `${colorTemperatureValue(0)}`,
82
+ },
83
+ {
84
+ uri: 'model/attribute/set/LightCtrl/Brightness',
85
+ startValue: '0',
86
+ },
87
+ ],
88
+ enable: true,
89
+ iconId: 1,
90
+ },
91
+ {
92
+ index: 1,
93
+ icon: icon12,
94
+ time: 420,
95
+ name: I18n.getLang('bio_ryhthm_default_field_text2'),
96
+ colorTemperature: 25,
97
+ brightness: 20,
98
+ action: [
99
+ {
100
+ uri: 'model/attribute/set/LightCtrl/ColorTemperature',
101
+ startValue: `${colorTemperatureValue(25)}`,
102
+ },
103
+ {
104
+ uri: 'model/attribute/set/LightCtrl/Brightness',
105
+ startValue: '20',
106
+ },
107
+ ],
108
+ enable: true,
109
+ iconId: 5,
110
+ },
111
+ {
112
+ index: 2,
113
+ icon: icon2,
114
+ time: 540,
115
+ name: I18n.getLang('bio_ryhthm_default_field_text3'),
116
+ colorTemperature: 100,
117
+ brightness: 100,
118
+ action: [
119
+ {
120
+ uri: 'model/attribute/set/LightCtrl/ColorTemperature',
121
+ startValue: `${colorTemperatureValue(100)}`,
122
+ },
123
+ {
124
+ uri: 'model/attribute/set/LightCtrl/Brightness',
125
+ startValue: '100',
126
+ },
127
+ ],
128
+ enable: true,
129
+ iconId: 2,
130
+ },
131
+ {
132
+ index: 3,
133
+ icon: icon3,
134
+ time: 1200,
135
+ name: I18n.getLang('bio_ryhthm_default_field_text4'),
136
+ colorTemperature: 50,
137
+ brightness: 80,
138
+ action: [
139
+ {
140
+ uri: 'model/attribute/set/LightCtrl/ColorTemperature',
141
+ startValue: `${colorTemperatureValue(50)}`,
142
+ },
143
+ {
144
+ uri: 'model/attribute/set/LightCtrl/Brightness',
145
+ startValue: '80',
146
+ },
147
+ ],
148
+ enable: true,
149
+ iconId: 9,
150
+ },
151
+ {
152
+ index: 4,
153
+ icon: icon4,
154
+ time: 1410,
155
+ name: I18n.getLang('bio_ryhthm_default_field_text5'),
156
+ colorTemperature: 0,
157
+ brightness: 0,
158
+ action: [
159
+ {
160
+ uri: 'model/attribute/set/LightCtrl/ColorTemperature',
161
+ startValue: `${colorTemperatureValue(0)}`,
162
+ },
163
+ {
164
+ uri: 'model/attribute/set/LightCtrl/Brightness',
165
+ startValue: '0',
166
+ },
167
+ ],
168
+ enable: true,
169
+ iconId: 3,
170
+ },
171
+ ],
172
+ }
173
+ }
174
+
175
+ export function getDefRepeatPeriod(): Period[] {
176
+ return [
177
+ {
178
+ index: 7,
179
+ title: I18n.getLang('bio_ryhthm_default_weekday7_text'),
180
+ enabled: true,
181
+ },
182
+ {
183
+ index: 1,
184
+ title: I18n.getLang('bio_ryhthm_default_weekday1_text'),
185
+ enabled: true,
186
+ },
187
+ {
188
+ index: 2,
189
+ title: I18n.getLang('bio_ryhthm_default_weekday2_text'),
190
+ enabled: true,
191
+ },
192
+ {
193
+ index: 3,
194
+ title: I18n.getLang('bio_ryhthm_default_weekday3_text'),
195
+ enabled: true,
196
+ },
197
+ {
198
+ index: 4,
199
+ title: I18n.getLang('bio_ryhthm_default_weekday4_text'),
200
+ enabled: true,
201
+ },
202
+ {
203
+ index: 5,
204
+ title: I18n.getLang('bio_ryhthm_default_weekday5_text'),
205
+ enabled: true,
206
+ },
207
+ {
208
+ index: 6,
209
+ title: I18n.getLang('bio_ryhthm_default_weekday6_text'),
210
+ enabled: true,
211
+ },
212
+ ]
213
+ }
214
+
215
+ export interface RemoteBiorhythmBean {
216
+ enable: boolean;
217
+ repeatPeriod: number[];
218
+ gradientWay: string;
219
+ rhythmPlan: RemoteBiorhythmPlan[];
220
+ }
221
+
222
+ interface RemoteBiorhythmPlan {
223
+ iconId: any;
224
+ name: string;
225
+ rhythmIcon: string;
226
+ enable: boolean;
227
+ startTime: string;
228
+ sustain: number; // 持续时间涂鸦这边没有,直接用来存ID
229
+ action: Action[];
230
+ }