diff --git a/app.json b/app.json index c1c5566eb42e95b99a7ef47f05184e97ed832cd4..7b6108e6c9970d6fc1cec7ebcee973c38a3ba666 100644 --- a/app.json +++ b/app.json @@ -7,7 +7,7 @@ "icon": "./assets/images/icon.png", "scheme": "myapp", "userInterfaceStyle": "automatic", - "newArchEnabled": true, + "newArchEnabled": false, "ios": { "supportsTablet": true }, @@ -36,6 +36,9 @@ ], "experiments": { "typedRoutes": true + }, + "updates":{ + "enabled":false } } } diff --git a/app/(tabs)/Find.tsx b/app/(tabs)/Find.tsx index ba6b53ab491af734544a5ec418953c13f56bce9e..91fb332cb128f29f4ae741ed97d40fcb00f342b3 100644 --- a/app/(tabs)/Find.tsx +++ b/app/(tabs)/Find.tsx @@ -1,9 +1,7 @@ +import React, { useEffect, useState } from 'react' import { StyleSheet, Text, View } from "react-native"; -import React from "react"; import Crad from "../lllpLogin/components/Card"; -// import axios from "axios"; import axiosApi from "../Api/axios"; -import { useEffect, useState } from "react"; export default function Find() { const [data, setData] = useState([]); diff --git a/app/(tabs)/User.tsx b/app/(tabs)/User.tsx index 6318b465555b6291464c2057ceb613dd202f92d1..c4eed7a6ff05719c7aa3933ff3721be57790bb5d 100644 --- a/app/(tabs)/User.tsx +++ b/app/(tabs)/User.tsx @@ -2,7 +2,9 @@ import { useNavigation } from '@react-navigation/native' import { Link, router, Redirect } from 'expo-router' import { StyleSheet, Alert, Text, View, Button, Image, ScrollView, Switch, TouchableOpacity } from 'react-native' import React, { useState } from 'react' - +import axiosApi from '../zhcFile/axiosApi/axiosApi' +import { login } from '../zhcFile/services/hotTrack.d' +import AsyncStorage from '@react-native-async-storage/async-storage'; export default function User() { const navigation = useNavigation() @@ -41,10 +43,38 @@ export default function User() { } ] ) + } - - + //模拟登录 + const Login = async () => { + const res: any = await login({ users: 'admin', password: '123456' }) + if (res.data.code === 200) { + console.log(res.data.user) + // 登录成功,保存用户信息 + // router.push('/MyViews/MyPage'); + // rn保存信息持久化 + storeData('user', res.data.user) + } + } + //模拟登录 + const Login1 = async () => { + const res: any = await login({ users: 'xiaoliu', password: '111111' }) + if (res.data.code === 200) { + console.log(res.data.user) + // 登录成功,保存用户信息 + // router.push('/MyViews/MyPage'); + // rn保存信息持久化 + storeData('user', res.data.user) + } } + const storeData = async (key: string, value: any) => { + try { + await AsyncStorage.setItem(key, JSON.stringify(value)); + } catch (error) { + console.error('Failed to save data', error); + } + }; + return ( @@ -80,7 +110,7 @@ export default function User() { 我的下载 > - + @@ -161,6 +191,22 @@ export default function User() { }} > + + + + + + diff --git a/app/zhcFile/chat.tsx b/app/zhcFile/chat.tsx index 373c51941e7cded8fe704efaccfe7c2c6af182a2..ad8668cfa0aabbcbe7d7d8c706aa7a9ec91db593 100644 --- a/app/zhcFile/chat.tsx +++ b/app/zhcFile/chat.tsx @@ -1,17 +1,48 @@ import { StyleSheet, Text, View } from 'react-native' -import React from 'react' +import React, { useEffect, useState } from 'react' import Socket from './components/Socket' import { useSearchParams } from 'expo-router/build/hooks' +import AsyncStorage from '@react-native-async-storage/async-storage'; + const chat = () => { const [_id, mingname] = useSearchParams() - console.log(mingname[1]) + console.log(mingname[1], _id[1]) + + interface User1 { + users: string, + names: string, + password: string, + phone: string, + focusOn: Array, + } + const [userOne, setUserOne] = useState() + useEffect(() => { + getUser() + }, []) + const getUser = async () => { + getData('user') + } + const getData = async (key: string) => { + try { + const value: any = await AsyncStorage.getItem(key); + if (value !== null) { + setUserOne(JSON.parse(value)) + console.log(value?.names) + } else { + console.log('No data found for the key') + } + return value ? JSON.parse(value) : null; + } catch (error) { + console.error('Failed to fetch data', error); + } + }; return ( - + ) } diff --git a/app/zhcFile/components/Socket.tsx b/app/zhcFile/components/Socket.tsx index b8c3187eec14eaef6cff6a0dd969526fb109de7f..577d5f1a98ac68f6b94597ce6e896750568c547a 100644 --- a/app/zhcFile/components/Socket.tsx +++ b/app/zhcFile/components/Socket.tsx @@ -4,77 +4,108 @@ import { } from 'react-native' import React, { useEffect, useState } from 'react' import { io } from 'socket.io-client' +import AsyncStorage from '@react-native-async-storage/async-storage'; +import { getChatList } from '../services/hotTrack.d'; const Socket = (props: any) => { + interface Message { username: string, message: string, } const [messageList, setMessageList] = useState([]) const [value, setValue] = useState('') - + interface User1 { + users: string, + names: string, + password: string, + phone: string, + focusOn: Array, + } + const [userOne, setUserOne] = useState() const socket = io('http://192.168.75.194:3001'); useEffect(() => { - socket.on('message', (message: string, username: string) => { - let newMessage = { - username: username, - message: message, - }; - console.log(newMessage, 111111111111111111) - setMessageList([...messageList, newMessage]) + getUser() + socket.on('message', msg => { + setMessageList([...messageList, msg]) }) }, []) + useEffect(() => { + getList() + }, [value]) + const getList = async () => { + const res: any = await getChatList() + setUserOne(res.data.data) + console.log(res.data.data, 1) + } + + const getUser = async () => { + getData('user') + } + const getData = async (key: string) => { + try { + const value: any = await AsyncStorage.getItem(key); + if (value !== null) { + setUserOne(JSON.parse(value)) + console.log(value?.names) + } else { + console.log('No data found for the key') + } + console.log(userOne?.names, 2) + return value ? JSON.parse(value) : null; + } catch (error) { + console.error('Failed to fetch data', error); + } + }; const send = () => { let newMessage = { username: props.username, message: value, + // 对方的_id + _id: props._id, }; - socket.emit('message', value, props.username) - // setMessageList([...messageList, newMessage]) + socket.emit('message', newMessage) setValue('') } return ( - - - { - props.username === "小米" ? ( - - + { + props.username === userOne?.names ? ( + + - - {item.username} - {item.message} - + }} + style={{ width: 40, height: 40, borderRadius: 20, marginRight: 10 }} /> + + {item.username} + {item.message} - )} - /> : ( - - + )} + /> : ( + + - - {item.username} - {item.message} - + }} + style={{ width: 40, height: 40, borderRadius: 20, marginRight: 10 }} /> + + {item.username} + {item.message} - )} - /> - } - - - + + )} + /> + } + { pathname: '/zhcFile/chat', params: { _id: _id[1], - mingname: `${itemOne.mingname}(${itemOne.job})` + mingname: `${itemOne.mingname}` } }) } @@ -92,8 +92,8 @@ const doctorDetails = () => { }}> + gotoChat1() + }}> diff --git a/app/zhcFile/services/hotTrack.d.tsx b/app/zhcFile/services/hotTrack.d.tsx index 9d8b1443c038016fb25579bf90b933385049b01f..cfa76dd060b7c128b8fd26e6e0756bce55a43955 100644 --- a/app/zhcFile/services/hotTrack.d.tsx +++ b/app/zhcFile/services/hotTrack.d.tsx @@ -22,4 +22,15 @@ export const getItem = (data: { _id: any }) => axiosApi({ method: 'POST', url: 'zhc/getItem', data +}) + +export const login=(data:{users: any,password:any})=> axiosApi({ + method: 'POST', + url: 'zhc/login', + data +}) + +export const getChatList = () => axiosApi({ + method: 'GET', + url: 'zhc/chatList', }) \ No newline at end of file