• uni-app 九宫格抽奖活动


    一、效果图

    二、代码 

    1. <template>
    2. <view class="container">
    3. <view class="container_circle" v-for="(v,i) in circleList" :key="i"
    4. :style="{'top':v.topCircle+'rpx','left':v.leftCircle+'rpx','background-color':(i%2 ==0)?oneCircleColor:twoCircleColor}">view>
    5. <view class="container_content">
    6. <view class="content_out" v-for="(v,i) in prizeList" :key="i"
    7. :style="{'top':v.topAward+'rpx','left':v.leftAward+'rpx',
    8. 'background': (i==indexSelect)?prizeCheckColor:prizeDefaultColor,
    9. 'background-size':' 400%',
    10. 'animation': 'animatebox 4s linear infinite'
    11. }">
    12. <image class="award_image" :src="v.imgList">image>
    13. view>
    14. <view class="content_btn" @tap="handleStart" :style="{'background-color':isRunning?'#55ffff':'#f7f7f7'}">开始view>
    15. view>
    16. <view class="container_num">剩余抽奖次数{{luckDrawNum}}view>
    17. view>
    18. template>
    19. <script>
    20. export default {
    21. data() {
    22. return {
    23. circleList:[], // 圆圈数组
    24. prizeList:[], // 奖品数组
    25. oneCircleColor:'#29f5ff', // 圆圈颜色1
    26. twoCircleColor:'#aaaaff', // 圆圈颜色2
    27. prizeDefaultColor:'#FFF', // 奖品的默认颜色
    28. prizeCheckColor:'linear-gradient(72.5deg, #aa0000, #ff0000, #ff00ff, #550000, #ffaaff, #aa0000, #ff0000)', // 奖品的选中颜色
    29. indexSelect: 0, //被选中的奖品index
    30. isRunning: false, //是否正在抽奖
    31. //奖品图片数组
    32. imgList:[
    33. 'https://cdn.cnbj1.fds.api.mi-img.com/nr-pub/202209261921_a1b840c267bd26bcf4dc654d52f259e5.png?w=800&h=800',
    34. 'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/0bcd64f412dfb5e15695fa96d21ecb23.png?w=800&h=800',
    35. 'https://cdn.cnbj1.fds.api.mi-img.com/nr-pub/202208111030_e3554c41e0484da99b16bb9e02142e68.png?w=800&h=800',
    36. 'https://cdn.cnbj0.fds.api.mi-img.com/b2c-shopapi-pms/pms_1653393310.29013051.png',
    37. 'https://cdn.cnbj1.fds.api.mi-img.com/nr-pub/202209261921_a1b840c267bd26bcf4dc654d52f259e5.png?w=800&h=800',
    38. 'https://cdn.cnbj0.fds.api.mi-img.com/b2c-shopapi-pms/9E253411E26FD16C7215D7E74321FA45.png',
    39. 'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/cc0be95d45d0063b0aa8bb541be22c77.png?w=800&h=800',
    40. 'https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/0c4b5e30d14ca8b51dc6fa6917295ff5.png?w=800&h=800'
    41. ],
    42. luckDrawNum:2 ,//剩余抽奖次数
    43. repeat:true
    44. };
    45. },
    46. onLoad() {
    47. //圆点设置
    48. let topCircle = 7.5;
    49. let leftCircle = 7.5;
    50. let circleList = [];
    51. for(let i = 0; i < 24; i++) {
    52. if(i == 0) {
    53. topCircle = 15;
    54. leftCircle = 15;
    55. }else if (i < 6) {
    56. topCircle = 7.5;
    57. leftCircle += 102.5;
    58. }else if (i == 6) {
    59. topCircle = 15;
    60. leftCircle = 620;
    61. }else if (i < 12) {
    62. topCircle += 94;
    63. leftCircle = 620;
    64. }else if (i == 12) {
    65. topCircle = 565;
    66. leftCircle = 620;
    67. }else if (i < 18) {
    68. topCircle = 570;
    69. leftCircle-= 102.5;
    70. }else if (i == 18) {
    71. topCircle = 565;
    72. leftCircle = 15;
    73. }else if (i < 24) {
    74. topCircle -= 94;
    75. leftCircle = 7.5;
    76. }else {
    77. return;
    78. }
    79. circleList.push({ topCircle, leftCircle });
    80. }
    81. this.circleList = circleList;
    82. //圆点闪烁
    83. setInterval(()=> {
    84. if (this.oneCircleColor == '#29f5ff') {
    85. this.oneCircleColor = '#aaaaff';
    86. this.twoCircleColor = '#29f5ff';
    87. } else {
    88. this.oneCircleColor = '#29f5ff';
    89. this.twoCircleColor = '#aaaaff';
    90. }
    91. },500)
    92. let prizeList = [];
    93. //间距,怎么顺眼怎么设置吧.
    94. let topAward = 25;
    95. let leftAward = 25;
    96. for (let j = 0; j < 8; j++) {
    97. if (j == 0) {
    98. topAward = 25;
    99. leftAward = 25;
    100. } else if (j < 3) {
    101. topAward = topAward;
    102. //166.6666是宽.15是间距.下同
    103. leftAward = leftAward + 166.6666 + 15;
    104. } else if (j < 5) {
    105. leftAward = leftAward;
    106. //150是高,15是间距,下同
    107. topAward = topAward + 150 + 15;
    108. } else if (j < 7) {
    109. leftAward = leftAward - 166.6666 - 15;
    110. topAward = topAward;
    111. } else if (j < 8) {
    112. leftAward = leftAward;
    113. topAward = topAward - 150 - 15;
    114. }
    115. let imgList = this.imgList[j];
    116. prizeList.push({ topAward, leftAward,imgList});
    117. }
    118. this.prizeList = prizeList;
    119. },
    120. methods:{
    121. // 点击开始
    122. handleStart(){
    123. if (this.isRunning) return;
    124. if (this.luckDrawNum != 0) {
    125. this.luckDrawNum--
    126. } else{
    127. uni.showModal({
    128. title: '提示',
    129. content: '分享获取抽奖次数',
    130. showCancel: false,
    131. success: (res)=> {
    132. if (res.confirm) {
    133. }
    134. }
    135. });
    136. this.indexSelect = 0
    137. return
    138. }
    139. this.isRunning = true;
    140. let indexSelect = 0;
    141. let i = 0;
    142. let timer = setInterval(()=> {
    143. indexSelect++;
    144. i += 30;
    145. let randomNum = 1000+Math.ceil(Math.random()*1000)//控制奖品
    146. if (i > randomNum) {
    147. //去除循环
    148. clearInterval(timer);
    149. //获奖提示
    150. uni.showModal({
    151. title: '恭喜您',
    152. content: '获得了第' + (this.indexSelect + 1) + '个奖品',
    153. showCancel: false,
    154. success: (res)=> {
    155. if (res.confirm) {
    156. this.isRunning = false;
    157. }
    158. }
    159. });
    160. }
    161. indexSelect = indexSelect % 8;
    162. this.indexSelect = indexSelect;
    163. },200 + i)
    164. }
    165. }
    166. }
    167. script>
    168. <style lang="scss">
    169. .container {
    170. position: relative;
    171. height: 600rpx;
    172. width: 650rpx;
    173. margin: 100rpx auto;
    174. border-radius: 40rpx;
    175. background: linear-gradient(72.5deg, #e9f78c, #ffffb9, #cc55e5, #ef9bcb, #e5b8d8, #ffb140, #f7ed54);
    176. background-size: 400%;
    177. animation: animatebox 4s linear infinite;
    178. @keyframes animatebox {
    179. 0% {
    180. background-position: 0%;
    181. }
    182. 50% {
    183. background-position: 100%;
    184. }
    185. 100% {
    186. background-position: 0%;
    187. }
    188. }
    189. .container_circle {
    190. position: absolute;
    191. display: block;
    192. border-radius: 50%;
    193. height: 20rpx;
    194. width: 20rpx;
    195. }
    196. .container_content{
    197. position: absolute;
    198. left: 0;
    199. right: 0;
    200. top: 0;
    201. bottom: 0;
    202. width: 580rpx;
    203. height: 530rpx;
    204. background-color: #b375ff;
    205. border-radius: 40rpx;
    206. margin: auto;
    207. background: linear-gradient(72.5deg, #ef499c, #cc55e5, #ffb140, #f7ed54, #ffb140, #cc55e5, #ef499c);
    208. background-size: 400%;
    209. animation: animate1 4s linear infinite;
    210. @keyframes animate1 {
    211. 0% {
    212. background-position: 0%;
    213. }
    214. 50% {
    215. background-position: 100%;
    216. }
    217. 100% {
    218. background-position: 0%;
    219. }
    220. }
    221. .content_out{
    222. position: absolute;
    223. height: 150rpx;
    224. width: 166.6666rpx;
    225. background-color: #f5f0fc;
    226. border-radius: 15rpx;
    227. box-shadow: 0 5px 0 #d87fde;
    228. .award_image{
    229. position: absolute;
    230. margin: auto;
    231. top: 0;
    232. left: 0;
    233. bottom: 0;
    234. right: 0;
    235. height: 140rpx;
    236. width: 130rpx;
    237. }
    238. }
    239. .content_btn{
    240. position: absolute;
    241. top: 50%;
    242. left: 50%;
    243. transform: translate(-50%,-50%);
    244. border-radius: 15rpx;
    245. height: 150rpx;
    246. width: 166.6666rpx;
    247. background-color: #ffe400;
    248. box-shadow: 0 5rpx 0 #e7930a;
    249. color: #b375ff;
    250. text-align: center;
    251. font-size: 55rpx;
    252. font-weight: bolder;
    253. line-height: 150rpx;
    254. background: linear-gradient(72.5deg, #f7a0ec, #ffb140, #e58da0, #ef7ecb, #ab9ae5, #ffec8a, #f6f7a6);
    255. background-size: 400%;
    256. animation: animate 4s linear infinite;
    257. @keyframes animate {
    258. 0% {
    259. background-position: 0%;
    260. }
    261. 50% {
    262. background-position: 100%;
    263. }
    264. 100% {
    265. background-position: 0%;
    266. }
    267. }
    268. }
    269. }
    270. .container_num{
    271. position: absolute;
    272. top: -60rpx;
    273. left: 50%;
    274. transform: translateX(-50%);
    275. background-image: -webkit-linear-gradient(left, #083a96, #e63609 25%, #083a96 50%, #e63609 75%, #083a96);
    276. -webkit-text-fill-color: transparent;
    277. background-clip: text;
    278. background-size: 200% 100%;
    279. animation: masked-animation 4s infinite linear;
    280. @keyframes masked-animation {
    281. 0%{ background-position: 0 0;}
    282. 100% { background-position: -100% 0;}
    283. }
    284. }
    285. }
    286. style>

     

  • 相关阅读:
    android 11 供第三方应用使用系统so库
    SpringMVC基础:拦截器
    RxJava(二)-转换操作符
    SBT 综述
    统计信号处理基础 习题解答6-4
    MySQL之数据查询(WHERE)
    【Python小程序】浮点矩阵加减法
    [附源码]计算机毕业设计springboot学生综合数据分析系统
    C++之泛型编程
    Flutter小功能实现-咖啡店
  • 原文地址:https://blog.csdn.net/Tianxiaoxixi/article/details/127422927