|
|
@@ -8,13 +8,15 @@ import { useSelector } from 'react-redux';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
var currentValue = 0;
|
|
|
-export default function (props: { onChanged?: Function, value?: number, edit?: boolean, isPreMeal?: boolean, id?: string }) {
|
|
|
+var lastValue = 0;
|
|
|
+export default function (props: { onChanged?: Function, value?: number, edit?: boolean, isPreMeal?: boolean, isPostMeal?: boolean, id?: string }) {
|
|
|
const sliderWidth = 578;
|
|
|
const [brightness, setBrightness] = useState(props.value ? props.value * 10 : 0);
|
|
|
const [isSliding, setIsSliding] = useState(false);
|
|
|
const [value, setValue] = useState(props.value ? props.value : 0)
|
|
|
const [startX, setStartX] = useState(0);
|
|
|
const common = useSelector((state: any) => state.common);
|
|
|
+ const [showArrow, setShowArrow] = useState(true)
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -25,6 +27,7 @@ export default function (props: { onChanged?: Function, value?: number, edit?: b
|
|
|
|
|
|
const handleTouchStart = (event) => {
|
|
|
setIsSliding(true);
|
|
|
+ setShowArrow(false);
|
|
|
setStartX(event.touches[0].clientX);
|
|
|
};
|
|
|
|
|
|
@@ -43,8 +46,15 @@ export default function (props: { onChanged?: Function, value?: number, edit?: b
|
|
|
setStartX(touchX)
|
|
|
setBrightness(brightnessValue);
|
|
|
currentValue = brightnessValue;
|
|
|
+ var data = calculateNumber(brightnessValue)
|
|
|
+ if (lastValue != data && data == 5) {
|
|
|
+ Taro.vibrateShort({
|
|
|
+ type: 'heavy'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ lastValue = data
|
|
|
|
|
|
- setValue(calculateNumber(brightnessValue))
|
|
|
+ setValue(data)
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -65,6 +75,7 @@ export default function (props: { onChanged?: Function, value?: number, edit?: b
|
|
|
props.onChanged && props.onChanged(value);
|
|
|
}
|
|
|
else {
|
|
|
+ setShowArrow(true)
|
|
|
if (props.isPreMeal) {
|
|
|
setStartX(0);
|
|
|
setBrightness(0)
|
|
|
@@ -95,6 +106,7 @@ export default function (props: { onChanged?: Function, value?: number, edit?: b
|
|
|
confirmText: '好的',
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
+ setShowArrow(true)
|
|
|
setStartX(0);
|
|
|
setBrightness(0)
|
|
|
setValue(0)
|
|
|
@@ -176,31 +188,31 @@ export default function (props: { onChanged?: Function, value?: number, edit?: b
|
|
|
onTouchMove={handleTouchMove}
|
|
|
onTouchEnd={handleTouchEnd}>
|
|
|
<View className='slider-tip-bg' style={{ width: (100 - brightness) * 0.01 * rpxToPx(sliderWidth - 120) + rpxToPx(28) }}>
|
|
|
- <Text className='slider-tip-title'>{props.isPreMeal || !props.onChanged ?
|
|
|
+ <Text className={value < 5 ? 'slider-tip-title' : 'slider-tip-title-post'}>{value < 5 ?
|
|
|
t('feature.food.slider_tip_pre_meal_title') :
|
|
|
t('feature.food.slider_tip_post_meal_title')}</Text>
|
|
|
- <Text className='slider-tip-desc'>{props.isPreMeal || !props.onChanged ?
|
|
|
+ <Text className={value < 5 ? 'slider-tip-desc' : 'slider-tip-desc-post'}>{value < 5 ?
|
|
|
t('feature.food.slider_tip_pre_meal_desc') :
|
|
|
t('feature.food.slider_tip_post_meal_desc')}</Text>
|
|
|
</View>
|
|
|
<View className='slider-item-content'>
|
|
|
- <View className='slider-item-bg' style={{ width: brightness * 0.01 * rpxToPx(sliderWidth - 126) + rpxToPx(112) }}>
|
|
|
- <View className='slider-item' style={{
|
|
|
- width: brightness * 0.01 * rpxToPx(sliderWidth - 126) + rpxToPx(112)+1,
|
|
|
+ <View className='slider-item-bg' style={{ width: brightness * 0.01 * rpxToPx(sliderWidth - 126) + rpxToPx(112),
|
|
|
+ backgroundColor: value==5?'#fff':value<5?ColorType.fast:ColorType.food}}>
|
|
|
+ {/* <View className='slider-item' style={{
|
|
|
+ width: brightness * 0.01 * rpxToPx(sliderWidth - 126) + rpxToPx(112) + 1,
|
|
|
backgroundColor: brightness <= 50 ? ColorType.fast : ColorType.food,
|
|
|
opacity: calculateOpacity(brightness),
|
|
|
}}>
|
|
|
-
|
|
|
- </View>
|
|
|
+ </View> */}
|
|
|
|
|
|
|
|
|
</View>
|
|
|
</View>
|
|
|
{
|
|
|
- isSliding || value != 0 ? <View className='slider-text-bg'>
|
|
|
+ !showArrow ? <View className='slider-text-bg'>
|
|
|
<Text className='slider-text'>{value}</Text>
|
|
|
</View> :
|
|
|
- <View className='slider-arrow-bg'>
|
|
|
+ <View className='slider-arrow-bg' style={{ left: props.isPostMeal ? brightness * 0.01 * rpxToPx(sliderWidth - 120) : 0 }}>
|
|
|
<Image src={require('@assets/images/arrow4.png')} className='slider-arrow' />
|
|
|
</View>
|
|
|
}
|