|
|
@@ -10,30 +10,35 @@ var timerA = null
|
|
|
var lastValue = 0
|
|
|
export default function Component(props: {
|
|
|
step: number, min: number,
|
|
|
- max: number, default_value: number, changed: Function, unit: string
|
|
|
+ max: number, default_value: number,
|
|
|
+ scale:number,
|
|
|
+ changed: Function, unit: string
|
|
|
themeColor: string,
|
|
|
updateStatus: Function
|
|
|
}) {
|
|
|
const scrollViewRef = useRef<any>();
|
|
|
const minNum: number = props.min;//props.step < 1 ?props.default_value-2:props.default_value-20//
|
|
|
const maxNum: number = props.max;//props.step < 1 ?props.default_value+2:props.default_value+20//
|
|
|
+ const min = props.min//(props.default_value - props.step * 20) < props.min ? props.min : props.default_value - props.step * 20
|
|
|
+ const max = props.max//(props.default_value + props.step * 20) > props.max ? props.max : props.default_value + props.step * 20
|
|
|
+ // const [minNum, setMinNum] = useState(min)
|
|
|
+ // const [maxNum, setMaxNum] = useState(max)
|
|
|
|
|
|
const stepNum: number = props.step * 10;
|
|
|
- const jingdu: number = props.step < 1 ? 10 : 1;
|
|
|
+ const jingdu: number = props.step<0.1?100:props.step < 1 ? 10 : 1;
|
|
|
const list: any[] = [];
|
|
|
+ // const [list, setList] = useState([])
|
|
|
|
|
|
const slidngWidth = 10
|
|
|
|
|
|
const [current, setCurrent] = useState(props.default_value)
|
|
|
- const [left, setLeft] = useState((props.default_value - minNum) * slidngWidth / props.step);
|
|
|
+ const [left, setLeft] = useState((props.default_value - min) * slidngWidth / props.step);
|
|
|
const [isDraging, setIsDraging] = useState(false)
|
|
|
const [isEnd, setIsEnd] = useState(true)
|
|
|
const [enableText, setEnableText] = useState(true)
|
|
|
|
|
|
- // const [showScrollView, setShowScrollView] = useState(false)
|
|
|
-
|
|
|
for (var i: number = minNum; i <= maxNum; i += props.step) {
|
|
|
- var value: number = parseFloat(i.toFixed(1));
|
|
|
+ var value: number = parseFloat(i.toFixed(props.scale==0?1:props.scale));
|
|
|
var isBig: boolean = Math.round((value - minNum) * jingdu) % Math.round(stepNum * jingdu) == 0;
|
|
|
var isMiddle: boolean = (Math.round((value - minNum) * jingdu) * 2) % Math.round(stepNum * jingdu) == 0;
|
|
|
|
|
|
@@ -44,6 +49,47 @@ export default function Component(props: {
|
|
|
})
|
|
|
|
|
|
}
|
|
|
+ console.log(list)
|
|
|
+
|
|
|
+ // const [showScrollView, setShowScrollView] = useState(false)
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ // var array: any = []
|
|
|
+ // for (var i: number = min; i <= max; i += props.step) {
|
|
|
+ // var value: number = parseFloat(i.toFixed(props.scale));
|
|
|
+ // var isBig: boolean = Math.round((value - min) * jingdu) % Math.round(stepNum * jingdu) == 0;
|
|
|
+ // var isMiddle: boolean = (Math.round((value - min) * jingdu) * 2) % Math.round(stepNum * jingdu) == 0;
|
|
|
+
|
|
|
+ // array.push({
|
|
|
+ // value: props.step < 1 ? value : Math.round(value),
|
|
|
+ // showBig: isBig && i >= min && i <= max,
|
|
|
+ // showMiddle: isMiddle && !isBig && i >= min && i <= max
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // setList(array)
|
|
|
+
|
|
|
+ // setTimeout(() => {
|
|
|
+ // var min2 = props.min
|
|
|
+ // var max2 = props.max
|
|
|
+ // setMinNum(min2)
|
|
|
+ // setMaxNum(max2)
|
|
|
+ // setLeft((props.default_value - min2) * slidngWidth / props.step)
|
|
|
+
|
|
|
+ // var array2: any = []
|
|
|
+ // for (var i: number = min2; i <= max2; i += props.step) {
|
|
|
+ // var value: number = parseFloat(i.toFixed(1));
|
|
|
+ // var isBig: boolean = Math.round((value - min2) * jingdu) % Math.round(stepNum * jingdu) == 0;
|
|
|
+ // var isMiddle: boolean = (Math.round((value - min2) * jingdu) * 2) % Math.round(stepNum * jingdu) == 0;
|
|
|
+
|
|
|
+ // array2.push({
|
|
|
+ // value: props.step < 1 ? value : Math.round(value),
|
|
|
+ // showBig: isBig && i >= min2 && i <= max2,
|
|
|
+ // showMiddle: isMiddle && !isBig && i >= min2 && i <= max2
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // setList(array2)
|
|
|
+ // }, 50)
|
|
|
+ }, [])
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (isEnd && !isDraging) {
|
|
|
@@ -110,7 +156,7 @@ export default function Component(props: {
|
|
|
const { scrollLeft } = e.detail;
|
|
|
|
|
|
var count = scrollLeft / slidngWidth;
|
|
|
- var strValue = (minNum + Math.round(count) * props.step).toFixed(1);
|
|
|
+ var strValue = (minNum + Math.round(count) * props.step).toFixed(props.scale==0?1:props.scale);
|
|
|
if ((strValue as any) < minNum) {
|
|
|
strValue = minNum as any;
|
|
|
}
|
|
|
@@ -122,7 +168,7 @@ export default function Component(props: {
|
|
|
if (parseFloat(strValue) != current) {
|
|
|
var data = strValue as any;
|
|
|
if (props.step < 1) {
|
|
|
- data = parseFloat(strValue).toFixed(1);
|
|
|
+ data = parseFloat(strValue).toFixed(props.scale==0?1:props.scale);
|
|
|
if (data.indexOf('.') > 0) {
|
|
|
const regexp = /(?:\.0*|(\.\d+?)0+)$/
|
|
|
data = data.replace(regexp, '$1')
|
|
|
@@ -145,17 +191,16 @@ export default function Component(props: {
|
|
|
// setLeft(scrollLeft)
|
|
|
}
|
|
|
|
|
|
- function itemContent(data) {
|
|
|
- var item = list[data.index]
|
|
|
- var index = data.index
|
|
|
- return <View className={item.showBig ? 'slidng_item_big' : item.showMiddle ? 'slidng_item_middle' : 'slidng_item'} style={{ width: 2, marginRight: 8, backgroundColor: props.themeColor, zIndex: 0 }} key={index}>
|
|
|
- {
|
|
|
- item.showBig ? <Text className="slidng_text">{item.value}</Text> : null
|
|
|
- }
|
|
|
- </View>
|
|
|
- }
|
|
|
+ // function itemContent(data) {
|
|
|
+ // var item = list[data.index]
|
|
|
+ // var index = data.index
|
|
|
+ // return <View className={item.showBig ? 'slidng_item_big' : item.showMiddle ? 'slidng_item_middle' : 'slidng_item'} style={{ width: 2, marginRight: 8, backgroundColor: props.themeColor, zIndex: 0 }} key={index}>
|
|
|
+ // {
|
|
|
+ // item.showBig ? <Text className="slidng_text">{item.value}</Text> : null
|
|
|
+ // }
|
|
|
+ // </View>
|
|
|
+ // }
|
|
|
|
|
|
- console.log(isEnd, isDraging)
|
|
|
return <View className="slidng">
|
|
|
<View className="number_bg" style={{ opacity: enableText ? 1 : 0.4 }}>
|
|
|
<Text className="number">{current}</Text>
|
|
|
@@ -181,14 +226,14 @@ export default function Component(props: {
|
|
|
enhanced
|
|
|
>
|
|
|
<View className="scrollContent">
|
|
|
- <View className="scrollPadding" style={{width:rpxToPx(372)}}/>
|
|
|
+ <View className="scrollPadding" style={{ width: rpxToPx(372) }} />
|
|
|
<View className="content">
|
|
|
{
|
|
|
list.map((item, index) => {
|
|
|
- return <View className={item.showBig ? 'slidng_item_big' : item.showMiddle ? 'slidng_item_middle' : 'slidng_item'}
|
|
|
- style={{ width: 2, marginRight: list.length-1==index?0:8, backgroundColor: props.themeColor, zIndex: 0 }} key={index}>
|
|
|
+ return <View className={(item as any).showBig ? 'slidng_item_big' : (item as any).showMiddle ? 'slidng_item_middle' : 'slidng_item'}
|
|
|
+ style={{ width: 2, marginRight: list.length - 1 == index ? 0 : 8, backgroundColor: props.themeColor, zIndex: 0 }} key={index}>
|
|
|
{
|
|
|
- item.showBig ? <Text className="slidng_text">{item.value}</Text> : null
|
|
|
+ (item as any).showBig ? <Text className="slidng_text">{(item as any).value}</Text> : null
|
|
|
}
|
|
|
</View>
|
|
|
})
|