examInfo.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <!-- 开始考试 -->
  2. <template>
  3. <view id="examInfo" v-if="pageType">
  4. <view class="time-box">倒计时:{{minute}}:{{second}}</view>
  5. <view class="exam-top-box">
  6. <view class="exam-title-box">{{examIndex+1}}.{{examData.content}}</view>
  7. <radio-group @change="radioChange" class="exam-topic-for" v-if="examList[examIndex].topicType == 'radioList'||examList[examIndex].topicType == 'judgeList'">
  8. <label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in examData.elPaperQuAnswerList" :key="index">
  9. <view class="for-min-box">
  10. <radio :value="item.content" :checked="item.checked" color="#0183FA"/>{{item.abc}}.{{item.content}}
  11. </view>
  12. </label>
  13. </radio-group>
  14. <checkbox-group @change="checkboxChange" class="exam-topic-for" v-if="examList[examIndex].topicType == 'multiList'">
  15. <label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in examData.elPaperQuAnswerList" :key="index">
  16. <view class="for-min-box">
  17. <checkbox :value="item.content" :checked="item.checked" color="#0183FA"/>{{item.abc}}.{{item.content}}
  18. </view>
  19. </label>
  20. </checkbox-group>
  21. <view class="exam-topic-for">
  22. <view class="button-box">
  23. <view class="left-p" v-if="examIndex != 0" @click="topicSwitch(1)">上一题</view>
  24. <view class="right-p" v-if="examIndex < examList.length-1" @click="topicSwitch(2)">下一题</view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="exam-bottom-box" @click.stop="shadeClick">
  29. <view class="button-box" @click.stop="upDataButton('交卷成功')">交卷</view>
  30. <view class="null-view"></view>
  31. <img src="@/images/icon_09.png">
  32. <view class="num-box">
  33. <view>{{topicNum}}</view>
  34. <view>/{{maxTopicNum}}</view>
  35. </view>
  36. </view>
  37. <view class="shade-max-box" v-if="shadeType">
  38. <view class="null-box" @click.stop="shadeClick"></view>
  39. <view class="shade-big-box">
  40. <view class="shade-big-box">
  41. <view class="shade-top-box">
  42. <view class="button-box" @click="upDataButton('交卷成功')">交卷</view>
  43. <view class="null-view"></view>
  44. <img src="@/images/icon_09.png">
  45. <view class="num-box">
  46. <view>{{topicNum}}</view>
  47. <view>/{{maxTopicNum}}</view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="for-max-box">
  53. <view class="for-box" @click="topicClick(index)"
  54. :class="index == examIndex?'colorB':(item.answerType == 1?'colorA':'')"
  55. v-for="(item,index) in examList" :key="index">{{index+1}}</view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import { getPaper,paperDetail,fillAnswer,handPaper } from '@/api/index.js'
  62. export default {
  63. data() {
  64. return {
  65. //时间数据
  66. timer:{},
  67. //接收参数
  68. itemData:{},
  69. //分
  70. minute:"",
  71. //秒
  72. second:"",
  73. //当前选中
  74. examIndex:0,
  75. //遮罩层开关
  76. shadeType:false,
  77. //最大提数
  78. maxTopicNum:0,
  79. //当前做过的题
  80. topicNum:0,
  81. //答题卡
  82. examList:[],
  83. //当前答题
  84. examData:{},
  85. //违规考试
  86. violationId:"",
  87. //页面开关/加载完毕后开启
  88. pageType:false,
  89. }
  90. },
  91. onLoad(option) {
  92. console.log("option",option)
  93. this.itemData = JSON.parse(decodeURIComponent(option.item));
  94. //修改页面title
  95. uni.setNavigationBarTitle({
  96. title:this.itemData.title
  97. });
  98. this.time(this.itemData.totalTime);
  99. this.getPaper();
  100. if(option.violationId){
  101. this.violationId = option.violationId;
  102. }
  103. },
  104. methods: {
  105. //定时器
  106. time(num){
  107. let self = this;
  108. let time = num * 60;
  109. this.timer = setInterval(refreshCount, 1000);
  110. function refreshCount() {
  111. if(time<=0){
  112. clearInterval(this.timer);
  113. self.upDataButton('考试时间结束,交卷成功');
  114. }else{
  115. time--;
  116. self.minute = parseInt(time/60);
  117. self.second = time%60;
  118. }
  119. }
  120. },
  121. //交卷按钮
  122. upDataButton(text){
  123. let self = this;
  124. let list = [];
  125. for(let i=0;i<self.examData.elPaperQuAnswerList.length;i++){
  126. if(self.examData.elPaperQuAnswerList[i].checked == 1){
  127. list.push(self.examData.elPaperQuAnswerList[i]);
  128. }
  129. }
  130. if(list[0]){
  131. this.fillAnswer(list).then(res => {
  132. this.handPaper(text);
  133. });
  134. }else{
  135. this.handPaper(text);
  136. }
  137. },
  138. //交卷
  139. async handPaper(text){
  140. let obj = {};
  141. if(this.violationId){
  142. obj.violationId = this.violationId;
  143. }
  144. const {data} = await handPaper(this.itemData.newPaperId,obj);
  145. if(data.code == 200){
  146. uni.showToast({
  147. title: text,
  148. icon:"none",
  149. mask:true,
  150. duration: 2000
  151. });
  152. setTimeout(function(){
  153. uni.navigateBack();
  154. },2000);
  155. }
  156. },
  157. //单选事件
  158. radioChange(e){
  159. let self = this;
  160. console.log("单选",e)
  161. this.examList[this.examIndex].answerType = '1';
  162. for(let i=0;i<self.examData.elPaperQuAnswerList.length;i++){
  163. if(e.detail.value == self.examData.elPaperQuAnswerList[i].content){
  164. self.examData.elPaperQuAnswerList[i].checked = 1
  165. }else{
  166. self.examData.elPaperQuAnswerList[i].checked = 0
  167. }
  168. }
  169. },
  170. //多选事件
  171. checkboxChange(e){
  172. let self = this;
  173. console.log("多选",e)
  174. this.examList[this.examIndex].answerType = '1';
  175. for(let i=0;i<self.examData.elPaperQuAnswerList.length;i++){
  176. let num = 0;
  177. for(let o=0;o<e.detail.value.length;o++){
  178. if(e.detail.value[o] == self.examData.elPaperQuAnswerList[i].content){
  179. num ++
  180. }
  181. }
  182. if(num>0){
  183. self.examData.elPaperQuAnswerList[i].checked = 1
  184. }else{
  185. self.examData.elPaperQuAnswerList[i].checked = 0
  186. }
  187. }
  188. },
  189. //提交答案
  190. async fillAnswer(list){
  191. let self = this;
  192. let obj ={
  193. answer: "",
  194. elPaperQuAnswerList: list,
  195. paperId:this.examData.paperId,
  196. quId:this.examData.quId,
  197. }
  198. const {data} = await fillAnswer(obj);
  199. return data
  200. },
  201. //获取答题卡
  202. async getPaper(){
  203. let self = this;
  204. const {data} = await getPaper(this.itemData.newPaperId);
  205. if(data.code == 200){
  206. let list = [];
  207. //单选题
  208. if(data.data.radioList){
  209. for(let i=0;i<data.data.radioList.length;i++){
  210. data.data.radioList[i].topicType = 'radioList'
  211. data.data.radioList[i].answerType = '0'
  212. list.push(data.data.radioList[i])
  213. }
  214. }
  215. //多选题
  216. if(data.data.multiList){
  217. for(let i=0;i<data.data.multiList.length;i++){
  218. data.data.multiList[i].topicType = 'multiList'
  219. data.data.multiList[i].answerType = '0'
  220. list.push(data.data.multiList[i])
  221. }
  222. }
  223. //判断题
  224. if(data.data.judgeList){
  225. for(let i=0;i<data.data.judgeList.length;i++){
  226. data.data.judgeList[i].topicType = 'judgeList'
  227. data.data.judgeList[i].answerType = '0'
  228. list.push(data.data.judgeList[i])
  229. }
  230. }
  231. this.maxTopicNum = list.length;
  232. this.examList = list;
  233. this.paperDetail(list[0]).then(response => {
  234. this.pageType = true;
  235. });
  236. }
  237. },
  238. //获取题目
  239. async paperDetail(item){
  240. let self = this;
  241. let obj ={
  242. paperId:item.paperId,
  243. quId:item.quId,
  244. };
  245. const {data} = await paperDetail(obj);
  246. if(data.code == 200){
  247. this.examData = data.data;
  248. }
  249. },
  250. //计算已做数量
  251. calculateTheNumber(){
  252. let self = this;
  253. let num = 0;
  254. for(let i=0;i<self.examList.length;i++){
  255. if(self.examList[i].answerType == '1'){
  256. num++
  257. }
  258. }
  259. this.topicNum = num;
  260. },
  261. //上一题/下一题
  262. topicSwitch(type){
  263. let self = this;
  264. if(type==1){
  265. if(this.examIndex>0){
  266. let list = [];
  267. for(let i=0;i<self.examData.elPaperQuAnswerList.length;i++){
  268. if(self.examData.elPaperQuAnswerList[i].checked == 1){
  269. list.push(self.examData.elPaperQuAnswerList[i]);
  270. }
  271. }
  272. if(list[0]){
  273. this.fillAnswer(list).then(res => {
  274. this.examIndex--;
  275. this.paperDetail(this.examList[this.examIndex]);
  276. });
  277. }else{
  278. this.examIndex--;
  279. this.paperDetail(this.examList[this.examIndex]);
  280. }
  281. }
  282. }else if(type==2){
  283. if(this.examIndex<this.examList.length-1){
  284. let list = [];
  285. for(let i=0;i<self.examData.elPaperQuAnswerList.length;i++){
  286. if(self.examData.elPaperQuAnswerList[i].checked == 1){
  287. list.push(self.examData.elPaperQuAnswerList[i]);
  288. }
  289. }
  290. if(list[0]){
  291. this.fillAnswer(list).then(res => {
  292. this.examIndex++;
  293. this.paperDetail(this.examList[this.examIndex]);
  294. });
  295. }else{
  296. this.examIndex++;
  297. this.paperDetail(this.examList[this.examIndex]);
  298. }
  299. }
  300. }
  301. this.calculateTheNumber();
  302. },
  303. //题目点击切换
  304. topicClick(index){
  305. let self = this;
  306. if(this.examIndex != index){
  307. let list = [];
  308. for(let i=0;i<self.examData.elPaperQuAnswerList.length;i++){
  309. if(self.examData.elPaperQuAnswerList[i].checked == 1){
  310. list.push(self.examData.elPaperQuAnswerList[i]);
  311. }
  312. }
  313. if(list[0]){
  314. this.fillAnswer(list).then(res => {
  315. this.examIndex = index;
  316. this.paperDetail(this.examList[this.examIndex]);
  317. });
  318. }else{
  319. this.examIndex = index;
  320. this.paperDetail(this.examList[this.examIndex]);
  321. }
  322. }
  323. this.calculateTheNumber();
  324. },
  325. //遮罩开关
  326. shadeClick(){
  327. this.shadeType = !this.shadeType;
  328. },
  329. },
  330. beforeDestroy() {
  331. //清除定时器
  332. clearInterval(this.timer);
  333. console.log("beforeDestroy");
  334. },
  335. }
  336. </script>
  337. <style lang="stylus" scoped>
  338. #examInfo{
  339. height:100%;
  340. width:100%;
  341. display flex
  342. flex-direction column
  343. .time-box{
  344. line-height:80rpx;
  345. text-align center
  346. border-bottom:1rpx solid #e0e0e0;
  347. background #fff
  348. font-size:26rpx;
  349. }
  350. .exam-top-box{
  351. flex:1;
  352. .exam-title-box{
  353. line-height:85rpx;
  354. padding:0 20rpx;
  355. font-size:30rpx;
  356. color:#333;
  357. background #fff
  358. }
  359. .exam-topic-for{
  360. background #fff
  361. .for-min-box{
  362. margin:0 30rpx;
  363. padding:25rpx 0;
  364. line-height:28rpx;
  365. font-size:28rpx;
  366. color:#666666;
  367. }
  368. .for-color-type{
  369. color:#0183FA;
  370. }
  371. .button-box{
  372. position:relative;
  373. height:180rpx;
  374. .left-p{
  375. width: 180rpx;
  376. line-height: 80rpx;
  377. background: #FFFFFF;
  378. border: 2rpx solid #E0E0E0;
  379. border-radius: 10rpx;
  380. font-size:22rpx;
  381. color: #666666;
  382. text-align center;
  383. // margin:0 44rpx 0 0;
  384. position absolute;
  385. top:50rpx;
  386. left:172rpx;
  387. }
  388. .right-p{
  389. width: 180rpx;
  390. height: 80rpx;
  391. line-height: 80rpx;
  392. border: 2rpx solid #0183FA;
  393. background: #0183FA;
  394. border-radius: 10rpx;
  395. font-size:22rpx;
  396. color: #fff;
  397. text-align center;
  398. position absolute;
  399. top:50rpx;
  400. left:396rpx;
  401. }
  402. }
  403. }
  404. }
  405. .exam-bottom-box{
  406. height:100rpx;
  407. display flex
  408. background #fff
  409. .button-box{
  410. width:130rpx;
  411. line-height:60rpx;
  412. color:#fff;
  413. background :#0183FA;
  414. margin:20rpx 0 20rpx 20rpx;
  415. border-radius: 30rpx;
  416. text-align center
  417. }
  418. .null-view{
  419. flex:1;
  420. }
  421. img{
  422. width:30rpx;
  423. height:30rpx;
  424. margin:35rpx 15rpx 35rpx 0;
  425. }
  426. .num-box{
  427. display flex
  428. margin-right:20rpx;
  429. view{
  430. line-height:100rpx;
  431. }
  432. view:nth-child(1){
  433. color:#0183FA;
  434. }
  435. view:nth-child(2){
  436. color:#999999;
  437. }
  438. }
  439. }
  440. .shade-max-box{
  441. position absolute
  442. top:0;
  443. left:0;
  444. background rgba(0,0,0,0.4)
  445. height:100%;
  446. width:100%;
  447. display flex
  448. flex-direction column
  449. .null-box{
  450. flex:1;
  451. }
  452. .shade-big-box{
  453. background #fff
  454. .shade-top-box{
  455. height:100rpx;
  456. display flex
  457. background #fff
  458. .button-box{
  459. width:130rpx;
  460. line-height:60rpx;
  461. color:#fff;
  462. background :#0183FA;
  463. margin:20rpx 0 20rpx 20rpx;
  464. border-radius: 30rpx;
  465. text-align center
  466. }
  467. .null-view{
  468. flex:1;
  469. }
  470. img{
  471. width:30rpx;
  472. height:30rpx;
  473. margin:35rpx 15rpx 35rpx 0;
  474. }
  475. .num-box{
  476. display flex
  477. margin-right:20rpx;
  478. view{
  479. line-height:100rpx;
  480. }
  481. view:nth-child(1){
  482. color:#0183FA;
  483. }
  484. view:nth-child(2){
  485. color:#999999;
  486. }
  487. }
  488. }
  489. }
  490. .for-max-box{
  491. background #fff
  492. padding-bottom:33rpx;
  493. .for-box{
  494. display inline-block
  495. width:97rpx;
  496. height:97rpx;
  497. line-height:97rpx;
  498. text-align center;
  499. font-size:34rpx;
  500. color:#999999;
  501. border:1rpx solid #999999;
  502. border-radius:50%;
  503. margin:33rpx 0 0 22rpx;
  504. }
  505. .colorA{
  506. border:1rpx solid #cce6fd;
  507. background: #cce6fd;
  508. color:#0183FA;
  509. }
  510. .colorB{
  511. border:1rpx solid #0183FA;
  512. }
  513. }
  514. }
  515. }
  516. </style>