examStart.vue 59 KB

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