@ledvance/ui-biz-bundle 1.1.170 → 1.1.171
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
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
1
2
|
import ThemeType from "@ledvance/base/src/config/themeType";
|
|
2
3
|
import { parseMinutes, PriceSegment } from "./component/EnergyModal";
|
|
3
4
|
import { Utils } from 'tuya-panel-kit'
|
|
4
5
|
import { StyleSheet } from "react-native";
|
|
6
|
+
import {exchangeNumber} from "@ledvance/base/src/utils/common";
|
|
5
7
|
|
|
6
8
|
export const useEditPriceSegment = (segment: PriceSegment | undefined,
|
|
7
9
|
onSegmentSet: (s: PriceSegment) => void, theme?: ThemeType,) => {
|
|
@@ -11,7 +13,14 @@ export const useEditPriceSegment = (segment: PriceSegment | undefined,
|
|
|
11
13
|
|
|
12
14
|
const startTime = parseMinutes(startMin);
|
|
13
15
|
const endTime = parseMinutes(endMin);
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
const [priceStr, setPriceStr] = useState<string>(() => {
|
|
18
|
+
if (segment?.price === undefined) {
|
|
19
|
+
return '0';
|
|
20
|
+
}
|
|
21
|
+
return segment.price.toString();
|
|
22
|
+
});
|
|
23
|
+
|
|
15
24
|
const handleTimeChange = (type: 'startHour' | 'startMinute' | 'endHour' | 'endMinute', value: string) => {
|
|
16
25
|
let startH = Math.floor(startMin / 60);
|
|
17
26
|
let startM = startMin % 60;
|
|
@@ -32,15 +41,24 @@ export const useEditPriceSegment = (segment: PriceSegment | undefined,
|
|
|
32
41
|
|
|
33
42
|
onSegmentSet(updatedSegment);
|
|
34
43
|
};
|
|
44
|
+
|
|
35
45
|
const handlePriceChange = (t: string) => {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
46
|
+
const cleaned = exchangeNumber(t)
|
|
47
|
+
const parsed = parseFloat(cleaned);
|
|
48
|
+
let numericVal = isNaN(parsed) ? 0 : parsed;
|
|
49
|
+
if (numericVal > 999999) {
|
|
50
|
+
numericVal = 999999;
|
|
51
|
+
setPriceStr('999999');
|
|
52
|
+
} else {
|
|
53
|
+
setPriceStr(t);
|
|
54
|
+
}
|
|
55
|
+
|
|
39
56
|
onSegmentSet({
|
|
40
57
|
...(segment ?? {}),
|
|
41
|
-
price:
|
|
42
|
-
} as PriceSegment)
|
|
43
|
-
}
|
|
58
|
+
price: numericVal
|
|
59
|
+
} as PriceSegment);
|
|
60
|
+
};
|
|
61
|
+
|
|
44
62
|
const style = StyleSheet.create({
|
|
45
63
|
timerHeader: {
|
|
46
64
|
fontSize: cx(16),
|
|
@@ -84,6 +102,6 @@ export const useEditPriceSegment = (segment: PriceSegment | undefined,
|
|
|
84
102
|
|
|
85
103
|
})
|
|
86
104
|
return {
|
|
87
|
-
style, startTime, endTime, currentPrice, handleTimeChange, handlePriceChange,
|
|
105
|
+
style, startTime, endTime, currentPrice: priceStr, handleTimeChange, handlePriceChange,
|
|
88
106
|
}
|
|
89
107
|
}
|
|
@@ -42,10 +42,32 @@ export const useSetSegmentPrice = (params: SetSegmentedPricesParams, theme?: The
|
|
|
42
42
|
isLoading: false,
|
|
43
43
|
isDataChanged: false,
|
|
44
44
|
});
|
|
45
|
+
const findEmptySegment = useCallback(()=>{
|
|
46
|
+
let ptr = 0;
|
|
47
|
+
const TOTAL_MINUTES = 1439; // (0 ~ 1439)
|
|
48
|
+
for (const segment of uiState.segments) {
|
|
49
|
+
if(segment.startMinute > ptr) {
|
|
50
|
+
return {
|
|
51
|
+
startMinute: ptr,
|
|
52
|
+
endMinute: segment.startMinute,
|
|
53
|
+
price: 0,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
ptr = segment.endMinute;
|
|
57
|
+
}
|
|
58
|
+
if(ptr < TOTAL_MINUTES) {
|
|
59
|
+
return {
|
|
60
|
+
startMinute: ptr,
|
|
61
|
+
endMinute: TOTAL_MINUTES,
|
|
62
|
+
price:0,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return undefined
|
|
66
|
+
},[uiState.segments])
|
|
45
67
|
const showAddPopup = useCallback(() => {
|
|
46
68
|
uiState.editingSegmentPrice = {
|
|
47
69
|
isShow: true,
|
|
48
|
-
editingSegmentPrice:
|
|
70
|
+
editingSegmentPrice: findEmptySegment(),
|
|
49
71
|
}
|
|
50
72
|
}, [uiState]);
|
|
51
73
|
const showEditPopup = useCallback((item: PriceSegment) => {
|
|
@@ -78,7 +78,7 @@ const MoodItem = (props: MoodItemProps) => {
|
|
|
78
78
|
<View style={styles.contentContainer}>
|
|
79
79
|
{/* 顶部内容 */}
|
|
80
80
|
<View style={styles.row}>
|
|
81
|
-
<Text style={styles.headText}>{mood.name}</Text>
|
|
81
|
+
<Text style={styles.headText} numberOfLines={2}>{mood.name}</Text>
|
|
82
82
|
{/* checkbox 的 TouchableOpacity 现在也应用了阴影样式 */}
|
|
83
83
|
<TouchableOpacity style={styles.checkbox} onPress={() => onSwitch(!enable)}>
|
|
84
84
|
<Image
|