话不多说上代码:
HTML
<div class="chous"> <div class="cjbj"> <div style="padding-top:8%"> <div class="ch"> <div :class="'item' + color[0]"> <img src="https://gd-hbimg.huaban.com/14cf7ebaa67b2f6b53ad88cf9a7084b4e01ca2fe216745-kveXWr_fw658webp" alt=""> <p>{{ list[0]?.name }}</p> </div> <div :class="'item' + color[1]"> <img src="https://gd-hbimg.huaban.com/14cf7ebaa67b2f6b53ad88cf9a7084b4e01ca2fe216745-kveXWr_fw658webp" alt=""> <p>{{ list[1]?.name }}</p> </div> <div :class="'item' + color[2]"> <img src="https://gd-hbimg.huaban.com/14cf7ebaa67b2f6b53ad88cf9a7084b4e01ca2fe216745-kveXWr_fw658webp" alt=""> <p>{{ list[2]?.name }}</p> </div> </div> <div class="ch"> <div :class="'item' + color[7]"> <img src="https://gd-hbimg.huaban.com/14cf7ebaa67b2f6b53ad88cf9a7084b4e01ca2fe216745-kveXWr_fw658webp" alt=""> <p>{{ list[7]?.name }}</p> </div> <img src="../assets/dianjichoujiangd.png" alt="" @click="bb"> <div :class="'item' + color[3]"> <img src="https://gd-hbimg.huaban.com/14cf7ebaa67b2f6b53ad88cf9a7084b4e01ca2fe216745-kveXWr_fw658webp" alt=""> <p>{{ list[3]?.name }}</p> </div> </div> <div class="ch"> <div :class="'item' + color[6]"> <img src="https://gd-hbimg.huaban.com/14cf7ebaa67b2f6b53ad88cf9a7084b4e01ca2fe216745-kveXWr_fw658webp" alt=""> <p>{{ list[6]?.name }}</p> </div> <div :class="'item' + color[5]"> <img src="https://gd-hbimg.huaban.com/14cf7ebaa67b2f6b53ad88cf9a7084b4e01ca2fe216745-kveXWr_fw658webp" alt=""> <p>{{ list[5]?.name }}</p> </div> <div :class="'item' + color[4]"> <img src="https://gd-hbimg.huaban.com/14cf7ebaa67b2f6b53ad88cf9a7084b4e01ca2fe216745-kveXWr_fw658webp" alt=""> <p>{{ list[4]?.name }}</p> </div> </div> </div> </div> </div>
STYLE
<style> .chous { background-image: url(../assets/k_bg.gif); width: 94%; height: 23.5rem; background-size: 100%; margin-left: 3%; } .ch { display: flex; margin-left: 6%; } .ch div img{ width: 40px; height: 40px; margin-top: 10%; } .ch div { text-align: center; margin: 2%; width: 5.625rem; height: 5.625rem; background-color: #ffffff; border-radius: 10%; box-shadow: 2px 5px; display: flex; flex-wrap: wrap; justify-content: center; } .ch div p { width: 100%; height: 18px; margin: 1%; } .ch img { width: 6.25rem; height: 6.25rem; } .item1 { background: #66ccff !important; } </style>
Vue部分:
import axios from 'axios'; import qs from 'qs'; import { ref } from 'vue' import { names } from "debug"; // import router from '@/router'; import { useRouter, useRoute } from "vue-router"; const router = useRouter(); const route = useRoute(); const titleName = ref(''); const list = ref([]) const press = ref([]) console.log(route.query.id,); console.log(route.query.eventid); var clickse = true; const color = ref([0, 0, 0, 0, 0, 0, 0, 0]); let i = -1; var int; // 定时器 var quan = 7; // 圈数 var co = 0; //记录圈数 var time = 500; // 时间 const arr = ref([]); // 空的奖池 let ar; // 获取的是一个下标 let ars; // 随机数 axios({ method: "post", //请求方式 url: "域名", //url data: qs.stringify({ // 参数 }), }).then((res) => { console.log(res.data); //成功回调 list.value = res.data.data console.log(list.value); for (let i = 0; i < list.value.length; i++) { let nus = list.value[i].chance; for (let k = 0; k < nus; k++) { arr.value.push(i); } } }) const bb = () => { if (clickse) { clickse = false; ar = Math.round(Math.random() * arr.value.length); // 获取的是一个下标 ars = arr.value[ar]; // 随机数 console.log(ar); aa() } } const aa = () => { console.log(i); // clickse.value = true // var delay = delay || 200; var timer; // isThtottle = ref(true) int = setInterval(() => { color.value[i] = 0; // 重置 i++; // 递增 // console.log(co); // 当循环完一圈到7的位置让i重置 if (i > 7) { i = 0; // 重置 co += 1; // 记录圈数 } // 第0圈到第1圈 if (co <= 1) { clearInterval(int); // 清除定时器 aa(); // 调用函数 time -= 20; // 速度加快,时间越短转的就越快 } // 第2圈到第4圈 if (co <= 4 && co > 1) { clearInterval(int); aa(); } // 第6圈到第7圈 if (co <= 7 && co > 5) { clearInterval(int); aa(); time += 30; // } // 设置的圈数,至少循环 quan 才停止 if (co == quan && i == ars) { alert('恭喜你' + list.value[i].name) clickse = true; clearInterval(int); i = -1 co = 0 } color.value[i] = 1; // 改值 }, time); };
效果: