index.jsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { Component } from 'react'
  2. import { View, Text, Button, Image, scrollView, Input } from '@tarojs/components'
  3. import * as api from '../../../../service/index'
  4. import tool from '../../../../common/tool'
  5. import Taro, { getCurrentInstance } from '@tarojs/taro'
  6. import './index.less'
  7. export default class collection extends Component {
  8. $instance = getCurrentInstance()
  9. state = {
  10. booksinfo: {},
  11. is_collect: 0,//是否加入书架,0|1
  12. likeBookList: [],
  13. lastTime: 0
  14. }
  15. componentWillMount () {
  16. this.getBookinfo()
  17. this.getBookLike()
  18. }
  19. componentDidShow () {
  20. }
  21. getBookLike () {
  22. api.getBookLike().then(res => {
  23. if (res.code == 200) {
  24. this.setState({
  25. likeBookList: res.data.book_like
  26. })
  27. }
  28. })
  29. }
  30. getBookinfo () {
  31. let routers = this.$instance.router.params
  32. api.getBookinfo({ book_id: routers.book_id }).then(res => {
  33. if (res.code == 200) {
  34. this.setState({
  35. booksinfo: res.data.book_info[0],
  36. is_collect: res.data.is_collect
  37. })
  38. }
  39. })
  40. }
  41. bookCollect () {
  42. if (this.state.is_collect == 1) return
  43. let routers = this.$instance.router.params
  44. api.bookCollect({ book_id: routers.book_id }).then(res => {
  45. if (res.code == 200) {
  46. this.getBookinfo()
  47. }
  48. })
  49. }
  50. onReachBottom () {
  51. // if (!this.state.total) {
  52. // this.setState({
  53. // page: this.state.page + 1
  54. // })
  55. // }
  56. }
  57. toDetail (item, index) {
  58. Taro.navigateTo({
  59. url: '/pages/index/subpages/novel/index'
  60. })
  61. }
  62. toNovelText () {
  63. Taro.navigateTo({
  64. url: `/pages/index/subpages/novelText/index?book_id=${this.state.booksinfo.id}`
  65. })
  66. }
  67. toDirectory () {
  68. Taro.navigateTo({
  69. url: `/pages/index/subpages/directory/index?book_id=${this.state.booksinfo.id}`
  70. })
  71. }
  72. toLikeBooks (item, index) {
  73. Taro.navigateTo({
  74. url: `/pages/index/subpages/novel/index?book_id=${item.id}`
  75. })
  76. }
  77. copyCode () {
  78. let lastTime = this.state.lastTime;
  79. let now = new Date().getTime();
  80. if (now - lastTime < 2000) return
  81. this.setState({
  82. lastTime: now
  83. }, () => {
  84. api.getCommand({ book_id: this.state.booksinfo.id }).then(res => {
  85. if (res.code == 200) {
  86. let text = res.data
  87. // if (process.env.TARO_ENV == 'tt') {
  88. // text = res.data
  89. // }
  90. Taro.setClipboardData({
  91. data: text,
  92. success: function (res) {
  93. Taro.showModal({
  94. title: '口令复制成功',
  95. content: "是否前往了解赚钱计划?",
  96. success: function (res) {
  97. if (res.confirm) {
  98. Taro.navigateTo({
  99. url: `/pages/mine/subpages/moneyPlay/index`
  100. })
  101. } else if (res.cancel) {
  102. console.log('用户点击取消')
  103. }
  104. }
  105. })
  106. }
  107. })
  108. }
  109. })
  110. })
  111. }
  112. render () {
  113. return (
  114. <View className='mine'>
  115. <View className='mine-content'>
  116. <View className='book-top'>
  117. <Image className='book-img' src={this.state.booksinfo.img}></Image>
  118. <View className='top-right'>
  119. <View className='book-title'>{tool.ellipsis(this.state.booksinfo.name, 15)}</View>
  120. <View className='book-visit-num'>{this.state.booksinfo.paly_cnt}游览</View>
  121. </View>
  122. <View className='share update-active' onClick={e => (this.copyCode())}>
  123. <Image className='share-img' mode='widthFix' src='https://video-img.fyshark.com/1684206675357shykahfgl.png'></Image>
  124. </View>
  125. </View>
  126. <View className='book-tips'>
  127. <View className='book-tips-title'>书籍简介</View>
  128. <View className='book-tips-content'>{this.state.booksinfo.intro} </View>
  129. </View>
  130. <View className='directory' onClick={e => (this.toDirectory())}>
  131. <View className='directory-left'>
  132. <Image className='directory-icon' src='https://video-img.fyshark.com/1683618704652dadda%20.png'></Image>
  133. <View className='derectory-title'>查看目录</View>已更新到{this.state.booksinfo.album_cnt}章
  134. </View>
  135. <Image className='directory-right-icon' src='https://video-img.fyshark.com/1683618693594ddada%20.png'></Image>
  136. </View>
  137. <View className='like'>
  138. <View className='like-tips'>
  139. <View className='lick-title'>猜你喜欢</View>
  140. <View className='lick-change' onClick={e => (this.getBookLike())}>
  141. 换一换
  142. <Image className='like-img' src='https://video-img.fyshark.com/1683619412847dada%20.png'></Image>
  143. </View>
  144. </View>
  145. <View className='lick-list'>
  146. {
  147. this.state.likeBookList.map((item, index) => (
  148. <View className='lick-info' key={index} onClick={e => (this.toLikeBooks(item, index))}>
  149. <Image className='like-img' src={item.img}></Image>
  150. <View className='like-title'>{tool.ellipsis(item.name, 4)}</View>
  151. </View>
  152. ))
  153. }
  154. </View>
  155. </View>
  156. <View className='selected'>
  157. <View className='selected-title'>精选内容</View>
  158. <View className='selected-text'>{this.state.booksinfo.short_name}</View>
  159. </View>
  160. <View className='console'>
  161. <View className='console-content'>
  162. <View className='console-left'
  163. style={this.state.is_collect == 1 ? 'opacity:0.3' : ''}
  164. onClick={e => (this.bookCollect())}>
  165. <Image className='console-left-img' src='https://video-img.fyshark.com/1683620721580adda.png'></Image>
  166. <View className='console-left-title'>{this.state.is_collect == 0 ? '加入书架' : '已在书架'}</View>
  167. </View>
  168. <View className='console-right' onClick={e => (this.toNovelText())}>
  169. 继续阅读
  170. </View>
  171. </View>
  172. </View>
  173. </View>
  174. </View>
  175. )
  176. }
  177. }