Splash.js 1.4 KB

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