Welcome.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React, {Component} from 'react'
  2. import {StyleSheet, View, Text, Image, DeviceEventEmitter} from 'react-native'
  3. import SyncStorage from 'sync-storage';
  4. import {connect} from 'react-redux'
  5. import {NavigationActions, createAction, 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. let resetAction;
  17. if (credential && credential['token'] !== undefined) {
  18. dispatch({
  19. type: 'auth/authLogin',
  20. payload: credential,
  21. callback: () => {
  22. resetAction = NavigationActions.navigate({
  23. routeName: "Main",
  24. actions: [NavigationActions.navigate({routeName: 'SalesHome'})],
  25. })
  26. navigation.dispatch(resetAction);
  27. },
  28. unLogin: () => {
  29. resetAction = NavigationActions.navigate({
  30. routeName: "Login",
  31. actions: [NavigationActions.navigate({routeName: 'Login'})],
  32. })
  33. navigation.dispatch(resetAction);
  34. }
  35. })
  36. } else {
  37. resetAction = NavigationActions.navigate({
  38. routeName: "Login",
  39. actions: [NavigationActions.navigate({routeName: 'Login'})],
  40. })
  41. navigation.dispatch(resetAction);
  42. }
  43. // this.timer = setTimeout(
  44. // () => {
  45. // navigation.dispatch(resetAction);
  46. // },
  47. // 2000
  48. // );
  49. });
  50. }
  51. componentWillUnmount() {
  52. // this.timer && clearTimeout(this.timer);
  53. }
  54. render() {
  55. return (
  56. <View style={ComponentsStyles.container}>
  57. <View style={styles.up}>
  58. <Image source={require('../../assets/images/logo.png')} style={styles.logo}/>
  59. </View>
  60. <View style={styles.down}>
  61. <Text style={styles.rights}>©2021 装集客 All rights reserved.</Text>
  62. </View>
  63. </View>
  64. )
  65. }
  66. }
  67. const styles = StyleSheet.create({
  68. up: {
  69. flex: 4,
  70. paddingTop: ScreenUtil.scaleSize(80),
  71. textAlign: 'center',
  72. alignItems: 'center',
  73. },
  74. logo: {
  75. width: ScreenUtil.scaleSize(80),
  76. height: ScreenUtil.scaleSize(80),
  77. },
  78. title: {
  79. fontSize: ScreenUtil.scaleSize(24),
  80. color: '#03C762',
  81. textAlign: 'center',
  82. },
  83. down: {
  84. flex: 1,
  85. textAlign: 'center',
  86. justifyContent: 'flex-end'
  87. },
  88. rights: {
  89. height: 50,
  90. fontSize: ScreenUtil.scaleSize(12),
  91. color: '#aaaaaa',
  92. textAlign: 'center',
  93. }
  94. })
  95. export default Welcome