You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
5.2 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <div class="choujiang-main">
  3. <Lottery3D ref="lottery3DRef" />
  4. <PrizePanel
  5. :prizes="dataManager.state.basicData.prizes"
  6. />
  7. <ControlBar
  8. :lottery-state="lotteryState"
  9. :is-disabled="isDisabled"
  10. @lottery-click="handleLotteryClick"
  11. @reset="handleReset"
  12. @export="handleExport"
  13. />
  14. <MusicPlayer />
  15. <!-- <UserList
  16. :lucky-users="
  17. dataManager.state.basicData.luckyUsers[
  18. dataManager.state.currentPrize?.type
  19. ] || []
  20. "
  21. :left-users="dataManager.state.basicData.leftUsers"
  22. /> -->
  23. <!-- <Qipao :text="qipaoText" :show="showQipao" /> -->
  24. </div>
  25. </template>
  26. <script setup>
  27. import Lottery3D from "./lottery/Lottery3D.vue";
  28. import PrizePanel from "./lottery/PrizePanel.vue";
  29. import ControlBar from "./lottery/ControlBar.vue";
  30. import MusicPlayer from "./lottery/MusicPlayer.vue";
  31. import Qipao from "./lottery/Qipao.vue";
  32. import UserList from "./lottery/UserList.vue";
  33. import { ref, onMounted, nextTick, computed, watch } from "vue";
  34. import { useDataManager } from "./lottery/dataManager.js";
  35. import { useLotteryEngine } from "./lottery/lotteryEngine.js";
  36. import { useLotteryStore } from "../../store/lottery"; // 路径根据实际情况调整
  37. const qipaoText = ref("");
  38. const showQipao = ref(false);
  39. // const lotteryState = ref('idle'); // idle, ready, rotating, result
  40. // 新增
  41. const lotteryStore = useLotteryStore();
  42. const lotteryState = computed({
  43. get: () => lotteryStore.lotteryState,
  44. set: (val) => lotteryStore.setLotteryState(val),
  45. });
  46. const isDisabled = ref(false);
  47. watch(isDisabled, (newVal, oldVal) => {
  48. console.log("isDisabled 变化:", oldVal, "->", newVal);
  49. });
  50. // 数据与抽奖主流程
  51. const dataManager = useDataManager();
  52. let lottery3DRef = ref(null);
  53. const lotteryEngine = useLotteryEngine(dataManager, {
  54. resetCard: (...args) => lottery3DRef.value?.resetCard?.(...args),
  55. addHighlight: (...args) => lottery3DRef.value?.addHighlight?.(...args),
  56. switchScreen: (...args) => lottery3DRef.value?.switchScreen?.(...args),
  57. rotateBallStart: (...args) => lottery3DRef.value?.rotateBallStart?.(...args),
  58. rotateBallStop: (...args) => lottery3DRef.value?.rotateBallStop?.(...args),
  59. selectCard: (...args) => lottery3DRef.value?.selectCard?.(...args),
  60. });
  61. onMounted(async () => {
  62. await dataManager.getBasicData();
  63. await dataManager.getUsers();
  64. });
  65. function showLotteryQipao() {
  66. const luckys = dataManager.state.currentLuckys;
  67. const prize = dataManager.state.currentPrize;
  68. if (!luckys || luckys.length === 0) return;
  69. const names = luckys.map((item) => item[1]).join("、");
  70. qipaoText.value = `恭喜${names}获得${prize?.title || ""}`;
  71. showQipao.value = true;
  72. setTimeout(() => {
  73. showQipao.value = false;
  74. }, 3000);
  75. }
  76. async function handleLotteryClick() {
  77. if (isDisabled.value) return; // 2秒内不能重复点击
  78. isDisabled.value = true;
  79. setTimeout(() => {
  80. isDisabled.value = false;
  81. }, 2000);
  82. switch (lotteryState.value) {
  83. case "idle":
  84. // 先切换到球体布局
  85. console.log("lotteryState 变更前:", lotteryState.value, "-> ready");
  86. lotteryState.value = "ready";
  87. console.log("lotteryState 变更后:", lotteryState.value);
  88. await lottery3DRef.value?.switchScreen?.("lottery");
  89. break;
  90. case "ready":
  91. // 立即切换为“停止抽奖”
  92. console.log("lotteryState 变更前:", lotteryState.value, "-> rotating");
  93. lotteryState.value = "rotating";
  94. console.log("lotteryState 变更后:", lotteryState.value);
  95. // 开始转动
  96. // isRunning.value = false; // 无论如何都恢复
  97. await lottery3DRef.value?.rotateBallStart?.();
  98. break;
  99. case "rotating":
  100. // 停止转动并开奖
  101. await lottery3DRef.value?.rotateBallStop?.();
  102. await lotteryEngine.executeLottery();
  103. await nextTick();
  104. showLotteryQipao();
  105. console.log("lotteryState 变更前:", lotteryState.value, "-> idle");
  106. lotteryState.value = "result";
  107. console.log("lotteryState 变更后:", lotteryState.value);
  108. break;
  109. case "result":
  110. // result 状态下点击不做任何事,或者你可以加提示
  111. await lottery3DRef.value?.switchScreen?.("lottery");
  112. // 去除高光
  113. lottery3DRef.value?.changeCard1?.();
  114. lotteryState.value = "ready";
  115. break;
  116. default:
  117. break;
  118. }
  119. }
  120. function handleReset() {
  121. lotteryEngine.resetLottery();
  122. }
  123. function handleExport() {
  124. dataManager.exportData();
  125. }
  126. function handlePrevPrize() {
  127. if (dataManager.state.currentPrizeIndex > 0) {
  128. dataManager.state.currentPrizeIndex--;
  129. dataManager.state.currentPrize =
  130. dataManager.state.basicData.prizes[dataManager.state.currentPrizeIndex];
  131. }
  132. }
  133. function handleNextPrize() {
  134. if (
  135. dataManager.state.currentPrizeIndex <
  136. dataManager.state.basicData.prizes.length - 1
  137. ) {
  138. dataManager.state.currentPrizeIndex++;
  139. dataManager.state.currentPrize =
  140. dataManager.state.basicData.prizes[dataManager.state.currentPrizeIndex];
  141. }
  142. }
  143. </script>
  144. <style scoped>
  145. .choujiang-main {
  146. width: 100vw;
  147. height: 100vh;
  148. position: relative;
  149. overflow: hidden;
  150. /* 添加背景图片 */
  151. background: url('../../assets/登录.png') ;
  152. background-size: 1920px 980px;
  153. }
  154. </style>