shenwu 5 kuukautta sitten
vanhempi
commit
0f2f2e6156

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

@@ -18,7 +18,7 @@ function BookboxRowBig(props: BookboxRowBigProps) {
     const { bookName, picUrl, bookDesc, labelInfoList, authorName, bookId, wordCount, bookStatus,vipFree } = props
     let describe = ""
     if(wordCount && bookStatus) {
-        describe = `${bookName}·${(wordCount/10000).toFixed(0)}万字·${bookStatus === 0 ? '连载' : '完本'}`
+        describe = `${authorName}·${(wordCount/10000).toFixed(0)}万字·${bookStatus === 0 ? '连载' : '完本'}`
     }
     const click = () => {
         // BookStore.setData({ openBookData: props })

+ 0 - 3
src/components/PupPetry/BookTypeTabs/index.tsx

@@ -30,9 +30,6 @@ const BookTypeTabs = (props: props) => {
     let openHandle = useCallback(() => {
         onCallback?.(!open)
     }, [open])
-
-    useEffect(() => {
-    }, [])
     return <>
         <View className="BookTypeTabs">
             {

+ 1 - 0
src/components/ScrollView/index.tsx

@@ -96,6 +96,7 @@ class ScrollViewHoc extends Component<Props, State> {
   }
 
   calculateFilterHeight = () => {
+    console.log("calculateFilterHeight")
     let { filterClassName, navHeight = 0 } = this.props;
     if (filterClassName) {
       Taro.createSelectorQuery()

+ 21 - 1
src/pages/book/BookArticle/index.tsx

@@ -5,7 +5,7 @@ import { View, Text, ScrollView } from '@tarojs/components';
 import { observer, inject } from 'mobx-react';
 import './index.less';
 import TopNavBar from '@src/components/TopNavBar/index';
-import Taro from '@tarojs/taro';
+import Taro, { useShareAppMessage } from '@tarojs/taro';
 import BookConfigPuP from '@src/components/bookConfigPup';
 import { BookStore } from '@src/store/book';
 import useApi from '@src/Hook/useApi';
@@ -14,6 +14,7 @@ import GlobalModal from '@src/components/bottomModal';
 import IosShowPay from '@src/components/pay/IosShowPay';
 import { Store } from '@src/app';
 import { cashBuy, virtualBuy } from '@src/server/wx/pay';
+import { share } from '@src/utils';
 
 interface Config {
     size: 'pre_15' | 'pre_17' | 'pre_19' | 'pre_21' | 'pre_23' | 'pre_25' | 'pre_27' | 'pre_29' | any;
@@ -280,6 +281,25 @@ const BookArticle: React.FC<BookArticleProps> = ({ store }) => {
 
     }
     const { size, bg, off_on, lh } = bookConfig;
+    // 分享
+    useShareAppMessage(async () => {
+        // 获取当前页面栈
+        const pages = Taro.getCurrentPages()
+        // 获取栈顶的页面,即当前页面
+        const currentPage = pages[pages.length - 1]
+        // 获取页面的路径和参数
+        const route = currentPage.route // 页面路径
+        if (route) {
+            let shareInfo = await share({ pagePath: route, bookId: openBookData?.bookId })
+            let { sharePicUrl, shareTitles, pageName, pagePath } = shareInfo
+            return {
+                title: shareTitles || app.appInfo?.appName + '-' + pageName,
+                path: pagePath || undefined,
+                imageUrl: sharePicUrl || undefined
+            }
+        }
+        return {}
+    })
     return (
         <ScrollView
             lowerThreshold={indexStore.navHeight}

+ 20 - 2
src/pages/book/bookDetails/index.tsx

@@ -6,6 +6,7 @@ import BookHead from '@src/components/PupPetry/BookHead'
 import { Store } from '@src/app'
 import Taro from '@tarojs/taro'
 import useApi from '@src/Hook/useApi'
+import { share } from '@src/utils'
 /**书详情 */
 
 type state = {
@@ -41,7 +42,24 @@ class BookDetails extends Component<Props> {
             log(params?.bookId)
         }
     }
-
+    async onShareAppMessage() {
+        // 获取当前页面栈
+        const pages = Taro.getCurrentPages()
+        // 获取栈顶的页面,即当前页面
+        const currentPage = pages[pages.length - 1]
+        // 获取页面的路径和参数
+        const route = currentPage.route // 页面路径
+        if (route) {
+            let shareInfo = await share({ pagePath: route, bookId: this.props?.store?.bookStore?.openBookData?.bookId })
+            let { sharePicUrl, shareTitles, pageName, pagePath } = shareInfo
+            return {
+                title: shareTitles || app.appInfo?.appName + '-' + pageName,
+                path: pagePath || undefined,
+                imageUrl: sharePicUrl || undefined
+            }
+        }
+        return {}
+    }
     render() {
         let { bookStore } = this.props.store
         let { openBookData } = bookStore
@@ -69,7 +87,7 @@ class BookDetails extends Component<Props> {
                                     </View>
                                 </View>
                                 <View className='right'>
-                                    <Image src={openBookData?.picUrl || ""} className={`img ${openBookData?.vipFree ? "isVip" :""}`} />
+                                    <Image src={openBookData?.picUrl || ""} className={`img ${openBookData?.vipFree ? "isVip" : ""}`} />
                                 </View>
                             </View>
                         </View>

+ 191 - 0
src/pages/classify/index copy.tsx

@@ -0,0 +1,191 @@
+import { forwardRef, useEffect, useRef, useState } from 'react'
+import Taro, { useShareAppMessage } from '@tarojs/taro'
+import { useDidHide, useDidShow } from '@tarojs/taro'
+import { observer, inject } from 'mobx-react'
+import { ScrollView, View } from '@tarojs/components'
+import './index.less'
+//==========components组件引用========================
+import TopNavBar from '@src/components/TopNavBar/index'
+import BookboxRowBig from '@src/components/PupPetry/BookBox/BookboxRowBig'
+import BookTypeTabs from '@src/components/PupPetry/BookTypeTabs'
+import Empty from '@src/components/Empty'
+import { Store } from '@src/app'
+import useApi from '@src/Hook/useApi'
+import { getBookCategoryList } from '@src/server/classify'
+import { share } from '@src/utils'
+
+
+interface Props {
+    store: Store;
+}
+
+const Index = forwardRef((props: Props) => {
+    const { classifyStore, indexStore } = props.store
+    const { getBookPageList } = useApi()
+    const [pageShow, setPageShow] = useState(false)//防止小程序切换页面组件不会被真实卸载,阻止不必要的操作
+    const [open, setOpen] = useState(false)
+    const [showEmpty, setShowEmpty] = useState(false)
+    const [isSetOpen, setIsSetOpen] = useState(true)
+    const [filterHeight, setFilterHeight] = useState(0)
+    // 获取分类列表
+    useEffect(() => {
+        if (pageShow) {
+            console.log("获取分类列表")
+            let { workDirection } = classifyStore
+            getBookCategoryList(workDirection).then((res: any) => {
+                if (res?.data?.code === 200) {
+                    classifyStore.setData({ classifyData: res?.data?.data })
+                }
+            })
+        }
+    }, [classifyStore.workDirection, pageShow]); // Dependency array, runs effect only once on mount and unmount
+    //获取书籍列表
+    useEffect(() => {
+        if (pageShow) {
+            console.log("获取书籍列表")
+            let { workDirection } = classifyStore
+            let { categoryId } = classifyStore
+            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) {
+                    setShowEmpty(true)
+                } else {
+                    setShowEmpty(false)
+                }
+            })
+        }
+    }, [classifyStore.workDirection, classifyStore.categoryId, pageShow])
+    // 使用 useDidShow 代替 onShow
+    useDidShow(() => {
+        setPageShow(true)
+    });
+    // 使用 useDidHide 如果需要在页面隐藏时做一些处理
+    useDidHide(() => {
+        setPageShow(false)
+    });
+
+    //下拉加载
+    const load = () => {
+        return new Promise((resolve, reject) => {
+            let { size, total, records } = classifyStore.bookList
+            let pageSize = size + 10
+            let { workDirection } = classifyStore
+            let { categoryId } = classifyStore
+            if (records?.length >= total) {
+                Taro.showToast({
+                    title: '没有更多了~~',
+                    duration: 2000,
+                    icon: 'none'
+                })
+                reject()
+                return
+            } else {
+                getList({ workDirection, categoryId: categoryId.id, pageNum: 1, pageSize, type: 'class' }).then((res: any) => {
+                    if (res?.data?.data?.total === 0) {
+                        setShowEmpty(true)
+                    } else {
+                        console.log("isSetOpen", isSetOpen)
+                        setShowEmpty(false)
+                    }
+                    resolve(true)
+                })
+            }
+        })
+    }
+    const getList = async (params) => {
+        return getBookPageList(params)
+    }
+    // 分享
+    useShareAppMessage(async () => {
+        // 获取当前页面栈
+        const pages = Taro.getCurrentPages()
+        // 获取栈顶的页面,即当前页面
+        const currentPage = pages[pages.length - 1]
+        // 获取页面的路径和参数
+        const route = currentPage.route // 页面路径
+        if (route) {
+            let shareInfo = await share({ pagePath: route })
+            let { sharePicUrl, shareTitles, pageName, pagePath } = shareInfo
+            return {
+                title: shareTitles || app.appInfo?.appName + '-' + pageName,
+                path: pagePath || undefined,
+                imageUrl: sharePicUrl || undefined
+            }
+        }
+        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 (
+        <View className='index'>
+            {classifyStore?.classifyData?.length > 0 && <View style={{ background: "#fff" }} className='classList' onClick={() => { setIsSetOpen(false) }}>
+                <BookTypeTabs open={open} onCallback={callBacn} typeValue={classifyStore?.classifyData} typeTabIndex={classifyStore.categoryId} workDirection={classifyStore.workDirection} ></BookTypeTabs>
+            </View>}
+            <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) => {
+                        console.log(evt)
+                        let top = evt.detail.scrollTop
+                        if (isSetOpen) {
+                            if (top > 100 && open) {
+                                callBacn(false)
+                            }
+                            if (top < 100 && !open) {
+                                callBacn(true)
+                            }
+                        }
+                    }}
+                    className="scrollview"
+                    scrollY={true}
+                    refresherDefaultStyle="black"
+                // scrollWithAnimation={true}
+                >
+                    <View className='w  row for_top1 pd_btm'>
+                        {
+                            classifyStore?.bookList?.records?.length > 0 && classifyStore?.bookList?.records?.map((item, index) => {
+                                return <>
+                                    <View key={item.bookId} ><BookboxRowBig {...item} /></View>
+                                </>
+                            })
+                        }
+                        {
+                            showEmpty && <Empty />
+                        }
+                    </View>
+                </ScrollView>
+            </View>
+        </View>
+
+    );
+});
+export default TopNavBar(inject('store')(observer(Index)), {
+    tab: true,
+    tabVal: [{ value: 0, text: "男生" }, { value: 1, text: "女生" }],
+    backgroundColor: '#fff',
+    color: "#333",
+    search: false,
+});

+ 62 - 31
src/pages/classify/index.tsx

@@ -2,11 +2,10 @@ import { forwardRef, useEffect, useRef, useState } from 'react'
 import Taro, { useShareAppMessage } from '@tarojs/taro'
 import { useDidHide, useDidShow } from '@tarojs/taro'
 import { observer, inject } from 'mobx-react'
-import { View } from '@tarojs/components'
+import { ScrollView, View } from '@tarojs/components'
 import './index.less'
 //==========components组件引用========================
 import TopNavBar from '@src/components/TopNavBar/index'
-import ScrollViewHoc from '@src/components/ScrollView'
 import BookboxRowBig from '@src/components/PupPetry/BookBox/BookboxRowBig'
 import BookTypeTabs from '@src/components/PupPetry/BookTypeTabs'
 import Empty from '@src/components/Empty'
@@ -27,9 +26,12 @@ const Index = forwardRef((props: Props) => {
     const [open, setOpen] = useState(false)
     const [showEmpty, setShowEmpty] = useState(false)
     const [isSetOpen, setIsSetOpen] = useState(true)
+    const [filterHeight, setFilterHeight] = useState(0)
+    const timeRef = useRef<any>()
     // 获取分类列表
     useEffect(() => {
         if (pageShow) {
+            console.log("获取分类列表")
             let { workDirection } = classifyStore
             getBookCategoryList(workDirection).then((res: any) => {
                 if (res?.data?.code === 200) {
@@ -41,12 +43,13 @@ const Index = forwardRef((props: Props) => {
     //获取书籍列表
     useEffect(() => {
         if (pageShow) {
+            console.log("获取书籍列表")
             let { workDirection } = classifyStore
             let { categoryId } = classifyStore
             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) {
                     setShowEmpty(true)
-                }else{
+                } else {
                     setShowEmpty(false)
                 }
             })
@@ -58,20 +61,8 @@ const Index = forwardRef((props: Props) => {
     });
     // 使用 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 = () => {
         return new Promise((resolve, reject) => {
@@ -88,10 +79,11 @@ const Index = forwardRef((props: Props) => {
                 reject()
                 return
             } 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) {
                         setShowEmpty(true)
-                    }else{
+                    } else {
+                        console.log("isSetOpen", isSetOpen)
                         setShowEmpty(false)
                     }
                     resolve(true)
@@ -121,23 +113,62 @@ const Index = forwardRef((props: Props) => {
         }
         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 (
         <View className='index'>
             {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 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'>
                         {
                             classifyStore?.bookList?.records?.length > 0 && classifyStore?.bookList?.records?.map((item, index) => {
@@ -150,7 +181,7 @@ const Index = forwardRef((props: Props) => {
                             showEmpty && <Empty />
                         }
                     </View>
-                </ScrollViewHoc>
+                </ScrollView>
             </View>
         </View>
 

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

@@ -17,8 +17,6 @@ import BookboxColumnBig from '@src/components/PupPetry/BookBox/BookboxColumnBig'
 import { share } from '@src/utils';
 import BookboxRowBig from '@src/components/PupPetry/BookBox/BookboxRowBig';
 
-
-
 interface Props {
     store: Store;
 }
@@ -186,6 +184,14 @@ const Index: React.FC<Props> = ({ store }) => {
         }
         return {}
     })
+
+    const startMessage = () => {
+        console.log('开始');
+    };
+
+    const completeMessage = () => {
+        console.log('完成');
+    };
     console.log("bookStore?.bookList", bookStore?.bookList?.total)
     return <ScrollViewHoc load={load} filterClassName='.searchTs' navHeight={indexStore.navHeight}>
         <TopNavBar1 {...{

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

@@ -275,15 +275,16 @@ export function enumDictList() {
 /**
  * 分享信息获取
  * @param path 路径
+ * @param bookId 书籍ID
 */
-export function getShareInfo(pagePath:string) {
+export function getShareInfo(data) {
     return new Promise(async (resolve, reject) => {
         try {
             // 初始化
             Taro.request({
                 url: '/app/appPage/getShareInfo',
                 method: 'GET',
-                data:{pagePath},
+                data,
                 success: (res) => {
                     resolve(res)
                 },

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

@@ -36,7 +36,7 @@ export function wxlogin() {
             let response: any = await Taro.request<ResData>({
               url: '/app/wechatMiniappUser/jsCodeLogin',
               method: 'POST',
-              data: { jsCode: res.code, params: app.pathParams },
+              data: { jsCode: res.code, params: {...app.pathParams,system:app.system} },
             });
             if (response.code === 200) {
               setApp({ token: response.data.token, userInfo: response.data.userInfo ,tokenValid:true})//存放token

+ 2 - 2
src/utils/index.tsx

@@ -11,6 +11,7 @@ export const getEnum = (enumName: string) => {
 
 interface ShareProps {
     pagePath: string,//分享路径
+    bookId?:any
 }
 /**
  * 分享
@@ -18,7 +19,6 @@ interface ShareProps {
  * @param props.pagePath 分享路径
  * */
 export async function share(props: ShareProps) {
-    let { pagePath } = props
-    let shareInfo: any = await getShareInfo(pagePath)
+    let shareInfo: any = await getShareInfo(props)
     return shareInfo?.data?.data
 }