ZhangXianQiang
2024-06-06 0f52b1e924693795faea619cd68ea7ecc855a61f
feat:倒计时
5个文件已修改
3个文件已添加
297 ■■■■■ 已修改文件
components.d.ts 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/ExamInfo/index.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/index.js 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/modules/exam.js 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/exam/components/answer-main/answer-multiple/index.vue 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/exam/components/answer-main/answer-single/index.vue 97 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/exam/components/answer-time/index.vue 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/exam/index.vue 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
components.d.ts
@@ -13,6 +13,7 @@
    ElCol: typeof import('element-plus/es')['ElCol']
    ElCollapse: typeof import('element-plus/es')['ElCollapse']
    ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
    ElCountdown: typeof import('element-plus/es')['ElCountdown']
    ElIcon: typeof import('element-plus/es')['ElIcon']
    ElInput: typeof import('element-plus/es')['ElInput']
    ElPagination: typeof import('element-plus/es')['ElPagination']
src/components/ExamInfo/index.vue
@@ -17,6 +17,6 @@
<style lang="scss" scoped>
.img-item {
  max-width: 500px;
  max-width: 400px;
}
</style>
src/store/index.js
@@ -2,4 +2,5 @@
const pinia = createPinia();
export default pinia;
export * from './modules/user';
export * from './modules/user.js';
export * from './modules/exam.js';
src/store/modules/exam.js
New file
@@ -0,0 +1,11 @@
import { ref } from 'vue';
import { defineStore } from 'pinia';
const useExamStore = defineStore('exam', () => {
  const examInfo = ref(null);
  return {
    examInfo
  }
});
export default useExamStore;
src/views/exam/components/answer-main/answer-multiple/index.vue
New file
@@ -0,0 +1,123 @@
<template>
  <div class="answer-container w-full h-full">
    <el-scrollbar>
      <ExamInfo class="mb-5"></ExamInfo>
      <div class="answer-content">
        <div class="answer-item flex" v-for="item, index in examInfo.answerList" @click="answerClick(item)"
          :class="answerState(item)">
          <div class="answer-icon flex flex-col justify-center items-center flex-shrink-0">{{ item.type }}</div>
          <div class="answer-text text-gray-700">{{ item.text }}</div>
        </div>
      </div>
    </el-scrollbar>
  </div>
