/**
* 首页抽屉菜单
* @邠心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 &&
);
}
const styles = StyleSheet.create({
drawerTop: {
top: 0,
left: 0,
right: 0,
height: statusHeight,
position: 'absolute',
fontSize: 10,
backgroundColor: drawerBackgroundColor
},
drawerView: {
paddingTop: 16,
minHeight: $vhs(100)
},
guessView: {
padding: 16
},
loginView: {
padding: 16
},
nickname: {
color: '#333',
fontSize:21,
fontWeight: 'bold',
paddingTop: 8,
paddingBottom: 16
},
itemButton: {
borderRadius: 0,
backgroundColor: drawerBackgroundColor
},
itemView: {
flex: 1,
height: 56,
paddingLeft: 16,
marginBottom: 6,
alignItems: 'center',
flexDirection: 'row'
},
disableItem: {
height: 56,
paddingLeft: 16,
marginBottom: 6,
alignItems: 'center',
flexDirection: 'row'
},
icon: {
width: 26,
height: 26,
marginRight: 16
},
icon2: {
width: 24,
height: 24,
marginLeft: 1,
marginRight: 17
},
label: {
color: '#333',
fontSize: 16.5
},
disable: {
color: '#999',
fontSize: 18
},
divided: {
height: 1,
marginTop: 24,
marginLeft: 16,
backgroundColor: colorAccent
},
walletView: {
paddingTop: 16,
paddingLeft: 48,
paddingRight: 48
},
balanceView: {
marginTop: 16,
borderRadius: 8,
...$padding(13, 22),
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'center',
backgroundColor: 'rgba(255, 204, 44, 0.6)'
},
balanceText: {
color: '#333',
fontSize: 22,
fontWeight: 'bold'
},
referText: {
flex: 1,
color: '#333',
fontSize: 13
},
bottomView: {
flex: 1,
paddingTop: 48,
paddingBottom: 8,
alignItems: 'center',
justifyContent: 'flex-end'
},
logoutView: {
backgroundColor: colorAccent
}
});