/** * 充电中的页面组件 * @邠心vbe on 2021/04/13 */ import React, { useRef, useEffect, useState } from 'react'; import { Animated, View, Easing, StyleSheet, Image, Text, ImageBackground, TextInput } from 'react-native'; import { RadialGradient } from 'react-native-gradients'; import Modal from 'react-native-modal'; import { ModalProps } from '../../components/BottomModal'; import Button, { ElevationObject, ViewHeight } from '../../components/Button'; import ChargeItemSelect from '../../icons/ChargeItemSelect'; import { DialogMaxWidth } from './InfoDialog'; import { QRResult } from '../charge/QRScan'; import Svg, { Defs, LinearGradient, Rect, Stop } from 'react-native-svg'; import utils from '../../utils/utils'; import TextView from '../../components/TextView'; export const circleSize = $vw(50.66) < 300 ? $vw(50.66) : 300; const batterySize = 0.463 * circleSize; const batteryWidth = 0.659*batterySize; export const TypeImage = { AC: require('../../images/charge/ic-type-ac.png'), DC: require('../../images/charge/ic-type-dc.png'), CHADEMO: require('../../images/charge/ic-type-chademo.png') } export const TypeImageList = [ { name: 'AC', key: 'AC', icon: require('../../images/charge/ic-type-ac.png') }, { name: 'DC', key: 'DC', icon: require('../../images/charge/ic-type-dc.png') }, /*{ name: 'Chademo', key: 'CHADEMO', icon: require('../../images/charge/ic-type-chademo.png') }*/ ] export const getConnectTypeByKey = (key) => { for (let item of TypeImageList) { if (item.key == key) { return item; } } } export const CircleAnimate = ({isStart = false}) => { var rotate = useRef(new Animated.Value(0)).current; const spins = () => { Animated.timing(rotate, { toValue: 1, duration: 10000, easing: Easing.linear, useNativeDriver: true }).start(() => { rotate.setValue(0); spins(); }); } useEffect(() => { if (isStart) { spins(); } }, [rotate]); const spin = rotate.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '360deg'] }) return ( { isStart && } ); } export const BatteryView = ({soc, isPending, isCharging}) => { var [powerPercent, setPercent] = useState(-1); /*var [powerText, setText] = useState(0); const autoCharge = () => { setTimeout(() => { const p = powerPercent + 0.001 setPercent(Number(p.toFixed(4))) setText((powerPercent * 100).toFixed(0)) if (powerPercent >= 1) { onComplete(); } }, 50 + powerPercent * 100); } useEffect(() => { if (run && powerPercent <= 1) { autoCharge(); } }, [powerPercent])*/ useEffect(() => { if (isCharging) { try { var s = '-1' + soc; var d = '' + parseInt(s); d = d.replace('-1', ''); if (d) { setPercent(parseInt(d)) } else { setPercent(-1); } } catch (e) { setPercent(-1); } } }, [soc]); const getOpacity = (unit) => { var op = 1 * (powerPercent + unit); return op < 1 ? op : 1; } const getHeight = () => { if (powerPercent > 1) { return batterySize * powerPercent / 100; } else if (powerPercent > 0) { return batterySize * powerPercent; } else { return 0 } } return ( isCharging ? { isPending ? {$t('charging.statusInitiating')} : powerPercent != -1 ? {powerPercent}% : {$t('charging.statusInCharging')} } : {$t('charging.tipsDisconnectConnector')} ); } export const DashboardView = ({isCharging=false, connectorInfo={}}) => { if (isCharging) { return ( {$t('charging.chargingInProgress')} {utils.minutes2HHmm(connectorInfo?.timeElapsed ?? 0)} {$t('charging.labelTimeElapsed')} {utils.toFixed(connectorInfo?.totalKWhDelivered, 2) ?? "0"} kWh {$t('charging.labelTotalkWh')} {/* {currency} {utils.toFixed(connectorInfo?.totalCharges, 2) ?? "0.0"} */} {connectorInfo?.totalCharges ?? "$0.0"} {$t('charging.labelTotalCharges')} ) } else { return ( {$t('charging.pressStartToBegin')} - {$t('charging.labelTimeElapsed')} - {$t('charging.labelTotalkWh')} - {$t('charging.labelTotalCharges')} ) } } export const EnterStationDialog = ({visible, stationId, onConfirm, onClose}) => { var [inputStationId, setInput] = useState('') var [iosKillDialog, killDialog] = useState(true) const enterStatioinId= () => { //console.log(inputStationId); if (inputStationId) { if (isIOS && iosKillDialog) { onClose(); killDialog(false); } else { QRResult.applyInputStation(inputStationId, stationId, (success, err) => { setInput('') if (success) { if (onConfirm) onConfirm() } else if (err) { toastShort(err) } if (onClose) onClose() }); } } else { toastShort($t('charging.plsInputStationId')); } } useEffect(() => { if (!visible && !iosKillDialog) { killDialog(true); setTimeout(() => { enterStatioinId(); }, 100); } }, [iosKillDialog]) return ( iosKillDialog ? onClose} onBackButtonPress={() => onClose}> {$t('charging.enterStationId')} setInput(text)} />