sunlupeng 1 年之前
父節點
當前提交
d1303aa243

+ 207 - 0
public/drawCarousel.html

@@ -0,0 +1,207 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<meta charset="UTF-8">
+	<meta name="viewport" content="width=device-width, initial-scale=1.0">
+	<title>转盘抽奖</title>
+	<style>
+		* { margin: 0; padding: 0; box-sizing: border-box; }
+		[v-cloak] {
+			display: none;
+		}
+		.container {
+      overflow: hidden;
+			width: 540px;
+			height: 540px;
+			/* background: #98d3fc url('https://www.jq22.com/demo/vue-luck-draw-pdmm202010260015/img/bg.a4b976d5.png') no-repeat center / 100% 100%;
+      background: conic-gradient( 
+       red 6deg, orange 6deg 18deg, yellow 18deg 45deg, 
+       green 45deg 110deg, blue 110deg 200deg, purple 200deg); */
+			margin: 0 auto;
+      position: relative;
+		}
+    .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: 30%;
+			height: 20%;
+      margin: 40px auto 10px;
+      display: block;
+		}
+		.prize-item p {
+			color: #fff;
+			font-size: 12px;
+			text-align: center;
+			line-height: 20px;
+		}
+    .btn {
+      width: 160px;
+      height: 160px;
+      background: url('https://xiaoyou.dgtis.com/images/image/2023/08/15/wwn4p7lua9t5h0rx8tlz.png') no-repeat center / 100% 100%;
+      position: absolute;
+      left: 0;
+      right: 0;
+      top: 0;
+      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: -33px;
+      margin: auto;
+    }
+	</style>
+</head>
+<body>
+	<div id="app" v-cloak>
+    <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.pic" alt="">
+  				<p>{{ item.name }}</p>
+  			</div>
+  		</div>
+  		<div class="btn" @click="start"></div>
+    </div>
+	</div>
+
+	<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
+	<script>
+	  const { createApp, onMounted, onUnmounted, ref, reactive, toRefs, computed, nextTick } = Vue
+	  
+	  createApp({
+	  	setup () {
+	  		const state = reactive({
+		      prizeList: [
+	        	{ name: '手机', pic: 'https://xiaoyou.dgtis.com/images/image/2023/08/15/6b8jfssjhybfj572ybs3.jpg' },
+	        	{ name: '手表', pic: 'https://img1.baidu.com/it/u=2631716577,1296460670&fm=253&fmt=auto&app=120&f=JPEG' },
+	        	{ name: '苹果', pic: 'https://img2.baidu.com/it/u=2611478896,137965957&fm=253&fmt=auto&app=138&f=JPEG' },
+	        	{ name: '棒棒糖', pic: 'https://img2.baidu.com/it/u=576980037,1655121105&fm=253&fmt=auto&app=138&f=PNG' },
+	        	{ name: '娃娃', pic: 'https://img2.baidu.com/it/u=4075390137,3967712457&fm=253&fmt=auto&app=138&f=PNG' },
+	        	{ name: '木马', pic: 'https://img1.baidu.com/it/u=2434318933,2727681086&fm=253&fmt=auto&app=120&f=JPEG' },
+	        	{ name: '德芙', pic: 'https://img0.baidu.com/it/u=1378564582,2397555841&fm=253&fmt=auto&app=120&f=JPEG' },
+	        	{ name: '玫瑰', pic: 'https://img1.baidu.com/it/u=1125656938,422247900&fm=253&fmt=auto&app=120&f=JPEG' }
+	        ], // 后台配置的奖品数据
+	        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 * 270 * Math.sin(_degree / 2 * Math.PI / 180)}px;
+              height: 270px;
+              transform: rotate(${_degree * i + _degree / 2}deg);
+              transform-origin: 50% 100%;
+            `
+          }
+        })
+
+        onMounted(() => {
+          prizeWrap.value.style = `${bgColor.value} transform: rotate(-${rotateAngle.value / 2}deg)`
+        })
+
+        onUnmounted(() => {
+          prizeWrap.value.removeEventListener('transitionend', stopRun)
+        })
+
+        // 获取随机数
+        const getRandomNum = () => {
+        	const num = Math.floor(Math.random() * state.prizeList.length)
+      		return num    		
+        }
+
+        const start = () => {
+        	if (!state.isRunning) {
+        		state.isRunning = true
+
+        		console.log('开始抽奖,后台请求中奖奖品')
+        		// 请求返回的奖品编号 这里使用随机数
+        		const prizeId = getRandomNum()
+        		console.log('中奖ID>>>', prizeId, state.prizeList[prizeId])
+        		state.prizeId = prizeId
+        		startRun()
+        	}
+        }
+
+        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);
+          `
+        }
+
+        return {
+        	...toRefs(state),
+          bgColor,
+          prizeStyle,
+          prizeWrap,
+        	start
+        }
+	  	}
+	  }).mount('#app')
+	</script>
+</body>
+</html>

