| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- import { StackScreenProps } from '@react-navigation/stack';
- import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
- import * as React from 'react';
- import { Div, Button, Image, Text, Avatar, Input } from 'react-native-magnus';
- import { ScrollView } from 'react-native-gesture-handler';
- import { TextInputMask } from 'react-native-masked-text';
- import { useMount } from 'ahooks';
- import { useNavigation } from '@react-navigation/native';
- import { useTranslation } from 'react-i18next';
- import useModel from 'flooks';
- import { MainStackParamList, LoginTabParamList } from '../types';
- import Navigation from '../navigation';
- import Login from './model';
- import SmsInput from '../components/SmsInput';
- const LoginTab = createMaterialTopTabNavigator<LoginTabParamList>();
- export default function LoginScreen({
- navigation,
- }: StackScreenProps<MainStackParamList, 'Login'>) {
- const { t } = useTranslation();
- return (
- <Div flex={1} bg="yellow200">
- <ScrollView
- contentContainerStyle={{
- flexGrow: 1,
- backgroundColor: '#FFF2C7',
- justifyContent: 'center',
- }}
- keyboardDismissMode="on-drag"
- >
- <Div bg="white" mx={13} px={10} py={20} rounded="xs">
- <Image
- source={require('../assets/images/loginImg2.png')}
- alignSelf="center"
- w={217}
- h={100}
- />
- <Image
- source={require('../assets/images/loginImg.png')}
- w={275}
- h={60}
- position="absolute"
- top={-59}
- left="50%"
- ml={-137}
- zIndex={2}
- />
- <Div bg="white">
- <LoginTab.Navigator
- initialRouteName="Psd"
- tabBarOptions={{
- inactiveTintColor: '#000',
- activeTintColor: '#FFC21C',
- indicatorStyle: { height: 0 },
- labelStyle: { fontSize: 13 },
- }}
- >
- <LoginTab.Screen
- name="Psd"
- component={LoginByPsd}
- options={{
- title: t('mi-ma-deng-lu'),
- backgroundColor: '#fff',
- }}
- />
- <LoginTab.Screen
- name="Code"
- component={LoginByCode}
- options={{
- title: t('yan-zheng-ma-deng-lu'),
- }}
- />
- </LoginTab.Navigator>
- </Div>
- </Div>
- </ScrollView>
- </Div>
- );
- }
- function LoginByPsd() {
- const { t } = useTranslation();
- const [phone, setphone] = React.useState<string>('');
- const [password, setpassword] = React.useState<string>('');
- const navigation = useNavigation();
- const loginModel = useModel(Login, []);
- return (
- <Div bg="white" h="100%">
- <Div row alignItems="center" py={10}>
- <Text w={96} textAlign="right">
- {t('shou-ji-hao')}:
- </Text>
- <Div
- flex={1}
- bg="gray100"
- rounded="sm"
- px={15}
- ml={5}
- h={30}
- alignItems="stretch"
- >
- <TextInputMask
- type={'custom'}
- value={phone}
- keyboardType="numeric"
- options={{
- mask: '999 9999 9999',
- }}
- onChangeText={(text) => {
- console.log(text);
- setphone(text);
- }}
- style={{ flex: 1, fontSize: 14 }}
- placeholderTextColor="#a6a6a6"
- placeholder={t('shu-ru-shou-ji-hao')}
- />
- {__DEV__ && (
- <Input
- onChangeText={(text) => {
- console.log(text);
- setphone(text);
- }}
- />
- )}
- </Div>
- </Div>
- <Div row alignItems="center" py={10}>
- <Text w={96} textAlign="right">
- {t('mi-ma')}:
- </Text>
- <Input
- flex={1}
- bg="gray100"
- rounded="sm"
- px={15}
- ml={5}
- h={30}
- type={'custom'}
- value={password}
- borderWidth={0}
- fontSize="md"
- opacity={1}
- loaderColor="gray400"
- color="gray900"
- secureTextEntry
- onChangeText={(text) => {
- console.log(text);
- setpassword(text);
- }}
- style={{ flex: 1 }}
- placeholder={t('shu-ru-mi-ma')}
- />
- </Div>
- <Div row justifyContent="space-between" pl={90}>
- <Button
- color="gray400"
- fontSize="sm"
- bg="white"
- onPress={() => navigation.navigate('ForgetPsd')}
- >
- {t('wang-ji-mi-ma')}
- </Button>
- <Button
- color="gray400"
- fontSize="sm"
- bg="white"
- onPress={() => navigation.navigate('Register')}
- >
- {t('qi-shou-zhu-ce')}
- </Button>
- </Div>
- <Button
- block
- bg="yellow500"
- w={112}
- fontSize="sm"
- ml={96}
- mt={10}
- disabled={!phone || !password}
- onPress={() => {
- loginModel.loginByPsd(phone, password);
- }}
- >
- {t('deng-lu')}
- </Button>
- </Div>
- );
- }
- function LoginByCode() {
- const { t } = useTranslation();
- const [phone, setphone] = React.useState<string>('');
- const [code, setCode] = React.useState<string>('');
- const loginModel = useModel(Login, []);
- const navigation = useNavigation();
- return (
- <Div bg="white" h="100%">
- <Div row alignItems="center" py={10}>
- <Text w={96} textAlign="right">
- {t('shou-ji-hao')}:
- </Text>
- <Div
- flex={1}
- bg="gray100"
- rounded="sm"
- px={15}
- ml={5}
- h={30}
- alignItems="stretch"
- >
- <TextInputMask
- type={'custom'}
- value={phone}
- keyboardType="numeric"
- options={{
- mask: '999 9999 9999',
- }}
- onChangeText={(text) => {
- console.log(text);
- setphone(text);
- }}
- placeholderTextColor="#a6a6a6"
- style={{ flex: 1, fontSize: 14 }}
- placeholder={t('shu-ru-shou-ji-hao')}
- />
- {__DEV__ && (
- <Input
- onChangeText={(text) => {
- console.log(text);
- setphone(text);
- }}
- />
- )}
- </Div>
- </Div>
- <SmsInput phone={phone} onCodeChange={setCode} type="login" />
- <Div row justifyContent="space-between" pl={90}>
- {/* <Button
- color="gray400"
- fontSize="sm"
- bg="white"
- onPress={() => navigation.navigate('ForgetPsd')}
- >
- {t('wang-ji-mi-ma')}
- </Button> */}
- <Button
- color="gray400"
- fontSize="sm"
- bg="white"
- onPress={() => navigation.navigate('Register')}
- >
- {t('qi-shou-zhu-ce')}
- </Button>
- </Div>
- <Button
- onPress={() => loginModel.loginByCode(phone, code)}
- block
- bg="yellow500"
- w={112}
- fontSize="sm"
- ml={96}
- mt={10}
- >
- {t('deng-lu')}
- </Button>
- </Div>
- );
- }
|