Browse Source

Merge remote-tracking branch 'origin/dev-20240819' into dev-20240819

JutarryWu 6 months ago
parent
commit
2b9d28e935

+ 65 - 4
src/pages/cognitiveTasks/BreadthTraining/index.vue

@@ -9,7 +9,9 @@
 
 import { shuffle } from 'lodash-es'
 import CountUp from 'vue-countup-v3'
+import { showSuccessToast } from 'vant'
 import BTRandomPentagram from './BTRandomPentagram.vue'
+import GameAPI, { type GameResultVO, type GameVO } from '@/api/game'
 
 const router = useRouter()
 interface IMainData {
@@ -23,7 +25,7 @@ interface IMainChildData {
   extraScore?: number
 }
 
-const subjectInfo = ref({
+const subjectInfo = ref<GameVO>({
   name: '广度训练',
 })
 
@@ -44,7 +46,15 @@ const mainData: IMainData = reactive({
 //   return Math.round((currentIndex.value / mainData.dataList.length) * 100)
 // })
 const selectiveIndex = ref(-1) // 选择的索引
-
+// 游戏收集的数据
+const gameData: GameResultVO = {
+  finish: '1',
+  gameId: subjectInfo.value.id,
+  gameName: subjectInfo.value.name,
+  userId: sessionStorage.getItem('userId'),
+  paramList: [],
+  levelList: [],
+}
 /**
  * 生成基础数据
  */
@@ -60,8 +70,8 @@ function generateBaseData() {
     ...Array.from({ length: 10 }).fill([9, 10, 11, 12, 13]),
     ...Array.from({ length: 10 }).fill([10, 11, 12, 13, 14]),
   ]
-  selectArray = selectDataList.map((item: number[]) => {
-    return shuffle(item)
+  selectArray = selectDataList.map((item) => {
+    return shuffle(item as number[])
   })
 
   // 生成主体数据
@@ -106,6 +116,7 @@ function nextClick() {
   }
   else {
     // console.log('游戏结束')
+    sendData()
   }
 }
 
@@ -166,7 +177,57 @@ function exec() {
   changeShow.value = true
 }
 
+function sendData() {
+  const { totalReactionTime, gameTime } = mainData.dataList.reduce(
+    (obj, it) => {
+      obj.gameTime = obj.gameTime + (it.endTime - it.beginTime)
+      obj.totalReactionTime += it.reactionTime
+      return obj
+    },
+    { gameTime: 0, totalReactionTime: 0 },
+  )
+
+  gameData.paramList = [
+    {
+      code: 'score',
+      name: '得分',
+      value: mainData.totalScore,
+    },
+    {
+      code: 'gameTime',
+      name: '游戏用时',
+      value: `${(gameTime / 1000).toFixed(2)}s`,
+    },
+    {
+      code: 'avrTime',
+      name: '平均反应时长',
+      value: `${Math.ceil(totalReactionTime / mainData.dataList.length)}ms`,
+    },
+    {
+      code: 'attentionBreadthPath',
+      name: '注意广度曲线图',
+      value: JSON.stringify(mainData.dataList),
+    },
+    {
+      code: 'attentionBreadth',
+      name: '注意广度',
+      value: JSON.stringify(mainData.dataList),
+    },
+  ]
+
+  GameAPI.add(gameData).then(() => {
+    showSuccessToast('本次训练已结束')
+    setTimeout(() => {
+      router.go(-1)
+    }, 1300)
+  })
+}
+
 onMounted(() => {
+  const temp = sessionStorage.getItem('subjectInfo')
+  if (temp) {
+    subjectInfo.value = JSON.parse(temp)
+  }
   showCountDown.value = true
   generateBaseData()
   mainData.dataList[currentIndex.value].beginTime = Date.now()

+ 2 - 2
src/pages/cognitiveTasks/ContinueAddition/index.vue

@@ -27,7 +27,7 @@ const additionNumCount = ref(2)
 // 统计每个层级答对个数
 const rightCountList: Result[] = reactive([])
 // 测试时长 100 秒
-const gameDuration = ref(10 * 1000)
+const gameDuration = ref(100 * 1000)
 // 游戏结束时间戳
 const gameEndTime = ref(0)
 // 游戏开始时间戳
@@ -138,7 +138,7 @@ function sendData() {
   gameData.levelList = rightCountList.map((item) => {
     return {
       level: item.name,
-      levelParamList: [{ item }] as Result,
+      levelParamList: [{ ...item }],
     } as ResultLevel
   })