ad.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div class="module-item-tuwen" :style="!module.base.m ? 'margin-top:0':''">
  3. <div class="item-tuwen-con">
  4. <moduleBg :base="module.base" />
  5. <!--样式一-->
  6. <div class="item-tuwen-style1" :style="!module.base.m ? 'padding:0':''" v-if="module.base.s == 0">
  7. <ad v-if="banner_id" :unitId="banner_id"></ad>
  8. </div>
  9. <!--样式二-->
  10. <div class="item-tuwen-style2" :style="!module.base.m ? 'padding:0':''" v-if="module.base.s == 1">
  11. <div @click="bindad" class="item" :style="!module.base.m ? 'margin:0' : ''">
  12. <p v-if="module.img">
  13. <image :style="style" :src="module.img" />
  14. </p>
  15. <p v-else><img :src="$util.icon('img.jpg')" alt=""></p>
  16. <div class="note" v-if="module.note.s">
  17. <moduleText :text="module.note" />
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. import moduleBg from './bg.vue';
  26. import moduleText from './text.vue';
  27. export default {
  28. props: ['module'],
  29. components: {
  30. moduleBg,
  31. moduleText
  32. },
  33. data() {
  34. return {
  35. banner_id: '',
  36. };
  37. },
  38. computed: {
  39. style() {
  40. let style = `height:${this.module.note.h}px;`;
  41. return style;
  42. },
  43. },
  44. mounted() {
  45. this.banner_id = uni.getStorageSync("systemInfo").set.banner_id;
  46. },
  47. methods: {
  48. bindad() {
  49. let that = this;
  50. let videoAd = wx.createRewardedVideoAd({
  51. adUnitId: uni.getStorageSync("systemInfo").set.jili_id,
  52. });
  53. try {
  54. if (videoAd.closeHandler) {
  55. videoAd.offClose(videoAd.closeHandler);
  56. console.log("---videoAd.offClose 卸载成功---");
  57. }
  58. } catch (e) {
  59. console.log("---videoAd.offClose 卸载失败---");
  60. console.error(e);
  61. }
  62. videoAd.closeHandler = function(res) {
  63. // 用户点击了【关闭广告】按钮
  64. if (res && res.isEnded || res === undefined) {
  65. // 正常播放结束,可以下发奖励
  66. console.log("播放完毕");
  67. that.advertisements()
  68. } else {
  69. //提前关闭小程序
  70. uni.showToast({
  71. title: '观看结束才能获得积分喔',
  72. icon: 'none'
  73. })
  74. }
  75. };
  76. videoAd.onClose(videoAd.closeHandler);
  77. videoAd.onLoad((err) => {
  78. console.log(err, '激励视频 广告加载成功')
  79. })
  80. videoAd.onError((err) => {
  81. console.log(err, '激励视频 广告显示失败')
  82. })
  83. if (videoAd) {
  84. videoAd.show().catch(() => {
  85. // 失败重试
  86. videoAd.load()
  87. .then(() => videoAd.show())
  88. .catch(err => {
  89. console.log(err, '激励视频 广告显示失败')
  90. uni.showToast({
  91. title: '激励视频,广告显示失败',
  92. icon: 'none'
  93. })
  94. })
  95. })
  96. }
  97. },
  98. advertisements() {
  99. let params = {
  100. user_id: this.$store.state.userInfo.id,
  101. store_id: this.$store.state.store_id,
  102. }
  103. let share_user_id = uni.getStorageSync('share_user_id')
  104. if (share_user_id) {
  105. params.share_id = share_user_id
  106. }
  107. this.$http.request('yy/get_advertisements', params, "", "", true).then(res => {
  108. if (res.code == "200") {
  109. uni.showToast({
  110. title: res.message,
  111. icon: 'none'
  112. })
  113. }
  114. }).catch((res) => {});
  115. },
  116. }
  117. };
  118. </script>
  119. <style lang="less">
  120. /***图文模块***/
  121. .module-item-tuwen {
  122. margin-top: 10px;
  123. position: relative;
  124. .mg0 {
  125. margin-top: 0;
  126. }
  127. .item-tuwen-con {
  128. position: relative;
  129. overflow: hidden;
  130. }
  131. .item-tuwen-style1 {
  132. position: relative;
  133. z-index: 1;
  134. padding: 10px 0;
  135. overflow: hidden;
  136. .tit {
  137. white-space: nowrap;
  138. font-size: 14px;
  139. padding: 10px;
  140. text-align: center;
  141. overflow: hidden;
  142. text-overflow: ellipsis;
  143. }
  144. .item {
  145. margin: 0 10px;
  146. position: relative;
  147. overflow: hidden;
  148. width: auto;
  149. image {
  150. display: block;
  151. height: 150px;
  152. width: 100%;
  153. }
  154. .note {
  155. line-height: 18px;
  156. color: #fff;
  157. background: rgba(0, 0, 0, 0.5);
  158. position: absolute;
  159. bottom: 0;
  160. padding: 6px 10px;
  161. width: 100%;
  162. }
  163. }
  164. }
  165. .item-tuwen-style2 {
  166. position: relative;
  167. display: flex;
  168. flex-wrap: wrap;
  169. z-index: 1;
  170. padding: 10px 0;
  171. overflow: hidden;
  172. .item {
  173. margin: 0 10px;
  174. width: 100%;
  175. image {
  176. display: block;
  177. height: 150px;
  178. width: 100%;
  179. }
  180. .tit {
  181. white-space: nowrap;
  182. font-size: 14px;
  183. padding-top: 10px;
  184. text-align: center;
  185. overflow: hidden;
  186. text-overflow: ellipsis;
  187. }
  188. .note {
  189. line-height: 20px;
  190. color: #999;
  191. padding: 6px 10px;
  192. }
  193. }
  194. }
  195. }
  196. </style>