etMobileTest.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #include "etMobileTest.h"
  2. #include "ui_etMobileTest.h"
  3. #include <QScrollBar>
  4. #include <QHBoxLayout>
  5. #include <QLabel>
  6. #include "CAppInfo.h"
  7. #include "CQREncode.h"
  8. #include "awMsgBox.h"
  9. etMobileTest::etMobileTest(QWidget *parent) :
  10. QWidget(parent),
  11. ui(new Ui::etMobileTest)
  12. {
  13. ui->setupUi(this);
  14. setStyleSheet(g_appInfoPtr->m_sQssStr);
  15. m_nUploadStatus = 2;
  16. qRegisterMetaType<CGetWXQrCode>("CGetWXQrCode");
  17. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetWXQrCode, this, &etMobileTest::onGetWXQrCode);
  18. qRegisterMetaType<CSaveUploadedFileAcknowledgeStatus>("CSaveUploadedFileAcknowledgeStatus");
  19. connect(g_httpBllPtr.get(), &CHttpBll::sgnSaveUploadedFileAcknowledgeStatus, this, &etMobileTest::onSaveUploadedFileAcknowledgeStatus);
  20. if (g_websocketPtr == nullptr)
  21. {
  22. g_websocketPtr = std::make_shared<CWebsocketProc>();
  23. }
  24. g_websocketPtr->open(QString("wss://%1:%2/api/ws/fileAnswer")
  25. .arg(g_appInfoPtr->m_sHttpServer).arg(g_appInfoPtr->m_sHttpPort),
  26. g_httpBllPtr->getToken(), g_httpBllPtr->getKey());
  27. connect(g_websocketPtr.get(), &CWebsocketProc::mobileStatus, this, &etMobileTest::onMobileStatus);
  28. connect(g_websocketPtr.get(), &CWebsocketProc::fileAnswer, this, &etMobileTest::onFileAnswer);
  29. CHttpRequestPackage hrp;
  30. hrp.sUri = "/api/ecs_oe_student/examControl/getQrCode";
  31. hrp.nRequestType = RequestType::rtGetWXQrCode;
  32. Json::Value jBody = Json::Value::null;
  33. jBody["examRecordDataId"] = g_appInfoPtr->m_oExamInfo.nExamId;
  34. jBody["order"] = 1;
  35. jBody["transferFileType"] = "AUDIO";
  36. jBody["testEnv"] = true;
  37. hrp.sParamList.push_back(QString("CustomBody,%1").arg(jBody.toStyledString().c_str()));
  38. hrp.eParamType = HttpParamType::hptCustomBody;
  39. g_httpBllPtr->post(hrp);
  40. }
  41. etMobileTest::~etMobileTest()
  42. {
  43. g_websocketPtr->close();
  44. delete ui;
  45. }
  46. int etMobileTest::setUI(const int nLeft, const int nTop, const int nWidth)
  47. {
  48. setGeometry(nLeft, nTop, nWidth, g_appInfoPtr->m_fRate*427);
  49. ui->label_etmv_qrcode->setGeometry(g_appInfoPtr->m_fRate*30, g_appInfoPtr->m_fRate*30,
  50. g_appInfoPtr->m_fRate*220, g_appInfoPtr->m_fRate*220);
  51. ui->label_etmt_tips->setGeometry(ui->label_etmv_qrcode->x() + ui->label_etmv_qrcode->width() + g_appInfoPtr->m_fRate*30,
  52. ui->label_etmv_qrcode->y(), g_appInfoPtr->m_fRate*490, g_appInfoPtr->m_fRate*66);
  53. ui->label_etmt_tips->setText(QString::fromLocal8Bit(R"(<html>
  54. <body>
  55. <style type="text/css">
  56. #normalText {
  57. color: #717171;
  58. font-size:%1px;
  59. font-family:Microsoft YaHei;
  60. text-align: left;
  61. }
  62. #hoverText {
  63. color: #13BA8C;
  64. font-size:%2px;
  65. font-family:Microsoft YaHei;
  66. text-align: left;
  67. }
  68. </style>
  69. <span id="normalText">请使用</span>
  70. <span id="hoverText">微信</span>
  71. <span id="normalText">扫描二维码后,在微信小程序上录音,并上传文件</span>
  72. </body>
  73. </html>)").arg((int)(g_appInfoPtr->m_fRate*24)).arg((int)(g_appInfoPtr->m_fRate*24)));
  74. ui->label_HLine->setGeometry(ui->label_etmt_tips->x(), ui->label_etmt_tips->y() + ui->label_etmt_tips->height() + g_appInfoPtr->m_fRate*20,
  75. g_appInfoPtr->m_fRate*490, g_appInfoPtr->m_fRate*1);
  76. ui->label_etmt_status->adjustSize();
  77. ui->label_etmt_status->setGeometry(ui->label_etmt_tips->x(), ui->label_HLine->y() + ui->label_HLine->height() + 20,
  78. g_appInfoPtr->m_fRate*490, ui->label_etmt_status->height());
  79. ui->btn_etmt_canotScan->setGeometry(ui->label_etmt_tips->x(), ui->label_etmv_qrcode->y() + ui->label_etmv_qrcode->height() - g_appInfoPtr->m_fRate*40,
  80. g_appInfoPtr->m_fRate*240, g_appInfoPtr->m_fRate*40);
  81. ui->btn_etmt_canotScan->setIconSize(QSize(g_appInfoPtr->m_fRate*13, g_appInfoPtr->m_fRate*13));
  82. ui->btn_etmt_canotScan->setIcon(QIcon(":/images/btn-can-not-play"));
  83. ui->btn_etmt_uploadFaild->setGeometry(ui->btn_etmt_canotScan->x() + ui->btn_etmt_canotScan->width() + g_appInfoPtr->m_fRate*10,
  84. ui->btn_etmt_canotScan->y(), ui->btn_etmt_canotScan->width(), ui->btn_etmt_canotScan->height());
  85. ui->btn_etmt_uploadFaild->setIconSize(QSize(g_appInfoPtr->m_fRate*13, g_appInfoPtr->m_fRate*13));
  86. ui->btn_etmt_uploadFaild->setIcon(QIcon(":/images/btn-can-not-play"));
  87. ui->tablewt_envTest->setGeometry(ui->label_etmv_qrcode->x(), ui->label_etmv_qrcode->y() + ui->label_etmv_qrcode->height() + g_appInfoPtr->m_fRate*30,
  88. width() - g_appInfoPtr->m_fRate*30*2, height() - ui->label_etmv_qrcode->y() - ui->label_etmv_qrcode->height() - g_appInfoPtr->m_fRate*30);
  89. ui->tablewt_envTest->setEditTriggers(QAbstractItemView::NoEditTriggers);
  90. //整行选中的方式
  91. ui->tablewt_envTest->setSelectionBehavior(QAbstractItemView::SelectRows);
  92. //设置为只能选中一行
  93. ui->tablewt_envTest->setSelectionMode(QAbstractItemView::SingleSelection);
  94. //隐藏列表头
  95. ui->tablewt_envTest->verticalHeader()->setVisible(false);
  96. //隐藏边框
  97. ui->tablewt_envTest->setShowGrid(false);
  98. //表头不高亮显示
  99. ui->tablewt_envTest->horizontalHeader()->setHighlightSections(false);
  100. //设置行数
  101. ui->tablewt_envTest->setRowCount(2);
  102. //设置列数
  103. ui->tablewt_envTest->setColumnCount(3);
  104. ui->tablewt_envTest->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
  105. ui->tablewt_envTest->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
  106. QStringList sHeadStr;
  107. sHeadStr << QString::fromLocal8Bit("检测项") <<
  108. QString::fromLocal8Bit("值") <<
  109. QString::fromLocal8Bit("状态");
  110. ui->tablewt_envTest->setHorizontalHeaderLabels(sHeadStr);
  111. ui->tablewt_envTest->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  112. ui->tablewt_envTest->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
  113. ui->tablewt_envTest->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
  114. ui->tablewt_envTest->setColumnWidth(0, g_appInfoPtr->m_fRate*525);
  115. ui->tablewt_envTest->setColumnWidth(1, g_appInfoPtr->m_fRate*170);
  116. ui->tablewt_envTest->setColumnWidth(2, g_appInfoPtr->m_fRate*24);
  117. ui->tablewt_envTest->horizontalHeader()->setStretchLastSection(true);
  118. {
  119. int i = 0;
  120. ui->tablewt_envTest->setItem(i, 0, new QTableWidgetItem(QString::fromLocal8Bit("扫描二维码")));
  121. ui->tablewt_envTest->setItem(i, 1, new QTableWidgetItem(QString::fromLocal8Bit("")));
  122. /* QWidget *widget = new QWidget;
  123. QHBoxLayout *layout = new QHBoxLayout;
  124. widget->setLayout(layout);
  125. QLabel *icon = new QLabel;
  126. icon->setFixedSize(QSize(g_appInfoPtr->m_fRate*12, g_appInfoPtr->m_fRate*9));
  127. icon->setPixmap(QPixmap(":/images/icon-et-item-pass.png").scaled(g_appInfoPtr->m_fRate*12, g_appInfoPtr->m_fRate*9));
  128. layout->addWidget(icon);
  129. layout->addStretch();
  130. ui->tablewt_envTest->setCellWidget(i, 2, widget);*/
  131. }
  132. {
  133. int i = 1;
  134. ui->tablewt_envTest->setItem(i, 0, new QTableWidgetItem(QString::fromLocal8Bit("上传录音")));
  135. ui->tablewt_envTest->setItem(i, 1, new QTableWidgetItem(QString::fromLocal8Bit("")));
  136. /*QWidget *widget = new QWidget;
  137. QHBoxLayout *layout = new QHBoxLayout;
  138. widget->setLayout(layout);
  139. QLabel *icon = new QLabel;
  140. icon->setFixedSize(QSize(g_appInfoPtr->m_fRate * 12, g_appInfoPtr->m_fRate * 9));
  141. icon->setPixmap(QPixmap(":/images/icon-et-item-pass.png").scaled(g_appInfoPtr->m_fRate * 12, g_appInfoPtr->m_fRate * 9));
  142. layout->addWidget(icon);
  143. layout->addStretch();
  144. ui->tablewt_envTest->setCellWidget(i, 2, widget);*/
  145. }
  146. return height();
  147. }
  148. int etMobileTest::widgetHeight()
  149. {
  150. return height();
  151. }
  152. void etMobileTest::onGetWXQrCode(CGetWXQrCode getWXQrCode)
  153. {
  154. if (getWXQrCode.nCode == 200)
  155. {
  156. ui->label_etmv_qrcode->setPixmap(CQREncode::GenerateQRcode(getWXQrCode.sUrl, ui->label_etmv_qrcode->width()));
  157. }
  158. else
  159. {
  160. if(getWXQrCode.sMessage.isEmpty())
  161. {
  162. ShowMsg(QString::fromLocal8Bit("获取二维码失败"), (QWidget*)(this->parent()));
  163. }
  164. else
  165. {
  166. ShowMsg(getWXQrCode.sMessage, (QWidget*)(this->parent()));
  167. }
  168. }
  169. }
  170. void etMobileTest::onMobileStatus(__int64 nExamRecordDataId, int nOrder, QString sScanStatus)
  171. {
  172. if (sScanStatus == "SCANNED")
  173. {
  174. int i = 0;
  175. ui->tablewt_envTest->setItem(i, 0, new QTableWidgetItem(QString::fromLocal8Bit("扫描二维码")));
  176. ui->tablewt_envTest->setItem(i, 1, new QTableWidgetItem(QString::fromLocal8Bit("正常")));
  177. QWidget *widget = new QWidget;
  178. QHBoxLayout *layout = new QHBoxLayout;
  179. widget->setLayout(layout);
  180. QLabel *icon = new QLabel;
  181. icon->setFixedSize(QSize(g_appInfoPtr->m_fRate*12, g_appInfoPtr->m_fRate*9));
  182. icon->setPixmap(QPixmap(":/images/icon-et-item-pass.png").scaled(g_appInfoPtr->m_fRate*12, g_appInfoPtr->m_fRate*9));
  183. layout->addWidget(icon);
  184. layout->addStretch();
  185. ui->tablewt_envTest->setCellWidget(i, 2, widget);
  186. }
  187. }
  188. void etMobileTest::onFileAnswer(__int64 nExamRecordDataId, int nOrder, QString sFileType, QString sFileUrl)
  189. {
  190. CHttpRequestPackage hrp;
  191. hrp.sUri = "/api/ecs_oe_student/examControl/saveUploadedFileAcknowledgeStatus";
  192. hrp.nRequestType = RequestType::rtSaveUploadedFileAcknowledgeStatus;
  193. Json::Value jBody = Json::Value::null;
  194. jBody["examRecordDataId"] = nExamRecordDataId;
  195. jBody["order"] = nOrder;
  196. jBody["filePath"] = sFileUrl.toStdString();
  197. jBody["acknowledgeStatus"] = "CONFIRMED";
  198. hrp.sParamList.push_back(QString("CustomBody,%1").arg(jBody.toStyledString().c_str()));
  199. hrp.eParamType = HttpParamType::hptCustomBody;
  200. g_httpBllPtr->post(hrp);
  201. }
  202. void etMobileTest::onSaveUploadedFileAcknowledgeStatus(CSaveUploadedFileAcknowledgeStatus saveUploadedFileAcknowledgeStatus)
  203. {
  204. if (saveUploadedFileAcknowledgeStatus.nCode == 200)
  205. {
  206. int i = 1;
  207. ui->tablewt_envTest->setItem(i, 0, new QTableWidgetItem(QString::fromLocal8Bit("上传录音")));
  208. ui->tablewt_envTest->setItem(i, 1, new QTableWidgetItem(QString::fromLocal8Bit("正常")));
  209. QWidget *widget = new QWidget;
  210. QHBoxLayout *layout = new QHBoxLayout;
  211. widget->setLayout(layout);
  212. QLabel *icon = new QLabel;
  213. icon->setFixedSize(QSize(g_appInfoPtr->m_fRate * 12, g_appInfoPtr->m_fRate * 9));
  214. icon->setPixmap(QPixmap(":/images/icon-et-item-pass.png").scaled(g_appInfoPtr->m_fRate * 12, g_appInfoPtr->m_fRate * 9));
  215. layout->addWidget(icon);
  216. layout->addStretch();
  217. ui->tablewt_envTest->setCellWidget(i, 2, widget);
  218. m_nUploadStatus = 1;
  219. }
  220. else
  221. {
  222. int i = 1;
  223. ui->tablewt_envTest->setItem(i, 0, new QTableWidgetItem(QString::fromLocal8Bit("上传录音")));
  224. ui->tablewt_envTest->setItem(i, 1, new QTableWidgetItem(QString::fromLocal8Bit("出错")));
  225. QWidget *widget = new QWidget;
  226. QHBoxLayout *layout = new QHBoxLayout;
  227. widget->setLayout(layout);
  228. QLabel *icon = new QLabel;
  229. icon->setFixedSize(QSize(g_appInfoPtr->m_fRate * 8, g_appInfoPtr->m_fRate * 8));
  230. icon->setPixmap(QPixmap(":/images/icon-et-iten-unpass.png").scaled(g_appInfoPtr->m_fRate * 8, g_appInfoPtr->m_fRate * 8));
  231. layout->addWidget(icon);
  232. layout->addStretch();
  233. ui->tablewt_envTest->setCellWidget(i, 2, widget);
  234. }
  235. }
  236. void etMobileTest::on_btn_etmt_canotScan_clicked()
  237. {
  238. int i = 0;
  239. ui->tablewt_envTest->setItem(i, 0, new QTableWidgetItem(QString::fromLocal8Bit("扫描二维码")));
  240. ui->tablewt_envTest->setItem(i, 1, new QTableWidgetItem(QString::fromLocal8Bit("出错")));
  241. QWidget *widget = new QWidget;
  242. QHBoxLayout *layout = new QHBoxLayout;
  243. widget->setLayout(layout);
  244. QLabel *icon = new QLabel;
  245. icon->setFixedSize(QSize(g_appInfoPtr->m_fRate * 8, g_appInfoPtr->m_fRate * 8));
  246. icon->setPixmap(QPixmap(":/images/icon-et-iten-unpass.png").scaled(g_appInfoPtr->m_fRate * 8, g_appInfoPtr->m_fRate * 8));
  247. layout->addWidget(icon);
  248. layout->addStretch();
  249. ui->tablewt_envTest->setCellWidget(i, 2, widget);
  250. m_nUploadStatus = 0;
  251. }
  252. void etMobileTest::on_btn_etmt_uploadFaild_clicked()
  253. {
  254. int i = 1;
  255. ui->tablewt_envTest->setItem(i, 0, new QTableWidgetItem(QString::fromLocal8Bit("上传录音")));
  256. ui->tablewt_envTest->setItem(i, 1, new QTableWidgetItem(QString::fromLocal8Bit("出错")));
  257. QWidget *widget = new QWidget;
  258. QHBoxLayout *layout = new QHBoxLayout;
  259. widget->setLayout(layout);
  260. QLabel *icon = new QLabel;
  261. icon->setFixedSize(QSize(g_appInfoPtr->m_fRate * 8, g_appInfoPtr->m_fRate * 8));
  262. icon->setPixmap(QPixmap(":/images/icon-et-iten-unpass.png").scaled(g_appInfoPtr->m_fRate * 8, g_appInfoPtr->m_fRate * 8));
  263. layout->addWidget(icon);
  264. layout->addStretch();
  265. ui->tablewt_envTest->setCellWidget(i, 2, widget);
  266. m_nUploadStatus = 0;
  267. }
  268. int etMobileTest::getCheckStatus()
  269. {
  270. return m_nUploadStatus;
  271. }