/** * 首页抽屉菜单 * @邠心vbe on 2021/03/23 */ import React, { Component } from 'react'; import {View, Text, StyleSheet, Image, Pressable, BackHandler, Linking, Touchable} from 'react-native'; import { createDrawerNavigator, DrawerContentScrollView } from '@react-navigation/drawer'; import { Styles } from '../../components/Toolbar'; import app from '../../../app.json'; import Maps from './Home'; import { PageList } from '../Router'; import Dialog from '../../components/Dialog'; import { host, setAccessToken } from '../../api/http'; import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage'; import Button from '../../components/Button'; import { AutoLogin } from '../sign/Login'; import apiCharge from '../../api/apiCharge'; import { TouchableWithoutFeedback } from 'react-native-gesture-handler'; import { toTopupPage } from '../payment/PaymentConfig'; import utils from '../../utils/utils'; const Drawer = createDrawerNavigator(); const DEBUG = app.debug && !app.product; export default class Home extends Component { constructor(props) { super(props); this.state = { isLogin: false, userInfo: {}, } } componentDidMount() { AutoLogin(() => { this.setState({ userInfo: userInfo }); }); this.props.navigation.addListener('focus', () => { //console.log('drawer focus'); getUserInfo(info => { this.setState({ userInfo: info }); }, true); }); /*BackHandler.addEventListener('hardwareBackPress', (e) => { if (global.dialogId !== 0) { Dialog.dismissLoading(); return true; } return false; })*/ } componentDidUpdate() { const status = isLogin(); if (this.state.isLogin != status) { this.setState({ isLogin: status }, () => { getUserInfo(info => { this.setState({ userInfo: info }); if (info.firebaseToken) { let token = isIOS ? info.firebaseToken?.ios : info.firebaseToken?.android if (notifyToken.token) { utils.registerFirebaseToken(token ?? ""); } } }, true); }); } } async requestLogout() { const data = await getStorageJsonSync('loginData'); if (data && data.email) { delete data.password setStorageJson('loginData', data); setStorage('RegisterTokenDate', ""); } global.userInfo = {} this.setState({ isLogin: false, userInfo: {} }); setAccessToken(''); Dialog.dismissLoading(); } render () { return ( this.requestLogout()} /> } drawerType={ global.$width >= 768 ? 'back' : 'front' } drawerStyle={{ width: $vw(75) > 320 ? 320 : $vw(75), backgroundColor: colorLight }}> ); } }; const CustomerDrawerContent = (props) => { return ( ); } const DrawerContent = ({isLogin, userInfo, onLogout, navigation}) => { const getCharging = () => { Dialog.showProgressDialog(); apiCharge.getUserCharging().then(res => { Dialog.dismissLoading(); if (res.data.sitePk) { startPage(PageList.chargeDetailPage, {stationInfo: {id: res.data.sitePk}, action: 'view', from: PageList.home}); //startPage(PageList.chargeDetail, { stationInfo: {id: res.data.sitePk}, action: 'view'}); } else if (res.msg) { toastShort(res.msg); } else { toastShort($t("drawer.noChargingSession")); } }).catch((err) => { if (app.debug) console.log(err); Dialog.dismissLoading(); toastShort($t("drawer.noChargingSession")); }) } const logout = () => { Dialog.showDialog({ title: 'Sign out', message: 'Are you sure you want to sign out?', callback: btn => { if (btn == 'ok') { Dialog.showProgressDialog(); setTimeout(() => { onLogout(); }, 500); } } }) } return ( { (isLogin && userInfo.photoUrl) ? startPage(PageList.profile)}> : startPage(PageList.login)}> } startPage(isLogin ? PageList.profile : PageList.login)}> { isLogin ? userInfo.nickName ? userInfo.nickName : $t('drawer.logging') : $t('drawer.sign') } {/* isLogin ? : */} {/* */} { isLogin ? : {/* */} {$t('drawer.charging')} } {/* isLogin ? : {$t('drawer.wallet')} */} { isLogin && <> } {/*附加功能-开始*/} { (app.modules.notifications && isLogin) && } { (app.modules.bookmarks && isLogin) && } {/*附加功能-结束*/} { isLogin && } {/* */} {/* */} { DEBUG && <> {$t('drawer.debugOnly')} } {/* isLogin ? toTopupPage()}> {currency}{userInfo.credit} {/* { startPage(PageList.referral); }}> Refer your friends to get $5 credit! *} : s */} {app.displayName + ' ' + app.versionName} {/* isLogin &&