App.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, { Component } from 'react';
  9. import { AsyncStorage } from 'react-native';
  10. import { createStackNavigator, createAppContainer } from 'react-navigation';
  11. import Storage from 'react-native-storage';
  12. import MainActivity from './pages/MainActivity';
  13. import SchoolAge from './pages/SchoolAge';
  14. import MainPage from './pages/components/MainPage';
  15. import SchedulePage from './pages/components/SchedulePage';
  16. import PersonalInfo from './pages/PersonalInfo';
  17. import CourseDetails from './pages/CourseDetails';
  18. import userCenter from './pages/userCenter';
  19. import Order from './pages/buy/order';
  20. import Ticket from './pages/buy/ticket';
  21. import Buy from './pages/buy/buy';
  22. import Login from './pages/Login';
  23. import SearchResult from './pages/searchResult';
  24. import PhoneBind from './pages/PhoneBind';
  25. import Splash from './pages/Splash';
  26. import './pages/components/RootView';
  27. import commonutil from './pages/utils/commonutil';
  28. const RootNavigator = createStackNavigator(
  29. {
  30. MainActivity: { screen: MainActivity },
  31. SchoolAge: { screen: SchoolAge },
  32. MainPage: { screen: MainPage },
  33. SchedulePage: { screen: SchedulePage },
  34. PersonalInfo: { screen: PersonalInfo },
  35. userCenter: { screen: userCenter },
  36. CourseDetails: { screen: CourseDetails },
  37. Order: { screen: Order },
  38. Ticket: { screen: Ticket },
  39. Login: { screen: Login },
  40. Buy: { screen: Buy },
  41. SearchResult: { screen: SearchResult },
  42. PhoneBind: { screen: PhoneBind },
  43. Splash: { screen: Splash }
  44. },
  45. {
  46. initialRouteName: 'Splash',
  47. headerMode: 'null'
  48. }
  49. );
  50. const App = createAppContainer(RootNavigator);
  51. export default App;
  52. let storage = new Storage({
  53. size: 1000,
  54. storageBackend: AsyncStorage,
  55. defaultExpires: null,
  56. enableCache: true
  57. });
  58. global.storage = storage;
  59. getUserInfo().then((result) => {
  60. if (result == null) {
  61. global.userInfo = null;
  62. return true;
  63. }
  64. var json = JSON.parse(result);
  65. global.userInfo = {
  66. avatar: json.avatar,
  67. ageGroup: json.ageGroup,
  68. birthday: json.birthday,
  69. channel: json.channel,
  70. city: json.city,
  71. country: json.country,
  72. eid: json.eid,
  73. gmtCreated: json.gmtCreated,
  74. gmtModified: json.gmtModified,
  75. mobile: json.mobile,
  76. nickName: json.nickName,
  77. province: json.province,
  78. school: json.school,
  79. sex: json.sex,
  80. status: json.status,
  81. uid: json.uid,
  82. isVisitor: json.isVisitor
  83. };
  84. });
  85. async function getUserInfo() {
  86. let info = await global.storage
  87. .load({
  88. key: 'userInfo'
  89. })
  90. .then((result) => {
  91. return result;
  92. })
  93. .catch((err) => {
  94. console.log('ERROR' + err.message);
  95. return null;
  96. });
  97. return info;
  98. }