Browse Source

日常开发

林旭祥 3 days ago
parent
commit
4f4a71ec22
2 changed files with 10 additions and 10 deletions
  1. 1 1
      App.tsx
  2. 9 9
      src/pages/Login/index.tsx

+ 1 - 1
App.tsx

@@ -106,7 +106,7 @@ function TabNavigator() {
 function App(): React.JSX.Element {
   return (
     <NavigationContainer>
-      <Stack.Navigator initialRouteName="MainTabs">
+      <Stack.Navigator initialRouteName="Login">
         <Stack.Screen
           name="Login"
           component={LoginScreen}

+ 9 - 9
src/pages/Login/index.tsx

@@ -1,4 +1,4 @@
-import React, {useState} from 'react';
+import React, { useState } from 'react';
 import {
   View,
   Text,
@@ -14,7 +14,7 @@ import {
 } from 'react-native';
 import { useNavigation } from '@react-navigation/native';
 
-const LoginScreen = ({}) => {
+const LoginScreen = ({ }) => {
   const navigation = useNavigation();
   const [username, setUsername] = useState('manage1');
   const [password, setPassword] = useState('trops@2022');
@@ -23,7 +23,7 @@ const LoginScreen = ({}) => {
 
   const handleLogin = async () => {
     if (!username || !password) {
-      ToastAndroid.show('请输入用户名和密码',2000);
+      ToastAndroid.show('请输入用户名和密码', 2000);
       return;
     }
     setIsLoading(true);
@@ -32,17 +32,17 @@ const LoginScreen = ({}) => {
         username,
         password,
       };
-      global.$http.common.getLogin(params).then((res:any) => {
-        console.log("eeeeeee",res)
+      global.$http.common.getLogin(params).then((res: any) => {
+        console.log("eeeeeee", res)
         if (res.data.access_token) {
           // let token = "JWT " + res.data.access_token;
-          ToastAndroid.show('登录成功',2000);
-          navigation.navigate('Home'); // 登录成功后跳转到主页
+          ToastAndroid.show('登录成功', 2000);
+          navigation.navigate('MainTabs'); // 登录成功后跳转到主页
         }
       })
-    } catch (error:any) {
+    } catch (error: any) {
       console.log(error);
-      ToastAndroid.show(error.response?.data?.message || '网络请求失败',2000);
+      ToastAndroid.show(error.response?.data?.message || '网络请求失败', 2000);
     } finally {
       setIsLoading(false);
     }