ad.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="page" :style="{height:windowHeight}">
  3. <view class="dis j-s a-c" style="padding: 0 10px;">
  4. <view class="maskTool">
  5. <text>广告</text>
  6. <text>丨</text>
  7. <text v-if="countdownTime>0">观看{{countdownTime}}秒后获得奖励</text>
  8. <text v-else>已获得奖励</text>
  9. </view>
  10. <view class="maskTool1 dis j-s a-c">
  11. <image :src="isMuted?'../../static/img/volume1.png':'../../static/img/volume2.png'" mode=""
  12. style="width: 15px;height: 15px;" @click="isMuteds"></image>
  13. <text>丨</text>
  14. <!-- #ifdef APP -->
  15. <text @click="showAlert">关闭</text>
  16. <!-- #endif -->
  17. <text @click="showAlert1">关闭</text>
  18. </view>
  19. </view>
  20. <view class="" :style="{width:'100%',height:'calc(100% - 45px)',position: 'relative'}">
  21. <video id="myVideo" src="../../ad.mp4" autoplay controls :style="{width:'100%',height:'100%'}"
  22. :controls="true" @play="startCountdown">
  23. </video>
  24. </view>
  25. <u-modal v-model="show" content="暂未获得奖励,是否继续观看视频"></u-modal>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. countdownTime: 30,
  33. windowHeight: "",
  34. isMuted: true,
  35. show: false,
  36. }
  37. },
  38. onShow() {
  39. // 确保视频元素存在
  40. this.$nextTick(() => {
  41. this.video = document.getElementById('myVideo');
  42. });
  43. },
  44. onLoad() {
  45. const res = uni.getSystemInfoSync();
  46. this.windowHeight = res.windowHeight + 'px';
  47. },
  48. methods: {
  49. isMuteds() {
  50. this.isMuted = !this.isMuted;
  51. this.video.muted = this.isMuted;
  52. },
  53. startCountdown() {
  54. if (this.intervalId) {
  55. clearInterval(this.intervalId);
  56. }
  57. this.intervalId = setInterval(() => {
  58. if (this.countdownTime > 0) {
  59. this.countdownTime--;
  60. } else {
  61. clearInterval(this.intervalId);
  62. }
  63. }, 1000);
  64. },
  65. showAlert1() {
  66. this.show = true;
  67. },
  68. showAlert() {
  69. // 判断plus对象是否存在
  70. if (plus) {
  71. // 创建一个提示窗
  72. plus.nativeUI.alert('这是一个弹窗', function() {});
  73. } else {
  74. // 非App环境的处理逻辑
  75. alert('这是一个浏览器的弹窗');
  76. }
  77. }
  78. },
  79. beforeDestroy() {
  80. if (this.intervalId) {
  81. clearInterval(this.intervalId);
  82. }
  83. }
  84. }
  85. </script>
  86. <style>
  87. page {
  88. background-color: #000;
  89. }
  90. </style>
  91. <style lang="scss" scoped>
  92. .page {
  93. padding-top: 20px;
  94. background-color: #000;
  95. }
  96. .maskTool {
  97. border: 1px solid #999;
  98. height: auto;
  99. color: #fff;
  100. border-radius: 20px;
  101. padding: 5px 10px;
  102. }
  103. .maskTool1 {
  104. border: 1px solid #999;
  105. height: auto;
  106. color: #fff;
  107. border-radius: 20px;
  108. padding: 5px 10px;
  109. }
  110. </style>