shenwu 7 hónapja
szülő
commit
85581cc63b

+ 11 - 2
src/Hook/useApi.ts

@@ -1,13 +1,22 @@
-import { getParagraphList, getShortBookInfoAppListOfPage } from '@src/server/book/short'
+import { getParagraphList, getShortBookInfo, getShortBookInfoAppListOfPage } from '@src/server/book/short'
+import { getShortBanners, getShortHotCategory, getShortHotBooks } from '@src/server/index/index'
 /**用于长短篇小说区别,使用不同的接口*/
 function useApi(store) {
     //判断是长篇
-    let isLong = store.appInfo.appCategory === 1
+    let isLong = store?.appInfo?.appCategory === 1
     return {
         /**获取小说列表*/
         getBookPageList: isLong ? getShortBookInfoAppListOfPage : getShortBookInfoAppListOfPage,
         /**获取小说内容*/
         getBookContent: isLong ? getParagraphList : getParagraphList,
+        /**获取小说详情用于分享进入*/
+        getBookInfo: isLong ? getShortBookInfo : getShortBookInfo,
+        /**首页组件接口*/
+        indexComponents: {
+            "banners": isLong ? getShortBanners : getShortBanners,
+            "hot_books": isLong ? getShortHotBooks : getShortHotBooks,//热门标签
+            "hot_category": isLong ? getShortHotCategory : getShortHotCategory,//热门书籍
+        }
     }
 
 }

+ 1 - 1
src/app.config.ts

@@ -55,5 +55,5 @@ export default {
         selectedIconPath:'./icon/wd_2.png',//选中的图片变化
       },
     ]
-  }
+  },
 }

+ 51 - 27
src/app.less

