|
@@ -0,0 +1,331 @@
|
|
|
+import {Component, OnInit} from '@angular/core';
|
|
|
+import {AlertController, MenuController, ModalController} from "@ionic/angular";
|
|
|
+import {ActivatedRoute, Router} from "@angular/router";
|
|
|
+import {ConfigService, RequsetData} from "../../../../service/config.service";
|
|
|
+import * as moment from 'moment';
|
|
|
+import {CardComponent} from "./card/card.component";
|
|
|
+import {ResultComponent} from "./result/result.component";
|
|
|
+import {UserService} from "../../../../service/user.service";
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-showpaper',
|
|
|
+ templateUrl: './showpaper.component.html',
|
|
|
+ styleUrls: ['./showpaper.component.scss'],
|
|
|
+})
|
|
|
+export class ShowpaperComponent implements OnInit {
|
|
|
+
|
|
|
+ lstorage = localStorage;
|
|
|
+ myexam: any = {};
|
|
|
+ userInfo: any = {};
|
|
|
+ examing = null;
|
|
|
+ examtip = "";
|
|
|
+ examendtip = "";
|
|
|
+ testQuestionList = [];
|
|
|
+ timer;
|
|
|
+ datatimer;
|
|
|
+ testId = "";
|
|
|
+ exambegintimer;
|
|
|
+ previewList = [];
|
|
|
+ questionIndex = 0;
|
|
|
+ paperScore = 0;
|
|
|
+ questiontypeList = [];
|
|
|
+ curQuestionList = [];
|
|
|
+ order = 1;
|
|
|
+ questionCount = 0;
|
|
|
+ answerCount = 0;
|
|
|
+
|
|
|
+ constructor(private userService: UserService, private modalController: ModalController, public alertController: AlertController, private menu: MenuController, private router: Router, private configService: ConfigService, private routeInfo: ActivatedRoute) {
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ this.routeInfo.queryParams.subscribe(params => {
|
|
|
+ this.testId = params['id'];
|
|
|
+ this.getQuestiontypeList();
|
|
|
+ this.getExamTest();
|
|
|
+ this.userInfo = this.userService.GetUser();
|
|
|
+ this.exambegintimer = setInterval(() => {
|
|
|
+ this.getExamTest();
|
|
|
+ }, 1000);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ getExamTest() {
|
|
|
+ this.configService.HttpGetRomote
|
|
|
+ ('/api/exammanage/plan/getMyExamPlan', {testId: this.testId}).subscribe((data) => {
|
|
|
+ this.myexam = data.item;
|
|
|
+ this.configService.HttpGetRomote('/api/exammanage/plan/getServerDate', {}).subscribe((date) => {
|
|
|
+ var sysdate = date + "";
|
|
|
+ if (this.myexam != null) {
|
|
|
+ if (this.myexam.manStatus > 2) {
|
|
|
+ this.showMsg('提示', '不在待考试,不允许进入');
|
|
|
+ clearInterval(this.exambegintimer);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (moment(sysdate).isAfter(this.myexam.testEndDate)) {
|
|
|
+ this.showMsg('提示', '考试时间已过,不允许进入');
|
|
|
+ clearInterval(this.exambegintimer);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (moment(sysdate).isBetween(this.myexam.testBeginDate, this.myexam.testEndDate)) {
|
|
|
+ clearInterval(this.exambegintimer);
|
|
|
+ this.timer = setInterval(() => {
|
|
|
+ this.checkTestExamTime();
|
|
|
+ }, 1000);
|
|
|
+ this.datatimer = setInterval(() => {
|
|
|
+ this.getTestExamTime();
|
|
|
+ this.cacheQuestion();
|
|
|
+ }, 60000);
|
|
|
+ this.examing = true;
|
|
|
+ this.showPaper();
|
|
|
+ this.updateTestManStatu(this.myexam.testmanId, 2);
|
|
|
+ } else {
|
|
|
+ this.examing = false;
|
|
|
+ var duration = moment.duration(
|
|
|
+ moment(sysdate).diff(moment(this.myexam.testBeginDate))
|
|
|
+ );
|
|
|
+ var hours = Math.abs(duration.get("hours"));
|
|
|
+ var mins = Math.abs(duration.get("minutes"));
|
|
|
+ var ss = Math.abs(duration.get("seconds"));
|
|
|
+ this.examtip = hours + "小时" + mins + "分" + ss + "秒";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ cacheQuestion = () => {
|
|
|
+ if (this.testQuestionList != undefined && this.testQuestionList.length > 0) {
|
|
|
+ this.lstorage.setItem("paperQuestion_" + this.testId, JSON.stringify(this.testQuestionList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ getTestExamTime = () => {
|
|
|
+ this.configService.HttpGetRomote('/api/exammanage/plan/getTestEndDate', {testId: this.testId}).subscribe((result) => {
|
|
|
+ this.myexam.testEndDate = result.item;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ checkTestExamTime = () => {
|
|
|
+ var myexam = this.myexam;
|
|
|
+ this.configService.HttpGetRomote('/api/exammanage/plan/getServerDate').subscribe((p) => {
|
|
|
+ var sysdate = p + "";
|
|
|
+ if (moment(sysdate).isAfter(this.myexam.testEndDate)) {
|
|
|
+ clearInterval(this.timer);
|
|
|
+ clearInterval(this.datatimer);
|
|
|
+ this.showMsg('提示', '考试时间已到,已自动为您交卷');
|
|
|
+ this.examendtip = "0小时0分";
|
|
|
+ this.submitExamTestSync();
|
|
|
+ } else {
|
|
|
+ var duration = moment.duration(
|
|
|
+ moment(sysdate).diff(moment(myexam.testEndDate))
|
|
|
+ );
|
|
|
+ var hours = Math.abs(duration.get("hours"));
|
|
|
+ var mins = Math.abs(duration.get("minutes"));
|
|
|
+ //因为不显示秒,避免秒倒计时的时候分为0
|
|
|
+ mins = mins == 0 && hours == 0 ? 1 : mins + 1;
|
|
|
+ this.examendtip = hours + "小时" + mins + "分";
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ submitExamTestSync = () => {
|
|
|
+ let pm = new Promise((resolve, reject) => {
|
|
|
+ this.configService.HttpPostRomote('/api/examtest/submitExamTest', {
|
|
|
+ onlinetestId: this.myexam.onlinetestId,
|
|
|
+ testmanId: this.myexam.testmanId,
|
|
|
+ userQuestionList: this.testQuestionList,
|
|
|
+ }).subscribe((data) => {
|
|
|
+ if (data.success) {
|
|
|
+ var subjectiveCount = this.testQuestionList.filter(function (type) {
|
|
|
+ return type.OBJECTIVE_TYPE == 1
|
|
|
+ }).length;
|
|
|
+ var objectiveCount = this.testQuestionList.filter(function (type) {
|
|
|
+ return type.OBJECTIVE_TYPE == 2
|
|
|
+ }).length;
|
|
|
+ this.resultModal(subjectiveCount, objectiveCount);
|
|
|
+ } else {
|
|
|
+ this.showMsg('错误', data.msg);
|
|
|
+ }
|
|
|
+ resolve();
|
|
|
+ })
|
|
|
+ });
|
|
|
+ return pm;
|
|
|
+ }
|
|
|
+ submitExamTest = () => {
|
|
|
+ this.presentAlertConfirm("是否确认交卷?", () => {
|
|
|
+ this.submitExamTestSync().then(() => {
|
|
|
+
|
|
|
+ });
|
|
|
+ })
|
|
|
+ };
|
|
|
+
|
|
|
+ showPaper() {
|
|
|
+ this.getUserTestPaperQuestions().then(() => {
|
|
|
+ this.changeView();
|
|
|
+ this.questionCount = this.testQuestionList.length;
|
|
|
+ this.answerCount = this.testQuestionList.filter(x => x.isAnswer).length;
|
|
|
+
|
|
|
+ this.previewList = [];
|
|
|
+ this.questionIndex = 0;
|
|
|
+ var selectQuestionTypeList = this.questiontypeList.filter((type) => {
|
|
|
+ return this.testQuestionList.filter((pquestion) => {
|
|
|
+ return pquestion.BASE_QUESTION_TYPE_ID == type.baseQuestionTypeId;
|
|
|
+ }).length > 0;
|
|
|
+ });
|
|
|
+ selectQuestionTypeList.forEach((type) => {
|
|
|
+ var typequestion = this.testQuestionList.filter((pquestion) => {
|
|
|
+ return pquestion.BASE_QUESTION_TYPE_ID == type.baseQuestionTypeId;
|
|
|
+ })
|
|
|
+ if (typequestion.length > 0) {
|
|
|
+ var previewItem = Object.assign({}, type);
|
|
|
+ var typescore = 0;
|
|
|
+ typequestion.forEach((tquestion) => {
|
|
|
+ typescore += tquestion.SCORE;
|
|
|
+ this.questionIndex++;
|
|
|
+ tquestion.order = this.questionIndex;
|
|
|
+ })
|
|
|
+ this.paperScore += typescore;
|
|
|
+ previewItem.score = typescore;//题型总分
|
|
|
+ previewItem.questionNum = typequestion.length;
|
|
|
+ previewItem.question = typequestion;
|
|
|
+ this.previewList.push(previewItem);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ //加载试题类型数据
|
|
|
+ getQuestiontypeList = () => {
|
|
|
+ this.configService.HttpGetRomote('/api/exammanage/questiontypeSetting/getList', {}).subscribe((data: RequsetData) => {
|
|
|
+ if (data.success) {
|
|
|
+ this.questiontypeList = data.item;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ getUserTestPaperQuestions() {
|
|
|
+ let pm = new Promise((resolve, reject) => {
|
|
|
+ //先取缓存数据
|
|
|
+ var lstkey = "paperQuestion_" + this.testId;
|
|
|
+ if (this.lstorage.getItem(lstkey)) {
|
|
|
+ this.testQuestionList = JSON.parse(this.lstorage.getItem(lstkey));
|
|
|
+ resolve();
|
|
|
+ } else {
|
|
|
+ this.configService.HttpGetRomote('/api/examtest/getUserTestPaperQuestions', {
|
|
|
+ paperid: this.myexam.testPaperId,
|
|
|
+ testid: this.myexam.onlinetestId,
|
|
|
+ }).subscribe((data: RequsetData) => {
|
|
|
+ if (data.success) {
|
|
|
+ this.testQuestionList = data.item;
|
|
|
+ this.testQuestionList.forEach((x, index) => {
|
|
|
+ x.ANSWERS = this.sort(x.ANSWERS, 'ORDER');
|
|
|
+ x.order = index + 1;
|
|
|
+ })
|
|
|
+ this.lstorage.setItem(lstkey, JSON.stringify(this.testQuestionList));
|
|
|
+ resolve();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return pm;
|
|
|
+ }
|
|
|
+
|
|
|
+ updateTestManStatu(testmanId, manStatu) {
|
|
|
+ this.configService.HttpGetRomote('/api/examtest/updateTestManStatu', {
|
|
|
+ testmanId: testmanId, manStatu: manStatu
|
|
|
+ }).subscribe((data: RequsetData) => {
|
|
|
+ if (data.success) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ sort(list: any[], field: string) {
|
|
|
+ return list.sort((a, b) => a[field] - b[field]);
|
|
|
+ }
|
|
|
+
|
|
|
+ options(index) {
|
|
|
+ return String.fromCharCode(65 + index);
|
|
|
+ }
|
|
|
+
|
|
|
+ answer(ques) {
|
|
|
+ ques.isAnswer = true;
|
|
|
+ this.answerCount = this.testQuestionList.filter(x => x.isAnswer).length;
|
|
|
+ }
|
|
|
+
|
|
|
+ changeView() {
|
|
|
+ this.curQuestionList = this.testQuestionList.filter(x => x.order == this.order);
|
|
|
+ }
|
|
|
+
|
|
|
+ close() {
|
|
|
+ this.router.navigate(['../'], {
|
|
|
+ relativeTo: this.routeInfo,
|
|
|
+ queryParams: {id: 'id', random: Math.random()}
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async presentModal() {
|
|
|
+ const modal = await this.modalController.create({
|
|
|
+ component: CardComponent,
|
|
|
+ cssClass: 'examtest-modal',
|
|
|
+ componentProps: {
|
|
|
+ 'previewList': this.previewList,
|
|
|
+ 'testQuestionList': this.testQuestionList
|
|
|
+ }
|
|
|
+ });
|
|
|
+ await modal.present();
|
|
|
+
|
|
|
+ const {data} = await modal.onWillDismiss();
|
|
|
+
|
|
|
+ if (data != undefined && data.dismissed) {
|
|
|
+ this.order = data.order;
|
|
|
+ this.changeView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async showMsg(title: string, msg: string) {
|
|
|
+ const alert = await this.alertController.create({
|
|
|
+ header: title,
|
|
|
+ subHeader: '',
|
|
|
+ message: msg,
|
|
|
+ buttons: ['确定']
|
|
|
+ });
|
|
|
+
|
|
|
+ await alert.present();
|
|
|
+ }
|
|
|
+
|
|
|
+ async presentAlertConfirm(msg: string, handler) {
|
|
|
+ const alert = await this.alertController.create({
|
|
|
+ header: '提示',
|
|
|
+ message: '<strong>' + msg + '</strong>',
|
|
|
+ buttons: [
|
|
|
+ {
|
|
|
+ text: '关闭',
|
|
|
+ role: 'cancel',
|
|
|
+ cssClass: 'secondary',
|
|
|
+ handler: () => {
|
|
|
+
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ text: '确定',
|
|
|
+ handler: handler
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ });
|
|
|
+ await alert.present();
|
|
|
+ }
|
|
|
+
|
|
|
+ async resultModal(subjectiveCount: number, objectiveCount: number) {
|
|
|
+ const modal = await this.modalController.create({
|
|
|
+ component: ResultComponent,
|
|
|
+ cssClass: 'onlineresult-modal',
|
|
|
+ componentProps: {
|
|
|
+ 'subjectiveCount': subjectiveCount,
|
|
|
+ 'objectiveCount': objectiveCount
|
|
|
+ }
|
|
|
+ });
|
|
|
+ await modal.present();
|
|
|
+
|
|
|
+ const {data} = await modal.onWillDismiss();
|
|
|
+
|
|
|
+ if (data != undefined && data.dismissed) {
|
|
|
+ this.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|