shenwu 6 maanden geleden
bovenliggende
commit
fb36c94979

+ 1 - 0
src/app.tsx

@@ -15,6 +15,7 @@ import { initApp, setApp } from './config'
 import './interceptor'
 import api from './server/index'
 import { getShortBookInfo } from './server/book/short'
+import { getUserInfo } from './server/wx/login'
 
 
 

+ 4 - 3
src/components/PupPetry/BookBox/BookboxColumnBig.tsx

@@ -12,21 +12,22 @@ export interface BookboxColumnBigProps {
     bookStatus: number,//完本|连载状态
     wordCount: number,//字数
     labelInfoList: { name: string }[],//标签
+    vipFree: boolean
 }
 function BookboxColumnBig(props: BookboxColumnBigProps) {
     const click = () => {
         // BookStore.setData({ openBookData: props })
     }
-    const { picUrl, bookName, bookId, authorName } = props
+    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'></Image>
+            <Image src={picUrl || ''} className={`img ${vipFree ? "isVip" : ""}`}></Image>
             <View className='bottom'>
                 <Text className='title'>{bookName}</Text>
                 <Text className='author'>{authorName}</Text>
             </View>
         </Navigator>
     </View>
-}
+} 
 
 export default React.memo(BookboxColumnBig)

+ 3 - 2
src/components/PupPetry/BookBox/BookboxColumnSmall.tsx