</template>
<script setup>
import { ref } from 'vue';
import ExamInfo from '@/components/ExamInfo/index.vue';
const examInfo = ref({
  qId: 1,
  answerList: [
    {
      type: 'A',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
    {
      type: 'B',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
    {
      type: 'C',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
    {
      type: 'D',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
    {
      type: 'E',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
    {
      type: 'F',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
  ]
});
const activeIndex = ref(null);
const answerClick = (item) => {
  if(item) {
    resetAnswer();
    item.isActive = true
  }
};
const answerState = (item) => {
  return {
    active: item.isActive
  };
}
const resetAnswer = () => {
  examInfo.value.answerList.forEach(item => item.isActive = false);
}
</script>
<style lang="scss" scoped>
.answer-item {
  max-width: 500px;
  border-radius: 10px;
  border: 1px solid #DCDFE6;
  overflow: hidden;
  margin-bottom: 20px;
  cursor: pointer;
  &:last-of-type {
    margin-bottom: 0;
  }
  &:hover {
    border-color: #3680fa;
    .answer-icon {
      color: #3680fa;
      border-color: #3680fa;
    }
  }
  .answer-icon {
    width: 50px;
    background-color: #F0F2F5;
    border-right: 1px solid #ffffff;
  }
  .answer-text {
    min-height: 50px;
    padding: 15px 0;
    margin: 0 10px;
  }
}
.active {
  border-color: #409EFF !important;
  .answer-icon {
    color: #ffffff !important;
    border-color: #409EFF !important;
    background-color: #409EFF !important;
  }
}
</style>
src/views/exam/components/answer-main/answer-single/index.vue
@@ -1,12 +1,13 @@
<template>
  <div class="answer-container w-full h-full">
    <el-scrollbar>
      <ExamInfo></ExamInfo>
      <ExamInfo class="mb-5"></ExamInfo>
      <div class="answer-content">
        <div class="answer-item flex">
          <div class="answer-icon flex justify-center items-center">A</div>
          <div class="answer-text"></div>
        <div class="answer-item flex" v-for="item, index in examInfo.answerList" @click="answerClick(item)"
          :class="answerState(item)">
          <div class="answer-icon flex flex-col justify-center items-center flex-shrink-0">{{ item.type }}</div>
          <div class="answer-text text-gray-700">{{ item.text }}</div>
        </div>
      </div>
@@ -15,18 +16,98 @@
</template>
<script setup>
import { ref } from 'vue';
import ExamInfo from '@/components/ExamInfo/index.vue';
const examInfo = ref({
  qId: 1,
  answerList: [
    {
      type: 'A',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
    {
      type: 'B',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
    {
      type: 'C',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
    {
      type: 'D',
      text: '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试试测试',
      isActive: false
    },
  ]
});
const activeIndex = ref(null);
const answerClick = (item) => {
  if(item) {
    resetAnswer();
    item.isActive = true
  }
};
const answerState = (item) => {
  return {
    active: item.isActive
  };
}
const resetAnswer = () => {
  examInfo.value.answerList.forEach(item => item.isActive = false);
}
</script>
<style lang="scss" scoped>
.answer-item {
  max-width: 400px;
  max-width: 500px;
  border-radius: 10px;
  padding: 10px 0;
  border: 1px solid #EBEEF5;
  border: 1px solid #DCDFE6;
  overflow: hidden;
  margin-bottom: 20px;
  cursor: pointer;
  &:last-of-type {
    margin-bottom: 0;
  }
  &:hover {
    border-color: #3680fa;
    .answer-icon {
      color: #3680fa;
      border-color: #3680fa;
    }
  }
  .answer-icon {
    width: 50px;
    height: 100%;
    background-color: #F0F2F5;
    border-right: 1px solid #ffffff;
  }
  .answer-text {
    min-height: 50px;
    padding: 15px 0;
    margin: 0 10px;
  }
}
.active {
  border-color: #409EFF !important;
  .answer-icon {
    color: #ffffff !important;
    border-color: #409EFF !important;
    background-color: #409EFF !important;
  }
}
</style>
src/views/exam/components/answer-time/index.vue
New file
@@ -0,0 +1,28 @@
<template>
  <div class="time-container flex justify-center text-white items-center shadow-md">
    <el-icon class="mr-1 text-xl" size="24"><Timer /></el-icon>
    <div class="label mr-1">剩余时间:</div>
    <el-countdown :value="time" />
  </div>
</template>
<script setup>
import {ref} from 'vue';
import { Timer } from '@element-plus/icons-vue';
const time = ref(1000);
</script>
<style lang="scss" scoped>
.time-container {
  width: 220px;
  border-radius: 100px;
  padding: 10px 0;
  background-color: rgba($color: #86d7f7, $alpha: 0.3);
}
:deep(.el-statistic__number) {
  color: #ffffff;
}
</style>
src/views/exam/index.vue
@@ -4,9 +4,12 @@
    <div class="exam-content">
      <div class="exam-wrapper container mx-auto h-full flex flex-col">
        <div class="exam-header flex items-center mt-12 mb-10">
          <div class="title-container text-3xl font-semibold text-white">
          <div class="title-container text-3xl font-semibold text-white mr-8">
            测试测试测试
          </div>
          <AnswerTime></AnswerTime>
        </div>
        <div class="exam-main grow flex justify-between">
@@ -44,22 +47,22 @@
              <div class="main-wrapper w-full grow relative my-5">
                <div class="main-content absolute top-0 bottom-0 w-full">
                  <AnswerSingle></AnswerSingle>
                  <Transition appear name="fade-transform" mode="out-in">
                    <component :is="typeComponent[currentType]" :key="questionIndex"></component>
                  </Transition>
                </div>
              </div>
              <div class="tool-wrapper flex justify-end">
                <div class="button-container flex items-center">
                  <div class="button-item">
                    <el-button class="tool-button">上一题</el-button>
                    <el-button class="tool-button" @click="prevQuestion">上一题</el-button>
                  </div>
                  <div class="button-item">
                    <el-button class="tool-button" type="primary">下一题</el-button>
                    <el-button class="tool-button" type="primary" @click="nextQuestion">下一题</el-button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
@@ -69,12 +72,29 @@
</template>
<script setup>
import {ref} from 'vue';
import AnswerTag from './components/answer-tag/index.vue';
import AnswerProgress from './components/answer-progress/index.vue';
import AnswerSheet from './components/answer-sheet/index.vue';
import AnswerSingle from './components/answer-main/answer-single/index.vue';
import AnswerMultiple from './components/answer-main/answer-multiple/index.vue';
import AnswerTime from './components/answer-time/index.vue';
const typeComponent = {
  1: AnswerSingle,
  2: AnswerMultiple,
}
const currentType = ref(1);
const questionIndex = ref(0);
const prevQuestion = () => {
  questionIndex.value--;
}
const nextQuestion = () => {
  questionIndex.value++;
}
</script>
<style lang="scss" scoped>