/** * 首页抽屉菜单 * @邠心vbe on 2021/03/23 */ import React, { Component } from 'react'; import {View, Text, StyleSheet, Image, Pressable, BackHandler, Linking} 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, RegisterToken } from '../sign/Login'; import apiCharge from '../../api/apiCharge'; const Drawer = createDrawerNavigator(); const drawerBackgroundColor = '#FFFCF8'; 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 }); RegisterToken(); }, 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: drawerBackgroundColor }}> ); } }; 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.chargeDetail, { stationInfo: {id: res.data.sitePk}, action: 'view'}); } else if (res.msg) { toastShort(res.msg); } else { toastShort('No charging session found'); } }).catch(err => { Dialog.dismissLoading(); toastShort('No charging session found'); }) } 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.nickName ? userInfo.nickName : 'Logging...' } : } { isLogin ? : } { isLogin ? : Charging } { isLogin ? : Transactions } { DEBUG && <> } { isLogin ? { startPage(PageList.topup); }}> {currency}{userInfo.credit} { startPage(PageList.referral); }}> Refer your friends to get $5 credit! : } {app.displayName + ' ' + app.versionName} { isLogin &&