shapeIntuition_random.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <template>
  2. <div class="content-container shape-intuition-random-container">
  3. <div class="content-outline" v-if="!testResultStr">
  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
  31. class="start"
  32. type="primary"
  33. v-if="button0Show"
  34. @click="startTest(0)"
  35. >
  36. 练习测试
  37. </el-button>
  38. <el-button
  39. class="start"
  40. type="primary"
  41. v-if="button1Show"
  42. @click="startTest(1)"
  43. >
  44. 正式测试
  45. </el-button>
  46. </div>
  47. </div>
  48. </div>
  49. <!-- LOGO -->
  50. <div v-show="testResultStrShow" style="width: 650px; margin: 20px auto; line-height: 2">
  51. <p style="margin-top: 20%; font-size: 30px">
  52. {{ testResultStr }}
  53. </p>
  54. </div>
  55. <div
  56. v-if="testFlag"
  57. :class="{ testMainDiv: !testState, activeTask: testState }"
  58. @contextmenu.prevent=""
  59. @click.left="userClick('L')"
  60. @click.right="userClick('R')"
  61. >
  62. <div class="taskHead">
  63. <div class="scale" @click.stop="screen">
  64. <img src="../../assets/small-big.png" alt="" />
  65. </div>
  66. <el-progress
  67. class="main_progress"
  68. :stroke-width="24"
  69. :text-inside="true"
  70. :format="format"
  71. :percentage="(imgIndex * 100) / 120"
  72. v-if="testTypeCode == 1"
  73. style="width:50%"
  74. ></el-progress>
  75. </div>
  76. <div class="glass">
  77. <p v-show="countDownShow" class="countdownStr">
  78. {{ countDownStr }}
  79. </p>
  80. <img v-show="showDuckEgg" :src="examImgUrl" alt="" class="shapeImg" />
  81. </div>
  82. <!-- <img v-show="showWhiteFlag" src='../../assets/congnitiveAblitity/whiteFlag.png' alt="" style="width: 50px; height: 50px; margin-top: 20%"> -->
  83. <!-- 演示使用 -->
  84. <!-- <div class="steering">
  85. <el-button type="primary" icon="el-icon-arrow-left" @click="userClick('L')"></el-button>
  86. <el-button type="primary" @click="userClick('R')"><i class="el-icon-arrow-right el-icon--right"></i></el-button>
  87. </div> -->
  88. </div>
  89. <go-back />
  90. </div>
  91. </template>
  92. <script>
  93. import { oSessionStorage } from "@/utils/utils";
  94. import { preloader } from "@/utils/utils";
  95. import screenfull from "screenfull";
  96. import GoBack from "@/components/goBack/index.vue";
  97. export default {
  98. components: {GoBack},
  99. data() {
  100. return {
  101. userId: "",
  102. userTestResult: {},
  103. imgUrl: "",
  104. examImgUrl: "",
  105. taskId: "", // 认知任务id
  106. testFlag: false,
  107. testState: false,
  108. saveFlag: false, //结果保存按钮显示标志
  109. subjectInfo: "", //认知任务详情
  110. button0Show: true, // 控制按钮显示隐藏
  111. button1Show: false, // 控制按钮显示隐藏
  112. buttonName: "开始测试", // 正式测试 // 重新练习
  113. testTypeCode: 0, // 0-练习测试 1-正式测试 2-重新测试
  114. imgIndex: 0,
  115. userTestPicList: [], //用户点击图片列表
  116. showImage: true,
  117. difficultList: [0], // [0,10,30,45,60,90,120,180,360]
  118. testPicCount: 10, //测试数目
  119. userRightClickDirection: "", //测试者应该点击的方向
  120. userRightResponseCount: 0, //测试者反应正确的次数
  121. showDuckEgg: false,
  122. countDownTime: 6, //开始前的倒计时
  123. countDownStr: "练习马上开始!",
  124. countDownShow: true,
  125. testTunrnCount: 0, //正式测试轮数
  126. testEndFlag: false, //测试结束标志
  127. testResultStrShow: false, //测试结果展示
  128. testResultStr: "", //测试成绩
  129. userCanClick: true, //用户标识用户单次刺激只能点击一次
  130. myInterval: "",
  131. timeOne: "",
  132. timeTwo: "",
  133. startMilliSeconds: 0, //反应时
  134. userResponseRecords: [], //用户测试反应记录
  135. saveFalg: true,
  136. };
  137. },
  138. // 页面初始化函数
  139. created() {
  140. this.taskId = this.$route.query.taskId;
  141. this.init(this.taskId);
  142. },
  143. destroyed() {
  144. clearInterval(this.myInterval);
  145. clearTimeout(this.timeOne);
  146. clearTimeout(this.timeTwo);
  147. },
  148. methods: {
  149. init(taskId) {
  150. //this.subjectInfo = cognitiveAbilityTaskList[taskId];
  151. this.subjectInfo = JSON.parse(oSessionStorage.getItem("subjectInfo"));
  152. },
  153. userClick(clickFlag) {
  154. if (this.countDownShow || !this.userCanClick) {
  155. return;
  156. }
  157. this.userCanClick = false;
  158. let milliSecondsCount = new Date().getTime() - this.startMilliSeconds;
  159. let userResponseStr = "Wrong";
  160. clearTimeout(this.timeOne);
  161. //用户反应正确性判断
  162. if (this.userRightClickDirection == clickFlag) {
  163. this.userRightResponseCount++;
  164. userResponseStr = "Right";
  165. }
  166. //判断是否测试结束
  167. if (this.imgIndex == this.userTestPicList.length) {
  168. this.testEndFlag = true;
  169. }
  170. //记录用户反应
  171. if (this.testTypeCode == 1) {
  172. this.userResponseRecords.push({
  173. index: this.imgIndex,
  174. rightOrWrong: userResponseStr,
  175. responseTime: milliSecondsCount,
  176. diff: this.userTestPicList[this.imgIndex - 1].diff,
  177. });
  178. }
  179. this.showDuckEgg = false;
  180. this.timeTwo = setTimeout(() => {
  181. this.showTargetNow();
  182. }, 500);
  183. },
  184. format(percentage) {
  185. return percentage === 100 ? "测试已完成" : "任务进度";
  186. },
  187. screen() {
  188. screenfull.toggle();
  189. },
  190. startTest(testType) {
  191. if (
  192. sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f") == "" ||
  193. sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f") == null
  194. ) {
  195. this.$message.error("请先登录!");
  196. return;
  197. }
  198. this.screen();
  199. if (testType == 0) {
  200. this.testTypeCode = 0;
  201. } else {
  202. this.saveFalg = true;
  203. this.testTypeCode = 1;
  204. }
  205. this.userId = sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f");
  206. if (this.testTypeCode == 1) {
  207. this.difficultList = [360, 180, 90, 60, 30, 0]; // [360,180,90,60,30,0]
  208. this.imgIndex = 0;
  209. this.countDownStr = "马上开始!";
  210. this.countDownTime = 6;
  211. this.testEndFlag = false;
  212. this.showDuckEgg = false;
  213. this.userTestPicList = [];
  214. }
  215. this.countDownShow = true;
  216. this.userTestPicListCreate();
  217. // 预加载图片后开始测试
  218. preloader(this.userTestPicList, () => {
  219. this.testFlag = true;
  220. this.testState = true;
  221. this.countDown();
  222. });
  223. },
  224. showTargetNow() {
  225. // 练习间隔2~4,正式测试2~12;
  226. this.showDuckEgg = false;
  227. if (this.testEndFlag) {
  228. this.computeScore();
  229. } else {
  230. this.userRightClickDirection = this.userTestPicList[this.imgIndex].imgDirection;
  231. this.examImgUrl = this.userTestPicList[this.imgIndex].imgUrl;
  232. this.showDuckEgg = true;
  233. this.imgIndex++;
  234. this.startMilliSeconds = new Date().getTime();
  235. this.userCanClick = true;
  236. if (this.imgIndex == this.userTestPicList.length) {
  237. this.testEndFlag = true;
  238. }
  239. this.timeOne = setTimeout(this.ifShowNextOne, 10 * 1000, this.imgIndex);
  240. }
  241. },
  242. ifShowNextOne(needClickIndex) {
  243. if (needClickIndex == this.imgIndex) {
  244. this.userClick("NULL");
  245. }
  246. },
  247. computeScore() {
  248. screenfull.exit();
  249. if (this.testTypeCode == 0) {
  250. this.testFlag = false;
  251. this.testState = false;
  252. //this.testTypeCode =1
  253. this.countDownStr = "练习马上开始!";
  254. this.userRightResponseCount = 0;
  255. this.imgIndex = 0;
  256. this.countDownTime = 6;
  257. this.testEndFlag = false;
  258. this.showDuckEgg = false;
  259. this.userTestPicList = [];
  260. this.button1Show = true;
  261. this.$message({
  262. message: "测试结束!",
  263. type: "success",
  264. });
  265. } else {
  266. let userScore = (
  267. (this.userRightResponseCount / this.userResponseRecords.length) *
  268. 100
  269. ).toFixed(2);
  270. this.testFlag = false;
  271. this.testState = false;
  272. this.button0Show = false;
  273. this.button1Show = false;
  274. //console.log(this.userResponseRecords)
  275. if (this.saveFalg) {
  276. this.$http.post(
  277. `/cognize/SHAPE_RANDOM`,
  278. {
  279. userId: this.userId,
  280. userScore: userScore + "%",
  281. userResponseRecords: this.userResponseRecords,
  282. testPlanId: this.$route.query.testPlanId || "",
  283. },
  284. (response) => {
  285. this.goTestResult(response.data)
  286. this.$message({
  287. message: "测试结束!",
  288. type: "success",
  289. });
  290. // this.$router.push({
  291. // name: "TestResult",
  292. // params: {
  293. // result: [
  294. // {
  295. // name: "测试准确率",
  296. // value: userScore + "%",
  297. // }
  298. // ],
  299. // },
  300. // });
  301. }
  302. );
  303. this.saveFalg = false;
  304. }
  305. }
  306. },
  307. userTestPicListCreate() {
  308. let imgObj = {
  309. // imgUrl:'',
  310. // imgDirection:'',
  311. // userClickDirection:''
  312. };
  313. if (this.testTypeCode == 0) {
  314. //随机呈现最简单的10张图片
  315. let imgIndexList = this.getRandomNumber(10, 20);
  316. for (let j = 0; j < this.difficultList.length; j++) {
  317. for (let i = 0; i < imgIndexList.length; i++) {
  318. imgObj = {};
  319. if (i % 2 == 0) {
  320. imgObj.imgUrl = require("../../assets/congnitiveAblitity/shapeIntuition/R_ELP_test_jitter" +
  321. this.difficultList[j] +
  322. "_s" +
  323. imgIndexList[i] +
  324. ".jpg");
  325. imgObj.imgDirection = "R";
  326. imgObj.userClickDirection = "";
  327. } else {
  328. imgObj.imgUrl = require("../../assets/congnitiveAblitity/shapeIntuition/ELP_test_jitter" +
  329. this.difficultList[j] +
  330. "_s" +
  331. imgIndexList[i] +
  332. ".jpg");
  333. imgObj.imgDirection = "L";
  334. imgObj.userClickDirection = "";
  335. }
  336. this.userTestPicList.push(imgObj);
  337. }
  338. }
  339. this.shuffle(this.userTestPicList);
  340. } else {
  341. //展示所有图片
  342. for (let j = 0; j < this.difficultList.length; j++) {
  343. var tempList = [];
  344. for (let i = 1; i < 11; i++) {
  345. imgObj = {};
  346. imgObj.imgUrl = require("../../assets/congnitiveAblitity/shapeIntuition/R_ELP_test_jitter" +
  347. this.difficultList[j] +
  348. "_s" +
  349. i +
  350. ".jpg");
  351. imgObj.imgDirection = "R";
  352. imgObj.userClickDirection = "";
  353. imgObj.diff = this.difficultList[j];
  354. tempList.push(imgObj);
  355. imgObj = {};
  356. imgObj.imgUrl = require("../../assets/congnitiveAblitity/shapeIntuition/ELP_test_jitter" +
  357. this.difficultList[j] +
  358. "_s" +
  359. i +
  360. ".jpg");
  361. imgObj.imgDirection = "L";
  362. imgObj.userClickDirection = "";
  363. imgObj.diff = this.difficultList[j];
  364. tempList.push(imgObj);
  365. //console.log(tempList)
  366. }
  367. //this.shuffle(tempList);
  368. this.userTestPicList = this.userTestPicList.concat(tempList);
  369. this.testPicCount = this.userTestPicList.length;
  370. }
  371. this.shuffle(this.userTestPicList);
  372. console.log(this.userTestPicList);
  373. }
  374. },
  375. getRandomNumber(size, maxNumber) {
  376. let numberList = [];
  377. for (var i = 0; i < size; i++) {
  378. numberList.push(Math.floor(Math.random() * maxNumber) + 1);
  379. }
  380. return numberList;
  381. },
  382. countDown() {
  383. // 测试时间倒计时
  384. this.myInterval = setInterval(() => {
  385. this.countDownTime--;
  386. this.countDownStr = this.countDownTime;
  387. if (this.countDownTime == 0) {
  388. this.countDownShow = false;
  389. //显示鸭蛋
  390. this.showTargetNow();
  391. // 清除定时器
  392. clearInterval(this.myInterval);
  393. //this.countDownTime = 5;
  394. }
  395. }, 1000);
  396. },
  397. shuffle(arr) {
  398. var i = arr.length,
  399. t,
  400. j;
  401. while (i) {
  402. j = Math.floor(Math.random() * i--);
  403. t = arr[i];
  404. arr[i] = arr[j];
  405. arr[j] = t;
  406. }
  407. },
  408. },
  409. };
  410. </script>
  411. <style lang="scss" scoped>
  412. .content-container {
  413. .activeTask {
  414. background: url(../../assets/congnitiveAblitity/shapeIntuition.png) no-repeat
  415. center;
  416. background-size: cover;
  417. width: 100vw;
  418. height: 100vh;
  419. position: fixed;
  420. left: 0;
  421. top: 0;
  422. }
  423. }
  424. .testMainDiv {
  425. margin: 0 auto;
  426. margin-top: 10px;
  427. background: gray;
  428. background-size: cover;
  429. /* text-align:center; */
  430. width: 500px;
  431. height: 300px;
  432. /* object-fit:fill; */
  433. }
  434. .scaleName {
  435. margin-top: 70px;
  436. background-size: cover;
  437. }
  438. .scaleButton {
  439. margin-top: 20px;
  440. margin-bottom: 20px;
  441. background-size: cover;
  442. }
  443. .steering {
  444. width: 50%;
  445. position: absolute;
  446. bottom: 20%;
  447. left: 50%;
  448. transform: translateX(-50%);
  449. display: flex;
  450. justify-content: space-between;
  451. }
  452. .steering .left {
  453. width: 60px;
  454. height: 60px;
  455. background: url(../../assets/left.png) no-repeat center;
  456. }
  457. .steering .right {
  458. width: 60px;
  459. height: 60px;
  460. background: url(../../assets/right.png) no-repeat center;
  461. margin-left: 15px;
  462. }
  463. .imgBox {
  464. font-size: 50px;
  465. color: black;
  466. position: absolute;
  467. top: 50%;
  468. left: 50%;
  469. transform: translate(-50%, -50%);
  470. }
  471. .shapeImg {
  472. width: 50%;
  473. position: absolute;
  474. top: 50%;
  475. left: 50%;
  476. transform: translate(-50%, -50%);
  477. }
  478. .addImg {
  479. width: 71px;
  480. width: 71px;
  481. position: absolute;
  482. top: 50%;
  483. left: 50%;
  484. transform: translate(-50%, -50%);
  485. }
  486. </style>