issue.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <!-- -->
  2. <template>
  3. <div class="issue">
  4. <div class="main">
  5. <div class="top">
  6. <h2 v-if="flag === 'tow'">{{ Mylangue ? "趣味课题" : "Quiz" }}</h2>
  7. <h2 v-else>&nbsp;</h2>
  8. <i class="el-icon-close" @click="$emit('close')"></i>
  9. </div>
  10. <!-- 开始答题 -->
  11. <div class="begin" v-show="flag === 'one'">
  12. <div class="begin_left">
  13. <div class="renwen"></div>
  14. </div>
  15. <div class="begin_right">
  16. <template v-if="Mylangue">
  17. <p>欢迎来到</p>
  18. <p>大理洱海科普教育中心趣味问答小游戏,</p>
  19. <p>您将随机抽取二十道题进行作答,</p>
  20. <p>答对十二题及以上为闯关成功!</p>
  21. </template>
  22. <p v-else>
  23. You will be given a random selection of 20 questions to answer, and
  24. if you answer 12 questions correctly or above, you will be declared
  25. a winner.
  26. </p>
  27. <div class="btnn" @click="beginTopic">{{Mylangue?'开始答题':'Start'}}</div>
  28. </div>
  29. </div>
  30. <!-- 答题页面 -->
  31. <div class="topic" v-if="flag === 'tow'">
  32. <div class="conBox">
  33. <p class="topicTxt">
  34. {{ topicInd + 1 }}.{{ topic[topicInd].title }}---{{
  35. topic[topicInd].correct
  36. }}
  37. </p>
  38. <!-- 答对或答错之后的页面颜色变化 -->
  39. <ul class="topic_con" v-if="caseErr">
  40. <li
  41. v-for="(item, index) in topic[topicInd].answer"
  42. :key="index"
  43. :class="{
  44. cuoWu: caseABC === item.id,
  45. zhengQue: item.id === topic[topicInd].correct,
  46. }"
  47. >
  48. <div class="case">
  49. <!-- 选中了之后的显示 -->
  50. <div></div>
  51. </div>
  52. <span :class="{ active: caseInd === index }">{{
  53. item.id + "、" + item.txt
  54. }}</span>
  55. </li>
  56. </ul>
  57. <!-- 答题--选择答案 -->
  58. <ul class="topic_con" v-else>
  59. <li
  60. v-for="(item, index) in topic[topicInd].answer"
  61. :key="index"
  62. :class="{ xuanze: caseInd === index }"
  63. >
  64. <div class="case" @click="select(index, item.id)">
  65. <!-- 选中了之后的显示 -->
  66. <div></div>
  67. </div>
  68. <span
  69. @click="select(index, item.id)"
  70. :class="{ active: caseInd === index }"
  71. >{{ item.id + "、" + item.txt }}</span
  72. >
  73. </li>
  74. </ul>
  75. </div>
  76. <!-- 下面的按钮 -->
  77. <div class="topic_btn" @click="nextTi" v-if="caseErr">
  78. {{ topicInd < 20 ? `${Mylangue?'下一题':'Next'}` : `${Mylangue?'完成问答':'accomplish'}` }}
  79. </div>
  80. <div class="topic_btn" @click="btnOk" v-else>{{Mylangue?'确 定':'Confirm'}}</div>
  81. </div>
  82. <!-- 答对通关 -->
  83. <div class="topicDui" v-if="flag === 'three'">
  84. <img class="tini" src="@/assets/img/win.png" alt="" />
  85. <div>
  86. <p>{{Mylangue?'您的得分:':'Your Score:'}}{{ cunot + "0" }}</p>
  87. <p>{{Mylangue?'分享海报,传播洱海的美丽文化!':"Share this poster to spread the word about Erhai's rich culture."}}</p>
  88. <img src="share/shareM.png" alt="" v-if="isMobile" />
  89. <img src="share/share.png" alt="" v-else />
  90. <a class="btnn" href="share/shareM.png" download v-if="isMobile"
  91. >保存海报</a
  92. >
  93. <a class="btnn" href="share/share.png" download v-else>{{Mylangue?'保存海报':'Save the poster'}}</a>
  94. </div>
  95. </div>
  96. <!-- 答错失败 -->
  97. <div class="topicCuo" v-if="flag === 'four'">
  98. <img src="@/assets/img/lose.png" alt="" />
  99. <p>{{Mylangue?'您的得分:':'Your Score:'}}{{ cunot + "0" }}</p>
  100. <p>{{Mylangue?'失败乃兵家常事,大侠请重头再来':'Try again!'}}</p>
  101. <div @click="beginTopic()">{{Mylangue?'重新开始':'Restart'}}</div>
  102. </div>
  103. </div>
  104. </div>
  105. </template>
  106. <script>
  107. //引入题目
  108. import { questions } from "./data.js";
  109. export default {
  110. name: "issue",
  111. components: {},
  112. data() {
  113. //这里存放数据
  114. return {
  115. flag: "one",
  116. // 题目组
  117. topic: [],
  118. topicInd: 0, //用来控制题目的索引
  119. cunot: 0, //用来记录答对的题目个数
  120. caseInd: null, //用来控制选择的样式
  121. caseABC: null, //用来记录当前选择的答案,进行判断
  122. caseErr: "", //点击确定判断答对了还是错了'zhengQue'--答对;'cuoWu'--答错
  123. };
  124. },
  125. //监听属性 类似于data概念
  126. computed: {},
  127. //监控data中的数据变化
  128. watch: {},
  129. //方法集合
  130. methods: {
  131. //点击答错里面的下一题
  132. nextTi() {
  133. // 最后一题
  134. if (this.topicInd === 19 && this.cunot >= 12) {
  135. this.flag = "three";
  136. } else if (this.topicInd === 19 && this.cunot < 12) {
  137. this.flag = "four";
  138. }
  139. this.caseErr = "";
  140. if (this.topicInd < 20) this.topicInd++;
  141. }, //选择题目
  142. select(index, id) {
  143. this.caseInd = index;
  144. this.caseABC = id;
  145. },
  146. //点击确定
  147. btnOk() {
  148. if (this.caseInd === null) return this.$message.warning(`${this.Mylangue?'未选择答案':'No Answer is Selected'}`);
  149. if (this.topic[this.topicInd].correct === this.caseABC) {
  150. // console.log('答对了');
  151. this.caseErr = "zhengQue";
  152. this.cunot++;
  153. } else {
  154. // console.log('答错了');
  155. this.caseErr = "cuoWu";
  156. }
  157. this.caseInd = null;
  158. },
  159. // 点击开始答题
  160. beginTopic() {
  161. this.caseInd = null;
  162. this.cunot = 0;
  163. this.topicInd = 0;
  164. this.caseErr = "";
  165. this.flag = "tow";
  166. this.getTopic();
  167. },
  168. // 封装随机获取10道题目
  169. getTopic() {
  170. this.topic = [];
  171. let arr = [];
  172. for (let i = 0; i < 101; i++) {
  173. //一个从0到101的数组
  174. arr.push(i);
  175. }
  176. arr.sort(function () {
  177. //随机打乱这个数组
  178. return Math.random() - 0.5;
  179. });
  180. arr.length = 20; //改写长度
  181. arr.forEach((v) => {
  182. this.topic.push(questions[v]);
  183. });
  184. // console.log(999, this.topic); //控制台会输出20个不同的数
  185. },
  186. },
  187. //生命周期 - 创建完成(可以访问当前this实例)
  188. created() {
  189. // console.log('题目长度',questions.length);
  190. },
  191. //生命周期 - 挂载完成(可以访问DOM元素)
  192. mounted() {},
  193. beforeCreate() {}, //生命周期 - 创建之前
  194. beforeMount() {}, //生命周期 - 挂载之前
  195. beforeUpdate() {}, //生命周期 - 更新之前
  196. updated() {}, //生命周期 - 更新之后
  197. beforeDestroy() {}, //生命周期 - 销毁之前
  198. destroyed() {}, //生命周期 - 销毁完成
  199. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  200. };
  201. </script>
  202. <style lang='less' scoped>
  203. ::-webkit-scrollbar-thumb {
  204. outline: 2px solid #165491;
  205. }
  206. .issue {
  207. position: fixed;
  208. top: 0;
  209. left: 0;
  210. z-index: 9999;
  211. width: 100vw;
  212. height: 100vh;
  213. .main {
  214. padding: 20px;
  215. border-radius: 3px;
  216. position: absolute;
  217. top: 50%;
  218. left: 50%;
  219. transform: translate(-50%, -50%);
  220. z-index: 9999;
  221. width: 1100px;
  222. height: 700px;
  223. background: url("../../../assets/img/bg.png");
  224. background-size: 100% 100%;
  225. .top {
  226. margin-bottom: 20px;
  227. margin-top: 80px;
  228. display: flex;
  229. justify-content: space-between;
  230. align-items: center;
  231. color: #165491;
  232. font-weight: 700;
  233. font-size: 22px;
  234. & > i {
  235. cursor: pointer;
  236. font-size: 30px;
  237. }
  238. }
  239. .begin {
  240. margin: 20px auto 0;
  241. display: flex;
  242. width: 750px;
  243. height: 450px;
  244. .begin_left {
  245. position: relative;
  246. width: 286px;
  247. height: 470px;
  248. background: url("../../../assets/img/issue.png");
  249. background-size: 100% 100%;
  250. .renwen {
  251. position: absolute;
  252. left: 10px;
  253. bottom: 0;
  254. width: 45px;
  255. height: 88px;
  256. background: url("../../../assets/img/renwen.png");
  257. background-size: 100% 100%;
  258. }
  259. }
  260. .begin_right {
  261. padding-top: 80px;
  262. flex: 1;
  263. color: #fff;
  264. & > p {
  265. text-align: center;
  266. margin-bottom: 20px;
  267. font-size: 24px;
  268. &:nth-of-type(1) {
  269. width: 94%;
  270. }
  271. }
  272. .btnn {
  273. padding-right: 20px;
  274. cursor: pointer;
  275. margin: 100px auto 0;
  276. width: 257px;
  277. height: 75px;
  278. background: url("../../../assets/img/btn.png");
  279. background-size: 100% 100%;
  280. display: flex;
  281. justify-content: center;
  282. align-items: center;
  283. font-size: 24px;
  284. }
  285. }
  286. }
  287. .topic {
  288. position: relative;
  289. padding: 30px 50px;
  290. border-radius: 3px;
  291. width: 100%;
  292. height: 530px;
  293. background-color: rgba(22, 84, 145, 0.5);
  294. color: #fff;
  295. .topicTxt {
  296. font-size: 20px;
  297. line-height: 30px;
  298. }
  299. .topic_con {
  300. width: 90%;
  301. margin: 0 auto;
  302. li {
  303. display: flex;
  304. height: 80px;
  305. align-items: center;
  306. .case {
  307. cursor: pointer;
  308. width: 30px;
  309. height: 30px;
  310. border: 2px solid #fff;
  311. margin-right: 30px;
  312. border-radius: 50%;
  313. & > div {
  314. margin: 3px;
  315. width: 20px;
  316. height: 20px;
  317. background-color: transparent;
  318. border-radius: 50%;
  319. }
  320. }
  321. & > span {
  322. font-size: 18px;
  323. }
  324. }
  325. .xuanze {
  326. .case {
  327. & > div {
  328. background-color: #fff;
  329. }
  330. }
  331. }
  332. .cuoWu {
  333. .case {
  334. & > div {
  335. background-color: #FF5050;
  336. }
  337. }
  338. }
  339. .zhengQue {
  340. .case {
  341. & > div {
  342. background-color: #50FFA2;
  343. }
  344. }
  345. }
  346. }
  347. .topic_btn {
  348. padding-right: 20px;
  349. cursor: pointer;
  350. margin: 10px auto 0;
  351. width: 257px;
  352. height: 75px;
  353. background: url("../../../assets/img/btn.png");
  354. background-size: 100% 100%;
  355. display: flex;
  356. justify-content: center;
  357. align-items: center;
  358. font-size: 24px;
  359. }
  360. .error {
  361. position: absolute;
  362. bottom: 0;
  363. left: 0;
  364. height: 100%;
  365. width: 100%;
  366. background-color: rgba(0, 0, 0, 0.8);
  367. p {
  368. margin: 20px;
  369. font-size: 24px;
  370. text-align: center;
  371. }
  372. div {
  373. padding-right: 20px;
  374. cursor: pointer;
  375. margin: 10px auto 0;
  376. width: 257px;
  377. height: 75px;
  378. background: url("../../../assets/img/btn.png");
  379. background-size: 100% 100%;
  380. display: flex;
  381. justify-content: center;
  382. align-items: center;
  383. font-size: 24px;
  384. }
  385. }
  386. }
  387. // 答题失败的页面
  388. .topicCuo {
  389. width: 100%;
  390. text-align: center;
  391. color: #fff;
  392. & > img {
  393. width: 300px;
  394. height: 300px;
  395. }
  396. & > p {
  397. text-align: center;
  398. font-size: 20px;
  399. margin: 15px 0;
  400. }
  401. & > div {
  402. padding-right: 20px;
  403. cursor: pointer;
  404. margin: 80px auto 0;
  405. width: 257px;
  406. height: 75px;
  407. background: url("../../../assets/img/btn.png");
  408. background-size: 100% 100%;
  409. display: flex;
  410. justify-content: center;
  411. align-items: center;
  412. font-size: 24px;
  413. }
  414. }
  415. // 答题通过的页面
  416. .topicDui {
  417. color: #fff;
  418. .tini {
  419. position: absolute;
  420. top: 60px;
  421. left: 10px;
  422. }
  423. & > div {
  424. text-align: center;
  425. & > p {
  426. font-size: 22px;
  427. }
  428. & > img {
  429. margin: 30px 0;
  430. max-width: 600px;
  431. max-height: 410px;
  432. }
  433. .btnn {
  434. padding-right: 20px;
  435. cursor: pointer;
  436. margin: 0px auto 0;
  437. width: 257px;
  438. height: 75px;
  439. background: url("../../../assets/img/btn.png");
  440. background-size: 100% 100%;
  441. display: flex;
  442. justify-content: center;
  443. align-items: center;
  444. font-size: 24px;
  445. }
  446. }
  447. }
  448. }
  449. }
  450. @media only screen and (max-width: 800px) {
  451. .issue {
  452. .main {
  453. top: auto;
  454. bottom: 5px;
  455. transform: translate(-50%, 0);
  456. width: 100%;
  457. max-width: 350px;
  458. height: calc(100vh - 40px);
  459. background: url("../../../assets/imgM/bg.png");
  460. background-size: 100% 100%;
  461. padding-top: 70px;
  462. .top {
  463. margin-bottom: 5px;
  464. margin-top: 0;
  465. }
  466. .begin {
  467. width: 100%;
  468. margin: 0 auto;
  469. display: block;
  470. .begin_left {
  471. margin: 0 auto;
  472. width: 130px;
  473. height: 240px;
  474. .renwen {
  475. left: -15px;
  476. }
  477. }
  478. .begin_right {
  479. padding-top: 10px;
  480. & > p {
  481. font-size: 16px;
  482. }
  483. .btnn {
  484. padding-right: 10px;
  485. width: 140px;
  486. height: 42px;
  487. margin: 10px auto 0;
  488. font-size: 16px;
  489. }
  490. }
  491. }
  492. .topic {
  493. padding: 10px;
  494. height: calc(100% - 35px);
  495. .topicTxt {
  496. font-size: 18px;
  497. line-height: 24px;
  498. }
  499. .topic_con {
  500. & > li {
  501. height: auto;
  502. padding: 10px 0;
  503. font-size: 16px;
  504. .case {
  505. width: 20px;
  506. height: 20px;
  507. margin-right: 15px;
  508. min-width: 20px;
  509. & > div {
  510. width: 10px;
  511. height: 10px;
  512. }
  513. }
  514. }
  515. }
  516. .conBox {
  517. height: calc(100% - 60px);
  518. overflow-y: auto;
  519. }
  520. .topic_btn {
  521. padding-right: 10px;
  522. position: absolute;
  523. left: 50%;
  524. bottom: 20px;
  525. transform: translateX(-50%);
  526. width: 140px;
  527. height: 42px;
  528. font-size: 16px;
  529. }
  530. .error {
  531. & > p {
  532. font-size: 16px;
  533. }
  534. .errBtn {
  535. padding-right: 10px;
  536. width: 140px;
  537. height: 42px;
  538. margin: 10px auto 0;
  539. font-size: 16px;
  540. }
  541. }
  542. }
  543. .topicCuo {
  544. & > img {
  545. width: 200px;
  546. height: 200px;
  547. }
  548. & > div {
  549. padding-right: 10px;
  550. width: 140px;
  551. height: 42px;
  552. margin: 50px auto 0;
  553. font-size: 16px;
  554. }
  555. }
  556. .topicDui {
  557. padding-top: 60px;
  558. .tini {
  559. width: 120px;
  560. height: 120px;
  561. left: 50%;
  562. transform: translateX(-50%);
  563. top: 55px;
  564. }
  565. & > div {
  566. & > p {
  567. font-size: 16px;
  568. }
  569. & > img {
  570. max-height: 280px;
  571. }
  572. .btnn {
  573. padding-right: 10px;
  574. width: 140px;
  575. height: 42px;
  576. margin: 10px auto 0;
  577. font-size: 16px;
  578. }
  579. }
  580. }
  581. }
  582. }
  583. }
  584. </style>