@@ -12,15 +12,16 @@ export interface BookboxColumnSmallProps {
     bookStatus: number,//完本|连载状态
     wordCount: number,//字数
     labelInfoList: { name: string }[],//标签
+    vipFree:boolean
 }
 function BookboxColumnSmall(props: BookboxColumnSmallProps) {
-    const { picUrl, bookName, bookId } = props
+    const { picUrl, bookName, bookId ,vipFree} = props
     const click = () => {
         // BookStore.setData({ openBookData: props })
     }
     return <View className='book_box_column_small' onClick={click}>
         <Navigator url={'/pages/book/bookDetails/index?bookId=' + bookId} hoverClass="none">
-            <Image src={picUrl || ''} className='img'></Image>
+            <Image src={picUrl || ''}  className={`img ${vipFree ? "isVip" : ""}`}></Image>
             <View className='bottom'>
                 <Text className='title'>{bookName}</Text>
             </View>

+ 3 - 2
src/components/PupPetry/BookBox/BookboxRowBig.tsx

@@ -12,9 +12,10 @@ export interface BookboxRowBigProps {
     bookStatus: number,//完本|连载状态
     wordCount: number,//字数
     labelInfoList:{name:string}[],//标签
+    vipFree:boolean
 }
 function BookboxRowBig(props: BookboxRowBigProps) {
-    const { bookName, picUrl, bookDesc, labelInfoList, authorName, bookId, wordCount, bookStatus } = props
+    const { bookName, picUrl, bookDesc, labelInfoList, authorName, bookId, wordCount, bookStatus,vipFree } = props
     let describe = ""
     if(wordCount && bookStatus) {
         describe = `${bookName}·${(wordCount/10000).toFixed(0)}万字·${bookStatus === 0 ? '连载' : '完本'}`
@@ -24,7 +25,7 @@ function BookboxRowBig(props: BookboxRowBigProps) {
     }
     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>
+            <Image src={picUrl || ''}  className={`img ${vipFree ? "isVip" : ""}`}></Image>
             <View className='right'>
                 <Text className='title'>{bookName}</Text>
                 <View className='content'>

+ 5 - 4
src/components/PupPetry/BookBox/BookboxRowMiddle.tsx

@@ -12,20 +12,21 @@ export interface BookboxRowMiddleProps {
     bookStatus: number,//完本|连载状态
     wordCount: number,//字数
     labelInfoList: { name: string }[],//标签
+    vipFree: boolean
 }
 function BookboxRowMiddle(props: BookboxRowMiddleProps) {
-    const { bookName, picUrl, bookDesc, labelInfoList, authorName, bookId, wordCount, bookStatus } = props
+    const { bookName, picUrl, bookDesc, labelInfoList, authorName, bookId, vipFree, wordCount, bookStatus } = props
     const click = () => {
         // BookStore.setData({ openBookData: props })
     }
-    return <View className='book_box_row_middle'  onClick={click}>
+    return <View className='book_box_row_middle' onClick={click}>
         <Navigator url={'/pages/book/bookDetails/index?bookId=' + bookId} hoverClass="none">
-            <Image src={picUrl || ''} className='img'></Image>
+            <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>
+                        <Text className='details'>{bookDesc?.replace(/\s/ig, '')}</Text>
                         <View className='bottom'>
                             <Text className='describe'>{authorName}</Text>
                             <Text className='label'>{labelInfoList?.[0].name}</Text>

+ 3 - 2
src/components/PupPetry/BookBox/BookboxRowSmall.tsx

@@ -16,12 +16,13 @@ export interface BookboxRowSmallProps {
         wordCount: number,//字数
         labelInfoList: { name: string }[],//标签
         readLogId: string,//上次阅读的记录
+        vipFree: boolean
     }
     lastReadingTime: string,//最近阅读时间
 }
 function BookboxRowSmall(props: BookboxRowSmallProps) {
     const { lastReadingTime, bookInfo } = props
-    const { bookName, picUrl, authorName, bookId, readLogId } = bookInfo
+    const { bookName, picUrl, authorName, bookId, readLogId, vipFree } = bookInfo
     const click = () => {
         BookStore.setData({ openBookData: props })
         if (readLogId) {
@@ -30,7 +31,7 @@ function BookboxRowSmall(props: BookboxRowSmallProps) {
     }
     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'></Image>
+            <Image src={picUrl} className={`img ${vipFree ? "isVip" : ""}`}></Image>
             <View className='right'>
                 <Text className='title'>{bookName}</Text>
                 <View className='content'>

+ 1 - 0
src/components/PupPetry/BookBox/index.less

@@ -3,6 +3,7 @@
   margin: 30px;
   display: block;
   overflow: hidden;
+  position: relative;
   .img {
     width: 146px;
     height: 196px;

+ 5 - 5
src/components/bottomModal/index.tsx

@@ -42,11 +42,11 @@ const GlobalModal: React.FC<Props> = (props) => {
             }
               
             console.log("支付模板数据", params)
-            // let res = await templateBuy(params)
-            // if(res){
-            //     callBackFn?.()//刷新页面
-            //     modalStore.hideModal()
-            // }
+            let res = await templateBuy(params)
+            if(res){
+                callBackFn?.()//刷新页面
+                modalStore.hideModal()
+            }
           
         }
         return <>

+ 74 - 55
src/globaStyle.less

@@ -1,70 +1,89 @@
 /**字体大小**/
-@fs_20:20px;
-@fs_24:24px;
-@fs_28:28px;
-@fs_30:30px;
-@fs_32:32px;
-@fs_34:34px;
-@fs_36:36px;
-@fs_38:38px;
-@fs_40:40px;
-@fs_42:42px;
-@fs_44:44px;
-@fs_46:46px;
-@fs_48:48px;
-@fs_50:50px;
-@fs_54:54px;
-@fs_58:58px;
+@fs_20: 20px;
+@fs_24: 24px;
+@fs_28: 28px;
+@fs_30: 30px;
+@fs_32: 32px;
+@fs_34: 34px;
+@fs_36: 36px;
+@fs_38: 38px;
+@fs_40: 40px;
+@fs_42: 42px;
+@fs_44: 44px;
+@fs_46: 46px;
+@fs_48: 48px;
+@fs_50: 50px;
+@fs_54: 54px;
+@fs_58: 58px;
 /**字体粗细**/
-@fw_100:100;
-@fw_400:400;
-@fw_500:500;
-@fw_900:900;
+@fw_100: 100;
+@fw_400: 400;
+@fw_500: 500;
+@fw_900: 900;
 /**字体颜色**/
-@cl_333:#333333;
-@cl_666:#666666;
-@cl_999:#999999;
-@cl_949:#949BAB;
-@cl_6E9:#6E9DE8;
-@cl_F02:#F02C4D;
-@cl_253:#253C6F;
-@cl_C8:#C8C8C8;
-@cl_94:#949bab;
+@cl_333: #333333;
+@cl_666: #666666;
+@cl_999: #999999;
+@cl_949: #949BAB;
+@cl_6E9: #6E9DE8;
+@cl_F02: #F02C4D;
+@cl_253: #253C6F;
+@cl_C8: #C8C8C8;
+@cl_94: #949bab;
 /**背景色***/
-@bg_EC:#ECECEC;
-@bg_FF:#FFF0F3;
-@bg_E5:#E5EBFA;
-@bg_D8:#D8D8D8;
-@bg_F8:#F8F8F8;
-@bg_E9:#E9E9E9;
-@bg_F4:#F4F4F4;
-@bg_F5:#F5F6F7;
-@bg_F5E:#F5F6EE;
-@bg_D6E:#D6E4CC;
-@bg_36:#363738;
-@bg_11:#111111;
-@bg_F7:#F7F8F9;
-@bg_94:#949bab;
+@bg_EC: #ECECEC;
+@bg_FF: #FFF0F3;
+@bg_E5: #E5EBFA;
+@bg_D8: #D8D8D8;
+@bg_F8: #F8F8F8;
+@bg_E9: #E9E9E9;
+@bg_F4: #F4F4F4;
+@bg_F5: #F5F6F7;
+@bg_F5E: #F5F6EE;
+@bg_D6E: #D6E4CC;
+@bg_36: #363738;
+@bg_11: #111111;
+@bg_F7: #F7F8F9;
+@bg_94: #949bab;
 /**边框色***/
 @br_2_6E: 2px solid #6E9DE8;
 /**圆角**/
-@r_10:10px;
-@r_20:20px;
-@r_30:30px;
-@r_34:34px;
-@r_26:26px;
+@r_10: 10px;
+@r_20: 20px;
+@r_30: 30px;
+@r_34: 34px;
+@r_26: 26px;
+
 /**单行溢出隐藏**/
-.hide_font(@a,@b){
+.hide_font(@a, @b) {
     overflow: hidden;
     text-overflow: ellipsis;
     -webkit-box-orient: vertical;
-    white-space:@b;
+    white-space: @b;
     -webkit-line-clamp: @a;
     display: -webkit-box;
 }
+
 /**行高**/
-@lh_60:60px;
-@lh_64:64px;
-@lh_72:72px;
-@lh_84:84px;
-@lh_96:96px;
+@lh_60: 60px;
+@lh_64: 64px;
+@lh_72: 72px;
+@lh_84: 84px;
+@lh_96: 96px;
+
+.isVip {
+    position: relative;
+    &::after {
+        content: "";
+        display: inline-block;
+        position: absolute;
+        height: 100%;
+        background: url("./icon/isVip.png") no-repeat;
+        top: 0;
+        left: 0;
+        right: 0;
+        background-size: 50%;
+        z-index: 999;
+    }
+
+}

BIN
src/icon/isVip.png


+ 1 - 0
src/interceptor.ts

@@ -69,6 +69,7 @@ const responseInterceptor = (chain) => {
                     enumDictList()
                     // 登录
                     let user: any = await api.login()
+                    console.log("user",user)
                     // 存放user信息到本地
                     Taro.setStorageSync("userInfo", user)
                     // 获取充值模板

+ 37 - 13
src/pages/book/BookArticle/index.tsx

@@ -64,7 +64,19 @@ const BookArticle: React.FC<BookArticleProps> = ({ store }) => {
             onReport()
             //假如存在阅读记录获取对应章节的条数
             let readLogId = getReadLog(openBookData?.bookId)
-            getBookContent({ pageNum: 1, pageSize: readLogId ? Number(readLogId?.split('-')[1]) : 2 }).then(res => {
+            getBookContent({ pageNum: 1, pageSize: readLogId ? Number(readLogId?.split('-')[1]) : 2 }).then((res: any) => {
+                if (res?.data) {
+                    for (let item of res?.data?.data?.records) {
+                        let needPay = item.needPay //是否付费解锁
+                        let isPay = item.isPay //是否已付费
+                        if (!showPay && needPay && !isPay) {
+                            setShowPay(true)
+                            setShowVip(item.vipFree)
+                            setPayBook(item)
+                            break
+                        }
+                    }
+                }
                 //继续阅读时跳转到上次阅读的段落
                 console.log("上次阅读到readLogId", readLogId)
                 setCurrentScrollId(readLogId)
@@ -168,7 +180,20 @@ const BookArticle: React.FC<BookArticleProps> = ({ store }) => {
             if (records.length < total || reload) {
                 console.log("加载")
                 setIsLoad(true)
-                await getBookContent({ pageNum: 1, pageSize: reload ? size : size + 1 }).then(res => {
+                await getBookContent({ pageNum: 1, pageSize: reload ? size : size + 1 }).then((res: any) => {
+                    if (res?.data) {
+                        for (let item of res?.data?.data?.records) {
+                            let needPay = item.needPay //是否付费解锁
+                            let isPay = item.isPay //是否已付费
+                            // let isVip = 
+                            if (!showPay && needPay && !isPay) {
+                                setShowPay(true)
+                                setShowVip(item.vipFree)
+                                setPayBook(item)
+                                break
+                            }
+                        }
+                    }
                     setIsLoad(false)
                 })
             } else {
@@ -218,13 +243,13 @@ const BookArticle: React.FC<BookArticleProps> = ({ store }) => {
             let res = await cashBuy(params, onLoad)
             if (res) {
                 console.log("全本购买:", res)
-                setTimeout(()=>{
+                setTimeout(() => {
                     setShowPay(false)
                     setShowVip(false)
                     setPayBook(null)
-                },100)
+                }, 100)
             }
-        
+
         }
     }
     // 书币购买
@@ -240,14 +265,13 @@ const BookArticle: React.FC<BookArticleProps> = ({ store }) => {
             let res = await virtualBuy(params, onLoad)
             if (res) {
                 console.log("书币购买章节:", res)
-                setTimeout(()=>{
+                setTimeout(() => {
                     setShowPay(false)
                     setShowVip(false)
                     setPayBook(null)
                     modalStore.hideModal()
-                },100)
+                }, 100)
             }
-           
         }
 
     }
@@ -294,12 +318,12 @@ const BookArticle: React.FC<BookArticleProps> = ({ store }) => {
                             let arr = item.paragraphInfo.content?.match(/[^\n]*\n?/g);
                             // 是否需要付费
                             if (!showPay && needPay && !isPay) {
-                                console.log("是否需要付费====>",item,)
+                                console.log("是否需要付费====>", item,)
                                 showText = false
-                                setShowPay(true)
-                                setShowVip(item.vipFree)
-                                setPayBook(item)
-                            }else{
+                                // setShowPay(true)
+                                // setShowVip(item.vipFree)
+                                // setPayBook(item)
+                            } else {
                                 // if (showPay) {
                                 //     setShowPay(false)
                                 //     setShowVip(false)

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

@@ -69,7 +69,7 @@ class BookDetails extends Component<Props> {
                                     </View>
                                 </View>
                                 <View className='right'>
-                                    <Image src={openBookData?.picUrl || ""} className='img' />
+                                    <Image src={openBookData?.picUrl || ""} className={`img ${openBookData?.vipFree ? "isVip" :""}`} />
                                 </View>
                             </View>
                         </View>

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

@@ -77,7 +77,7 @@ function My(props: Props) {
                                 <View className="txt">
                                     <Text>会员尊享免费解锁权益</Text>
                                     {
-                                        userInfoStore.isVip && <Text className="tfv">有效期至:{1111}</Text>
+                                        userInfoStore.isVip && <Text className="tfv">有效期至:{userInfoStore?.userInfo?.vipExpireTime}</Text>
                                     }
                                 </View>
                             </View>

+ 14 - 11
src/server/wx/login.ts

@@ -39,8 +39,8 @@ export function wxlogin() {
               data: { jsCode: res.code },
             });
             if (response.code === 200) {
-              setApp({token:response.data.token,userInfo:response.data.userInfo})//存放token
-              userInfoStore.setData({userInfo:response.data.userInfo})
+              setApp({ token: response.data.token, userInfo: response.data.userInfo })//存放token
+              userInfoStore.setData({ userInfo: response.data.userInfo })
               resolve(response.data)
             }
           } else {
@@ -54,23 +54,26 @@ export function wxlogin() {
     })
   } else {
     log("已登录")
-    return Promise.resolve({token:app.token,userInfo:app?.userInfo})
+    return getUserInfo()
   }
 }
 
 /***
  * 获取个人信息
  * */
-export function getUserInfo(){
-  new Promise((res,rej)=>{
+export function getUserInfo() {
+  new Promise((resolve, reject) => {
     Taro.request({
-      url:"",
-      method:"GET",
-      success:(res)=>{
-        
+      url: "/app/wechatMiniappUser/refreshUserInfo",
+      method: "POST",
+      success: (res) => {
+        let {token,userInfo} = res?.data?.data
+        setApp({ token, userInfo })//存放token
+        userInfoStore.setData({ userInfo:userInfo,isVip:userInfo})
+        resolve(res?.data?.data.userInfo)
       },
-      fail:(err)=>{
-
+      fail: (err) => {
+        reject(err);
       }
     })
   })

+ 3 - 0
src/server/wx/pay.ts

@@ -1,4 +1,5 @@
 import Taro from "@tarojs/taro";
+import { getUserInfo } from "./login";
 type PublicData = {
     bookId: number,//小说ID
     bookParagraphId: number,//章节ID
@@ -38,6 +39,7 @@ export function virtualBuy(data: PublicData, callbackFn?: (b:boolean) => void) {
                 method: 'POST',
                 data,
                 success: async (res) => {
+                    getUserInfo()//刷新个人信息
                     callbackFn?.(true)
                     resolve(res)
                 },
@@ -66,6 +68,7 @@ export function templateBuy(data: Data, callbackFn?: (b:boolean) => void) {
                 success:async (res) => {
                     let r = await whcatPay(res.data?.data?.wechatMchPayInfo)
                     console.log("支付操作完成!!", r)
+                    getUserInfo()//刷新个人信息
                     callbackFn?.(true)
                     resolve(r)
                 },

+ 1 - 0
src/store/book.ts

@@ -16,6 +16,7 @@ export interface OpenBookData {
     wordCount: number,//字数
     labelInfoList: { name: string }[],//标签
     contentData: ContentData | null //内容数据
+    vipFree:boolean//vip免费
 }
 
 interface ClassifyData {