12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import React, {Component} from 'react';
- import {
- View,
- Image,
- Text,
- Alert,
- Platform,
- TouchableOpacity,
- } from 'react-native';
- import * as WeChat from 'react-native-wechat';
- import Login from './login';
- import public_css from '../../source/css/public_css';
- export default class login_head extends Component {
- constructor(props) {
- super(props);
- this.props.navigation.dangerouslyGetParent().setOptions({
- tabBarVisible: false,
- });
- }
- render() {
- return (
- <View style={public_css.body}>
- <View style={{flex: 1}}>
- <View
- style={{
- justifyContent: 'center',
- alignItems: 'center',
- flexDirection: 'column',
- }}>
- <Image
- source={require('../../source/img/personal/headImg.png')}
- style={{
- width: 90,
- height: 90,
- margin: 30,
- borderRadius: 50,
- }}
- />
- <Login login_navigation={this.props.navigation} />
- </View>
- </View>
- <View style={{height: 50, alignItems: 'center', justifyContent: 'center'}}>
- <TouchableOpacity
- onPress={() => {
- this.loginWeChat();
- }}>
- <Image source={require('../../source/img/wechat.png')} />
- </TouchableOpacity>
- </View>
- </View>
- );
- }
- componentDidMount(): void {
- WeChat.registerApp('wxc4f72f029a280bc4');
- }
- loginWeChat = () => {
- let scope = 'snsapi_userinfo';
- let state = 'wechat_sdk_demo';
- //判断微信是否安装
- WeChat.isWXAppInstalled().then((isInstalled) => {
- if (isInstalled) {
- //发送授权请求
- WeChat.sendAuthRequest(scope, state)
- .then((responseCode) => {
- //返回code码,通过code获取access_token
- console.log(responseCode);
- // this.getAccessToken(responseCode.code);
- })
- .catch((err) => {
- Alert.alert('登录授权发生错误:', err.message, [{text: '确定'}]);
- });
- } else {
- Platform.OS == 'ios'
- ? Alert.alert('没有安装微信', '是否安装微信?', [
- {text: '取消'},
- {text: '确定', onPress: () => {}},
- ])
- : Alert.alert('没有安装微信', '请先安装微信客户端在进行登录', [
- {text: '确定'},
- ]);
- }
- });
- };
- }
|