|
@@ -7,28 +7,233 @@
|
|
|
*/
|
|
|
// import { shuffle } from 'lodash-es'
|
|
|
|
|
|
-const subjectInfo = ref({
|
|
|
- name: '广度训练',
|
|
|
+import { shuffle } from 'lodash-es'
|
|
|
+import CountUp from 'vue-countup-v3'
|
|
|
+import BTRandomPentagram from './BTRandomPentagram.vue'
|
|
|
+
|
|
|
+interface IMainData {
|
|
|
+ totalScore: number
|
|
|
+ dataList: any[]
|
|
|
+}
|
|
|
+
|
|
|
+let selectArray: any[] = reactive([])
|
|
|
+const BTRandomPentagramRef = ref()
|
|
|
+const tempBeginScore = ref(0)
|
|
|
+const tempEndScore = ref(0)
|
|
|
+const changeShow = ref(false)
|
|
|
+const choiceAreaShow = ref(true)
|
|
|
+const currentIndex = ref(0) // 当前序列
|
|
|
+const mainData: IMainData = reactive({
|
|
|
+ totalScore: 0,
|
|
|
+ dataList: [],
|
|
|
})
|
|
|
+
|
|
|
+// 当前进度
|
|
|
+// const percentage = computed(() => {
|
|
|
+// return Math.round((currentIndex.value / mainData.dataList.length) * 100)
|
|
|
+// })
|
|
|
+const selectiveIndex = ref(-1) // 选择的索引
|
|
|
+
|
|
|
+/**
|
|
|
+ * 生成基础数据
|
|
|
+ */
|
|
|
+function generateBaseData() {
|
|
|
+ // 生成选项组
|
|
|
+ const selectDataList: number[][] = [
|
|
|
+ // [3, 4, 5, 6, 7], [3, 4, 5, 6, 7], ...,
|
|
|
+ // [4, 5, 6, 7, 8], [4, 5, 6, 7, 8], ...,
|
|
|
+ ...Array.from({ length: 10 }).fill([3, 4, 5, 6, 7]),
|
|
|
+ ...Array.from({ length: 10 }).fill([4, 5, 6, 7, 8]),
|
|
|
+ ...Array.from({ length: 10 }).fill([5, 6, 7, 8, 9]),
|
|
|
+ ...Array.from({ length: 10 }).fill([6, 7, 8, 9, 10]),
|
|
|
+ ...Array.from({ length: 10 }).fill([7, 8, 9, 10, 11]),
|
|
|
+ ...Array.from({ length: 10 }).fill([8, 9, 10, 11, 12]),
|
|
|
+ ...Array.from({ length: 10 }).fill([9, 10, 11, 12, 13]),
|
|
|
+ ...Array.from({ length: 10 }).fill([10, 11, 12, 13, 14]),
|
|
|
+ ]
|
|
|
+ selectArray = selectDataList.map((item) => {
|
|
|
+ return shuffle(item)
|
|
|
+ })
|
|
|
+
|
|
|
+ // 生成主体数据
|
|
|
+ const baseDataList = [
|
|
|
+ // { count: 5, score: 10, extraScore: 0 }, { count: 5, score: 10, extraScore: 0 }, ...
|
|
|
+ // { count: 5, score: 10, extraScore: 0 }, { count: 5, score: 10, extraScore: 0 }, ...
|
|
|
+ ...Array.from({ length: 10 }).fill({ count: 5, score: 10, extraScore: 0 }),
|
|
|
+ ...Array.from({ length: 10 }).fill({ count: 6, score: 20, extraScore: 0 }),
|
|
|
+ ...Array.from({ length: 10 }).fill({ count: 7, score: 30, extraScore: 0 }),
|
|
|
+ ...Array.from({ length: 10 }).fill({ count: 8, score: 40, extraScore: 0 }),
|
|
|
+ ...Array.from({ length: 10 }).fill({ count: 9, score: 50, extraScore: 0 }),
|
|
|
+ ...Array.from({ length: 10 }).fill({ count: 10, score: 60, extraScore: 0 }),
|
|
|
+ ...Array.from({ length: 10 }).fill({ count: 11, score: 70, extraScore: 0 }),
|
|
|
+ ...Array.from({ length: 10 }).fill({ count: 12, score: 80, extraScore: 0 }),
|
|
|
+ ]
|
|
|
+
|
|
|
+ mainData.dataList = baseDataList.map((item, index) => {
|
|
|
+ return {
|
|
|
+ index,
|
|
|
+ ...item,
|
|
|
+ ...{ reactionTime: 0, beginTime: 0, endTime: 0, choice: '' },
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ mainData.dataList = shuffle(mainData.dataList)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 下一步
|
|
|
+ */
|
|
|
+function nextClick() {
|
|
|
+ tempBeginScore.value = mainData.totalScore
|
|
|
+ if (currentIndex.value < mainData.dataList.length - 1) {
|
|
|
+ selectiveIndex.value = -1
|
|
|
+ currentIndex.value++
|
|
|
+ changeShow.value = false
|
|
|
+ setTimeout(() => {
|
|
|
+ mainData.dataList[currentIndex.value].beginTime = Date.now()
|
|
|
+ BTRandomPentagramRef.value.reGeneratePentagramList()
|
|
|
+ choiceAreaShow.value = true
|
|
|
+ }, 320)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // console.log('游戏结束')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 选择点击事件
|
|
|
+ * 1、将选择的数量choice 赋值给当前序列的choice
|
|
|
+ * 2、计算当前序列的得分
|
|
|
+ * 3、计算当前序列反应时间,判断反应时间是否超过2000ms,超过则加30分
|
|
|
+ * 4、隐式计算CountUp的变化数值:tempBeginScore,tempEndScore
|
|
|
+ * 5、判断是否超过80,超过则结束
|
|
|
+ * @param choice
|
|
|
+ * @param index
|
|
|
+ */
|
|
|
+function choiceClick(choice: number, index: number) {
|
|
|
+ setTimeout(() => {
|
|
|
+ choiceAreaShow.value = false
|
|
|
+ }, 400)
|
|
|
+ if (mainData.dataList[currentIndex.value].choice === '') {
|
|
|
+ selectiveIndex.value = index
|
|
|
+ mainData.dataList[currentIndex.value].endTime = Date.now()
|
|
|
+ mainData.dataList[currentIndex.value].reactionTime = Date.now() - mainData.dataList[currentIndex.value].beginTime
|
|
|
+ mainData.dataList[currentIndex.value].choice = choice
|
|
|
+ if (mainData.dataList[currentIndex.value].count === choice) {
|
|
|
+ tempEndScore.value += mainData.dataList[currentIndex.value].score
|
|
|
+ if (mainData.dataList[currentIndex.value].reactionTime <= 2000) {
|
|
|
+ mainData.dataList[currentIndex.value].extraScore = 30
|
|
|
+ setTimeout(() => {
|
|
|
+ tempBeginScore.value = tempEndScore.value
|
|
|
+ tempEndScore.value += 30
|
|
|
+ }, 1200)
|
|
|
+ }
|
|
|
+ mainData.totalScore
|
|
|
+ += mainData.dataList[currentIndex.value].extraScore + mainData.dataList[currentIndex.value].score
|
|
|
+ }
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ nextClick()
|
|
|
+ }, 2300)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 重新开始
|
|
|
+ */
|
|
|
+function reOverFn() {
|
|
|
+ setTimeout(() => {
|
|
|
+ changeShow.value = true
|
|
|
+ }, 320)
|
|
|
+ setTimeout(() => {
|
|
|
+ changeShow.value = false
|
|
|
+ }, 2000)
|
|
|
+}
|
|
|
+
|
|
|
const showCountDown = ref(false) // 显示倒计时
|
|
|
|
|
|
function exec() {
|
|
|
showCountDown.value = false
|
|
|
+ changeShow.value = true
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
showCountDown.value = true
|
|
|
+ generateBaseData()
|
|
|
+ mainData.dataList[currentIndex.value].beginTime = Date.now()
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<section class="app-container">
|
|
|
- <van-nav-bar :title="subjectInfo.name" />
|
|
|
+ <!-- <van-nav-bar :title="subjectInfo.name" /> -->
|
|
|
<count-down v-if="showCountDown" :time="5" @end-count-down="exec" />
|
|
|
+
|
|
|
+ <div v-else class="breadth-training-container h-full w-full flex flex-col items-center gap-y-[15px]">
|
|
|
+ <!-- <el-progress -->
|
|
|
+ <!-- :show-text="false" -->
|
|
|
+ <!-- :stroke-width="4" -->
|
|
|
+ <!-- :percentage="percentage" -->
|
|
|
+ <!-- color="#FFC400" -->
|
|
|
+ <!-- stroke-linecap="square" -->
|
|
|
+ <!-- class="w-full" -->
|
|
|
+ <!-- /> -->
|
|
|
+
|
|
|
+ <BTRandomPentagram
|
|
|
+ ref="BTRandomPentagramRef"
|
|
|
+ :count="mainData.dataList[currentIndex]?.count"
|
|
|
+ :min-distance="20"
|
|
|
+ :change-show="changeShow"
|
|
|
+ class="mt-[40px]"
|
|
|
+ @re-over="reOverFn"
|
|
|
+ />
|
|
|
+ <div class="flex flex-row items-center text-[16px] text-white">
|
|
|
+ <span>累计得分:</span>
|
|
|
+ <CountUp :start-val="tempBeginScore" :end-val="tempEndScore" :duration="1.8" />
|
|
|
+ </div>
|
|
|
+ <div v-if="choiceAreaShow" class="flex flex-row gap-x-[20px] flex-justify-between">
|
|
|
+ <div
|
|
|
+ v-for="(item, index) in selectArray[mainData.dataList[currentIndex]?.index]"
|
|
|
+ :key="`${currentIndex}${index}`"
|
|
|
+ class="pos-relative min-w-[50px] cursor-pointer rounded-[8px] bg-[#ffffff] p-y-3 text-center text-[24px]"
|
|
|
+ @click="choiceClick(item, index)"
|
|
|
+ >
|
|
|
+ {{ item }}
|
|
|
+ <transition name="el-fade-in">
|
|
|
+ <img
|
|
|
+ v-if="selectiveIndex === index && item === mainData.dataList[currentIndex].count"
|
|
|
+ src="@/assets/images/task/breadthTraining/correct.png"
|
|
|
+ alt="correct"
|
|
|
+ width="20"
|
|
|
+ height="17"
|
|
|
+ class="pos-absolute bottom-[4px] right-[4px]"
|
|
|
+ >
|
|
|
+ </transition>
|
|
|
+ <transition name="el-fade-in">
|
|
|
+ <img
|
|
|
+ v-if="selectiveIndex === index && item !== mainData.dataList[currentIndex].count"
|
|
|
+ src="@/assets/images/task/breadthTraining/wrong.png"
|
|
|
+ alt="wrong"
|
|
|
+ width="20"
|
|
|
+ height="20"
|
|
|
+ class="pos-absolute bottom-[4px] right-[4px]"
|
|
|
+ >
|
|
|
+ </transition>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</section>
|
|
|
</template>
|
|
|
|
|
|
<style scoped lang="less">
|
|
|
-.app-container {
|
|
|
+.breadth-training-container {
|
|
|
+ background-color: #0a0c23;
|
|
|
+ //background-image: url('/bg-breadthTraining.png');
|
|
|
+ background-size: 100% 100%;
|
|
|
+ background-position: center center;
|
|
|
+
|
|
|
+ :deep(.el-progress-bar__outer) {
|
|
|
+ background-color: rgba(0, 0, 0, 0.1);
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|