awWaitExam.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1.  #include "awWaitExam.h"
  2. #include "ui_awWaitExam.h"
  3. #include "CAppInfo.h"
  4. #include "awMsgBox.h"
  5. #include <QListWidgetItem>
  6. #include <QHBoxLayout>
  7. #include <QLabel>
  8. awWaitExam::awWaitExam(QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::awWaitExam)
  11. {
  12. ui->setupUi(this);
  13. setStyleSheet(g_appInfoPtr->m_sQssStr);
  14. qRegisterMetaType<CGetExamProperty>("CGetExamProperty");
  15. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamProperty, this, &awWaitExam::onGetExamProperty);
  16. qRegisterMetaType<CGetExamRecordPaperStruct>("CGetExamRecordPaperStruct");
  17. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetExamRecordPaperStruct, this, &awWaitExam::onGetExamRecordPaperStruct);
  18. qRegisterMetaType<CStartExam>("CStartExam");
  19. connect(g_httpBllPtr.get(), &CHttpBll::sgnStartExam, this, &awWaitExam::onStartExam);
  20. CHttpRequestPackage hrp;
  21. hrp.sUri = QString("/api/ecs_exam_work/exam/getExamPropertyFromCacheByStudentSession/%1/%2")
  22. .arg(g_appInfoPtr->m_oExamInfo.nExamId).arg("BEFORE_EXAM_REMARK");
  23. hrp.nRequestType = RequestType::rtGetExamProperty;
  24. hrp.sCommonStr = "BEFORE_EXAM_REMARK";
  25. g_httpBllPtr->get(hrp);
  26. CHttpRequestPackage hrp1;
  27. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/startExam";
  28. hrp1.nRequestType = RequestType::rtStartExam;
  29. hrp1.sParamList.push_back(QString("examStudentId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamStudentId));
  30. hrp1.eParamType = HttpParamType::hptUrl;
  31. g_httpBllPtr->post(hrp1);
  32. bHasStruct = false;
  33. nCountDownCount = 60 * 2;
  34. m_pTimer = std::make_shared<QTimer>();
  35. m_pTimer->setInterval(1000);
  36. m_pTimer->start();
  37. connect(m_pTimer.get(), &QTimer::timeout, this, [&]() {
  38. --nCountDownCount;
  39. ui->btn_we_startExam->setText(QString::fromLocal8Bit("接受以上条款,开始考试(倒计时:%1:%2:%3)")
  40. .arg(nCountDownCount / 3600, 2, 10, QChar('0'))
  41. .arg((nCountDownCount % 3600) / 60, 2, 10, QChar('0'))
  42. .arg(nCountDownCount % 60, 2, 10, QChar('0')));
  43. if (bHasStruct && nCountDownCount < 110)
  44. {
  45. ui->btn_we_startExam->setStyleSheet(QString(R"( QPushButton
  46. {
  47. background:rgba(19,187,138,1);
  48. border-radius:%1px;
  49. font-size:%2px;
  50. font-family:"Microsoft YaHei";
  51. font-weight:600;
  52. color:rgba(255,255,255,0.5);
  53. })").arg((int)(g_appInfoPtr->m_fRate*10))
  54. .arg((int)(g_appInfoPtr->m_fRate * 14)));
  55. }
  56. if (nCountDownCount == 0)
  57. {
  58. m_pTimer->stop();
  59. emit enterExam();
  60. return;
  61. }
  62. });
  63. }
  64. awWaitExam::~awWaitExam()
  65. {
  66. awMsgBox::clear(this);
  67. delete ui;
  68. }
  69. void awWaitExam::setUI(const int nLeft, const int nTop, const int nWidth, const int nHeight)
  70. {
  71. setGeometry(nLeft, nTop, nWidth, nHeight);
  72. ui->widget_we_preNotice->setGeometry(0, 0, width()*970/(970+270), height());
  73. ui->widget_we_paperStruct->setGeometry(ui->widget_we_preNotice->x() + ui->widget_we_preNotice->width() + g_appInfoPtr->m_fRate*20, 0,
  74. width() - ui->widget_we_preNotice->width() - g_appInfoPtr->m_fRate*20, height());
  75. ui->label_we_notice->adjustSize();
  76. ui->label_we_notice->setGeometry(g_appInfoPtr->m_fRate*40, g_appInfoPtr->m_fRate*30,
  77. ui->label_we_notice->width(), ui->label_we_notice->height());
  78. ui->txtb_we_prenotice->setGeometry(ui->label_we_notice->x(), ui->label_we_notice->y() + ui->label_we_notice->height() + g_appInfoPtr->m_fRate*20,
  79. ui->widget_we_preNotice->width() - g_appInfoPtr->m_fRate*40*2, g_appInfoPtr->m_fRate*390);
  80. ui->btn_we_startExam->setGeometry((ui->widget_we_preNotice->width() - g_appInfoPtr->m_fRate*380)/2,
  81. ui->txtb_we_prenotice->y() + ui->txtb_we_prenotice->height() + g_appInfoPtr->m_fRate*110,
  82. g_appInfoPtr->m_fRate*380, g_appInfoPtr->m_fRate*40);
  83. ui->label_we_struct->adjustSize();
  84. ui->label_we_struct->setGeometry(g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*20,
  85. ui->label_we_struct->width(), ui->label_we_struct->height());
  86. ui->label_we_totalScore->adjustSize();
  87. ui->label_we_totalScore->setGeometry(ui->widget_we_paperStruct->width() - g_appInfoPtr->m_fRate*30 - ui->label_we_totalScore->width(),
  88. ui->label_we_struct->y() + (ui->label_we_struct->height() - ui->label_we_totalScore->height())/2,
  89. ui->label_we_totalScore->width(), ui->label_we_totalScore->height());
  90. ui->lw_we_struct->setGeometry(ui->label_we_struct->x(), ui->label_we_struct->y() + ui->label_we_struct->height() + g_appInfoPtr->m_fRate*20,
  91. ui->widget_we_paperStruct->width() - g_appInfoPtr->m_fRate*30*2,
  92. ui->widget_we_paperStruct->height() - ui->label_we_struct->y() - ui->label_we_struct->height() - g_appInfoPtr->m_fRate*(20 + 30));
  93. }
  94. void awWaitExam::onStartExam(CStartExam startExam)
  95. {
  96. if (startExam.nCode == 200)
  97. {
  98. g_appInfoPtr->m_oExamInfo.nExamRecordDataId = startExam.nExamRecordDataId;
  99. g_appInfoPtr->m_oExamInfo.sCourseCode = startExam.sCourseCode;
  100. g_appInfoPtr->m_oExamInfo.sCourseName = startExam.sCourseName;
  101. g_appInfoPtr->m_oExamInfo.nFaceVerifyMinute = startExam.nFaceVerifyMinute;
  102. CHttpRequestPackage hrp1;
  103. hrp1.sUri = "/api/ecs_oe_student/client/exam/process/getExamRecordPaperStruct";
  104. hrp1.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  105. hrp1.nRequestType = RequestType::rtGetExamRecordPaperStruct;
  106. hrp1.eParamType = HttpParamType::hptUrl;
  107. g_httpBllPtr->post(hrp1);
  108. }
  109. else
  110. {
  111. if(startExam.sMessage.isEmpty())
  112. {
  113. ShowMsg(QString::fromLocal8Bit("开始考试失败,退出登录"), (QWidget*)g_appInfoPtr->m_pAnsBgWidget->parent(), MSG_ICON_TYPE::mit_error);
  114. }
  115. else
  116. {
  117. ShowMsg(startExam.sMessage, (QWidget*)g_appInfoPtr->m_pAnsBgWidget->parent(), MSG_ICON_TYPE::mit_error);
  118. }
  119. QTimer::singleShot(2000, this, [&](){emit gobackLogin();});
  120. }
  121. }
  122. void awWaitExam::onGetExamRecordPaperStruct(CGetExamRecordPaperStruct getExamRecordPaperStruct)
  123. {
  124. if (getExamRecordPaperStruct.nCode == 200)
  125. {
  126. int nSize = getExamRecordPaperStruct.vPaperGroupStruct.size();
  127. double tTotalScore = 0;
  128. for (int i = 0; i < nSize; ++i)
  129. {
  130. CPaperGroupStruct pgs = getExamRecordPaperStruct.vPaperGroupStruct[i];
  131. QListWidgetItem *pItem = new QListWidgetItem;
  132. QSize size = pItem->sizeHint();
  133. size.setHeight(g_appInfoPtr->m_fRate * 37);
  134. pItem->setSizeHint(size);
  135. ui->lw_we_struct->addItem(pItem);
  136. QWidget *w = new QWidget;
  137. // w->setStyleSheet(QString("QWidget{background:rgba(19, 187, 138, 1); border-radius:%1px}").arg((int)(g_appInfoPtr->m_fRate*10)));
  138. QHBoxLayout *l = new QHBoxLayout;
  139. QString sLabelSubjectStyle = QString(R"(QLabel{
  140. font-size:%1px;
  141. font-family:"Microsoft YaHei";
  142. font-weight:500;
  143. color:rgba(68,68,68,1);})").arg((int)(g_appInfoPtr->m_fRate * 12));
  144. QString sLabelSubjectInfoStyle = QString(R"(QLabel{
  145. font-size:%1px;
  146. font-family:"Microsoft YaHei";
  147. font-weight:500;
  148. color:rgba(153,153,153,1);})").arg((int)(g_appInfoPtr->m_fRate * 12));
  149. QLabel *label_subject = new QLabel;
  150. label_subject->setText(QString::fromLocal8Bit("%1、%2").arg(i+1).arg(pgs.sGroupName));
  151. label_subject->setStyleSheet(sLabelSubjectStyle);
  152. label_subject->adjustSize();
  153. QLabel *label_subjectInfo = new QLabel;
  154. label_subjectInfo->setText(QString::fromLocal8Bit("共%1题,共%2分").arg(pgs.nTotalSubquestion).arg(pgs.fGroupScore));
  155. label_subjectInfo->setStyleSheet(sLabelSubjectInfoStyle);
  156. l->setContentsMargins(0, 0, 0, 0);
  157. l->addWidget(label_subject);
  158. l->addStretch();
  159. l->addWidget(label_subjectInfo);
  160. w->setLayout(l);
  161. ui->lw_we_struct->setItemWidget(pItem, w);
  162. tTotalScore += pgs.fGroupScore;
  163. }
  164. ui->label_we_totalScore->setText(QString::fromLocal8Bit("总分:%1").arg(tTotalScore));
  165. bHasStruct = true;
  166. }
  167. else
  168. {
  169. if(getExamRecordPaperStruct.sMessage.isEmpty())
  170. {
  171. ShowMsg(QString::fromLocal8Bit("获取试卷结构失败,退出登录"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  172. }
  173. else
  174. {
  175. ShowMsg(getExamRecordPaperStruct.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  176. }
  177. QTimer::singleShot(2000, this, [&](){emit gobackLogin();});
  178. }
  179. }
  180. void awWaitExam::onGetExamProperty(CGetExamProperty getExamProperty)
  181. {
  182. if (getExamProperty.nCode == 200)
  183. {
  184. if (getExamProperty.sType == "BEFORE_EXAM_REMARK")
  185. {
  186. ui->txtb_we_prenotice->insertHtml(getExamProperty.sBeforeExamRemark);
  187. }
  188. }
  189. else
  190. {
  191. if(getExamProperty.sMessage.isEmpty())
  192. {
  193. ShowMsg(QString::fromLocal8Bit("获取考试信息失败,退出登录"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  194. }
  195. else
  196. {
  197. ShowMsg(getExamProperty.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  198. }
  199. QTimer::singleShot(2000, this, [&](){emit gobackLogin();});
  200. }
  201. }
  202. void awWaitExam::on_btn_we_startExam_clicked()
  203. {
  204. if (bHasStruct && nCountDownCount < 110)
  205. {
  206. m_pTimer->stop();
  207. emit enterExam();
  208. }
  209. }