|
@@ -6,8 +6,8 @@
|
|
|
* 编写者: JutarryWu
|
|
|
*/
|
|
|
import { shuffle } from 'lodash-es'
|
|
|
-import { Decimal } from 'decimal.js'
|
|
|
-import { generateRandomNumbers } from '@/utils'
|
|
|
+import { showSuccessToast } from 'vant'
|
|
|
+import { formatSeconds, generateRandomNumbers } from '@/utils'
|
|
|
import Url_forest from '@/assets/images/task/spatialOrientationAbility/forest.png'
|
|
|
import Url_hospital from '@/assets/images/task/spatialOrientationAbility/hospital.png'
|
|
|
import Url_lakes from '@/assets/images/task/spatialOrientationAbility/lakes.png'
|
|
@@ -18,6 +18,7 @@ import Url_car from '@/assets/images/task/spatialOrientationAbility/car.png'
|
|
|
import Url_trafficLight from '@/assets/images/task/spatialOrientationAbility/trafficLight.png'
|
|
|
import Url_stop from '@/assets/images/task/spatialOrientationAbility/stop.png'
|
|
|
import Url_house from '@/assets/images/task/spatialOrientationAbility/house.png'
|
|
|
+import GameAPI, { type GameResultVO, type GameVO, type ResultLevel } from '@/api/game'
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
@@ -36,21 +37,19 @@ interface IData {
|
|
|
angle?: string
|
|
|
}
|
|
|
|
|
|
-const subjectInfo = ref({
|
|
|
- name: '空间定向训练',
|
|
|
-})
|
|
|
-
|
|
|
+const subjectInfo = ref<GameVO>({})
|
|
|
const showCountDown = ref(false) // 显示倒计时
|
|
|
const showCountDownBottom = ref(false) // 显示底部倒计时
|
|
|
const showSubmit = ref(false) // 显示画布
|
|
|
const isSubmit = ref(false) // 是否提交进程中
|
|
|
|
|
|
-const levelNum = [3, 5, 7] // 正式测试:3个难度等级需要呈现的刺激目标数
|
|
|
-const tryCount = 3 // 正式测试:每个难度等级需要进行的试次数
|
|
|
+const levelNum = [3, 4, 5] // 正式测试:3个难度等级需要呈现的刺激目标数
|
|
|
+const tryCount = 1 // 正式测试:每个难度等级需要进行的试次数
|
|
|
const currentIndex = ref(0) // 当前试次索引值:练习模式2次最大为1, 正式测试45次
|
|
|
const itemAngle = ref(0) // 选项物品实际角度
|
|
|
const roundSliderVal = ref(0) // 圆形滑杆产生的值(即:用户操作实际角度)
|
|
|
const offsetAngle = ref(0) // 角度偏差值(用户绘制时产生的实际偏差值)
|
|
|
+let gameStartTime = null // 游戏开始时间
|
|
|
|
|
|
const showDataArr = ref<IData[][]>([]) // 伪随机数组
|
|
|
let arrDataDemo: IData[] = [
|
|
@@ -80,7 +79,7 @@ const secondObj = ref<IData>()
|
|
|
const topCoordinate = ref<IData>()
|
|
|
const thirdObj = ref<IData>()
|
|
|
const thirdCoordinate = ref<IData>()
|
|
|
-const resultDataArr = ref([]) // 存放结果数组
|
|
|
+const levelList = ref<ResultLevel[]>([]) // 存放结果数组
|
|
|
|
|
|
/**
|
|
|
* 生成不重叠随机点
|
|
@@ -207,18 +206,44 @@ submitAngle() {
|
|
|
// console.log('用户操作逻辑角度值: ', roundSliderVal)
|
|
|
// console.log('角度偏差值: ', offsetAngle)
|
|
|
// console.log('---------------------------------------------------------------')
|
|
|
- resultDataArr.value.push({
|
|
|
- // level: showDataArr.value[currentIndex.value][0].level,
|
|
|
+ levelList.value.push({
|
|
|
+ level: showDataArr.value[currentIndex.value][0].level,
|
|
|
+ levelParamList: [
|
|
|
+ {
|
|
|
+ code: 'itemAngle',
|
|
|
+ name: '物品实际角度值',
|
|
|
+ value: itemAngle.value.toFixed(2),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'rotationAngle',
|
|
|
+ name: '用户操作逻辑角度值',
|
|
|
+ value: Math.abs(roundSliderVal.value).toFixed(2),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'offsetAngle',
|
|
|
+ name: '角度偏差值',
|
|
|
+ value: offsetAngle.value,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'CenterName',
|
|
|
+ name: '中心点物体',
|
|
|
+ value: centerCoordinate.value.name,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'BaseName',
|
|
|
+ name: '顶点物体',
|
|
|
+ value: topCoordinate.value.name,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ code: 'TargetName',
|
|
|
+ name: '目标物体',
|
|
|
+ value: thirdCoordinate.value.name,
|
|
|
+ },
|
|
|
+ ],
|
|
|
// onceStartTime: dayjs(new Date(showDataArr.value[currentIndex.value].onceStartTime)).format('YY-mm-dd HH:MM:SS'),
|
|
|
// onceEndTime: dayjs(new Date(showDataArr.value[currentIndex.value].onceEndTime)).format('YY-mm-dd HH:MM:SS'),
|
|
|
// reactionTime: (showDataArr.value[currentIndex.value].onceEndTime - showDataArr.value[currentIndex.value].onceStartTime).toFixed(2),
|
|
|
- itemAngle: itemAngle.value.toFixed(2), // 物品实际角度值
|
|
|
- rotationAngle: Math.abs(roundSliderVal.value).toFixed(2), // 用户操作逻辑角度值
|
|
|
- offsetAngle: offsetAngle.value, // 角度偏差值
|
|
|
- CenterName: centerCoordinate.value.name, // 中心点物体
|
|
|
- BeseName: topCoordinate.value.name, // 顶点物体
|
|
|
- TargetName: thirdCoordinate.value.name, // 目标物体
|
|
|
- randomArr: dealArrDataPoint(showDataArr.value[currentIndex.value], centerCoordinate.value), // 物品随机坐标位置
|
|
|
+ // randomArr: dealArrDataPoint(showDataArr.value[currentIndex.value], centerCoordinate.value), // 物品随机坐标位置
|
|
|
})
|
|
|
currentIndex.value++
|
|
|
// curPercentage.value = Number(roundToFixed((currentIndex.value / showDataArr.value.length), 2))
|
|
@@ -226,32 +251,28 @@ submitAngle() {
|
|
|
resetGame()
|
|
|
}
|
|
|
else {
|
|
|
- // taskEndTime.value = Date.now()
|
|
|
- // console.log(`本次 空间定向任务共计耗时:${taskEndTime.value - taskStartTime.value}ms`, resultDataArr.value)
|
|
|
- // $http.post(
|
|
|
- // `/cognize/SpatialOrientation`,
|
|
|
- // {
|
|
|
- // userId: userId,
|
|
|
- // userResponseRecords: resultDataArr,
|
|
|
- // testPlanId: $route.query.testPlanId || '',
|
|
|
- // taskStartTime: dateFormat('YY-mm-dd HH:MM:SS', new Date(taskStartTime)),
|
|
|
- // taskEndTime: dateFormat('YY-mm-dd HH:MM:SS', new Date(taskEndTime)),
|
|
|
- // },
|
|
|
- // (res) => {
|
|
|
- // console.log('res: ', res)
|
|
|
- // if (res && res.code === '200') {
|
|
|
- // // 跳转新测试结果页面
|
|
|
- // goTestResult(res.data)
|
|
|
- // }
|
|
|
- // else {
|
|
|
- // $toast.fail(res?.msg)
|
|
|
- // }
|
|
|
- //
|
|
|
- // setTimeout(() => {
|
|
|
- // isSubmit = false
|
|
|
- // }, 500)
|
|
|
- // },
|
|
|
- // )
|
|
|
+ const gameTime = formatSeconds(Math.ceil(performance.now() - gameStartTime))
|
|
|
+
|
|
|
+ const data: GameResultVO = {
|
|
|
+ finish: '1',
|
|
|
+ gameId: subjectInfo.value.id,
|
|
|
+ gameName: subjectInfo.value.name,
|
|
|
+ paramList: [
|
|
|
+ {
|
|
|
+ code: 'gameTime',
|
|
|
+ name: '游戏时长',
|
|
|
+ value: gameTime,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ levelList: levelList.value,
|
|
|
+ userId: sessionStorage.getItem('userId'),
|
|
|
+ }
|
|
|
+ GameAPI.add(data).then(() => {
|
|
|
+ showSuccessToast('本次训练已结束')
|
|
|
+ setTimeout(() => {
|
|
|
+ router.go(-1)
|
|
|
+ }, 1300)
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -260,17 +281,17 @@ submitAngle() {
|
|
|
* @param arrData
|
|
|
* @param centerPoint
|
|
|
*/
|
|
|
-function dealArrDataPoint(arrData: IData[], centerPoint: IData) {
|
|
|
- const xAxisOffset = new Decimal(centerPoint.xAxis)
|
|
|
- const yAxisOffset = new Decimal(centerPoint.yAxis)
|
|
|
- return arrData.map((item) => {
|
|
|
- const xAxis = new Decimal(item.xAxis)
|
|
|
- const yAxis = new Decimal(item.yAxis)
|
|
|
- item.xAxis = xAxis.minus(xAxisOffset).toNumber()
|
|
|
- item.yAxis = yAxis.minus(yAxisOffset).toNumber()
|
|
|
- return item
|
|
|
- })
|
|
|
-}
|
|
|
+// function dealArrDataPoint(arrData: IData[], centerPoint: IData) {
|
|
|
+// const xAxisOffset = new Decimal(centerPoint.xAxis)
|
|
|
+// const yAxisOffset = new Decimal(centerPoint.yAxis)
|
|
|
+// return arrData.map((item) => {
|
|
|
+// const xAxis = new Decimal(item.xAxis)
|
|
|
+// const yAxis = new Decimal(item.yAxis)
|
|
|
+// item.xAxis = xAxis.minus(xAxisOffset).toNumber()
|
|
|
+// item.yAxis = yAxis.minus(yAxisOffset).toNumber()
|
|
|
+// return item
|
|
|
+// })
|
|
|
+// }
|
|
|
|
|
|
function resetGame() {
|
|
|
showCountDown.value = false
|
|
@@ -291,9 +312,14 @@ function resetGame() {
|
|
|
function exec() {
|
|
|
showCountDown.value = false
|
|
|
showCountDownBottom.value = true
|
|
|
+ gameStartTime = performance.now()
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
+ const temp = sessionStorage.getItem('subjectInfo')
|
|
|
+ if (temp) {
|
|
|
+ subjectInfo.value = JSON.parse(temp)
|
|
|
+ }
|
|
|
showCountDown.value = true
|
|
|
initImgDataList()
|
|
|
})
|