123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- import React, {Component} from 'react';
- import {
- View,
- Image,
- Text,
- Alert,
- Platform,
- TouchableOpacity,
- DeviceEventEmitter,
- } from 'react-native';
- import * as WeChat from 'react-native-wechat';
- import Login from './login';
- import public_css from '../../source/css/public_css';
- import {CheckPassword, CheckPhoneNumber} from '../../source/inspect/inspect';
- import {GetDataPost} from '../../data/encryption';
- import {StorageData} from '../../data/storage';
- import {ShowToast} from '../../components/rootToast/root_toast';
- 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={{alignItems: 'center', justifyContent: 'center', height: 50}}>*/}
- {/* <TouchableOpacity*/}
- {/* onPress={() => {*/}
- {/* this.loginWeChat();*/}
- {/* }}>*/}
- {/* <Image source={require('../../source/img/wechat.png')} />*/}
- {/* </TouchableOpacity>*/}
- {/*</View>*/}
- </View>
- );
- }
- componentDidMount(): void {
- WeChat.registerApp('wxc4f72f029a280bc4');
- }
- //微信授权登录
- loginWeChat = async () => {
- let scope = 'snsapi_userinfo';
- let state = 'wechat_sdk_demo';
- //判断微信是否安装
- let isInstalled = await WeChat.isWXAppInstalled();
- if (isInstalled) {
- WeChat.sendAuthRequest(scope, state)
- .then(response => {
- this.weChatSignIn(response.code);
- })
- .catch(error => {
- let errorCode = Number(error.code);
- Alert.alert('登录授权发生错误:', error.errStr, [{text: '确定'}]);
- });
- } else {
- Platform.OS == 'ios'
- ? Alert.alert('没有安装微信', '是否安装微信?', [
- {text: '取消'},
- {text: '确定', onPress: () => {}},
- ])
- : Alert.alert('没有安装微信', '请先安装微信客户端在进行登录', [
- {text: '确定'},
- ]);
- }
- };
- //微信免登
- weChatSignIn = async code => {
- const url = '/auth/wx/login';
- let token = null;
- let response = await GetDataPost(
- url,
- token,
- {
- code: code,
- reqChannel: 3,
- },
- false,
- 1,
- );
- if (response) {
- if (response.code == 0) {
- let authority = JSON.stringify(response.data.authorities);
- await StorageData(response);
- await this._initRealm();
- DeviceEventEmitter.emit('updateCurMon', null);
- this.props.login_navigation.goBack();
- this.props.login_navigation.navigate('home_navigation', {
- authority: authority,
- });
- } else {
- ShowToast(response.msg);
- this.setLoadingStatus(false);
- }
- } else {
- ShowToast(response.msg);
- this.setLoadingStatus(false);
- }
- };
- }
|