advertise.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="content">
  3. <view class="con" :style="{width: windowWidth + 'px',height: windowHeight + 'px' }"><image :src="imgSrc" mode="scaleToFill" > </image></view>
  4. <view class="btn" id="timer">
  5. <view id="info"> </view>
  6. <view class="circleProgress_wrapper btn">
  7. <view class="wrapper right"><view class="circleProgress rightcircle"></view></view>
  8. <view class="wrapper left"><view class="circleProgress leftcircle"></view></view>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. import { getAdvertisement } from '@/api/home.js';
  15. function getRandom(start, end, fixed = 0) {
  16. let differ = end - start;
  17. let random = Math.random();
  18. return (start + differ * random).toFixed(fixed);
  19. }
  20. export default {
  21. data() {
  22. return {
  23. imgSrc: '',
  24. windowWidth: 0,
  25. windowHeight: 0
  26. };
  27. },
  28. onLoad() {
  29. const res = uni.getSystemInfoSync();
  30. this.windowWidth = res.windowWidth;
  31. this.windowHeight = res.windowHeight;
  32. this.init();
  33. },
  34. methods: {
  35. init() {
  36. getAdvertisement().then(res => {
  37. if (res.statusCode === 200) {
  38. const ads = res.data[getRandom(0, res.data.length - 1)];
  39. this.imgSrc = ads.pic_url;
  40. console.warn(this.imgSrc);
  41. }
  42. });
  43. }
  44. }
  45. };
  46. </script>
  47. <style lang="less" scoped>
  48. .content {
  49. width: 100%;
  50. height: 100%;
  51. .con {
  52. display: flex;
  53. align-items: center;
  54. image {
  55. width: 100%;
  56. height: 100%;
  57. }
  58. }
  59. }
  60. #timer {
  61. display: inline-block;
  62. position: fixed;
  63. top: 40px;
  64. right: 10px;
  65. }
  66. #info {
  67. position: absolute;
  68. top: 0;
  69. left: 0;
  70. width: 36px;
  71. height: 36px;
  72. line-height: 36px;
  73. border-radius: 50%;
  74. background-color: rgba(0, 0, 0, 0.3);
  75. text-align: center;
  76. color: #ffffff;
  77. font-size: 12px;
  78. }
  79. .circleProgress_wrapper {
  80. width: 36px;
  81. height: 36px;
  82. position: relative;
  83. }
  84. .wrapper {
  85. width: 18px;
  86. height: 36px;
  87. position: absolute;
  88. top: 0;
  89. overflow: hidden;
  90. }
  91. .right {
  92. right: 0;
  93. }
  94. .left {
  95. left: 0;
  96. }
  97. .circleProgress {
  98. width: 32px;
  99. height: 32px;
  100. border: 2px solid #ffffff;
  101. border-radius: 50%;
  102. position: absolute;
  103. top: 0;
  104. -webkit-transform: rotate(45deg);
  105. }
  106. .rightcircle {
  107. border-top: 2px solid #03a9f4;
  108. border-right: 2px solid #03a9f4;
  109. right: 0;
  110. -webkit-animation: circleProgressLoad_right 4s linear;
  111. /*动画停留在最后一帧*/
  112. animation-fill-mode: forwards;
  113. -moz-animation-fill-mode: forwards;
  114. -webkit-animation-fill-mode: forwards;
  115. -o-animation-fill-mode: forwards;
  116. }
  117. .leftcircle {
  118. border-bottom: 2px solid #03a9f4;
  119. border-left: 2px solid #03a9f4;
  120. left: 0;
  121. -webkit-animation: circleProgressLoad_left 4s linear;
  122. /*动画停留在最后一帧*/
  123. animation-fill-mode: forwards;
  124. -moz-animation-fill-mode: forwards;
  125. -webkit-animation-fill-mode: forwards;
  126. -o-animation-fill-mode: forwards;
  127. }
  128. @-webkit-keyframes circleProgressLoad_right {
  129. 0% {
  130. border-top: 2px solid #03a9f4;
  131. border-right: 2px solid #03a9f4;
  132. -webkit-transform: rotate(45deg);
  133. }
  134. 50% {
  135. border-top: 2px solid #03a9f4;
  136. border-right: 2px solid #03a9f4;
  137. border-left: 2px solid #ffffff;
  138. border-bottom: 2px solid #ffffff;
  139. -webkit-transform: rotate(225deg);
  140. }
  141. 100% {
  142. border-left: 2px solid #ffffff;
  143. border-bottom: 2px solid #ffffff;
  144. -webkit-transform: rotate(225deg);
  145. }
  146. }
  147. @-webkit-keyframes circleProgressLoad_left {
  148. 0% {
  149. border-bottom: 2px solid #03a9f4;
  150. border-left: 2px solid #03a9f4;
  151. -webkit-transform: rotate(45deg);
  152. }
  153. 50% {
  154. border-bottom: 2px solid #03a9f4;
  155. border-left: 2px solid #03a9f4;
  156. border-top: 2px solid #ffffff;
  157. border-right: 2px solid #ffffff;
  158. -webkit-transform: rotate(45deg);
  159. }
  160. 100% {
  161. border-top: 2px solid #ffffff;
  162. border-right: 2px solid #ffffff;
  163. -webkit-transform: rotate(225deg);
  164. }
  165. }
  166. </style>