index.ux 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <import name="info" src="../../components/book-detail/info"></import>
  2. <import name="add-desktop" src="../../components/addDesktop"></import>
  3. <import
  4. name="comment-item-simple"
  5. src="../../components/book-detail/comment-item-simple"
  6. ></import>
  7. <import name="my-toast" src="apex-ui/components/toast/index"></import>
  8. <template>
  9. <div class="page-wrapper">
  10. <list>
  11. <list-item type="info"> <info info="{{bookInfo}}"></info> </list-item>
  12. <list-item type="description" class="description">
  13. <text class="description-title">作品简介</text>
  14. <text class="text-remark">{{ bookInfo.novelIntroduction }}</text>
  15. </list-item>
  16. <list-item type="sub-title" class="sub-title">
  17. <text class="text-title">共{{ bookInfo.novelChapterCount || 100 }}章</text>
  18. <div @click="goToContents">
  19. <text class="text-remark">{{ bookInfo.createTime && bookInfo.createTime.split('T')[0] || '' }}更新</text>
  20. <text class="text-remark iconfont">&#xe622;</text>
  21. </div>
  22. </list-item>
  23. <!-- <list-item type="sub-title" class="detail-title">
  24. <text class="text-title">热门评论</text>
  25. <div @click="goToComment">
  26. <text class="text-remark">30人正在讨论</text>
  27. <text class="text-remark iconfont">&#xe6d7;</text>
  28. </div>
  29. </list-item> -->
  30. <!-- <list-item type="comment" for="{{commentList}}">
  31. <comment-item-simple
  32. item="{{$item}}"
  33. ></comment-item-simple>
  34. </list-item> -->
  35. <!-- <list-item type="detail-title" class="detail-title">
  36. <text class="text-title">相似图书推荐</text>
  37. </list-item>
  38. <list-item type="image-list" class="book-image-list">
  39. <div
  40. class="book-image-item"
  41. for="{{recommandBook}}"
  42. @click="goToDetail($item)"
  43. >
  44. <image src="{{$item.image}}"></image>
  45. <text class="book-image-title">{{ $item.title }}</text>
  46. <text class="text-remark">{{ $item.author }}</text>
  47. </div>
  48. </list-item> -->
  49. </list>
  50. <div class="detail-bottom-bar">
  51. <text
  52. class="btn btn-shelf {{isInShelf ? 'btn-shelf-disabled' : ''}}"
  53. @click="addToShelf"
  54. >
  55. {{ isInShelf ? '已加入书架' : '加入书架' }}
  56. </text>
  57. <text class="btn-read" @click="goToContent">开始阅读</text>
  58. </div>
  59. <my-toast id="toast"></my-toast>
  60. <add-desktop></add-desktop>
  61. </div>
  62. </template>
  63. <script>
  64. import { bookListData } from '../../assets/data/book-list.js'
  65. import { commentData } from '../../assets/data/comment.js'
  66. import device from '@system.device'
  67. import prompt from '@system.prompt'
  68. export default {
  69. public: {
  70. info: '',
  71. linkId:'',//链接id
  72. },
  73. private: {
  74. bookInfo: {},
  75. commentList: commentData.slice(0, 3),
  76. recommandBook: bookListData.slice(0, 3),
  77. isInShelf: false,
  78. shelfList: [],
  79. shelfInfo:{},//书架信息
  80. linkInfo:{},
  81. adList:[],
  82. ad:null,
  83. screenHeight:0,
  84. },
  85. async onInit() {
  86. // 此处直接将图书内容传进来,实际开发中也可以传入id查询图书信息
  87. this.bookInfo = this.info ? JSON.parse(this.info) : {}
  88. if(this.linkId){
  89. this.linkId = this.linkId.replace(/\?/g, '');
  90. const detail = await $apis.common.ytNovelLinkDetail({ linkId:this.linkId })
  91. this.linkInfo = detail.data
  92. // channelName 渠道名称 phoneTypeName 机型名称
  93. this.bookInfo.novelId = detail.data.novelId
  94. }
  95. // $shelfList:全局变量
  96. this.shelfList = $shelfList
  97. this.isInShelf = !!this.shelfList.filter(book => {
  98. return book.id === this.bookInfo.id
  99. }).length
  100. if(this.isInShelf){ // 如果在书架中
  101. this.shelfInfo = this.shelfList.filter(book => {
  102. return book.id === this.bookInfo.id
  103. })[0] || {}
  104. }
  105. // 如果没有书名 有id
  106. if(this.bookInfo.novelId){
  107. const res = await $apis.common.novelDetail({id:this.bookInfo.novelId})
  108. this.bookInfo = res.data.ytNovel
  109. }
  110. this.initAd();
  111. setTimeout(()=>{
  112. if(this.ad) {
  113. this.ad.show();
  114. } else {
  115. this.initAd();
  116. }
  117. },50)
  118. // this.indexNativeAd() // 原生退出广告弹窗
  119. },
  120. async initAd(){
  121. try {
  122. var that = this
  123. const ret = await device.getInfo()
  124. that.ad = require('@service.ad').createBannerAd({ // 使用require方式避免在不支持的广告接口的厂商运行是报错
  125. adUnitId: '9bcd5671a506459c9e6ef9c642468dc9',
  126. style:{
  127. left: 0,
  128. top: ret.data.statusBarHeight > 119 ? ret.data.screenHeight - 100 : ret.data.screenHeight + (120 - ret.data.statusBarHeight),
  129. height:100,
  130. width: 1080
  131. }
  132. })
  133. } catch (e) {
  134. console.log(e)
  135. }
  136. },
  137. indexNativeAd(){
  138. // 原生广告 1.0
  139. let nativeAd = require('@service.ad').createNativeAd({ // 使用require方式避免在不支持的广告接口的厂商运行是报错
  140. adUnitId: 'e2528e5d2baf4cef9a359f3074ca193c',
  141. })
  142. nativeAd.onLoad((data) => {
  143. console.log('Native ad resources!', data); // 广告加载成功,返回原生广告资源,根据但是资源自行渲染展现
  144. })
  145. nativeAd.load();
  146. // 原生广告2.0
  147. let adParams = {
  148. adUnitId: 'e2528e5d2baf4cef9a359f3074ca193c', // 原生广告2.0广告位id
  149. type: 'native', // 原生广告2.0广告类型
  150. adCount: 2, // 原生广告2.0广告预期返回广告条数
  151. }
  152. require('@service.ad').preloadAd({
  153. ...adParams,
  154. success: (data) => {
  155. this.adList = data.adList
  156. console.log('data',data)
  157. // prompt.showToast({
  158. // message: `success! data=${JSON.stringify(data)}`
  159. // })
  160. }, fail: (data, code) => {
  161. console.log(data, code)
  162. // prompt.showToast({
  163. // message: `fail! data=${JSON.stringify(data)}, code=${code}`
  164. // })
  165. }
  166. })
  167. },
  168. /* -------------------SelfCustomEvent------------------ */
  169. goToComment() {
  170. $utils.route2theUrl('pages/comment-all', this.bookInfo)
  171. },
  172. goToContents() {
  173. $utils.route2theUrl('pages/contents', {
  174. bookId: this.bookInfo.id,
  175. bookTitle: this.bookInfo.novelName
  176. })
  177. },
  178. goToDetail(item) {
  179. console.log(item)
  180. // 根据id查询详情,跳转到另一个图书的详情页,用router.replace,无法返回当前页
  181. $utils.routeReplacetheUrl('pages/book-detail', {
  182. info: JSON.stringify(item)
  183. })
  184. },
  185. goToContent() {
  186. $utils.route2theUrl('pages/book-content', {
  187. bookId: this.bookInfo.id,
  188. bookTitle: this.bookInfo.novelName,//title,
  189. total: this.bookInfo.novelChapterCount,//count
  190. chapterId:this.shelfInfo.chapterId || 1, // 如果在书架中
  191. })
  192. },
  193. addToShelf() {
  194. if (this.isInShelf) {
  195. return
  196. }
  197. if (!this.bookInfo.id) {
  198. this.$child('toast').showToast({
  199. content: '图书信息有误',
  200. icon: 'warning'
  201. })
  202. return
  203. }
  204. this.isInShelf = true
  205. this.bookInfo.chapterId = 1 // 设置默认章节为第一章
  206. this.shelfList.push(this.bookInfo)
  207. $utils.setShelfList(this.shelfList, true) // 保存到全局变量和storage
  208. this.$child('toast').showToast({
  209. content: '已加入书架',
  210. icon: 'thumbs-up'
  211. })
  212. }
  213. }
  214. </script>
  215. <style lang="less">
  216. @import '../../assets/styles/index.less';
  217. .description {
  218. padding: @gap-4;
  219. width: 100%;
  220. background-color: @white;
  221. .flex-box-mixins(column, flex-start, flex-start);
  222. .description-title {
  223. .text-title;
  224. margin-bottom: @gap-2;
  225. }
  226. }
  227. .sub-title {
  228. .detail-title;
  229. padding: @gap-4;
  230. }
  231. .detail-title {
  232. background-color: @white;
  233. padding: @gap-4 @gap-4 @gap-2 @gap-4;
  234. margin-top: @gap-2;
  235. .text-title;
  236. .flex-box-mixins(row, space-between, center);
  237. }
  238. .comment-more {
  239. margin-right: @gap-3;
  240. }
  241. .book-image-list {
  242. width: 100%;
  243. padding: 0 @gap-2 @gap-2 @gap-2;
  244. background-color: @white;
  245. margin-bottom: @gap-2;
  246. flex-wrap: wrap;
  247. .flex-box-mixins(row, flex-start, flex-start);
  248. .g22kjdgy{
  249. color: #ffffff;
  250. }
  251. .book-image-item {
  252. width: 28%;
  253. margin: @gap-2;
  254. .flex-box-mixins(column, flex-start, flex-start);
  255. image {
  256. border-radius: 5px;
  257. width: 100%;
  258. height: 270px;
  259. flex: 1;
  260. }
  261. .book-image-title {
  262. .text-remark-black;
  263. margin: @gap-1 0 5px 0;
  264. }
  265. }
  266. }
  267. .detail-bottom-bar {
  268. padding: @gap-3 @gap-4 115px;
  269. background-color: @bg-grey;
  270. .border-top-mixins();
  271. .flex-box-mixins(row, space-between, center);
  272. }
  273. .btn-shelf {
  274. color: @brand;
  275. border: 1px solid @brand;
  276. border-radius: 5px;
  277. padding: 15px 0;
  278. flex: 1;
  279. text-align: center;
  280. margin-right: @gap-2;
  281. }
  282. .btn-read {
  283. color: @white;
  284. border: 1px solid @brand;
  285. background-color: @brand;
  286. border-radius: 5px;
  287. padding: 15px 0;
  288. flex: 1;
  289. text-align: center;
  290. }
  291. .btn-shelf-disabled {
  292. .btn-disabled;
  293. }
  294. </style>