123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>转盘抽奖</title>
- <style>
- .el-overlay {
- background-color: rgba(0, 0, 0, 0.8);
- }
- ::-webkit-scrollbar {
- width: 6px;
- height: 6px;
- }
- ::-webkit-scrollbar-track {
- width: 3px;
- background: rgba(#101F1C, 0.1);
- -webkit-border-radius: 2em;
- -moz-border-radius: 2em;
- border-radius: 2em;
- }
- ::-webkit-scrollbar-thumb {
- background-color: rgba(144, 147, 153, .5);
- background-clip: padding-box;
- min-height: 28px;
- -webkit-border-radius: 2em;
- -moz-border-radius: 2em;
- border-radius: 2em;
- transition: background-color .3s;
- cursor: pointer;
- }
- ::-webkit-scrollbar-thumb:hover {
- background-color: rgba(144, 147, 153, .3);
- }
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- #app {
- background: url('https://xiaoyou.dgtis.com/images/image/2023/09/12/5opx47olb1unf4po3vxt.png') no-repeat;
- /* background: url('https://xiaoyou.dgtis.com/images/image/2023/09/19/y5epqefrpodtfzyw0qd9.png') no-repeat; */
- background-size: 100% 100%;
- width: 640px;
- height: 680px;
- margin: 0 auto;
- margin-top: 20px;
- }
- .el-dialog__body {
- padding-top: 0px !important;
- }
- [v-cloak] {
- display: none;
- }
- .rules {
- cursor: pointer;
- position: absolute;
- width: 50px;
- height: 50px;
- background: #fff;
- border-radius: 50%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 14px;
- font-weight: 600;
- left: 8%;
- top: 22%;
- }
- .recordBtn {
- cursor: pointer;
- position: absolute;
- width: 50px;
- height: 50px;
- background: #fff;
- border-radius: 50%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 14px;
- font-weight: 600;
- right: 8%;
- top: 22%;
- }
- .recordBtn>img {
- width: 80px;
- height: auto;
- }
- .container {
- overflow: hidden;
- width: 500px;
- height: 500px;
- margin: 0 auto;
- position: relative;
- top: 22%;
- }
- .prize-list {
- width: 100%;
- height: 100%;
- border-radius: 50%;
- border: 10px solid #98d3fc;
- overflow: hidden;
- }
- .prize-item {
- /*border: 2px solid red;*/
- position: absolute;
- left: 0;
- right: 0;
- top: -10px;
- margin: auto;
- }
- .prize-item img {
- width: 35%;
- /* height: 25%; */
- margin: 35px auto 10px;
- display: block;
- }
- .prize-item p {
- color: #fff;
- font-size: 12px;
- text-align: center;
- line-height: 20px;
- }
- .btn {
- width: 80px;
- height: 110px;
- background: url('https://xiaoyou.dgtis.com/images/image/2023/09/12/xvtwunkntyc65fngc9pb.png') no-repeat center / 100% 100%;
- position: absolute;
- left: 0;
- right: 0;
- top: -5%;
- bottom: 0;
- margin: auto;
- cursor: pointer;
- }
- /* .btn::before {
- content: "";
- width: 41px;
- height: 39px;
- background: url('https://xiaoyou.dgtis.com/images/image/2023/08/15/2vac6uuqd3gpbl35l8e1.png') no-repeat center / 100% 100%;
- position: absolute;
- left: 0;
- right: 0;
- top: -30px;
- margin: auto;
- -webkit-transform: rotate(-5deg);
- transform: rotate(-5deg);
- } */
- .recordListBox {
- max-height: 200px;
- overflow: auto;
- }
- .title {
- font-size: 15px;
- font-weight: 600;
- }
- .recordItem {
- display: flex;
- justify-content: space-around;
- align-items: center;
- margin: 10px 0;
- }
- </style>
- </head>
- <body>
- <div id="app" v-cloak class="app">
- <div class="rules" @click="showRules">
- 抽奖<br>规则
- </div>
- <!-- <div class="recordBtn" @click="showRecordList">
- 获奖<br>名单
- </div> -->
- <!-- <div class="recordBtn" @click="showRecordList">
- <img src="https://xiaoyou.dgtis.com/images/image/2023/09/06/lt1vbg426idwq725ysdm.png" alt="抽奖记录">
- </div> -->
- <div class="container">
- <div class="prize-list" ref="prizeWrap" :style="bgColor">
- <div class="prize-item" v-for="(item, index) in prizeList" :style="prizeStyle(index)">
- <img :src="item.imgUrl" alt="">
- <p>{{ item.prizeName }}</p>
- </div>
- </div>
- <div class="btn" @click="start"></div>
- </div>
- <el-dialog v-model="dialogVisible" title="抽奖规则" width="80%" center>
- <div style="max-height: 200px;overflow: auto;" v-html="rule"></div>
- </el-dialog>
- <el-dialog v-model="dialogRecordList" title="获奖名单" width="80%" center>
- <div class="recordListBox">
- <div class="recordItem title">
- <div style="width: 30%;text-align: center;">姓名</div>
- <div style="width: 30%;text-align: center;">奖品</div>
- <div style="width: 40%;text-align: center;">获奖时间</div>
- </div>
- <el-empty description="暂无数据" v-if="recordList.length==0" :image-size="20"></el-empty>
- <div class="recordItem" v-for="(item, index) in recordList">
- <div style="width: 30%;text-align: center;">{{item.userName}}</div>
- <div style="width: 30%;text-align: center;">{{item.prizeName}}</div>
- <div style="width: 40%;text-align: center;">{{item.createTime}}</div>
- </div>
- </div>
- </el-dialog>
- </div>
- </body>
- <script src="./js/crypto-js.min.js"></script>
- <script src="./js/vue.global.js"></script>
- <link href="./css/index.css" rel="stylesheet">
- <script src="./js/index.full.min.js"></script>
- <script src="./js/jquery.js"></script>
- <script>
- const {
- createApp,
- onBeforeMount,
- onMounted,
- onUnmounted,
- ref,
- reactive,
- toRefs,
- computed,
- nextTick
- } = Vue
- createApp({
- setup() {
- const state = reactive({
- recordList: [],
- dialogRecordList: false,
- dialogVisible: false,
- rule: '',
- token: '',
- actId: '',
- keyStr: 'qwerasdfzxcvtyui',
- prizeList: [
- ], // 后台配置的奖品数据
- isRunning: false, // 是否正在抽奖
- baseRunAngle: 360 * 5, // 总共转动角度 至少5圈
- prizeId: 0, // 中奖id
- })
- const prizeWrap = ref(null)
- // 平均每个奖品角度
- const rotateAngle = computed(() => {
- const _degree = 360 / state.prizeList.length
- return _degree
- })
- // 要执行总角度数
- const totalRunAngle = computed(() => {
- return state.baseRunAngle + 360 - state.prizeId * rotateAngle.value - rotateAngle.value / 2
- })
- // 计算绘制转盘背景
- const bgColor = computed(() => {
- const _len = state.prizeList.length
- const colorList = ['#5352b3', '#363589']
- let colorVal = ''
- for (let i = 0; i < _len; i++) {
- colorVal += `${colorList[i % 2]} ${rotateAngle.value * i}deg ${rotateAngle.value * (i + 1)}deg,`
- }
- return `
- background: conic-gradient(${colorVal.slice(0, -1)});
- `
- })
- // 每个奖品布局
- const prizeStyle = computed(() => {
- const _degree = rotateAngle.value
- return (i) => {
- return `
- width: ${2 * 250 * Math.sin(_degree / 2 * Math.PI / 180)}px;
- height: 250px;
- transform: rotate(${_degree * i + _degree / 2}deg);
- transform-origin: 50% 100%;
- `
- }
- })
- onBeforeMount(() => {
- debugger
- window.addEventListener('message', function (e) {
- // console.log("接收值:", e.data)
- state.token = e.data.token;
- state.actId = e.data.actId;
- ElementPlus.ElLoading.service();
- getTurntableInfo();
- ElementPlus.ElLoading.service().close();
- })
- })
- onMounted(() => {
- prizeWrap.value.style = `${bgColor.value} transform: rotate(-${rotateAngle.value / 2}deg)`;
- })
- onUnmounted(() => {
- prizeWrap.value.removeEventListener('transitionend', stopRun)
- })
- // 获取大转盘信息
- async function getTurntableInfo() {
- debugger
- const postData = {
- actId: state.actId,
- };
- let res = await httpAjax('get', '/mall-prize/prize/info', postData)
- if (res.errno === 0) {
- // console.log('获取大转盘信息',res.data);
- state.prizeList = res.data.pool;
- state.rule = res.data.content;
- } else {
- ElementPlus.ElMessage({
- showClose: true,
- message: res.errmsg,
- type: 'error',
- });
- }
- };
- function encryptECB(word) {
- var keyHex = CryptoJS.enc.Utf8.parse(state.keyStr)
- var plaintText = word
- var encryptedData = CryptoJS.AES.encrypt(
- plaintText,
- keyHex,
- {
- mode: CryptoJS.mode.ECB,
- padding: CryptoJS.pad.Pkcs7
- })
- return encryptedData.toString();
- };
- // 大转盘抽奖按钮
- async function starDraw() {
- const postData = {
- actId: state.actId,
- };
- postData = JSON.stringify(postData)
- postData = encryptECB(postData)
- postData = postData.replace(/[\t\r\f\n\s]*/g, '');
- // let res = await httpAjax('post', '/mall-prize/prize', getFormData(postData));
- let res = await httpAjax('post', '/mall-prize/prize', postData);
- if (res.errno === 0) {
- // console.log('抽奖',res.data);
- state.prizeId = res.data.index;
- startRun();
- } else {
- state.isRunning = false;
- ElementPlus.ElMessage({
- showClose: true,
- message: res.errmsg,
- type: 'error',
- });
- }
- };
- //抽奖记录
- // async function getRecordList() {
- // const postData = {
- // actId: state.actId,
- // };
- // let res = await httpAjax('get', '/mall-prize/prize/user/list', postData);
- // if (res.errno === 0) {
- // console.log('抽奖记录',res.data);
- // state.recordList = res.data;
- // } else {
- // state.isRunning = false;
- // ElementPlus.ElMessage({
- // showClose: true,
- // message: res.errmsg,
- // type: 'error',
- // });
- // }
- // };
- //获奖名单
- async function getRecordList() {
- const postData = {
- actId: state.actId,
- };
- let res = await httpAjax('get', '/mall-prize/prize/winners', postData);
- if (res.errno === 0) {
- state.recordList = res.data;
- } else {
- state.isRunning = false;
- ElementPlus.ElMessage({
- showClose: true,
- message: res.errmsg,
- type: 'error',
- });
- }
- };
- // 简单封装ajax
- const httpAjax = (type, url, data) => {
- ajaxHeaders = {
- "Authorization": state.token
- }
- return new Promise((resolve, reject) => {
- $.ajax({
- type: type,
- // url: 'http://192.168.100.208:9083/admin' + url, //本地
- url: "http://47.103.79.143:9085/admin" + url,//测试环境
- // url: "https://xiaoyou.dgtis.com/admin" + url,//正式环境
- data: data,
- contentType: type === 'post' ? false : true,
- processData: type === 'post' ? false : true,
- headers: ajaxHeaders,
- success: function (res) {
- if (res.errno == 503) {
- window.location.href = 'https://dgt.dgtis.com/oneportal/login'
- } else {
- resolve(res);
- }
- },
- error: function (error) {
- reject(error);
- ElementPlus.ElMessage({
- showClose: true,
- message: '网络错误,请稍后再试!',
- type: 'error',
- });
- }
- })
- })
- }
- // 处理formData数据格式
- const getFormData = (datas) => {
- let formData = new FormData();
- for (let key in datas) {
- formData.append(key, datas[key]);
- }
- return formData;
- }
- // 获取随机数
- const getRandomNum = () => {
- const num = Math.floor(Math.random() * state.prizeList.length)
- return num
- }
- const showRules = () => {
- state.dialogVisible = true;
- }
- const showRecordList = () => {
- getRecordList();
- state.dialogRecordList = true;
- }
- const start = () => {
- debugger
- // ElementPlus.ElMessage({
- // showClose: true,
- // message: '已无抽奖次数!',
- // type: 'warning',
- // })
- // return
- if (!state.isRunning) {
- state.isRunning = true;
- starDraw();
- // console.log('开始抽奖,后台请求中奖奖品')
- // // 请求返回的奖品编号 这里使用随机数
- // const prizeId = getRandomNum()
- // console.log('中奖ID>>>', prizeId, state.prizeList[prizeId])
- // state.prizeId = prizeId
- }
- }
- const startRun = () => {
- // console.log(state.isRunning, totalRunAngle.value)
- // 设置动效
- prizeWrap.value.style = `
- ${bgColor.value}
- transform: rotate(${totalRunAngle.value}deg);
- transition: all 4s ease;
- `
- // 监听transition动效停止事件
- prizeWrap.value.addEventListener('transitionend', stopRun)
- }
- const stopRun = (e) => {
- // console.log(e)
- state.isRunning = false
- prizeWrap.value.style = `
- ${bgColor.value}
- transform: rotate(${totalRunAngle.value - state.baseRunAngle}deg);
- `
- if (state.prizeList[state.prizeId].prizeType != '40') {
- ElementPlus.ElMessageBox.alert("恭喜,您中了" + state.prizeList[state.prizeId].prizeName + "," + "可在“个人中心”我的礼品券中查看,在礼品兑换中兑换相应物品。", {
- showClose: false,
- center: true,
- confirmButtonText: '确定',
- })
- // ElementPlus.ElMessage({
- // offset:window.screen.height / 2,
- // duration:3000,
- // showClose: true,
- // message: "恭喜,您中了" + state.prizeList[state.prizeId].prizeName + "," + "可在“个人中心”我的礼品券中查看,在礼品兑换中兑换响应物品。",
- // type: 'success',
- // })
- } else {
- ElementPlus.ElMessageBox.alert("很遗憾,您未中奖。", {
- showClose: false,
- center: true,
- confirmButtonText: '确认',
- })
- // ElementPlus.ElMessage({
- // offset:window.screen.height / 4,
- // duration:10000,
- // showClose: true,
- // message: "很遗憾,您未中奖。",
- // type: 'error',
- // })
- }
- }
- return {
- ...toRefs(state),
- bgColor,
- prizeStyle,
- prizeWrap,
- start,
- showRules,
- showRecordList
- }
- }
- }).use(ElementPlus).mount('#app')
- </script>
- </html>
|