|
@@ -2,11 +2,10 @@ import { forwardRef, useEffect, useRef, useState } from 'react'
|
|
import Taro, { useShareAppMessage } from '@tarojs/taro'
|
|
import Taro, { useShareAppMessage } from '@tarojs/taro'
|
|
import { useDidHide, useDidShow } from '@tarojs/taro'
|
|
import { useDidHide, useDidShow } from '@tarojs/taro'
|
|
import { observer, inject } from 'mobx-react'
|
|
import { observer, inject } from 'mobx-react'
|
|
-import { View } from '@tarojs/components'
|
|
|
|
|
|
+import { ScrollView, View } from '@tarojs/components'
|
|
import './index.less'
|
|
import './index.less'
|
|
//==========components组件引用========================
|
|
//==========components组件引用========================
|
|
import TopNavBar from '@src/components/TopNavBar/index'
|
|
import TopNavBar from '@src/components/TopNavBar/index'
|
|
-import ScrollViewHoc from '@src/components/ScrollView'
|
|
|
|
import BookboxRowBig from '@src/components/PupPetry/BookBox/BookboxRowBig'
|
|
import BookboxRowBig from '@src/components/PupPetry/BookBox/BookboxRowBig'
|
|
import BookTypeTabs from '@src/components/PupPetry/BookTypeTabs'
|
|
import BookTypeTabs from '@src/components/PupPetry/BookTypeTabs'
|
|
import Empty from '@src/components/Empty'
|
|
import Empty from '@src/components/Empty'
|
|
@@ -27,9 +26,12 @@ const Index = forwardRef((props: Props) => {
|
|
const [open, setOpen] = useState(false)
|
|
const [open, setOpen] = useState(false)
|
|
const [showEmpty, setShowEmpty] = useState(false)
|
|
const [showEmpty, setShowEmpty] = useState(false)
|
|
const [isSetOpen, setIsSetOpen] = useState(true)
|
|
const [isSetOpen, setIsSetOpen] = useState(true)
|
|
|
|
+ const [filterHeight, setFilterHeight] = useState(0)
|
|
|
|
+ const timeRef = useRef<any>()
|
|
// 获取分类列表
|
|
// 获取分类列表
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (pageShow) {
|
|
if (pageShow) {
|
|
|
|
+ console.log("获取分类列表")
|
|
let { workDirection } = classifyStore
|
|
let { workDirection } = classifyStore
|
|
getBookCategoryList(workDirection).then((res: any) => {
|
|
getBookCategoryList(workDirection).then((res: any) => {
|
|
if (res?.data?.code === 200) {
|
|
if (res?.data?.code === 200) {
|
|
@@ -41,12 +43,13 @@ const Index = forwardRef((props: Props) => {
|
|
//获取书籍列表
|
|
//获取书籍列表
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (pageShow) {
|
|
if (pageShow) {
|
|
|
|
+ console.log("获取书籍列表")
|
|
let { workDirection } = classifyStore
|
|
let { workDirection } = classifyStore
|
|
let { categoryId } = classifyStore
|
|
let { categoryId } = classifyStore
|
|
categoryId.id != 0 && classifyStore.categoryId && getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize: 10, type: 'class' }).then((res: any) => {
|
|
categoryId.id != 0 && classifyStore.categoryId && getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize: 10, type: 'class' }).then((res: any) => {
|
|
if (res?.data?.data?.total === 0) {
|
|
if (res?.data?.data?.total === 0) {
|
|
setShowEmpty(true)
|
|
setShowEmpty(true)
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
setShowEmpty(false)
|
|
setShowEmpty(false)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -58,20 +61,8 @@ const Index = forwardRef((props: Props) => {
|
|
});
|
|
});
|
|
// 使用 useDidHide 如果需要在页面隐藏时做一些处理
|
|
// 使用 useDidHide 如果需要在页面隐藏时做一些处理
|
|
useDidHide(() => {
|
|
useDidHide(() => {
|
|
- setPageShow(false)
|
|
|
|
|
|
+ // setPageShow(false)
|
|
});
|
|
});
|
|
- //上拉刷新
|
|
|
|
- const refresh = async () => {
|
|
|
|
- let { workDirection } = classifyStore
|
|
|
|
- let { categoryId } = classifyStore
|
|
|
|
- getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize: 10, type: 'class' }).then((res: any) => {
|
|
|
|
- if (res?.data?.data?.total === 0) {
|
|
|
|
- setShowEmpty(true)
|
|
|
|
- }else{
|
|
|
|
- setShowEmpty(false)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
//下拉加载
|
|
//下拉加载
|
|
const load = () => {
|
|
const load = () => {
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
@@ -88,10 +79,11 @@ const Index = forwardRef((props: Props) => {
|
|
reject()
|
|
reject()
|
|
return
|
|
return
|
|
} else {
|
|
} else {
|
|
- getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize, type: 'class' }).then((res:any) => {
|
|
|
|
|
|
+ getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize, type: 'class' }).then((res: any) => {
|
|
if (res?.data?.data?.total === 0) {
|
|
if (res?.data?.data?.total === 0) {
|
|
setShowEmpty(true)
|
|
setShowEmpty(true)
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
|
|
+ console.log("isSetOpen", isSetOpen)
|
|
setShowEmpty(false)
|
|
setShowEmpty(false)
|
|
}
|
|
}
|
|
resolve(true)
|
|
resolve(true)
|
|
@@ -121,23 +113,62 @@ const Index = forwardRef((props: Props) => {
|
|
}
|
|
}
|
|
return {}
|
|
return {}
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ const callBacn = (b) => {
|
|
|
|
+ Taro.createSelectorQuery()
|
|
|
|
+ .select('.classList') // 选择器,用于选择要获取信息的元素
|
|
|
|
+ .boundingClientRect() // 获取节点的布局信息
|
|
|
|
+ .exec((res) => {
|
|
|
|
+ if (res[0]) {
|
|
|
|
+ const height = res[0].height; // 获取元素的高度
|
|
|
|
+ setFilterHeight(height + indexStore.navHeight);
|
|
|
|
+ } else {
|
|
|
|
+ console.log("未找到指定元素");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ setOpen(b)
|
|
|
|
+ }
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ callBacn(false)
|
|
|
|
+ }, [])
|
|
return (
|
|
return (
|
|
<View className='index'>
|
|
<View className='index'>
|
|
{classifyStore?.classifyData?.length > 0 && <View style={{ background: "#fff" }} className='classList' onClick={() => { setIsSetOpen(false) }}>
|
|
{classifyStore?.classifyData?.length > 0 && <View style={{ background: "#fff" }} className='classList' onClick={() => { setIsSetOpen(false) }}>
|
|
- <BookTypeTabs open={open} onCallback={setOpen} typeValue={classifyStore?.classifyData} typeTabIndex={classifyStore.categoryId} workDirection={classifyStore.workDirection} ></BookTypeTabs>
|
|
|
|
|
|
+ <BookTypeTabs open={open} onCallback={callBacn} typeValue={classifyStore?.classifyData} typeTabIndex={classifyStore.categoryId} workDirection={classifyStore.workDirection} ></BookTypeTabs>
|
|
</View>}
|
|
</View>}
|
|
- <View onTouchStart={() => { setIsSetOpen(true) }}>
|
|
|
|
- <ScrollViewHoc
|
|
|
|
- callback={(top) => {
|
|
|
|
- if (isSetOpen) {
|
|
|
|
- if (top > 100 && open) {
|
|
|
|
- setOpen(false)
|
|
|
|
- }
|
|
|
|
- if (top < 100 && !open) {
|
|
|
|
- setOpen(true)
|
|
|
|
- }
|
|
|
|
|
|
+ <View>
|
|
|
|
+
|
|
|
|
+ </View>
|
|
|
|
+ <View onTouchStart={() => {
|
|
|
|
+ setIsSetOpen(true)
|
|
|
|
+ }} >
|
|
|
|
+ <ScrollView
|
|
|
|
+ lowerThreshold={filterHeight}
|
|
|
|
+ // refresherTriggered={this.state.isShow}
|
|
|
|
+ style={{ height: `calc(100vh - ${filterHeight + 10}px)` }}
|
|
|
|
+ onScrollToLower={load}
|
|
|
|
+ onScroll={(evt: any) => {
|
|
|
|
+ let top = evt.detail.scrollTop
|
|
|
|
+ if(timeRef.current){
|
|
|
|
+ clearTimeout(timeRef.current)
|
|
}
|
|
}
|
|
- }} load={load} refresh={refresh} reloadState={open} filterClassName='.classList' navHeight={indexStore.navHeight}>
|
|
|
|
|
|
+ timeRef.current=setTimeout(()=>{
|
|
|
|
+ if (isSetOpen) {
|
|
|
|
+ if (top > 100 && open) {
|
|
|
|
+ callBacn(false)
|
|
|
|
+ }
|
|
|
|
+ if (top < 100 && !open) {
|
|
|
|
+ callBacn(true)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },100)
|
|
|
|
+
|
|
|
|
+ }}
|
|
|
|
+ className="scrollview"
|
|
|
|
+ scrollY={true}
|
|
|
|
+ refresherDefaultStyle="black"
|
|
|
|
+ // scrollWithAnimation={true}
|
|
|
|
+ >
|
|
<View className='w row for_top1 pd_btm'>
|
|
<View className='w row for_top1 pd_btm'>
|
|
{
|
|
{
|
|
classifyStore?.bookList?.records?.length > 0 && classifyStore?.bookList?.records?.map((item, index) => {
|
|
classifyStore?.bookList?.records?.length > 0 && classifyStore?.bookList?.records?.map((item, index) => {
|
|
@@ -150,7 +181,7 @@ const Index = forwardRef((props: Props) => {
|
|
showEmpty && <Empty />
|
|
showEmpty && <Empty />
|
|
}
|
|
}
|
|
</View>
|
|
</View>
|
|
- </ScrollViewHoc>
|
|
|
|
|
|
+ </ScrollView>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
|
|
|