index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="container">
  3. <button @click="fetch">拉取激励广告</button>
  4. </div>
  5. </template>
  6. <script setup>
  7. import { ref, nextTick } from "vue"
  8. const visible = ref(true)
  9. const openId = ref('')
  10. uni.login({
  11. provider: 'weixin',
  12. success(res){
  13. uni.request({
  14. url: 'https://browse.test.caixiao365.com/userinfo',
  15. method: 'POST',
  16. data: { code: res.code },
  17. header: { 'content-type': 'application/json' },
  18. success(res){
  19. openId.value = res.data.data.openid
  20. }
  21. })
  22. }
  23. })
  24. let videoAd = null
  25. if (process.env.UNI_PLATFORM.toUpperCase() === 'MP-WEIXIN') {
  26. if (wx.createRewardedVideoAd) {
  27. videoAd = wx.createRewardedVideoAd({
  28. adUnitId: 'adunit-c90f984d29d8d175'
  29. })
  30. videoAd.onLoad(() => {
  31. console.log('自动激励视频家加载中....')
  32. })
  33. videoAd.onError(() => {
  34. console.log('自动激励视频家加载失败....')
  35. })
  36. }
  37. }
  38. function fetch(){
  39. uni.request({
  40. url: 'https://browse.test.caixiao365.com/browse',
  41. method: 'POST',
  42. data: { openId: openId.value, nickname: 'null' ,isClicks: '1' },
  43. header: { 'content-type': 'application/json' },
  44. fail(err){ console.log('记录失败', err) }
  45. })
  46. if(videoAd){
  47. videoAd.onClose((res) => {
  48. uni.request({
  49. url: 'https://browse.test.caixiao365.com/browse',
  50. method: 'POST',
  51. data: { openId: openId.value, nickname: 'null' ,isClicks: '0' },
  52. header: { 'content-type': 'application/json' },
  53. fail(err){ console.log('记录失败', err) }
  54. })
  55. })
  56. }
  57. if (videoAd) {
  58. videoAd.show().catch((res) => {
  59. videoAd.load().then(() => { videoAd.show() })
  60. })
  61. }
  62. }
  63. </script>
  64. <style lang="scss">
  65. .ad-container {
  66. min-height: 130px;
  67. height: 130px;
  68. width: 100%;
  69. margin-bottom: 10px;
  70. position: relative;
  71. }
  72. .ad-side-container {
  73. position: absolute;
  74. top:300px;
  75. z-index:999;
  76. height:200px;
  77. width:50px;
  78. &.left { left:0px; }
  79. &.right { right:0px; }
  80. }
  81. .container {
  82. position: relative;
  83. }
  84. .ad-overlay {
  85. position: absolute;
  86. top: 0;
  87. left: 0;
  88. width: 100%;
  89. height: 100%;
  90. background: transparent; /* 透明背景 */
  91. }
  92. </style>