alertnessAddiction.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <!-- 精神运动警觉度(成瘾版) -->
  2. <template>
  3. <div>
  4. <!-- LOGO -->
  5. <div class="desc_wrap" v-if="!testResultDivShow">
  6. <div
  7. style="
  8. width: 70%;
  9. height: 100%;
  10. background: rgb(248, 248, 248);
  11. opacity: 1;
  12. border-radius: 12px;
  13. margin: 0 auto;
  14. "
  15. >
  16. <div class="left_part">
  17. <div id="left_top">
  18. <div>
  19. <div id="setting">
  20. <img src="../../assets/9551.png" alt="" />
  21. </div>
  22. <div id="text">
  23. <span>操作提示:</span>
  24. </div>
  25. </div>
  26. </div>
  27. <div style="margin: 100px auto; width: 80%; text-align: justify;text-justify: distribute-all-lines;">
  28. <p v-html="subjectInfo.testDescription"></p>
  29. <!-- <p>{{subjectInfo.description}}</p> -->
  30. </div>
  31. </div>
  32. <div
  33. class="right_part"
  34. :style="{
  35. background:
  36. 'url(' + require('../../assets/page' + taskId + '.png') + ')',
  37. 'background-size': '100% 100%',
  38. }"
  39. >
  40. <div id="title">
  41. <span>{{ subjectInfo.name }}</span>
  42. </div>
  43. <div style="position: absolute; bottom: 30px; right: 40%">
  44. <el-button type="primary" class="start" @click="startTest()">{{
  45. buttonName
  46. }}</el-button>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. <div v-if="testResultDivShow" class="coginitiveTestResultDiv">
  52. <p v-if="testResultDivShow" class="testResultStr" style="margin-top: 5%">
  53. 超过0.5秒的比例:{{ pass05SecRate }}%
  54. </p>
  55. <p v-if="testResultDivShow" class="testResultStr">
  56. 超过1秒的比例:{{ pass1SecRate }}%
  57. </p>
  58. <p v-if="testResultDivShow" class="testResultStr">
  59. 平均时长:{{ severalTime }}(ms)
  60. </p>
  61. </div>
  62. <div
  63. v-if="testFlag"
  64. :class="{ testMainDiv: !testState, activeTask: testState }"
  65. @click="userClick()"
  66. >
  67. <div class="taskHead">
  68. <div class="scale" @click.stop="scaleScreen">
  69. <img src="../../assets/small-big.png" alt="" />
  70. </div>
  71. <el-progress
  72. class="main_progress"
  73. v-if="testTypeCode == 1"
  74. :text-inside="true"
  75. :format="format"
  76. :stroke-width="24"
  77. :percentage="((50 - testCount) / 50) * 100"
  78. style="width: 50%"
  79. ></el-progress>
  80. </div>
  81. <div class="glass_wrap">
  82. <div class="glass">
  83. <div class="cognitiveTask" v-if="divShow">
  84. <img :src="imgList[currentIndex].imgUrl" alt="" />
  85. </div>
  86. <p class="countdownStr" v-show="showCountDown">
  87. {{ countDownStr }}
  88. </p>
  89. </div>
  90. </div>
  91. </div>
  92. <div
  93. style="
  94. text-align: center;
  95. padding-bottom: 2rem;
  96. display: block;
  97. margin-top: 3%;
  98. "
  99. >
  100. <!-- <el-button
  101. class="scaleButton"
  102. type="primary"
  103. v-if="buttonShow"
  104. @click="startTest()"
  105. >{{ buttonName }}</el-button
  106. > -->
  107. <el-button
  108. class="scaleButton"
  109. type="primary"
  110. v-if="saveFlag"
  111. @click="resultSave()"
  112. >结果保存</el-button
  113. >
  114. </div>
  115. </div>
  116. </template>
  117. <script>
  118. import cognitiveAbilityTaskList from "@/assets/data/cognitiveAbilityData.js";
  119. import screenfull from "screenfull";
  120. import { oSessionStorage, preloader } from "@/utils/utils";
  121. import { relevant, irrelevant } from "@/utils/addictionImg";
  122. export default {
  123. data() {
  124. return {
  125. userId: "",
  126. countDownTime: 20, //倒计时时长
  127. testCount: 50, //正式测试时50次结束
  128. userResponseMilliSeconds: 0, //当前刺激用户反应时间
  129. userTestAnswer: [], //用户测试反应记录
  130. taskId: "", // 认知任务id
  131. saveFlag: false, //结果保存按钮显示标志
  132. subjectInfo: "", //认知任务详情
  133. divShow: false, // 控制黑框显示隐藏
  134. buttonShow: true, // 控制按钮显示吟唱
  135. passTestExam: false, //练习测试通过标识
  136. testType: "练习测试", // 正式测试
  137. testFlag: false,
  138. buttonName: "开始练习", // 正式测试 // 重新练习
  139. testTypeCode: 0, // 0-练习测试 1-正式测试 2-重新测试
  140. startMilliSeconds: 0, //div出现时的毫秒数
  141. divShowInteval: "", //控制div显示的定时器
  142. countDownInterval: "", //倒计时定时器
  143. myInterval: null,
  144. qualifiedCount: 0, //点击合格数
  145. unQualifiedCount: 0, //点击不合格数
  146. cuntdownMinMilliSeconds: 2000, //练习时 2-4秒 2000
  147. cuntdownMaxMilliSeconds: 4000, //正式测试时2-12秒
  148. testState: false, // 开始测试
  149. testResultDivShow: false, //控制结果展示隐藏
  150. pass05SecRate: "", //超过0.5秒的比例
  151. pass1SecRate: "", //超过1秒的比例
  152. severalTime: "", //平均时长(ms)
  153. showCountDown: true,
  154. countDownStr: "练习马上开始!",
  155. redayTime: 5,
  156. imgList: [...relevant, ...irrelevant],
  157. currentIndex: 0
  158. };
  159. },
  160. // 页面初始化函数
  161. created() {
  162. this.taskId = this.$route.query.taskId;
  163. this.init(this.taskId);
  164. window.addEventListener(
  165. "popstate",
  166. function (e) {
  167. this.divShow = false;
  168. this.testState = false;
  169. this.testFlag = false;
  170. clearInterval(this.divShowInteval);
  171. clearInterval(this.countDownInterval);
  172. },
  173. false
  174. );
  175. },
  176. mounted() {
  177. document.onkeydown = function (e) {
  178. let key = window.event.keyCode;
  179. if (key === 122) {
  180. e.preventDefault();
  181. screenfull.toggle();
  182. }
  183. };
  184. },
  185. destroyed() {
  186. clearInterval(this.divShowInteval);
  187. clearInterval(this.myInterval);
  188. },
  189. methods: {
  190. init(taskId) {
  191. // this.subjectInfo = cognitiveAbilityTaskList[taskId];
  192. this.subjectInfo = JSON.parse(oSessionStorage.getItem("subjectInfo"));
  193. this.imgUrl = this.subjectInfo.imageUrl;
  194. this.imgList = this.shuffle(this.imgList);
  195. },
  196. format(percentage) {
  197. return percentage === 100 ? "测试已完成" : "任务进度";
  198. },
  199. screen() {
  200. screenfull.toggle();
  201. },
  202. userClick() {
  203. //用户点击动作
  204. if (this.divShow) {
  205. this.userResponseMilliSeconds =
  206. new Date().getTime() - this.startMilliSeconds;
  207. //console.log(this.userResponseMilliSeconds)
  208. if (this.userResponseMilliSeconds > 500) {
  209. this.unQualifiedCount++;
  210. } else {
  211. this.qualifiedCount++;
  212. }
  213. this.divShow = false;
  214. } else {
  215. this.unQualifiedCount++;
  216. this.$message.error("错误点击!");
  217. }
  218. },
  219. startTest() {
  220. if (
  221. sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f") == "" ||
  222. sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f") == null
  223. ) {
  224. this.$message.error("请先登录!");
  225. return;
  226. }
  227. this.userId = sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f");
  228. this.startTestTime = new Date().getTime();
  229. this.testState = true;
  230. this.buttonShow = false;
  231. this.testFlag = true;
  232. this.screen();
  233. this.showCountDown = true;
  234. if (this.testTypeCode == 0) {
  235. this.countDownStr = "练习马上开始!";
  236. } else {
  237. this.countDownStr = "测试马上开始!";
  238. }
  239. preloader(this.imgList, () => {
  240. // 测试准备倒计时
  241. var countDown2 = setInterval(() => {
  242. if (this.redayTime == 0) {
  243. // 测试开始
  244. this.countDownStr = "开始";
  245. this.redayTime = 5;
  246. setTimeout(() => {
  247. this.showCountDown = false;
  248. }, 1000);
  249. clearInterval(countDown2);
  250. if (this.testTypeCode == 0) {
  251. this.countDownTime = 20;
  252. this.countDown();
  253. }
  254. this.divShowInteval = setInterval(() => {
  255. this.divRandomShow();
  256. this.currentIndex ++;
  257. if (this.testTypeCode == 1) {
  258. this.testCount--;
  259. if (this.testCount == 0) {
  260. //计算测试结果
  261. this.computeScore();
  262. //清除div控制定时器
  263. clearInterval(this.divShowInteval);
  264. }
  265. }
  266. }, Math.floor(Math.random() * (this.cuntdownMaxMilliSeconds - this.cuntdownMinMilliSeconds + 1)) + this.cuntdownMinMilliSeconds);
  267. } else {
  268. this.countDownStr = this.redayTime;
  269. this.showCountDown = true;
  270. this.redayTime--;
  271. }
  272. }, 1000);
  273. });
  274. },
  275. testEnd() {
  276. //clearInterval(divShowInteval);
  277. this.testState = false;
  278. this.testFlag = false;
  279. this.$message({
  280. message: "测试结束!",
  281. type: "success",
  282. });
  283. },
  284. computeScore() {
  285. this.screen();
  286. //计算练习成绩
  287. if (this.testTypeCode == 0) {
  288. let qualifiedRate =
  289. (this.qualifiedCount * 100) /
  290. (this.unQualifiedCount * 100 + this.qualifiedCount * 100);
  291. if (qualifiedRate >= 0.6) {
  292. this.$message({
  293. message: "通过练习测试,开始进行正式测试!",
  294. type: "success",
  295. });
  296. this.subjectInfo.testDescription = this.subjectInfo.description;
  297. this.passTestExam = true;
  298. this.buttonName = "正式测试";
  299. this.buttonShow = true;
  300. this.testType = "正式测试";
  301. this.testState = false;
  302. this.testFlag = false;
  303. this.testTypeCode = 1;
  304. this.cuntdownMaxMilliSeconds = 6000;
  305. } else {
  306. this.divShow = false;
  307. this.passTestExam = false;
  308. this.buttonName = "重新练习";
  309. this.buttonShow = true;
  310. this.testState = false;
  311. this.testFlag = false;
  312. this.$message({
  313. message: "测试未通过,请点击'重新测试'按钮继续练习!",
  314. type: "warning",
  315. });
  316. }
  317. } else {
  318. this.testState = false;
  319. this.testFlag = false;
  320. //结果保存
  321. this.userResponserSave();
  322. //this.userTestAnswer.push({key:60-this.testCount,value:this.userResponseMilliSeconds==0?new Date()-this.startMilliSeconds:this.userResponseMilliSeconds})
  323. this.$message({
  324. message: "测试结束!",
  325. type: "success",
  326. });
  327. this.buttonShow = false;
  328. }
  329. },
  330. countDown() {
  331. // 测试时间倒计时
  332. this.myInterval = setInterval(() => {
  333. this.countDownTime--;
  334. if (this.countDownTime == 0) {
  335. //计算测试结果
  336. this.computeScore();
  337. // 清除定时器
  338. clearInterval(this.myInterval);
  339. this.countDownTime = 0;
  340. this.currentIndex = 0;
  341. //清除div控制定时器
  342. clearInterval(this.divShowInteval);
  343. screenfull.toggle();
  344. }
  345. }, 1000);
  346. },
  347. divRandomShow() {
  348. if (this.testTypeCode == 1) {
  349. this.userTestAnswer.push({
  350. key: 50 - this.testCount,
  351. value:
  352. this.userResponseMilliSeconds == 0
  353. ? new Date() - this.startMilliSeconds
  354. : this.userResponseMilliSeconds,
  355. });
  356. }
  357. this.divShow = !this.divShow;
  358. this.userResponseMilliSeconds = 0;
  359. this.startMilliSeconds = new Date().getTime();
  360. setTimeout(() => {
  361. this.divShow = false;
  362. }, 1000);
  363. },
  364. userResponserSave() {
  365. this.$http.post(
  366. `/cognize/ALERTNESS_ADDICTION`,
  367. {
  368. userId: this.userId,
  369. data: this.userTestAnswer,
  370. testPlanId: this.$route.query.testPlanId,
  371. },
  372. (response) => {
  373. // this.$router.push({
  374. // name: "TestResult",
  375. // params: {
  376. // result: [
  377. // {
  378. // name: "超过0.5秒的比例",
  379. // value: response.data["超过0.5秒的比例"],
  380. // },
  381. // {
  382. // name: "超过1秒的比例",
  383. // value: response.data["超过1秒的比例"],
  384. // },
  385. // {
  386. // name: "平均时长(ms)",
  387. // value: response.data["平均时长(ms)"],
  388. // },
  389. // ],
  390. // },
  391. // });
  392. if(response && response.code == 200){
  393. this.goTestResult(response.data);
  394. } else {
  395. this.$message({
  396. message: response.msg,
  397. type: "error",
  398. });
  399. }
  400. }
  401. );
  402. },
  403. // 缩放屏幕
  404. scaleScreen() {
  405. screenfull.toggle();
  406. },
  407. // 实现数组随机排序
  408. shuffle(arr) {
  409. var len = arr.length;
  410. for (var i = 0; i < len; i++) {
  411. var a = parseInt(Math.random() * len);
  412. var temp = arr[a];
  413. arr[a] = arr[i];
  414. arr[i] = temp;
  415. }
  416. return arr;
  417. },
  418. },
  419. };
  420. </script>
  421. <style scoped>
  422. .coginitiveTestResultDiv {
  423. margin: 0 auto;
  424. /* margin-top: 2%; */
  425. margin-left: 33%;
  426. /* background: black; */
  427. background-size: cover;
  428. /* text-align:center; */
  429. width: 500px;
  430. height: 150px;
  431. }
  432. .testResultStr {
  433. color: red;
  434. text-align: left;
  435. font-size: 30px;
  436. margin-top: 2%;
  437. margin-left: 15%;
  438. }
  439. .testMainDiv {
  440. margin: 0 auto;
  441. margin-top: 10px;
  442. background: gray;
  443. background-size: cover;
  444. /* text-align:center; */
  445. width: 500px;
  446. height: 300px;
  447. /* object-fit:fill; */
  448. }
  449. .activeTask {
  450. /* background: linear-gradient(180deg, #57acbb 0%, #6190db 100%); */
  451. background: url(../../assets/congnitiveAblitity/alert.png) no-repeat center;
  452. background-size: cover;
  453. position: fixed;
  454. top: 0;
  455. left: 0;
  456. right: 0;
  457. bottom: 0;
  458. display: flex;
  459. flex-direction: column;
  460. }
  461. .cognitiveTask {
  462. display: flex;
  463. align-items: center;
  464. width: 347px;
  465. height: 351px;
  466. background: #000000;
  467. border-radius: 24px;
  468. position: absolute;
  469. top: 50%;
  470. left: 50%;
  471. transform: translate(-50%, -50%);
  472. }
  473. .cognitiveTask img {
  474. width: 100%;
  475. height: auto;
  476. }
  477. .scaleName {
  478. margin-top: 70px;
  479. background-size: cover;
  480. }
  481. .scaleButton {
  482. margin-top: 40px;
  483. margin-bottom: 20px;
  484. background-size: cover;
  485. }
  486. </style>