@ledvance/ui-biz-bundle 1.1.109 → 1.1.111

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/ui-biz-bundle",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.1.109",
7
+ "version": "1.1.111",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@ledvance/base": "^1.x",
@@ -4,9 +4,10 @@ import {Result} from '@ledvance/base/src/models/modules/Result'
4
4
  import { useRandomTime } from '../newModules/randomTime/RandomTimeActions'
5
5
  import { useBiorhythm } from '../newModules/biorhythm/BiorhythmActions'
6
6
  import { useFixedTime } from '../newModules/fixedTime/FixedTimeActions'
7
+ import { useSwitchInching } from '../newModules/swithInching/SwithInchingAction'
7
8
  import { getEndTime, getStartTime, useSleepMode, useWakeUp } from '../newModules/sleepWakeUp/SleepWakeUpActions'
8
9
  import { isConflictTask } from '@ledvance/base/src/utils/common'
9
- import { isEmpty } from 'lodash'
10
+ import { cloneDeep, isEmpty } from 'lodash'
10
11
  import { useReactive } from 'ahooks'
11
12
 
12
13
  export const WHITE = 'white'
@@ -63,6 +64,7 @@ interface ConflictDps {
63
64
  biorhythmDpCode?: string
64
65
  sleepDpCode?: string
65
66
  wakeUpDpCode?: string
67
+ switchIngCode?: string
66
68
  }
67
69
 
68
70
  interface ConflictItem {
@@ -72,17 +74,19 @@ interface ConflictItem {
72
74
  enable: boolean
73
75
  }
74
76
 
75
- export const useConflictTask = (conflictDps: ConflictDps): [(v: ConflictItem) => boolean, () => void] => {
77
+ export const useConflictTask = (conflictDps: ConflictDps, isPlug?: boolean): [(v: ConflictItem) => boolean, () => void] => {
76
78
  const [biorhythm, setBiorhythm] = useBiorhythm(conflictDps.biorhythmDpCode!, true)
77
- const [fixedTime, setFixedTime] = useFixedTime(conflictDps.fixedTimeDpCode!, false, true)
78
- const [randomTime, setRandomTime] = useRandomTime(conflictDps.randomTimeDpCode!, false, true)
79
+ const [fixedTime, setFixedTime] = useFixedTime(conflictDps.fixedTimeDpCode!, !!isPlug, true)
80
+ const [randomTime, setRandomTime] = useRandomTime(conflictDps.randomTimeDpCode!, !!isPlug, true)
79
81
  const [sleepPlan, setSleepPlan] = useSleepMode(conflictDps.sleepDpCode!, true)
80
82
  const [wakeUpPlan, setWakeUpPlan] = useWakeUp(conflictDps.wakeUpDpCode!, true)
83
+ const [switchInching, setSwitchInching] = useSwitchInching(conflictDps.switchIngCode!)
81
84
  const state = useReactive({
82
85
  conflictTask: {}
83
86
  })
87
+
84
88
  const checkConflict = (conflictItem: ConflictItem) => {
85
- state.conflictTask = {}
89
+ let newState = {...state.conflictTask}
86
90
  if (conflictDps.biorhythmDpCode && biorhythm.enable){
87
91
  const biorhythmTask = {
88
92
  startTime: 0,
@@ -90,12 +94,9 @@ export const useConflictTask = (conflictDps: ConflictDps): [(v: ConflictItem) =>
90
94
  weeks: biorhythm.repeatPeriod.map(item => item.enabled ? 1 : 0)
91
95
  }
92
96
  if (isConflictTask(conflictItem, biorhythmTask)){
93
- state.conflictTask = {
94
- ...state.conflictTask,
95
- [conflictDps.biorhythmDpCode]: {
96
- ...biorhythm,
97
+ newState[conflictDps.biorhythmDpCode] = {
98
+ ...biorhythm,
97
99
  enable: false
98
- }
99
100
  }
100
101
  }
101
102
  }
@@ -112,10 +113,7 @@ export const useConflictTask = (conflictDps: ConflictDps): [(v: ConflictItem) =>
112
113
  return item
113
114
  })
114
115
  if (conflict){
115
- state.conflictTask = {
116
- ...state.conflictTask,
117
- [conflictDps.fixedTimeDpCode]: newFixedTime
118
- }
116
+ newState[conflictDps.fixedTimeDpCode] = newFixedTime
119
117
  }
120
118
  }
121
119
  if (conflictDps.randomTimeDpCode && randomTime.length){
@@ -131,10 +129,7 @@ export const useConflictTask = (conflictDps: ConflictDps): [(v: ConflictItem) =>
131
129
  return item
132
130
  })
133
131
  if (conflict){
134
- state.conflictTask = {
135
- ...state.conflictTask,
136
- [conflictDps.randomTimeDpCode]: newRandomTime
137
- }
132
+ newState[conflictDps.randomTimeDpCode] = newRandomTime
138
133
  }
139
134
  }
140
135
  if (conflictDps.sleepDpCode && sleepPlan.length){
@@ -154,10 +149,7 @@ export const useConflictTask = (conflictDps: ConflictDps): [(v: ConflictItem) =>
154
149
  return item
155
150
  })
156
151
  if (conflict){
157
- state.conflictTask = {
158
- ...state.conflictTask,
159
- [conflictDps.sleepDpCode]: newSleepPlan
160
- }
152
+ newState[conflictDps.sleepDpCode] = newSleepPlan
161
153
  }
162
154
  }
163
155
  if (conflictDps.wakeUpDpCode && wakeUpPlan.length){
@@ -177,13 +169,17 @@ export const useConflictTask = (conflictDps: ConflictDps): [(v: ConflictItem) =>
177
169
  return item
178
170
  })
179
171
  if (conflict){
180
- state.conflictTask = {
181
- ...state.conflictTask,
182
- [conflictDps.wakeUpDpCode]: newWakeUpPlan
183
- }
172
+ newState[conflictDps.wakeUpDpCode] = newWakeUpPlan
173
+ }
174
+ }
175
+ if (conflictDps.switchIngCode && switchInching.enable){
176
+ newState[conflictDps.switchIngCode] = {
177
+ ...switchInching,
178
+ enable: false
184
179
  }
185
180
  }
186
- return !isEmpty(state.conflictTask)
181
+ state.conflictTask = cloneDeep(newState)
182
+ return !isEmpty(newState)
187
183
  }
