QiXiAnswerGame.vue 14 KB

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