+ 2 - 10
src/router/index.js

@@ -87,17 +87,9 @@ const routes = [
         component: () => import('@/views/HomeView/AnswerGame/AnswerGame.vue')
       },
       {
-        path: '/home/festiveEvents/answerGame/home',
-        component: () => import('@/views/HomeView/AnswerGame/Home.vue')
+        path: '/home/festiveEvents/drawCarouselGame',
+        component: () => import('@/views/HomeView/DrawCarouselGame/DrawCarouselGame.vue')
       },
-      {
-        path: '/home/festiveEvents/answerGame/item',
-        component: () => import('@/views/HomeView/AnswerGame/Item.vue')
-      },
-      {
-        path: '/home/festiveEvents/answerGame/score',
-        component: () => import('@/views/HomeView/AnswerGame/Score.vue')
-      }
     ]
   },
   {

+ 8 - 8
src/views/HomeView/AnswerGame/AnswerGame.vue

@@ -284,8 +284,8 @@ export default{
     z-index: 10;
     background: url(@/assets/image/answerGame/item/itemBg.png) no-repeat;
     background-size: 100% 100%;
-    width: 450px;
-    height: 800px;
+    width: 375px;
+    height: 667px;
 }
 .item .integralBox{
     position: absolute;
@@ -339,8 +339,8 @@ export default{
 }
 .item .questionBox{
     position: absolute;
-    width: 450px;
-    top: 35%;
+    width: 375px;
+    top: 28%;
     left: 0;
     right: 0;
     display: flex;
@@ -400,8 +400,8 @@ export default{
     z-index: 10;
     background: url(@/assets/image/answerGame/home/homeBg.png) no-repeat;
     background-size: 100% 100%;
-    width: 450px;
-    height: 800px;
+    width: 375px;
+    height: 667px;
 }
 .home .rules{
     cursor: pointer;
@@ -424,7 +424,7 @@ export default{
     cursor: pointer;
     position: absolute;
     width: 200px;
-    bottom: 15%;
+    bottom: 14%;
     left: 0;
     right: 0;
     margin:auto;
@@ -433,7 +433,7 @@ export default{
     cursor: pointer;
     position: absolute;
     width: 200px;
-    bottom: 8%;
+    bottom: 5%;
     left: 0;
     right: 0;
     margin:auto;

+ 69 - 0
src/views/HomeView/DrawCarouselGame/DrawCarouselGame.vue

@@ -0,0 +1,69 @@
+<template>
+    <div class="timeline-container">
+        <div class="timeline-content">
+            <div class="timeline-entry-list">
+                <div class="gameBox">
+                    <iframe id="iframe"  frameborder="0" :src="src" style="width: 720px;height: 540px;"></iframe>
+                </div>
+            </div>
+            <SiderInfo></SiderInfo>
+        </div>
+    </div>
+</template>
+<script>
+import SiderInfo from '@/components/SiderInfo.vue'
+import { getToken } from '@/utils/auth'
+export default{
+  components: {
+    SiderInfo
+  },
+  data() {
+    return {
+            src: '', //需要加载的子页面url
+            actId:this.$route.query.actId
+        };
+  },
+  created(){},
+  async mounted(){
+	    var that = this
+        that.src = './drawCarousel.html';
+	    this.iframe = document.getElementById('iframe');
+	    this.iframe.onload = function(){
+	        // iframe加载完成后要进行的操作
+	        that.postMsg()
+	    };
+	},
+	methods: {
+        async postMsg() {
+        	//将token传递给子页面
+            let token = getToken();
+            let actId = this.actId;
+            let param = {
+                token,
+                actId
+            }
+          	this.iframe.contentWindow.postMessage(param,'*')
+        },
+    }
+}
+</script>
+<style scoped>
+.timeline-container{
+    margin: 0 auto;
+}
+.timeline-entry-list{
+    margin-right: 17.5rem;
+    border-radius: 2px;
+    width: 720px;
+    position: relative;
+}
+.timeline-entry-list .gameBox{
+   
+    background-color: #fff;
+    padding: 2.67rem;
+    min-height: 280px;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+}
+</style>

+ 1 - 1
src/views/HomeView/FestiveEvents.vue

@@ -75,7 +75,7 @@ export default {
             // window.location.href = val;
             if(val.activityUrl){
                 this.$router.push({
-                    path: '/home/festiveEvents/game',
+                    path: '/home/festiveEvents/drawCarouselGame',
                     query: {
                         activityUrl: val.activityUrl,
                         actId:val.actId

+ 0 - 169
src/views/HomeView/Game.vue

@@ -52,174 +52,5 @@ export default {
 .right-wrap {
     background-color: #fff;
 }
-
-.tab-header {
-    display: flex;
-    align-items: center;
-    justify-content: space-between;
-    padding: 20px 20px 16px;
-    border-bottom: 1px solid #e5e6eb;
-    overflow: hidden;
-}
-
-.tab-header .tab-title {
-    white-space: nowrap;
-    font-size: 18px;
-    font-weight: 500;
-    color: #1d2129;
-}
-.list-content{
-    padding: 0px 20px 40px;
-}
-.list-container .prize-item:nth-child(4n) {
-    margin-right: 0;
-}
-
-.list-container {
-    border-radius: 2px;
-    background-color: transparent;
-}
-
-.list-container .prize-list {
-    padding: 20px 0;
-    background: #fff;
-    display: flex;
-    flex-flow: row wrap;
-    box-sizing: border-box;
-}
-
-.list-container .prize-item {
-    width: calc(25% - 15px);
-    margin-right: 20px;
-    margin-bottom: 20px;
-    border-radius: 2px;
-}
-
-.prize-card {
-    background: #fff;
-    border: 1px solid #e4e6eb;
-    box-sizing: border-box;
-    border-radius: 2px;
-}
-
-.prize-card .img-container {
-    height: 159px;
-    background: #f7f8fa;
-    border-radius: 2px 2px 0 0;
-    display: flex;
-    align-items: center;
-    justify-content: center;
-}
-
-.prize-card .img-container .prize-img {
-    max-height: 120px;
-    max-width: 120px;
-}
-
-.prize-card .content {
-    padding: 0 16px;
-}
-
-.prize-card .content .desc,
-.prize-card .content .title {
-    white-space: nowrap;
-    overflow: hidden;
-    text-overflow: ellipsis;
-}
-
-.prize-card .content .title {
-    font-weight: 400;
-    font-size: 16px;
-    line-height: 24px;
-    margin-top: 12px;
-    color: #1d2129;
-    margin-bottom: 0;
-}
-
-.prize-card .content .desc {
-    margin: 10px 0;
-    display: inline-block;
-    font-size: 12px;
-    line-height: 18px;
-    height: 18px;
-    width: 100%;
-}
-
-.prize-card .content .desc span {
-    color: #ff7d00;
-    background: #fff7e8;
-    padding: 2px 4px;
-}
-
-.prize-card .content .redeem-info {
-    margin-top: 0;
-    margin-bottom: 0;
-    display: flex;
-    justify-content: space-between;
-    white-space: nowrap;
-    align-items: center;
-}
-
-.prize-card .content .price {
-    font-weight: 500;
-    font-size: 14px;
-    line-height: 24px;
-    color: #1e80ff;
-    flex: auto;
-    display: flex;
-    align-items: center;
-    justify-content: center;
-    justify-content: flex-start;
-}
-
-.prize-card .content .price .icon {
-    height: 16px;
-    width: 16px;
-    position: relative;
-    margin-right: 4px;
-}
-
-.prize-card .content .count {
-    font-size: 12px;
-    line-height: 20px;
-    margin-left: 12px;
-    color: #8a919f;
-}
-
-.prize-card .btn {
-    border-radius: 16px;
-}
-
-.ui-btn.medium {
-    padding: 5px 16px;
-}
-
-.ui-btn.primary {
-    background-color: #1d7dfa;
-}
-.ui-btn.default {
-    color:#8a919f;
-    /* background-color: #1d7dfa; */
-}
-
-.ui-btn {
-    box-sizing: border-box;
-    font-size: 14px;
-    line-height: 22px;
-    padding: 5px 16px;
-    color: #fff;
-    border: none;
-    white-space: nowrap;
-    cursor: pointer;
-}
-
-.prize-card .btn-container {
-    border-top: 1px solid #e4e6eb;
-    padding: 12px 16px;
-    display: flex;
-    align-items: center;
-    justify-content: center;
-}
 </style>
-<style></style>