Browse Source

一期终版

songtongtong/feature-20250717104937-众筹
no99 1 month ago
parent
commit
55c3d34dcc
  1. 2
      .env.development
  2. 2
      .env.production
  3. 26
      src/api/API.js
  4. 6
      src/utils/TrackballControls.js
  5. 1
      src/utils/request.js
  6. 718
      src/views/choujiang/hxl-cj/cj.vue
  7. 77
      src/views/choujiang/lottery/Lottery3D.vue
  8. 18
      vite.config.js

2
.env.development

@ -5,7 +5,7 @@ VITE_OUTPUT_DIR = 'dev'
VITE_PUBLIC_PATH = / VITE_PUBLIC_PATH = /
#新数据接口 #新数据接口
VITE_APP_API_BASE_URL = "http://47.92.148.30:3003/mock/3267"
VITE_APP_API_BASE_URL = "https://dbqb.nfdxy.net/devLotApi"
# Whether to open mock # Whether to open mock

2
.env.production

@ -9,7 +9,7 @@ VITE_PUBLIC_PATH = /aixiaocaishen
VITE_USE_MOCK = true VITE_USE_MOCK = true
#新数据接口 #新数据接口
VITE_APP_API_BASE_URL = http://47.92.148.30:3003/mock/3267
VITE_APP_API_BASE_URL = https://dbqb.nfdxy.net/devLotApi
# Whether to enable gzip or brotli compression # Whether to enable gzip or brotli compression
# Optional: gzip | brotli | none # Optional: gzip | brotli | none

26
src/api/API.js

@ -2,3 +2,29 @@ import request from "../utils/request";
const APIurl = import.meta.env.VITE_APP_API_BASE_URL; const APIurl = import.meta.env.VITE_APP_API_BASE_URL;
// 查询所有奖品和对应等级,按sort排序
export const getPrizeListApi = function (params) {
return request({
url: `/Api/api/prize/list`,
method: "POST",
data: new URLSearchParams(params),
});
};
// 查询用户
export const getUserListApi = function (params) {
return request({
url: `/Api/api/user/list`,
method: "POST",
data: new URLSearchParams(params),
});
};
// 查询中奖名单
export const getGetPrizeUserListApi = function (params) {
return request({
url: `/Api/admin/win/list`,
method: "POST",
data: params,
});
};

6
src/utils/TrackballControls.js

