import { View, Text, FlatList, ScrollView, Image as NativeImage, } from "react-native"; import React, { useState, useEffect, useRef } from "react"; import { useTailwind } from "tailwind-rn"; import Toast from "react-native-toast-message"; import Empty from "../../../components/Empty"; import { ListItem, Icon, SearchBar } from "@rneui/themed"; import { Image } from "expo-image"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import baseRequest from "../../../utils/baseRequest"; import { generateSignature } from "../../../utils/crypto"; import formatTimestamp from "../../../utils/formatTimestamp"; export default function SpaceSearch({ navigation }) { const blurhash = "LcKUTa%gOYWBYRt6xuoJo~s8V@fk"; const tailwind = useTailwind(); const insets = useSafeAreaInsets(); const [data, setData] = useState([]); const [search, setSearch] = useState(""); const [isloading, setIsloading] = useState(false); const searchRef = useRef(null); const getData = async (searchValue) => { if (searchValue?.length != 6) { setIsloading(false); return; } if (/[^0-9]/.test(searchValue)) { setIsloading(false); Toast.show({ type: "error", text1: "请输入六位用户ID", topOffset: 60, }); return; } const apiUrl = process.env.EXPO_PUBLIC_API_URL; try { const base = await baseRequest(); const body = { member_user_id: Number(searchValue), ...base, }; console.log(body); const signature = await generateSignature(body); const _response = await fetch( `${apiUrl}/api/zone/search_zone_member?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body), } ); console.log("******", JSON.stringify(body)); const _data = await _response.json(); if (_data.ret === -1) { console.log("_data", _data); setIsloading(false); Toast.show({ type: "error", text1: _data.msg, topOffset: 60, }); return; } setData(_data.data.list); setIsloading(false); } catch (error) { console.error(error); } }; //进入页面默认focus useEffect(() => { searchRef.current.focus(); getData(); }, []); //搜索框文本变化时进行搜索 useEffect(() => { if (!search) { setData([]); return; } let ignore = false; getData(search); return () => { ignore = true; }; }, [search]); const updateSearch = (search) => { setSearch(search); if (!search) return; setIsloading(true); }; //单个成员组件 const RenderItem = ({ item }) => { return ( {item?.account?.name} {item?.is_ironfan == 1 && ( 铁粉 )} {item?.is_superfan == 1 && ( 超粉 )} {item?.account?.user_id} {formatTimestamp(item?.join_ct)} ); }; return ( navigation.goBack()} /> <>} searchIcon={() => <>} showLoading={isloading} onChangeText={updateSearch} value={search} /> {data?.map((item, index) => ( ))} {data.length === 0 && } ); }