188
184
 
189
185
  const resolveConfict = () => {
@@ -202,6 +198,9 @@ export const useConflictTask = (conflictDps: ConflictDps): [(v: ConflictItem) =>
202
198
  if (conflictDps.wakeUpDpCode && state.conflictTask[conflictDps.wakeUpDpCode]){
203
199
  setWakeUpPlan(state.conflictTask[conflictDps.wakeUpDpCode], false).then()
204
200
  }
201
+ if (conflictDps.switchIngCode && state.conflictTask[conflictDps.switchIngCode]){
202
+ setSwitchInching(state.conflictTask[conflictDps.switchIngCode]).then()
203
+ }
205
204
  }
206
205
  return [checkConflict, resolveConfict]
207
206
  }
@@ -91,7 +91,7 @@ export const useFixedTime: UseFixedTimeType = (dpKey, isPlug, disableFeature) =>
91
91
  return {
92
92
  ...item,
93
93
  index: idx,
94
- name: featureItem && featureItem?.n ? featureItem?.n : `${I18n.getLang('randomtimecycle_sockets_headline_text')} ${idx + 1}`
94
+ name: featureItem && featureItem?.n ? featureItem?.n : `${I18n.getLang('fixedTimeCycle_socket_headline')} ${idx + 1}`
95
95
  }
96
96
  })
97
97
  setFixedTimeUiList(uiPlan)
@@ -32,6 +32,7 @@ export interface FixedTimePageParams {
32
32
  biorhythmDpCode?: string
33
33
  sleepDpCode?: string
34
34
  wakeUpDpCode?: string
35
+ switchIngCode?: string
35
36
  }
36
37
  isPlug?: boolean
37
38
  showTags?: boolean
