list-wrap.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="list-wrap scroll-touch">
  3. <wsh-list-item
  4. v-for="(item, index) in newsLists"
  5. :key = 'index' :itemData = 'item' />
  6. <!-- <div class="list-wrap-ad">
  7. <ad unit-id="adunit-7496c51cbc82905d"></ad>
  8. </div> -->
  9. <div class="list-footer">
  10. <p v-if="moreStatus"> 没有更多数据</p>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. import {get} from '@/utils/request'
  16. import ListItem from './list-item'
  17. export default {
  18. props: ['channelId'],
  19. data () {
  20. return {
  21. tips: '请稍后',
  22. show: true,
  23. animated: true,
  24. newsLists: [],
  25. page: 1,
  26. limit: 40,
  27. moreStatus: false,
  28. interstitialAd: null,
  29. rewardedVideoAd: null,
  30. onlyPlay: true
  31. }
  32. },
  33. onLoad () {
  34. // 加载视频广告
  35. if (wx.createRewardedVideoAd) {
  36. this.rewardedVideoAd = wx.createRewardedVideoAd({
  37. adUnitId: 'adunit-de36057cf600716b'
  38. })
  39. this.rewardedVideoAd.onLoad(() => {
  40. console.log('onLoad event emit')
  41. })
  42. this.rewardedVideoAd.onError((err) => {
  43. console.log('onError event emit', err)
  44. })
  45. this.rewardedVideoAd.onClose((res) => {
  46. console.log('onClose event emit', res)
  47. })
  48. }
  49. // 加载插屏广告
  50. if (wx.createInterstitialAd) {
  51. this.interstitialAd = wx.createInterstitialAd({ adUnitId: 'adunit-5ecedc2dc28ef414' })
  52. this.interstitialAd.onLoad(() => {
  53. console.log('onLoad event emit')
  54. console.log('插屏 广告加载成功')
  55. })
  56. this.interstitialAd.onError((err) => {
  57. console.log('onError event emit', err)
  58. })
  59. this.interstitialAd.onClose((res) => {
  60. console.log('onClose event emit', res)
  61. })
  62. }
  63. },
  64. components: {
  65. 'wsh-list-item': ListItem
  66. },
  67. methods: {
  68. async getListDate (init) {
  69. if (init) {
  70. this.page = 1
  71. this.moreStatus = false
  72. }
  73. this.page++
  74. // wx.showNavigationBarLoading()
  75. const params = {
  76. page: this.page,
  77. limit: this.limit,
  78. channel_id: this.channelId,
  79. }
  80. // if (this.page !== 1) {
  81. // wx.showToast({
  82. // title: '加载中...',
  83. // mask: true,
  84. // icon: 'loading'
  85. // })
  86. // }
  87. console.log('params', params)
  88. const newsData = await get('/v1/info/web-list', params)
  89. console.log('newDate', newsData)
  90. if (newsData.list.length < this.limit & this.page > 1) {
  91. this.moreStatus = true
  92. }
  93. if (init) {
  94. wx.stopPullDownRefresh() // 手动停止下拉刷新
  95. this.newsLists = newsData.list
  96. } else {
  97. wx.hideNavigationBarLoading() // 关闭下拉刷新加载
  98. if (newsData.list) {
  99. this.newsLists = this.newsLists.concat(newsData.list)
  100. this.onlyPlay = true
  101. } else {
  102. }
  103. }
  104. }
  105. },
  106. onPullDownRefresh () {
  107. wx.stopPullDownRefresh();
  108. // console.log('观看视频获取最新资讯')
  109. var that = this
  110. wx.showModal({
  111. title: '提示',
  112. content: '观看视频获取最新资讯',
  113. success (res) {
  114. if (res.confirm) {
  115. // console.log('用户点击确定')
  116. that.rewardedVideoAd.show()
  117. .then(() => console.log('激励视频 广告显示'))
  118. .catch(() => {
  119. that.rewardedVideoAd.load()
  120. .then(() => that.rewardedVideoAd.show())
  121. .catch(err => {
  122. console.log('激励视频 广告显示失败', err)
  123. })
  124. })
  125. that.rewardedVideoAd.onClose(res => {
  126. // 用户点击了【关闭广告】按钮
  127. if (res && res.isEnded) {
  128. // 正常播放结束,可以下发游戏奖励
  129. wx.showToast({
  130. title: '更多最新资讯尽请期待',
  131. icon: 'none',
  132. duration: 2000
  133. });
  134. } else {
  135. // 播放中途退出,不下发游戏奖励
  136. }
  137. })
  138. } else if (res.cancel) {
  139. // console.log('用户点击取消')
  140. }
  141. }
  142. })
  143. // wx.startPullDownRefresh()
  144. },
  145. onReachBottom () {
  146. // if (!this.moreStatus) {
  147. // // 没有更多了
  148. // return false
  149. // }
  150. this.interstitialAd.show().catch((err) => {
  151. console.error(err)
  152. })
  153. this.interstitialAd.onClose(res => {
  154. console.log('插屏 广告关闭')
  155. })
  156. if (this.onlyPlay) {
  157. this.onlyPlay = false
  158. this.getListDate()
  159. }
  160. // console.log('上拉加载', this.page)
  161. },
  162. mounted () {
  163. this.getListDate(true)
  164. },
  165. created () {
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. .scroll-touch {
  171. -webkit-overflow-scrolling: touch;
  172. }
  173. .list-wrap {
  174. // border-top: 1px solid #ebebeb;
  175. height: 100%;
  176. .list-wrap-ad {
  177. width: 100%;
  178. }
  179. }
  180. .list-footer {
  181. display: none;
  182. width: 100%;
  183. height: 40px;
  184. line-height: 40px;
  185. text-align: center;
  186. }
  187. </style>