@ledvance/group-ui-biz-bundle 1.0.150 → 1.0.151

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/group-ui-biz-bundle",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.0.150",
7
+ "version": "1.0.151",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@ledvance/base": "^1.x",
@@ -1,3 +1,6 @@
1
+ import { xLog } from '@ledvance/base/src/utils'
2
+ import { cloneDeep } from 'lodash'
3
+ import { AsyncStorage } from 'react-native'
1
4
  import {
2
5
  BiorhythmBean,
3
6
  BiorhythmGradientType,
@@ -11,8 +14,9 @@ import {hex2Int, spliceByStep} from '@ledvance/base/src/utils/common'
11
14
  import I18n from '@ledvance/base/src/i18n'
12
15
  import res from '@ledvance/base/src/res'
13
16
  import { to16 } from '@tuya/tuya-panel-lamp-sdk/lib/utils'
14
- import { useCallback } from 'react'
17
+ import { useCallback, useEffect, useState } from 'react'
15
18
  import { Result } from '@ledvance/base/src/models/modules/Result'
19
+ import iconList from './iconListData'
16
20
 
17
21
  interface BiorhythmConfig {
18
22
  rhythm_mode: BiorhythmBean
@@ -179,6 +183,7 @@ function getRepeatPeriodTitleByIndex(index: number): string {
179
183
  let title = ''
180
184
  switch (index) {
181
185
  case 0:
186
+ case 7:
182
187
  title = I18n.getLang('bio_ryhthm_default_weekday7_text')
183
188
  break
184
189
  case 1:
@@ -231,3 +236,104 @@ function obj2Dp(obj: BiorhythmBean): string {
231
236
  .join('')
232
237
  return versionHex + enableHex + gradientHex + repeatPeriodHex + planCountHex + planListHex
233
238
  }
239
+
240
+ export const replaceImg = (img) => {
241
+ const item = iconList?.find(val => val.id === Number(img))
242
+ switch (img) {
243
+ case 'rhythm_icon1':
244
+ case '31':
245
+ return { icon: res.biorhythom_icon1, iconId: 1 }
246
+ case 'rhythm_icon2':
247
+ case '33':
248
+ return { icon: res.biorhythom_icon5, iconId: 5 }
249
+ case 'rhythm_icon3':
250
+ case '35':
251
+ return { icon: res.biorhythom_icon2, iconId: 2 }
252
+ case 'rhythm_icon4':
253
+ case '32':
254
+ return { icon: res.biorhythom_icon9, iconId: 9 }
255
+ case 'rhythm_icon12':
256
+ case '39':
257
+ return { icon: res.biorhythom_icon3, iconId: 3 }
258
+ default:
259
+ return { icon: item?.icon, iconId: item?.id }
260
+ }
261
+ }
262
+
263
+ export function useStorageBiorhythm(): [[], (key, enable: boolean, gradient: BiorhythmGradientType, repeatPeriod: Period[], planList: Plan[]) => void, (key) => void, (key) => {
264
+ repeatPeriod: Period[];
265
+ planList: Plan[];
266
+ enable: boolean;
267
+ gradient: BiorhythmGradientType
268
+ }] {
269
+ const [storageBiorhythms, setStorageBiorhythms] = useState([])
270
+ useEffect(() => {
271
+ AsyncStorage.getItem('BIORHYTHM_STORAGE').then(res => {
272
+ if (res) {
273
+ const storageBiorhythms = JSON.parse(res)
274
+ setStorageBiorhythms(storageBiorhythms)
275
+ xLog('AsyncStorage getBiorhythm', storageBiorhythms)
276
+ }
277
+ })
278
+ }, [])
279
+
280
+ const saveBiorhythm = useCallback((key, enable: boolean, gradient: BiorhythmGradientType, repeatPeriod: Period[], planList: Plan[]) => {
281
+ const newPlanList = planList?.map(item => {
282
+ return { ...item, icon: `${item.icon}` }
283
+ }).sort((a, b) => a.time - b.time)
284
+ const weeks = repeatPeriod.map(item => item.enabled ? 1 : 0)
285
+ const sun = weeks.splice(6, 1)[0]
286
+ weeks.unshift(sun)
287
+ weeks.push(0)
288
+ const biorhythm = cloneDeep({
289
+ key: key,
290
+ enable: enable,
291
+ weeks: weeks,
292
+ gradient: gradient,
293
+ planList: newPlanList,
294
+ })
295
+ const newStorageBiorhythms = storageBiorhythms.filter(item => item.key !== key)
296
+ newStorageBiorhythms.unshift(biorhythm)
297
+ setStorageBiorhythms(newStorageBiorhythms)
298
+ xLog('AsyncStorage saveBiorhythm', newStorageBiorhythms)
299
+ AsyncStorage.setItem('BIORHYTHM_STORAGE', JSON.stringify(newStorageBiorhythms), (error) => {
300
+ xLog('AsyncStorage saveBiorhythm error', error)
301
+ }).then()
302
+ }, [storageBiorhythms])
303
+
304
+ const removeBiorhythm = useCallback((key) => {
305
+ const newStorageBiorhythms = storageBiorhythms.filter(item => item.key !== key)
306
+ setStorageBiorhythms(newStorageBiorhythms)
307
+ AsyncStorage.setItem('BIORHYTHM_STORAGE', JSON.stringify(newStorageBiorhythms)).then(res => {
308
+ xLog('AsyncStorage removeBiorhythm res', res)
309
+ })
310
+ }, [storageBiorhythms])
311
+
312
+ const applyBiorhythm = useCallback((key) => {
313
+ const newBiorhythm = storageBiorhythms.find(item => item.key === key)
314
+ const planList = newBiorhythm.planList?.map((it, index) => {
315
+ return {
316
+ ...it,
317
+ id: it.id ?? index,
318
+ icon: replaceImg(it?.iconId || it?.icon)?.icon,
319
+ iconId: replaceImg(it?.iconId || it?.icon)?.iconId,
320
+ }
321
+ })
322
+ const repeatPeriod = newBiorhythm.weeks.slice(0, 7).map((it, index) => {
323
+ const idx = index === 0 ? 7 : index
324
+ return {
325
+ index: idx,
326
+ title: getRepeatPeriodTitleByIndex(idx),
327
+ enabled: it,
328
+ }
329
+ })
330
+ repeatPeriod.sort((a, b) => a.index - b.index)
331
+ return {
332
+ repeatPeriod: repeatPeriod,
333
+ planList: planList,
334
+ enable: newBiorhythm.enable,
335
+ gradient: newBiorhythm.gradient,
336
+ }
337
+ }, [storageBiorhythms])
338
+ return [storageBiorhythms, saveBiorhythm, removeBiorhythm, applyBiorhythm]
339
+ }
@@ -1,4 +1,5 @@
1
- import React, { useCallback, useEffect, useMemo } from 'react'
1
+ import { xLog } from '@ledvance/base/src/utils'
2
+ import React, { useCallback, useEffect, useMemo, useState } from 'react'
2
3
  import { FlatList, Image, Linking, ScrollView, Switch, Text, TouchableOpacity, View } from 'react-native'
3
4
  import { useNavigation } from '@react-navigation/native'
4
5
  import { useDebounceFn, useReactive, useUpdateEffect } from 'ahooks'
@@ -23,8 +24,11 @@ import res from '@ledvance/base/src/res'
23
24
  import { ui_biz_routerKey } from '../../navigation/Routers'
24
25
  import { cctToColor } from '@ledvance/base/src/utils/cctUtils'
25
26
  import { BiorhythmEditPageParams } from './BiorhythmDetailPage'
26
- import { useBiorhythm } from './BiorhythmActions'
27
- import { convertMinutesTo12HourFormat, showDialog as showCommonDialog, showDialog } from '@ledvance/base/src/utils/common'
27
+ import { replaceImg, useBiorhythm, useStorageBiorhythm } from './BiorhythmActions'
28
+ import {
29
+ convertMinutesTo12HourFormat,
30
+ showDialog
31
+ } from '@ledvance/base/src/utils/common'
28
32
  import { useParams } from '@ledvance/base/src/hooks/Hooks'
29
33
  import Page from '@ledvance/base/src/components/Page'
30
34
  import Spacer from '@ledvance/base/src/components/Spacer'
@@ -63,6 +67,8 @@ const BiorhythmPage = (props: { theme?: ThemeType }) => {
63
67
  const is24Hour = useSystemTimeFormate()
64
68
  const { productId } = deviceInfo
65
69
  const devicesJudge = pIdList.some(val => val === productId)
70
+ const [storageBiorhythms, saveStorageBiorhythms, removeStorageBiorhythm, applyStorageBiorhythm] = useStorageBiorhythm()
71
+ const [biorhythmListVisible, setBiorhythmListVisible] = useState(false)
66
72
 
67
73
  const state = useReactive<UIState>({
68
74
  ...cloneDeep(biorhythm),
@@ -144,29 +150,6 @@ const BiorhythmPage = (props: { theme?: ThemeType }) => {
144
150
  run()
145
151
  }, [state.flag])
146
152
 
147
- const replaceImg = (img) => {
148
- const item = iconList?.find(val => val.id === Number(img))
149
- switch (img) {
150
- case 'rhythm_icon1':
151
- case '31':
152
- return { icon: res.biorhythom_icon1, iconId: 1 }
153
- case 'rhythm_icon2':
154
- case '33':
155
- return { icon: res.biorhythom_icon5, iconId: 5 }
156
- case 'rhythm_icon3':
157
- case '35':
158
- return { icon: res.biorhythom_icon2, iconId: 2 }
159
- case 'rhythm_icon4':
160
- case '32':
161
- return { icon: res.biorhythom_icon9, iconId: 9 }
162
- case 'rhythm_icon12':
163
- case '39':
164
- return { icon: res.biorhythom_icon3, iconId: 3 }
165
- default:
166
- return { icon: item?.icon, iconId: item?.id }
167
- }
168
- }
169
-
170
153
  useUpdateEffect(() => {
171
154
  console.log('Redux 生物节律数据更新', biorhythm)
172
155
  const cloneBiorhym = cloneDeep(biorhythm)
@@ -262,6 +245,26 @@ const BiorhythmPage = (props: { theme?: ThemeType }) => {
262
245
  <Page
263
246
  backText={uaGroupInfo.name}
264
247
  onBackClick={navigation.goBack}
248
+ headlineTopContent={<View style={{ flexDirection: 'row', width: '100%', justifyContent: 'space-between' }}>
249
+ <DeleteButton style={{flex: 1}} text={I18n.getLang('biorhythm_save_as')} onPress={() => {
250
+ Dialog.prompt({
251
+ title: I18n.getLang('biorhythm_save_title'),
252
+ placeholder: I18n.getLang('biorhythm_save_placeholder'),
253
+ defaultValue: `${uaGroupInfo.name}`,
254
+ cancelText: I18n.getLang('auto_scan_system_cancel'),
255
+ confirmText: I18n.getLang('auto_scan_system_wifi_confirm'),
256
+ inputWrapperStyle: {backgroundColor: props.theme?.textInput.background, borderRadius: cx(10)},
257
+ autoFocus: true,
258
+ onConfirm: (data, { close }) => {
259
+ saveStorageBiorhythms(data, state.enable, state.gradient, state.repeatPeriod, state.planList)
260
+ close()
261
+ }
262
+ })
263
+ }} />
264
+ <DeleteButton style={{flex: 1}} text={I18n.getLang('biorhythm_load')} onPress={() => {
265
+ setBiorhythmListVisible(true)
266
+ }} />
267
+ </View>}
265
268
  headlineText={I18n.getLang('add_new_trigger_time_system_back_text')}
266
269
  headlineIconContent={<Switch
267
270
  value={state.enable}
@@ -626,7 +629,7 @@ const BiorhythmPage = (props: { theme?: ThemeType }) => {
626
629
  <DeleteButton
627
630
  text={I18n.getLang('bio_ryhthm_default_button_reset_text')}
628
631
  onPress={() => {
629
- showCommonDialog({
632
+ showDialog({
630
633
  method: 'confirm',
631
634
  title: I18n.getLang('bio_ryhthm_reset_description_text'),
632
635
  onConfirm: (_, { close }) => {
@@ -691,6 +694,54 @@ const BiorhythmPage = (props: { theme?: ThemeType }) => {
691
694
  state.flag = Symbol()
692
695
  }}
693
696
  />
697
+ <Modal visible={biorhythmListVisible} onMaskPress={() => {setBiorhythmListVisible(false)}}>
698
+ <View style={{ height: cx(300), padding: cx(16), backgroundColor: props.theme?.card.background }}>
699
+ {
700
+ storageBiorhythms.length === 0 ? (
701
+ <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
702
+ <InfoText
703
+ textStyle={{ flex: undefined }}
704
+ icon={res.ic_info}
705
+ text={I18n.getLang('energyconsumption_emptydata')}
706
+ />
707
+ </View>
708
+ ) : (
709
+ <FlatList
710
+ data={storageBiorhythms}
711
+ renderItem={({ item }) => {
712
+ return <View style={{ padding: cx(5), flexDirection: 'row' }}>
713
+ <Text style={{ flex: 1, color: props.theme?.global.fontColor }}>{item.key}</Text>
714
+ <TouchableOpacity style={{width: cx(24), height: cx(24), marginRight: cx(20)}} onPress={() => {
715
+ showDialog({
716
+ method: 'confirm',
717
+ title: I18n.getLang('biorhythm_delete_tips'),
718
+ onConfirm: (_, { close }) => {
719
+ removeStorageBiorhythm(item.key)
720
+ close()
721
+ }
722
+ })
723
+ }}>
724
+ <Image source={{ uri: res.delete}} style={{width: cx(24), height: cx(24), tintColor: props.theme?.global.warning}} />
725
+ </TouchableOpacity>
726
+ <TouchableOpacity style={{width: cx(24), height: cx(24), marginRight: cx(10)}} onPress={() => {
727
+ const newBiorhythm = applyStorageBiorhythm(item.key)
728
+ state.enable = newBiorhythm.enable
729
+ state.gradient = newBiorhythm.gradient
730
+ state.repeatPeriod = newBiorhythm.repeatPeriod
731
+ state.planList = newBiorhythm.planList
732
+ run()
733
+ setBiorhythmListVisible(false)
734
+ }}>
735
+ <Image source={{ uri:res.ic_checked}} style={{width: cx(24), height: cx(24), tintColor: props.theme?.icon.normal}} />
736
+ </TouchableOpacity>
737
+ </View>
738
+ }}
739
+ keyExtractor={(item) => `${item.key}`}
740
+ />
741
+ )
742
+ }
743
+ </View>
744
+ </Modal>
694
745
  </>
695
746
  </Page>
696
747
  )