index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div class="detail-container scroll-touch">
  3. <div class="detail-ad-wrap">
  4. <ad unit-id="adunit-21265a59493c9c9b"></ad>
  5. </div>
  6. <!-- {{info_id}} -->
  7. <div v-if="detailHtml" :class="[ contentDisplayAll ? 'detail-context-all' : 'detail-context' ]">
  8. <h2 class="new-title">{{newsDetail.title}}</h2>
  9. <div v-html="detailHtml"></div>
  10. </div>
  11. <div class="click-display-all"
  12. v-if="detailHtml && !contentDisplayAll"
  13. @click="handleClickAll">
  14. 查看全文
  15. <span class="caret"></span>
  16. </div>
  17. <!-- 相关推荐 -->
  18. <div class="rise-container" v-if="newsDetail.relation_list">
  19. <h4 class="rise-name">相关推荐</h4>
  20. <div class="relation-item"
  21. v-for="(item, index) in newsDetail.relation_list"
  22. @click="handleToPage(item.info_id)"
  23. :key= "index">
  24. <div class="item-title">{{item.title}}</div>
  25. <div class="item-pic-wrap">
  26. <div class="item-pic-item" v-for="(url, idx ) in item.img_list" :key = "idx">
  27. <img :src="url" alt="">
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import {get} from '@/utils/request'
  36. import config from '@/utils/config'
  37. export default {
  38. onLoad: function (options) {
  39. this.info_id = options.info_id
  40. // var timer = setTimeout(() => {
  41. // this.handleConsume()
  42. // clearTimeout(timer)
  43. // }, 5000)
  44. if (wx.createRewardedVideoAd) {
  45. this.videoAd = wx.createRewardedVideoAd({
  46. adUnitId: 'adunit-adf736062e0b8ffa'
  47. })
  48. this.videoAd.onLoad(() => {})
  49. this.videoAd.onError((err) => console.log(err))
  50. // this.videoAd.onClose((res) => {})
  51. }
  52. },
  53. // onUnload: function () {
  54. // wx.reLaunch({
  55. // url: '/pages/index/main'
  56. // })
  57. // },
  58. data () {
  59. return {
  60. info_id: '',
  61. newsDetail: {},
  62. detailHtml: '',
  63. contentDisplayAll: false,
  64. ptTime: {
  65. hr: 0,
  66. min: 0
  67. },
  68. videoAd: null
  69. }
  70. },
  71. methods: {
  72. async handleConsume () {
  73. await wx.request({
  74. method: 'post',
  75. url: `${config.host}/mp/common/read-coin`,
  76. data: {
  77. appid: config.appId,
  78. mp_token: wx.getStorageSync('mpToken'),
  79. user_id: wx.getStorageSync('userInfo').user_id,
  80. info_id: this.info_id
  81. },
  82. success: res => {
  83. if (res.data.code === 0) {
  84. wx.showToast({
  85. title: `扣除10枚金币`,
  86. icon: 'none',
  87. duration: 2000
  88. })
  89. }
  90. }
  91. })
  92. },
  93. handleClickAll () {
  94. const self = this
  95. wx.showModal({
  96. title: '友情提示',
  97. content: '观看完视频查看',
  98. success (res) {
  99. if (res.confirm) {
  100. // console.log('用户点击确定')
  101. self.videoAd.show().catch(() => {
  102. self.videoAd.load()
  103. .then(() => self.videoAd.show())
  104. .catch(err => {
  105. console.log('激励视频 广告显示失败', err)
  106. })
  107. })
  108. } else if (res.cancel) {
  109. // console.log('用户点击取消')
  110. }
  111. }
  112. })
  113. this.videoAd.onClose(res => {
  114. // 用户点击了【关闭广告】按钮
  115. if (res && res.isEnded) {
  116. // 正常播放结束,可以下发游戏奖励
  117. this.contentDisplayAll = true
  118. } else {
  119. // 播放中途退出,不下发游戏奖励
  120. }
  121. })
  122. },
  123. handleToPage (infoId) {
  124. wx.navigateTo({
  125. url: `/pages/detail/main?info_id=${infoId}`
  126. })
  127. },
  128. async getNewsDetail () {
  129. const params = {
  130. sid: 'aad1ad2da28cadec36d3c9bec53ca609',
  131. info_id: this.info_id,
  132. // callback:jQuery331017495393845717588_1564626981414,
  133. _: 1564626981418
  134. }
  135. let detailData = await get('/v1/info/web-detail', params)
  136. this.newsDetail = detailData
  137. this.detailHtml = detailData.content.replace(/<img/gi, '<img style="max-width:100%;height:auto" ')
  138. }
  139. },
  140. mounted () {
  141. this.contentDisplayAll = false
  142. this.detailHtml = ''
  143. this.newsDetail = {}
  144. this.getNewsDetail()
  145. },
  146. onPullDownRefresh () {
  147. wx.stopPullDownRefresh();
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .scroll-touch {
  153. -webkit-overflow-scrolling: touch;
  154. }
  155. .detail-container {
  156. margin: 0 auto 14px;
  157. display: flex;
  158. width: 100%;
  159. flex-direction: column;
  160. align-items: center;
  161. justify-content: flex-start;
  162. .detail-context {
  163. max-height: 1000px;
  164. overflow-y: hidden;
  165. padding: 0 10px;
  166. }
  167. .detail-context-all {
  168. padding: 0 10px;
  169. }
  170. .new-title {
  171. font-size: 22px;
  172. font-weight: 560;
  173. margin-bottom: 10px;
  174. }
  175. }
  176. .rise-container {
  177. padding: 0 10px;
  178. .rise-name {
  179. color: #999;
  180. font-size: 18px;
  181. margin-top: 10px;
  182. }
  183. .relation-item {
  184. border-bottom: 1px solid #eae8e8;
  185. padding: 10px 0;
  186. .item-title {
  187. font-size: 16px;
  188. }
  189. .item-pic-wrap {
  190. margin-top: 10px;
  191. width: 100%;
  192. display: flex;
  193. align-items: center;
  194. justify-content: space-between;
  195. .item-pic-item {
  196. display: inline-block;
  197. width: 32%;
  198. height: 66px;
  199. img {
  200. width: 100%;
  201. height: 100%
  202. }
  203. }
  204. }
  205. }
  206. }
  207. </style>
  208. <style lang="scss">
  209. .detail-context {
  210. .album-item {
  211. width: 100%;
  212. padding: 10px;
  213. .a-image {
  214. display: inline-block;
  215. width: 100%;
  216. img {
  217. width: 100%;
  218. }
  219. }
  220. }
  221. }
  222. .click-display-all {
  223. height: 32px;
  224. line-height: 32px;
  225. text-align: center;
  226. width: 100%;
  227. font-size: 14px;
  228. color: #ff6700;
  229. background-color: #fff;
  230. font-weight: 800;
  231. .caret {
  232. display: inline-block;
  233. width: 0;
  234. height: 0;
  235. margin-left: 2px;
  236. vertical-align: middle;
  237. border-top: 4px dashed;
  238. border-top: 4px solid\9;
  239. border-right: 4px solid transparent;
  240. border-left: 4px solid transparent;
  241. }
  242. }
  243. .detail-ad-wrap {
  244. width: 100%;
  245. }
  246. </style>