大转盘调试

This commit is contained in:
tcubic 2022-08-05 17:45:13 +08:00
parent 5eff916173
commit 4b9f4586c8
2 changed files with 512 additions and 216 deletions

View File

@ -0,0 +1,280 @@
<template>
<div class="LuckyWheelCon" @touchmove.prevent>
<div class="LuckyWheel_container">
<div class="LuckyWheel_box">
<div class="prize p-1" ref="p1"></div>
<div class="prize p-2" ref="p2"></div>
<div class="prize p-3" ref="p3"></div>
<div class="prize p-4" ref="p4"></div>
<div class="prize p-5" ref="p5"></div>
<div class="prize p-1" ref="p6"></div>
<div class="prize p-2" ref="p7"></div>
<div class="prize p-3" ref="p8"></div>
<div class="prize p-4" ref="p9"></div>
<div class="prize p-5" ref="p10"></div>
<div class="prize p-1" ref="p11"></div>
<div class="prize p-2" ref="p12"></div>
<div class="prize p-3" ref="p13"></div>
<div class="prize p-4" ref="p14"></div>
<div class="prize p-5" ref="p15"></div>
<div class="prize p-5" ref="p16"></div>
<div class="prize p-5" ref="p17"></div>
<div class="prize p-5" ref="p18"></div>
<div class="prize p-5" ref="p19"></div>
<!-- <div class="prize p-3" ref="p20"></div> -->
</div>
<!-- <div class="btn" @click="btn">开始抽奖</div> -->
</div>
</div>
</template>
<script setup>
import {
onBeforeMount,
onMounted,
defineEmits,
defineProps,
reactive,
ref,
toRefs,
defineExpose,
} from "vue";
import gsap from "gsap";
import axios from "axios";
import { Toast } from "vant";
import { useStore } from "vuex";
// import { PixiPlugin } from "gsap/PixiPlugin.js";
import { MotionPathPlugin } from "gsap/MotionPathPlugin.js";
// import { MorphSVGPlugin } from "gsap/MorphSVGPlugin";
gsap.registerPlugin(MotionPathPlugin);
//
const emit = defineEmits(["luckyWheel"]); //
const props = defineProps({ sendMessage: Object }); // props
const store = useStore();
const p1 = ref(null);
const p2 = ref(null);
const p3 = ref(null);
const p4 = ref(null);
const p5 = ref(null);
const p6 = ref(null);
const p7 = ref(null);
const p8 = ref(null);
const p9 = ref(null);
const p10 = ref(null);
const p11 = ref(null);
const p12 = ref(null);
const p13 = ref(null);
const p14 = ref(null);
const p15 = ref(null);
const p16 = ref(null);
const p17 = ref(null);
const p18 = ref(null);
const p19 = ref(null);
const aniGroup = ref([]);
const eqcode = ref(require("../assets/img/pop/eqcode.png"));
const luckyWheelStatus = ref(false);
//
const isStop = () => {
if (!luckyWheelStatus.value) {
luckyWheelStatus.value = true;
console.log("大转盘结束");
emit('luckyWheel') //
}
};
//
onBeforeMount(() => {});
onMounted(() => {
showDrawAni();
});
// bingo index pArrindex
const showDrawAni = (bingo, repeat) => {
const pArr = [
p1, // 1.08
p2, // 2.68
p3, // 6.66
p4, // 8.88
p5, //
p6, // 便
p7,
p8,
p9,
p10,
p11,
p12,
p13,
p14,
p15,
p16,
p17,
p18,
p19,
];
const singleRate = 1 / pArr.length; //
const delta = singleRate + 0.068; //
let rotateDelta = 0; // |
if (bingo) {
rotateDelta = (5 - bingo) * singleRate;
}
for (let i = 1; i < pArr.length + 1; i++) {
let ani = gsap.to(
[pArr[i - 1].value],
{
duration: 10,
paused: bingo ? false : true, //
// repeat: -1,
// delay: i * 0.5 - 1,
// stagger: 0.5,
// repeatDelay: 3,
// yoyo: true,
ease: "back.out(1.4)",
motionPath: {
path: "M115.37,73.45C177.05-25.14,462-22.69,535,70,686.45,248.93,797.17,321.7,324.48,321.7-121,321.7-20.39,248.93,115.37,73.45Z",
// align: [1, 1],
autoRotate: true,
start: i * singleRate + rotateDelta - delta, // 0-1
end: i * singleRate + 1 + rotateDelta - delta, // 0-
offsetX: -177,
offsetY: -43,
alignOrigin: [0.5, 0],
},
onUpdate: () => {
// if (i === 1) console.log(ani.progress());
},
onStart: () => {
if (i == pArr.length - 1) {
setTimeout(() => {
// console.log("2");
isStop()
}, 5000);
}
},
onComplete: () => {},
},
"same"
);
//
ani.seek(0);
if (bingo && repeat) {
setTimeout(() => {
showDrawAni(bingo, false);
}, 800);
}
}
};
const btn = () => {
console.log("抽奖");
// ID
// 1 - 1.08
// 2 - 2.68
// 3 - 6.66
// 4 - 8.88
// 5 -
// id, fasle
showDrawAni(2, true);
};
//
defineExpose({
showDrawAni,
});
</script>
<style lang="scss" scoped>
.LuckyWheelCon {
width: 100%;
height: 800px;
position: absolute;
top: 0;
left: 0;
pointer-events: none;
.LuckyWheel_container {
position: absolute;
top: 770px;
left: 0px;
width: 760px;
height: 500px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
.LuckyWheel_box {
width: 760px;
height: 500px;
// // border-width: 123px;
// border-style: solid;
// border-radius: 50%;
// // box-shadow: -1.569px -17.932px 16px 0px rgba(234, 6, 16, 0.16);
// width: 831px;
// height: 305px;
// width: 100%;
// height: 100%;
// position: absolute;
// top: 0;
// left: 20px;
.li {
width: 100px;
height: 100px;
background-color: #ff6000;
}
}
.btn {
width: 200px;
height: 100px;
text-align: center;
line-height: 100px;
font-size: 30px;
color: #fff;
background: #ff6000;
}
}
.prize {
position: absolute;
width: 160px;
height: 96px;
left: 0px;
top: 10px;
//
&.p-1 {
background-image: url("~@/assets/img/p_1.png");
background-size: 160px 96px;
}
&.p-2 {
background-image: url("~@/assets/img/p_2.png");
background-size: 160px 96px;
}
&.p-3 {
background-image: url("~@/assets/img/p_3.png");
background-size: 160px 96px;
}
&.p-4 {
background-image: url("~@/assets/img/p_4.png");
background-size: 160px 96px;
}
&.p-5 {
background-image: url("~@/assets/img/p_5.png");
background-size: 160px 96px;
}
// background-color: #f00;
}
}
</style>

