Splash.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 style={{ flex: 1 }} />
  16. <View style={{ flex: 5 }}>
  17. <Text style={{ fontSize: 30 }}>模拟活动广告。。。。</Text>
  18. </View>
  19. </View>
  20. );
  21. }
  22. componentWillMount() {
  23. // global.storage.remove({ key: 'userInfo' });
  24. this.getUserInfo();
  25. }
  26. componentDidMount() {}
  27. async getUserInfo() {
  28. //判断是否有用户
  29. await global.storage
  30. .load({
  31. key: 'userInfo'
  32. })
  33. .then((result) => {
  34. SplashScreen.hide();
  35. var usermap = commonutil.jsonToMap(result);
  36. this.setState({
  37. exist: true,
  38. MainPageParams: usermap.get('ageGroup')
  39. });
  40. this.Advertisement();
  41. })
  42. .catch((err) => {
  43. console.log(err.message);
  44. switch (err.name) {
  45. case 'NotFoundError':
  46. // TODO;
  47. // alert('NotFoundError');
  48. this.setState({
  49. exist: false
  50. });
  51. break;
  52. case 'ExpiredError':
  53. // TODO
  54. // alert('ExpiredError');
  55. break;
  56. }
  57. });
  58. }
  59. //获取用户之后的操作,或者是别的操作。
  60. Advertisement() {
  61. //假装3秒广告
  62. setTimeout(() => {
  63. if (this.state.exist) {
  64. this.clearPageToNext('MainPage');
  65. } else {
  66. this.clearPageToNext('Login');
  67. }
  68. }, 3000);
  69. }
  70. }