diff --git a/src/pages/my/my.module.scss b/src/pages/my/my.module.scss index d190f39..d4667f3 100644 --- a/src/pages/my/my.module.scss +++ b/src/pages/my/my.module.scss @@ -1,5 +1,7 @@ page { background: #F2F8F6 !important; + width:750rpx; + overflow: hidden; } .content { diff --git a/src/pages/preview/search/search/components/list.tsx b/src/pages/preview/search/search/components/list.tsx index 184097b..7082961 100644 --- a/src/pages/preview/search/search/components/list.tsx +++ b/src/pages/preview/search/search/components/list.tsx @@ -1,16 +1,17 @@ -import {FC, useCallback, useEffect, useRef, useState} from "react"; +import {FC, useCallback, useEffect, useState} from "react"; import {ScrollView, View} from "@tarojs/components"; import styles from './list.module.scss' import Taro from "@tarojs/taro"; import Empty from "@/components/empty/empty"; -import Spinner from "@/components/spinner"; import Img from "@/components/image/image"; import { SearchApi } from "@/api/search"; +import { AtLoadMore } from 'taro-ui' type Props = { name:string + clear:boolean } -const SearchList: FC<{name:string}> = ({name}:Props) => { +const SearchList: FC = ({name,clear}) => { const globalData = Taro.getApp().globalData const [page, setPage] = useState(1) const [brands, setBrands] = useState([]) @@ -18,8 +19,16 @@ const SearchList: FC<{name:string}> = ({name}:Props) => { const [text, setText] = useState('') const [loading, setLoading] = useState(true) + useEffect(()=>{ + if(!clear){ + setBrands([]) + setLoading(true) + } + },[clear]) useEffect(() => { - getData() + if(name){ + getData() + } }, [page,name]) const getData = useCallback(async () => { @@ -32,12 +41,17 @@ const SearchList: FC<{name:string}> = ({name}:Props) => { } else { setText('上拉加载更多~') } + setBrands([ + ...data.data + ]) + }else{ + setBrands([ + ...brands, + ...data.data + ]) } setTotal(data.total) - setBrands([ - ...brands, - ...data.data - ]) + } catch (e) { } setLoading(false) @@ -66,13 +80,12 @@ const SearchList: FC<{name:string}> = ({name}:Props) => { } function onScrollToLower(){ - useCallback(() => { if (brands?.length < total) { setPage(page + 1) + getData().then() } else { setText('没有更多了~') } - }, [total, brands]) } return ( @@ -80,12 +93,12 @@ const SearchList: FC<{name:string}> = ({name}:Props) => { className='scrollview' scrollY scrollWithAnimation - style={{height:`${globalData.windowHeight-60}px`}} + style={{height:`${globalData.windowHeight-60-30}px`,paddingBottom:`30px`}} onScrollToLower={onScrollToLower} > - + { loading && } { - brands.length ? + brands.length >= 1 && !loading && <> {brands.map((d) => jumpInfo(d.data.id,d.data.table)} className={styles.box} key={d.data.id}> @@ -95,9 +108,10 @@ const SearchList: FC<{name:string}> = ({name}:Props) => { ) } - {text} - : + {text} + } + { !loading && brands.length === 0 && } ) } diff --git a/src/pages/preview/search/search/index.tsx b/src/pages/preview/search/search/index.tsx index 75f21da..81379a7 100644 --- a/src/pages/preview/search/search/index.tsx +++ b/src/pages/preview/search/search/index.tsx @@ -1,5 +1,5 @@ import {Input, View, Text, PageContainer} from "@tarojs/components"; -import {FC, useState} from "react"; +import {FC, useEffect, useState} from "react"; import { AtIcon } from 'taro-ui' import styles from './index.module.scss' import Taro from "@tarojs/taro"; @@ -20,6 +20,10 @@ const Search:FC = () => { getRecentSearch() }) + useEffect(()=>{ + getRecentSearch() + },[!show]) + function inpFn(e){ setValue(e.detail.value) } @@ -55,7 +59,10 @@ const Search:FC = () => { - + { show ? + {value}: + + } { @@ -98,7 +105,7 @@ const Search:FC = () => { } { setShow(false)}} show={show} round={true} overlay={true} overlayStyle={'background:rgba(0,0,0,0)'} > - +