login_head.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. Alert,
  7. Platform,
  8. TouchableOpacity,
  9. DeviceEventEmitter,
  10. } from 'react-native';
  11. import * as WeChat from 'react-native-wechat';
  12. import Login from './login';
  13. import public_css from '../../source/css/public_css';
  14. import {CheckPassword, CheckPhoneNumber} from '../../source/inspect/inspect';
  15. import {GetDataPost} from '../../data/encryption';
  16. import {StorageData} from '../../data/storage';
  17. import {ShowToast} from '../../components/rootToast/root_toast';
  18. export default class login_head extends Component {
  19. constructor(props) {
  20. super(props);
  21. this.props.navigation.dangerouslyGetParent().setOptions({
  22. tabBarVisible: false,
  23. });
  24. }
  25. render() {
  26. return (
  27. <View style={public_css.body}>
  28. <View style={{flex: 1}}>
  29. <View
  30. style={{
  31. justifyContent: 'center',
  32. alignItems: 'center',
  33. flexDirection: 'column',
  34. }}>
  35. <Image
  36. source={require('../../source/img/personal/headImg.png')}
  37. style={{
  38. width: 90,
  39. height: 90,
  40. margin: 30,
  41. borderRadius: 50,
  42. }}
  43. />
  44. <Login login_navigation={this.props.navigation} />
  45. </View>
  46. </View>
  47. {/*<View style={{alignItems: 'center', justifyContent: 'center', height: 50}}>*/}
  48. {/* <TouchableOpacity*/}
  49. {/* onPress={() => {*/}
  50. {/* this.loginWeChat();*/}
  51. {/* }}>*/}
  52. {/* <Image source={require('../../source/img/wechat.png')} />*/}
  53. {/* </TouchableOpacity>*/}
  54. {/*</View>*/}
  55. </View>
  56. );
  57. }
  58. componentDidMount(): void {
  59. WeChat.registerApp('wxc4f72f029a280bc4');
  60. }
  61. //微信授权登录
  62. loginWeChat = async () => {
  63. let scope = 'snsapi_userinfo';
  64. let state = 'wechat_sdk_demo';
  65. //判断微信是否安装
  66. let isInstalled = await WeChat.isWXAppInstalled();
  67. if (isInstalled) {
  68. WeChat.sendAuthRequest(scope, state)
  69. .then(response => {
  70. this.weChatSignIn(response.code);
  71. })
  72. .catch(error => {
  73. let errorCode = Number(error.code);
  74. Alert.alert('登录授权发生错误:', error.errStr, [{text: '确定'}]);
  75. });
  76. } else {
  77. Platform.OS == 'ios'
  78. ? Alert.alert('没有安装微信', '是否安装微信?', [
  79. {text: '取消'},
  80. {text: '确定', onPress: () => {}},
  81. ])
  82. : Alert.alert('没有安装微信', '请先安装微信客户端在进行登录', [
  83. {text: '确定'},
  84. ]);
  85. }
  86. };
  87. //微信免登
  88. weChatSignIn = async code => {
  89. const url = '/auth/wx/login';
  90. let token = null;
  91. let response = await GetDataPost(
  92. url,
  93. token,
  94. {
  95. code: code,
  96. reqChannel: 3,
  97. },
  98. false,
  99. 1,
  100. );
  101. if (response) {
  102. if (response.code == 0) {
  103. let authority = JSON.stringify(response.data.authorities);
  104. await StorageData(response);
  105. await this._initRealm();
  106. DeviceEventEmitter.emit('updateCurMon', null);
  107. this.props.login_navigation.goBack();
  108. this.props.login_navigation.navigate('home_navigation', {
  109. authority: authority,
  110. });
  111. } else {
  112. ShowToast(response.msg);
  113. this.setLoadingStatus(false);
  114. }
  115. } else {
  116. ShowToast(response.msg);
  117. this.setLoadingStatus(false);
  118. }
  119. };
  120. }