continueAdditionTask.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <template>
  2. <div class="content-container">
  3. <div class="content-outline" v-if="!testResultDivShow">
  4. <div class="left_part">
  5. <div id="left_top" class="flex-row">
  6. <el-image class="setting" :src="require('@/assets/9551.png')" fit="cover" />
  7. <div class="text"> 操作提示:</div>
  8. </div>
  9. <div class="left-desc-80" v-html="subjectInfo.testDescription"></div>
  10. </div>
  11. <div
  12. class="right_part"
  13. :style="{
  14. background:
  15. 'url(' + require('./../../assets/page' + taskId + '.png') + ')',
  16. 'background-size': '100% 100%',
  17. }"
  18. >
  19. <div id="title">
  20. <span>{{ subjectInfo.name }}</span>
  21. </div>
  22. <div
  23. style="
  24. position: absolute;
  25. bottom: 0.156rem;
  26. left: 50%;
  27. transform: translateX(-50%);
  28. "
  29. >
  30. <el-button type="primary" class="start" @click="startTest()">{{
  31. buttonName
  32. }}</el-button>
  33. </div>
  34. </div>
  35. </div>
  36. <!-- LOGO -->
  37. <!-- <h1 class="txt-center">
  38. {{ subjectInfo.name }}
  39. <h5>({{ testType }})</h5>
  40. </h1>
  41. <div
  42. v-if="!testResultDivShow"
  43. style="width: 650px; margin: 20px auto; line-height: 2"
  44. >
  45. <p style="text-align: left; text-indent: 2em">
  46. {{ subjectInfo.testDescription }}
  47. </p>
  48. </div> -->
  49. <div v-if="testResultDivShow" class="testResultDiv">
  50. <table class="test_result">
  51. <tr>
  52. <th>指标名称</th>
  53. <th>测试结果</th>
  54. </tr>
  55. <tr>
  56. <td>测试题目总数:</td>
  57. <td>{{ totalCount }}</td>
  58. </tr>
  59. <tr>
  60. <td>正确题目数:</td>
  61. <td>{{ rightCount }}</td>
  62. </tr>
  63. <tr>
  64. <td>测试成绩:</td>
  65. <td>{{ userScore }}</td>
  66. </tr>
  67. </table>
  68. </div>
  69. <div
  70. v-if="testFlag"
  71. :class="{ testMainDiv: !testState, activeTask: testState }"
  72. >
  73. <MainProgress v-if="testTypeCode === 1" :cur-percentage="(100 - countDownTime) / 100" />
  74. <div class="taskHead">
  75. <div class="scale" @click.stop="screenState">
  76. <img src="@/assets/small-big.png" alt="" />
  77. </div>
  78. </div>
  79. <!-- <h1 class="txt-center" style="color: rgb(231, 226, 226); font-size: 52px">
  80. {{ showSpanText }}
  81. </h1> -->
  82. <div v-if="answerButtonShow" style="" class="txt-center">
  83. <div align="center" style="padding-bottom: 20px; padding-top: 100px">
  84. <span class="bn-in"> {{ showSpanText }}</span>
  85. </div>
  86. <div class="add-mid">
  87. <div style="margin-top: 10px">
  88. <el-button class="oneBu bn-bottom" @click="userClick(1)">1</el-button>
  89. <el-button class="oneBu bn-bottom" @click="userClick(2)">2</el-button>
  90. <el-button class="bn-bottom" @click="userClick(3)">3</el-button>
  91. </div>
  92. <div style="margin-top: 10px">
  93. <el-button class="oneBu bn-bottom" @click="userClick(4)">4</el-button>
  94. <el-button class="oneBu bn-bottom" @click="userClick(5)">5</el-button>
  95. <el-button class="bn-bottom" @click="userClick(6)">6</el-button>
  96. </div>
  97. <div style="margin-top: 10px">
  98. <el-button class="oneBu bn-bottom" @click="userClick(7)">7</el-button>
  99. <el-button class="oneBu bn-bottom" @click="userClick(8)">8</el-button>
  100. <el-button class="bn-bottom" @click="userClick(9)">9</el-button>
  101. </div>
  102. <div style="margin-top: 10px">
  103. <el-button class="bn-bottom" @click="userClick(0)">0</el-button>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <div style="text-align: center">
  109. <!-- <el-button
  110. class="scaleButton"
  111. type="primary"
  112. v-if="buttonShow"
  113. @click="startTest()"
  114. >{{ buttonName }}</el-button
  115. > -->
  116. <el-button
  117. class="scaleButton"
  118. type="primary"
  119. v-if="saveFlag"
  120. @click="resultSave()"
  121. >结果保存</el-button
  122. >
  123. </div>
  124. <go-back />
  125. </div>
  126. </template>
  127. <script>
  128. import axios from "axios";
  129. import cognitiveAbilityTaskList from "@/assets/data/cognitiveAbilityData.js";
  130. import { oSessionStorage } from "@/utils/utils";
  131. import screenfull from "screenfull";
  132. import MainProgress from "@/components/MainProgress/index.vue";
  133. import GoBack from "@/components/goBack/index.vue";
  134. export default {
  135. components: {GoBack, MainProgress},
  136. data() {
  137. return {
  138. userId: "",
  139. testResult: {},
  140. countDownTime: 100, //倒计时时长
  141. testCount: 6,
  142. taskId: "", // 认知任务id
  143. saveFlag: false, //结果保存按钮显示标志
  144. subjectInfo: "", //认知任务详情
  145. answerButtonShow: false,
  146. buttonShow: true, // 控制按钮显示隐藏
  147. passTestExam: false, //练习测试通过标识
  148. testType: "练习测试", // 正式测试
  149. buttonName: "开始练习", // 正式测试 // 重新练习
  150. testTypeCode: 0, // 0-练习测试 1-正式测试 2-重新测试
  151. testFlag: false, //true继续测试,false结束测试
  152. countDownInterval: "", //倒计时定时器
  153. additionNumCount: 2, //当前轮需要计算的数字个数
  154. currentAnswer: 0, //当前题答案
  155. showSpanText: "", //显示题目文本
  156. totalCount: 0, //测试总次数
  157. rightCount: 0, //正确总次数
  158. rightCount2: 0, //n个数相加正确次数
  159. rightCount3: 0,
  160. rightCount4: 0,
  161. rightCount5: 0,
  162. rightCount6: 0,
  163. currentRoundRightCount: 0, //当前轮正确次数
  164. stepWidth: 1, //练习测试时步长为2,正式测试为1
  165. stepEndFlag: 6,
  166. testState: false,
  167. testResultDivShow: false, //控制测试结果显示
  168. testResultStr: "", //测试结果
  169. userScore: "", //用户总成绩
  170. rightThree: 0, //连续对3次
  171. wrongTwo: 0, //连续错两次
  172. rightCountList: [],//统计每个层级答对个数
  173. };
  174. },
  175. // 页面初始化函数
  176. created() {
  177. this.taskId = this.$route.query.taskId;
  178. this.init(this.taskId);
  179. this.divShow = false;
  180. this.testState = false;
  181. clearInterval(this.divShowInteval);
  182. clearInterval(this.countDownInterval);
  183. },
  184. destroyed() {
  185. clearInterval(this.divShowInteval);
  186. clearInterval(this.countDownInterval);
  187. },
  188. mounted: function () {
  189. var _this = this;
  190. document.onkeydown = function (e) {
  191. let key = window.event.keyCode;
  192. if (key === 122) {
  193. e.preventDefault();
  194. screenfull.toggle();
  195. }
  196. if ((57 >= key && key >= 48) || (105 >= key && key >= 96))
  197. _this.userClick(window.event.key);
  198. };
  199. },
  200. methods: {
  201. screenState() {
  202. screenfull.toggle();
  203. },
  204. init(taskId) {
  205. // this.subjectInfo = cognitiveAbilityTaskList[taskId];
  206. this.subjectInfo = JSON.parse(oSessionStorage.getItem("subjectInfo"));
  207. this.imgUrl = this.subjectInfo.imageUrl;
  208. },
  209. userClick(answer) {
  210. //用户点击动作
  211. this.totalCount++;
  212. if (answer == this.currentAnswer) {
  213. if (this.testTypeCode == 1) {
  214. //正确次数
  215. this.rightCount++;
  216. //当前数字个数计算正确数加1
  217. this.nNumRightCount();
  218. //本轮正确次数
  219. this.currentRoundRightCount++;
  220. // if (
  221. // this.additionNumCount <= 6 &&
  222. // this.currentRoundRightCount == this.additionNumCount
  223. // ) {
  224. // this.currentRoundRightCount = 0;
  225. // this.additionNumCount =
  226. // this.additionNumCount + 1 > 6 ? 6 : this.additionNumCount + 1;
  227. // }
  228. this.rightThree ++;
  229. this.wrongTwo = 0;
  230. if(this.rightThree >= 3 && this.wrongTwo == 0){
  231. this.additionNumCount ++;
  232. this.rightThree = 0;
  233. this.wrongTwo = 0;
  234. }
  235. } else {
  236. this.rightCount++;
  237. if (this.totalCount % 2 == 0) {
  238. this.additionNumCount =
  239. this.additionNumCount + 1 > 6 ? 6 : this.additionNumCount + 1;
  240. }
  241. }
  242. } else {
  243. //分练习时和正式测试时两种情况,练习测试时,不加处理
  244. //正式测试时要做降级处理
  245. if (this.testTypeCode == 1) {
  246. this.currentRoundRightCount = 0;
  247. // this.additionNumCount -= 1;
  248. // if (this.additionNumCount == 1) {
  249. // this.additionNumCount = 2;
  250. // }
  251. this.rightThree = 0;
  252. this.wrongTwo ++;
  253. if(this.additionNumCount > 2 && this.rightThree == 0 && this.wrongTwo >= 2){
  254. this.additionNumCount --;
  255. this.rightThree = 0;
  256. this.wrongTwo = 0;
  257. }
  258. } else {
  259. if (this.totalCount % 2 == 0) {
  260. this.additionNumCount =
  261. this.additionNumCount + 1 > 6 ? 6 : this.additionNumCount + 1;
  262. }
  263. }
  264. }
  265. if (this.totalCount == 6 && this.testTypeCode == 0) {
  266. this.testEnd();
  267. this.testFlag = false;
  268. this.showSpanText = "";
  269. this.answerButtonShow = false;
  270. return;
  271. }
  272. //生成下一道题
  273. if (this.testFlag) {
  274. this.createComputeSpanText();
  275. }
  276. },
  277. format(percentage) {
  278. return percentage === 100 ? "任务已完成" : "任务进度";
  279. },
  280. screen() {
  281. // 如果不允许进入全屏,发出不允许提示
  282. // if (!screenfull.isEnabled) {
  283. // this.$message("您的浏览器不能全屏");
  284. // return false;
  285. // }
  286. screenfull.request();
  287. },
  288. screenExit() {
  289. // 如果不允许进入全屏,发出不允许提示
  290. // if (!screenfull.isEnabled) {
  291. // this.$message("您的浏览器不能全屏");
  292. // return false;
  293. // }
  294. screenfull.exit();
  295. },
  296. startTest() {
  297. if (
  298. sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f") == "" ||
  299. sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f") == null
  300. ) {
  301. alert("请先登录!");
  302. return;
  303. }
  304. this.userId = sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f");
  305. //开始测试
  306. this.createComputeSpanText();
  307. // 按钮隐藏
  308. this.testFlag = true;
  309. this.buttonShow = false;
  310. this.answerButtonShow = true;
  311. this.testState = true;
  312. this.screen();
  313. //练习测试时进行倒计时,正式测试时进行测试测试校验
  314. if (this.testTypeCode == 1) {
  315. this.countDown();
  316. }
  317. },
  318. testEnd() {
  319. this.screen();
  320. //计算练习成绩
  321. if (this.testTypeCode == 0) {
  322. if (this.totalCount == this.rightCount) {
  323. //通过测试
  324. //开始正式测试
  325. this.subjectInfo.testDescription = this.subjectInfo.testExplain;
  326. this.testTypeCode = 1;
  327. this.buttonName = "正式测试";
  328. this.testType = "正式测试";
  329. this.buttonShow = true;
  330. this.answerButtonShow = true;
  331. this.testState = false;
  332. this.$message({
  333. message: "通过练习测试,开始进行正式测试!",
  334. type: "success",
  335. });
  336. //this.pageDataInit()
  337. } else {
  338. //重新测试
  339. this.testTypeCode = 0;
  340. this.buttonName = "重新测试";
  341. this.buttonShow = true;
  342. this.testState = false;
  343. this.answerButtonShow = true;
  344. this.$message({
  345. message: "测试未通过,请点击'重新测试'按钮继续练习!",
  346. type: "warning",
  347. });
  348. }
  349. this.screenExit();
  350. this.pageDataInit();
  351. } else {
  352. this.screenExit();
  353. this.testState = false;
  354. this.getUserTestScore();
  355. this.$message({
  356. message: "测试结束!",
  357. type: "success",
  358. });
  359. this.buttonShow = false;
  360. this.answerButtonShow = false;
  361. this.showSpanText = "";
  362. //测试结束隐藏测试页面-liwenlong20220720
  363. this.testFlag = false;
  364. }
  365. },
  366. countDown() {
  367. // 测试时间倒计时
  368. let myInterval = setInterval(() => {
  369. this.countDownTime--;
  370. if (this.countDownTime == 0) {
  371. //计算测试结果
  372. this.testEnd();
  373. // 清除定时器
  374. clearInterval(myInterval);
  375. this.countDownTime = 0;
  376. }
  377. }, 1000);
  378. },
  379. createComputeSpanText() {
  380. //生成下一道题和答案
  381. this.testCount--;
  382. var tempSpanText = "";
  383. var additionResult = 0;
  384. for (var i = this.additionNumCount; i > 0; i--) {
  385. var tempNum = Math.floor(Math.random() * 10);
  386. additionResult += tempNum;
  387. tempSpanText += tempNum + "+";
  388. }
  389. this.showSpanText = tempSpanText.substr(0, tempSpanText.length - 1);
  390. this.currentAnswer = additionResult % 10;
  391. },
  392. nNumRightCount() {
  393. // switch (this.additionNumCount) {
  394. // case 2:
  395. // this.rightCount2++;
  396. // break;
  397. // case 3:
  398. // this.rightCount3++;
  399. // break;
  400. // case 4:
  401. // this.rightCount4++;
  402. // break;
  403. // case 5:
  404. // this.rightCount5++;
  405. // break;
  406. // case 6:
  407. // this.rightCount6++;
  408. // break;
  409. // default:
  410. // break;
  411. // }
  412. let isIndex = this.rightCountList.findIndex(item => item.key == this.additionNumCount);
  413. if(isIndex !== -1){
  414. this.rightCountList[isIndex].value ++;
  415. }else {
  416. this.rightCountList.push({
  417. key: this.additionNumCount,
  418. value: 1
  419. })
  420. }
  421. },
  422. pageDataInit() {
  423. this.rightCount2 = 0;
  424. this.rightCount3 = 0;
  425. this.rightCount4 = 0;
  426. this.rightCount5 = 0;
  427. this.rightCount6 = 0;
  428. this.totalCount = 0;
  429. this.rightCount = 0;
  430. this.additionNumCount = 2;
  431. this.currentAnswer = 0;
  432. this.currentRoundRightCount = 0;
  433. },
  434. getUserTestScore() {
  435. console.log(this.rightCountList,"测试记录列表")
  436. this.testResult.userId = this.userId;
  437. this.testResult.total = this.totalCount;
  438. this.testResult.testPlanId = this.$route.query.testPlanId || "";
  439. // let data = [];
  440. // data.push({ key: 2, value: this.rightCount2 });
  441. // data.push({ key: 3, value: this.rightCount3 });
  442. // data.push({ key: 4, value: this.rightCount4 });
  443. // data.push({ key: 5, value: this.rightCount5 });
  444. // data.push({ key: 6, value: this.rightCount6 });
  445. // this.testResult.data = data;
  446. // this.userScore = parseFloat(
  447. // Math.log2(
  448. // this.rightCount2 * Math.pow(2, 0) +
  449. // this.rightCount3 * Math.pow(2, 1) +
  450. // this.rightCount4 * Math.pow(2, 2) +
  451. // this.rightCount5 * Math.pow(2, 3) +
  452. // this.rightCount6 * Math.pow(2, 4)
  453. // )
  454. // ).toFixed(2);
  455. // this.testResult.score = this.userScore;
  456. this.testResult.data = this.rightCountList;
  457. let sum = 0;
  458. this.rightCountList.map((item) => {
  459. sum += item.value * Math.pow(2, item.key - 2)
  460. });
  461. this.testResult.score = sum == 0 ? 0 : parseFloat(Math.log2(sum)).toFixed(2);
  462. this.userTestResultSave();
  463. },
  464. userTestResultSave() {
  465. let that = this;
  466. // this.testResultDivShow = true;
  467. //跳转页面到结果页面
  468. this.$http.post(`/cognize/ADDITION`, this.testResult, (res) => {
  469. // that.$router.push({
  470. // name: "TestResult",
  471. // params: {
  472. // result: [
  473. // {
  474. // name: "测试题目总数",
  475. // value: that.totalCount,
  476. // },
  477. // {
  478. // name: "正确题目数",
  479. // value: that.rightCount,
  480. // },
  481. // {
  482. // name: "测试成绩",
  483. // value: this.testResult.score,
  484. // },
  485. // ],
  486. // },
  487. // });
  488. // that.testState = false;
  489. // that.testFlag = false;
  490. this.goTestResult(res.data);
  491. });
  492. }
  493. },
  494. };
  495. </script>
  496. <style scoped>
  497. .testResultDiv {
  498. margin: 0 auto;
  499. /* margin-top: 10%; */
  500. margin-left: 33%;
  501. /* background: gray; */
  502. background-size: cover;
  503. /* text-align:center; */
  504. width: 500px;
  505. height: 100px;
  506. }
  507. .testMainDiv {
  508. margin: 0 auto;
  509. margin-top: 10px;
  510. background: gray;
  511. background-size: cover;
  512. /* text-align:center; */
  513. width: 500px;
  514. height: 300px;
  515. /* object-fit:fill; */
  516. }
  517. .activeTask {
  518. background: url(../../assets/congnitiveAblitity/add-bg.png) no-repeat center;
  519. background-size: cover;
  520. /* background: gray; */
  521. position: fixed;
  522. top: 0;
  523. left: 0;
  524. right: 0;
  525. bottom: 0;
  526. }
  527. .el-progress__text {
  528. color: black;
  529. }
  530. .scaleName {
  531. margin-top: 70px;
  532. background-size: cover;
  533. }
  534. .scaleButton {
  535. margin-top: 20px;
  536. margin-bottom: 20px;
  537. background-size: cover;
  538. }
  539. .add-mid {
  540. background: url('~@/assets/congnitiveAblitity/add-mid.png') no-repeat 0 0 / 100% 100%;
  541. height: 470px;
  542. width: 425px;
  543. margin: 20px auto 0;
  544. }
  545. h1 {
  546. font-size: 2em;
  547. margin: 0em 0 !important;
  548. }
  549. .oneBu {
  550. margin-right: 55px;
  551. }
  552. .bn-bottom {
  553. margin-top: 20px;
  554. width: 84px;
  555. height: 84px;
  556. background: rgb(87, 172, 187);
  557. box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.48);
  558. border-radius: 50%;
  559. opacity: 1;
  560. color: white;
  561. font-size: 28px;
  562. }
  563. .bn-in {
  564. border-radius: 14px;
  565. display: block;
  566. width: 500px;
  567. height: 54px;
  568. color: white;
  569. background-color: black;
  570. font-size: 32px;
  571. padding-top: 10px;
  572. }
  573. .aa {
  574. visibility: hidden;
  575. }
  576. </style>