Splash.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React, { PureComponent } from 'react';
  2. import { StyleSheet, Text, View, Image, TouchableOpacity, StatusBar, ToastAndroid, TextInput } from 'react-native';
  3. import BasePage from './BasePage';
  4. import SplashScreen from 'react-native-splash-screen';
  5. export default class Splash extends BasePage {
  6. state = {
  7. exist: false
  8. };
  9. render() {
  10. return (
  11. <View style={{ flex: 1 }}>
  12. <StatusBar backgroundColor={'transparent'} translucent={true} />
  13. </View>
  14. );
  15. }
  16. componentWillMount() {
  17. // global.storage.remove({ key: 'userInfo' });
  18. this.getUserInfo();
  19. }
  20. componentDidMount() {
  21. setTimeout(() => {
  22. SplashScreen.hide();
  23. if (this.state.exist) {
  24. this.clearPageToNext('MainPage');
  25. } else {
  26. this.clearPageToNext('Login');
  27. }
  28. }, 3000);
  29. }
  30. getUserInfo() {
  31. //判断是否有用户
  32. global.storage
  33. .load({
  34. key: 'userInfo'
  35. })
  36. .then((result) => {
  37. console.log('====================================');
  38. console.log(result);
  39. console.log('====================================');
  40. this.setState({
  41. exist: true
  42. });
  43. })
  44. .catch((err) => {
  45. console.log(err.message);
  46. switch (err.name) {
  47. case 'NotFoundError':
  48. // TODO;
  49. // alert('NotFoundError');
  50. this.setState({
  51. exist: false
  52. });
  53. break;
  54. case 'ExpiredError':
  55. // TODO
  56. // alert('ExpiredError');
  57. break;
  58. }
  59. });
  60. }
  61. }