|
@@ -11,7 +11,7 @@ var lastValue = 0
|
|
|
export default function Component(props: {
|
|
export default function Component(props: {
|
|
|
step: number, min: number,
|
|
step: number, min: number,
|
|
|
max: number, default_value: number,
|
|
max: number, default_value: number,
|
|
|
- scale:number,
|
|
|
|
|
|
|
+ scale: number,
|
|
|
changed: Function, unit: string
|
|
changed: Function, unit: string
|
|
|
themeColor: string,
|
|
themeColor: string,
|
|
|
updateStatus: Function
|
|
updateStatus: Function
|
|
@@ -25,7 +25,7 @@ export default function Component(props: {
|
|
|
// const [maxNum, setMaxNum] = useState(max)
|
|
// const [maxNum, setMaxNum] = useState(max)
|
|
|
|
|
|
|
|
const stepNum: number = props.step * 10;
|
|
const stepNum: number = props.step * 10;
|
|
|
- const jingdu: number = props.step<0.1?100:props.step < 1 ? 10 : 1;
|
|
|
|
|
|
|
+ const jingdu: number = props.step < 0.1 ? 100 : props.step < 1 ? 10 : 1;
|
|
|
const list: any[] = [];
|
|
const list: any[] = [];
|
|
|
// const [list, setList] = useState([])
|
|
// const [list, setList] = useState([])
|
|
|
|
|
|
|
@@ -38,7 +38,7 @@ export default function Component(props: {
|
|
|
const [enableText, setEnableText] = useState(true)
|
|
const [enableText, setEnableText] = 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(props.scale==0?1:props.scale));
|
|
|
|
|
|
|
+ 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 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;
|
|
var isMiddle: boolean = (Math.round((value - minNum) * jingdu) * 2) % Math.round(stepNum * jingdu) == 0;
|
|
|
|
|
|
|
@@ -49,7 +49,6 @@ export default function Component(props: {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
- console.log(list)
|
|
|
|
|
|
|
|
|
|
// const [showScrollView, setShowScrollView] = useState(false)
|
|
// const [showScrollView, setShowScrollView] = useState(false)
|
|
|
|
|
|
|
@@ -156,7 +155,7 @@ export default function Component(props: {
|
|
|
const { scrollLeft } = e.detail;
|
|
const { scrollLeft } = e.detail;
|
|
|
|
|
|
|
|
var count = scrollLeft / slidngWidth;
|
|
var count = scrollLeft / slidngWidth;
|
|
|
- var strValue = (minNum + Math.round(count) * props.step).toFixed(props.scale==0?1:props.scale);
|
|
|
|
|
|
|
+ var strValue = (minNum + Math.round(count) * props.step).toFixed(props.scale == 0 ? 1 : props.scale);
|
|
|
if ((strValue as any) < minNum) {
|
|
if ((strValue as any) < minNum) {
|
|
|
strValue = minNum as any;
|
|
strValue = minNum as any;
|
|
|
}
|
|
}
|
|
@@ -168,7 +167,7 @@ export default function Component(props: {
|
|
|
if (parseFloat(strValue) != current) {
|
|
if (parseFloat(strValue) != current) {
|
|
|
var data = strValue as any;
|
|
var data = strValue as any;
|
|
|
if (props.step < 1) {
|
|
if (props.step < 1) {
|
|
|
- data = parseFloat(strValue).toFixed(props.scale==0?1:props.scale);
|
|
|
|
|
|
|
+ data = parseFloat(strValue).toFixed(props.scale == 0 ? 1 : props.scale);
|
|
|
if (data.indexOf('.') > 0) {
|
|
if (data.indexOf('.') > 0) {
|
|
|
const regexp = /(?:\.0*|(\.\d+?)0+)$/
|
|
const regexp = /(?:\.0*|(\.\d+?)0+)$/
|
|
|
data = data.replace(regexp, '$1')
|
|
data = data.replace(regexp, '$1')
|
|
@@ -191,15 +190,26 @@ export default function Component(props: {
|
|
|
// setLeft(scrollLeft)
|
|
// 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 style={{ width: 2, height: 100, backgroundColor: 'red', marginRight: 8 }}></View>
|
|
|
|
|
+ // 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>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var svg2 = `<svg xmlns="http://www.w3.org/2000/svg" width="${list.length * 10 - 8}" height="50">`;
|
|
|
|
|
+ for (var i = 0; i < list.length; i++) {
|
|
|
|
|
+ var obj = list[i];
|
|
|
|
|
+ svg2 += `<line x1="${i * 10}" y1="0" x2="${i * 10}" y2="${obj.showBig ? rpxToPx(28) : obj.showMiddle ? rpxToPx(24) : rpxToPx(16)}" stroke="${props.themeColor}" stroke-width="2"/>`
|
|
|
|
|
+ if (obj.showBig) {
|
|
|
|
|
+ svg2 += `<text x="${i * 10}" y="${rpxToPx(30 + 36)}" text-anchor="middle" fill="white" font-size="${rpxToPx(36)}">${obj.value}</text>`
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ svg2 += `</svg>`
|
|
|
|
|
|
|
|
return <View className="slidng">
|
|
return <View className="slidng">
|
|
|
<View className="number_bg" style={{ opacity: enableText ? 1 : 0.4 }}>
|
|
<View className="number_bg" style={{ opacity: enableText ? 1 : 0.4 }}>
|
|
@@ -228,7 +238,7 @@ export default function Component(props: {
|
|
|
<View className="scrollContent">
|
|
<View className="scrollContent">
|
|
|
<View className="scrollPadding" style={{ width: rpxToPx(372) }} />
|
|
<View className="scrollPadding" style={{ width: rpxToPx(372) }} />
|
|
|
<View className="content">
|
|
<View className="content">
|
|
|
- {
|
|
|
|
|
|
|
+ {/* {
|
|
|
list.map((item, index) => {
|
|
list.map((item, index) => {
|
|
|
return <View className={(item as any).showBig ? 'slidng_item_big' : (item as any).showMiddle ? 'slidng_item_middle' : 'slidng_item'}
|
|
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}>
|
|
style={{ width: 2, marginRight: list.length - 1 == index ? 0 : 8, backgroundColor: props.themeColor, zIndex: 0 }} key={index}>
|
|
@@ -237,8 +247,10 @@ export default function Component(props: {
|
|
|
}
|
|
}
|
|
|
</View>
|
|
</View>
|
|
|
})
|
|
})
|
|
|
- }
|
|
|
|
|
- {/* <View style={{position:'fixed',right:0,top:0,width:100,bottom:0,backgroundColor:'red',zIndex:10}}/> */}
|
|
|
|
|
|
|
+ } */}
|
|
|
|
|
+ <View style={{ width: list.length * 10 - 8, height: 200 }}>
|
|
|
|
|
+ <mysvg src={svg2} />
|
|
|
|
|
+ </View>
|
|
|
</View>
|
|
</View>
|
|
|
<View className="scrollPadding" />
|
|
<View className="scrollPadding" />
|
|
|
|
|
|