@ -375,7 +375,7 @@ export class TrackballControls extends THREE.EventDispatcher {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return;
// return;
switch (event.deltaMode) { switch (event.deltaMode) {
case 2: case 2:
@ -485,7 +485,7 @@ export class TrackballControls extends THREE.EventDispatcher {
this.dispose = function () { this.dispose = function () {
this.domElement.removeEventListener("contextmenu", contextmenu, false); this.domElement.removeEventListener("contextmenu", contextmenu, false);
this.domElement.removeEventListener("mousedown", mousedown, false); this.domElement.removeEventListener("mousedown", mousedown, false);
this.domElement.removeEventListener("wheel", mousewheel, false);
// this.domElement.removeEventListener("wheel", mousewheel, false);
this.domElement.removeEventListener("touchstart", touchstart, false); this.domElement.removeEventListener("touchstart", touchstart, false);
this.domElement.removeEventListener("touchend", touchend, false); this.domElement.removeEventListener("touchend", touchend, false);
@ -500,7 +500,7 @@ export class TrackballControls extends THREE.EventDispatcher {
this.domElement.addEventListener("contextmenu", contextmenu, false); this.domElement.addEventListener("contextmenu", contextmenu, false);
this.domElement.addEventListener("mousedown", mousedown, false); this.domElement.addEventListener("mousedown", mousedown, false);
this.domElement.addEventListener("wheel", mousewheel, false);
// this.domElement.addEventListener("wheel", mousewheel, false);
this.domElement.addEventListener("touchstart", touchstart, false); this.domElement.addEventListener("touchstart", touchstart, false);
this.domElement.addEventListener("touchend", touchend, false); this.domElement.addEventListener("touchend", touchend, false);

1
src/utils/request.js

@ -1,6 +1,5 @@
import axios from 'axios' import axios from 'axios'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { config } from '@/config'
const ERROR_MESSAGES = { const ERROR_MESSAGES = {
badRequest: '请求错误(400)', badRequest: '请求错误(400)',

718
src/views/choujiang/hxl-cj/cj.vue

@ -1,7 +1,7 @@
<template> <template>
<div class="homepage"> <div class="homepage">
<img src="../../../assets/img/麒麟.png" alt="麒麟" class="hllogo" /> <img src="../../../assets/img/麒麟.png" alt="麒麟" class="hllogo" />
<div class="music">
<div class="music" @click="musicPlay()">
<audio id="music" :src="musicFile" class="music-item" loop></audio> <audio id="music" :src="musicFile" class="music-item" loop></audio>
<div id="musicBox" class="music-box" title="播放/暂停背景音乐">Music</div> <div id="musicBox" class="music-box" title="播放/暂停背景音乐">Music</div>
</div> </div>
@ -29,9 +29,9 @@
<div class="prize-text"> <div class="prize-text">
<div class="prize-title"> <div class="prize-title">
<div class="level"> <div class="level">
{{ item.text }}
{{ item.gradeName }}
</div> </div>
{{ item.title }}
{{ item.prizeName }}
</div> </div>
<div class="prize-count"> <div class="prize-count">
<div class="progress"> <div class="progress">
@ -80,19 +80,13 @@
<div class="gradient-line"></div> <div class="gradient-line"></div>
</div> </div>
<el-scrollbar class="tableBody"> <el-scrollbar class="tableBody">
<div
v-for="item in [
{ id: '11111', prize: '六等奖' },
{ id: '22222', prize: '六等奖' },
]"
:key="item"
>
<div v-for="item in getPrizeUserList" :key="item">
<div class="tableItem"> <div class="tableItem">
<div class="tableItem1"> <div class="tableItem1">
{{ item.id }}
{{ item.jwcode }}
</div> </div>
<div class="tableItem2"> <div class="tableItem2">
{{ item.prize }}
{{ item.gradeName }}
</div> </div>
</div> </div>
</div> </div>
@ -101,9 +95,16 @@
</div> </div>
</div> </div>
<div id="container"></div>
<div id="container">
<div ref="threeContainer" class="three-container"></div>
<img
<!-- 分页指示器 -->
<div v-if="pageMaxIndex > 1" class="page-indicator">
{{ pageIndex + 1 }} / {{ pageMaxIndex }}
</div>
</div>
<!-- <img
src="../../../assets/img/展开.png" src="../../../assets/img/展开.png"
alt="向右" alt="向右"
@click="rightPage()" @click="rightPage()"
@ -117,7 +118,7 @@
@click="leftPage()" @click="leftPage()"
class="leftPage" class="leftPage"
id="leftPage" id="leftPage"
/>
/> -->
<div id="menu"> <div id="menu">
<div id="enter" ref="enterRef" @click="enterLottery()" class="btn"> <div id="enter" ref="enterRef" @click="enterLottery()" class="btn">
@ -145,6 +146,12 @@ import { NUMBER_MATRIX } from "../../../utils/config";
import { CSS3DObject, CSS3DRenderer } from "../../../utils/CSS3DRenderer.js"; import { CSS3DObject, CSS3DRenderer } from "../../../utils/CSS3DRenderer.js";
import { TrackballControls } from "../../../utils/TrackballControls.js"; import { TrackballControls } from "../../../utils/TrackballControls.js";
import {
getPrizeListApi,
getUserListApi,
getGetPrizeUserListApi,
} from "../../../api/API";
// //
const ROTATE_TIME = 10000; // const ROTATE_TIME = 10000; //
const ROTATE_LOOP = 1000; const ROTATE_LOOP = 1000;
@ -184,7 +191,7 @@ let rotate = false;
// //
const prizes = ref([]); const prizes = ref([]);
// //
let EACH_COUNT;
let EACH_COUNT = [];
const users = ref([]); const users = ref([]);
@ -203,9 +210,6 @@ const currentPrize = ref({});
let currentLuckys = []; let currentLuckys = [];
let prizeElement = {}; let prizeElement = {};
let defaultType = 0;
let lasetPrizeIndex = 0;
const qipaoText = ref(""); const qipaoText = ref("");
const qipaoTextRef = ref(null); const qipaoTextRef = ref(null);
const addQipao = (text) => { const addQipao = (text) => {
@ -221,21 +225,24 @@ const addQipao = (text) => {
// //
setTimeout(() => { setTimeout(() => {
qipaoTextRef.value.style.display = "none"; qipaoTextRef.value.style.display = "none";
}, 500);
}, 800);
}, 1000); }, 1000);
}; };
const getPrizeUserList = ref([]);
const isOpen = ref(false); const isOpen = ref(false);
const openGetPrize = () => {
const openGetPrize = async () => {
if (!prizes.value[prizes.value.length - 1].isLook) { if (!prizes.value[prizes.value.length - 1].isLook) {
addQipao("请先揭晓奖品。"); addQipao("请先揭晓奖品。");
return; return;
} }
let res = await getGetPrizeUserListApi({});
getPrizeUserList.value = res.data.list;
isOpen.value = true; isOpen.value = true;
console.log("currentPrize", currentPrize.value);
// console.log("currentPrize", currentPrize.value);
prizes.value.forEach((item) => { prizes.value.forEach((item) => {
console.log("item", item);
// console.log("item", item);
if (item.type != currentPrize.value.type) { if (item.type != currentPrize.value.type) {
let box = document.querySelector(`#prize-item-${item.type}`); let box = document.querySelector(`#prize-item-${item.type}`);
box.style.display = "none"; box.style.display = "none";
@ -248,7 +255,7 @@ const openGetPrize = () => {
const closeGetPrize = () => { const closeGetPrize = () => {
isOpen.value = false; isOpen.value = false;
prizes.value.forEach((item) => { prizes.value.forEach((item) => {
console.log("item", item);
// console.log("item", item);
if (item.type != currentPrize.value.type) { if (item.type != currentPrize.value.type) {
let box = document.querySelector(`#prize-item-${item.type}`); let box = document.querySelector(`#prize-item-${item.type}`);
box.style.display = "flex"; box.style.display = "flex";
@ -262,7 +269,7 @@ const closeGetPrize = () => {
const lookPrize = (item) => { const lookPrize = (item) => {
// //
if (!joinLottery) { if (!joinLottery) {
addQipao("请先进入抽奖");
addQipao("请先进入抽奖");
return; return;
} }
// //
@ -295,7 +302,7 @@ const lookPrize = (item) => {
} }
if (lastIndex != -1) { if (lastIndex != -1) {
let lastPrize = prizes.value[lastIndex]; let lastPrize = prizes.value[lastIndex];
console.log("lastPrize", lastPrize);
// console.log("lastPrize", lastPrize);
let lastBox = document.querySelector(`#prize-item-${lastPrize.type}`); let lastBox = document.querySelector(`#prize-item-${lastPrize.type}`);
lastBox.classList.remove("shine"); lastBox.classList.remove("shine");
lastBox.classList.add("done"); lastBox.classList.add("done");
@ -309,13 +316,8 @@ const lookPrize = (item) => {
} }
}; };
function setPrizes(pri) {
defaultType = pri[0]["type"];
lasetPrizeIndex = pri.length - 1;
}
function setPrizeData(currentPrizeIndex, isInit) { function setPrizeData(currentPrizeIndex, isInit) {
console.log("prizes", prizes.value);
// console.log("prizes", prizes.value);
// let currentPrize = prizes.value[currentPrizeIndex]; // let currentPrize = prizes.value[currentPrizeIndex];
let type = currentPrize.value.type; let type = currentPrize.value.type;
let elements = prizeElement[type]; let elements = prizeElement[type];
@ -342,8 +344,7 @@ function setPrizeData(currentPrizeIndex, isInit) {
} }
} }
console.log("lasetPrizeIndex", lasetPrizeIndex);
console.log("currentPrize", currentPrize);
// console.log("currentPrize", currentPrize);
let percent = (count / totalCount).toFixed(2); let percent = (count / totalCount).toFixed(2);
if (elements.bar) { if (elements.bar) {
@ -354,24 +355,34 @@ function setPrizeData(currentPrizeIndex, isInit) {
/** /**
* 初始化所有DOM * 初始化所有DOM
*/ */
let pageIndex = 0;
let pageMaxIndex = 1;
const pageIndex = ref(0);
const pageMaxIndex = ref(0);
const cardsPerPage = 10; //
let isPageTransitioning = false; //
//
let globalCardIndexes = [];
const initAll = async () => { const initAll = async () => {
const response = await axios.post(`http://192.168.3.35:8090/getTempData`);
console.log("response", response);
let data = response.data;
const [prizeList, userList] = await Promise.all([
getPrizeListApi(),
getUserListApi(),
]);
// //
prizes.value = data.cfgData.prizes;
prizes.value[7].count = 100;
prizes.value.forEach((item) => {
item.leftCount = item.count; //
item.hasCount = item.count; //
item.isLook = false; //
prizes.value = prizeList.data;
//
users.value = userList.data;
prizes.value.forEach((item, index) => {
item.type = index;
item.count = item.amount;
item.leftCount = item.amount; //
item.hasCount = item.amount; //
item.isLook = false; //
EACH_COUNT.push(item.perWin);
}); });
EACH_COUNT = data.cfgData.EACH_COUNT;
EACH_COUNT[7] = 19;
console.log("prizes", prizes.value);
console.log("EACH_COUNT", EACH_COUNT);
HIGHLIGHT_CELL = createHighlight(); HIGHLIGHT_CELL = createHighlight();
setPrizes(prizes.value);
TOTAL_CARDS = ROW_COUNT * COLUMN_COUNT; TOTAL_CARDS = ROW_COUNT * COLUMN_COUNT;
@ -380,16 +391,6 @@ const initAll = async () => {
await nextTick(); await nextTick();
setPrizeData(currentPrizeIndex, true); setPrizeData(currentPrizeIndex, true);
// window.AJAX({
// url: "/getTempData",
// success(data) {
// //
// },
// });
const response1 = await axios.post(`http://192.168.3.35:8090/getUsers`);
const data1 = response1.data;
users.value = data1;
initCards(); initCards();
// startMaoPao(); // startMaoPao();
@ -461,8 +462,12 @@ const initCards = () => {
renderer = new CSS3DRenderer(); renderer = new CSS3DRenderer();
renderer.setSize(window.innerWidth * 1, window.innerHeight * 0.9); renderer.setSize(window.innerWidth * 1, window.innerHeight * 0.9);
renderer.domElement.style.margin = "7% 0 0 4%";
document.getElementById("container").appendChild(renderer.domElement);
renderer.domElement.style.margin = "7% 0 0 0";
// document.getElementById("container").appendChild(renderer.domElement);
if (threeContainer.value) {
threeContainer.value.appendChild(renderer.domElement);
}
// //
@ -525,7 +530,9 @@ const createElement = (css, text) => {
const createCard = (user, isBold, id) => { const createCard = (user, isBold, id) => {
var element = createElement(); var element = createElement();
element.id = "card-" + id; element.id = "card-" + id;
element.style.display = "flex";
element.style.alignItems = "center";
element.style.justifyContent = "center";
if (isBold) { if (isBold) {
element.className = "element lightitem"; element.className = "element lightitem";
element.classList.add("highlight"); element.classList.add("highlight");
@ -537,7 +544,7 @@ const createCard = (user, isBold, id) => {
element.style.border = "2px solid rgba(255, 255, 255, 1)"; element.style.border = "2px solid rgba(255, 255, 255, 1)";
} }
element.appendChild(createElement("name", user[1]));
element.appendChild(createElement("name", user.jwcode));
return element; return element;
}; };
@ -635,128 +642,347 @@ function render() {
} }
// //
const rightPage = () => {
if (pageIndex == pageMaxIndex) return;
console.log("点击了向右");
//
resetCard(300).then(() => {
pageIndex++;
selectCard(600, pageIndex);
});
};
const leftPage = () => {
if (pageIndex == 0) return;
console.log("点击了向左");
//
resetCard(300).then(() => {
pageIndex--;
selectCard(600, pageIndex);
});
};
// const rightPage = () => {
// if (pageIndex == pageMaxIndex) return;
// console.log("");
// //
// resetCard(300).then(() => {
// pageIndex++;
// selectCard(600, pageIndex);
// });
// };
// const leftPage = () => {
// if (pageIndex == 0) return;
// console.log("");
// //
// resetCard(300).then(() => {
// pageIndex--;
// selectCard(600, pageIndex);
// });
// };
// //
function selectCard(duration = 600, index = 0) {
console.log("pageIndex", pageIndex, "pageMaxIndex", pageMaxIndex);
let right = document.getElementById("rightPage");
let left = document.getElementById("leftPage");
right.style.display = "flex";
left.style.display = "flex";
pageMaxIndex = Math.ceil(selectedCardIndex.length / 10) - 1;
let getCurrentIndex = [];
for (let i = 0; i < selectedCardIndex.length; i += 10) {
getCurrentIndex.push(selectedCardIndex.slice(i, i + 10));
}
// function selectCard(duration = 600, index = 0) {
// console.log("pageIndex", pageIndex, "pageMaxIndex", pageMaxIndex);
// let right = document.getElementById("rightPage");
// let left = document.getElementById("leftPage");
// right.style.display = "flex";
// left.style.display = "flex";
// pageMaxIndex = Math.ceil(selectedCardIndex.length / 10) - 1;
// let getCurrentIndex = [];
// for (let i = 0; i < selectedCardIndex.length; i += 10) {
// getCurrentIndex.push(selectedCardIndex.slice(i, i + 10));
// }
// let getCurrentLucky = [];
// for (let i = 0; i < currentLuckys.length; i += 10) {
// getCurrentLucky.push(currentLuckys.slice(i, i + 10));
// }
// console.log("getCurrentIndex", getCurrentIndex);
// console.log("getCurrentLucky", getCurrentLucky);
// rotate = false; //
// let width = 180;
// let tag = -(getCurrentLucky[index].length - 1) / 2;
// let locates = [];
// // , 5
// if (getCurrentLucky[index].length > 5) {
// let yPosition = [-120, 120];
// let l = getCurrentIndex[index].length;
// let mid = Math.ceil(l / 2);
// tag = -(mid - 1) / 2;
// for (let i = 0; i < mid; i++) {
// locates.push({
// x: tag * width * Resolution,
// y: yPosition[0] * Resolution,
// });
// tag++;
// }
// console.log("locates", locates);
// // console.log("selectedCardIndex", selectedCardIndex);
// // console.log("currentLuckys", currentLuckys);
// tag = -(l - mid - 1) / 2;
// for (let i = mid; i < l; i++) {
// locates.push({
// x: tag * width * Resolution,
// y: yPosition[1] * Resolution,
// });
// tag++;
// }
// } else {
// for (let i = getCurrentIndex[index].length; i > 0; i--) {
// locates.push({
// x: tag * width * Resolution,
// y: 0 * Resolution,
// });
// tag++;
// }
// }
// getCurrentIndex[index].forEach((cardIndex, iindex) => {
// changeCard(cardIndex, getCurrentLucky[index][iindex]);
// var object = threeDCards[cardIndex];
// new TWEEN.Tween(object.position)
// .to(
// {
// x: locates[iindex].x,
// y: locates[iindex].y * Resolution,
// z: 2000,
// },
// Math.random() * duration + duration
// )
// .easing(TWEEN.Easing.Exponential.InOut)
// .start();
// new TWEEN.Tween(object.rotation)
// .to(
// {
// x: 0,
// y: 0,
// z: 0,
// },
// Math.random() * duration + duration
// )
// .easing(TWEEN.Easing.Exponential.InOut)
// .start();
// object.element.classList.add("prize");
// });
// new TWEEN.Tween(this)
// .to({}, duration * 2)
// .onUpdate(render)
// .start()
// .onComplete(() => {
// //
// setLotteryStatus();
// });
// }
const threeContainer = ref(null);
function selectCard(duration = 600) {
return new Promise((resolve) => {
const width = 160;
//
pageMaxIndex.value = Math.ceil(currentLuckys.length / cardsPerPage);
pageIndex.value = 0;
//
const pageLocates = [];
for (let page = 0; page < pageMaxIndex.value; page++) {
const startIndex = page * cardsPerPage;
const endIndex = Math.min(
(page + 1) * cardsPerPage,
currentLuckys.length
);
const pageCount = endIndex - startIndex;
const pageLocate = [];
//
if (pageCount > 5) {
// 510
const yPosition = [-75, 120];
const mid = Math.ceil(pageCount / 2);
let tag = -(mid - 1) / 2;
for (let i = 0; i < mid; i++) {
pageLocate.push({
x: tag * width,
y: yPosition[0],
});
tag++;
}
let getCurrentLucky = [];
for (let i = 0; i < currentLuckys.length; i += 10) {
getCurrentLucky.push(currentLuckys.slice(i, i + 10));
}
tag = -(pageCount - mid - 1) / 2;
for (let i = mid; i < pageCount; i++) {
pageLocate.push({
x: tag * width,
y: yPosition[1],
});
tag++;
}
} else {
// 510
let tag = -(pageCount - 1) / 2;
for (let i = 0; i < pageCount; i++) {
pageLocate.push({
x: tag * width,
y: 0,
});
tag++;
}
}
console.log("getCurrentIndex", getCurrentIndex);
console.log("getCurrentLucky", getCurrentLucky);
rotate = false; //
let width = 180;
let tag = -(getCurrentLucky[index].length - 1) / 2;
let locates = [];
// , 5
if (getCurrentLucky[index].length > 5) {
let yPosition = [-120, 120];
let l = getCurrentIndex[index].length;
let mid = Math.ceil(l / 2);
tag = -(mid - 1) / 2;
for (let i = 0; i < mid; i++) {
locates.push({
x: tag * width * Resolution,
y: yPosition[0] * Resolution,
});
tag++;
pageLocates.push(pageLocate);
} }
console.log("locates", locates);
// console.log("selectedCardIndex", selectedCardIndex);
// console.log("currentLuckys", currentLuckys);
// console.log("pageLocates calculated:", pageLocates);
tag = -(l - mid - 1) / 2;
for (let i = mid; i < l; i++) {
locates.push({
x: tag * width * Resolution,
y: yPosition[1] * Resolution,
});
tag++;
}
} else {
for (let i = getCurrentIndex[index].length; i > 0; i--) {
locates.push({
x: tag * width * Resolution,
y: 0 * Resolution,
//
selectedCardIndex.forEach((cardIndex, index) => {
changeSelectedCard(cardIndex, currentLuckys[index]);
const object = threeDCards[cardIndex];
//
const cardPage = Math.floor(index / cardsPerPage);
const isVisible = cardPage === 0;
//
const pageNowIndex = index % cardsPerPage;
const pageLocate = pageLocates[cardPage][pageNowIndex];
new TWEEN.Tween(object.position)
.to(
{
x: isVisible ? pageLocate.x : pageLocate.x,
y: isVisible ? pageLocate.y : pageLocate.y + 1000, //
z: 2100,
},
Math.random() * duration + duration
)
.easing(TWEEN.Easing.Exponential.InOut)
.start();
new TWEEN.Tween(object.rotation)
.to(
{
x: 0,
y: 0,
z: 0,
},
Math.random() * duration + duration
)
.easing(TWEEN.Easing.Exponential.InOut)
.start();
object.element.classList.add("prize");
});
// switchPage使
window.pageLocates = pageLocates;
new TWEEN.Tween({})
.to({}, duration * 2)
.onUpdate(() => render())
.start()
.onComplete(() => {
console.log("selectCard animation completed");
//
if (pageMaxIndex.value > 1) {
// console.log("pageMaxIndex", pageMaxIndex.value);
//
addWheelListener();
}
setLotteryStatus();
resolve();
}); });
tag++;
}
});
}
//
function switchPage(direction) {
if (isPageTransitioning || pageMaxIndex.value <= 1) return;
const newPage =
direction === "next" ? pageIndex.value + 1 : pageIndex.value - 1;
if (newPage < 0 || newPage >= pageMaxIndex.value) return;
isPageTransitioning = true;
const duration = 800;
// 使
const pageLocates = window.pageLocates;
if (!pageLocates) {
console.error("页面位置信息未找到");
isPageTransitioning = false;
return;
} }
getCurrentIndex[index].forEach((cardIndex, iindex) => {
changeCard(cardIndex, getCurrentLucky[index][iindex]);
var object = threeDCards[cardIndex];
//
globalCardIndexes.forEach((cardIndex, index) => {
const object = threeDCards[cardIndex];
const cardPage = Math.floor(index / cardsPerPage);
const isVisible = cardPage === newPage;
//
const pageNowIndex = index % cardsPerPage;
const pageLocate = pageLocates[cardPage][pageNowIndex];
// console.log(
// "cardPage",
// cardPage,
// "pageNowIndex",
// pageNowIndex,
// "pageLocate",
// pageLocate
// );
new TWEEN.Tween(object.position) new TWEEN.Tween(object.position)
.to( .to(
{ {
x: locates[iindex].x,
y: locates[iindex].y * Resolution,
z: 2000,
},
Math.random() * duration + duration
)
.easing(TWEEN.Easing.Exponential.InOut)
.start();
new TWEEN.Tween(object.rotation)
.to(
{
x: 0,
y: 0,
z: 0,
x: pageLocate.x,
y: isVisible ? pageLocate.y : pageLocate.y + 1000,
z: 2100,
}, },
Math.random() * duration + duration
duration
) )
.easing(TWEEN.Easing.Exponential.InOut)
.easing(TWEEN.Easing.Cubic.InOut)
.start(); .start();
object.element.classList.add("prize");
}); });
new TWEEN.Tween(this)
.to({}, duration * 2)
.onUpdate(render)
.start()
new TWEEN.Tween({})
.to({}, duration)
.onUpdate(() => render())
.onComplete(() => { .onComplete(() => {
//
setLotteryStatus();
pageIndex.value = newPage;
isPageTransitioning = false;
console.log(
`切换到第 ${pageIndex.value + 1} 页,共 ${pageMaxIndex.value}`
);
})
.start();
}
//
function handleWheel(event) {
if (isPageTransitioning || pageMaxIndex.value <= 1) return;
event.preventDefault();
if (event.deltaY > 0) {
//
switchPage("next");
} else if (event.deltaY < 0) {
//
switchPage("prev");
}
}
//
function addWheelListener() {
if (threeContainer.value) {
threeContainer.value.addEventListener("wheel", handleWheel, {
passive: false,
}); });
}
}
//
function removeWheelListener() {
if (threeContainer.value) {
threeContainer.value.removeEventListener("wheel", handleWheel);
}
} }
/** /**
@ -767,6 +993,20 @@ function resetCard(duration = 500) {
return Promise.resolve(); return Promise.resolve();
} }
globalCardIndexes = [];
//
removeWheelListener();
//
pageIndex.value = 0;
pageMaxIndex.value = 0;
isPageTransitioning = false;
//
if (window.pageLocates) {
delete window.pageLocates;
}
selectedCardIndex.forEach((index) => { selectedCardIndex.forEach((index) => {
let object = threeDCards[index], let object = threeDCards[index],
target = targets.sphere[index]; target = targets.sphere[index];
@ -813,19 +1053,19 @@ function resetCard(duration = 500) {
// //
const lotteryBtn = () => { const lotteryBtn = () => {
console.log("isLotting", isLotting);
console.log("currentPrize.value", currentPrize.value);
// console.log("isLotting", isLotting);
// console.log("currentPrize.value", currentPrize.value);
if (isLotting) { if (isLotting) {
stopLottery(); stopLottery();
return; return;
} }
if (!currentPrize.value.isLook) { if (!currentPrize.value.isLook) {
addQipao("请先揭秘礼品");
addQipao("请先揭秘礼品");
return; return;
} }
if (currentPrize.value.leftCount <= 0) { if (currentPrize.value.leftCount <= 0) {
addQipao("该礼品已抽取完毕,请揭秘下一个礼品");
addQipao("该礼品已抽取完毕,请揭秘下一个礼品");
return; return;
} }
@ -840,8 +1080,8 @@ const lotteryBtn = () => {
console.log("currentPrize", currentPrize.value); console.log("currentPrize", currentPrize.value);
const text = "正在抽取[" + currentPrize.value.title + "],调整好姿势";
addQipao(text);
const text = "正在抽取[" + currentPrize.value.prizeName + "],调整好姿势";
// addQipao(text);
}; };
/** /**
* 抽奖 * 抽奖
@ -862,7 +1102,6 @@ const lottery = () => {
let index = user[0] + i; let index = user[0] + i;
user[0] = index; user[0] = index;
user[1] = index; user[1] = index;
user[2] = index;
currentLuckys.push(user); currentLuckys.push(user);
currentPrize.value.hasCount--; currentPrize.value.hasCount--;
@ -878,7 +1117,7 @@ const lottery = () => {
} }
} }
selectCard(600, pageIndex);
selectCard(600);
}); });
}; };
@ -913,6 +1152,17 @@ function random(num) {
function changeCard(cardIndex, user) { function changeCard(cardIndex, user) {
let card = threeDCards[cardIndex].element; let card = threeDCards[cardIndex].element;
card.innerHTML = `<div class="name">${user.jwcode}</div>`;
}
function changeSelectedCard(cardIndex, user) {
//
if (!globalCardIndexes.includes(cardIndex)) {
globalCardIndexes.push(cardIndex);
}
let card = threeDCards[cardIndex].element;
card.innerHTML = `<div class="name">${user[1]}</div>`; card.innerHTML = `<div class="name">${user[1]}</div>`;
} }
/** /**
@ -972,55 +1222,68 @@ const createHighlight = () => {
return highlight; return highlight;
}; };
let onload = window.onload;
//
const initMusicPlayer = () => {
const musicBox = document.querySelector("#musicBox");
if (musicBox) {
// 1
setTimeout(() => {
musicPlay();
}, 1000);
}
};
window.onload = function () {
if (onload) {
onload();
const musicPlay = () => {
console.log("musicPlay 方法被调用");
const music = document.querySelector("#music");
const musicBox = document.querySelector("#musicBox");
if (!music || !musicBox) {
console.error("音乐元素未找到");
return;
} }
let music = document.querySelector("#music");
if (music.paused) {
music
.play()
.then(() => {
console.log("音乐开始播放");
startRotateAnimation(musicBox);
})
.catch((error) => {
console.error("音乐播放失败:", error);
});
} else {
console.log("音乐暂停");
music.pause();
stopRotateAnimation();
}
};
//
let rotationState = { rotated: 0, stopAnimate: false, animationId: null };
let rotated = 0;
let stopAnimate = false;
let musicBox = document.querySelector("#musicBox");
const startRotateAnimation = (element) => {
rotationState.stopAnimate = false;
function animate() { function animate() {
requestAnimationFrame(function () {
if (stopAnimate) {
return;
}
rotated = rotated % 360;
musicBox.style.transform = "rotate(" + rotated + "deg)";
rotated += 1;
animate();
});
if (rotationState.stopAnimate) return;
rotationState.rotated = (rotationState.rotated + 1) % 360;
element.style.transform = `rotate(${rotationState.rotated}deg)`;
rotationState.animationId = requestAnimationFrame(animate);
} }
musicBox.addEventListener(
"click",
function (e) {
if (music.paused) {
music.play().then(
() => {
stopAnimate = false;
animate();
},
() => {
addQipao("背景音乐自动播放失败,请手动播放!");
}
);
} else {
music.pause();
stopAnimate = true;
}
},
false
);
animate();
};
setTimeout(function () {
musicBox.click();
}, 1000);
const stopRotateAnimation = () => {
rotationState.stopAnimate = true;
if (rotationState.animationId) {
cancelAnimationFrame(rotationState.animationId);
rotationState.animationId = null;
}
}; };
function onWindowResize() { function onWindowResize() {
@ -1030,8 +1293,9 @@ function onWindowResize() {
render(); render();
} }
onMounted(() => {
onMounted(async () => {
initAll(); initAll();
initMusicPlayer();
window.addEventListener("resize", onWindowResize, false); window.addEventListener("resize", onWindowResize, false);
}); });
@ -1065,7 +1329,7 @@ body,
width: 100%; width: 100%;
z-index: 100; z-index: 100;
position: absolute; position: absolute;
top: 11vh;
top: 27vh;
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
color: #db5c58; color: #db5c58;
@ -1091,6 +1355,26 @@ a {
overflow: hidden; overflow: hidden;
} }
.three-container {
width: 100%;
height: 100%;
}
/* 分页指示器样式 */
.page-indicator {
position: absolute;
bottom: 10%;
left: 50%;
transform: translateX(-50%);
z-index: 1000;
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 8px 16px;
border-radius: 20px;
font-size: 14px;
pointer-events: none;
}
.rightPage { .rightPage {
width: 75px; width: 75px;
position: fixed; position: fixed;
@ -1157,10 +1441,6 @@ a {
} }
.element .name { .element .name {
position: absolute;
top: 4.6vh;
left: 0;
right: 0;
font-size: 2.9vh; font-size: 2.9vh;
font-weight: bold; font-weight: bold;
color: rgba(255, 255, 255, 1); color: rgba(255, 255, 255, 1);
@ -1243,7 +1523,7 @@ a {
#prizeBar { #prizeBar {
height: 650px; height: 650px;
width: 500px;
width: 330px;
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;

77
src/views/choujiang/lottery/Lottery3D.vue

@ -189,7 +189,10 @@ function selectCard(selectedCardIndex, currentLuckys, duration = 600) {
for (let page = 0; page < totalPages.value; page++) { for (let page = 0; page < totalPages.value; page++) {
const startIndex = page * cardsPerPage; const startIndex = page * cardsPerPage;
const endIndex = Math.min((page + 1) * cardsPerPage, currentLuckys.length);
const endIndex = Math.min(
(page + 1) * cardsPerPage,
currentLuckys.length
);
const pageCount = endIndex - startIndex; const pageCount = endIndex - startIndex;
const pageLocate = []; const pageLocate = [];
@ -296,7 +299,8 @@ function selectCard(selectedCardIndex, currentLuckys, duration = 600) {
function switchPage(direction) { function switchPage(direction) {
if (isPageTransitioning || totalPages.value <= 1) return; if (isPageTransitioning || totalPages.value <= 1) return;
const newPage = direction === 'next' ? currentPage.value + 1 : currentPage.value - 1;
const newPage =
direction === "next" ? currentPage.value + 1 : currentPage.value - 1;
if (newPage < 0 || newPage >= totalPages.value) return; if (newPage < 0 || newPage >= totalPages.value) return;
isPageTransitioning = true; isPageTransitioning = true;
@ -305,11 +309,11 @@ function switchPage(direction) {
// 使 // 使
const pageLocates = window.pageLocates; const pageLocates = window.pageLocates;
if (!pageLocates) { if (!pageLocates) {
console.error('页面位置信息未找到');
console.error("页面位置信息未找到");
isPageTransitioning = false; isPageTransitioning = false;
return; return;
} }
console.log("globalCardIndexes", globalCardIndexes);
// //
globalCardIndexes.forEach((cardIndex, index) => { globalCardIndexes.forEach((cardIndex, index) => {
const object = threeDCards[cardIndex]; const object = threeDCards[cardIndex];
@ -320,6 +324,15 @@ function switchPage(direction) {
const pageIndex = index % cardsPerPage; const pageIndex = index % cardsPerPage;
const pageLocate = pageLocates[cardPage][pageIndex]; const pageLocate = pageLocates[cardPage][pageIndex];
console.log(
"cardPage",
cardPage,
"pageIndex",
pageIndex,
"pageLocate",
pageLocate
);
new TWEEN.Tween(object.position) new TWEEN.Tween(object.position)
.to( .to(
{ {
@ -339,12 +352,13 @@ function switchPage(direction) {
.onComplete(() => { .onComplete(() => {
currentPage.value = newPage; currentPage.value = newPage;
isPageTransitioning = false; isPageTransitioning = false;
console.log(`切换到第 ${currentPage.value + 1} 页,共 ${totalPages.value}`);
console.log(
`切换到第 ${currentPage.value + 1} 页,共 ${totalPages.value}`
);
}) })
.start(); .start();
} }
// function switchPage(direction) { // function switchPage(direction) {
// if (isPageTransitioning || totalPages.value <= 1) return; // if (isPageTransitioning || totalPages.value <= 1) return;
@ -405,24 +419,26 @@ function handleWheel(event) {
if (event.deltaY > 0) { if (event.deltaY > 0) {
// //
switchPage('next');
switchPage("next");
} else if (event.deltaY < 0) { } else if (event.deltaY < 0) {
// //
switchPage('prev');
switchPage("prev");
} }
} }
// //
function addWheelListener() { function addWheelListener() {
if (threeContainer.value) { if (threeContainer.value) {
threeContainer.value.addEventListener('wheel', handleWheel, { passive: false });
threeContainer.value.addEventListener("wheel", handleWheel, {
passive: false,
});
} }
} }
// //
function removeWheelListener() { function removeWheelListener() {
if (threeContainer.value) { if (threeContainer.value) {
threeContainer.value.removeEventListener('wheel', handleWheel);
threeContainer.value.removeEventListener("wheel", handleWheel);
} }
} }
@ -501,17 +517,15 @@ function changeCard(cardIndex, user) {
// user[0] || "" // user[0] || ""
// }<br/>${user[2] || "PSST"}</div>`; // }<br/>${user[2] || "PSST"}</div>`;
card.style.setProperty('background-color', '#ffffff', 'important');
card.style.setProperty("background-color", "#ffffff", "important");
// card.style.backgroundColor = '#ffffff'; // card.style.backgroundColor = '#ffffff';
// card.style.backgroundColor = '';
// card.style.backgroundColor = '';
} }
function changeCard1() { function changeCard1() {
console.log('执行取消高光,当前卡片索引:', globalCardIndexes);
console.log("执行取消高光,当前卡片索引:", globalCardIndexes);
// //
removeWheelListener(); removeWheelListener();
@ -526,13 +540,17 @@ function changeCard1() {
delete window.pageLocates; delete window.pageLocates;
} }
globalCardIndexes.forEach(cardIndex => {
globalCardIndexes.forEach((cardIndex) => {
const card = threeDCards[cardIndex].element; const card = threeDCards[cardIndex].element;
console.log('取消卡片', cardIndex, '的高光');
card.style.setProperty('background-color', 'rgba(254, 177, 48, 1)', 'important');
console.log("取消卡片", cardIndex, "的高光");
card.style.setProperty(
"background-color",
"rgba(254, 177, 48, 1)",
"important"
);
// prizeCSSbackgroundColor // prizeCSSbackgroundColor
card.classList.remove('prize');
card.classList.remove("prize");
}); });
// //
globalCardIndexes = []; globalCardIndexes = [];
@ -633,9 +651,9 @@ onMounted(() => {
10000 10000
); );
camera.position.z = 3000; camera.position.z = 3000;
// camera.position.y = 250; // 10px
//
// scene.position.y = 10; // 10px
// camera.position.y = 250; // 10px
//
// scene.position.y = 10; // 10px
renderer = new CSS3DRenderer(); renderer = new CSS3DRenderer();
renderer.setSize(window.innerWidth, window.innerHeight); renderer.setSize(window.innerWidth, window.innerHeight);
if (threeContainer.value) { if (threeContainer.value) {
@ -671,7 +689,7 @@ onMounted(() => {
[17, "周二十"], [17, "周二十"],
[18, "吴二一"], [18, "吴二一"],
[19, "郑二二"], [19, "郑二二"],
[0, "张三"],
[0, "张三"],
[1, "李四"], [1, "李四"],
[2, "王五"], [2, "王五"],
[3, "赵六"], [3, "赵六"],
@ -691,7 +709,7 @@ onMounted(() => {
[17, "周二十"], [17, "周二十"],
[18, "吴二一"], [18, "吴二一"],
[19, "郑二二"], [19, "郑二二"],
[0, "张三"],
[0, "张三"],
[1, "李四"], [1, "李四"],
[2, "王五"], [2, "王五"],
[3, "赵六"], [3, "赵六"],
@ -711,7 +729,7 @@ onMounted(() => {
[17, "周二十"], [17, "周二十"],
[18, "吴二一"], [18, "吴二一"],
[19, "郑二二"], [19, "郑二二"],
[0, "张三"],
[0, "张三"],
[1, "李四"], [1, "李四"],
[2, "王五"], [2, "王五"],
[3, "赵六"], [3, "赵六"],
@ -837,7 +855,12 @@ defineExpose({
} }
@keyframes fadeInOut { @keyframes fadeInOut {
0%, 100% { opacity: 0.6; }
50% { opacity: 1; }
0%,
100% {
opacity: 0.6;
}
50% {
opacity: 1;
}
} }
</style> </style>

18
vite.config.js

@ -2,6 +2,22 @@ import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/ // https://vite.dev/config/
// export default defineConfig({
// plugins: [vue()],
// })
export default defineConfig({ export default defineConfig({
plugins: [vue()],
plugins: [
vue(),
],
server: {
proxy: {
'/Api': {
target: 'https://dbqb.nfdxy.net/devLotApi',
// target: 'http://localhost:8080',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/Api/, '')
}
}
}
}) })
Loading…
Cancel
Save