Leon 1 year ago
parent
commit
6bfc69c67b

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

@@ -51,8 +51,10 @@ export default function Component(props: {
         setIsChanging(true)
         setTimeout(() => {
             setIsChanging(false)
-        }, 700)
-    }, [props.unit, props.default_value,props.special])
+        }, process.env.TARO_ENV == 'weapp' ? 700 : 100)
+
+    }, [props.unit, props.default_value, props.special])
+
 
 
     if (isFT_IN) {
@@ -81,6 +83,7 @@ export default function Component(props: {
             })
         }
     }
+    console.log('list length', list.length)
 
 
     useEffect(() => {
@@ -97,6 +100,9 @@ export default function Component(props: {
     }, [isEnd, isDraging])
 
     function scrollContent(e) {
+        if (global.dimissSel) {
+            global.dimissSel()
+        }
         if (isChanging) {
             return
         }
@@ -118,7 +124,9 @@ export default function Component(props: {
     }
 
     const handleScroll = throttle((e) => {
-
+        if (global.dimissSel) {
+            global.dimissSel()
+        }
         update(e)
 
 
@@ -144,6 +152,7 @@ export default function Component(props: {
     }
 
     function dragStart(e) {
+        debugger
         lastValue = e.detail.scrollLeft;
         setIsEnd(false)
         setIsDraging(true)
@@ -155,7 +164,6 @@ export default function Component(props: {
 
     function update(e) {
         const { scrollLeft } = e.detail;
-        debugger
         var count = scrollLeft / slidngWidth;
         if (isFT_IN) {
             count = count / 1.2
@@ -237,7 +245,7 @@ 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="${isFT_IN ? 120 : 100}" height="${rpxToPx(28)}" patternUnits="userSpaceOnUse">`
+    svgLine2 += `<pattern id="pattern" width="${isFT_IN ? 144 : 100}" height="${rpxToPx(28)}" patternUnits="userSpaceOnUse">`
 
     if (isFT_IN) {
         for (var i = 0; i < 12; i++) {

+ 6 - 0
src/components/layout/layout.tsx

@@ -74,6 +74,9 @@ export default function Layout(props: {
     }
 
     function onScroll(e) {
+        if (global.dimissSel){
+            global.dimissSel()
+        }
         if (props.titleShowStyle == NaviBarTitleShowType.scrollToShow) {
             if (e.nativeEvent){
                 const {contentOffset} = e.nativeEvent
@@ -107,6 +110,9 @@ export default function Layout(props: {
     }
 
     usePageScroll((e) => {
+        if (global.dimissSel){
+            global.dimissSel()
+        }
         if (props.titleShowStyle == NaviBarTitleShowType.scrollToShow) {
             if (e.scrollTop > 70) {
                 setShowTitle(true)

+ 15 - 11
src/features/trackSomething/components/MetricHistory.tsx

@@ -24,6 +24,10 @@ export default function Component(props: { records: any[] }) {
 
     }, [props.records])
 
+    global.dimissSel = ()=>{
+        setSelIndex([-1,-1])
+    }
+
     function formateHourMinutes(timestamp: number) {
         var date = new Date(timestamp)
         var hour = date.getHours()
@@ -142,9 +146,12 @@ export default function Component(props: { records: any[] }) {
     }
 
     var lastYearStr = '2050年'
-    return <View style={{ display: 'flex', flexDirection: 'column' }}>
+    return <View style={{ display: 'flex', flexDirection: 'column' }} onClick={()=>{setSelIndex([-1,-1])}}>
         {
-            user.test_user && <Text style={{ color: '#fff', position: 'absolute', right: 50, top: 0 }} onClick={() => global.clearHistory()}>删除全部</Text>
+            user.test_user && <Text style={{ color: '#fff', position: 'absolute', right: 50, top: 0 }} onClick={() => {
+                debugger
+                global.clearHistory()
+            }}>删除全部</Text>
         }
         {
             metricStandard()
@@ -161,7 +168,12 @@ export default function Component(props: { records: any[] }) {
                     {
                         item.records.map((record, j) => {
                             return <RecordItem delete={() => deleteRecord(record)}>
-                                <View className="operate_item1" onClick={() => tapItem(index, j)} style={{ position: 'relative' }}>
+                                <View className="operate_item1" onClick={(e) => {
+                                    if (process.env.TARO_ENV=='weapp'){
+                                        e.stopPropagation()
+                                    }
+                                    tapItem(index, j)
+                                }} style={{ position: 'relative' }}>
                                     {
                                         index == selIndex[0] && j == selIndex[1] && <View style={{ position: 'absolute', right: 20, zIndex: 1000000 }}>
                                             <View style={{ display: 'flex', flexDirection: 'column', position: 'absolute', top: 30, right: 0, backgroundColor: 'red' }}>
@@ -171,14 +183,6 @@ export default function Component(props: { records: any[] }) {
 
                                                             changeUnit(k)
                                                             setSelIndex([-1,-1])
-                                                            // var dt = JSON.parse(JSON.stringify(metricItem))
-                                                            // dt.schemas[index].chosen_unit = obj.unit
-                                                            // setMetricItem(dt)
-
-                                                            // setChangeIndex(index)
-                                                            // setTimeout(() => {
-                                                            //     setChangeIndex(-1)
-                                                            // }, 100)
                                                         }}>
                                                             <Text>{obj.unit}</Text>
                                                         </View>

+ 60 - 25
src/features/trackSomething/components/MetricModalAdd.tsx

@@ -1,7 +1,7 @@
 import { View, Text, CoverView } from '@tarojs/components'
 import './MetricModalAdd.scss'
 import { useTranslation } from 'react-i18next'
-import { alphaToHex } from '@/utils/tools'
+import { alphaToHex, rpxToPx } from '@/utils/tools'
 import SlidngScale from '@/components/input/SlidngScale'
 import { useEffect, useState } from 'react'
 
@@ -9,8 +9,9 @@ export default function Component(props: { item: any, strTime: string, showPicke
     const [metricItem, setMetricItem] = useState(props.item)
     const [enable, setEnable] = useState(true)
     const [currentSel, setCurrentSel] = useState<any>({})
-    const [selUnit,setSelUnit] = useState(-1)
-    const [changeIndex,setChangeIndex] = useState(-1)
+    const [selUnit, setSelUnit] = useState(-1)
+    const [changeIndex, setChangeIndex] = useState(-1)
+    const [isChanging, setIsChanging] = useState(false)
     // const [disableCode,setDisableCode] = useState(0)
     const { t } = useTranslation()
 
@@ -20,6 +21,10 @@ export default function Component(props: { item: any, strTime: string, showPicke
         setMetricItem(props.item)
     }, [props.item])
 
+    global.dimissSel = () => {
+        setSelUnit(-1)
+    }
+
     return <View>
         <View className='modal_content'>
             <Text className='modal_title' style={{ color: (metricItem as any).theme_color }}>{(metricItem as any).name ? (metricItem as any).name : ''}</Text>
@@ -38,7 +43,7 @@ export default function Component(props: { item: any, strTime: string, showPicke
                                 }
                             })
                         }
-                        return <View key={index} style={{position:'relative'}}>
+                        return <View key={index} style={{ position: 'relative' }}>
                             {
                                 (metricItem as any).schemas.length > 1 && <Text style={{
                                     textAlign: 'center', width: '100%', display: 'flex',
@@ -47,23 +52,31 @@ export default function Component(props: { item: any, strTime: string, showPicke
                                 }}>{item.name}</Text>
                             }
                             {
-                                unit_options && unit_options.length > 1 && <View style={{position:'absolute',right:20,zIndex:1000000}}>
-                                    <Text style={{color:'#fff'}} onClick={()=>{
+                                unit_options && unit_options.length > 1 && <View style={{ position: 'absolute', right: 20, zIndex: 1000000 }}>
+                                    <Text style={{ color: '#fff' }} onClick={(e) => {
+                                        if (process.env.TARO_ENV == 'weapp') {
+                                            e.stopPropagation()
+                                        }
                                         setSelUnit(index)
                                     }}>切换</Text>
                                     {
-                                        selUnit==index && <View style={{display:'flex',flexDirection:'column',position:'absolute',top:30,right:0,backgroundColor:'red'}}>
+                                        selUnit == index && <View style={{ display: 'flex', flexDirection: 'column', position: 'absolute', top: 30, right: 0, backgroundColor: 'red' }}>
                                             {
-                                                unit_options.map((obj,j)=>{
-                                                    return <View key={j*1000} onClick={()=>{
+                                                unit_options.map((obj, j) => {
+                                                    return <View key={j * 1000} onClick={() => {
                                                         var dt = JSON.parse(JSON.stringify(metricItem))
                                                         dt.schemas[index].chosen_unit = obj.unit
                                                         setMetricItem(dt)
 
                                                         setChangeIndex(index)
-                                                        setTimeout(()=>{
+                                                        setIsChanging(true)
+                                                        setTimeout(() => {
+                                                            setIsChanging(false)
+                                                        }, 20)
+                                                        setTimeout(() => {
                                                             setChangeIndex(-1)
-                                                        },100)
+
+                                                        }, 100)
                                                     }}>
                                                         <Text>{obj.unit}</Text>
                                                     </View>
@@ -73,20 +86,42 @@ export default function Component(props: { item: any, strTime: string, showPicke
                                     }
                                 </View>
                             }
-                            <SlidngScale step={obj.step} min={obj.min} max={obj.max}
-                                default_value={obj.default_value}
-                                scale={obj.scale}
-                                unit={obj.unit ? obj.unit : item.default_unit}
-                                special={obj.special ?? null}
-                                themeColor={(metricItem as any).theme_color}
-                                changed={(e) => { 
-                                    item.tempValue = e; 
-                                    item.tempUnit = obj.unit ? obj.unit : item.default_unit
-                                    debugger
-                                }}
-                                updateStatus={(isEnable) => {
-                                    setEnable(isEnable)
-                                }} />
+                            {
+                                !isChanging && process.env.TARO_ENV == 'rn' && <SlidngScale step={obj.step} min={obj.min} max={obj.max}
+                                    default_value={obj.default_value}
+                                    scale={obj.scale}
+                                    unit={obj.unit ? obj.unit : item.default_unit}
+                                    special={obj.special ?? null}
+                                    themeColor={(metricItem as any).theme_color}
+                                    changed={(e) => {
+                                        item.tempValue = e;
+                                        item.tempUnit = obj.unit ? obj.unit : item.default_unit
+                                        debugger
+                                    }}
+                                    updateStatus={(isEnable) => {
+                                        setEnable(isEnable)
+                                    }} />
+                            }
+                            {
+                                isChanging && process.env.TARO_ENV == 'rn' && <View style={{ height: rpxToPx(240) }} />
+                            }
+                            {
+                                process.env.TARO_ENV == 'weapp' && <SlidngScale step={obj.step} min={obj.min} max={obj.max}
+                                    default_value={obj.default_value}
+                                    scale={obj.scale}
+                                    unit={obj.unit ? obj.unit : item.default_unit}
+                                    special={obj.special ?? null}
+                                    themeColor={(metricItem as any).theme_color}
+                                    changed={(e) => {
+                                        item.tempValue = e;
+                                        item.tempUnit = obj.unit ? obj.unit : item.default_unit
+                                        debugger
+                                    }}
+                                    updateStatus={(isEnable) => {
+                                        setEnable(isEnable)
+                                    }} />
+                            }
+
                         </View>
                     })
                 }

+ 1 - 0
src/pages/common/RecordsHistory.tsx

@@ -280,6 +280,7 @@ export default function Page() {
         // var page = Taro.getCurrentPages()[0]
         // debugger
         // page.refresh()
+        debugger
         showAlert({
             title: t('feature.common.modal.delete_all_title'),
             content: t('feature.common.modal.delete_all_content'),