Welcome.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React, {Component} from 'react'
  2. import {StyleSheet, View, Text, Image} from 'react-native'
  3. import SyncStorage from 'sync-storage';
  4. import {connect} from 'react-redux'
  5. import {NavigationActions, StackActions, ScreenUtil} from '../utils'
  6. import {ComponentsStyles} from '../components'
  7. @connect(auth => ({...auth}))
  8. class Welcome extends Component {
  9. constructor(props) {
  10. super(props);
  11. }
  12. componentDidMount() {
  13. const {navigation, dispatch} = this.props;
  14. SyncStorage.init().then((data) => {
  15. const credential = SyncStorage.get('credential');
  16. var resetAction;
  17. if (credential && credential.token) {
  18. // resetAction = NavigationActions.navigate({
  19. // routeName: "Main",
  20. // actions: [NavigationActions.navigate({routeName: 'HomePage'})],
  21. // })
  22. // resetAction = StackActions.reset({
  23. // index: 0,//默认打开actions中的第几个页面
  24. // actions: [//actions是页面集合
  25. // NavigationActions.navigate({routeName: 'Main'}),
  26. // ]
  27. // });
  28. dispatch({
  29. type: 'auth/tokenRefresh',
  30. payload: credential,
  31. callback: () => {
  32. resetAction = NavigationActions.navigate({
  33. routeName: "Main",
  34. actions: [NavigationActions.navigate({routeName: 'DesktopHome'})],
  35. })
  36. navigation.dispatch(resetAction);
  37. },
  38. unLogin: () => {
  39. resetAction = NavigationActions.navigate({
  40. routeName: "Login",
  41. actions: [NavigationActions.navigate({routeName: 'Login'})],
  42. })
  43. navigation.dispatch(resetAction);
  44. }
  45. })
  46. } else {
  47. // resetAction = NavigationActions.navigate({ routeName: 'Login' })
  48. // resetAction = NavigationActions.navigate({
  49. // routeName: "Login",
  50. // actions: [NavigationActions.navigate({routeName: 'Login'})],
  51. // })
  52. // resetAction = StackActions.reset({
  53. // index: 1,//默认打开actions中的第几个页面
  54. // actions: [//actions是页面集合
  55. // NavigationActions.navigate({routeName: 'Main'}),
  56. // NavigationActions.navigate({routeName: 'Login'}),
  57. // ]
  58. // });
  59. SyncStorage.remove('credential');
  60. resetAction = NavigationActions.navigate({
  61. routeName: "Login",
  62. actions: [NavigationActions.navigate({routeName: 'Login'})],
  63. })
  64. navigation.dispatch(resetAction);
  65. }
  66. })
  67. }
  68. componentWillUnmount() {
  69. this.timer && clearTimeout(this.timer);
  70. }
  71. render() {
  72. return (
  73. <View style={ComponentsStyles.container}>
  74. <View style={styles.up}>
  75. <Image source={require('../../assets/images/logo.png')} style={styles.logo}/>
  76. <Text style={styles.title}>电金睛</Text>
  77. </View>
  78. <View style={styles.down}>
  79. <Text style={styles.rights}>©2020 郑州燎原 All rights reserved.</Text>
  80. </View>
  81. </View>
  82. )
  83. }
  84. }
  85. const styles = StyleSheet.create({
  86. up: {
  87. flex: 4,
  88. paddingTop: ScreenUtil.scaleSize(80),
  89. textAlign: 'center',
  90. alignItems: 'center',
  91. },
  92. logo: {
  93. width: ScreenUtil.scaleSize(80),
  94. height: ScreenUtil.scaleSize(80),
  95. },
  96. title: {
  97. paddingTop: 20,
  98. fontSize: ScreenUtil.scaleSize(24),
  99. color: '#5394e4',
  100. textAlign: 'center',
  101. },
  102. down: {
  103. flex: 1,
  104. textAlign: 'center',
  105. justifyContent: 'flex-end'
  106. },
  107. rights: {
  108. height: 50,
  109. fontSize: ScreenUtil.scaleSize(12),
  110. color: '#aaaaaa',
  111. textAlign: 'center',
  112. }
  113. })
  114. export default Welcome