Browse Source

修改旋转节奏

milestone-20250826-财富金轮
zhaoruhui 3 days ago
parent
commit
1a722cc1a1
  1. 57
      src/views/wealth/goldenWheel.vue

57
src/views/wealth/goldenWheel.vue

@ -161,11 +161,12 @@ export default {
showNoTimesModal: false, showNoTimesModal: false,
showRuleModal: false, showRuleModal: false,
isFirstVisit: true, isFirstVisit: true,
currentRotation: -23.5, // -22.5
currentRotation: -22.5, // -22.5
noTimesTimer: null, noTimesTimer: null,
prizeMessage: '', prizeMessage: '',
prizeAmount: '', prizeAmount: '',
textWidth: 0
textWidth: 0,
targetRotation: 0 //
} }
}, },
computed: { computed: {
@ -309,6 +310,37 @@ export default {
} }
}, },
//
calculateRandomStop() {
// 845
const sectorDegrees = 45;
// (0-7)
const randomSector = Math.floor(Math.random() * 8);
// (-22.5)
// = * 45 - 22.5
const targetAngle = randomSector * sectorDegrees - 22.5;
//
// 3-5
const extraRotations = 5 + Math.floor(Math.random() * 3); // 3-5
const extraDegrees = extraRotations * 360;
//
//
//
let rotationNeeded = targetAngle - this.currentRotation;
// 360使
if (rotationNeeded < 0) {
rotationNeeded += 360;
}
//
return this.currentRotation + rotationNeeded + extraDegrees;
},
// //
async handleSpin() { async handleSpin() {
if (this.showRuleModal || this.isFirstVisit || this.isSpinning) return; if (this.showRuleModal || this.isFirstVisit || this.isSpinning) return;
@ -331,9 +363,14 @@ export default {
// //
this.isSpinning = true; this.isSpinning = true;
// -22.5
const newRotation = this.currentRotation + 1440;
this.currentRotation = newRotation;
//
this.targetRotation = this.calculateRandomStop();
// CSS
document.documentElement.style.setProperty('--target-rotation', `${this.targetRotation}deg`);
//
this.currentRotation = this.targetRotation;
// API // API
const success = await this.fetchPrizeInfo(); const success = await this.fetchPrizeInfo();
@ -538,7 +575,7 @@ export default {
} }
.wheel-img.spinning { .wheel-img.spinning {
animation: optimal-spin 3s cubic-bezier(0.17, 0.67, 0.21, 0.98) forwards;
animation: optimal-spin 3s cubic-bezier(0.47, 0.57, 0.45, 0.15) forwards;
backface-visibility: hidden; backface-visibility: hidden;
transform: translateZ(0); transform: translateZ(0);
} }
@ -547,8 +584,14 @@ export default {
0% { 0% {
transform: rotate(-22.5deg); /* 从-22.5度开始旋转 */ transform: rotate(-22.5deg); /* 从-22.5度开始旋转 */
} }
20% {
transform: rotate(calc(-22.5deg + (var(--target-rotation, 1440deg) + 22.5deg) * 0.2)); /* 加速阶段 */
}
80% {
transform: rotate(calc(-22.5deg + (var(--target-rotation, 1440deg) + 22.5deg) * 0.8)); /* 减速阶段 */
}
100% { 100% {
transform: rotate(1417.5deg); /* 1440 - 22.5 = 1417.5度 */
transform: rotate(var(--target-rotation, 1417.5deg)); /* 使用CSS变量控制最终旋转角度 */
} }
} }

Loading…
Cancel
Save