index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="q-t-main">
  3. <view :class="{'q-t-rotation':true, 'isEnd': isEnd, 'isReset': isReset}" :style="{transform: `rotate(${rotation}deg)`}">
  4. <view class="item"
  5. v-for="(item,index) in content" :key="item.id"
  6. :style="{transform: `rotate(${itemDeg*index}deg) translateX(${leftParam}rpx)`}"
  7. >
  8. <view :style="{border: `${borderParam}rpx solid transparent`}">
  9. <image :src="item.prize_img"/>
  10. <text>{{item.name}}</text>
  11. </view>
  12. </view>
  13. <image class="circle" :src="big_wheel_disc"/>
  14. </view>
  15. <image class="button" :src="big_wheel_button" @click="start"/>
  16. </view>
  17. </template>
  18. <script>
  19. export default{
  20. components:{
  21. },
  22. props:["drawProducts", "big_wheel_disc", "big_wheel_button", "isValid"],
  23. data(){
  24. return {
  25. content: [],
  26. rotation: 0,
  27. timer: 0,
  28. isEnd: false,
  29. isRotation:false,
  30. isReset: false
  31. }
  32. },
  33. computed:{
  34. itemDeg(){
  35. if(!this.content.length) return 0;
  36. return 360 / this.content.length;
  37. },
  38. borderParam(){
  39. return Math.tan(this.itemDeg/2 * Math.PI / 180)*250
  40. },
  41. leftParam(){
  42. return 250 - this.borderParam;
  43. }
  44. },
  45. methods:{
  46. init(list){
  47. this.content = [...list];
  48. },
  49. start(){
  50. if(this.isEnd||this.isRotation || !this.isValid) return;
  51. this.$emit("start");
  52. this.rotation = -360;
  53. this.isRotation = true;
  54. this.timer = setInterval(()=>{
  55. this.rotation -= 360;
  56. }, 900)
  57. },
  58. end(index){
  59. const endDeg = this.rotation - this.itemDeg * index - 360
  60. clearInterval(this.timer);
  61. this.isEnd = true;
  62. this.rotation = endDeg;
  63. this.isRotation = false;
  64. return new Promise((resolve,reject)=>{
  65. setTimeout(()=>{
  66. resolve(true);
  67. }, 2500)
  68. })
  69. },
  70. reset(){
  71. this.isEnd = false;
  72. this.isReset = true;
  73. this.rotation = 0;
  74. setTimeout(()=>{
  75. this.isReset = false;
  76. },100)
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. .q-t-main{
  83. width: 100%;
  84. height:500rpx;
  85. text-align: center;
  86. overflow: hidden;
  87. .q-t-rotation{
  88. margin:0 auto;
  89. width: 500rpx;
  90. height:500rpx;
  91. overflow: hidden;
  92. border-radius: 100%;
  93. transition: 1s all linear;
  94. // animation: rotation 1s linear infinite;
  95. >image{
  96. &.circle{
  97. position: relative;
  98. z-index: 1;
  99. width: 100%;
  100. height: 100%;
  101. }
  102. }
  103. &.isEnd{
  104. transition: 2.5s all ease-out;
  105. }
  106. &.isReset{
  107. transition: 0s all!important;
  108. }
  109. .item{
  110. transform-origin: 250rpx 250rpx;
  111. width: 0px;
  112. height:0px;
  113. overflow: visible;
  114. > view {
  115. border-bottom: 250rpx solid transparent!important;
  116. image{
  117. width: 72rpx;
  118. height: 86rpx;
  119. -webkit-transform: translate(-36rpx, -207rpx);
  120. transform: translate(-36rpx, -207rpx);
  121. }
  122. text{
  123. width: 80rpx;
  124. -webkit-transform: translate(-40rpx, -214rpx);
  125. transform: translate(-40rpx, -214rpx);
  126. color: #A8872A;
  127. display: block;
  128. font-size: 22rpx;
  129. font-weight: bold;
  130. line-height: 25rpx;
  131. }
  132. }
  133. }
  134. .item:nth-of-type(odd) > view{
  135. width: 0px;
  136. height:0px;
  137. border-top: 250rpx solid #F9EABA!important;
  138. }
  139. .item:nth-of-type(even) > view{
  140. width: 0px;
  141. height:0px;
  142. border-top: 250rpx solid #FBF9F3!important;
  143. }
  144. }
  145. }
  146. image.button{
  147. position: relative;
  148. z-index: 2;
  149. width: 100rpx;
  150. height: 113rpx;
  151. top: -316rpx;
  152. }
  153. @keyframes rotation {
  154. from{
  155. transform: rotate(0deg);
  156. }
  157. to{
  158. transform: rotate(360deg);
  159. }
  160. }
  161. </style>