|
@@ -21,7 +21,7 @@ interface Props {
|
|
|
}
|
|
|
|
|
|
const Index = forwardRef((props: Props) => {
|
|
|
- const { bookStore, classifyStore, indexStore } = props.store
|
|
|
+ const { classifyStore, indexStore } = props.store
|
|
|
const { getBookPageList } = useApi()
|
|
|
const [pageShow, setPageShow] = useState(false)//防止小程序切换页面组件不会被真实卸载,阻止不必要的操作
|
|
|
const [open, setOpen] = useState(false)
|
|
@@ -30,23 +30,28 @@ const Index = forwardRef((props: Props) => {
|
|
|
// 获取分类列表
|
|
|
useEffect(() => {
|
|
|
if (pageShow) {
|
|
|
- let { workDirection } = bookStore
|
|
|
- getBookCategoryList(workDirection)
|
|
|
+ let { workDirection } = classifyStore
|
|
|
+ getBookCategoryList(workDirection).then((res: any) => {
|
|
|
+ if (res?.data?.code === 200) {
|
|
|
+ classifyStore.setData({ classifyData: res?.data?.data })
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
- }, [bookStore.workDirection, pageShow]); // Dependency array, runs effect only once on mount and unmount
|
|
|
+ }, [classifyStore.workDirection, pageShow]); // Dependency array, runs effect only once on mount and unmount
|
|
|
//获取书籍列表
|
|
|
useEffect(() => {
|
|
|
if (pageShow) {
|
|
|
- let { workDirection } = bookStore
|
|
|
+ let { workDirection } = classifyStore
|
|
|
let { categoryId } = classifyStore
|
|
|
- showEmpty && setShowEmpty(false)
|
|
|
- categoryId.id != 0 && classifyStore.categoryId && getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize: 10 }).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) {
|
|
|
- !showEmpty && setShowEmpty(true)
|
|
|
+ setShowEmpty(true)
|
|
|
+ }else{
|
|
|
+ setShowEmpty(false)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- }, [bookStore.workDirection, classifyStore.categoryId, pageShow])
|
|
|
+ }, [classifyStore.workDirection, classifyStore.categoryId, pageShow])
|
|
|
// 使用 useDidShow 代替 onShow
|
|
|
useDidShow(() => {
|
|
|
setPageShow(true)
|
|
@@ -54,20 +59,25 @@ const Index = forwardRef((props: Props) => {
|
|
|
// 使用 useDidHide 如果需要在页面隐藏时做一些处理
|
|
|
useDidHide(() => {
|
|
|
setPageShow(false)
|
|
|
- bookStore.setData({ bookList: [] })
|
|
|
});
|
|
|
//上拉刷新
|
|
|
const refresh = async () => {
|
|
|
- let { workDirection } = bookStore
|
|
|
+ let { workDirection } = classifyStore
|
|
|
let { categoryId } = classifyStore
|
|
|
- getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize: 10 })
|
|
|
+ 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 = () => {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- let { size, total, records } = bookStore.bookList
|
|
|
+ let { size, total, records } = classifyStore.bookList
|
|
|
let pageSize = size + 10
|
|
|
- let { workDirection } = bookStore
|
|
|
+ let { workDirection } = classifyStore
|
|
|
let { categoryId } = classifyStore
|
|
|
if (records?.length >= total) {
|
|
|
Taro.showToast({
|
|
@@ -78,8 +88,12 @@ const Index = forwardRef((props: Props) => {
|
|
|
reject()
|
|
|
return
|
|
|
} else {
|
|
|
- getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize }).then(res => {
|
|
|
- console.log("Res", res)
|
|
|
+ getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize, type: 'class' }).then((res:any) => {
|
|
|
+ if (res?.data?.data?.total === 0) {
|
|
|
+ setShowEmpty(true)
|
|
|
+ }else{
|
|
|
+ setShowEmpty(false)
|
|
|
+ }
|
|
|
resolve(true)
|
|
|
})
|
|
|
}
|
|
@@ -109,8 +123,8 @@ const Index = forwardRef((props: Props) => {
|
|
|
})
|
|
|
return (
|
|
|
<View className='index'>
|
|
|
- {bookStore?.classifyData?.length > 0 && <View style={{ background: "#fff" }} className='classList' onClick={() => { setIsSetOpen(false) }}>
|
|
|
- <BookTypeTabs open={open} onCallback={setOpen} typeValue={bookStore?.classifyData} typeTabIndex={classifyStore.categoryId} workDirection={bookStore.workDirection} ></BookTypeTabs>
|
|
|
+ {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>
|
|
|
</View>}
|
|
|
<View onTouchStart={() => { setIsSetOpen(true) }}>
|
|
|
<ScrollViewHoc
|
|
@@ -126,7 +140,7 @@ const Index = forwardRef((props: Props) => {
|
|
|
}} load={load} refresh={refresh} reloadState={open} filterClassName='.classList' navHeight={indexStore.navHeight}>
|
|
|
<View className='w row for_top1 pd_btm'>
|
|
|
{
|
|
|
- bookStore?.bookList?.records?.length > 0 && bookStore?.bookList?.records?.map((item, index) => {
|
|
|
+ classifyStore?.bookList?.records?.length > 0 && classifyStore?.bookList?.records?.map((item, index) => {
|
|
|
return <>
|
|
|
<View key={item.bookId} ><BookboxRowBig {...item} /></View>
|
|
|
</>
|