View File

@ -1,44 +1,56 @@
<template> <template>
<div class="LuckyWheelCon" @touchmove.prevent> <div class="LuckyWheelCon" @touchmove.prevent>
<div class="LuckyWheel_container"> <div class="LuckyWheel_container">
<div class="LuckyWheel_box"> <!-- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 665.32 321.7">
<div class="prize p-1" ref="p1"></div> <g id="图层_2" data-name="图层 2">
<div class="prize p-2" ref="p2"></div> <path
<div class="prize p-3" ref="p3"></div> id="path"
<div class="prize p-4" ref="p4"></div> ref="path"
<div class="prize p-5" ref="p5"></div> class="cls-1"
<div class="prize p-1" ref="p6"></div> d="M129.65,82.55c69.31-110.8,389.54-108,471.58-3.88,170.2,201.08,294.62,282.86-236.59,282.86C-136,361.53-22.92,279.75,129.65,82.55Z"
<div class="prize p-2" ref="p7"></div> />
<div class="prize p-3" ref="p8"></div> </g>
<div class="prize p-4" ref="p9"></div> </svg> -->
<div class="prize p-5" ref="p10"></div> <div class="LuckyWheel_box">
<div class="prize p-1" ref="p11"></div> <div class="prize p-1" ref="p1"></div>
<div class="prize p-2" ref="p12"></div> <div class="prize p-2" ref="p2"></div>
<div class="prize p-3" ref="p13"></div> <div class="prize p-3" ref="p3"></div>
<div class="prize p-4" ref="p14"></div> <div class="prize p-4" ref="p4"></div>
<div class="prize p-5" ref="p15"></div> <div class="prize p-5" ref="p5"></div>
<div class="prize p-5" ref="p16"></div> <div class="prize p-1" ref="p6"></div>
<div class="prize p-5" ref="p17"></div> <div class="prize p-2" ref="p7"></div>
<div class="prize p-5" ref="p18"></div> <div class="prize p-3" ref="p8"></div>
<div class="prize p-5" ref="p19"></div> <div class="prize p-4" ref="p9"></div>
<!-- <div class="prize p-3" ref="p20"></div> --> <div class="prize p-5" ref="p10"></div>
</div> <div class="prize p-1" ref="p11"></div>
<!-- <div class="btn" @click="btn">开始抽奖</div> --> <div class="prize p-2" ref="p12"></div>
<div class="prize p-3" ref="p13"></div>
<div class="prize p-4" ref="p14"></div>
<div class="prize p-5" ref="p15"></div>
<div class="prize p-5" ref="p16"></div>
<div class="prize p-5" ref="p17"></div>
<div class="prize p-5" ref="p18"></div>
<div class="prize p-5" ref="p19"></div>
<!-- <div class="prize p-3" ref="p20"></div> -->
</div>
</div> <!-- 对照div 重点 -->
</div> <div class="relative-box" ref="container"></div>
<div class="btn" @click="btn">开始抽奖</div>
</div>
</div>
</template> </template>
<script setup> <script setup>
import { import {
onBeforeMount, onBeforeMount,
onMounted, onMounted,
defineEmits, defineEmits,
defineProps, defineProps,
reactive, reactive,
ref, ref,
toRefs, toRefs,
defineExpose,
} from "vue"; } from "vue";
import gsap from "gsap"; import gsap from "gsap";
import axios from "axios"; import axios from "axios";
@ -48,11 +60,10 @@ import { useStore } from "vuex";
// import { PixiPlugin } from "gsap/PixiPlugin.js"; // import { PixiPlugin } from "gsap/PixiPlugin.js";
import { MotionPathPlugin } from "gsap/MotionPathPlugin.js"; import { MotionPathPlugin } from "gsap/MotionPathPlugin.js";
// import { MorphSVGPlugin } from "gsap/MorphSVGPlugin"; // import { MorphSVGPlugin } from "gsap/MorphSVGPlugin";
gsap.registerPlugin(MotionPathPlugin); gsap.registerPlugin(MotionPathPlugin);
// //
const emit = defineEmits(["luckyWheel"]); // const emit = defineEmits(["ServicePop"]); //
const props = defineProps({ sendMessage: Object }); // props const props = defineProps({ sendMessage: Object }); // props
const store = useStore(); const store = useStore();
const p1 = ref(null); const p1 = ref(null);
@ -75,206 +86,211 @@ const p17 = ref(null);
const p18 = ref(null); const p18 = ref(null);
const p19 = ref(null); const p19 = ref(null);
const aniGroup = ref([]); const aniGroup = ref([]);
const container = ref();
const eqcode = ref(require("../assets/img/pop/eqcode.png")); const eqcode = ref(require("../assets/img/pop/eqcode.png"));
const luckyWheelStatus = ref(false);
//
const isStop = () => {
if (!luckyWheelStatus.value) {
luckyWheelStatus.value = true;
console.log("大转盘结束");
emit('luckyWheel') //
}
};
// //
onBeforeMount(() => {}); onBeforeMount(() => {});
onMounted(() => { onMounted(() => {
showDrawAni(); // div便
const fontSize = getComputedStyle(window.document.documentElement)[
"font-size"
].replace("px", "");
const ratio = fontSize / 37.5;
// alert(fontSize);
console.log(ratio);
gsap.set(container.value, {
scale: ratio,
x:
200 * (ratio - 1) +
(ratio < 0.9 ? 10 * ratio : ratio > 1.2 ? 65 * ratio : 0),
y:
230 * (ratio - 1) +
(ratio < 0.9 ? 10 * ratio : ratio > 1.2 ? 35 * ratio : 0),
});
showDrawAni();
// let a = path.value.getBBox();
// console.log(a);
// console.log(window.innerWidth / 375);
}); });
// bingo index pArrindex // bingo index pArrindex
const showDrawAni = (bingo, repeat) => { const showDrawAni = (bingo, repeat) => {
const pArr = [
const pArr = [ p1, // 1.08
p1, // 1.08 p2, // 2.68
p2, // 2.68 p3, // 6.66
p3, // 6.66 p4, // 8.88
p4, // 8.88 p5, //
p5, // p6, // 便
p6, // 便 p7,
p7, p8,
p8, p9,
p9, p10,
p10, p11,
p11, p12,
p12, p13,
p13, p14,
p14, p15,
p15, p16,
p16, p17,
p17, p18,
p18, p19,
p19, ];
]; const singleRate = 1 / pArr.length; //
const singleRate = 1 / pArr.length; // const delta = singleRate + 0.068; //
const delta = singleRate + 0.068; // let rotateDelta = 0; // |
let rotateDelta = 0; // | if (bingo) {
if (bingo) { rotateDelta = (5 - bingo) * singleRate;
rotateDelta = (5 - bingo) * singleRate; }
} for (let i = 1; i < pArr.length + 1; i++) {
for (let i = 1; i < pArr.length + 1; i++) { let ani = gsap.to(
let ani = gsap.to( [pArr[i - 1].value],
[pArr[i - 1].value], {
{ duration: 10,
duration: 10, paused: bingo ? false : true, //
paused: bingo ? false : true, // // repeat: -1,
// repeat: -1, // delay: i * 0.5 - 1,
// delay: i * 0.5 - 1, // stagger: 0.5,
// stagger: 0.5, // repeatDelay: 3,
// repeatDelay: 3, // yoyo: true,
// yoyo: true, ease: "back.out(1.4)",
ease: "back.out(1.4)", motionPath: {
motionPath: { path: "M115.37,73.45C177.05-25.14,462-22.69,535,70,686.45,248.93,797.17,321.7,324.48,321.7-121,321.7-20.39,248.93,115.37,73.45Z",
path: "M115.37,73.45C177.05-25.14,462-22.69,535,70,686.45,248.93,797.17,321.7,324.48,321.7-121,321.7-20.39,248.93,115.37,73.45Z", align: ".relative-box", //div
// align: [1, 1], autoRotate: true,
autoRotate: true, start: i * singleRate + rotateDelta - delta, // 0-1
start: i * singleRate + rotateDelta - delta, // 0-1 end: i * singleRate + 1 + rotateDelta - delta, // 0-
end: i * singleRate + 1 + rotateDelta - delta, // 0- offsetX: -22, //-177,
offsetX: -177, offsetY: 70,
offsetY: -43, alignOrigin: [0.5, 0],
alignOrigin: [0.5, 0], },
}, onUpdate: () => {
onUpdate: () => { // if (i === 1) console.log(ani.progress());
// if (i === 1) console.log(ani.progress()); },
}, },
onStart: () => { "same"
if (i == pArr.length - 1) { );
setTimeout(() => { //
// console.log("2"); ani.seek(0);
isStop() if (bingo && repeat) {
}, 5000); setTimeout(() => {
} showDrawAni(bingo, false);
}, }, 800);
}
onComplete: () => {}, }
},
"same"
);
//
ani.seek(0);
if (bingo && repeat) {
setTimeout(() => {
showDrawAni(bingo, false);
}, 800);
}
}
}; };
const btn = () => { const btn = () => {
console.log("抽奖"); console.log("抽奖");
// ID // ID
// 1 - 1.08 // 1 - 1.08
// 2 - 2.68 // 2 - 2.68
// 3 - 6.66 // 3 - 6.66
// 4 - 8.88 // 4 - 8.88
// 5 - // 5 -
// id, fasle // id, fasle
showDrawAni(2, true); showDrawAni(1, true);
}; };
//
defineExpose({
showDrawAni,
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.LuckyWheelCon { .LuckyWheelCon {
width: 100%; width: 100%;
height: 800px; height: 100%;
position: absolute; position: fixed;
top: 0; z-index: 10;
left: 0; top: 0;
pointer-events: none; left: 0;
// right: 0;
// bottom: 0;
// display: flex;
// justify-content: center;
// align-items: center;
background-color: rgba(0, 0, 0, 0.3);
.LuckyWheel_container {
position: absolute;
top: 700px;
left: 0;
width: 750px;
height: 500px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
.LuckyWheel_container { .LuckyWheel_box {
position: absolute; // // border-width: 123px;
top: 770px; // border-style: solid;
left: 0px; // border-radius: 50%;
width: 760px; // // box-sh
height: 500px; position: absolute;
display: flex; left: 0;
justify-content: center; top: 0;
align-items: center; width: 750px;
flex-direction: column; height: 500px;
.LuckyWheel_box { .li {
width: 100px;
height: 100px;
background-color: #ff6000;
}
}
width: 760px; .relative-box {
height: 500px; position: absolute;
left: 0;
// // border-width: 123px; top: 0;
// border-style: solid; width: 750px;
// border-radius: 50%; height: 500px;
// // box-shadow: -1.569px -17.932px 16px 0px rgba(234, 6, 16, 0.16); }
// width: 831px; .cls-1 {
// height: 305px; fill: none;
}
// width: 100%; .btn {
// height: 100%; position: relative;
// position: absolute; z-index: 111;
// top: 0; width: 200px;
// left: 20px; height: 100px;
text-align: center;
.li { line-height: 100px;
width: 100px; font-size: 30px;
height: 100px; color: #fff;
background-color: #ff6000; background: #ff6000;
} }
} }
.prize {
.btn { position: absolute;
width: 200px; width: 160px;
height: 100px; height: 96px;
text-align: center; left: 0;
line-height: 100px; top: 10px;
font-size: 30px; //
color: #fff; &.p-1 {
background: #ff6000; background-image: url("~@/assets/img/p_1.png");
} background-size: 160px 96px;
} }
.prize { &.p-2 {
position: absolute; background-image: url("~@/assets/img/p_2.png");
width: 160px; background-size: 160px 96px;
height: 96px; }
left: 0px; &.p-3 {
top: 10px; background-image: url("~@/assets/img/p_3.png");
// background-size: 160px 96px;
&.p-1 { }
background-image: url("~@/assets/img/p_1.png"); &.p-4 {
background-size: 160px 96px; background-image: url("~@/assets/img/p_4.png");
} background-size: 160px 96px;
&.p-2 { }
background-image: url("~@/assets/img/p_2.png"); &.p-5 {
background-size: 160px 96px; background-image: url("~@/assets/img/p_5.png");
} background-size: 160px 96px;
&.p-3 { }
background-image: url("~@/assets/img/p_3.png"); // background-color: #f00;
background-size: 160px 96px; }
}
&.p-4 {
background-image: url("~@/assets/img/p_4.png");
background-size: 160px 96px;
}
&.p-5 {
background-image: url("~@/assets/img/p_5.png");
background-size: 160px 96px;
}
// background-color: #f00;
}
} }
</style> </style>