Splash.js 2.1 KB

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