123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- <!-- -->
- <template>
- <div class="issue">
- <div class="main">
- <div class="top">
- <h2 v-if="flag === 'tow'">{{ Mylangue ? "趣味课题" : "Quiz" }}</h2>
- <h2 v-else> </h2>
- <i class="el-icon-close" @click="$emit('close')"></i>
- </div>
- <!-- 开始答题 -->
- <div class="begin" v-show="flag === 'one'">
- <div class="begin_left">
- <div class="renwen"></div>
- </div>
- <div class="begin_right">
- <template v-if="Mylangue">
- <p>欢迎来到</p>
- <p>大理洱海科普教育中心趣味问答小游戏,</p>
- <p>您将随机抽取二十道题进行作答,</p>
- <p>答对十二题及以上为闯关成功!</p>
- </template>
- <p v-else>
- You will be given a random selection of 20 questions to answer, and
- if you answer 12 questions correctly or above, you will be declared
- a winner.
- </p>
- <div class="btnn" @click="beginTopic">{{Mylangue?'开始答题':'Start'}}</div>
- </div>
- </div>
- <!-- 答题页面 -->
- <div class="topic" v-if="flag === 'tow'">
- <div class="conBox">
- <p class="topicTxt">
- {{ topicInd + 1 }}.{{ topic[topicInd].title }}---{{
- topic[topicInd].correct
- }}
- </p>
- <!-- 答对或答错之后的页面颜色变化 -->
- <ul class="topic_con" v-if="caseErr">
- <li
- v-for="(item, index) in topic[topicInd].answer"
- :key="index"
- :class="{
- cuoWu: caseABC === item.id,
- zhengQue: item.id === topic[topicInd].correct,
- }"
- >
- <div class="case">
- <!-- 选中了之后的显示 -->
- <div></div>
- </div>
- <span :class="{ active: caseInd === index }">{{
- item.id + "、" + item.txt
- }}</span>
- </li>
- </ul>
- <!-- 答题--选择答案 -->
- <ul class="topic_con" v-else>
- <li
- v-for="(item, index) in topic[topicInd].answer"
- :key="index"
- :class="{ xuanze: caseInd === index }"
- >
- <div class="case" @click="select(index, item.id)">
- <!-- 选中了之后的显示 -->
- <div></div>
- </div>
- <span
- @click="select(index, item.id)"
- :class="{ active: caseInd === index }"
- >{{ item.id + "、" + item.txt }}</span
- >
- </li>
- </ul>
- </div>
- <!-- 下面的按钮 -->
- <div class="topic_btn" @click="nextTi" v-if="caseErr">
- {{ topicInd < 20 ? `${Mylangue?'下一题':'Next'}` : `${Mylangue?'完成问答':'accomplish'}` }}
- </div>
- <div class="topic_btn" @click="btnOk" v-else>{{Mylangue?'确 定':'Confirm'}}</div>
- </div>
- <!-- 答对通关 -->
- <div class="topicDui" v-if="flag === 'three'">
- <img class="tini" src="@/assets/img/win.png" alt="" />
- <div>
- <p>{{Mylangue?'您的得分:':'Your Score:'}}{{ cunot + "0" }}</p>
- <p>{{Mylangue?'分享海报,传播洱海的美丽文化!':"Share this poster to spread the word about Erhai's rich culture."}}</p>
- <img src="share/shareM.png" alt="" v-if="isMobile" />
- <img src="share/share.png" alt="" v-else />
- <a class="btnn" href="share/shareM.png" download v-if="isMobile"
- >保存海报</a
- >
- <a class="btnn" href="share/share.png" download v-else>{{Mylangue?'保存海报':'Save the poster'}}</a>
- </div>
- </div>
- <!-- 答错失败 -->
- <div class="topicCuo" v-if="flag === 'four'">
- <img src="@/assets/img/lose.png" alt="" />
- <p>{{Mylangue?'您的得分:':'Your Score:'}}{{ cunot + "0" }}</p>
- <p>{{Mylangue?'失败乃兵家常事,大侠请重头再来':'Try again!'}}</p>
- <div @click="beginTopic()">{{Mylangue?'重新开始':'Restart'}}</div>
- </div>
- </div>
- </div>
- </template>
- <script>
- //引入题目
- import { questions } from "./data.js";
- export default {
- name: "issue",
- components: {},
- data() {
- //这里存放数据
- return {
- flag: "one",
- // 题目组
- topic: [],
- topicInd: 0, //用来控制题目的索引
- cunot: 0, //用来记录答对的题目个数
- caseInd: null, //用来控制选择的样式
- caseABC: null, //用来记录当前选择的答案,进行判断
- caseErr: "", //点击确定判断答对了还是错了'zhengQue'--答对;'cuoWu'--答错
- };
- },
- //监听属性 类似于data概念
- computed: {},
- //监控data中的数据变化
- watch: {},
- //方法集合
- methods: {
- //点击答错里面的下一题
- nextTi() {
- // 最后一题
- if (this.topicInd === 19 && this.cunot >= 12) {
- this.flag = "three";
- } else if (this.topicInd === 19 && this.cunot < 12) {
- this.flag = "four";
- }
- this.caseErr = "";
- if (this.topicInd < 20) this.topicInd++;
- }, //选择题目
- select(index, id) {
- this.caseInd = index;
- this.caseABC = id;
- },
- //点击确定
- btnOk() {
- if (this.caseInd === null) return this.$message.warning(`${this.Mylangue?'未选择答案':'No Answer is Selected'}`);
- if (this.topic[this.topicInd].correct === this.caseABC) {
- // console.log('答对了');
- this.caseErr = "zhengQue";
- this.cunot++;
- } else {
- // console.log('答错了');
- this.caseErr = "cuoWu";
- }
- this.caseInd = null;
- },
- // 点击开始答题
- beginTopic() {
- this.caseInd = null;
- this.cunot = 0;
- this.topicInd = 0;
- this.caseErr = "";
- this.flag = "tow";
- this.getTopic();
- },
- // 封装随机获取10道题目
- getTopic() {
- this.topic = [];
- let arr = [];
- for (let i = 0; i < 101; i++) {
- //一个从0到101的数组
- arr.push(i);
- }
- arr.sort(function () {
- //随机打乱这个数组
- return Math.random() - 0.5;
- });
- arr.length = 20; //改写长度
- arr.forEach((v) => {
- this.topic.push(questions[v]);
- });
- // console.log(999, this.topic); //控制台会输出20个不同的数
- },
- },
- //生命周期 - 创建完成(可以访问当前this实例)
- created() {
- // console.log('题目长度',questions.length);
- },
- //生命周期 - 挂载完成(可以访问DOM元素)
- mounted() {},
- beforeCreate() {}, //生命周期 - 创建之前
- beforeMount() {}, //生命周期 - 挂载之前
- beforeUpdate() {}, //生命周期 - 更新之前
- updated() {}, //生命周期 - 更新之后
- beforeDestroy() {}, //生命周期 - 销毁之前
- destroyed() {}, //生命周期 - 销毁完成
- activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
- };
- </script>
- <style lang='less' scoped>
- ::-webkit-scrollbar-thumb {
- outline: 2px solid #165491;
- }
- .issue {
- position: fixed;
- top: 0;
- left: 0;
- z-index: 9999;
- width: 100vw;
- height: 100vh;
- .main {
- padding: 20px;
- border-radius: 3px;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- z-index: 9999;
- width: 1100px;
- height: 700px;
- background: url("../../../assets/img/bg.png");
- background-size: 100% 100%;
- .top {
- margin-bottom: 20px;
- margin-top: 80px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- color: #165491;
- font-weight: 700;
- font-size: 22px;
- & > i {
- cursor: pointer;
- font-size: 30px;
- }
- }
- .begin {
- margin: 20px auto 0;
- display: flex;
- width: 750px;
- height: 450px;
- .begin_left {
- position: relative;
- width: 286px;
- height: 470px;
- background: url("../../../assets/img/issue.png");
- background-size: 100% 100%;
- .renwen {
- position: absolute;
- left: 10px;
- bottom: 0;
- width: 45px;
- height: 88px;
- background: url("../../../assets/img/renwen.png");
- background-size: 100% 100%;
- }
- }
- .begin_right {
- padding-top: 80px;
- flex: 1;
- color: #fff;
- & > p {
- text-align: center;
- margin-bottom: 20px;
- font-size: 24px;
- &:nth-of-type(1) {
- width: 94%;
- }
- }
- .btnn {
- padding-right: 20px;
- cursor: pointer;
- margin: 100px auto 0;
- width: 257px;
- height: 75px;
- background: url("../../../assets/img/btn.png");
- background-size: 100% 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 24px;
- }
- }
- }
- .topic {
- position: relative;
- padding: 30px 50px;
- border-radius: 3px;
- width: 100%;
- height: 530px;
- background-color: rgba(22, 84, 145, 0.5);
- color: #fff;
- .topicTxt {
- font-size: 20px;
- line-height: 30px;
- }
- .topic_con {
- width: 90%;
- margin: 0 auto;
- li {
- display: flex;
- height: 80px;
- align-items: center;
- .case {
- cursor: pointer;
- width: 30px;
- height: 30px;
- border: 2px solid #fff;
- margin-right: 30px;
- border-radius: 50%;
- & > div {
- margin: 3px;
- width: 20px;
- height: 20px;
- background-color: transparent;
- border-radius: 50%;
- }
- }
- & > span {
- font-size: 18px;
- }
- }
- .xuanze {
- .case {
- & > div {
- background-color: #fff;
- }
- }
- }
- .cuoWu {
- .case {
- & > div {
- background-color: #FF5050;
- }
- }
- }
- .zhengQue {
- .case {
- & > div {
- background-color: #50FFA2;
- }
- }
- }
- }
- .topic_btn {
- padding-right: 20px;
- cursor: pointer;
- margin: 10px auto 0;
- width: 257px;
- height: 75px;
- background: url("../../../assets/img/btn.png");
- background-size: 100% 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 24px;
- }
- .error {
- position: absolute;
- bottom: 0;
- left: 0;
- height: 100%;
- width: 100%;
- background-color: rgba(0, 0, 0, 0.8);
- p {
- margin: 20px;
- font-size: 24px;
- text-align: center;
- }
- div {
- padding-right: 20px;
- cursor: pointer;
- margin: 10px auto 0;
- width: 257px;
- height: 75px;
- background: url("../../../assets/img/btn.png");
- background-size: 100% 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 24px;
- }
- }
- }
- // 答题失败的页面
- .topicCuo {
- width: 100%;
- text-align: center;
- color: #fff;
- & > img {
- width: 300px;
- height: 300px;
- }
- & > p {
- text-align: center;
- font-size: 20px;
- margin: 15px 0;
- }
- & > div {
- padding-right: 20px;
- cursor: pointer;
- margin: 80px auto 0;
- width: 257px;
- height: 75px;
- background: url("../../../assets/img/btn.png");
- background-size: 100% 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 24px;
- }
- }
- // 答题通过的页面
- .topicDui {
- color: #fff;
- .tini {
- position: absolute;
- top: 60px;
- left: 10px;
- }
- & > div {
- text-align: center;
- & > p {
- font-size: 22px;
- }
- & > img {
- margin: 30px 0;
- max-width: 600px;
- max-height: 410px;
- }
- .btnn {
- padding-right: 20px;
- cursor: pointer;
- margin: 0px auto 0;
- width: 257px;
- height: 75px;
- background: url("../../../assets/img/btn.png");
- background-size: 100% 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 24px;
- }
- }
- }
- }
- }
- @media only screen and (max-width: 800px) {
- .issue {
- .main {
- top: auto;
- bottom: 5px;
- transform: translate(-50%, 0);
- width: 100%;
- max-width: 350px;
- height: calc(100vh - 40px);
- background: url("../../../assets/imgM/bg.png");
- background-size: 100% 100%;
- padding-top: 70px;
- .top {
- margin-bottom: 5px;
- margin-top: 0;
- }
- .begin {
- width: 100%;
- margin: 0 auto;
- display: block;
- .begin_left {
- margin: 0 auto;
- width: 130px;
- height: 240px;
- .renwen {
- left: -15px;
- }
- }
- .begin_right {
- padding-top: 10px;
- & > p {
- font-size: 16px;
- }
- .btnn {
- padding-right: 10px;
- width: 140px;
- height: 42px;
- margin: 10px auto 0;
- font-size: 16px;
- }
- }
- }
- .topic {
- padding: 10px;
- height: calc(100% - 35px);
- .topicTxt {
- font-size: 18px;
- line-height: 24px;
- }
- .topic_con {
- & > li {
- height: auto;
- padding: 10px 0;
- font-size: 16px;
- .case {
- width: 20px;
- height: 20px;
- margin-right: 15px;
- min-width: 20px;
- & > div {
- width: 10px;
- height: 10px;
- }
- }
- }
- }
- .conBox {
- height: calc(100% - 60px);
- overflow-y: auto;
- }
- .topic_btn {
- padding-right: 10px;
- position: absolute;
- left: 50%;
- bottom: 20px;
- transform: translateX(-50%);
- width: 140px;
- height: 42px;
- font-size: 16px;
- }
- .error {
- & > p {
- font-size: 16px;
- }
- .errBtn {
- padding-right: 10px;
- width: 140px;
- height: 42px;
- margin: 10px auto 0;
- font-size: 16px;
- }
- }
- }
- .topicCuo {
- & > img {
- width: 200px;
- height: 200px;
- }
- & > div {
- padding-right: 10px;
- width: 140px;
- height: 42px;
- margin: 50px auto 0;
- font-size: 16px;
- }
- }
- .topicDui {
- padding-top: 60px;
- .tini {
- width: 120px;
- height: 120px;
- left: 50%;
- transform: translateX(-50%);
- top: 55px;
- }
- & > div {
- & > p {
- font-size: 16px;
- }
- & > img {
- max-height: 280px;
- }
- .btnn {
- padding-right: 10px;
- width: 140px;
- height: 42px;
- margin: 10px auto 0;
- font-size: 16px;
- }
- }
- }
- }
- }
- }
- </style>
|