etMobileTest.cpp 14 KB

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