QiXiAnswerGame.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <template>
  2. <div class="timeline-container">
  3. <div class="timeline-content">
  4. <div class="timeline-entry-list">
  5. <div class="gameBox">
  6. <div class="item" v-if="isShowItem==true">
  7. <div :class="{ 'dim': isDim }">
  8. <div class="timer">
  9. <div class="second">{{ countdown }}</div>
  10. </div>
  11. <div class="topicNum">
  12. <div class="topic">{{itemNum+1}}/5</div>
  13. </div>
  14. <div class="questionBox" v-if="questions.length>0">
  15. <div class="title animated zoomIn">
  16. <span style="text-align: center;">{{ questions[itemNum].ask }}</span>
  17. </div>
  18. <div class="content animated" :class="animate_showChoice" v-if="animate_showChoice">
  19. <div v-for="(item,index) in questions[itemNum].answers" :key="index" class="answerItem" :class="index == clickIndex ? answerColor : ''" @click="answer(item,index)">
  20. <span>{{ item.answer }}</span>
  21. <img v-if="index == clickIndex&&answerColor=='error'" class="invisible" src="@/assets/image/answerGame/qiXi/error.png" alt="错误">
  22. <img v-if="index == clickIndex&&answerColor=='right'" class="invisible" style="width: 25px;" src="@/assets/image/answerGame/qiXi/right.png" alt="正确">
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. <div class="home" v-else>
  29. <div :class="{ 'dim': isDim }">
  30. <img class="rules" src="@/assets/image/answerGame/qiXi/rules.png" alt="互动规则" @click="clickRuleWrapper">
  31. <div class="top" v-if="top">
  32. <span style="font-size: 18px;color: #fff;font-weight: 600;">排名:{{ top }}</span>
  33. </div>
  34. <img class="answer" src="@/assets/image/answerGame/qiXi/answer.png" alt="答题按钮" @click="clickAnswer">
  35. <img class="exit" src="@/assets/image/answerGame/qiXi/exit.png" alt="退出互动" @click="getOut">
  36. </div>
  37. </div>
  38. <div class="ruleWrapper" v-if="isRuleWrapper">
  39. <el-card class="box-card">
  40. <div slot="header" class="clearfix">
  41. <span>互动规则</span>
  42. <span style="float: right; font-size: 20px;cursor: pointer;" @click="closeRuleWrapper">
  43. <i class="el-icon-close"></i>
  44. </span>
  45. </div>
  46. <div v-html="rule"></div>
  47. </el-card>
  48. </div>
  49. <div class="confirmWrapper" v-if="isConfirmWrapper">
  50. <img class="goHome" src="@/assets/image/answerGame/qiXi/goHome.png" alt="返回首页" @click="clickGoHome">
  51. </div>
  52. <div class="failWrapper" v-if="isFailWrapper">
  53. <img class="goHome" src="@/assets/image/answerGame/qiXi/goHome.png" alt="返回首页" @click="clickGoHome">
  54. </div>
  55. </div>
  56. </div>
  57. <SiderInfo></SiderInfo>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import { homeData,questionList,submitAnswer } from "@/api/qixiFestival";
  63. import AES from "@/utils/AES.js";
  64. import SiderInfo from '@/components/SiderInfo.vue';
  65. import { mapGetters } from 'vuex';
  66. export default{
  67. components: {
  68. SiderInfo
  69. },
  70. data() {
  71. return {
  72. actId:this.$route.query.actId,
  73. roomId:'',
  74. rule:'',
  75. top:'',
  76. isConfirmWrapper:false,
  77. isFailWrapper:false,
  78. animate_showChoice:'zoomIn',
  79. localClick:false,
  80. clickIndex:-1,
  81. answerColor:'',
  82. isShowItem:false,
  83. isRuleWrapper: false,
  84. isDim:false,
  85. questions:[],
  86. chooseStr: '',
  87. itemNum: 0,
  88. result: [],
  89. timer:null,
  90. countdown:60,
  91. };
  92. },
  93. computed: {
  94. // 将 getter 映射到当前组件的计算属性
  95. ...mapGetters(['userInfo'])
  96. },
  97. created(){
  98. this.getHomeData();
  99. },
  100. methods:{
  101. getOut(){
  102. this.$router.push({
  103. path: '/home/festiveEvents',
  104. });
  105. },
  106. saveAnswer(){
  107. submitAnswer({answers:this.result,roomId:this.roomId}).then(response=>{
  108. console.log(response.data.data);
  109. this.result = [];
  110. })
  111. },
  112. getQuestionList(){
  113. questionList({}).then(response=>{
  114. //解密
  115. let resData = JSON.parse(AES.decrypt(response.data.data));
  116. console.log(resData);
  117. this.questions = resData.questions;
  118. this.roomId = resData.roomId;
  119. this.timerCountdown();
  120. this.isShowItem = true;
  121. })
  122. },
  123. getHomeData(){
  124. homeData({actId:this.actId}).then(response=>{
  125. console.log(response.data.data);
  126. this.rule = response.data.data.rule;
  127. this.top = response.data.data.top;
  128. })
  129. },
  130. clickGoHome(){
  131. this.getHomeData();
  132. this.isFailWrapper = false;
  133. this.isConfirmWrapper = false;
  134. this.isDim = false;
  135. this.isShowItem = false;
  136. this.countdown = 60;
  137. this.itemNum = 0;
  138. this.animate_showChoice = 'fadeIn';
  139. this.localClick = false;
  140. },
  141. timerCountdown(){
  142. this.timer = setInterval(() => {
  143. this.countdown--;
  144. if (this.countdown == 0) {
  145. clearInterval(this.timer);
  146. let resLength = 5 - this.result.length;
  147. for (let i = 0; i < resLength; i++) {
  148. this.result.push('');
  149. }
  150. this.isDim = true;
  151. this.isConfirmWrapper = true;
  152. this.saveAnswer();
  153. console.log(this.result);
  154. }
  155. }, 1000)
  156. },
  157. answer(val,index){
  158. console.log(this.itemNum);
  159. if(!this.localClick && this.itemNum<5){
  160. this.clickIndex = index;
  161. if(val.right){
  162. this.answerColor = 'right';
  163. }else{
  164. this.answerColor = 'error';
  165. }
  166. this.localClick = true;
  167. setTimeout(() => {
  168. this.result.push(val.answer);
  169. this.clickIndex = -1;
  170. this.answerColor = '';
  171. this.animate_showChoice = 'fadeOut';
  172. if(this.itemNum==4){
  173. clearInterval(this.timer);
  174. this.localClick = true;
  175. this.isDim = true;
  176. this.isConfirmWrapper = true;
  177. this.saveAnswer();
  178. console.log(this.result);
  179. }else{
  180. setTimeout(() => {
  181. this.itemNum++
  182. this.animate_showChoice = 'fadeIn';
  183. this.localClick = false;
  184. }, 1000)
  185. }
  186. }, 1000)
  187. }
  188. },
  189. clickAnswer(){
  190. this.getQuestionList();
  191. // if(this.top){
  192. // this.$message({
  193. // message: '今日已答题!',
  194. // type: 'warning'
  195. // });
  196. // return;
  197. // }else{
  198. // this.getQuestionList();
  199. // this.isShowItem = true;
  200. // this.timerCountdown();
  201. // }
  202. },
  203. clickRuleWrapper(){
  204. this.isDim = true;
  205. this.isRuleWrapper = true;
  206. },
  207. closeRuleWrapper(){
  208. this.isDim = false;
  209. this.isRuleWrapper = false;
  210. }
  211. },
  212. }
  213. </script>
  214. <style scoped>
  215. .animated {
  216. animation-duration: 0.5s;
  217. animation-fill-mode: forwards;
  218. }
  219. @keyframes zoomIn {
  220. from {
  221. opacity: 0;
  222. transform: scale3d(.2, .2, .2);
  223. }
  224. 50% {
  225. opacity: 1;
  226. }
  227. }
  228. .zoomIn {
  229. animation-name: zoomIn;
  230. }
  231. @keyframes fadeIn {
  232. from {
  233. opacity: 0;
  234. }
  235. to {
  236. opacity: 1;
  237. }
  238. }
  239. .fadeIn {
  240. animation-name: fadeIn;
  241. }
  242. @keyframes fadeOut {
  243. from {
  244. opacity: 1;
  245. }
  246. to {
  247. opacity: 0;
  248. }
  249. }
  250. .fadeOut {
  251. animation-name: fadeOut;
  252. }
  253. .timeline-container{
  254. margin: 0 auto;
  255. }
  256. .timeline-entry-list{
  257. margin-right: 17.5rem;
  258. border-radius: 2px;
  259. width: 720px;
  260. position: relative;
  261. }
  262. .timeline-entry-list .gameBox{
  263. border-radius: 4px 4px 0 0;
  264. position: relative;
  265. padding: 2.667rem 0;
  266. z-index: 1;
  267. overflow: hidden;
  268. background-color: #fff;
  269. padding-left: 2.67rem;
  270. padding-right: 2.67rem;
  271. margin-bottom: 2rem;
  272. box-sizing: border-box;
  273. min-height: 280px;
  274. display: flex;
  275. justify-content: center;
  276. align-content: center;
  277. }
  278. .gameBox .item{
  279. position: relative;
  280. z-index: 10;
  281. background: url(@/assets/image/answerGame/qiXi/itemBg.png) no-repeat;
  282. background-size: 100% 100%;
  283. width: 375px;
  284. height: 667px;
  285. }
  286. .item .integralBox{
  287. position: absolute;
  288. top: 7.3%;
  289. right: 8%;
  290. width: 90px;
  291. height: 35.2px;
  292. /* background: greenyellow; */
  293. display: flex;
  294. justify-content: center;
  295. line-height: 35.2px;
  296. }
  297. .integralBox .integral{
  298. font-size: 16px;
  299. color: orange;
  300. font-weight: 600;
  301. }
  302. .item .timer{
  303. position: absolute;
  304. background: url(@/assets/image/answerGame/qiXi/timer.png) no-repeat;
  305. background-size: 100% 100%;
  306. width: 80px;
  307. height: 80px;
  308. top: 5%;
  309. right: 10%;
  310. display: flex;
  311. justify-content: center;
  312. align-items: center;
  313. }
  314. .timer .second{
  315. font-size: 16px;
  316. color: #fff;
  317. font-weight: 600;
  318. }
  319. .item .topicNum{
  320. position: absolute;
  321. background: url(@/assets/image/answerGame/qiXi/topicNum.png) no-repeat;
  322. background-size: 100% 100%;
  323. width: 120px;
  324. height: 42px;
  325. top: 14%;
  326. left: 4.5%;
  327. display: flex;
  328. justify-content: center;
  329. align-items: center;
  330. }
  331. .topicNum .topic{
  332. font-size: 16px;
  333. color: #fff;
  334. font-weight: 600;
  335. }
  336. .item .questionBox{
  337. position: absolute;
  338. width: 375px;
  339. top: 18%;
  340. left: 0;
  341. right: 0;
  342. display: flex;
  343. flex-direction: column;
  344. justify-content: center;
  345. align-items: center;
  346. }
  347. .questionBox .title{
  348. margin:auto 50px;
  349. height: 180px;
  350. font-size: 18px;
  351. display: flex;
  352. flex-direction: column;
  353. justify-content: center;
  354. align-items: center;
  355. /* font-weight: 600; */
  356. }
  357. .content{
  358. width: 100%;
  359. display: flex;
  360. flex-direction: column;
  361. justify-content: center;
  362. align-items: center;
  363. }
  364. .answerItem{
  365. cursor: pointer;
  366. margin: 10px 0;
  367. color: #bc2641;
  368. background: rgb(221, 218, 218);
  369. border-radius: 20px;
  370. width: 80%;
  371. height: 40px;
  372. line-height: 40px;
  373. display: flex;
  374. justify-content: center;
  375. align-items: center;
  376. position: relative;
  377. }
  378. .right {
  379. /*选择正确的答案颜色*/
  380. background: #3ede58;
  381. color: #fff;
  382. }
  383. .error {
  384. /*选择错误的答案颜色*/
  385. background: #e53117;
  386. color: #fff;
  387. }
  388. .invisible{
  389. width: 25px;
  390. position: absolute;
  391. right: 15px;
  392. }
  393. .gameBox .home{
  394. position: relative;
  395. z-index: 10;
  396. background: url(@/assets/image/answerGame/qiXi/homeBg.png) no-repeat;
  397. background-size: 100% 100%;
  398. width: 375px;
  399. height: 667px;
  400. }
  401. .home .rules{
  402. cursor: pointer;
  403. position: absolute;
  404. width: 50px;
  405. top: 22%;
  406. left: 2%;
  407. }
  408. .home .top{
  409. position: absolute;
  410. bottom: 18.5%;
  411. left: 0;
  412. right: 0;
  413. margin:auto;
  414. display: flex;
  415. justify-content: center;
  416. align-items: center;
  417. }
  418. .home .answer{
  419. cursor: pointer;
  420. position: absolute;
  421. width: 200px;
  422. bottom: 17%;
  423. left: 0;
  424. right: 0;
  425. margin:auto;
  426. }
  427. .home .exit{
  428. cursor: pointer;
  429. position: absolute;
  430. width: 200px;
  431. bottom: 8%;
  432. left: 0;
  433. right: 0;
  434. margin:auto;
  435. }
  436. .hidden {
  437. display: none;
  438. }
  439. .show {
  440. display: block;
  441. }
  442. .dim {
  443. /* opacity:0.6; */
  444. height:100%;
  445. width:100%;
  446. background: rgba(0,0,0,.4);
  447. pointer-events: none;
  448. }
  449. .clearfix:before,
  450. .clearfix:after {
  451. display: table;
  452. content: "";
  453. }
  454. .clearfix:after {
  455. clear: both
  456. }
  457. .ruleWrapper{
  458. position: absolute;
  459. top: 50%;
  460. left: 50%;
  461. transform: translate(-50%, -50%);
  462. z-index: 12;
  463. }
  464. .box-card {
  465. width: 350px;
  466. }
  467. .confirmWrapper{
  468. position: absolute;
  469. background: url(@/assets/image/answerGame/qiXi/finish.png) no-repeat;
  470. background-size: 100% 100%;
  471. width: 240px;
  472. height: 275px;
  473. top: 50%;
  474. left: 50%;
  475. transform: translate(-50%, -50%);
  476. z-index: 12;
  477. display: flex;
  478. justify-content: center;
  479. align-items: flex-end;
  480. }
  481. .confirmWrapper .goHome{
  482. cursor: pointer;
  483. width: 100px;
  484. height: 40px;
  485. margin-bottom: 20px;
  486. }
  487. .failWrapper{
  488. position: absolute;
  489. background: url(@/assets/image/answerGame/qiXi/fail.png) no-repeat;
  490. background-size: 100% 100%;
  491. width: 240px;
  492. height: 208.5px;
  493. top: 50%;
  494. left: 50%;
  495. transform: translate(-50%, -50%);
  496. z-index: 12;
  497. display: flex;
  498. justify-content: center;
  499. align-items: flex-end;
  500. }
  501. .failWrapper .goHome{
  502. cursor: pointer;
  503. width: 100px;
  504. height: 40px;
  505. margin-bottom: 20px;
  506. }
  507. </style>
  508. <style>
  509. .el-card__header {
  510. padding: 10px 20px !important;
  511. }
  512. </style>