Splash.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. import http_showcase from '../pages/services/showcase';
  7. export default class Splash extends BasePage {
  8. state = {
  9. exist: false,
  10. MainPageParams: '',
  11. boothContent: { uri: '' }
  12. };
  13. render() {
  14. return (
  15. <View style={{ flex: 1 }}>
  16. <StatusBar backgroundColor={'transparent'} translucent={true} />
  17. <Image source={this.state.boothContent} style={{ width: '100%', height: '100%' }} />
  18. </View>
  19. );
  20. }
  21. componentWillMount() {
  22. // global.storage.remove({ key: 'userInfo' });
  23. this.getUserInfo();
  24. }
  25. componentDidMount() {}
  26. async getUserInfo() {
  27. //判断是否有用户
  28. await global.storage
  29. .load({
  30. key: 'userInfo'
  31. })
  32. .then((result) => {
  33. var usermap = commonutil.jsonToMap(result);
  34. this.setState({
  35. exist: true,
  36. MainPageParams: usermap.get('ageGroup')
  37. });
  38. this.getShowCase();
  39. })
  40. .catch((err) => {
  41. console.log(err.message);
  42. this.getShowCase();
  43. this.setState({
  44. exist: false
  45. });
  46. switch (err.name) {
  47. case 'NotFoundError':
  48. break;
  49. case 'ExpiredError':
  50. // TODO
  51. // alert('ExpiredError');
  52. break;
  53. }
  54. });
  55. }
  56. getShowCase() {
  57. http_showcase.getSTARTING_UP_RECOMMEND().then((res) => {
  58. console.log('====================================');
  59. console.log('res', res.data[0].boothContent);
  60. console.log('====================================');
  61. this.setState({
  62. boothContent: { uri: res.data[0].boothContent }
  63. });
  64. SplashScreen.hide();
  65. this.Advertisement();
  66. });
  67. }
  68. //获取用户之后的操作,或者是别的操作。
  69. Advertisement() {
  70. //假装3秒广告
  71. setTimeout(() => {
  72. if (this.state.exist) {
  73. this.clearPageToNext('MainPage');
  74. } else {
  75. this.clearPageToNext('Login');
  76. }
  77. }, 5000);
  78. }
  79. }