|
@@ -1,7 +1,9 @@
|
|
|
import { ScrollView, View, Text, Image } from "@tarojs/components";
|
|
import { ScrollView, View, Text, Image } from "@tarojs/components";
|
|
|
|
|
+import VirtualList from '@tarojs/components/virtual-list';
|
|
|
import './SlidngScale.scss'
|
|
import './SlidngScale.scss'
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
import Taro from "@tarojs/taro";
|
|
import Taro from "@tarojs/taro";
|
|
|
|
|
+import { rpxToPx } from "@/utils/tools";
|
|
|
|
|
|
|
|
export default function Component(props: {
|
|
export default function Component(props: {
|
|
|
step: number, min: number,
|
|
step: number, min: number,
|
|
@@ -9,8 +11,8 @@ export default function Component(props: {
|
|
|
themeColor: string
|
|
themeColor: string
|
|
|
}) {
|
|
}) {
|
|
|
const scrollViewRef = useRef<any>();
|
|
const scrollViewRef = useRef<any>();
|
|
|
- const minNum: number = props.min;
|
|
|
|
|
- const maxNum: number = props.max;
|
|
|
|
|
|
|
+ const minNum: number = props.min;//props.step < 1 ?props.default_value-1:props.default_value-10//
|
|
|
|
|
+ const maxNum: number = props.max;//props.step < 1 ?props.default_value+1:props.default_value+10//
|
|
|
|
|
|
|
|
|
|
|
|
|
const stepNum: number = props.step * 10;
|
|
const stepNum: number = props.step * 10;
|
|
@@ -21,7 +23,7 @@ export default function Component(props: {
|
|
|
|
|
|
|
|
const [current, setCurrent] = useState(props.default_value)
|
|
const [current, setCurrent] = useState(props.default_value)
|
|
|
const [left, setLeft] = useState((props.default_value - minNum) * slidngWidth / props.step + 1);
|
|
const [left, setLeft] = useState((props.default_value - minNum) * slidngWidth / props.step + 1);
|
|
|
- const [showScrollView, setShowScrollView] = useState(false)
|
|
|
|
|
|
|
+ const [showScrollView, setShowScrollView] = useState(true)
|
|
|
|
|
|
|
|
for (var i: number = minNum; i <= maxNum; i += props.step) {
|
|
for (var i: number = minNum; i <= maxNum; i += props.step) {
|
|
|
var value: number = parseFloat(i.toFixed(1));
|
|
var value: number = parseFloat(i.toFixed(1));
|
|
@@ -37,12 +39,9 @@ export default function Component(props: {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- // var aa = current-props.min;
|
|
|
|
|
- // var bb = aa/props.step*slidngWidth;
|
|
|
|
|
- // setLeft(bb/ratio)
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- setShowScrollView(true)
|
|
|
|
|
- }, 50)
|
|
|
|
|
|
|
+ // setTimeout(() => {
|
|
|
|
|
+ // setShowScrollView(true)
|
|
|
|
|
+ // }, 50)
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
// const dpr = Taro.pxTransform//Taro.getSystemInfoSync().pixelRatio;
|
|
// const dpr = Taro.pxTransform//Taro.getSystemInfoSync().pixelRatio;
|
|
@@ -86,6 +85,18 @@ export default function Component(props: {
|
|
|
setLeft(scrollLeft)
|
|
setLeft(scrollLeft)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ console.log(list.length)
|
|
|
|
|
+
|
|
|
|
|
+ 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>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return <View className="slidng">
|
|
return <View className="slidng">
|
|
|
<View className="number_bg">
|
|
<View className="number_bg">
|
|
|
<Text className="number">{current}</Text>
|
|
<Text className="number">{current}</Text>
|
|
@@ -98,26 +109,35 @@ export default function Component(props: {
|
|
|
<View className="shadow_right" />
|
|
<View className="shadow_right" />
|
|
|
{showScrollView && <View className="top_line" style={{ backgroundColor: props.themeColor }} />}
|
|
{showScrollView && <View className="top_line" style={{ backgroundColor: props.themeColor }} />}
|
|
|
{
|
|
{
|
|
|
- showScrollView && <ScrollView style={{ zIndex: 0 }} ref={scrollViewRef} scrollX enhanced scrollLeft={left} className="scroll" onScroll={handleScroll} onDragEnd={scrollEnd}>
|
|
|
|
|
|
|
+ showScrollView && <ScrollView style={{ zIndex: 0,position:'relative' }} ref={scrollViewRef} scrollX enhanced scrollLeft={left} className="scroll" onScroll={handleScroll} onDragEnd={scrollEnd}>
|
|
|
<View className="scrollContent">
|
|
<View className="scrollContent">
|
|
|
<View className="scrollPadding" />
|
|
<View className="scrollPadding" />
|
|
|
<View className="content">
|
|
<View className="content">
|
|
|
- {
|
|
|
|
|
|
|
+ {
|
|
|
list.map((item, index) => {
|
|
list.map((item, index) => {
|
|
|
- return <View className={item.showBig ? 'slidng_item_big' : item.showMiddle ? 'slidng_item_middle' : 'slidng_item'} style={{ width: 2, marginRight: 8, backgroundColor: props.themeColor }} key={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
|
|
item.showBig ? <Text className="slidng_text">{item.value}</Text> : null
|
|
|
}
|
|
}
|
|
|
</View>
|
|
</View>
|
|
|
})
|
|
})
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ <View style={{position:'fixed',right:0,top:0,width:100,bottom:0,backgroundColor:'red',zIndex:10}}/>
|
|
|
</View>
|
|
</View>
|
|
|
- {/* <View className="demo2"/> */}
|
|
|
|
|
<View className="scrollPadding" />
|
|
<View className="scrollPadding" />
|
|
|
|
|
+
|
|
|
</View>
|
|
</View>
|
|
|
|
|
|
|
|
</ScrollView>
|
|
</ScrollView>
|
|
|
}
|
|
}
|
|
|
|
|
+ {/* <VirtualList height={rpxToPx(300)} width={rpxToPx(750)} onScroll={handleScroll} layout="horizontal"
|
|
|
|
|
+ initialScrollOffset={left}
|
|
|
|
|
+ itemCount={list.length}
|
|
|
|
|
+ item={itemContent}
|
|
|
|
|
+ itemSize={10}
|
|
|
|
|
+ itemData={list}
|
|
|
|
|
+ /> */}
|
|
|
|
|
|
|
|
<Image className="center_line" src={require('@assets/images/scale_center.png')} />
|
|
<Image className="center_line" src={require('@assets/images/scale_center.png')} />
|
|
|
{/* <View className="center_line" /> */}
|
|
{/* <View className="center_line" /> */}
|