@@ -1,34 +1,58 @@
 // 横向
 .row {
-    display: flex;
-    flex-flow: row wrap;
-    justify-content: space-between;
-    width: 690px;
-    margin: 0 auto;
-  }
-  // 循环BookboxRowBig组件用到
-  .for_top {
-    > view {
-      margin-top: 40px;
-      &:nth-child(1) {
-        margin-top: 30px;
-      }
+  display: flex;
+  flex-flow: row wrap;
+  justify-content: space-between;
+  width: 690px;
+  margin: 0 auto;
+}
+
+//横向4
+.row4 {
+  display: flex;
+  flex-flow: row wrap;
+  justify-content: left;
+  width: 690px;
+  margin: 0 auto;
+  >view{
+    margin-right: 35px;
+    &:nth-child(4n){
+      margin-right: 0px;
     }
   }
-  //循环BookboxRowBig组件用到
-  .for_top1 {
-    > view {
-      margin-top: 40px;
-      &:nth-child(1) {
-        margin-top: 11px;
-      }
+}
+
+// 循环BookboxRowBig组件用到
+.for_top {
+  >view {
+    margin-top: 40px;
+
+    &:nth-child(1) {
+      margin-top: 30px;
     }
   }
-  //底部padding留空
-  .pd_btm {
-    padding-bottom: 50px;
-  }
-  .scrollview {
-    height: 100%;
+}
+
+//循环BookboxRowBig组件用到
+.for_top1 {
+  >view {
+    margin-top: 40px;
+
+    &:nth-child(1) {
+      margin-top: 11px;
+    }
   }
-  image{height:auto}
+}
+
+//底部padding留空
+.pd_btm {
+  padding-bottom: 50px;
+}
+
+.scrollview {
+  height: 100%;
+}
+
+image {
+  height: auto
+}

+ 12 - 11
src/app.tsx

@@ -4,7 +4,7 @@ import Taro from '@tarojs/taro'
 import './app.less'
 // ======store======
 import userInfo from './store/userInfo'
-import indexStore from './store/index'
+import indexStore, { IndexStore } from './store/index'
 import Book, { BookStore } from './store/book'
 import appInfoStore, { AppInfoStore } from './store/appInfo'
 import classifyStore, { ClassifyStore } from './store/classIfy'
@@ -19,7 +19,7 @@ import api from './server/index'
 export interface Store {
   appInfoStore: AppInfoStore
   userInfo: any,
-  indexStore: any,
+  indexStore: IndexStore,
   bookStore: BookStore,
   classifyStore: ClassifyStore,
 }
@@ -34,14 +34,9 @@ class App extends Component {
 
   //每次打开小程序触发,后台切入不算
   async onLaunch(options) {
-    log("初始化只第一次发生", options, app.initToken)
-    initApp()//初始化全局变量
-    let appId = Taro.getAccountInfoSync().miniProgram.appId//获取当前小程序的APPID 
-    setApp({ appId })
-    // 初始化登录,获取登录使用的token存放用于登录使用
-    await api.loginInit(appId)
   }
   componentDidMount() {
+    console.log("APPcomponentDidMount")
     /**获取状态栏高度 */
     Taro.getSystemInfo({}).then(res => {
       let { system, statusBarHeight } = res
@@ -50,19 +45,25 @@ class App extends Component {
     })
   }
   async componentDidShow(options) {
-    let { scene,query } = options//获取当前小程序进入的场景值
+    let { scene, query } = options//获取当前小程序进入的场景值
     let bookConfig = Taro.getStorageSync("bookConfig")
     if (bookConfig) {
       Book.setData({ bookConfig: JSON.parse(bookConfig) })
     }
-    indexStore.setData({ scene ,query})
+    indexStore.setData({ scene, query })
+    // 启动初始化
+    console.log("初始化")
+    initApp()//初始化全局变量
+    let appId = Taro.getAccountInfoSync().miniProgram.appId//获取当前小程序的APPID 
+    setApp({ appId })
+    // 初始化登录,获取登录使用的token存放用于登录使用
+    await api.loginInit(appId)
   }
   componentDidHide() { }
 
   componentDidCatchError() { }
 
   render() {
-    log("store.appInfoStore.appInfo", store.appInfoStore.appInfo)
     return <Provider store={store}>
       {(this.props as ProviderProps).children}
     </Provider>

+ 5 - 7
src/components/PupPetry/BannerBox/index.tsx

@@ -3,8 +3,8 @@ import React from "react";
 import './index.less'
 /**轮播图 */
 interface Item {
-    img_url: string,
-    action: string
+    picUrl: string,
+    bookId: string
 }
 interface BannerBoxProps {
     data?: Item[]
@@ -22,12 +22,10 @@ function BannerBox(props: BannerBoxProps) {
     >
         {
             data?.map((item: Item, index: number) => {
-                let {action} = item
-                let arr = action?.split('/')
-                let id = arr[arr.length-1]
+                let {bookId,picUrl} = item
                 return <SwiperItem key={index}>
-                    <Navigator url={'/pages/book/bookDetails/index?book_id='+id} hoverClass="none">
-                        <Image src={item?.img_url} className='img' />
+                    <Navigator url={'/pages/book/bookDetails/index?book_id='+bookId} hoverClass="none">
+                        <Image src={picUrl} className='img' />
                     </Navigator>
                 </SwiperItem>
             })

+ 17 - 13
src/components/PupPetry/BookBox/BookboxColumnSmall.tsx

@@ -3,23 +3,27 @@
 import { Text, View, Image, Navigator } from "@tarojs/components";
 import React from 'react'
 import './index.less'
+import BookStore from "@src/store/book"
 export interface BookboxColumnSmallProps {
-    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 BookboxColumnSmall(props: BookboxColumnSmallProps) {
-    const { cover, book_name, book_id } = props
-    return <View className='book_box_column_small'>
-        <Navigator url={'/pages/book/bookDetails/index?book_id='+ book_id} hoverClass="none">
-            <Image src={cover || ''} className='img'></Image>
+    const { picUrl, bookName, bookId } = props
+    const click = () => {
+        BookStore.setData({ openBookData: props })
+    }
+    return <View className='book_box_column_small' onClick={click}>
+        <Navigator url={'/pages/book/bookDetails/index?book_id=' + bookId} hoverClass="none">
+            <Image src={picUrl || ''} className='img'></Image>
             <View className='bottom'>
-                <Text className='title'>{book_name}</Text>
+                <Text className='title'>{bookName}</Text>
             </View>
         </Navigator>
     </View>

+ 5 - 1
src/components/PupPetry/BookBox/BookboxRowBig.tsx

@@ -3,6 +3,7 @@
 import { Text, View, Image, Navigator } from "@tarojs/components";
 import React from 'react'
 import './index.less'
+import BookStore from "@src/store/book"
 export interface BookboxRowBigProps {
     bookId: number,//书ID
     authorName:string,//作者
@@ -19,7 +20,10 @@ function BookboxRowBig(props: BookboxRowBigProps) {
     if(wordCount && bookStatus) {
         describe = `${bookName}·${(wordCount/10000).toFixed(0)}万字·${bookStatus === 0 ? '连载' : '完本'}`
     }
-    return <View className='book_box_row_big'>
+    const click = () => {
+        BookStore.setData({ openBookData: props })
+    }
+    return <View className='book_box_row_big' onClick={click}>
         <Navigator url={'/pages/book/bookDetails/index?bookId=' + bookId} hoverClass="none">
             <Image src={picUrl || ''} className='img'></Image>
             <View className='right'>

+ 34 - 0
src/components/PupPetry/BookHotTabs/index.less

@@ -0,0 +1,34 @@
+@import "../../../globaStyle.less";
+.hotTabs {
+  margin: 30px 30px 0 30px;
+  .scroll::-webkit-scrollbar{
+    width: 0;
+    height: 0;
+    color: transparent;
+  }
+  .tab {
+    display: inline-flex;
+    padding: 0 32px;
+    background: @bg_F4;
+    border-radius: 34px;
+    margin-right: 20px;
+    height: 68px;
+    align-items: center;
+    line-height: 68px;
+    text {
+      font-size: 28px;
+      font-family: PingFangSC-Regular, PingFang SC;
+      font-weight: 400;
+      color: @cl_666;
+    }
+    &:last-child {
+      margin-right: 0;
+    }
+  }
+  .scrollTab {
+    margin-bottom: 30px;
+    text {
+      color: @cl_333;
+    }
+  }
+}

+ 60 - 0
src/components/PupPetry/BookHotTabs/index.tsx

@@ -0,0 +1,60 @@
+import { ScrollView, View, Text } from '@tarojs/components'
+import React, { useCallback, useState } from 'react'
+import indexStore from '@src/store/index'
+import './index.less'
+/**
+ * 热门 tabs
+ */
+
+type props = {
+    hotValue: {
+        name: string,
+        id: string,
+        color?: string,     // 选中字体颜色
+        backColor?: string  // 选中背景颜色
+    }[],
+    hotTabIndex?: number,  // tab选中第几个  默认1
+    onBack?: (value: string) => void,     // 切换回调函数
+    scroll?: boolean
+}
+
+const BookHotTabs = (props: props) => {
+    let { hotValue, hotTabIndex = 1, onBack, scroll = true } = props
+
+    let [stateIndex, setStateIndex] = useState<number>(hotTabIndex)
+    let selectHandle = useCallback((value: string, index: number) => {
+        setStateIndex(index)
+        onBack?.(value)
+        indexStore.setData({ indexCategoryId: value })
+    }, [stateIndex])
+
+    let scrollSelectHandle = useCallback((value: string) => {
+        onBack?.(value)
+    }, [])
+
+    return <View className="hotTabs">
+        {
+            scroll ? <ScrollView scrollX style={{ whiteSpace: 'nowrap' }} className="scroll">
+                {
+                    hotValue?.map((item, index) => {
+                        return <View className={`tab`} style={index === stateIndex - 1 ? item?.backColor ? { backgroundColor: item.backColor } : { backgroundColor: '#E5EBFA' } : {}} onClick={() => { selectHandle(item.id, index + 1) }}>
+                            <Text style={index === stateIndex - 1 ? item?.color ? { color: item.color } : { color: '#253C6F' } : {}}>{item.name}</Text>
+                        </View>
+                    })
+                }
+            </ScrollView> :
+                <View>
+                    {
+                        hotValue?.map((item) => {
+                            return <View className="tab scrollTab" onClick={() => { scrollSelectHandle(item.id) }}>
+                                <Text>{item.name}</Text>
+                            </View>
+                        })
+                    }
+                </View>
+        }
+
+    </View>
+}
+
+export default React.memo(BookHotTabs)

+ 12 - 8
src/components/ScrollView/index.tsx

@@ -27,7 +27,11 @@ class ScrollViewHoc extends Component<Props> {
     }
     //**向上刷新 */
     onScrollToUpper = () => {
-        console.log("向上刷新")
+        if(!this.props.refresh){
+            setTimeout(() => { this.setState({ isShow: false }) }, 500)
+            log('请传入自定义refresh事件')
+            return
+        }
         let { isShow } = this.state
         log(isShow)
         if (!isShow) {
@@ -37,14 +41,16 @@ class ScrollViewHoc extends Component<Props> {
                     await this?.props?.refresh().then(() => {
                         setTimeout(() => { this.setState({ isShow: false }) }, 500)
                     })
-                } else {
-                    log('请在组件中自定义refresh事件')
-                }
+                } 
             })
         }
     }
     /**向下加载 */
     onScrollToLower = () => {
+        if(!this.props.load){
+            log('请传入自定义load事件')
+            return
+        }
         let { isBoShow } = this.state
         if (!isBoShow) {
             log('上拉')
@@ -56,9 +62,7 @@ class ScrollViewHoc extends Component<Props> {
                         this.setState({ isNull: true, isBoShow: false })
                     })
                     setTimeout(() => { this.setState({ isBoShow: false }) }, 500)
-                } else {
-                    log('请在组件中自定义load事件')
-                }
+                } 
             })
         }
     }
@@ -71,7 +75,7 @@ class ScrollViewHoc extends Component<Props> {
         const { children } = this.props
         return <ScrollView
             lowerThreshold={10}
-            refresherEnabled={true}
+            // refresherEnabled={true}
             refresherTriggered={this.state.isShow}
             onScrollToLower={this.onScrollToLower}
             className='scrollview'

+ 0 - 4
src/components/TopNavBar/index.tsx

@@ -60,7 +60,6 @@ function CustomNavbar(WrappedComponent, props: Props) {
             let buttonBounding = Taro.getMenuButtonBoundingClientRect()
             log(buttonBounding);
             let { height, top, width } = buttonBounding
-            console.log("navBarTop", top, navBarTop)
             let navBar = (top - navBarTop) * 2 + height + 8
             this.setState({ capsuleWidth: width + 10, navBar, navBarTop })
             indexStore.setData({ navHeight: navBar + navBarTop + 5 })
@@ -95,9 +94,6 @@ function CustomNavbar(WrappedComponent, props: Props) {
                 this.setState({ capsuleWidth: width + 10, navBar: (top - newNavBarTop) * 2 + height + 8, navBarTop: newNavBarTop })
 
             }
-            if (props.store.indexStore.openType === 1) {
-                log(123321);
-            }
 
         }
 

+ 6 - 4
src/interceptor.ts

@@ -68,9 +68,11 @@ const responseInterceptor = (chain) => {
                 // 初始化接口调用登录接口,登录接口存在自己的执行判断
                 if (chain.requestParams.url.includes("loginInitialize")) {
                     setApp({ initToken: data.data.token })
-                    appInfoStore.actionAppInfo(data.data.appInfo)
-                    await api.getAppComponent()
-                    await api.login()
+                    // appInfoStore.actionAppInfo(data.data.appInfo)
+                    let res: any = await api.getAppComponent()
+                    let user:any = await api.login()
+                    console.log(user)
+                    appInfoStore.setData({ appInfo: data.data.appInfo, appComponent: res.data.data,token:user.token})
                 }
                 break;
             case 300:
@@ -79,7 +81,7 @@ const responseInterceptor = (chain) => {
                 await api.loginInit(app.appId)
                 // 重新执行当前请求
                 const newRequestParams = chain.requestParams;
-                // return Taro.request(newRequestParams).then(newResponse => newResponse.data);
+                return Taro.request(newRequestParams).then(newResponse => newResponse.data);
                 break;
             default:
                 log("未知错误", data)

+ 30 - 25
src/pages/book/BookArticle/index.tsx

@@ -175,7 +175,7 @@ const BookArticle: React.FC<BookArticleProps> = ({ store }) => {
     return (
         <ScrollView
             lowerThreshold={indexStore.navHeight}
-            refresherTriggered={isLoad}
+            // refresherTriggered={isLoad}//加载状态
             onScrollToLower={onLoad}
             style={{ height: `calc(100vh - ${indexStore.navHeight}px)` }}
             scrollY={true}
@@ -184,7 +184,8 @@ const BookArticle: React.FC<BookArticleProps> = ({ store }) => {
             scrollIntoView={currentScrollId}
             onScroll={handleScroll}
         >
-            <View className={`book_article ${off_on ? bg : 'bg_hh'} ${off_on ? 'cl_h' : 'cl_b'}`} onClick={togglePup}>
+            <View className={`book_article ${off_on ? bg : 'bg_hh'} ${off_on ? 'cl_h' : 'cl_b'}`} >
+                {/* 顶部设置 */}
                 <View className='header'>
                     <View className='btns'>
                         <View className='left'>
@@ -199,35 +200,39 @@ const BookArticle: React.FC<BookArticleProps> = ({ store }) => {
                         </View>
                         <View className='right'>
                             <Text onClick={() => { setOff() }}>{off_on ? '关灯' : '开灯'}</Text>
-                            <Text onClick={togglePup}>菜单</Text>
+                            {isLoad && <Text onClick={togglePup}>菜单</Text>}
                         </View>
                     </View>
                 </View>
-
-                {
-                    openBookData?.contentData?.records?.map(item => {
-                        let arr = item.paragraphInfo.content?.match(/[^\n]*\n?/g);
-                        return <View
-                            id={'paragraphNo-' + item.paragraphInfo.paragraphNo}
-                            key={item.paragraphInfo.paragraphNo}
-                            className={`pre ${size} ${lh}`}
-                        >
-                            {
-                                arr?.map((str, index) => {
-                                    // let strArr = str?.match(/[^。]*。/g)
-                                    return <Text className='shrot-text' id={'paragraphNo-' + item.paragraphInfo.paragraphNo + '-' + index} key={index}>{
-                                       str
-                                    }</Text>
-                                })
-                            }
-                        </View>
-                    })
-                }
+                {/* 正文内容 */}
+                <View onClick={togglePup}>
+                    {
+                        openBookData?.contentData?.records?.map(item => {
+                            let arr = item.paragraphInfo.content?.match(/[^\n]*\n?/g);
+                            return <View
+                                id={'paragraphNo-' + item.paragraphInfo.paragraphNo}
+                                key={item.paragraphInfo.paragraphNo}
+                                className={`pre ${size} ${lh}`}
+                            >
+                                {
+                                    arr?.map((str, index) => {
+                                        // let strArr = str?.match(/[^。]*。/g)
+                                        return <Text className='shrot-text' id={'paragraphNo-' + item.paragraphInfo.paragraphNo + '-' + index} key={index}>{
+                                            str
+                                        }</Text>
+                                    })
+                                }
+                            </View>
+                        })
+                    }
+                </View>
+                {/* 设置弹窗 */}
                 {pup && <BookConfigPuP {...bookConfig} off_on={off_on} setOff={setOff} setSize={setSize} setBg={setBg} setLh={setLh} />}
             </View>
-            {
+            {/* 底部下来加载 */}
+            {/* {
                 isLoad && <UpLoading />
-            }
+            } */}
         </ScrollView>
     );
 };

+ 22 - 5
src/pages/book/bookDetails/index.tsx

@@ -5,6 +5,7 @@ import './index.less'
 import BookHead from '@src/components/PupPetry/BookHead'
 import { Store } from '@src/app'
 import Taro from '@tarojs/taro'
+import useApi from '@src/Hook/useApi'
 /**书详情 */
 
 type state = {
@@ -17,17 +18,33 @@ interface Props {
 class BookDetails extends Component<Props> {
     state: state = {
     }
-    componentDidShow(options){
-        let params =  Taro.getCurrentInstance()?.router?.params
+    onShareAppMessage() {
+        return {
+            title: '我的好朋友',
+            path: 'pages/book/bookDetails/index?bookId' + this.props.store.bookStore.openBookData?.bookId,
+            imageUrl: this.props.store.bookStore.openBookData?.picUrl
+        }
+    }
+    componentDidShow(options) {
+        Taro.showShareMenu({
+            showShareItems: ["shareAppMessage"],
+            success: (res) => { console.log("成功") },
+            fail: (err) => { console.log("err") }
+        });
+        let params = Taro.getCurrentInstance()?.router?.params
+        let { bookStore, appInfoStore } = this.props.store
         // 获取书籍详情
-        if(params?.bookId){
+        if (params?.bookId && !bookStore.openBookData) {
+            let { getBookInfo } = useApi(appInfoStore)
+            console.log("分享进入")
+            getBookInfo(params.bookId)
             console.log(params?.bookId)
         }
     }
     render() {
         let { bookStore } = this.props.store
         let { openBookData } = bookStore
-        let describe = `${openBookData?.bookName}·${openBookData?.wordCount?(openBookData?.wordCount/10000).toFixed(0)+"万字·":""}${openBookData?.bookStatus === 0 ? '连载' : '完本'}`
+        let describe = `${openBookData?.bookName}·${openBookData?.wordCount ? (openBookData?.wordCount / 10000).toFixed(0) + "万字·" : ""}${openBookData?.bookStatus === 0 ? '连载' : '完本'}`
         return <>
             {
                 <View className='book_details'>
@@ -59,7 +76,7 @@ class BookDetails extends Component<Props> {
 
                         <BookHead title="简介" ></BookHead>
                         <View className='center'>
-                            <Text>{openBookData?.bookDesc.replace(/\s/ig,'')}</Text>
+                            <Text>{openBookData?.bookDesc.replace(/\s/ig, '')}</Text>
                         </View>
                     </View>
                     <View className='btn'>

+ 2 - 2
src/pages/classify/index.tsx

@@ -20,7 +20,7 @@ interface Props {
 
 const Index = forwardRef((props: Props) => {
     const { bookStore, appInfoStore, classifyStore } = props.store
-    console.log("appInfoStore", appInfoStore)
+    console.log("appInfoStore", appInfoStore.appInfo)
     const { getBookPageList } = useApi(appInfoStore)
     const [pageShow, setPageShow] = useState(false)//防止小程序切换页面组件不会被真实卸载,阻止不必要的操作
     // 获取分类列表
@@ -87,7 +87,7 @@ const Index = forwardRef((props: Props) => {
                     {
                         bookStore?.bookList?.records?.length > 0 ? bookStore?.bookList?.records?.map((item, index) => {
                             return <>
-                                <View key={index} onClick={() => bookStore.setOpenBookData(item)}><BookboxRowBig {...item} /></View>
+                                <View key={index} ><BookboxRowBig {...item} /></View>
                             </>
                         }) :
                             <Empty />

+ 83 - 14
src/pages/index/index.tsx

@@ -1,41 +1,110 @@
-import React, { useEffect, useState } from 'react';
+import React, { useEffect, useMemo, useState } from 'react';
 import { observer, inject } from 'mobx-react';
 import { useDidHide, useDidShow } from '@tarojs/taro';
 //==========components组件引用========================
 import TopNavBar from '@src/components/TopNavBar';
 import ScrollViewHoc from '@src/components/ScrollView';
-import Empty from '@src/components/Empty';
 import { Store } from '@src/app';
+import useApi from '@src/Hook/useApi';
+import BannerBox from '@src/components/PupPetry/BannerBox'
+import { View } from '@tarojs/components';
+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';
 
 
 interface Props {
     store: Store;
 }
-
 const Index: React.FC<Props> = ({ store }) => {
-    const [pageShow,setPageShow]=useState(false)//防止小程序切换页面组件不会被真实卸载,阻止不必要的操作
+    const { appInfoStore, bookStore, indexStore } = store
+    const { indexComponents } = useApi(appInfoStore)
+    const [pageShow, setPageShow] = useState(false)//防止小程序切换页面组件不会被真实卸载,阻止不必要的操作
+    // 首页配置信息
+    const indexConfig = useMemo(() => {
+        let obj = {}
+        appInfoStore.appComponent?.forEach((item, index) => {
+            return obj[item.componentType] = { ...item, eq: index }
+        })
+        return obj
+    }, [indexComponents])
+    // 页面显示请求数据
+    useEffect(() => {
+        if (pageShow && appInfoStore.token) {
+            indexCompontent()
+        }
+    }, [pageShow, appInfoStore.token, , bookStore.workDirection, appInfoStore.appComponent]); // Dependency array, runs effect only once on mount and unmount
+    // 分类改变重新请求分类列表
     useEffect(() => {
-        log("store.appInfoStore.appInfo", store.appInfoStore.appInfo);
-        log("APP", app);
-        return () => {
-            log("componentWillUnmount");
-        };
-    }, [store.appInfoStore.appInfo,pageShow]); // Dependency array, runs effect only once on mount and unmount
+        getHotBooks(indexStore.indexCategoryId)
+    }, [indexStore.indexCategoryId])
 
     // 使用 useDidShow 代替 onShow
     useDidShow(() => {
+        // 分享消息配置
         setPageShow(true)
-        log("Page is shown or brought to foreground");
+        // log("Page is shown or brought to foreground");
     });
-
     // 使用 useDidHide 如果需要在页面隐藏时做一些处理
     useDidHide(() => {
         setPageShow(false)
-        log("Page is hidden or sent to background");
+        // log("Page is hidden or sent to background");
     });
+    // 处理首页展示的组件的请求
+    const indexCompontent = () => {
+        // 小程序的组件配置
+        Object.keys(indexConfig)?.forEach(key => {
+            switch (key) {
+                case "banners"://轮播
+                    getBanners()
+                    break;
+                case "hot_category"://热门分类
+                    getHotCategory()
+                    break;
+            }
+        })
+    }
+    // 获取banners
+    const getBanners = () => {
+        indexComponents?.banners(bookStore.workDirection)
+    }
+    // 获取热门分类
+    const getHotCategory = () => {
+        indexComponents?.hot_category(bookStore.workDirection).then((res: any) => {
+            let data = res?.data?.data
+            if (data?.length > 0) {
+                getHotBooks(data[0].id)
+            }
+            console.log("data====>", data)
+        })
+    }
+    // 热门分类书籍
+    const getHotBooks = (categoryId) => {
+        if (categoryId) {
+            indexComponents?.hot_books(bookStore.workDirection, categoryId)
+        }
+    }
     return (
         <ScrollViewHoc>
-            <Empty />
+            <View style={{ display: "flex", flexFlow: 'column' }}>
+                {/* 轮播 */}
+                {indexConfig['banners'] && <View style={{ order: indexConfig['banners'].eq }}>
+                    <BannerBox data={indexStore?.indexBanners || []} />
+                </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) => {
+                                return <View key={index}><BookboxColumnSmall {...item} /></View>
+                            })
+                        }
+                    </View>
+                </View>}
+            </View>
         </ScrollViewHoc>
     );
 };

+ 1 - 1
src/pages/my/index.less

@@ -166,8 +166,8 @@ page{
 		}
 	}
 	.list_bt{
-		margin: 0 30px 30px;
 		background-color: #FFFFFF;
+		margin-top: 20px;
 		border-radius: 20px;
 		padding: 36px 30px;
 		box-sizing: border-box;

+ 24 - 24
src/pages/my/index.tsx

@@ -181,9 +181,8 @@ class My extends Component {
                                     <Image mode="widthFix" lazy-load src={indexStore.userInfo?.avatar_url ? indexStore.userInfo?.avatar_url : require('../../icon/avatar.jpg')} />
                                 </View>
                                 <View className="name" style={indexStore.userInfo?.is_auth === 0 ? { width: Taro.pxTransform(120) } : {}}>
-
                                     {
-                                        indexStore.openType !== 1 ? <View className="ID">{indexStore.userInfo?.user_name || ""}</View> :
+                                        indexStore.openType === 1 ? <View className="ID">{indexStore.userInfo?.user_name || ""}</View> :
                                             <View className="ID">读友_sdajhsd</View>
                                     }
                                     {
@@ -225,32 +224,33 @@ class My extends Component {
                             </View>
                             <Image lazy-load src={require('../../icon/vipBack.png')} />
                         </View>
+                        {/* 底部功能入口 */}
+                        <View className="list_bt" style={indexStore.openType === 1 ? { marginTop: Taro.pxTransform(100) } : {}}>
+                            <Navigator className="item" url="/pages/contactus/index">
+                                <View className="left">
+                                    <Image lazy-load src={require('../../icon/phone.png')} mode="widthFix" />
+                                    <Text>联系客服</Text>
+                                </View>
+                                <View className="right">
+                                    <Image lazy-load src={require('../../icon/jtRight.png')} mode="widthFix" />
+                                </View>
+                            </Navigator>
+                            <View className="line"></View>
+                            <Navigator className="item" url="/pages/aboutWe/index">
+                                <View className="left">
+                                    <Image lazy-load src={require('../../icon/we.png')} mode="widthFix" />
+                                    <Text>关于我们</Text>
+                                </View>
+                                <View className="right">
+                                    <Image lazy-load src={require('../../icon/jtRight.png')} mode="widthFix" />
+                                </View>
+                            </Navigator>
+                        </View>
                     </View>
                 </View>
 
 
-                {/* 底部功能入口 */}
-                <View className="list_bt" style={indexStore.openType === 1 ? { marginTop: Taro.pxTransform(100) } : {}}>
-                    <Navigator className="item" url="/pages/contactus/index">
-                        <View className="left">
-                            <Image lazy-load src={require('../../icon/phone.png')} mode="widthFix" />
-                            <Text>联系客服</Text>
-                        </View>
-                        <View className="right">
-                            <Image lazy-load src={require('../../icon/jtRight.png')} mode="widthFix" />
-                        </View>
-                    </Navigator>
-                    <View className="line"></View>
-                    <Navigator className="item" url="/pages/aboutWe/index">
-                        <View className="left">
-                            <Image lazy-load src={require('../../icon/we.png')} mode="widthFix" />
-                            <Text>关于我们</Text>
-                        </View>
-                        <View className="right">
-                            <Image lazy-load src={require('../../icon/jtRight.png')} mode="widthFix" />
-                        </View>
-                    </Navigator>
-                </View>
+
             </View>
         )
     }

+ 19 - 1
src/server/book/short/index.tsx

@@ -45,7 +45,25 @@ export function getParagraphList(data: ParagraphListParmas) {
             method: 'GET',
             data: { ...data, backContent: true, bookId: bookStore.openBookData?.bookId },
             success: (res) => {
-                bookStore.setData({ openBookData: {...bookStore.openBookData,contentData:res.data.data} })
+                bookStore.setData({ openBookData: { ...bookStore.openBookData, contentData: res.data.data } })
+                resolve(res)
+            },
+            fail: (err) => {
+                reject(err);
+            }
+        })
+    })
+}
+/**
+ * 短篇小说详情
+ * */
+export function getShortBookInfo(bookId: any) {
+    return new Promise(async (resolve, reject) => {
+        Taro.request({
+            url: `/app/shortBookInfo/getInfo/${bookId}`,
+            method: 'GET',
+            success: (res) => {
+                bookStore.setData({ openBookData: res.data.data })
                 resolve(res)
             },
             fail: (err) => {

+ 0 - 3
src/server/index.ts

@@ -2,7 +2,6 @@ import { wxlogin, wxloginInit } from './wx/login'
 import { dylogin, dyloginInit } from './dy/login'
 import { getAppComponent } from './index/index'
 import { getBookCategoryList } from './classify'
-import { getShortBookInfoAppListOfPage } from './book/short'
 const isWechat = process.env.TARO_ENV === 'weapp'
 //统一导出接口,用于判断打包时的环境,使用不同的接口
 const apiObj = {
@@ -14,7 +13,5 @@ const apiObj = {
     getAppComponent,
     /**小说分类列表*/
     getBookCategoryList,
-    /**获取小说列表*/
-    getBookPageList:getShortBookInfoAppListOfPage, 
 }
 export default apiObj

+ 73 - 19
src/server/index/index.ts

@@ -1,5 +1,5 @@
 import Taro from "@tarojs/taro";
-import appInfoStore from "@src/store/appInfo";
+import indexStore from "@src/store/index";
 /**
  * 获取小程序组件配置列表
  * */
@@ -11,7 +11,6 @@ export function getAppComponent() {
                 url: '/app/appComponent/list',
                 method: 'GET',
                 success: (res) => {
-                    appInfoStore.setAppComponent(res.data.data)
                     resolve(res)
                 },
                 fail: (err) => {
@@ -26,20 +25,75 @@ export function getAppComponent() {
 
 
 
-// /**
-//  * 获取短篇首页banners列表
-//  * */
-// function getBanners() {
-//     return new Promise(async (resolve, reject) => {
-//         try {
-//             // 初始化
-//             Taro.request<ResData>({
-//                 url: '/app/appComponent/getShortBookBanners',
-//                 method: 'GET',
-//                 data: { wechatAppId: appId || app.appId },
-//             })
-//         } catch (error) {
-//             reject(error);
-//         }
-//     })
-// }
+/**
+ * 获取短篇首页banners列表
+ * */
+export function getShortBanners(workDirection) {
+    return new Promise(async (resolve, reject) => {
+        try {
+            // 初始化
+            Taro.request({
+                url: '/app/appComponent/getShortBookBanners',
+                method: 'GET',
+                data: { workDirection },
+                success: (res) => {
+                    indexStore.setData({ indexBanners: res.data.data })
+                    resolve(res)
+                },
+                fail: (err) => {
+                    reject(err);
+                }
+            })
+        } catch (error) {
+            reject(error);
+        }
+    })
+}
+/**
+ * 获取短篇首页热门分类列表
+ * */
+export function getShortHotCategory(workDirection) {
+    return new Promise(async (resolve, reject) => {
+        try {
+            // 初始化
+            Taro.request({
+                url: '/app/appComponent/getHotCategory',
+                method: 'GET',
+                data: { workDirection },
+                success: (res) => {
+                    indexStore.setData({ indexHotCategory: res.data.data })
+                    resolve(res)
+                },
+                fail: (err) => {
+                    reject(err);
+                }
+            })
+        } catch (error) {
+            reject(error);
+        }
+    })
+}
+/**
+ * 获取短篇首页热门书籍列表
+ * */
+export function getShortHotBooks(workDirection, categoryId) {
+    return new Promise(async (resolve, reject) => {
+        try {
+            // 初始化
+            Taro.request({
+                url: '/app/appComponent/getShortBookHotBooks',
+                method: 'GET',
+                data: { workDirection, categoryId },
+                success: (res) => {
+                    indexStore.setData({ indexHotBooks: res.data.data })
+                    resolve(res)
+                },
+                fail: (err) => {
+                    reject(err);
+                }
+            })
+        } catch (error) {
+            reject(error);
+        }
+    })
+}

+ 1 - 2
src/server/wx/login.ts

@@ -1,6 +1,5 @@
 import { setApp } from "@src/config";
 import { ResData } from "@src/interceptor"
-import appInfoStore from "@src/store/appInfo";
 import Taro from "@tarojs/taro"
 
 /**
@@ -41,7 +40,6 @@ export function wxlogin() {
             });
             if (response.code === 200) {
               setApp({token:response.data.token})//存放token
-              appInfoStore.actionToken(response.data.token )
               resolve(response.data)
             }
           } else {
@@ -55,5 +53,6 @@ export function wxlogin() {
     })
   } else {
     log("已登录")
+    return Promise.resolve({token:app.token})
   }
 }

+ 13 - 4
src/store/appInfo.tsx

@@ -3,7 +3,7 @@ import { observable } from 'mobx'
 
 type ConfigParamList = {}
 export interface AppInfo {
-    appCategory: 1|2,//1长篇 2短篇
+    appCategory: 1 | 2,//1长篇 2短篇
     appName: string,//小程序名称
     appVersion: string,//小程序版本
     configParamList: ConfigParamList[],//小程序配置
@@ -26,14 +26,15 @@ export interface AppInfoStore {
     token?: string,//token
     /**进入的场景*/
     scene?: number,
-    /**分享值*/ 
-    shareSources?:any,
+    /**分享值*/
+    shareSources?: any,
     /**设置app初始化信息*/
     actionAppInfo: (appInfo: AppInfo) => void
     /**设置登录后的token*/
     actionToken: (token: string) => void
     /**设置组件列表*/
     setAppComponent: (appComponent: AppComponent[]) => void
+    setData: (data: { [key: string]: any }) => void,
 }
 /**
  * APP初始化信息
@@ -46,13 +47,21 @@ const appInfoStore: AppInfoStore = observable({
         }
     },
     actionToken(token: string) {
+        console.log("设置token",token)
         this.token = token
     },
     setAppComponent(appComponent: AppComponent[]) {
         if (appComponent) {
             this.appComponent = appComponent
         }
-    }
+    },
+    setData(data: { [key: string]: any }) {
+        if (data) {
+            Object.keys(data).forEach(key => {
+                this[key] = data[key]
+            })
+        }
+    },
 })
 
 export default appInfoStore

+ 0 - 1
src/store/book.ts

@@ -63,7 +63,6 @@ const Book: BookStore = observable({
     setData(data: { [key: string]: any }) {
         if (data) {
             Object.keys(data).forEach(key => {
-                console.log(key)
                 this[key] = data[key]
             })
         }

+ 19 - 4
src/store/index.ts

@@ -1,16 +1,31 @@
 import { observable } from 'mobx'
 
 let interval: NodeJS.Timeout | undefined = undefined
+export interface IndexStore {
+    scene: number,    // 场景值
+    system: string,  // 系统
+    navBarTop: number,//状态栏高度
+    navHeight: number,//导航栏高度
+    query: any,//本次进入小程序参数
+    indexBanners: any[],//首页banner数据
+    indexHotBooks: any[],//首页热门数据
+    indexHotCategory: any[],//首页热门分类
+    indexCategoryId:number,//首页分类选中的id
+    setData: (data: { [key: string]: any }) => void,
+}
 const Index = observable({
     scene: 0,    // 场景值
     system: '',  // 系统
-    navBarTop:0,//状态栏高度
-    navHeight:0,//导航栏高度
-    query:null,//本次进入小程序参数
+    navBarTop: 0,//状态栏高度
+    navHeight: 0,//导航栏高度
+    query: null,//本次进入小程序参数
+    indexBanners: [],//首页banner数据
+    indexHotBooks: [],//首页热门数据
+    indexHotCategory: [],//首页热门分类
+    indexCategoryId:0,
     setData(data: { [key: string]: any }) {
         if (data) {
             Object.keys(data).forEach(key => {
-                console.log(key)
                 this[key] = data[key]
             })
         }