shenwu 2 месяцев назад
Родитель
Сommit
6e4fc086f6

+ 62 - 39
src/app.tsx

@@ -18,6 +18,7 @@ import { getShortBookInfo } from './server/book/short'
 import { getUserInfo } from './server/wx/login'
 // 引入兼容性工具
 import { getAccountInfoSync } from './utils/compatibility'
+import { bookrackShrotAddOrRemove } from './server/bookrack'
 //引入官方小说阅读插件
 const novelPlugin = Taro.requirePlugin('novel-plugin')
 
@@ -44,58 +45,80 @@ class App extends Component {
 
   //每次打开小程序触发,后台切入不算
   onLaunch(options) {
- // 监听进入插件页事件
+    // 监听进入插件页事件
     novelPlugin.onPageLoad(this.onNovelPluginLoad)
   }
   onNovelPluginLoad(data) {
     console.log('onNovelPluginLoad', data)
-  // data.id - 阅读器实例 id,每个插件页对应一个阅读器实例
-  const novelManager = novelPlugin.getNovelManager(data.id)
-  
-  // getId() 返回当前阅读器实例 id
-  console.log('id:', novelManager.getId())
-
-  // 设置目录状态
-  novelManager.setContents({
-    contents: [
-      {
-        index: 0, // 第一章
-        status: 0, // 免费
-      },
-      {
-        index: 1, // 第二章
-        status: 2, // 未解锁
-      },
-      {
-        index: 2, // 第三章
-        status: 1, // 已解锁
-      },
-    ],
-  })
-
-  // 监听用户行为事件
-  novelManager.onUserTriggerEvent(res => {
-    console.log('onUserTriggerEvent', res.event_id, res)
-  })
-}
+    // data.id - 阅读器实例 id,每个插件页对应一个阅读器实例
+    const novelManager = novelPlugin.getNovelManager(data.id)
+    //获取自定义参数
+    let customParams = novelManager.getCustomServerParams();
+    if (customParams) {
+      try {
+        customParams = JSON.parse(decodeURIComponent(customParams));
+      } catch (e) {
+        console.error('解析失败', e);
+      }
+    }
+    //假如书籍已在书架改变插件书架状态
+    if(customParams && customParams.inBookshelf){
+      novelManager.setBookshelfStatus({
+        bookshelfStatus:1
+      })
+    }
+    // 默认设置目录状态
+    novelManager.setContents({
+      contents: [
+        {
+          index: 0, // 第一章
+          status: 0, // 免费
+        },
+        {
+          index: 1, // 第二章
+          status: 0, // 未解锁
+        },
+        {
+          index: 2, // 第三章
+          status: 0, // 已解锁
+        },
+      ],
+    })
+    // 监听用户行为事件
+    novelManager.onUserTriggerEvent(res => {
+    
+    })
+    novelManager.onClickBookshelf((res) => {
+      if(res.bookshelfStatus == 0){
+        console.log("点击了加入书架")
+        bookrackShrotAddOrRemove({ bookId: customParams.bookId, add: true })
+      }else if(res.bookshelfStatus == 1){
+        console.log("点击了移出书架")
+        bookrackShrotAddOrRemove({ bookId: customParams.bookId, add: false })
+      }
+       novelManager.setBookshelfStatus({
+        bookshelfStatus:res.bookshelfStatus == 0 ? 1 : 0
+      })
+    })
+  }
   componentDidMount() {
     console.log("APPcomponentDidMount")
     /**获取状态栏高度 */
     Taro.getSystemInfo({}).then(res => {
-      let { system, statusBarHeight,platform } = res
+      let { system, statusBarHeight, platform } = res
       indexStore.setData({ navBarTop: statusBarHeight, system })//设置navbar高度和当前系统
-      setApp({ system:platform })
+      setApp({ system: platform })
     })
   }
   async componentDidShow(options) {
-    console.log("appcomponentDidShow",options)
-    let { scene, query ,path} = options//获取当前小程序进入的场景值
+    console.log("appcomponentDidShow", options)
+    let { scene, query, path } = options//获取当前小程序进入的场景值
     let bookConfig = Taro.getStorageSync("bookConfig")
     if (bookConfig) {
       Book.setData({ bookConfig: JSON.parse(bookConfig) })
     }
     //阅读页面并且路径存在bookId请求数据
-    if(query?.bookId && path === "pages/book/bookArticle/index"){
+    if (query?.bookId && path === "pages/book/bookArticle/index") {
       getShortBookInfo(query?.bookId)
     }
     indexStore.setData({ scene, query })
@@ -104,11 +127,11 @@ class App extends Component {
     initApp()//初始化全局变量
     let accountInfo = getAccountInfoSync().miniProgram//获取当前小程序的APPID 
     let { appId, version, envVersion } = accountInfo;
-    setApp({ 
-      appId, 
-      proVersion: version, 
+    setApp({
+      appId,
+      proVersion: version,
       envVersion: envVersion as "develop" | "trial" | "release",
-      pathParams:{ scene, ...query } 
+      pathParams: { scene, ...query }
     })
     // 初始化登录,获取登录使用的token存放用于登录使用
     await api.loginInit(appId)

+ 29 - 10
src/components/PupPetry/BookBox/BookboxColumnBig.tsx

@@ -3,6 +3,9 @@
 import { Text, View, Image, Navigator } from "@tarojs/components";
 import React from 'react'
 import './index.less'
+import useApi from "@src/Hook/useApi";
+import Taro from "@tarojs/taro";
+let { getBookInfo } = useApi()
 export interface BookboxColumnBigProps {
     bookId: number,//书ID
     authorName: string,//作者
@@ -15,19 +18,35 @@ export interface BookboxColumnBigProps {
     vipFree: boolean
 }
 function BookboxColumnBig(props: BookboxColumnBigProps) {
+    const { picUrl, bookName, bookId, authorName, vipFree } = props
+   
     const click = () => {
-        // BookStore.setData({ openBookData: props })
+        getBookInfo(bookId).then((res: { data: any, code: any }) => {
+            if (res?.data?.code == 200) {
+                console.log(res?.data?.data)
+                let { wechatBookId,inBookshelf } = res?.data?.data
+                let json = JSON.stringify({inBookshelf,bookId})
+                let encode = encodeURIComponent(json)
+                if (wechatBookId) {
+                    Taro.navigateTo({
+                        url: `plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=${wechatBookId}&customServerParams=${encode}`
+                    })
+                }else{
+                    Taro.showToast({
+                        title: '小说未上架',
+                        icon: 'none'
+                    })
+                }
+            }
+        })
     }
-    const { picUrl, bookName, bookId, authorName, vipFree } = props
     return <View className='book_box_column_big' onClick={click} >
-        <Navigator url={'/pages/book/bookDetails/index?bookId=' + bookId} hoverClass="none" >
-            <Image src={picUrl || ''} className={`img ${vipFree ? "isVip" : ""}`}></Image>
-            <View className='bottom'>
-                <Text className='title'>{bookName}</Text>
-                <Text className='author'>{authorName}</Text>
-            </View>
-        </Navigator>
+        <Image src={picUrl || ''} className={`img ${vipFree ? "isVip" : ""}`}></Image>
+        <View className='bottom'>
+            <Text className='title'>{bookName}</Text>
+            <Text className='author'>{authorName}</Text>
+        </View>
     </View>
-} 
+}
 
 export default React.memo(BookboxColumnBig)

+ 30 - 12
src/components/PupPetry/BookBox/BookboxColumnSmall.tsx

@@ -1,8 +1,11 @@
 /**分类书籍的box容器 横大*/
 
-import { Text, View, Image, Navigator } from "@tarojs/components";
+import { Text, View, Image } from "@tarojs/components";
 import React from 'react'
 import './index.less'
+import useApi from "@src/Hook/useApi";
+import Taro from "@tarojs/taro";
+let { getBookInfo } = useApi()
 export interface BookboxColumnSmallProps {
     bookId: number,//书ID
     authorName: string,//作者
@@ -12,20 +15,35 @@ export interface BookboxColumnSmallProps {
     bookStatus: number,//完本|连载状态
     wordCount: number,//字数
     labelInfoList: { name: string }[],//标签
-    vipFree:boolean
+    vipFree: boolean
 }
 function BookboxColumnSmall(props: BookboxColumnSmallProps) {
-    const { picUrl, bookName, bookId ,vipFree} = props
-    const click = () => {
-        // BookStore.setData({ openBookData: props })
-    }
+    const { picUrl, bookName, bookId, vipFree } = props
+     const click = () => {
+           getBookInfo(bookId).then((res: { data: any, code: any }) => {
+               if (res?.data?.code == 200) {
+                   console.log(res?.data?.data)
+                   let { wechatBookId,inBookshelf } = res?.data?.data
+                   let json = JSON.stringify({inBookshelf,bookId})
+                   let encode = encodeURIComponent(json)
+                   if (wechatBookId) {
+                       Taro.navigateTo({
+                           url: `plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=${wechatBookId}&customServerParams=${encode}`
+                       })
+                   }else{
+                       Taro.showToast({
+                           title: '小说未上架',
+                           icon: 'none'
+                       })
+                   }
+               }
+           })
+       }
     return <View className='book_box_column_small' onClick={click}>
-        <Navigator url={'/pages/book/bookDetails/index?bookId=' + bookId} hoverClass="none">
-            <Image src={picUrl || ''}  className={`img ${vipFree ? "isVip" : ""}`}></Image>
-            <View className='bottom'>
-                <Text className='title'>{bookName}</Text>
-            </View>
-        </Navigator>
+        <Image src={picUrl || ''} className={`img ${vipFree ? "isVip" : ""}`}></Image>
+        <View className='bottom'>
+            <Text className='title'>{bookName}</Text>
+        </View>
     </View>
 }
 

+ 40 - 22
src/components/PupPetry/BookBox/BookboxRowBig.tsx

@@ -3,44 +3,62 @@
 import { Text, View, Image, Navigator } from "@tarojs/components";
 import React from 'react'
 import './index.less'
+import useApi from "@src/Hook/useApi";
+import Taro from "@tarojs/taro";
+let { getBookInfo } = useApi()
 export interface BookboxRowBigProps {
     bookId: number,//书ID
-    authorName:string,//作者
+    authorName: string,//作者
     bookName: string,//书名称
-    bookDesc:string,//描述
+    bookDesc: string,//描述
     picUrl: string,//封面
     bookStatus: number,//完本|连载状态
     wordCount: number,//字数
-    labelInfoList:{name:string}[],//标签
-    vipFree:boolean
+    labelInfoList: { name: string }[],//标签
+    vipFree: boolean
 }
 function BookboxRowBig(props: BookboxRowBigProps) {
-    const { bookName, picUrl, bookDesc, labelInfoList, authorName, bookId, wordCount, bookStatus,vipFree } = props
+    const { bookName, picUrl, bookDesc, labelInfoList, authorName, bookId, wordCount, bookStatus, vipFree } = props
     let describe = ""
-    if(wordCount && bookStatus) {
-        describe = `${authorName}·${(wordCount/10000).toFixed(0)}万字·${bookStatus === 0 ? '连载' : '完本'}`
+    if (wordCount && bookStatus) {
+        describe = `${authorName}·${(wordCount / 10000).toFixed(0)}万字·${bookStatus === 0 ? '连载' : '完本'}`
     }
     const click = () => {
-        // BookStore.setData({ openBookData: props })
+        getBookInfo(bookId).then((res: { data: any, code: any }) => {
+            if (res?.data?.code == 200) {
+                console.log(res?.data?.data)
+                let { wechatBookId, inBookshelf } = res?.data?.data
+                let json = JSON.stringify({ inBookshelf, bookId })
+                let encode = encodeURIComponent(json)
+                if (wechatBookId) {
+                    Taro.navigateTo({
+                        url: `plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=${wechatBookId}&customServerParams=${encode}`
+                    })
+                } else {
+                    Taro.showToast({
+                        title: '小说未上架',
+                        icon: 'none'
+                    })
+                }
+            }
+        })
     }
     return <View className='book_box_row_big' onClick={click}>
-        <Navigator url={'/pages/book/bookDetails/index?bookId=' + bookId} hoverClass="none">
-            <Image src={picUrl || ''}  className={`img ${vipFree ? "isVip" : ""}`}></Image>
-            <View className='right'>
-                <Text className='title'>{bookName}</Text>
-                <View className='content'>
-                    <View className='left'>
-                        <Text className='details'>{bookDesc.replace(/\s/ig,'')}</Text>
-                        <View className='bottom'>
-                            <Text className='describe'>{describe || authorName}</Text>
-                            {
-                                labelInfoList.length > 0 && <Text className='label'>{labelInfoList[0].name}</Text>
-                            }
-                        </View>
+        <Image src={picUrl || ''} className={`img ${vipFree ? "isVip" : ""}`}></Image>
+        <View className='right'>
+            <Text className='title'>{bookName}</Text>
+            <View className='content'>
+                <View className='left'>
+                    <Text className='details'>{bookDesc.replace(/\s/ig, '')}</Text>
+                    <View className='bottom'>
+                        <Text className='describe'>{describe || authorName}</Text>
+                        {
+                            labelInfoList.length > 0 && <Text className='label'>{labelInfoList[0].name}</Text>
+                        }
                     </View>
                 </View>
             </View>
-        </Navigator>
+        </View>
     </View>
 }
 

+ 33 - 14
src/components/PupPetry/BookBox/BookboxRowMiddle.tsx

@@ -1,8 +1,11 @@
 /**分类书籍的box容器 横大*/
 
-import { Text, View, Image, Navigator } from "@tarojs/components";
+import { Text, View, Image } from "@tarojs/components";
 import React from 'react'
 import './index.less'
+import useApi from "@src/Hook/useApi";
+import Taro from "@tarojs/taro";
+let { getBookInfo } = useApi()
 export interface BookboxRowMiddleProps {
     bookId: number,//书ID
     authorName: string,//作者
@@ -17,24 +20,40 @@ export interface BookboxRowMiddleProps {
 function BookboxRowMiddle(props: BookboxRowMiddleProps) {
     const { bookName, picUrl, bookDesc, labelInfoList, authorName, bookId, vipFree, wordCount, bookStatus } = props
     const click = () => {
-        // BookStore.setData({ openBookData: props })
+        getBookInfo(bookId).then((res: { data: any, code: any }) => {
+            if (res?.data?.code == 200) {
+                console.log(res?.data?.data)
+                let { wechatBookId, inBookshelf } = res?.data?.data
+                let json = JSON.stringify({ inBookshelf, bookId })
+                let encode = encodeURIComponent(json)
+                if (wechatBookId) {
+                    Taro.navigateTo({
+                        url: `plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=${wechatBookId}&customServerParams=${encode}`
+                    })
+                } else {
+                    Taro.showToast({
+                        title: '小说未上架',
+                        icon: 'none'
+                    })
+                }
+            }
+        })
     }
+
     return <View className='book_box_row_middle' onClick={click}>
-        <Navigator url={'/pages/book/bookDetails/index?bookId=' + bookId} hoverClass="none">
-            <Image src={picUrl || ''} className={`img ${vipFree ? "isVip" : ""}`}></Image>
-            <View className='right'>
-                <Text className='title'>{bookName}</Text>
-                <View className='content'>
-                    <View className='left'>
-                        <Text className='details'>{bookDesc?.replace(/\s/ig, '')}</Text>
-                        <View className='bottom'>
-                            <Text className='describe'>{authorName}</Text>
-                            <Text className='label'>{labelInfoList?.[0].name}</Text>
-                        </View>
+        <Image src={picUrl || ''} className={`img ${vipFree ? "isVip" : ""}`}></Image>
+        <View className='right'>
+            <Text className='title'>{bookName}</Text>
+            <View className='content'>
+                <View className='left'>
+                    <Text className='details'>{bookDesc?.replace(/\s/ig, '')}</Text>
+                    <View className='bottom'>
+                        <Text className='describe'>{authorName}</Text>
+                        <Text className='label'>{labelInfoList?.[0].name}</Text>
                     </View>
                 </View>
             </View>
-        </Navigator>
+        </View>
     </View>
 }
 

+ 30 - 28
src/components/PupPetry/BookBox/BookboxRowSmall.tsx

@@ -3,8 +3,9 @@
 import { Text, View, Image, Button, Navigator } from "@tarojs/components";
 import React from 'react'
 import './index.less'
-import BookStore from "@src/store/book"
-import { setReadLog } from "@src/utils/loginSto";
+import Taro from "@tarojs/taro";
+import useApi from "@src/Hook/useApi";
+let { getBookInfo } = useApi()
 export interface BookboxRowSmallProps {
     bookInfo: {
         bookId: number,//书ID
@@ -23,35 +24,36 @@ export interface BookboxRowSmallProps {
 function BookboxRowSmall(props: BookboxRowSmallProps) {
     const { lastReadingTime, bookInfo } = props
     const { bookName, picUrl, authorName, bookId, readLogId, vipFree } = bookInfo
-    const click = () => {
-        BookStore.setData({ openBookData: props })
-        if (readLogId) {
-            setReadLog({ [bookId]: readLogId })
-        }
-    }
+  const click = () => {
+          getBookInfo(bookId).then((res: { data: any, code: any }) => {
+              if (res?.data?.code == 200) {
+                  console.log(res?.data?.data)
+                  let { wechatBookId, inBookshelf } = res?.data?.data
+                  let json = JSON.stringify({ inBookshelf, bookId })
+                  let encode = encodeURIComponent(json)
+                  if (wechatBookId) {
+                      Taro.navigateTo({
+                          url: `plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=${wechatBookId}&customServerParams=${encode}`
+                      })
+                  } else {
+                      Taro.showToast({
+                          title: '小说未上架',
+                          icon: 'none'
+                      })
+                  }
+              }
+          })
+      }
     return <View className='book_box_row_small' onClick={click} style={{ margin: 0 }}>
-        <Navigator url={`/pages/book/bookArticle/index?bookId=${bookId}`} hoverClass="none">
-            <Image src={picUrl} className={`img ${vipFree ? "isVip" : ""}`}></Image>
-            <View className='right'>
-                <Text className='title'>{bookName}</Text>
-                <View className='content'>
-                    <View className='left'>
-                        <Text className='author'>{authorName}</Text>
-                        <View className='bottom'>
-                            {
-                                true ? <>
-                                    <Text className='time'>{lastReadingTime}</Text>
-                                    {/* <Text className='section'>{chapter_name}</Text> */}
-                                </>
-                                    :
-                                    <Text className='null'>未读</Text>
-                            }
-                        </View>
-                    </View>
-                    <Button className='btn' plain={true}>继续阅读</Button>
+        <Image src={picUrl} className={`img ${vipFree ? "isVip" : ""}`}></Image>
+        <View className='right'>
+            <Text className='title'>{bookName}</Text>
+            <View className='content'>
+                <View className='left'>
+                    <Text className='author'>{authorName}</Text>
                 </View>
             </View>
-        </Navigator>
+        </View>
     </View>
 }
 export default React.memo(BookboxRowSmall)

+ 1 - 1
src/pages/book/bookDetails/index.tsx

@@ -89,7 +89,7 @@ class BookDetails extends Component<Props> {
                     </View>
                     <View className='btn' >
                         {/* <Navigator url={`/pages/book/bookArticle/index?bookId=${openBookData?.bookId}`} hoverClass="none"> */}
-                        <Navigator url={`plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=${openBookData?.bookId}`} hoverClass="none">
+                        <Navigator url={`plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=A1HcfuuvKqNdTuMD9dMmQDxTuJ`} hoverClass="none">
                             {/* <Image src={require('../../../icon/btn.png')} className='img' /> */}
                             <View className='vip_btn' >开始阅读</View>
                         </Navigator>

+ 2 - 4
src/pages/bookrack/index.tsx

@@ -100,7 +100,7 @@ const Index: React.FC<Props> = ({ store }) => {
         // 获取页面的路径和参数
         const route = currentPage.route // 页面路径
         if (route) {
-            let shareInfo = await share({ pagePath: route })
+            let shareInfo:any = await share({ pagePath: route })
             let { sharePicUrl, shareTitles, pageName, pagePath } = shareInfo
             return {
                 title: shareTitles || app.appInfo?.appName + '-' + pageName,
@@ -120,9 +120,7 @@ const Index: React.FC<Props> = ({ store }) => {
                 {
                     readData?.records?.length > 0 && readData?.records?.map((item: any, index: number) => {
                         return <View key={item.bookId} style={{ margin: '30rpx' }}>
-                            <SwipeAction actions={actions(item.bookId)}>
-                                <BookboxRowSmall {...item} />
-                            </SwipeAction>
+                              <BookboxRowSmall {...item} />
                         </View>
                     })
                 }

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

@@ -23,3 +23,28 @@ export function bookrackShrot(data) {
         }
     })
 }
+
+/**
+ * 加入或移出书架
+ * */ 
+export function bookrackShrotAddOrRemove(data) {
+    return new Promise(async (resolve, reject) => {
+        try {
+            // 添加或移出书架
+            let {bookId,add} = data
+            Taro.request({
+                url: `/app/shortBookshelf/addOrRemove/${bookId}/${add}`,
+                method: 'PATCH',
+                data,
+                success: (res) => {
+                    resolve(res)
+                },
+                fail: (err) => {
+                    reject(err);
+                }
+            })
+        }catch (error) {
+            reject(error);
+        }
+    })
+}

+ 1 - 0
src/server/dy/login.ts

@@ -31,6 +31,7 @@ export function dylogin() {
       //获取code
       Taro.login({
         success: async function (res) {
+          console.log("获取code", res)
           if (res.code) {
             //后台登录
             let response: any = await Taro.request<ResData>({

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

@@ -33,6 +33,7 @@ export function wxlogin() {
       //获取code
       login({
         success: async function (res) {
+          console.log("res", res)
           if (res.code) {
             //后台登录
             let response: any = await Taro.request<ResData>({