shenwu 7 月之前
父節點
當前提交
c4e8f170cd

+ 8 - 3
src/Hook/useApi.ts

@@ -1,6 +1,9 @@
 import { getParagraphList, getShortBookInfo, getShortBookInfoAppListOfPage, readingShort, startReadShort } from '@src/server/book/short'
+import { bookrackShrot } from '@src/server/bookrack'
 import { getShortBanners, getShortHotCategory, getShortHotBooks } from '@src/server/index/index'
-/**用于长短篇小说区别,使用不同的接口*/
+/**用于长短篇小说区别,使用不同的接口
+ * 传入appInfoStroe
+*/
 function useApi(store) {
     //判断是长篇
     let isLong = store?.appInfo?.appCategory === 1
@@ -11,10 +14,12 @@ function useApi(store) {
         getBookContent: isLong ? getParagraphList : getParagraphList,
         /**获取小说详情用于分享进入*/
         getBookInfo: isLong ? getShortBookInfo : getShortBookInfo,
-        /**小说阅读上报*/ 
+        /**小说阅读上报*/
         startReadBook: isLong ? startReadShort : startReadShort,
-        /**小说阅读心跳上报*/ 
+        /**小说阅读心跳上报*/
         readingBook: isLong ? readingShort : readingShort,
+        /**书架*/
+        bookrackList: isLong ? bookrackShrot : bookrackShrot,
         /**首页组件接口*/
         indexComponents: {
             "banners": isLong ? getShortBanners : getShortBanners,

+ 1 - 1
src/app.config.ts

@@ -13,7 +13,7 @@ export default {
     'pages/my/contactService/index',//联系客服
     'pages/book/bookArticle/index',//书籍内容 阅读页
     // 'pages/search/index',//搜索
-    // 'pages/indexMore/index', // 更多
+    'pages/indexMore/index', // 更多
     // 'pages/book/bookDetails1/index',//书籍详情
   ],
 

+ 15 - 16
src/components/PupPetry/BookBox/BookboxRowMiddle.tsx

@@ -4,29 +4,28 @@ import { Text, View, Image, Navigator } from "@tarojs/components";
 import React from 'react'
 import './index.less'
 export interface BookboxRowMiddleProps {
-    book_id?: number,//书籍ID
-    book_name?: string,//名称
-    penname?: string,//作者
-    intro?: string,//描述
-    cover?: string,//图片
-    category?: string,//标签分类
-    sign?: string,//热度,阅读人数 
-    action?: string//地址
+    bookId: number,//书ID
+    authorName: string,//作者
+    bookName: string,//书名称
+    bookDesc: string,//描述
+    picUrl: string,//封面
+    bookStatus: number,//完本|连载状态
+    wordCount: number,//字数
+    labelInfoList: { name: string }[],//标签
 }
 function BookboxRowMiddle(props: BookboxRowMiddleProps) {
-    const { book_id, book_name, penname, intro, cover, category, sign, action, } = props
-    let tags = category ? category.split(',') : []
+    const { bookName, picUrl, bookDesc, labelInfoList, authorName, bookId, wordCount, bookStatus } = props
     return <View className='book_box_row_middle'>
-        <Navigator url={'/pages/book/bookDetails/index?book_id='+book_id} hoverClass="none">
-            <Image src={cover || ''} className='img'></Image>
+        <Navigator url={'/pages/book/bookDetails/index?book_id=' + bookId} hoverClass="none">
+            <Image src={picUrl || ''} className='img'></Image>
             <View className='right'>
-                <Text className='title'>{book_name}</Text>
+                <Text className='title'>{bookName}</Text>
                 <View className='content'>
                     <View className='left'>
-                        <Text className='details'>{intro}</Text>
+                        <Text className='details'>{bookDesc?.replace(/\s/ig,'')}</Text>
                         <View className='bottom'>
-                            <Text className='describe'>{penname}</Text>
-                            <Text className='label'>{tags[0]}</Text>
+                            <Text className='describe'>{authorName}</Text>
+                            <Text className='label'>{labelInfoList?.[0].name}</Text>
                         </View>
                     </View>
                 </View>

+ 7 - 8
src/components/PupPetry/BookHotTabs/index.tsx

@@ -1,5 +1,5 @@
 import { ScrollView, View, Text } from '@tarojs/components'
-import React, { useCallback, useState } from 'react'
+import React, { useCallback, useEffect, useState } from 'react'
 import indexStore from '@src/store/index'
 import './index.less'
 /**
@@ -27,11 +27,10 @@ const BookHotTabs = (props: props) => {
         onBack?.(value)
         indexStore.setData({ indexCategoryId: value })
     }, [stateIndex])
-
-    let scrollSelectHandle = useCallback((value: string) => {
-        onBack?.(value)
-    }, [])
-
+    // 列表数据改变重新设置第一个为选中状态样式
+    useEffect(()=>{
+        setStateIndex(1)
+    },[hotValue])
     return <View className="hotTabs">
         {
             scroll ? <ScrollView scrollX style={{ whiteSpace: 'nowrap' }} className="scroll">
@@ -45,8 +44,8 @@ const BookHotTabs = (props: props) => {
             </ScrollView> :
                 <View>
                     {
-                        hotValue?.map((item) => {
-                            return <View className="tab scrollTab" onClick={() => { scrollSelectHandle(item.id) }}>
+                        hotValue?.map((item, index) => {
+                            return <View className="tab scrollTab" onClick={() => { selectHandle(item.id, index + 1) }}>
                                 <Text>{item.name}</Text>
                             </View>
                         })

+ 5 - 1
src/pages/bookrack/index.tsx

@@ -13,6 +13,7 @@ import BookboxRowSmall from '@src/components/PupPetry/BookBox/BookboxRowSmall'
 import Divider from '@src/components/PupPetry/Divider'
 import Empty from '@src/components/Empty'
 import { Store } from '@src/app'
+import useApi from '@src/Hook/useApi'
 
 
 interface Props {
@@ -20,12 +21,15 @@ interface Props {
 }
 
 const Index: React.FC<Props> = ({ store }) => {
+    const { bookrackList } = useApi(store.appInfoStore)
+
     useEffect(() => {
         log("componentDidMount", store.appInfoStore.appInfo);
+        bookrackList()
         return () => {
             log("componentWillUnmount");
         };
-    }, [store.appInfoStore.appInfo]); // Dependency array, runs effect only once on mount and unmount
+    }, []); // Dependency array, runs effect only once on mount and unmount
 
     // 使用 useDidShow 代替 onShow
     useDidShow(() => {

+ 27 - 4
src/pages/index/index.tsx

@@ -12,6 +12,7 @@ import Taro from '@tarojs/taro';
 import BookHead from '@src/components/PupPetry/BookHead';
 import BookHotTabs from '@src/components/PupPetry/BookHotTabs';
 import BookboxColumnSmall from '@src/components/PupPetry/BookBox/BookboxColumnSmall';
+import BookboxRowMiddle from '@src/components/PupPetry/BookBox/BookboxRowMiddle';
 
 
 interface Props {
@@ -19,7 +20,7 @@ interface Props {
 }
 const Index: React.FC<Props> = ({ store }) => {
     const { appInfoStore, bookStore, indexStore } = store
-    const { indexComponents } = useApi(appInfoStore)
+    const { indexComponents, getBookPageList } = useApi(appInfoStore)
     const [pageShow, setPageShow] = useState(false)//防止小程序切换页面组件不会被真实卸载,阻止不必要的操作
     // 首页配置信息
     const indexConfig = useMemo(() => {
@@ -59,6 +60,9 @@ const Index: React.FC<Props> = ({ store }) => {
                 case "banners"://轮播
                     getBanners()
                     break;
+                case "hot_books"://今日热书
+                    getToDayHotBooks()
+                    break;
                 case "hot_category"://热门分类
                     getHotCategory()
                     break;
@@ -76,15 +80,18 @@ const Index: React.FC<Props> = ({ store }) => {
             if (data?.length > 0) {
                 getHotBooks(data[0].id)
             }
-            console.log("data====>", data)
         })
     }
     // 热门分类书籍
     const getHotBooks = (categoryId) => {
         if (categoryId) {
-            indexComponents?.hot_books(bookStore.workDirection, categoryId)
+            getBookPageList({ pageNum: 1, pageSize: 8, workDirection: bookStore.workDirection, categoryId })
         }
     }
+    // 今日热书
+    const getToDayHotBooks = () => {
+        indexComponents?.hot_books(bookStore.workDirection)
+    }
     return (
         <ScrollViewHoc>
             <View style={{ display: "flex", flexFlow: 'column' }}>
@@ -92,13 +99,29 @@ const Index: React.FC<Props> = ({ store }) => {
                 {indexConfig['banners'] && <View style={{ order: indexConfig['banners'].eq }}>
                     <BannerBox data={indexStore?.indexBanners || []} />
                 </View>}
+                {/* 今日热门 */}
+                {indexConfig['hot_books'] && <View style={{ order: indexConfig['banners'].eq }}>
+                    <BookHead title="今日热书" fitTitle="更多" imgUrl={require('../../icon/right.png')} fitOnBack={() => {
+                        Taro.navigateTo({ url: `/pages/indexMore/index?title=今日热书&dataName=indexHotBooks` })
+                    }}></BookHead>
+                    <View ><BookboxRowMiddle {...indexStore?.indexHotBooks?.[0]} /></View>
+                    <View className='w row'>
+                        {
+                            indexStore?.indexHotBooks?.map((item, index) => {
+                                if (index > 0 && index < 5) {
+                                    return <View key={index}><BookboxColumnSmall {...item} /></View>
+                                }
+                            })
+                        }
+                    </View>
+                </View>}
                 {/* 热门分类 */}
                 {indexConfig['hot_category'] && <View style={{ order: indexConfig['banners'].eq }}>
                     <BookHead title="热门分类" fitTitle="全部分类" imgUrl={require('../../icon/right.png')} fitOnBack={() => { Taro.switchTab({ url: '/pages/classify/index' }) }} />
                     <BookHotTabs hotValue={indexStore?.indexHotCategory || []} />
                     <View className='w row4'>
                         {
-                            indexStore?.indexHotBooks?.map((item, index) => {
+                            bookStore?.bookList?.records?.map((item, index) => {
                                 return <View key={index}><BookboxColumnSmall {...item} /></View>
                             })
                         }

+ 3 - 0
src/pages/indexMore/index.config.ts

@@ -0,0 +1,3 @@
+export default {
+    navigationStyle: 'custom'
+}

+ 0 - 0
src/pages/indexMore/index.less


+ 53 - 0
src/pages/indexMore/index.tsx

@@ -0,0 +1,53 @@
+import { Component } from 'react'
+import { View } from '@tarojs/components'
+import { observer, inject } from 'mobx-react'
+import './index.less'
+import BookboxRowBig from '@src/components/PupPetry/BookBox/BookboxRowBig'
+import CustomNavbar from '@src/components/TopNavBar'
+import { Store } from '@src/app'
+
+interface NormalListState {
+    title: string,
+    dataName: string,//store 中的参数名称
+    data: any[]
+}
+interface Props {
+    store: Store;
+}
+@inject('store')
+@observer
+class indexMore extends Component<Props> {
+    state: NormalListState = {
+        title: '',
+        dataName: '',
+        data: []
+    }
+    onLoad(opt: { title: string, dataName: string }) {
+        let { indexStore } = this.props.store
+        let { title, dataName } = opt
+        this.setState({
+            title,
+            data: indexStore[dataName]
+        })
+    }
+
+    render() {
+        let { title, data } = this.state
+        let Page: any = CustomNavbar(function Page() {
+            return <View className='indexMore pd_btm'>
+                {/* 头部bar */}
+                <View className='w  row for_top'>
+                    {
+                        data?.map((item, index) => {
+                            return <View key={index}><BookboxRowBig {...item} /></View>
+                        })
+                    }
+
+                </View>
+            </View>
+        }, { title, isToBack: true })
+        console.log(Page)
+        return <Page />
+    }
+}
+export default indexMore

+ 24 - 0
src/server/bookrack/index.tsx

@@ -0,0 +1,24 @@
+import Taro from "@tarojs/taro";
+import bookStore from "@src/store/book";
+/**
+ * 获取分类列表
+ * */
+export function bookrackShrot() {
+    return new Promise(async (resolve, reject) => {
+        try {
+            // 初始化
+            Taro.request({
+                url: '/app/shortBookshelf/listOfPage',
+                method: 'GET',
+                success: (res) => {
+                    resolve(res)
+                },
+                fail: (err) => {
+                    reject(err);
+                }
+            })
+        } catch (error) {
+            reject(error);
+        }
+    })
+}

+ 2 - 2
src/server/index/index.ts

@@ -76,14 +76,14 @@ export function getShortHotCategory(workDirection) {
 /**
  * 获取短篇首页热门书籍列表
  * */
-export function getShortHotBooks(workDirection, categoryId) {
+export function getShortHotBooks(workDirection) {
     return new Promise(async (resolve, reject) => {
         try {
             // 初始化
             Taro.request({
                 url: '/app/appComponent/getShortBookHotBooks',
                 method: 'GET',
-                data: { workDirection, categoryId },
+                data: { workDirection },
                 success: (res) => {
                     indexStore.setData({ indexHotBooks: res.data.data })
                     resolve(res)