index.tsx 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /**书详情 */
  10. type state = {
  11. }
  12. interface Props {
  13. store: Store;
  14. }
  15. @inject('store')
  16. @observer
  17. class BookDetails extends Component<Props> {
  18. state: state = {
  19. }
  20. onShareAppMessage() {
  21. return {
  22. title: '我的好朋友',
  23. path: 'pages/book/bookDetails/index?bookId' + this.props.store.bookStore.openBookData?.bookId,
  24. imageUrl: this.props.store.bookStore.openBookData?.picUrl
  25. }
  26. }
  27. componentDidShow(options) {
  28. Taro.showShareMenu({
  29. showShareItems: ["shareAppMessage"],
  30. success: (res) => { console.log("成功") },
  31. fail: (err) => { console.log("err") }
  32. });
  33. let params = Taro.getCurrentInstance()?.router?.params
  34. let { bookStore, appInfoStore } = this.props.store
  35. // 获取书籍详情
  36. if (params?.bookId && !bookStore.openBookData) {
  37. let { getBookInfo } = useApi(appInfoStore)
  38. console.log("分享进入")
  39. getBookInfo(params.bookId)
  40. console.log(params?.bookId)
  41. }
  42. }
  43. render() {
  44. let { bookStore } = this.props.store
  45. let { openBookData } = bookStore
  46. let describe = `${openBookData?.bookName}·${openBookData?.wordCount ? (openBookData?.wordCount / 10000).toFixed(0) + "万字·" : ""}${openBookData?.bookStatus === 0 ? '连载' : '完本'}`
  47. return <>
  48. {
  49. <View className='book_details'>
  50. <View className="details_top">
  51. <View className='header'>
  52. <View className="back">
  53. <Image src={openBookData?.picUrl || ""} className="backImg" mode="widthFix" />
  54. </View>
  55. <View className="content">
  56. <View className='left'>
  57. <Text className='title'>{openBookData?.bookName}</Text>
  58. <Text className='author'>{openBookData?.authorName}</Text>
  59. {/* bookDesc */}
  60. <Text className='author'>{describe}</Text>
  61. <View className='tags'>
  62. {
  63. openBookData?.labelInfoList?.map((item, index) => {
  64. return <Text className='tag' key={index}>{item.name}</Text>
  65. })
  66. }
  67. </View>
  68. </View>
  69. <View className='right'>
  70. <Image src={openBookData?.picUrl || ""} className='img' />
  71. </View>
  72. </View>
  73. </View>
  74. <BookHead title="简介" ></BookHead>
  75. <View className='center'>
  76. <Text>{openBookData?.bookDesc.replace(/\s/ig, '')}</Text>
  77. </View>
  78. </View>
  79. <View className='btn'>
  80. <Navigator url={`/pages/book/bookArticle/index?bookId=${openBookData?.bookId}`} hoverClass="none">
  81. <Image src={require('../../../icon/btn.png')} className='img' />
  82. </Navigator>
  83. </View>
  84. </View>
  85. }
  86. </>
  87. }
  88. }
  89. export default BookDetails