login_head.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. Image,
  5. Text,
  6. Alert,
  7. Platform,
  8. TouchableOpacity,
  9. } from 'react-native';
  10. import * as WeChat from 'react-native-wechat';
  11. import Login from './login';
  12. import public_css from '../../source/css/public_css';
  13. export default class login_head extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.props.navigation.dangerouslyGetParent().setOptions({
  17. tabBarVisible: false,
  18. });
  19. }
  20. render() {
  21. return (
  22. <View style={public_css.body}>
  23. <View style={{flex: 1}}>
  24. <View
  25. style={{
  26. justifyContent: 'center',
  27. alignItems: 'center',
  28. flexDirection: 'column',
  29. }}>
  30. <Image
  31. source={require('../../source/img/personal/headImg.png')}
  32. style={{
  33. width: 90,
  34. height: 90,
  35. margin: 30,
  36. borderRadius: 50,
  37. }}
  38. />
  39. <Login login_navigation={this.props.navigation} />
  40. </View>
  41. </View>
  42. <View style={{height: 50, alignItems: 'center', justifyContent: 'center'}}>
  43. <TouchableOpacity
  44. onPress={() => {
  45. this.loginWeChat();
  46. }}>
  47. <Image source={require('../../source/img/wechat.png')} />
  48. </TouchableOpacity>
  49. </View>
  50. </View>
  51. );
  52. }
  53. componentDidMount(): void {
  54. WeChat.registerApp('wxc4f72f029a280bc4');
  55. }
  56. loginWeChat = () => {
  57. let scope = 'snsapi_userinfo';
  58. let state = 'wechat_sdk_demo';
  59. //判断微信是否安装
  60. WeChat.isWXAppInstalled().then((isInstalled) => {
  61. if (isInstalled) {
  62. //发送授权请求
  63. WeChat.sendAuthRequest(scope, state)
  64. .then((responseCode) => {
  65. //返回code码,通过code获取access_token
  66. console.log(responseCode);
  67. // this.getAccessToken(responseCode.code);
  68. })
  69. .catch((err) => {
  70. Alert.alert('登录授权发生错误:', err.message, [{text: '确定'}]);
  71. });
  72. } else {
  73. Platform.OS == 'ios'
  74. ? Alert.alert('没有安装微信', '是否安装微信?', [
  75. {text: '取消'},
  76. {text: '确定', onPress: () => {}},
  77. ])
  78. : Alert.alert('没有安装微信', '请先安装微信客户端在进行登录', [
  79. {text: '确定'},
  80. ]);
  81. }
  82. });
  83. };
  84. }