搜索页面样式调整

v2
一杯沧海 1 year ago
parent 806614f5d6
commit eea8f99fe7
  1. 2
      src/pages/my/my.module.scss
  2. 44
      src/pages/preview/search/search/components/list.tsx
  3. 13
      src/pages/preview/search/search/index.tsx

@ -1,5 +1,7 @@
page { page {
background: #F2F8F6 !important; background: #F2F8F6 !important;
width:750rpx;
overflow: hidden;
} }
.content { .content {

@ -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 {ScrollView, View} from "@tarojs/components";
import styles from './list.module.scss' import styles from './list.module.scss'
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import Empty from "@/components/empty/empty"; import Empty from "@/components/empty/empty";
import Spinner from "@/components/spinner";
import Img from "@/components/image/image"; import Img from "@/components/image/image";
import { SearchApi } from "@/api/search"; import { SearchApi } from "@/api/search";
import { AtLoadMore } from 'taro-ui'
type Props = { type Props = {
name:string name:string
clear:boolean
} }
const SearchList: FC<{name:string}> = ({name}:Props) => { const SearchList: FC<Props> = ({name,clear}) => {
const globalData = Taro.getApp().globalData const globalData = Taro.getApp().globalData
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const [brands, setBrands] = useState<any[]>([]) const [brands, setBrands] = useState<any[]>([])
@ -18,8 +19,16 @@ const SearchList: FC<{name:string}> = ({name}:Props) => {
const [text, setText] = useState('') const [text, setText] = useState('')
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
useEffect(()=>{
if(!clear){
setBrands([])
setLoading(true)
}
},[clear])
useEffect(() => { useEffect(() => {
getData() if(name){
getData()
}
}, [page,name]) }, [page,name])
const getData = useCallback(async () => { const getData = useCallback(async () => {
@ -32,12 +41,17 @@ const SearchList: FC<{name:string}> = ({name}:Props) => {
} else { } else {
setText('上拉加载更多~') setText('上拉加载更多~')
} }
setBrands([
...data.data
])
}else{
setBrands([
...brands,
...data.data
])
} }
setTotal(data.total) setTotal(data.total)
setBrands([
...brands,
...data.data
])
} catch (e) { } catch (e) {
} }
setLoading(false) setLoading(false)
@ -66,13 +80,12 @@ const SearchList: FC<{name:string}> = ({name}:Props) => {
} }
function onScrollToLower(){ function onScrollToLower(){
useCallback(() => {
if (brands?.length < total) { if (brands?.length < total) {
setPage(page + 1) setPage(page + 1)
getData().then()
} else { } else {
setText('没有更多了~') setText('没有更多了~')
} }
}, [total, brands])
} }
return ( return (
@ -80,12 +93,12 @@ const SearchList: FC<{name:string}> = ({name}:Props) => {
className='scrollview' className='scrollview'
scrollY scrollY
scrollWithAnimation scrollWithAnimation
style={{height:`${globalData.windowHeight-60}px`}} style={{height:`${globalData.windowHeight-60-30}px`,paddingBottom:`30px`}}
onScrollToLower={onScrollToLower} onScrollToLower={onScrollToLower}
> >
<Spinner enable={loading} overlay/> { loading && <AtLoadMore status={'loading'}/>}
{ {
brands.length ? brands.length >= 1 && !loading &&
<> <>
{brands.map((d) => <View onClick={() => jumpInfo(d.data.id,d.data.table)} className={styles.box} key={d.data.id}> {brands.map((d) => <View onClick={() => jumpInfo(d.data.id,d.data.table)} className={styles.box} key={d.data.id}>
<Img width={128} height={128} src={d.data['@data'].logo} mode='aspectFill' className={styles.image}/> <Img width={128} height={128} src={d.data['@data'].logo} mode='aspectFill' className={styles.image}/>
@ -95,9 +108,10 @@ const SearchList: FC<{name:string}> = ({name}:Props) => {
</View> </View>
</View>) </View>)
} }
<View style={{width: '710rpx', textAlign: 'center', color: '#999'}} className="font-28 mt-3">{text}</View> <View style={{width: '750rpx', textAlign: 'center', color: '#999'}} className="font-28 mt-3">{text}</View>
</> : <Empty name='空空如也'/> </>
} }
{ !loading && brands.length === 0 && <Empty name='空空如也'/>}
</ScrollView> </ScrollView>
) )
} }

@ -1,5 +1,5 @@
import {Input, View, Text, PageContainer} from "@tarojs/components"; 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 { AtIcon } from 'taro-ui'
import styles from './index.module.scss' import styles from './index.module.scss'
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
@ -20,6 +20,10 @@ const Search:FC = () => {
getRecentSearch() getRecentSearch()
}) })
useEffect(()=>{
getRecentSearch()
},[!show])
function inpFn(e){ function inpFn(e){
setValue(e.detail.value) setValue(e.detail.value)
} }
@ -55,7 +59,10 @@ const Search:FC = () => {
<View className="flex flex-column"> <View className="flex flex-column">
<View className={styles.searchBox}> <View className={styles.searchBox}>
<AtIcon value='search' size='20' color='#ccc'></AtIcon> <AtIcon value='search' size='20' color='#ccc'></AtIcon>
<Input className={styles.input} placeholder="输入关键字搜索课程" type={'text'} confirmType={'search'} onInput={inpFn} onConfirm={searchInput} /> { show ?
<Text className={styles.input} >{value}</Text>:
<Input className={styles.input} placeholder="输入关键字搜索课程" type={'text'} confirmType={'search'} onInput={inpFn} onConfirm={searchInput} />
}
</View> </View>
{ {
@ -98,7 +105,7 @@ const Search:FC = () => {
} }
<PageContainer onClickOverlay={()=>{ setShow(false)}} show={show} round={true} overlay={true} overlayStyle={'background:rgba(0,0,0,0)'} > <PageContainer onClickOverlay={()=>{ setShow(false)}} show={show} round={true} overlay={true} overlayStyle={'background:rgba(0,0,0,0)'} >
<SearchList name={value}/> <SearchList name={value} clear={show} />
</PageContainer> </PageContainer>
</View> </View>

Loading…
Cancel
Save