leon 1 năm trước cách đây
mục cha
commit
e0fbd81f07

+ 13 - 11
src/components/input/SlidngScale.tsx

@@ -20,9 +20,11 @@ export default function Component(props: {
     scale: number,
     changed: Function, unit: string
     themeColor: string,
-    updateStatus: Function
+    updateStatus: Function,
+    special: any
 }) {
     const scrollViewRef = useRef<any>();
+    const isFT_IN = props.special == 'FT_IN'
     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
@@ -38,12 +40,12 @@ export default function Component(props: {
     const slidngWidth = 10
 
     const [current, setCurrent] = useState(props.default_value)
-    const [left, setLeft] = useState((props.default_value - min) * slidngWidth * (props.unit == 'in' ? 1.2 : 1) / props.step - 0.5);
+    const [left, setLeft] = useState((props.default_value - min) * slidngWidth * (isFT_IN ? 1.2 : 1) / props.step - 0.5);
     const [isDraging, setIsDraging] = useState(false)
     const [isEnd, setIsEnd] = useState(true)
     const [enableText, setEnableText] = useState(true)
 
-    if (props.unit == 'in') {
+    if (isFT_IN) {
         for (var i: number = minNum; i <= maxNum * 1.2; i += props.step) {
             var value: number = parseFloat(i.toFixed(props.scale == 0 ? 1 : props.scale));
             var isBig: boolean = i % 12 == 0;
@@ -146,7 +148,7 @@ export default function Component(props: {
         const { scrollLeft } = e.detail;
 
         var count = scrollLeft / slidngWidth;
-        if (props.unit == 'in') {
+        if (isFT_IN) {
             count = count / 1.2
         }
         var strValue = (minNum + Math.round(count) * props.step).toFixed(props.scale == 0 ? 1 : props.scale);
@@ -193,9 +195,9 @@ export default function Component(props: {
     const scrollEnd = (e) => {
     }
 
-    var svgLine = `<svg xmlns="http://www.w3.org/2000/svg" width="${props.unit == 'in' ? 144 : 100}" height="${rpxToPx(28)}">`;
+    var svgLine = `<svg xmlns="http://www.w3.org/2000/svg" width="${isFT_IN ? 144 : 100}" height="${rpxToPx(28)}">`;
     var svgNumber = `<svg xmlns="http://www.w3.org/2000/svg" width="${list.length * 10 - 8 + 60}" height="${rpxToPx(38)}">`;
-    if (props.unit == 'in') {
+    if (isFT_IN) {
         for (var i = 0; i < 12; i++) {
             var obj = list[i];
             svgLine += `<line x1="${i * 12 + 1}" y1="0" x2="${i * 12 + 1}" y2="${obj.showBig ? rpxToPx(28) : obj.showMiddle ? rpxToPx(24) : rpxToPx(16)}" stroke="${props.themeColor}"  stroke-width="2"/>`
@@ -214,7 +216,7 @@ export default function Component(props: {
         var obj = list[i];
         if (obj.showBig) {
             //字体设置参考 https://segmentfault.com/a/1190000006110417
-            svgNumber += `<text x="${i * (props.unit == 'in' ? 12 : 10) + 1 + 30}" y="${rpxToPx(2 + 36)}" text-anchor="middle" fill="white" font-family="PingFang SC,Helvetica Neue,Helvetica,Arial,Hiragino Sans GB,Heiti SC,Microsoft YaHei" font-size="${rpxToPx(36)}">${obj.value}</text>`
+            svgNumber += `<text x="${i * (isFT_IN ? 12 : 10) + 1 + 30}" y="${rpxToPx(2 + 36)}" text-anchor="middle" fill="white" font-family="PingFang SC,Helvetica Neue,Helvetica,Arial,Hiragino Sans GB,Heiti SC,Microsoft YaHei" font-size="${rpxToPx(36)}">${parseInt('' + obj.value / 12)}</text>`
         }
     }
     svgLine += `</svg>`
@@ -226,9 +228,9 @@ export default function Component(props: {
     var imgNum = `url("data:image/svg+xml,${basestr2}");`
 
     var svgLine2 = `<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">`
-    svgLine2 += `<pattern id="pattern" width="${props.unit == 'in' ? 120 : 100}" height="${rpxToPx(28)}" patternUnits="userSpaceOnUse">`
+    svgLine2 += `<pattern id="pattern" width="${isFT_IN ? 120 : 100}" height="${rpxToPx(28)}" patternUnits="userSpaceOnUse">`
 
-    if (props.unit == 'in') {
+    if (isFT_IN) {
         for (var i = 0; i < 12; i++) {
             var obj = list[i];
             svgLine2 += `<line x1="${i * 12 + 1}" y1="0" x2="${i * 12 + 1}" y2="${obj.showBig ? rpxToPx(28) : obj.showMiddle ? rpxToPx(24) : rpxToPx(16)}" stroke="${props.themeColor}"  stroke-width="2"/>`
@@ -247,7 +249,7 @@ export default function Component(props: {
 
     return <View className="slidng">
         {
-            props.unit == 'in' && <View className="number_bg" style={{ opacity: enableText ? 1 : 0.4 }}>
+            isFT_IN && <View className="number_bg" style={{ opacity: enableText ? 1 : 0.4 }}>
                 {
                     parseInt(current / 12 + '') > 0 && (process.env.TARO_ENV == 'weapp' ? <Text className="number" style={{ fontFamily: "PingFang SC,Helvetica Neue, Helvetica, Arial, Hiragino Sans GB, Heiti SC, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif;" }}>{parseInt(current / 12 + '')}</Text> :
                         <Text className="number">{parseInt(current / 12 + '')}</Text>)
@@ -301,7 +303,7 @@ export default function Component(props: {
                         <View>
                             <View style={{ width: list.length * 10 - 8, height: 100 }}>
                                 {
-                                    process.env.TARO_ENV == 'weapp' && <View style={{ width: props.unit == 'in' ? list.length * 10 - 8 : list.length * 10 - 8, height: rpxToPx(28), backgroundImage: imgLines, overflow: 'hidden' }} />
+                                    process.env.TARO_ENV == 'weapp' && <View style={{ width: isFT_IN ? list.length * 10 - 8 : list.length * 10 - 8, height: rpxToPx(28), backgroundImage: imgLines, overflow: 'hidden' }} />
                                 }
                                 {
                                     process.env.TARO_ENV == 'rn' && <SvgXml xml={svgLine2} width={list.length * 10 - 8} height={rpxToPx(28)} />

+ 13 - 7
src/features/trackSomething/components/MetricModalAdd.tsx

@@ -24,10 +24,15 @@ export default function Component(props: { item: any, strTime: string, showPicke
                 {
                     (metricItem as any).schemas.map((item, index) => {
                         var obj = item;
-                        const {unit_options} = item;
-                        if (unit_options && unit_options.length>0){
-                            obj = unit_options[0];
+                        const { unit_options, chosen_unit } = item;
+                        if (unit_options && unit_options.length > 0) {
+                            unit_options.map(temp => {
+                                if (temp.unit == chosen_unit) {
+                                    obj = temp
+                                }
+                            })
                         }
+                        debugger
                         return <View key={index}>
                             {
                                 (metricItem as any).schemas.length > 1 && <Text style={{
@@ -39,7 +44,8 @@ export default function Component(props: { item: any, strTime: string, showPicke
                             <SlidngScale step={obj.step} min={obj.min} max={obj.max}
                                 default_value={obj.default_value}
                                 scale={obj.scale}
-                                unit={obj.unit}
+                                unit={obj.unit?obj.unit:item.unit}
+                                special={obj.special ?? null}
                                 themeColor={(metricItem as any).theme_color}
                                 changed={(e) => { obj.tempValue = e }}
                                 updateStatus={(isEnable) => {
@@ -50,14 +56,14 @@ export default function Component(props: { item: any, strTime: string, showPicke
                 }
             </View>
             <View className="change_time_bg" >
-                <View className="gray1 time_bg"onClick={() => { props.showPicker(metricItem) }}>
+                <View className="gray1 time_bg" onClick={() => { props.showPicker(metricItem) }}>
                     <Text className="time" >{props.strTime}</Text>
                 </View>
 
             </View>
             <View className='modal_operate'>
                 <View className='modal_btn' style={{ backgroundColor: (metricItem as any).theme_color + alphaToHex(0.4) }} onClick={() => props.cancel()}>
-                    <Text className='modal_cancel_text' style={{ color: (metricItem as any).theme_color,fontWeight:'bold' }}>{
+                    <Text className='modal_cancel_text' style={{ color: (metricItem as any).theme_color, fontWeight: 'bold' }}>{
                         t('feature.common.picker_cancel_btn')
                     }</Text>
                 </View>
@@ -67,7 +73,7 @@ export default function Component(props: { item: any, strTime: string, showPicke
                         props.confirm(metricItem)
                     }
                 }}>
-                    <Text className='modal_confirm_text' style={{ color: '#000',fontWeight:'bold' }}>{
+                    <Text className='modal_confirm_text' style={{ color: '#000', fontWeight: 'bold' }}>{
                         t('feature.common.picker_confirm_btn')
                     }</Text>
                 </View>