examStart.vue 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815
  1. <template>
  2. <view class="container">
  3. <view>
  4. <!-- 提示信息弹窗 -->
  5. <uni-popup ref="message" type="message">
  6. <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
  7. </uni-popup>
  8. </view>
  9. </view>
  10. <view style="font-family: '微软雅黑', serif;
  11. font-size: 40px;
  12. color: #7f7f44;height: 30px;text-align: center;padding:20px;padding-bottom: 0;">
  13. {{examObject.examTitle}}
  14. </view>
  15. <uni-row>
  16. <uni-col :span="4" style="margin-top: 30px">
  17. <uni-card style="height: 85vh;">
  18. <l-divider color="#00a60d">
  19. <view style="font-size: 20px;">考生信息</view>
  20. </l-divider>
  21. <view
  22. style="font-family: '微软雅黑' , serif;font-size: 20px;color: #8c8c8c;height: 30px;text-align: center;padding:5px;">
  23. 姓名:{{user.realname}}
  24. </view>
  25. <view
  26. style="font-family: '微软雅黑', serif;font-size: 20px;color: #8c8c8c;height: 30px;text-align: center;padding:5px;">
  27. 考号:{{user.username}}
  28. </view>
  29. <l-divider color="#00a60d">
  30. <view style="font-size: 20px;">试卷名称</view>
  31. </l-divider>
  32. <radio-group>
  33. <label v-for="(item, index) in examObject.examPapersList" :key="item.value">
  34. <view>
  35. <view class="paperCss"
  36. :style="'background-color: '+(item.state === 0?'#b5aa09;':(item.state === 9?'#ececec':'#00f545'))">
  37. <view style="color: #000000;"> <strong>{{item.title}}</strong></view>
  38. </view>
  39. </view>
  40. </label>
  41. </radio-group>
  42. <l-divider color="#b3b3b3">
  43. </l-divider>
  44. <button type="primary" style="margin-top: 10px;" @click="subExam">交卷</button>
  45. <button type="primary" style="margin-top: 10px;" @click="reload">刷新</button>
  46. </uni-card>
  47. </uni-col>
  48. <uni-col :span="16" style="margin-top: 30px">
  49. <uni-card style="height: 85vh;">
  50. <scroll-view scroll-y="true" class="scroll-Y">
  51. <uni-section :title="scantron.questionIndex+'、'+scantron.questionTypeName" type="line" padding>
  52. <view v-if="scantron.questionType!==7&&scantron.questionType!==8" id="scantronNodes"
  53. style="height: 45vh;">
  54. </view>
  55. <view v-if="scantron.questionType==7||scantron.questionType==8" id="scantronNodes"
  56. style="height: 5vh;">
  57. </view>
  58. <template v-if="scantron.questionType===1||scantron.questionType===3">
  59. <view>
  60. <l-divider color="#aaaa7f">
  61. </l-divider>
  62. </view>
  63. <view>
  64. <radio-group>
  65. <label v-for="(item, index) in scantron.question.answerList" :key="item">
  66. <view>
  67. <button @click="radioAdd(item,index,scantron)"
  68. :style="'margin-top: 15px;padding-left:15px;font-size: 20px;text-align: left;background-color: '+(item.isRight?'#f9ea0d;':'#f0eff0')"><strong
  69. style="color: #0072eb;">{{item.tag+"、"}}</strong>{{item.content}}</button>
  70. </view>
  71. </label>
  72. </radio-group>
  73. </view>
  74. </template>
  75. <template v-if="scantron.questionType===2">
  76. <view>
  77. <l-divider color="#aaaa7f">
  78. </l-divider>
  79. </view>
  80. <view>
  81. <radio-group>
  82. <label v-for="(item, index) in scantron.question.answerList" :key="item.value">
  83. <view>
  84. <button @click="item.isRight=!item.isRight;radioAdd(item,index,scantron);"
  85. :style="'margin-top: 15px;padding-left:15px;font-size: 20px;text-align: left;background-color: '+(item.isRight?'#f9ea0d;':'#f0eff0')"><strong
  86. style="color: #0072eb;">{{item.tag+"、"}}</strong>{{item.content}}</button>
  87. </view>
  88. </label>
  89. </radio-group>
  90. </view>
  91. </template>
  92. <template v-if="scantron.questionType===4">
  93. <view>
  94. <l-divider color="#aaaa7f">
  95. </l-divider>
  96. </view>
  97. <view>
  98. <view>
  99. <view class="uni-textarea"
  100. style="border: #8c8c8c solid 2px;border-radius: 5px;height: 20vh;">
  101. <textarea @blur="radioAdd(null,null,scantron)"
  102. v-model="scantron.question.subjectiveAnswer"
  103. placeholder-style="color:#c7c7c7" placeholder="请输入答案" />
  104. </view>
  105. </view>
  106. </view>
  107. </template>
  108. <template v-if="scantron.questionType===5">
  109. <view>
  110. <l-divider color="#aaaa7f">
  111. </l-divider>
  112. </view>
  113. <view>
  114. <label v-for="(item, index) in scantron.question.answerList" :key="item.value">
  115. <view class="allceter"
  116. style="background-color: #e7f4ff; text-align: left;padding: 10px;margin-bottom: 10px;border: #2a7eeb solid 1px;border-radius: 5px;">
  117. <view style="display: inline-block;padding-left: 10px;">
  118. <strong style="font-size: 20px;color: #0072eb;">{{item.tag}}</strong>
  119. </view>
  120. <input @blur="radioAdd(item.blankcontent,item.tag,scantron)" class="uni-input"
  121. style="display: inline-block;background-color: white;" type="text"
  122. v-model="item.blankcontent" :placeholder="item.tag" />
  123. </view>
  124. </label>
  125. </view>
  126. </template>
  127. <template v-if="scantron.questionType===6">
  128. <view>
  129. <l-divider color="#aaaa7f">
  130. </l-divider>
  131. </view>
  132. <view class="" v-for="(combinationItem,index) in scantron.subQuestionList">
  133. <uni-card>
  134. <strong>{{scantron.questionIndex+'.'+combinationItem.questionIndex+'、'+combinationItem.questionTypeName}}</strong>
  135. <view :id="'combinationItemNodes'+index" style="height: 45vh;">
  136. <!-- <rich-text :nodes="combinationItem.question.content"></rich-text> -->
  137. </view>
  138. <template v-if="combinationItem.questionType===1||combinationItem.questionType===3">
  139. <view>
  140. <l-divider color="#aaaa7f">
  141. </l-divider>
  142. </view>
  143. <view>
  144. <radio-group>
  145. <label v-for="(item, index0) in combinationItem.question.answerList"
  146. :key="item">
  147. <view>
  148. <button @click="radioAdd(item,index0,scantron,combinationItem)"
  149. :style="'margin-top: 15px;padding-left:15px;font-size: 20px;text-align: left;background-color: '+(item.isRight?'#f9ea0d;':'#f0eff0')"><strong
  150. style="color: #0072eb;">{{item.tag+"、"}}</strong>{{item.content}}</button>
  151. </view>
  152. </label>
  153. </radio-group>
  154. </view>
  155. </template>
  156. <template v-if="combinationItem.questionType===2">
  157. <view>
  158. <l-divider color="#aaaa7f">
  159. </l-divider>
  160. </view>
  161. <view>
  162. <radio-group>
  163. <label v-for="(item, index) in combinationItem.question.answerList"
  164. :key="item.value">
  165. <view>
  166. <button
  167. @click="item.isRight=!item.isRight;radioAdd(item,index0,scantron,combinationItem);"
  168. :style="'margin-top: 15px;padding-left:15px;font-size: 20px;text-align: left;background-color: '+(item.isRight?'#f9ea0d;':'#f0eff0')"><strong
  169. style="color: #0072eb;">{{item.tag+"、"}}</strong>{{item.content}}</button>
  170. </view>
  171. </label>
  172. </radio-group>
  173. </view>
  174. </template>
  175. <template v-if="combinationItem.questionType===4">
  176. <view>
  177. <l-divider color="#aaaa7f">
  178. </l-divider>
  179. </view>
  180. <view>
  181. <view>
  182. <view class="uni-textarea"
  183. style="border: #8c8c8c solid 2px;border-radius: 5px;height: 20vh;">
  184. <textarea v-model="combinationItem.question.subjectiveAnswer"
  185. placeholder-style="color:#c7c7c7" placeholder="请输入答案" />
  186. </view>
  187. </view>
  188. </view>
  189. </template>
  190. <template v-if="combinationItem.questionType===5">
  191. <view>
  192. <l-divider color="#aaaa7f">
  193. </l-divider>
  194. </view>
  195. <view>
  196. <label v-for="(item, index) in combinationItem.question.answerList"
  197. :key="item.value">
  198. <view class="allceter"
  199. style="background-color: #e7f4ff; text-align: left;padding: 10px;margin-bottom: 10px;border: #2a7eeb solid 1px;border-radius: 5px;">
  200. <view style="display: inline-block;padding-left: 10px;">
  201. <strong
  202. style="font-size: 20px;color: #0072eb;">{{item.tag}}</strong>
  203. </view>
  204. <input
  205. @blur="radioAdd(item.blankcontent,item.tag,scantron,combinationItem)"
  206. class="uni-input"
  207. style="display: inline-block;background-color: white;"
  208. type="text" v-model="item.blankcontent"
  209. :placeholder="item.tag" />
  210. </view>
  211. </label>
  212. </view>
  213. </template>
  214. </uni-card>
  215. </view>
  216. </template>
  217. <template v-if="scantron.questionType===7">
  218. <button @click="restart">重置</button>
  219. <view>
  220. <l-divider color="#aaaa7f">
  221. </l-divider>
  222. </view>
  223. <view style="height: 600px;width: 800;background-color: #ffffff;">
  224. <movable-area
  225. :style="`height: 500px;width: 700px;background-color: #8c8c8c;margin: auto;background-image: url('${drag[this.scantron.sort].background.url}');background-size:${drag[this.scantron.sort].background.width}px ${drag[this.scantron.sort].background.height}px;background-repeat: no-repeat;`">
  226. <!-- <rich-text :nodes="scantron.question.content"></rich-text> -->
  227. <!-- <img v-if="drag.background.url!==''" :style="`width:${drag.background.width} px;height:${drag.background.height} px;`" :src="drag.background.url"/> -->
  228. <template v-for="item in drag[this.scantron.sort].answer">
  229. <view
  230. :style="`position: absolute;width: ${item.width}px;height: ${item.height}px;border:solid 1px black;left:${item.x}px;top:${item.y}px;`">
  231. </view>
  232. </template>
  233. <template v-for="item in drag[this.scantron.sort].option">
  234. <movable-view v-if="mbvShow" :id="item.id" :disabled="!disabledDrag"
  235. :style="'width: '+item.width+'px;height: '+item.height+'px;background-color: '+item.backgroundColor+';'"
  236. direction="all" :x="item.x" :y="item.y" @mousedown="onMousedown(item)"
  237. @change="onChange">
  238. </movable-view>
  239. <movable-view v-if="!mbvShow" :id="item.id" :disabled="!disabledDrag"
  240. :style="'width: '+item.width+'px;height: '+item.height+'px;background-color: '+item.backgroundColor+';'"
  241. direction="all" :x="item.x" :y="item.y" @mousedown="onMousedown(item)"
  242. @change="onChange">
  243. </movable-view>
  244. </template>
  245. </movable-area>
  246. </view>
  247. </template>
  248. <template v-if="scantron.questionType===8">
  249. <view style="height: 5vh;">
  250. </view>
  251. <view>
  252. <l-divider color="#aaaa7f">
  253. </l-divider>
  254. </view>
  255. <view>
  256. <view
  257. style="height: 600px;width: 800px;background-color: #8c8c8c;margin: auto;padding-top: 50px;">
  258. <movable-area
  259. style="height: 550px;width: 700px;background-color: #f6f6f6;margin: auto;">
  260. <canvas canvas-id="lineCanvas" style="width: 700px; height: 500px;">
  261. <template v-for="(item,index) in connectionHtml">
  262. <view
  263. style="display: inline-block;margin-top: 30px;margin-left: 30px;margin-right: 70px;">
  264. <!-- <rich-text :nodes="item.innerHTML"></rich-text> -->
  265. <view v-for="(item0,index0) in item.children" :key="index">
  266. <view :id="'option'+index+'-'+(index0+1)"
  267. style="width: 90px;height: 100px;padding: 10px;padding-bottom:0 ;margin-bottom: 10px;border-radius: 5px;border: #007aff solid 1px;background-color: #e0eef9;overflow: hidden;">
  268. </view>
  269. </view>
  270. </view>
  271. </template>
  272. </canvas>
  273. </movable-area>
  274. </view>
  275. </view>
  276. </template>
  277. </uni-section>
  278. </scroll-view>
  279. </uni-card>
  280. </uni-col>
  281. <uni-col :span="4" style="margin-top: 30px">
  282. <uni-card style="height: 85vh;">
  283. <l-divider color="#8f960c" style="margin-top: 20px;">
  284. <view style="font-size: 20px;">当前试卷时间</view>
  285. </l-divider>
  286. <view
  287. style="font-family: '微软雅黑', serif;font-size: 20px;color: #f90005;height: 30px;text-align: center;padding:10px;font-size: 35px;">
  288. <strong>{{paperTime}}</strong>
  289. </view>
  290. <!-- <l-divider color="#8f960c">
  291. <view style="font-size: 20px;">考试时间</view>
  292. </l-divider>
  293. <view
  294. style="font-family: '微软雅黑', serif;font-size: 15px;color: #00aaf9;height: 30px;text-align: center;padding:10px;">
  295. 剩余:{{examTime}}
  296. </view> -->
  297. <l-divider color="#251e75">
  298. <view style="font-size: 20px;">答题卡</view>
  299. </l-divider>
  300. <view>
  301. <scroll-view scroll-y="true" style="height: 50vh;">
  302. <label v-for="(item, index) in examObject.answerCardList2" :key="item">
  303. <uni-section class="mb-10" :title="item.questionTypeName" type="line">
  304. <template v-for="sort in item.indexList">
  305. <view style="display: inline-block;margin-left: 5px;"
  306. @mousedown="radioScantron(sort)">
  307. <view>
  308. <button type="radio"
  309. :style="'width: 30px;height: 30px;padding:0px;color:#FFFFFF;font-size: 12px;text-align: center;background-color: '+(sort === scantron.questionIndex?'#b5aa09;':(this.examObject.userExamQuestionList[sort-1].question.isAnswer?'#18da59':'#007aff'))">{{sort}}</button>
  310. </view>
  311. <view>
  312. {{item.questionTypeName.replace("题","")}}
  313. </view>
  314. </view>
  315. </template>
  316. </uni-section>
  317. </label>
  318. </scroll-view>
  319. </view>
  320. <l-divider color="#251e75" />
  321. <view>
  322. <button type="primary" style="margin-top: 10px;" @click="previousQuestion">上一题</button>
  323. <button type="primary" style="margin-top: 10px;" @click="nextQuestion">下一题</button>
  324. </view>
  325. </uni-card>
  326. </uni-col>
  327. </uni-row>
  328. <uni-popup ref="message" type="message">
  329. <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
  330. </uni-popup>
  331. <uni-popup ref="inputDialog" type="dialog">
  332. <uni-popup-dialog ref="inputClose" title="提交试卷" @confirm="dialogInputConfirm">
  333. <view>
  334. <view>1、提交当前试卷后不可再次作答</view>
  335. <view>2、本试卷剩余时间不计入下一套</view>
  336. <view>3、最终试卷提交将结束考试</view>
  337. <view style="text-align: center;">确认提交?</view>
  338. </view>
  339. </uni-popup-dialog>
  340. </uni-popup>
  341. <uni-popup ref="cheat" type="dialog">
  342. <uni-popup-dialog style="width: 50vh;" ref="inputClose" title="作弊提醒">
  343. <view style="color: red;">
  344. <view>1、鼠标请勿点击窗口之外的地方</view>
  345. <view>2、如果不小心退出全屏,请按F11恢复到全屏</view>
  346. <view>3、鼠标多次点击窗口之外的地方将按作弊处理</view>
  347. </view>
  348. </uni-popup-dialog>
  349. </uni-popup>
  350. </template>
  351. <script>
  352. import {
  353. exit,
  354. request,
  355. getExamDetail,
  356. cacheExamAnswer,
  357. getCacheAnswer,
  358. submitExamPaper,
  359. getExamQueryById
  360. } from '../../examJs/examRequest';
  361. import screenfull from "screenfull";
  362. import {
  363. redirectTo,
  364. toLogin
  365. } from '../../examJs/examRoute';
  366. import {
  367. windowState
  368. } from '../../util/examStartUtil';
  369. export default {
  370. name: "examStart",
  371. data() {
  372. return {
  373. // 所有方块============拖拽
  374. drag: [],
  375. // 拖拽元素刷新
  376. mbvShow: true,
  377. // 拖拽的方块信息
  378. dragItem: {},
  379. // 拖拽位置记录
  380. subDrag: [],
  381. // 拖拽后动作未完成禁用
  382. disabledDrag: true,
  383. // ==================================
  384. // 连线===============================
  385. // 连线题内容页面展示
  386. connectionHtml: [],
  387. // 连线题中间存储
  388. connectionInfo: [],
  389. // 连线题连线内容保存
  390. connectionContentALL: [],
  391. // 连线绘制
  392. ctx: null,
  393. // 点击过程颜色
  394. clickColor: '0px 0px 5px 2px rgba(80, 85, 83, 0.7)',
  395. // 点击结束颜色
  396. connectionColor: ['#ffaa00', '#00ff7f', '#6ca7ff', '#1d00ff', '#aa00ff', '#ffff00', '#550000', '#ff0000'],
  397. // ==============================
  398. // 所有试卷和试题
  399. examObject: {},
  400. // 当前题目
  401. examTopic: {},
  402. // 答题卡
  403. scantron: '',
  404. //选项
  405. answer: {},
  406. typeThree: '',
  407. userExamAnswers: [],
  408. user: {},
  409. // 拖动监听测试
  410. b: true,
  411. canvasWidth: 300,
  412. canvasHeight: 300,
  413. // 用户当前考试
  414. userExamPaper: {},
  415. // 倒计时实际时间
  416. examPaperTime: 0,
  417. // 除当前试卷的其他时间
  418. papersTime: 0,
  419. // 倒计时试卷显示时间
  420. paperTime: '',
  421. // 倒计时考试显示时间
  422. examTime: '',
  423. // 倒计时函数
  424. intervalId: null,
  425. // 切屏记录========================
  426. windowCheat: 0,
  427. // 切屏状态
  428. cheat: null,
  429. // 消息弹窗记录=================
  430. msgType: 'success',
  431. messageText: '这是一条成功提示',
  432. };
  433. },
  434. methods: {
  435. // 页面刷新
  436. reload() {
  437. cacheExamAnswer({
  438. 'examAnswers': this.userExamAnswers,
  439. 'userExamId': sessionStorage.getItem('examId'),
  440. 'leaveTime': this.windowCheat,
  441. 'paperId': this.userExamPaper.paperId,
  442. 'limitTime': this.userExamPaper.limitTime
  443. }).then(data => {
  444. console.log(data);
  445. window.location.reload()
  446. })
  447. },
  448. // 消息提示
  449. messageToggle(type, message) {
  450. this.msgType = type
  451. this.messageText = message
  452. this.$refs.message.open()
  453. },
  454. // 弹窗内容
  455. dialogInputConfirm(val) {
  456. this.submitExam()
  457. },
  458. // 提交试卷弹窗提示打开
  459. subExam() {
  460. this.$refs.inputDialog.open()
  461. },
  462. // 提交试卷
  463. submitExam(ins) {
  464. console.log(ins);
  465. submitExamPaper({
  466. 'examAnswers': this.userExamAnswers,
  467. 'userExamId': sessionStorage.getItem('examId'),
  468. 'paperId': this.userExamPaper.paperId,
  469. }).then(data => {
  470. if (data.data.result !== null && data.data.success) {
  471. if (ins !== 0 && ins !== 'cheat') {
  472. this.messageToggle('success', "本试卷提交成功,即将开始下一张试卷······")
  473. }
  474. this.userExamAnswers = []
  475. clearInterval(this.intervalId);
  476. this.examObject = data.data.result
  477. this.scantron = this.examObject.userExamQuestionList[0]
  478. this.userExamPaper = this.examObject.userExamPapersList[0]
  479. this.examPaperTime = this.addExamPaperTime(new Date(this.userExamPaper.systemTime),
  480. new Date(this
  481. .userExamPaper.limitTime))
  482. // 试卷计时
  483. this.papersTime = this.examPapersTime()
  484. this.intervalId = setInterval(this.updateCountDown, 1000);
  485. this.examTime = this.paperTime
  486. } else {
  487. if (ins === 'cheat') {
  488. this.messageToggle('error', "多次切屏,考试强行终止")
  489. } else if (ins !== 0) {
  490. this.messageToggle('success', "考试已结束,即将退出!")
  491. } else {
  492. this.messageToggle('warn', "时间已到,已为您自动交卷")
  493. }
  494. setTimeout(() => {
  495. screenfull.exit();
  496. window.removeEventListener('blur', this.handleBlur);
  497. window.removeEventListener('focus', this.handleFocus);
  498. exit()
  499. }, 2000)
  500. }
  501. if (data.data.result !== null && data.data.success && ins === 'cheat') {
  502. this.handleBlur(0)
  503. }
  504. })
  505. },
  506. // 重置
  507. restart() {
  508. this.disabledDrag = true
  509. this.drag[this.scantron.sort].answer = []
  510. this.drag[this.scantron.sort].option = []
  511. let content = this.stringToHTML(this.scantron.question.content)
  512. console.log(content);
  513. for (var i = 0; i < content.children.length; i++) {
  514. let thisTop = content.children[i].style.top.toString().replace("px", "")
  515. let thisLeft = content.children[i].style.left.toString().replace("px", "")
  516. let thisWidth = content.children[i].style.width.toString().replace("px", "")
  517. let thisHeight = content.children[i].style.height.toString().replace("px", "")
  518. let thisBackgroundColor = content.children[i].style.backgroundColor
  519. let thisInnerHTML = content.children[i].innerHTML
  520. if (content.children[i].id.includes("option")) {
  521. this.drag[this.scantron.sort].option.push({
  522. id: content.children[i].id,
  523. x: Number(thisLeft),
  524. y: Number(thisTop),
  525. old: {
  526. x: 0,
  527. y: 0,
  528. ax: Number(thisLeft),
  529. by: Number(thisTop)
  530. },
  531. // 只添加一次拖拽监听
  532. b: true,
  533. width: thisWidth,
  534. height: thisHeight,
  535. backgroundColor: thisBackgroundColor,
  536. innerHTML: thisInnerHTML
  537. })
  538. }
  539. if (content.children[i].id.includes("answer")) {
  540. this.drag[this.scantron.sort].answer.push({
  541. id: content.children[i].id,
  542. x: Number(thisLeft),
  543. y: Number(thisTop),
  544. old: {
  545. x: 0,
  546. y: 0
  547. },
  548. width: thisWidth,
  549. height: thisHeight,
  550. backgroundColor: thisBackgroundColor
  551. })
  552. }
  553. }
  554. },
  555. // 上一题目
  556. previousQuestion() {
  557. if (this.scantron.sort > 1) {
  558. this.radioScantron(this.scantron.sort - 1)
  559. }
  560. },
  561. // 下一题目
  562. nextQuestion() {
  563. if (this.scantron.sort < this.examObject.userExamQuestionList.length) {
  564. // this.scantron = this.examObject.userExamQuestionList[this.scantron.sort]
  565. this.radioScantron(this.scantron.sort + 1)
  566. }
  567. },
  568. // 答题卡单击题目
  569. radioScantron(value) {
  570. this.scantron = this.examObject.userExamQuestionList[value - 1]
  571. if (this.scantron.questionType !== 7 && this.scantron.questionType !== 8) {
  572. document.getElementById('scantronNodes').innerHTML = this.scantron.question.content
  573. }else{
  574. console.log(this.scantron.question.content.split('%||||||||%')[0]);
  575. document.getElementById('scantronNodes').innerHTML = this.scantron.question.content.split('%||||||||%')[0]
  576. }
  577. let combination = setInterval(() => {
  578. if (this.scantron.questionType == 6) {
  579. for (var i = 0; i < this.scantron.subQuestionList.length; i++) {
  580. if (document.getElementById('combinationItemNodes' + i) === null) {
  581. console.log("加载中");
  582. break;
  583. }
  584. document.getElementById('combinationItemNodes' + i).innerHTML = this.scantron
  585. .subQuestionList[i].question.content
  586. }
  587. clearInterval(combination);
  588. }
  589. }, 10)
  590. cacheExamAnswer({
  591. 'examAnswers': this.userExamAnswers,
  592. 'userExamId': sessionStorage.getItem('examId'),
  593. 'leaveTime': this.windowCheat,
  594. 'paperId': this.userExamPaper.paperId,
  595. 'limitTime': this.userExamPaper.limitTime
  596. })
  597. // 拖拽加载
  598. if (this.scantron.questionType == 7) {
  599. this.mbvShow = !this.mbvShow
  600. this.disabledDrag = true
  601. console.log(this.drag[this.scantron.questionIndex]);
  602. if (this.drag[this.scantron.questionIndex] !== undefined) {
  603. setTimeout(() => {
  604. for (var i = 0; i < this.drag[this.scantron.sort].option.length; i++) {
  605. let drags = this.drag[this.scantron.sort].option[i]
  606. console.log(document.getElementById(drags.id));
  607. document.getElementById(drags.id).innerHTML = drags.innerHTML
  608. }
  609. }, 10)
  610. return
  611. }
  612. this.drag[this.scantron.questionIndex] = {}
  613. this.drag[this.scantron.questionIndex].answer = []
  614. this.drag[this.scantron.questionIndex].option = []
  615. this.drag[this.scantron.questionIndex].background = {}
  616. let content = this.stringToHTML(this.scantron.question.content)
  617. for (var i = 0; i < content.children.length; i++) {
  618. let thisTop = content.children[i].style.top.toString().replace("px", "")
  619. let thisLeft = content.children[i].style.left.toString().replace("px", "")
  620. let thisWidth = content.children[i].style.width.toString().replace("px", "")
  621. let thisHeight = content.children[i].style.height.toString().replace("px", "")
  622. let thisBackgroundColor = content.children[i].style.backgroundColor
  623. let thisInnerHTML = content.children[i].innerHTML
  624. if (content.children[i].id.includes("option")) {
  625. this.drag[this.scantron.sort].option.push({
  626. id: content.children[i].id,
  627. x: Number(thisLeft),
  628. y: Number(thisTop),
  629. old: {
  630. x: 0,
  631. y: 0,
  632. ax: Number(thisLeft),
  633. by: Number(thisTop)
  634. },
  635. // 只添加一次拖拽监听
  636. b: true,
  637. width: thisWidth,
  638. height: thisHeight,
  639. backgroundColor: thisBackgroundColor,
  640. innerHTML: thisInnerHTML
  641. })
  642. }
  643. if (content.children[i].id.includes("answer")) {
  644. this.drag[this.scantron.sort].answer.push({
  645. id: content.children[i].id,
  646. x: Number(thisLeft),
  647. y: Number(thisTop),
  648. old: {
  649. x: 0,
  650. y: 0
  651. },
  652. width: thisWidth,
  653. height: thisHeight,
  654. backgroundColor: thisBackgroundColor
  655. })
  656. }
  657. if (content.children[i].tagName === 'IMG') {
  658. this.drag[this.scantron.sort].background.url = content.children[i].src
  659. this.drag[this.scantron.sort].background.width = content.children[i].style.width.toString()
  660. .replace("px", "")
  661. this.drag[this.scantron.sort].background.height = content.children[i].style.height.toString()
  662. .replace("px", "")
  663. }
  664. }
  665. console.log(this.drag[this.scantron.sort].option.length);
  666. setTimeout(() => {
  667. for (var i = 0; i < this.drag[this.scantron.sort].option.length; i++) {
  668. let drags = this.drag[this.scantron.sort].option[i]
  669. console.log(document.getElementById(drags.id));
  670. document.getElementById(drags.id).innerHTML = drags.innerHTML
  671. }
  672. }, 10)
  673. }
  674. // 连线题添加监听
  675. if (this.scantron.questionType == 8) {
  676. this.connectionHtml = []
  677. let content = this.stringToHTML(this.scantron.question.content)
  678. for (var i = 0; i < content.children.length; i++) {
  679. let child = content.children[i]
  680. for (var j = 0; j < child.children.length; j++) {
  681. if (child.children[j].id !== undefined && child.children[j].id.includes("option")) {
  682. this.connectionHtml.push(child.children[j])
  683. }
  684. }
  685. }
  686. if (this.connectionContentALL[value] === undefined) {
  687. this.connectionContentALL[value] = []
  688. }
  689. this.connectionInfo = []
  690. setTimeout(() => {
  691. // 画内容
  692. this.drawLineWriteContent()
  693. // 画缓存线
  694. this.drawLineWrite(value)
  695. }, 100)
  696. for (var i = 0; i < this.connectionHtml.length; i++) {
  697. let option = this.connectionHtml[i]
  698. for (var j = 0; j < option.children.length; j++) {
  699. let ids = "option" + i + "-" + (j + 1)
  700. if (document.getElementById(ids) === null) {
  701. setTimeout(() => {
  702. let optionCol = document.getElementById(ids)
  703. optionCol.addEventListener("mousedown", (event) => {
  704. console.log(event);
  705. let id = event.currentTarget.id
  706. console.log(id);
  707. let colId = Number(id.replace('option', '').split('-')[0])
  708. let rowId = Number(id.replace('option', '').split('-')[1])
  709. let left = event.target.offsetLeft
  710. let right = Number(event.target.offsetLeft + event.target
  711. .offsetWidth)
  712. let top = Number(event.target.offsetTop + event.target
  713. .offsetHeight / 2)
  714. if (this.connectionInfo.length === this.connectionHtml.length &&
  715. colId === 0) {
  716. this.connectionContentALL[this.scantron.sort].push(this
  717. .connectionInfo)
  718. this.radioAdd(this.connectionInfo, this
  719. .connectionInfo[0].id.replace('option', '').split('-')[
  720. 1], this.scantron)
  721. this.connectionInfo = []
  722. }
  723. let arr = []
  724. for (var i = 0; i < this.connectionContentALL[this.scantron.sort]
  725. .length; i++) {
  726. let all = this.connectionContentALL[this.scantron.sort][i]
  727. if (all[0].id !== id) {
  728. arr.push(this.connectionContentALL[this.scantron.sort][i])
  729. }
  730. }
  731. this.connectionContentALL[this.scantron.sort] = arr
  732. let infoLength = this.connectionInfo.length
  733. if (infoLength <= this.connectionHtml.length) {
  734. if (infoLength !== 0) {
  735. if (!this.isLine(id, this.scantron.sort)) {
  736. this.messageToggle('error', "这个已经连过了")
  737. this.drawLineWrite(this.scantron.sort)
  738. return
  739. }
  740. let last = this.connectionInfo[infoLength -
  741. 1]
  742. let lastId = Number(last.id.replace('option', '').split(
  743. '-')[0])
  744. if (lastId + 1 === colId) {
  745. this.connectionInfo.push({
  746. 'id': id,
  747. 'left': left,
  748. 'right': right,
  749. 'top': top
  750. })
  751. }
  752. if (lastId === colId && colId !== this.connectionHtml
  753. .length - 1) {
  754. this.connectionInfo[infoLength - 1] = {
  755. 'id': id,
  756. 'left': left,
  757. 'right': right,
  758. 'top': top
  759. }
  760. document.getElementById(ids).style.boxShadow = this
  761. .clickColor
  762. if (Number(last.id.replace('option', '').split(
  763. '-')[1]) === rowId &&
  764. this.connectionInfo.length === this.connectionHtml
  765. .length) {
  766. this.connectionContentALL[this.scantron.sort].push(
  767. this.connectionInfo)
  768. console.log(this.connectionContentALL[this.scantron
  769. .sort]);
  770. this.radioAdd(this.connectionInfo, this
  771. .connectionInfo[0].id.replace('option', '')
  772. .split('-')[1], this.scantron)
  773. this.connectionInfo = []
  774. }
  775. } else if (colId === this.connectionHtml.length - 1) {
  776. this.connectionContentALL[this.scantron.sort].push(
  777. this.connectionInfo)
  778. console.log(this.connectionContentALL[this.scantron
  779. .sort]);
  780. this.radioAdd(this.connectionInfo, this
  781. .connectionInfo[0].id.replace('option', '')
  782. .split('-')[1], this.scantron)
  783. this.connectionInfo = []
  784. }
  785. } else if (infoLength === 0) {
  786. if (colId === 0) {
  787. this.connectionInfo.push({
  788. 'id': id,
  789. 'left': left,
  790. 'right': right,
  791. 'top': top
  792. })
  793. console.log(document.getElementById(id + ''));
  794. document.getElementById(id + '').style.boxShadow = this
  795. .clickColor
  796. console.log(document.getElementById(id));
  797. }
  798. }
  799. }
  800. this.shadowClean()
  801. this.drawLineWrite(this.scantron.sort)
  802. })
  803. }, 10)
  804. } else {
  805. setTimeout(() => {
  806. this.shadowClean()
  807. }, 10)
  808. }
  809. }
  810. }
  811. }
  812. },
  813. // 连线绘制
  814. drawLine(x1, y1, x2, y2, index) {
  815. this.ctx = uni.createCanvasContext('lineCanvas');
  816. this.ctx.beginPath();
  817. let color = this.connectionColor[index]
  818. if (index === -1) {
  819. color = '#000000'
  820. this.ctx.shadowColor = 'red';
  821. // 设置阴影的模糊级别
  822. this.ctx.setshadowBlur = 100;
  823. // 设置阴影的水平偏移
  824. this.ctx.shadowOffsetX = 1;
  825. // 设置阴影的垂直偏移
  826. this.ctx.shadowOffsetY = 1;
  827. } else {
  828. this.ctx.shadowColor = '#000000';
  829. this.ctx.setshadowBlur = 0;
  830. this.ctx.shadowOffsetX = 0;
  831. this.ctx.shadowOffsetY = 0;
  832. }
  833. this.ctx.setStrokeStyle(color)
  834. this.ctx.lineWidth = 3
  835. this.ctx.moveTo(x1, y1); // 开始点
  836. this.ctx.lineTo(x2, y2); // 结束点
  837. this.ctx.stroke(); // 绘制线条
  838. this.ctx.draw(true);
  839. },
  840. // 连线清理
  841. clearRect() {
  842. const canvas = uni.createCanvasContext('lineCanvas');
  843. // 使用clearRect方法清空整个画布
  844. canvas.clearRect(0, 0, 700, 500); // 这里的300x300是画布的宽高,应该与你的实际画布尺寸相匹配
  845. canvas.draw(true); // 调用draw方法将清空操作应用到画布上
  846. },
  847. // 阴影清理
  848. shadowClean() {
  849. for (var i = 0; i < this.connectionHtml.length; i++) {
  850. let option = this.connectionHtml[i]
  851. for (var j = 0; j < option.children.length; j++) {
  852. let ids = "option" + i + "-" + (j + 1)
  853. document.getElementById(ids).style.boxShadow = ''
  854. }
  855. }
  856. },
  857. isLine(id, value) {
  858. for (var i = 0; i < this.connectionContentALL[value].length; i++) {
  859. let option = this.connectionContentALL[value][i]
  860. for (var j = 0; j < option.length; j++) {
  861. let oldId = option[j].id
  862. if (oldId === id) {
  863. return false
  864. }
  865. }
  866. }
  867. return true
  868. },
  869. // 连线题画内容
  870. drawLineWriteContent() {
  871. for (var i = 0; i < this.connectionHtml.length; i++) {
  872. let option = this.connectionHtml[i]
  873. for (var j = 0; j < option.children.length; j++) {
  874. let ids = "option" + i + "-" + (j + 1)
  875. document.getElementById(ids).innerHTML = option.children[j].innerHTML
  876. }
  877. }
  878. }, // 连线画线
  879. drawLineWrite(value) {
  880. this.clearRect()
  881. if (this.connectionInfo.length >= 2) {
  882. for (var i = 0; i < this.connectionInfo.length - 1; i++) {
  883. let one = this.connectionInfo[i]
  884. let two = this.connectionInfo[i + 1]
  885. // box-shadow: ;
  886. document.getElementById(one.id).style.boxShadow = this.clickColor
  887. document.getElementById(two.id).style.boxShadow = this.clickColor
  888. this.drawLine(one.right, one.top, two.left, two.top, -1)
  889. }
  890. } else if (this.connectionInfo.length === 1) {
  891. document.getElementById(this.connectionInfo[0].id).style.boxShadow = this.clickColor
  892. }
  893. for (var i = 0; i < this.connectionContentALL[value].length; i++) {
  894. let option = this.connectionContentALL[value][i]
  895. for (var j = 0; j < option.length - 1; j++) {
  896. let one = option[j]
  897. let two = option[j + 1]
  898. document.getElementById(one.id).style.boxShadow = '0px 0px 5px 2px ' + this.connectionColor[i]
  899. document.getElementById(two.id).style.boxShadow = '0px 0px 5px 2px ' + this.connectionColor[i]
  900. this.drawLine(one.right, one.top, two.left, two.top, i)
  901. }
  902. }
  903. },
  904. // 字符转换html对象
  905. stringToHTML(str) {
  906. var dom = document.createElement('div');
  907. dom.innerHTML = str;
  908. return dom;
  909. },
  910. // 拖动位置固定
  911. tap(index, subX, subY) {
  912. let x = subX
  913. let y = subY
  914. this.drag[this.scantron.sort].option[index].x = this.drag[this.scantron.sort].option[index].old.x
  915. this.drag[this.scantron.sort].option[index].y = this.drag[this.scantron.sort].option[index].old.y
  916. this.$nextTick(function() {
  917. this.drag[this.scantron.sort].option[index].x = x
  918. this.drag[this.scantron.sort].option[index].y = y
  919. })
  920. },
  921. // 鼠标按下
  922. onMousedown(item) {
  923. console.log(this.drag[this.scantron.sort].option.length);
  924. this.dragItem = item;
  925. },
  926. // 拖动监听
  927. onChange: function(e) {
  928. if (!this.disabledDrag) {
  929. return
  930. }
  931. let index = -1
  932. for (var j = 0; j < this.drag[this.scantron.sort].option.length; j++) {
  933. let option = this.drag[this.scantron.sort].option[j]
  934. if (option.id === this.dragItem.id) {
  935. index = j
  936. break;
  937. }
  938. }
  939. this.drag[this.scantron.sort].option[index].old.x = e.detail.x
  940. this.drag[this.scantron.sort].option[index].old.y = e.detail.y
  941. let asda = (event) => {
  942. document.removeEventListener('mouseup', asda)
  943. this.disabledDrag = false
  944. let dragOne;
  945. let bxs = true
  946. // 处理鼠标抬起事件
  947. for (var i = 0; i < this.drag[this.scantron.sort].answer.length; i++) {
  948. let drag = this.drag[this.scantron.sort].answer[i]
  949. let x = drag.x
  950. let y = drag.y
  951. if (
  952. (Number(this.drag[this.scantron.sort].option[index].old.x) <= (Number(drag.x) + Number(
  953. drag
  954. .width))) &&
  955. (Number(this.drag[this.scantron.sort].option[index].old.x) + Number(this.drag[this
  956. .scantron.sort].option[index]
  957. .width)) >= drag.x &&
  958. (Number(this.drag[this.scantron.sort].option[index].old.y) <= (Number(drag.y) + Number(
  959. drag
  960. .height))) &&
  961. (Number(this.drag[this.scantron.sort].option[index].old.y) + Number(this.drag[this
  962. .scantron.sort].option[index]
  963. .height)) >= drag.y
  964. ) {
  965. for (var p = 0; p < this.drag[this.scantron.sort].answer.length; p++) {
  966. if (this.drag[this.scantron.sort].answer[p].op !== undefined && this.drag[this
  967. .scantron.sort].answer[p].op === index) {
  968. this.drag[this.scantron.sort].answer[p].op = undefined
  969. }
  970. }
  971. if (this.drag[this.scantron.sort].answer[i].op !== undefined) {
  972. this.tap(this.drag[this.scantron.sort].answer[i].op, this.drag[this.scantron.sort]
  973. .option[this.drag[this.scantron.sort].answer[i].op].old.ax, this.drag[this
  974. .scantron.sort]
  975. .option[this.drag[this.scantron.sort].answer[i].op].old.by);
  976. this.drag[this.scantron.sort].answer[i].op = index
  977. } else {
  978. this.drag[this.scantron.sort].answer[i].op = index
  979. }
  980. this.tap(index, x, y);
  981. dragOne = drag
  982. bxs = false
  983. break;
  984. }
  985. }
  986. // console.log(this.drag[this.scantron.sort].option[index]);
  987. if (bxs) {
  988. this.tap(index, this.drag[this.scantron.sort].option[index].old.ax, this.drag[this.scantron
  989. .sort].option[index].old.by);
  990. }
  991. setTimeout(() => {
  992. if (dragOne !== undefined) {
  993. this.radioAdd(this.dragItem, dragOne.id.replace("answer", ""), this.scantron)
  994. }
  995. this.disabledDrag = true
  996. }, 700)
  997. }
  998. // if (this.drag[this.scantron.sort].option[index].b) {
  999. // this.drag[this.scantron.sort].option[index].b = false
  1000. document.addEventListener('mouseup', asda);
  1001. // }
  1002. },
  1003. //缓存答案读取
  1004. answerDisplay(data) {
  1005. this.windowCheat = Number(data.leaveTime)
  1006. this.userExamAnswers = data.examAnswers
  1007. let examAnswers = data.examAnswers
  1008. for (var i = 0; i < examAnswers.length; i++) {
  1009. let scantron = examAnswers[i]
  1010. let index = Number(scantron.index)
  1011. if (scantron.index.includes('.')) {
  1012. let parentIndex = Number(scantron.index.split('.')[0])
  1013. let childIndex = scantron.index.split('.')[1]
  1014. let childSubject = this.examObject.userExamQuestionList[parentIndex - 1].subQuestionList[
  1015. childIndex]
  1016. console.log(childSubject);
  1017. } else if (scantron.questionType === 1 || scantron.questionType === 3) {
  1018. console.log(this.examObject.userExamQuestionList[index - 1]);
  1019. this.examObject.userExamQuestionList[index - 1].question.isAnswer = true
  1020. this.examObject.userExamQuestionList[index - 1].question.answerList[Number(scantron.answerIndex[
  1021. 0])]
  1022. .isRight = true
  1023. } else if (scantron.questionType === 2) {
  1024. this.examObject.userExamQuestionList[index - 1].question.isAnswer = true
  1025. for (var j = 0; j < scantron.answerIndex.length; j++) {
  1026. this.examObject.userExamQuestionList[index - 1].question.answerList[Number(scantron
  1027. .answerIndex[j])].isRight = true
  1028. }
  1029. } else if (scantron.questionType === 4) {
  1030. this.examObject.userExamQuestionList[index - 1].question.isAnswer = true
  1031. this.examObject.userExamQuestionList[index - 1].question.subjectiveAnswer = scantron
  1032. .subjectiveAnswer
  1033. } else if (scantron.questionType === 5) {
  1034. this.examObject.userExamQuestionList[index - 1].question.isAnswer = true
  1035. let blankAnswer = JSON.parse(scantron.blankAnswer)
  1036. for (var k = 0; k < blankAnswer.length; k++) {
  1037. for (var j = 0; j < this.examObject.userExamQuestionList[index - 1].question.answerList
  1038. .length; j++) {
  1039. if (this.examObject.userExamQuestionList[index - 1].question.answerList[j].tag ===
  1040. blankAnswer[k].tag) {
  1041. this.examObject.userExamQuestionList[index - 1].question.answerList[j].blankcontent =
  1042. blankAnswer[k].content
  1043. }
  1044. }
  1045. }
  1046. } else if (scantron.questionType === 7) {
  1047. this.examObject.userExamQuestionList[index - 1].question.isAnswer = true
  1048. let blankAnswer = JSON.parse(scantron.blankAnswer)
  1049. for (var k = 0; k < blankAnswer.length; k++) {
  1050. for (var j = 0; j < this.examObject.userExamQuestionList[index - 1].question.answerList
  1051. .length; j++) {
  1052. if (this.examObject.userExamQuestionList[index - 1].question.answerList[j].tag ===
  1053. blankAnswer[k].tag) {
  1054. this.examObject.userExamQuestionList[index - 1].question.answerList[j].blankcontent =
  1055. blankAnswer[k].content
  1056. }
  1057. }
  1058. }
  1059. this.drag[index] = JSON.parse(scantron.coordinates)
  1060. } else if (scantron.questionType === 8) {
  1061. console.log(scantron);
  1062. this.examObject.userExamQuestionList[index - 1].question.isAnswer = true
  1063. let blankAnswer = JSON.parse(scantron.blankAnswer)
  1064. for (var k = 0; k < blankAnswer.length; k++) {
  1065. for (var j = 0; j < this.examObject.userExamQuestionList[index - 1].question.answerList
  1066. .length; j++) {
  1067. if (this.examObject.userExamQuestionList[index - 1].question.answerList[j].tag ===
  1068. blankAnswer[k].tag) {
  1069. this.examObject.userExamQuestionList[index - 1].question.answerList[j].blankcontent =
  1070. blankAnswer[k].content
  1071. }
  1072. }
  1073. }
  1074. this.connectionContentALL[index] = JSON.parse(scantron.coordinates)
  1075. }
  1076. }
  1077. },
  1078. // 题目做答
  1079. radioAdd(value, index, scantron, combinationItem) {
  1080. index = index + ''
  1081. let qIndex = scantron.questionIndex + ""
  1082. let arr = []
  1083. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer = true
  1084. if (scantron.questionType === 1 || scantron.questionType === 3) {
  1085. for (var i = 0; i < scantron.question.answerList.length; i++) {
  1086. scantron.question.answerList[i].isRight = false
  1087. }
  1088. scantron.question.answerList[index].isRight = true
  1089. for (var i = 0; i < this.userExamAnswers.length; i++) {
  1090. if (this.userExamAnswers[i].index !== qIndex) {
  1091. arr.push(this.userExamAnswers[i])
  1092. }
  1093. }
  1094. arr.push({
  1095. answerIndex: [index],
  1096. answers: [value.id],
  1097. index: qIndex,
  1098. questionType: scantron.questionType
  1099. })
  1100. } else if (scantron.questionType === 2) {
  1101. let b = true
  1102. for (var i = 0; i < this.userExamAnswers.length; i++) {
  1103. if (this.userExamAnswers[i].index !== qIndex) {
  1104. arr.push(this.userExamAnswers[i])
  1105. } else {
  1106. b = false
  1107. let bc = true
  1108. let arrAnswer = []
  1109. let arrAnswerId = []
  1110. let num = this.userExamAnswers[i].answers.length;
  1111. for (var j = 0; j < num; j++) {
  1112. if (this.userExamAnswers[i].answerIndex[j] !== index) {
  1113. arrAnswer.push(this.userExamAnswers[i].answerIndex[j])
  1114. arrAnswerId.push(this.userExamAnswers[i].answers[j])
  1115. } else {
  1116. if (!value.isRight) {
  1117. bc = false
  1118. }
  1119. }
  1120. }
  1121. if (bc) {
  1122. arrAnswer.push(index)
  1123. arrAnswerId.push(value.id)
  1124. }
  1125. if (arrAnswer.length !== 0) {
  1126. arr.push({
  1127. answerIndex: arrAnswer,
  1128. answers: arrAnswerId,
  1129. index: qIndex,
  1130. questionType: scantron.questionType
  1131. })
  1132. } else {
  1133. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer = false
  1134. }
  1135. }
  1136. }
  1137. if (b) {
  1138. arr.push({
  1139. answerIndex: [index],
  1140. answers: [value.id],
  1141. index: qIndex,
  1142. questionType: scantron.questionType
  1143. })
  1144. }
  1145. } else if (scantron.questionType === 4) {
  1146. for (var i = 0; i < this.userExamAnswers.length; i++) {
  1147. if (this.userExamAnswers[i].index !== qIndex) {
  1148. arr.push(this.userExamAnswers[i])
  1149. }
  1150. }
  1151. if (scantron.question.subjectiveAnswer === null || scantron.question.subjectiveAnswer === "") {
  1152. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer = false
  1153. }
  1154. arr.push({
  1155. subjectiveAnswer: scantron.question.subjectiveAnswer,
  1156. index: qIndex,
  1157. questionType: scantron.questionType
  1158. })
  1159. } else if (scantron.questionType === 5) {
  1160. if (value === undefined) {
  1161. return
  1162. }
  1163. let b = true
  1164. for (var i = 0; i < this.userExamAnswers.length; i++) {
  1165. if (this.userExamAnswers[i].index !== qIndex) {
  1166. arr.push(this.userExamAnswers[i])
  1167. } else {
  1168. b = false
  1169. let bc = true
  1170. let arrAnswer = []
  1171. let blankAnswer = JSON.parse(this.userExamAnswers[i].blankAnswer)
  1172. let num = blankAnswer.length;
  1173. for (var j = 0; j < num; j++) {
  1174. if (blankAnswer[j].tag !== index) {
  1175. arrAnswer.push({
  1176. tag: blankAnswer[j].tag,
  1177. content: blankAnswer[j].content
  1178. })
  1179. } else {
  1180. bc = false
  1181. }
  1182. }
  1183. if (bc) {
  1184. arrAnswer.push({
  1185. tag: index,
  1186. content: value
  1187. })
  1188. }
  1189. if (arrAnswer.length !== 0) {
  1190. arr.push({
  1191. blankAnswer: JSON.stringify(arrAnswer),
  1192. index: qIndex,
  1193. questionType: scantron.questionType
  1194. })
  1195. } else {
  1196. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer = false
  1197. }
  1198. }
  1199. }
  1200. if (b) {
  1201. if (value === null || value === "") {
  1202. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer = false
  1203. }
  1204. arr.push({
  1205. blankAnswer: JSON.stringify([{
  1206. tag: index,
  1207. content: value
  1208. }]),
  1209. index: qIndex,
  1210. questionType: scantron.questionType
  1211. })
  1212. }
  1213. } else if (scantron.questionType === 6) {
  1214. qIndex = qIndex + "." + combinationItem.sort
  1215. if (combinationItem.questionType === 1 || combinationItem.questionType ===
  1216. 3) {
  1217. for (var j = 0; j < combinationItem.question.answerList.length; j++) {
  1218. combinationItem.question.answerList[j].isRight = false
  1219. }
  1220. combinationItem.question.answerList[index].isRight = true
  1221. for (var j = 0; j < this.userExamAnswers.length; j++) {
  1222. if (this.userExamAnswers[j].index !== qIndex) {
  1223. arr.push(this.userExamAnswers[j])
  1224. }
  1225. }
  1226. arr.push({
  1227. answerIndex: [index],
  1228. answers: [value.id],
  1229. index: qIndex,
  1230. questionType: combinationItem.questionType
  1231. })
  1232. } else if (combinationItem.questionType === 2) {
  1233. let b = true
  1234. for (var j = 0; j < this.userExamAnswers.length; j++) {
  1235. if (this.userExamAnswers[j].index !== qIndex) {
  1236. arr.push(this.userExamAnswers[j])
  1237. } else {
  1238. b = false
  1239. let bca = true
  1240. let arrAnswer = []
  1241. let arrAnswerId = []
  1242. let num = this.userExamAnswers[j].answers.length;
  1243. for (var k = 0; k < num; k++) {
  1244. if (this.userExamAnswers[j].answerIndex[k] !== index) {
  1245. arrAnswer.push(this.userExamAnswers[j].answerIndex[k])
  1246. arrAnswerId.push(this.userExamAnswers[j].answers[k])
  1247. } else {
  1248. if (!value.isRight) {
  1249. bca = false
  1250. }
  1251. }
  1252. }
  1253. if (bca) {
  1254. arrAnswer.push(index)
  1255. arrAnswerId.push(value.id)
  1256. }
  1257. if (arrAnswer.length !== 0) {
  1258. arr.push({
  1259. answerIndex: arrAnswer,
  1260. answers: arrAnswerId,
  1261. index: qIndex,
  1262. questionType: combinationItem.questionType
  1263. })
  1264. } else {
  1265. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question
  1266. .isAnswer =
  1267. false
  1268. }
  1269. }
  1270. }
  1271. if (b) {
  1272. arr.push({
  1273. answerIndex: [index],
  1274. answers: [value.id],
  1275. index: qIndex,
  1276. questionType: combinationItem.questionType
  1277. })
  1278. }
  1279. } else if (combinationItem.questionType === 4) {
  1280. for (var j = 0; j < this.userExamAnswers.length; j++) {
  1281. if (this.userExamAnswers[j].index !== qIndex) {
  1282. arr.push(this.userExamAnswers[j])
  1283. }
  1284. }
  1285. if (combinationItem.question.subjectiveAnswer === null || scantron.subQuestionList[
  1286. i].question.subjectiveAnswer === "") {
  1287. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer = false
  1288. }
  1289. arr.push({
  1290. subjectiveAnswer: combinationItem.question.subjectiveAnswer,
  1291. index: qIndex,
  1292. questionType: combinationItem.questionType
  1293. })
  1294. } else if (combinationItem.questionType === 5) {
  1295. if (value === undefined) {
  1296. return
  1297. }
  1298. let b = true
  1299. for (var j = 0; j < this.userExamAnswers.length; j++) {
  1300. if (this.userExamAnswers[j].index !== qIndex) {
  1301. arr.push(this.userExamAnswers[j])
  1302. } else {
  1303. b = false
  1304. let bc = true
  1305. let arrAnswer = []
  1306. let blankAnswer = JSON.parse(this.userExamAnswers[j].blankAnswer)
  1307. let num = blankAnswer.length;
  1308. for (var q = 0; q < num; q++) {
  1309. if (blankAnswer[q].tag !== index) {
  1310. arrAnswer.push({
  1311. tag: blankAnswer[q].tag,
  1312. content: blankAnswer[q].content
  1313. })
  1314. } else {
  1315. bc = false
  1316. }
  1317. }
  1318. if (bc) {
  1319. arrAnswer.push({
  1320. tag: index,
  1321. content: value
  1322. })
  1323. }
  1324. if (arrAnswer.length !== 0) {
  1325. arr.push({
  1326. blankAnswer: JSON.stringify(arrAnswer),
  1327. index: qIndex,
  1328. questionType: scantron.subQuestionList[i].questionType
  1329. })
  1330. } else {
  1331. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question
  1332. .isAnswer = false
  1333. }
  1334. }
  1335. }
  1336. if (b) {
  1337. if (value === null || value === "") {
  1338. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer = false
  1339. }
  1340. console.log(qIndex);
  1341. console.log(scantron);
  1342. console.log(this.examObject.userExamQuestionList[scantron.questionIndex - 1].subQuestionList[
  1343. Number(combinationItem.sort)]);
  1344. arr.push({
  1345. blankAnswer: JSON.stringify([{
  1346. tag: index,
  1347. content: value
  1348. }]),
  1349. index: qIndex,
  1350. questionType: scantron.subQuestionList[i].questionType
  1351. })
  1352. }
  1353. }
  1354. } else if (scantron.questionType === 7) {
  1355. if (value === undefined) {
  1356. return
  1357. }
  1358. index = (Number(index) + 1) + ""
  1359. let b = true
  1360. for (var i = 0; i < this.userExamAnswers.length; i++) {
  1361. if (this.userExamAnswers[i].index !== qIndex) {
  1362. arr.push(this.userExamAnswers[i])
  1363. } else {
  1364. b = false
  1365. let bc = true
  1366. let arrAnswer = []
  1367. let blankAnswer = JSON.parse(this.userExamAnswers[i].blankAnswer)
  1368. let num = blankAnswer.length;
  1369. for (var j = 0; j < num; j++) {
  1370. if (blankAnswer[j].tag !== index) {
  1371. arrAnswer.push({
  1372. tag: blankAnswer[j].tag,
  1373. content: blankAnswer[j].content
  1374. })
  1375. } else {
  1376. arrAnswer.push({
  1377. tag: index,
  1378. content: value.id
  1379. })
  1380. bc = false
  1381. }
  1382. }
  1383. if (bc) {
  1384. arrAnswer.push({
  1385. tag: index,
  1386. content: value.id
  1387. })
  1388. }
  1389. if (arrAnswer.length !== 0) {
  1390. arr.push({
  1391. blankAnswer: JSON.stringify(arrAnswer),
  1392. coordinates: JSON.stringify(this.drag[qIndex]),
  1393. index: qIndex,
  1394. questionType: scantron.questionType
  1395. })
  1396. } else {
  1397. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer = false
  1398. }
  1399. }
  1400. }
  1401. if (b) {
  1402. if (value === null || value === "") {
  1403. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer = false
  1404. }
  1405. arr.push({
  1406. blankAnswer: JSON.stringify([{
  1407. tag: index,
  1408. content: value.id
  1409. }]),
  1410. coordinates: JSON.stringify(this.drag[qIndex]),
  1411. index: qIndex,
  1412. questionType: scantron.questionType
  1413. })
  1414. }
  1415. } else if (scantron.questionType === 8) {
  1416. console.log(this.connectionContentALL[qIndex]);
  1417. let info = value
  1418. value = ""
  1419. for (var i = 0; i < info.length; i++) {
  1420. console.log(info);
  1421. value += info[i].id.replace('option', '').split('-')[1]
  1422. }
  1423. // connectingCoordinates
  1424. if (value === undefined) {
  1425. return
  1426. }
  1427. let b = true
  1428. for (var j = 0; j < this.userExamAnswers.length; j++) {
  1429. if (this.userExamAnswers[j].index !== qIndex) {
  1430. arr.push(this.userExamAnswers[j])
  1431. } else {
  1432. b = false
  1433. let bc = true
  1434. let arrAnswer = []
  1435. let blankAnswer = JSON.parse(this.userExamAnswers[j].blankAnswer)
  1436. let num = blankAnswer.length;
  1437. for (var q = 0; q < num; q++) {
  1438. if (blankAnswer[q].tag !== index) {
  1439. arrAnswer.push({
  1440. tag: blankAnswer[q].tag,
  1441. content: blankAnswer[q].content
  1442. })
  1443. } else {
  1444. bc = false
  1445. }
  1446. }
  1447. if (bc) {
  1448. arrAnswer.push({
  1449. tag: index,
  1450. content: value
  1451. })
  1452. }
  1453. if (arrAnswer.length !== 0) {
  1454. arr.push({
  1455. blankAnswer: JSON.stringify(arrAnswer),
  1456. index: qIndex,
  1457. coordinates: JSON.stringify(this.connectionContentALL[qIndex]),
  1458. questionType: scantron.questionType
  1459. })
  1460. } else {
  1461. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question
  1462. .isAnswer =
  1463. false
  1464. }
  1465. }
  1466. }
  1467. if (b) {
  1468. if (value === null || value === "") {
  1469. this.examObject.userExamQuestionList[scantron.questionIndex - 1].question.isAnswer =
  1470. false
  1471. }
  1472. arr.push({
  1473. blankAnswer: JSON.stringify([{
  1474. tag: index,
  1475. content: value
  1476. }]),
  1477. coordinates: JSON.stringify(this.connectionContentALL[qIndex]),
  1478. index: qIndex,
  1479. questionType: scantron.questionType
  1480. })
  1481. }
  1482. }
  1483. this.userExamAnswers = arr
  1484. },
  1485. // 失去焦点时的处理函数
  1486. handleBlur(v) {
  1487. if (this.examObject.leaveOn) {
  1488. if (this.windowCheat < 2 && v !== 0) {
  1489. this.$refs.cheat.open()
  1490. }
  1491. let leaveCount = this.examObject.totalLeaveTimes
  1492. let leaveTime = this.examObject.leaveTime
  1493. if (this.windowCheat < leaveCount) {
  1494. this.cheat = setInterval(() => {
  1495. console.log("切屏加一");
  1496. this.windowCheat++
  1497. cacheExamAnswer({
  1498. 'examAnswers': this.userExamAnswers,
  1499. 'userExamId': sessionStorage.getItem('examId'),
  1500. 'leaveTime': this.windowCheat,
  1501. 'paperId': this.userExamPaper.paperId,
  1502. 'limitTime': this.userExamPaper.limitTime
  1503. })
  1504. clearInterval(this.cheat)
  1505. }, leaveTime * 1000)
  1506. } else {
  1507. this.submitExam('cheat')
  1508. }
  1509. console.log(this.windowCheat);
  1510. }
  1511. },
  1512. // 获得焦点时的处理函数
  1513. handleFocus() {
  1514. if (this.examObject.leaveOn) {
  1515. clearInterval(this.cheat)
  1516. }
  1517. },
  1518. // 时间
  1519. addExamPaperTime(systemTime, endTime) {
  1520. return (endTime.getTime() - systemTime.getTime()) / 1000
  1521. },
  1522. // 更新倒计时函数
  1523. updateCountDown() {
  1524. var distance = this.examPaperTime;
  1525. this.examPaperTime = this.examPaperTime - 1
  1526. if (distance < 0) {
  1527. clearInterval(this.intervalId);
  1528. console.log(0);
  1529. this.messageToggle('warn', "时间已到,2秒后为您自动交卷")
  1530. setTimeout(() => {
  1531. this.submitExam(0)
  1532. }, 2000)
  1533. return;
  1534. }
  1535. // 计算时分秒
  1536. var seconds = Math.floor((distance % (60)));
  1537. var minutes = Math.floor((distance % (60 * 60)) / (60));
  1538. var hours = Math.floor(distance / (60 * 60));
  1539. if (hours != 0) {
  1540. this.paperTime = hours + ":" + (minutes.toString().length == 2 ? minutes : '0' + minutes) + ":" + (
  1541. seconds.toString().length == 2 ? seconds : '0' + seconds)
  1542. } else {
  1543. this.paperTime = (minutes.toString().length == 2 ? minutes : '0' + minutes) + ":" + (seconds.toString()
  1544. .length == 2 ? seconds : '0' + seconds)
  1545. }
  1546. let examTime = this.papersTime + distance
  1547. // 计算考試时分秒
  1548. var examTimeseconds = Math.floor((examTime % (60)));
  1549. var examTimeminutes = Math.floor((examTime % (60 * 60)) / (60));
  1550. var examTimehours = Math.floor(examTime / (60 * 60));
  1551. if (examTimehours != 0) {
  1552. this.examTime = examTimehours + ":" + (examTimeminutes.toString().length == 2 ? examTimeminutes : '0' +
  1553. examTimeminutes) + ":" + (
  1554. seconds.toString().length == 2 ? examTimeseconds : '0' + examTimeseconds)
  1555. } else {
  1556. this.examTime = (examTimeminutes.toString().length == 2 ? examTimeminutes : '0' + examTimeminutes) +
  1557. ":" + (examTimeseconds.toString()
  1558. .length == 2 ? examTimeseconds : '0' + examTimeseconds)
  1559. }
  1560. },
  1561. examPapersTime() {
  1562. let list = this.examObject.examPapersList
  1563. let time = 0
  1564. for (var i = 0; i < list.length; i++) {
  1565. if (list[i].paperId !== this.userExamPaper.paperId) {
  1566. if (list[i].state === 9) {
  1567. time += list[i].paperTime * 60
  1568. }
  1569. }
  1570. }
  1571. return time
  1572. }
  1573. },
  1574. mounted() {
  1575. window.addEventListener("unload", (e) => {
  1576. e.preventDefault();
  1577. setTimeout(() => {
  1578. cacheExamAnswer({
  1579. 'examAnswers': this.userExamAnswers,
  1580. 'userExamId': sessionStorage.getItem('examId'),
  1581. 'leaveTime': this.windowCheat,
  1582. 'paperId': this.userExamPaper.paperId,
  1583. 'limitTime': this.userExamPaper.limitTime
  1584. }).then(data => {
  1585. console.log(data);
  1586. })
  1587. }, 100)
  1588. });
  1589. this.user = JSON.parse(sessionStorage.getItem("user"))
  1590. let examId = sessionStorage.getItem('examId')
  1591. getExamDetail({
  1592. 'userExamId': examId,
  1593. 't': new Date().toString()
  1594. }).then(data => {
  1595. if (data.data.code !== 200) {
  1596. sessionStorage.removeItem('examId')
  1597. toLogin()
  1598. }
  1599. this.examObject = data.data.result
  1600. this.scantron = this.examObject.userExamQuestionList[0]
  1601. this.userExamPaper = this.examObject.userExamPapersList[0]
  1602. this.examPaperTime = this.addExamPaperTime(new Date(this.userExamPaper.systemTime), new Date(this
  1603. .userExamPaper.limitTime))
  1604. // 试卷计时
  1605. this.papersTime = this.examPapersTime()
  1606. this.intervalId = setInterval(this.updateCountDown, 1000);
  1607. this.examTime = this.paperTime
  1608. // 添加切屏事件监听
  1609. if (windowState) {
  1610. window.addEventListener('blur', this.handleBlur);
  1611. window.addEventListener('focus', this.handleFocus);
  1612. }
  1613. // 获取缓存答案
  1614. getCacheAnswer({
  1615. 'userExamId': examId
  1616. }).then(answerData => {
  1617. if (answerData.data.result !== null) {
  1618. this.answerDisplay(answerData.data.result)
  1619. }
  1620. })
  1621. })
  1622. }
  1623. }
  1624. </script>
  1625. <style scoped>
  1626. .svg-container {
  1627. width: 100%;
  1628. height: 100%;
  1629. overflow: hidden;
  1630. position: runiative;
  1631. }
  1632. svg {
  1633. display: block;
  1634. width: 100%;
  1635. height: 100%;
  1636. }
  1637. .scroll-Y {
  1638. height: 80vh;
  1639. }
  1640. .allceter {
  1641. display: flex;
  1642. align-items: center;
  1643. height: 50px;
  1644. }
  1645. .scroll-view_H {
  1646. white-space: nowrap;
  1647. width: 100%;
  1648. }
  1649. .scroll-view-item {
  1650. height: 300rpx;
  1651. line-height: 300rpx;
  1652. text-align: center;
  1653. font-size: 36rpx;
  1654. }
  1655. .scroll-view-item_H {
  1656. display: inline-block;
  1657. width: 100%;
  1658. height: 300rpx;
  1659. line-height: 300rpx;
  1660. text-align: center;
  1661. font-size: 36rpx;
  1662. }
  1663. div {
  1664. margin: 0;
  1665. padding: 0;
  1666. }
  1667. /* CSS 预设*/
  1668. * {
  1669. margin: 0;
  1670. padding: 0;
  1671. }
  1672. a {
  1673. text-decoration: none;
  1674. outline: none;
  1675. }
  1676. body a {
  1677. outline: none;
  1678. blr: expression(this.onFocus=this.blur());
  1679. }
  1680. .uni-input {
  1681. padding-left: 20px;
  1682. border: 1rpx solid #5bb4ee;
  1683. height: 96rpx;
  1684. margin-left: 10px;
  1685. color: #000000;
  1686. width: 90%;
  1687. display: flex;
  1688. justify-content: center;
  1689. align-items: center;
  1690. }
  1691. img {
  1692. border: none;
  1693. }
  1694. .dialog-text {
  1695. font-size: 14px;
  1696. color: #333;
  1697. }
  1698. .paperCss {
  1699. width: 85%;
  1700. border-radius: 5px;
  1701. padding: 15px;
  1702. margin-top: 15px;
  1703. font-size: 15px;
  1704. text-align: left;
  1705. }
  1706. </style>