index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { Component } from 'react'
  2. import { View, Text, Image, Navigator } from '@tarojs/components'
  3. import { observer, inject } from 'mobx-react'
  4. import './index.less'
  5. import BookHead from '@src/components/PupPetry/BookHead'
  6. import { Store } from '@src/app'
  7. import Taro from '@tarojs/taro'
  8. import useApi from '@src/Hook/useApi'
  9. import { share } from '@src/utils'
  10. /**书详情 */
  11. type state = {
  12. }
  13. interface Props {
  14. store: Store;
  15. }
  16. @inject('store')
  17. @observer
  18. class BookDetails extends Component<Props> {
  19. state: state = {
  20. }
  21. componentDidShow(options) {
  22. let params = Taro.getCurrentInstance()?.router?.params
  23. // 获取书籍详情
  24. if (params?.bookId || params?.sBookId || params?.lBookId) {
  25. let bookId = params?.bookId || params?.sBookId || params?.lBookId
  26. let { getBookInfo } = useApi()
  27. log("分享进入")
  28. getBookInfo(bookId)
  29. log(bookId)
  30. }
  31. }
  32. async onShareAppMessage() {
  33. // 获取当前页面栈
  34. const pages = Taro.getCurrentPages()
  35. // 获取栈顶的页面,即当前页面
  36. const currentPage = pages[pages.length - 1]
  37. // 获取页面的路径和参数
  38. const route = currentPage.route // 页面路径
  39. if (route) {
  40. let shareInfo = await share({ pagePath: route, bookId: this.props?.store?.bookStore?.openBookData?.bookId })
  41. let { sharePicUrl, shareTitles, pageName, pagePath } = shareInfo
  42. return {
  43. title: shareTitles || app.appInfo?.appName + '-' + pageName,
  44. path: pagePath || undefined,
  45. imageUrl: sharePicUrl || undefined
  46. }
  47. }
  48. return {}
  49. }
  50. render() {
  51. let { bookStore } = this.props.store
  52. let { openBookData } = bookStore
  53. let describe = `${openBookData?.wordCount ? (openBookData?.wordCount / 10000).toFixed(0) + "万字·" : ""}${openBookData?.bookStatus === 0 ? '连载' : '完本'}`
  54. return <>
  55. {
  56. <View className='book_details'>
  57. <View className="details_top">
  58. <View className='header'>
  59. <View className="back">
  60. <Image src={openBookData?.picUrl || ""} className="backImg" mode="widthFix" />
  61. </View>
  62. <View className="content">
  63. <View className='left'>
  64. <Text className='title'>{openBookData?.bookName}</Text>
  65. <Text className='author'>{openBookData?.authorName}</Text>
  66. {/* bookDesc */}
  67. <Text className='author'>{describe}</Text>
  68. <View className='tags'>
  69. {
  70. openBookData?.labelInfoList?.map((item, index) => {
  71. return <Text className='tag' key={index}>{item.name}</Text>
  72. })
  73. }
  74. </View>
  75. </View>
  76. <View className='right'>
  77. <Image src={openBookData?.picUrl || ""} className={`img ${openBookData?.vipFree ? "isVip" : ""}`} />
  78. </View>
  79. </View>
  80. </View>
  81. <BookHead title="简介" ></BookHead>
  82. <View className='center'>
  83. <Text>{openBookData?.bookDesc?.replace(/\s/ig, '')}</Text>
  84. </View>
  85. </View>
  86. <View className='btn' >
  87. {/* <Navigator url={`/pages/book/bookArticle/index?bookId=${openBookData?.bookId}`} hoverClass="none"> */}
  88. <Navigator url={`plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=A1HcfuuvKqNdTuMD9dMmQDxTuJ`} hoverClass="none">
  89. {/* <Image src={require('../../../icon/btn.png')} className='img' /> */}
  90. <View className='vip_btn' >开始阅读</View>
  91. </Navigator>
  92. </View>
  93. </View>
  94. }
  95. </>
  96. }
  97. }
  98. export default BookDetails