@@ -48,7 +49,7 @@ const FixedTimePage = (props: { theme?: ThemeType }) => {
48
49
  const MAX_NUM = params.isPlug ? 10 : 4
49
50
  const is24Hour = useSystemTimeFormate()
50
51
  const [fixedTime, setFixedTime] = useFixedTime(params.fixedTimeDpCode, params.isPlug)
51
- const [checkConflict, resolveConflict] = useConflictTask(params.conflictDps)
52
+ const [checkConflict, resolveConflict] = useConflictTask(params.conflictDps, params.isPlug)
52
53
  const state = useReactive({
53
54
  loading: false,
54
55
  originList: cloneDeep(fixedTime),
@@ -68,14 +69,14 @@ const FixedTimePage = (props: { theme?: ThemeType }) => {
68
69
  state.fixedTimeList = cloneDeep(checkedList)
69
70
  }, [JSON.stringify(state.checkTags), JSON.stringify(state.originList)])
70
71
 
71
- const navigateToEdit = useCallback((mode: 'add' | 'edit', scheduleItem: FixedTimerUiItem) => {
72
+ const navigateToEdit = (mode: 'add' | 'edit', scheduleItem: FixedTimerUiItem) => {
72
73
  navigation.navigate(ui_biz_routerKey.ui_biz_fixed_time_edit_new, {
73
74
  ...params,
74
75
  mode,
75
76
  scheduleItem: cloneDeep(scheduleItem),
76
77
  onPost
77
78
  })
78
- }, [])
79
+ }
79
80
 
80
81
  const showMaxNumTip = useCallback(() => {
81
82
  return state.originList.length >= MAX_NUM
@@ -33,6 +33,7 @@ export interface RandomTimePageParams {
33
33
  biorhythmDpCode?: string
34
34
  sleepDpCode?: string
35
35
  wakeUpDpCode?: string
36
+ switchIngCode?: string
36
37
  }
37
38
  isPlug?: boolean
38
39
  showTags?: boolean
@@ -49,7 +50,7 @@ const RandomTimePage = (props: { theme?: ThemeType }) => {
49
50
  const MAX_NUM = params.isPlug ? 16 : 4
50
51
  const is24Hour = useSystemTimeFormate()
51
52
  const [randomTime, setRandomTime] = useRandomTime(params.randomTimeDpCode, params.isPlug)
52
- const [checkConflict, resolveConflict] = useConflictTask(params.conflictDps)
53
+ const [checkConflict, resolveConflict] = useConflictTask(params.conflictDps, params.isPlug)
53
54
  const state = useReactive({
54
55
  loading: false,
55
56
  originList: cloneDeep(randomTime),
@@ -69,14 +70,14 @@ const RandomTimePage = (props: { theme?: ThemeType }) => {
69
70
  state.randomTimeList = cloneDeep(checkedList)
70
71
  }, [JSON.stringify(state.checkTags), JSON.stringify(state.originList)])
71
72
 
72
- const navigateToEdit = useCallback((mode: 'add' | 'edit', scheduleItem?: RandomTimerUiItem) => {
73
+ const navigateToEdit = (mode: 'add' | 'edit', scheduleItem?: RandomTimerUiItem) => {
73
74
  navigation.navigate(ui_biz_routerKey.ui_biz_random_time_edit_new, {
74
75
  ...params,
75
76
  mode,
76
77
  scheduleItem: cloneDeep(scheduleItem),
77
78
  onPost,
78
79
  })
79
- }, [])
80
+ }
80
81
 
81
82
  const showMaxNumTip = useCallback(() => {
82
83
  return state.originList.length >= MAX_NUM
@@ -79,7 +79,7 @@ const SleepWakeUpPage = (props: { theme?: ThemeType }) => {
79
79
  state.loading = !wakeupComplete && !sleepComplete
80
80
  }, [wakeupComplete, sleepComplete])
81
81
 
82
- const onAddScheduleDialogItemClick = useCallback((isSleep: boolean, mode: 'add' | 'edit', scheduleItem?: any) => {
82
+ const onAddScheduleDialogItemClick = (isSleep: boolean, mode: 'add' | 'edit', scheduleItem?: any) => {
83
83
  if (mode === 'add' && isSleep && state.sleepScheduleList.length === MAX_SCHEDULE) return
84
84
  if (mode === 'add' && !isSleep && state.wakeUpScheduleList.length === MAX_SCHEDULE) return
85
85
  navigateToEdit({
@@ -90,7 +90,7 @@ const SleepWakeUpPage = (props: { theme?: ThemeType }) => {
90
90
  modDeleteTimeSchedule
91
91
  })
92
92
  state.showAddSchedulePopover = false
93
- }, [state.filteredScheduleList])
93
+ }
94
94
 
95
95
  const modDeleteTimeSchedule = async (mode: 'add' | 'edit' | 'del', isSleep: boolean, sleepWakeUp: SleepUIItem | WakeUpUIItem) => {
96
96
  let cloneSleepWakeUp: any[] = isSleep ? cloneDeep(state.sleepScheduleList) : cloneDeep(state.wakeUpScheduleList)
@@ -7,38 +7,27 @@ import { SwitchButton, Utils, Dialog } from "tuya-panel-kit";
7
7
  import LdvPickerView from "@ledvance/base/src/components/ldvPickerView";
8
8
  import I18n from '@ledvance/base/src/i18n'
9
9
  import { useReactive, useUpdateEffect } from "ahooks";
10
- import {SwitchInchingPageParams, useCountdown1, useSwitchInching} from "./SwithInchingAction";
11
- import {useRandomTime} from "../randomTime/RandomTimeActions";
12
- import {useFixedTime} from "../fixedTime/FixedTimeActions";
13
- import {useParams} from "@ledvance/base/src/hooks/Hooks";
10
+ import { SwitchInchingPageParams, useCountdown1, useSwitchInching } from "./SwithInchingAction";
11
+ import { useParams } from "@ledvance/base/src/hooks/Hooks";
14
12
  import ThemeType from '@ledvance/base/src/config/themeType'
13
+ import { useConflictTask } from "hooks/DeviceDpStateHooks";
14
+ import { showDialog } from "@ledvance/base/src/utils/common";
15
15
 
16
16
  const { convertX: cx } = Utils.RatioUtils
17
17
  const { withTheme } = Utils.ThemeUtils
18
18
 
19
- interface SwitchInchingState {
20
- enable: boolean,
21
- minute: string,
22
- second: string,
23
- flag: Symbol | number
24
- }
25
-
26
19
  const SwitchInching = (props: { theme?: ThemeType }) => {
27
20
  const params = useParams<SwitchInchingPageParams>()
28
21
  const deviceInfo = useDeviceInfo()
29
22
  const navigation = useNavigation()
30
- const [switchInching, setSwitchInching] = useSwitchInching(params.switchInchingCode)
31
- const [randomTimePlan, setRandomTimePlan] = useRandomTime(params.randomTimeCode, true)
32
- const [fixedTimePlan, setFixedTimePlan] = useFixedTime(params.cycleTimeCode, true)
23
+ const [switchInching, setSwitchInching] = useSwitchInching(params.switchIngCode)
33
24
  const [countdown1, setCountDown1] = useCountdown1(params.countdownCode)
34
- const randomEnable = randomTimePlan.some(item => item.enable)
35
- const fixedEnable = fixedTimePlan.some(item => item.enable)
36
- const timerEnable = !!countdown1
37
- const state = useReactive<SwitchInchingState>({
25
+ const [checkConflict, resolveConflict] = useConflictTask(params.conflictDps, true)
26
+ const state = useReactive({
38
27
  enable: false,
39
28
  minute: '00',
40
29
  second: '00',
41
- flag: 1
30
+ loading: false
42
31
  })
43
32
 
44
33
  useEffect(() => {
@@ -47,72 +36,15 @@ const SwitchInching = (props: { theme?: ThemeType }) => {
47
36
  state.second = formateValue('second')
48
37
  }, [JSON.stringify(switchInching)])
49
38
 
50
- const showDialog = (run: () => void) => {
51
- Dialog.confirm({
52
- title: I18n.getLang('conflict_dialog_save_item_inching_titel'),
53
- subTitle: I18n.getLang('conflict_dialog_save_item_inching_description'),
54
- cancelText: I18n.getLang('conflict_dialog_save_item_inching_answer_no_text'),
55
- confirmText: I18n.getLang('conflict_dialog_save_item_inching_answer_yes_text'),
56
- onConfirm: (_, { close }) => {
57
- close();
58
- setSwitchInching({ ...switchInching, enable: false })
59
- TurnOffFn()
60
- run()
61
- },
62
- })
63
- }
64
-
65
- const TurnOffFn = () => {
66
- if (randomEnable) {
67
- const randomTimeList = randomTimePlan.map(item => {
68
- if (item.enable) {
69
- return {
70
- ...item,
71
- enable: false
72
- }
73
- } else {
74
- return item
75
- }
76
- })
77
- setRandomTimePlan(randomTimeList)
78
- }
79
- if (fixedEnable) {
80
- const fixedTimeList = fixedTimePlan.map(item => {
81
- if (item.enable) {
82
- return {
83
- ...item,
84
- enable: false
85
- }
86
- } else {
87
- return item
88
- }
89
- })
90
- setFixedTimePlan(fixedTimeList)
91
- }
92
- if (timerEnable) {
39
+ const requestSwitchInching = async () => {
40
+ const enable = state.enable
41
+ const time = Number(state.minute) * 60 + Number(state.second)
42
+ if (enable && countdown1){
93
43
  setCountDown1(0)
94
44
  }
45
+ await setSwitchInching({ enable, time })
95
46
  }
96
47
 
97
-
98
- const requestSwitchInching = () => {
99
- const run = () => {
100
- const enable = state.enable
101
- const time = Number(state.minute) * 60 + Number(state.second)
102
- setSwitchInching({ enable, time })
103
- }
104
- if (state.enable && (randomEnable || fixedEnable || timerEnable)) {
105
- return showDialog(run)
106
- }
107
- run()
108
- }
109
-
110
- useEffect(() => {
111
- if (state.flag !== 1) {
112
- requestSwitchInching()
113
- }
114
- }, [state.flag])
115
-
116
48
  useUpdateEffect(() => {
117
49
  if (!!!Number(state.minute) && Number(state.second) < 2) {
118
50
  state.second = '02'
@@ -197,9 +129,34 @@ const SwitchInching = (props: { theme?: ThemeType }) => {
197
129
  </Text>
198
130
  <SwitchButton
199
131
  value={switchInching.enable}
200
- onValueChange={v => {
132
+ onValueChange={async v => {
133
+ if (v) {
134
+ const switchingTask = {
135
+ enable: v,
136
+ startTime: 0,
137
+ endTime: 1440,
138
+ weeks: [1, 1, 1, 1, 1, 1, 1],
139
+ }
140
+ if (checkConflict(switchingTask)) {
141
+ return showDialog({
142
+ method: 'confirm',
143
+ title: I18n.getLang('conflict_dialog_save_item_inching_titel'),
144
+ subTitle: I18n.getLang('conflict_dialog_save_item_inching_description'),
145
+ onConfirm: async (_, { close }) => {
146
+ resolveConflict()
147
+ close()
148
+ state.loading = true
149
+ state.enable = v;
150
+ await requestSwitchInching()
151
+ },
152
+ onCancel: () => {
153
+ Dialog.close()
154
+ }
155
+ })
156
+ }
157
+ }
201
158
  state.enable = v;
202
- state.flag = Symbol();
159
+ await requestSwitchInching()
203
160
  }}
204
161
  />
205
162
  </View>
@@ -3,10 +3,12 @@ import {Result} from "@ledvance/base/src/models/modules/Result"
3
3
  import {useDp} from "@ledvance/base/src/models/modules/NativePropsSlice";
4
4
 
5
5
  export interface SwitchInchingPageParams {
6
- switchInchingCode: string
6
+ switchIngCode: string
7
7
  countdownCode: string
8
- cycleTimeCode: string
9
- randomTimeCode: string
8
+ conflictDps: {
9
+ randomTimeDpCode?: string
10
+ fixedTimeDpCode?: string
11
+ }
10
12
  }
11
13
 
12
14
  interface SwitchInchingModel {
@@ -36,9 +38,13 @@ export function useSwitchInchingHex(switchInchingCode: string): [string, (switch
36
38
 
37
39
  export const useSwitchInching: SwitchInchingResult = (switchInchingCode: string) => {
38
40
  const [hex, setHex] = useSwitchInchingHex(switchInchingCode)
39
- const inching = Buffer.from(hex, 'base64')
40
- const enable = !!inching[0]
41
- const time = inching[1] * 256 + inching[2]
41
+ let enable = false
42
+ let time = 0
43
+ if (switchInchingCode && hex){
44
+ const inching = Buffer.from(hex, 'base64')
45
+ enable = !!inching[0]
46
+ time = inching[1] * 256 + inching[2]
47
+ }
42
48
  const setSwitchInching = ({enable, time}) => {
43
49
  const enableHex = enable ? '01' : '00'
44
50
  const timeHex = format(time?.toString(16), 4)