wxAnswer.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. #include "wxAnswer.h"
  2. #include "ui_wxAnswer.h"
  3. #include "CAppInfo.h"
  4. #include "awMsgBox.h"
  5. #include "CQREncode.h"
  6. #include "awMsgBox.h"
  7. #include <QDesktopWidget>
  8. #include "CAudioPlayerProc.h"
  9. #include <QFile>
  10. #include <QFileInfo>
  11. #include <QSettings>
  12. wxAnswer::wxAnswer(QString sAnswerType, int nOrder, QWidget *parent) :
  13. CBaseWidget(parent),
  14. ui(new Ui::wxAnswer), m_nOrder(nOrder), m_sAnswerType(sAnswerType)
  15. {
  16. ui->setupUi(this);
  17. setStyleSheet(g_appInfoPtr->m_sQssStr);
  18. qRegisterMetaType<CGetWXQrCode>("CGetWXQrCode");
  19. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetWXQrCode, this, &wxAnswer::onGetWXQrCode);
  20. qRegisterMetaType<CSaveUploadedFileAcknowledgeStatus>("CSaveUploadedFileAcknowledgeStatus");
  21. connect(g_httpBllPtr.get(), &CHttpBll::sgnSaveUploadedFileAcknowledgeStatus, this, &wxAnswer::onSaveUploadedFileAcknowledgeStatus);
  22. qRegisterMetaType<CDownLoadFileInfo>("CDownLoadFileInfo");
  23. connect(g_httpBllPtr.get(), &CHttpBll::sgnDownLoadFile, this, &wxAnswer::onDownLoadFile);
  24. qRegisterMetaType<CGetWXUploadedFile>("CGetWXUploadedFile");
  25. connect(g_httpBllPtr.get(), &CHttpBll::sgnGetWXUploadedFile, this, &wxAnswer::onGetWXUploadedFile);
  26. if (g_websocketPtr == nullptr)
  27. {
  28. g_websocketPtr = std::make_shared<CWebsocketProc>();
  29. }
  30. if(!g_websocketPtr->isConnected())
  31. {
  32. g_websocketPtr->open(QString("wss://%1:%2/api/ws/fileAnswer")
  33. .arg(g_appInfoPtr->m_sHttpServer).arg(g_appInfoPtr->m_sHttpPort),
  34. g_httpBllPtr->getToken(), g_httpBllPtr->getKey());
  35. }
  36. connect(g_websocketPtr.get(), &CWebsocketProc::mobileStatus, this, &wxAnswer::onMobileStatus);
  37. connect(g_websocketPtr.get(), &CWebsocketProc::fileAnswer, this, &wxAnswer::onFileAnswer);
  38. // if(m_picList == nullptr)
  39. // {
  40. // if(m_picList == nullptr)
  41. // {
  42. // m_picList = std::make_shared<wPictureList>(g_appInfoPtr->m_fRate*108, g_appInfoPtr->m_fRate*10, ui->widget_wxa);
  43. // }
  44. // connect(m_picList.get(), &wPictureList::picChange, this, [&](){
  45. // int nHeight = m_picList->setUI(g_appInfoPtr->m_fRate*30, ui->label_wxa_qrcode->y() + ui->label_wxa_qrcode->height() + g_appInfoPtr->m_fRate*20,
  46. // ui->widget_wxa->width() - g_appInfoPtr->m_fRate*30*2);
  47. // ui->btn_wxa_comfirm->setGeometry((ui->widget_wxa->width() - g_appInfoPtr->m_fRate*120)/2, m_picList->y() + m_picList->height() + g_appInfoPtr->m_fRate*30,
  48. // g_appInfoPtr->m_fRate*120, g_appInfoPtr->m_fRate*40);
  49. // ui->widget_wxa->setGeometry((width() - g_appInfoPtr->m_fRate*760)/2, (height() - (ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate*30))/2,
  50. // g_appInfoPtr->m_fRate*760, ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate*30);
  51. // m_picList->show();
  52. // if(m_picList->itemCount() > 5)
  53. // {
  54. // ui->label_wxa_qrcode->setVisible(false);
  55. // }
  56. // else
  57. // {
  58. // ui->label_wxa_qrcode->setVisible(true);
  59. // }
  60. // });
  61. // }
  62. CHttpRequestPackage hrp;
  63. hrp.sUri = "/api/ecs_oe_student/examControl/getQrCode";
  64. hrp.nRequestType = RequestType::rtGetWXQrCode;
  65. Json::Value jBody = Json::Value::null;
  66. jBody["examRecordDataId"] = g_appInfoPtr->m_oExamInfo.nExamRecordDataId;
  67. jBody["order"] = nOrder;
  68. if(sAnswerType == "SINGLE_AUDIO")
  69. {
  70. jBody["transferFileType"] = "AUDIO";
  71. }
  72. else
  73. {
  74. jBody["transferFileType"] = "PIC";
  75. }
  76. jBody["testEnv"] = false;
  77. hrp.sParamList.push_back(QString("CustomBody,%1").arg(jBody.toStyledString().c_str()));
  78. hrp.eParamType = HttpParamType::hptCustomBody;
  79. g_httpBllPtr->post(hrp);
  80. QFileInfo file("coe.cfgi");
  81. QString sFilePath = file.absoluteFilePath();
  82. QSettings set(sFilePath, QSettings::IniFormat);
  83. m_nPlayVol = set.value("config/playVol", 100).toInt();
  84. ui->hslider_etvt_volume->setValue(m_nPlayVol);
  85. if (g_audioPalyerPtr == nullptr)
  86. {
  87. g_audioPalyerPtr = std::make_shared<CAudioPlayerProc>();
  88. }
  89. m_pTimer = std::make_shared<QTimer>();
  90. m_pTimer->setInterval(1000);
  91. connect(m_pTimer.get(), &QTimer::timeout, this, [&]() {
  92. ui->hslider_etvt_voice->setValue(ui->hslider_etvt_voice->value() + 1);
  93. if (ui->hslider_etvt_voice->value() >= m_nAudioSecord)
  94. {
  95. m_pTimer->stop();
  96. g_audioPalyerPtr->stopPlay();
  97. }
  98. else
  99. {
  100. std::string sDeciceName = "";
  101. if (!g_audioPalyerPtr->getDeviceinfo(sDeciceName))
  102. {
  103. m_pTimer->stop();
  104. QString sErrorStr = g_audioPalyerPtr->getErrMsg();
  105. ShowMsg(sErrorStr, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  106. }
  107. if (sDeciceName != m_sRecordDevice)
  108. {
  109. ShowMsg(QString::fromLocal8Bit("播放设备拔出,请检查设备!"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  110. // myDebug()<<QString::fromLocal8Bit("播放设备拔出,请检查设备!");
  111. }
  112. }
  113. });
  114. m_pRefreshTimer = std::make_shared<QTimer>();
  115. m_pRefreshTimer->setInterval(1000);
  116. connect(m_pRefreshTimer.get(), &QTimer::timeout, this, [&]() {
  117. --m_nRefreshSeconds;
  118. ui->btn_refresh->setText(QString::fromLocal8Bit("倒计时%1s").arg(m_nRefreshSeconds));
  119. if(m_nRefreshSeconds <= 0)
  120. {
  121. m_pRefreshTimer->stop();
  122. ui->btn_refresh->setEnabled(true);
  123. ui->btn_refresh->setText(QString::fromLocal8Bit("刷新"));
  124. }
  125. });
  126. }
  127. wxAnswer::~wxAnswer()
  128. {
  129. QFileInfo file("coe.cfgi");
  130. QString sFilePath = file.absoluteFilePath();
  131. QSettings set(sFilePath, QSettings::IniFormat);
  132. set.setValue("config/playVol", m_nPlayVol);
  133. delete ui;
  134. }
  135. int wxAnswer::setUI(const int nWidth)
  136. {
  137. if(m_sAnswerType == "SINGLE_AUDIO")
  138. {
  139. ui->label_wxa_title->setVisible(false);
  140. ui->btn_wxa_close->setVisible(false);
  141. ui->label_HLine->setVisible(false);
  142. ui->btn_wxa_comfirm->setVisible(false);
  143. setGeometry(0, 0, nWidth, g_appInfoPtr->m_fRate*340);
  144. ui->widget_bg->setGeometry(0, 0, width(), height());
  145. ui->widget_wxa->setGeometry(0, 0, width(), height());
  146. ui->label_wxa_qrcode->setGeometry(0, 0,
  147. g_appInfoPtr->m_fRate*180, g_appInfoPtr->m_fRate*180);
  148. ui->label_wxa_tips->setFixedWidth(g_appInfoPtr->m_fRate*490);
  149. ui->label_wxa_tips->setText(QString::fromLocal8Bit(R"(<html>
  150. <style>
  151. p{
  152. font-family: "Microsoft YaHei";
  153. font-size: %1px;
  154. font-weight: 400;
  155. color: #717171;
  156. }
  157. span
  158. {
  159. font-family: Microsoft YaHei;
  160. font-size: %2px;
  161. font-weight: 400;
  162. color: #13BA8C;
  163. }
  164. </style>
  165. <body>
  166. <p>
  167. 请使用<span>微信</span>扫描二维码后,在微信小程序上录音,并上传文件。
  168. </p>
  169. <p>
  170. 上传期间,请勿关闭二维码。
  171. </p>
  172. </body>
  173. </html>
  174. )").arg((int)(g_appInfoPtr->m_fRate*24)).arg((int)(g_appInfoPtr->m_fRate*24)));
  175. ui->label_wxa_tips->adjustSize();
  176. ui->label_wxa_tips->setGeometry(ui->label_wxa_qrcode->x() + ui->label_wxa_qrcode->width() + g_appInfoPtr->m_fRate*30,
  177. ui->label_wxa_qrcode->y(), g_appInfoPtr->m_fRate*490, ui->label_wxa_tips->height());
  178. ui->label_wxa_statusIcon->setGeometry(ui->label_wxa_tips->x(), ui->label_wxa_tips->y() + ui->label_wxa_tips->height() + g_appInfoPtr->m_fRate*30,
  179. g_appInfoPtr->m_fRate*28, g_appInfoPtr->m_fRate*28);
  180. ui->label_wxa_status->setFixedWidth(g_appInfoPtr->m_fRate*490);
  181. ui->label_wxa_status->adjustSize();
  182. ui->label_wxa_status->setGeometry(ui->label_wxa_statusIcon->x() + ui->label_wxa_statusIcon->width() + g_appInfoPtr->m_fRate*10,
  183. ui->label_wxa_statusIcon->y() + (ui->label_wxa_statusIcon->height() - ui->label_wxa_status->height())/2,
  184. ui->label_wxa_status->width(), ui->label_wxa_status->height());
  185. ui->label_wxa_answerTips->adjustSize();
  186. ui->label_wxa_answerTips->setGeometry(ui->label_wxa_qrcode->x(), ui->label_wxa_qrcode->y() + ui->label_wxa_qrcode->height() + g_appInfoPtr->m_fRate*20,
  187. ui->label_wxa_answerTips->width(), ui->label_wxa_answerTips->height());
  188. ui->widget_etvt_voice->setVisible(false);
  189. ui->widget_etvt_voice->setGeometry(ui->label_wxa_answerTips->x() + ui->label_wxa_answerTips->width() + g_appInfoPtr->m_fRate*10,
  190. ui->label_wxa_answerTips->y(),
  191. g_appInfoPtr->m_fRate*423, g_appInfoPtr->m_fRate*40);
  192. ui->btn_etvt_play->setGeometry(g_appInfoPtr->m_fRate*8, (ui->widget_etvt_voice->height() - g_appInfoPtr->m_fRate*24)/2,
  193. g_appInfoPtr->m_fRate*24, g_appInfoPtr->m_fRate*24);
  194. ui->hslider_etvt_voice->setGeometry(ui->btn_etvt_play->x() + ui->btn_etvt_play->width() + g_appInfoPtr->m_fRate*21,
  195. (ui->widget_etvt_voice->height() - g_appInfoPtr->m_fRate*16)/2,
  196. g_appInfoPtr->m_fRate*224, g_appInfoPtr->m_fRate*12);
  197. ui->btn_etvt_volume->setGeometry(ui->hslider_etvt_voice->x() + ui->hslider_etvt_voice->width() + g_appInfoPtr->m_fRate*20,
  198. ui->btn_etvt_play->y(), ui->btn_etvt_play->width(), ui->btn_etvt_play->height());
  199. ui->hslider_etvt_volume->setGeometry(ui->btn_etvt_volume->x() + ui->btn_etvt_volume->width() + g_appInfoPtr->m_fRate * 10, ui->hslider_etvt_voice->y(),
  200. g_appInfoPtr->m_fRate*50, ui->hslider_etvt_voice->height());
  201. }
  202. else
  203. {
  204. if(m_picList == nullptr)
  205. {
  206. if(m_picList == nullptr)
  207. {
  208. m_picList = std::make_shared<wPictureList>(g_appInfoPtr->m_fRate*108, g_appInfoPtr->m_fRate*10, ui->widget_wxa);
  209. }
  210. connect(m_picList.get(), &wPictureList::picChange, this, [&](){
  211. int nHeight = m_picList->setUI(g_appInfoPtr->m_fRate*30, ui->label_wxa_qrcode->y() + ui->label_wxa_qrcode->height() + g_appInfoPtr->m_fRate*20,
  212. ui->widget_wxa->width() - g_appInfoPtr->m_fRate*30*2);
  213. ui->btn_wxa_comfirm->setGeometry((ui->widget_wxa->width() - g_appInfoPtr->m_fRate*120)/2, m_picList->y() + m_picList->height() + g_appInfoPtr->m_fRate*30,
  214. g_appInfoPtr->m_fRate*120, g_appInfoPtr->m_fRate*40);
  215. ui->widget_wxa->setGeometry((width() - g_appInfoPtr->m_fRate*760)/2, (height() - (ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate*30))/2,
  216. g_appInfoPtr->m_fRate*760, ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate*30);
  217. m_picList->show();
  218. if(m_picList->itemCount() > 5)
  219. {
  220. ui->label_wxa_qrcode->setVisible(false);
  221. }
  222. else
  223. {
  224. ui->label_wxa_qrcode->setVisible(true);
  225. }
  226. });
  227. }
  228. ui->widget_bg->setStyleSheet(QString(R"(QWidget#widget_bg
  229. {
  230. background:rgba(89,89,89,0.8);
  231. })"));
  232. ui->widget_wxa->setStyleSheet(QString(R"(QWidget#widget_wxa
  233. {
  234. border-radius:%1px;
  235. background:rgba(255,255,255,1);
  236. })").arg((int)(g_appInfoPtr->m_fRate*16)));
  237. ui->label_wxa_answerTips->setVisible(false);
  238. ui->widget_etvt_voice->setVisible(false);
  239. ui->btn_etvt_play->setVisible(false);
  240. ui->hslider_etvt_voice->setVisible(false);
  241. ui->btn_etvt_volume->setVisible(false);
  242. QDesktopWidget *dekwiget = QApplication::desktop();
  243. setGeometry(0, 0, dekwiget->width(), dekwiget->height());
  244. ui->widget_bg->setGeometry(0, 0, width(), height());
  245. ui->widget_wxa->setGeometry((width() - g_appInfoPtr->m_fRate*760)/2, (height() - g_appInfoPtr->m_fRate*395)/2, g_appInfoPtr->m_fRate*760, g_appInfoPtr->m_fRate*395);
  246. ui->label_wxa_title->adjustSize();
  247. ui->label_wxa_title->setGeometry(g_appInfoPtr->m_fRate*20, g_appInfoPtr->m_fRate*16,
  248. ui->label_wxa_title->width(), ui->label_wxa_title->height());
  249. ui->btn_wxa_close->setGeometry(ui->widget_wxa->width() - g_appInfoPtr->m_fRate*(20+16), g_appInfoPtr->m_fRate*19, g_appInfoPtr->m_fRate*16, g_appInfoPtr->m_fRate*16);
  250. ui->label_HLine->setGeometry(0, g_appInfoPtr->m_fRate*54, ui->widget_wxa->width(), g_appInfoPtr->m_fRate*1 < 1 ? 1 : g_appInfoPtr->m_fRate*1);
  251. ui->label_wxa_qrcode->setGeometry(g_appInfoPtr->m_fRate*30, ui->label_HLine->y() + ui->label_HLine->height() + g_appInfoPtr->m_fRate*30,
  252. g_appInfoPtr->m_fRate*180, g_appInfoPtr->m_fRate*180);
  253. ui->label_wxa_tips->setFixedWidth(g_appInfoPtr->m_fRate*490);
  254. ui->label_wxa_tips->setText(QString::fromLocal8Bit(R"(<html>
  255. <style>
  256. p{
  257. font-family: "Microsoft YaHei";
  258. font-size: %1px;
  259. font-weight: 400;
  260. color: #717171;
  261. }
  262. span
  263. {
  264. font-family: Microsoft YaHei;
  265. font-size: %2px;
  266. font-weight: 400;
  267. color: #13BA8C;
  268. }
  269. </style>
  270. <body>
  271. <p>
  272. 请使用<span>微信</span>扫描二维码后,在微信小程序上拍照,并上传文件。
  273. </p>
  274. <p>
  275. 上传期间,请勿关闭二维码(图片上传最多支持6张)。
  276. </p>
  277. </body>
  278. </html>
  279. )").arg((int)(g_appInfoPtr->m_fRate*24)).arg((int)(g_appInfoPtr->m_fRate*24)));
  280. ui->label_wxa_tips->adjustSize();
  281. ui->label_wxa_tips->setGeometry(ui->label_wxa_qrcode->x() + ui->label_wxa_qrcode->width() + g_appInfoPtr->m_fRate*30,
  282. ui->label_wxa_qrcode->y(), g_appInfoPtr->m_fRate*490, ui->label_wxa_tips->height());
  283. ui->label_wxa_statusIcon->setGeometry(ui->label_wxa_tips->x(), ui->label_wxa_tips->y() + ui->label_wxa_tips->height() + g_appInfoPtr->m_fRate*20,
  284. g_appInfoPtr->m_fRate*28, g_appInfoPtr->m_fRate*28);
  285. ui->label_wxa_status->setFixedWidth(g_appInfoPtr->m_fRate*490);
  286. ui->label_wxa_status->adjustSize();
  287. ui->label_wxa_status->setGeometry(ui->label_wxa_statusIcon->x() + ui->label_wxa_statusIcon->width() + g_appInfoPtr->m_fRate*10,
  288. ui->label_wxa_statusIcon->y() + (ui->label_wxa_statusIcon->height() - ui->label_wxa_status->height())/2,
  289. ui->label_wxa_status->width(), ui->label_wxa_status->height());
  290. ui->btn_refresh->setGeometry(g_appInfoPtr->m_fRate*20, ui->widget_wxa->height() - g_appInfoPtr->m_fRate*(30 + 30),
  291. g_appInfoPtr->m_fRate*80, g_appInfoPtr->m_fRate*30);
  292. ui->label_refreshTip->adjustSize();
  293. ui->label_refreshTip->setGeometry(ui->btn_refresh->x() + ui->btn_refresh->width() + g_appInfoPtr->m_fRate*10, ui->btn_refresh->y() + ui->btn_refresh->height()/2 - ui->label_refreshTip->height()/2,
  294. ui->label_refreshTip->width(), ui->label_refreshTip->height());
  295. ui->btn_wxa_comfirm->setGeometry((ui->widget_wxa->width() - g_appInfoPtr->m_fRate*120)/2, ui->widget_wxa->height() - g_appInfoPtr->m_fRate*(30 + 40),
  296. g_appInfoPtr->m_fRate*120, g_appInfoPtr->m_fRate*40);
  297. }
  298. ui->label_wxa_statusIcon->setVisible(false);
  299. ui->label_wxa_status->setVisible(false);
  300. return height();
  301. }
  302. void wxAnswer::onGetWXQrCode(CGetWXQrCode getWXQrCode)
  303. {
  304. if (getWXQrCode.nCode == 200)
  305. {
  306. ui->label_wxa_qrcode->setPixmap(CQREncode::GenerateQRcode(QString("%1%2")
  307. .arg(getWXQrCode.sUrl).arg(QByteArray(("&apiServer=" + g_httpBllPtr->getHttpUrl()).toLocal8Bit()).toPercentEncoding().data()), ui->label_wxa_qrcode->width()));
  308. }
  309. else
  310. {
  311. if(getWXQrCode.sMessage.isEmpty())
  312. {
  313. ShowMsg(QString::fromLocal8Bit("获取二维码失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  314. }
  315. else
  316. {
  317. ShowMsg(getWXQrCode.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  318. }
  319. }
  320. }
  321. QString wxAnswer::getFileUrl()
  322. {
  323. return m_sFileUrl;
  324. }
  325. void wxAnswer::setPics(QString sFileUrls)
  326. {
  327. if (sFileUrls.isEmpty())
  328. {
  329. return;
  330. }
  331. m_sFileUrl = sFileUrls;
  332. if(m_picList == nullptr)
  333. {
  334. m_picList = std::make_shared<wPictureList>(g_appInfoPtr->m_fRate*108, g_appInfoPtr->m_fRate*10, ui->widget_wxa);
  335. }
  336. m_picList->clearPic();
  337. if (!sFileUrls.isEmpty())
  338. {
  339. QStringList fileList = sFileUrls.split(",");
  340. for (QString sFile : fileList)
  341. {
  342. m_picList->AddPic(sFile);
  343. }
  344. }
  345. int nHeight = m_picList->setUI(g_appInfoPtr->m_fRate * 30, ui->label_wxa_qrcode->y() + ui->label_wxa_qrcode->height() + g_appInfoPtr->m_fRate * 20,
  346. ui->widget_wxa->width() - g_appInfoPtr->m_fRate * 30 * 2);
  347. ui->btn_wxa_comfirm->setGeometry((ui->widget_wxa->width() - g_appInfoPtr->m_fRate * 120) / 2, m_picList->y() + m_picList->height() + g_appInfoPtr->m_fRate * 30,
  348. g_appInfoPtr->m_fRate * 120, g_appInfoPtr->m_fRate * 40);
  349. ui->widget_wxa->setGeometry((width() - g_appInfoPtr->m_fRate * 760) / 2, (height() - (ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate * 30)) / 2,
  350. g_appInfoPtr->m_fRate * 760, ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate * 30);
  351. m_picList->show();
  352. }
  353. void wxAnswer::onMobileStatus(__int64 nExamRecordDataId, int nOrder, QString sScanStatus)
  354. {
  355. if (sScanStatus == "SCANNED" && nOrder == m_nOrder)
  356. {
  357. ui->label_wxa_statusIcon->setVisible(true);
  358. ui->label_wxa_status->setVisible(true);
  359. ui->label_wxa_status->setText(QString::fromLocal8Bit("已扫码"));
  360. }
  361. }
  362. void wxAnswer::onFileAnswer(__int64 nExamRecordDataId, int nOrder, QString sFileType, QString sFileUrl)
  363. {
  364. if(nOrder == m_nOrder)
  365. {
  366. CHttpRequestPackage hrp;
  367. hrp.sUri = "/api/ecs_oe_student/examControl/saveUploadedFileAcknowledgeStatus";
  368. hrp.nRequestType = RequestType::rtSaveUploadedFileAcknowledgeStatus;
  369. Json::Value jBody = Json::Value::null;
  370. jBody["examRecordDataId"] = nExamRecordDataId;
  371. jBody["order"] = nOrder;
  372. jBody["filePath"] = sFileUrl.toStdString();
  373. jBody["acknowledgeStatus"] = "CONFIRMED";
  374. hrp.sParamList.push_back(QString("CustomBody,%1").arg(jBody.toStyledString().c_str()));
  375. hrp.sCommonStr = sFileUrl;
  376. hrp.eParamType = HttpParamType::hptCustomBody;
  377. g_httpBllPtr->post(hrp);
  378. if(m_sAnswerType == "SINGLE_AUDIO")
  379. {
  380. m_sFileUrl = sFileUrl;
  381. {
  382. QString sFileName = sFileUrl.right(sFileUrl.length() - sFileUrl.lastIndexOf("/") - 1);
  383. sFileName = g_appInfoPtr->m_sCacheFileDir + sFileName;
  384. CHttpRequestPackage hrp;
  385. hrp.sUri = sFileUrl;
  386. hrp.sCommonStr = sFileName;
  387. hrp.sCommonStr1 = __FILE__;
  388. hrp.nRequestType = RequestType::rtDownLoadFile;
  389. hrp.nRetryCount = 3;
  390. g_httpBllPtr->downLoad(hrp);
  391. }
  392. }
  393. else
  394. {
  395. if(m_picList == nullptr)
  396. {
  397. m_picList = std::make_shared<wPictureList>(g_appInfoPtr->m_fRate*108, g_appInfoPtr->m_fRate*10, ui->widget_wxa);
  398. }
  399. QStringList fileList;
  400. if(!sFileUrl.isEmpty())
  401. {
  402. fileList = sFileUrl.split(",");
  403. for (QString sFile : fileList)
  404. {
  405. m_picList->AddPic(sFile);
  406. }
  407. }
  408. if(m_picList->itemCount() > 5)
  409. {
  410. ui->label_wxa_qrcode->setVisible(false);
  411. }
  412. int nHeight = m_picList->setUI(g_appInfoPtr->m_fRate*30, ui->label_wxa_qrcode->y() + ui->label_wxa_qrcode->height() + g_appInfoPtr->m_fRate*20,
  413. ui->widget_wxa->width() - g_appInfoPtr->m_fRate*30*2);
  414. ui->btn_wxa_comfirm->setGeometry((ui->widget_wxa->width() - g_appInfoPtr->m_fRate*120)/2, m_picList->y() + m_picList->height() + g_appInfoPtr->m_fRate*30,
  415. g_appInfoPtr->m_fRate*120, g_appInfoPtr->m_fRate*40);
  416. ui->widget_wxa->setGeometry((width() - g_appInfoPtr->m_fRate*760)/2, (height() - (ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate*30))/2,
  417. g_appInfoPtr->m_fRate*760, ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate*30);
  418. m_picList->show();
  419. }
  420. ui->label_wxa_status->setText(QString::fromLocal8Bit("已上传"));
  421. ShowMsg(QString::fromLocal8Bit("小程序作答已更新"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_information);
  422. }
  423. }
  424. void wxAnswer::onSaveUploadedFileAcknowledgeStatus(CSaveUploadedFileAcknowledgeStatus saveUploadedFileAcknowledgeStatus)
  425. {
  426. if (saveUploadedFileAcknowledgeStatus.nCode == 200)
  427. {
  428. if(m_sFileUrl == saveUploadedFileAcknowledgeStatus.sFileUrl)
  429. {
  430. if(m_sAnswerType == "SINGLE_AUDIO")
  431. {
  432. emit audioAnswered(m_sFileUrl);
  433. }
  434. /* else
  435. {
  436. emit picConfirm(m_sFileUrl);
  437. }*/
  438. }
  439. }
  440. else
  441. {
  442. if(saveUploadedFileAcknowledgeStatus.sMessage.isEmpty())
  443. {
  444. ShowMsg(QString::fromLocal8Bit("保存答案信息失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  445. }
  446. else
  447. {
  448. ShowMsg(saveUploadedFileAcknowledgeStatus.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  449. }
  450. }
  451. }
  452. void wxAnswer::setAnswer(QString sAnswer)
  453. {
  454. if (!sAnswer.isEmpty())
  455. {
  456. m_sFileUrl = sAnswer;
  457. QString sFileName = m_sFileUrl.right(m_sFileUrl.length() - m_sFileUrl.lastIndexOf("/") - 1);
  458. sFileName = g_appInfoPtr->m_sCacheFileDir + sFileName;
  459. CHttpRequestPackage hrp;
  460. hrp.sUri = m_sFileUrl;
  461. hrp.sCommonStr = sFileName;
  462. hrp.sCommonStr1 = __FILE__;
  463. hrp.nRequestType = RequestType::rtDownLoadFile;
  464. hrp.nRetryCount = 3;
  465. g_httpBllPtr->downLoad(hrp);
  466. }
  467. }
  468. int wxAnswer::widgetType()
  469. {
  470. return wt_WXAnswer;
  471. }
  472. void wxAnswer::onDownLoadFile(CDownLoadFileInfo downLoadFileInfo)
  473. {
  474. QString sFileName = m_sFileUrl.right(m_sFileUrl.length() - m_sFileUrl.lastIndexOf("/") - 1);
  475. sFileName = g_appInfoPtr->m_sCacheFileDir + sFileName;
  476. if (downLoadFileInfo.sFileName == sFileName &&
  477. downLoadFileInfo.sModuleName == __FILE__)
  478. {
  479. if (downLoadFileInfo.nCode == 200)
  480. {
  481. ui->label_wxa_answerTips->setText(QString::fromLocal8Bit("考生答案:"));
  482. ui->label_wxa_answerTips->adjustSize();
  483. ui->label_wxa_answerTips->setGeometry(ui->label_wxa_qrcode->x(), ui->label_wxa_qrcode->y() + ui->label_wxa_qrcode->height() + g_appInfoPtr->m_fRate*20,
  484. ui->label_wxa_answerTips->width(), ui->label_wxa_answerTips->height());
  485. ui->widget_etvt_voice->setVisible(true);
  486. ui->widget_etvt_voice->setGeometry(ui->label_wxa_answerTips->x() + ui->label_wxa_answerTips->width() + g_appInfoPtr->m_fRate*10,
  487. ui->label_wxa_answerTips->y(),
  488. g_appInfoPtr->m_fRate*423, g_appInfoPtr->m_fRate*40);
  489. }
  490. else
  491. {
  492. if(downLoadFileInfo.sMessage.isEmpty())
  493. {
  494. ShowMsg(QString::fromLocal8Bit("下载失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  495. }
  496. else
  497. {
  498. ShowMsg(downLoadFileInfo.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  499. }
  500. }
  501. }
  502. }
  503. void wxAnswer::on_btn_wxa_close_clicked()
  504. {
  505. emit exit();
  506. }
  507. void wxAnswer::on_btn_wxa_comfirm_clicked()
  508. {
  509. if (m_picList == nullptr)
  510. {
  511. emit exit();
  512. return;
  513. }
  514. m_sFileUrl = m_picList->getFileUrls();
  515. int nCount = m_sFileUrl.split(",").count();
  516. if(nCount > 6)
  517. {
  518. ShowMsg(QString::fromLocal8Bit("请删除多余的图片,图片总数不应该超过6张!"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  519. return;
  520. }
  521. emit picConfirm(m_sFileUrl);
  522. /* CHttpRequestPackage hrp;
  523. hrp.sUri = "/api/ecs_oe_student/examControl/saveUploadedFileAcknowledgeStatus";
  524. hrp.nRequestType = RequestType::rtSaveUploadedFileAcknowledgeStatus;
  525. Json::Value jBody = Json::Value::null;
  526. jBody["examRecordDataId"] = g_appInfoPtr->m_oExamInfo.nExamRecordDataId;
  527. jBody["order"] = m_nOrder;
  528. jBody["filePath"] = m_sFileUrl.toStdString();
  529. jBody["acknowledgeStatus"] = "CONFIRMED";
  530. hrp.sParamList.push_back(QString("CustomBody,%1").arg(jBody.toStyledString().c_str()));
  531. hrp.sCommonStr = m_sFileUrl;
  532. hrp.eParamType = HttpParamType::hptCustomBody;
  533. g_httpBllPtr->post(hrp);*/
  534. }
  535. void wxAnswer::on_btn_etvt_play_clicked()
  536. {
  537. QString sFileName = m_sFileUrl.right(m_sFileUrl.length() - m_sFileUrl.lastIndexOf("/") - 1);
  538. sFileName = g_appInfoPtr->m_sCacheFileDir + sFileName;
  539. if (QFile::exists(sFileName))
  540. {
  541. m_nAudioSecord = g_audioPalyerPtr->GetMediaDuration(sFileName);
  542. ui->hslider_etvt_voice->setMaximum(m_nAudioSecord);
  543. ui->hslider_etvt_voice->setValue(0);
  544. g_audioPalyerPtr->setVol(m_nPlayVol);
  545. if (!g_audioPalyerPtr->getDeviceinfo(m_sRecordDevice))
  546. {
  547. m_pTimer->stop();
  548. QString sErrorStr = g_audioPalyerPtr->getErrMsg();
  549. ShowMsg(sErrorStr, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  550. }
  551. g_audioPalyerPtr->playAudio(sFileName);
  552. m_pTimer->start();
  553. }
  554. }
  555. void wxAnswer::on_hslider_etvt_volume_valueChanged(int value)
  556. {
  557. m_nPlayVol = value;
  558. if (m_pTimer && m_pTimer->isActive())
  559. {
  560. g_audioPalyerPtr->setVol(m_nPlayVol);
  561. }
  562. }
  563. void wxAnswer::on_btn_etvt_volume_clicked()
  564. {
  565. if(m_bMute)
  566. {
  567. ui->btn_etvt_volume->setStyleSheet("border-image:url(:/images/btn-etvt-volume.png);");
  568. ui->hslider_etvt_volume->setValue(m_nLastVol);
  569. }
  570. else
  571. {
  572. ui->btn_etvt_volume->setStyleSheet("border-image:url(:/images/btn-etvt-mute.png);");
  573. m_nLastVol = ui->hslider_etvt_volume->value();
  574. ui->hslider_etvt_volume->setValue(0);
  575. }
  576. m_bMute = !m_bMute;
  577. }
  578. void wxAnswer::on_btn_refresh_clicked()
  579. {
  580. ui->btn_refresh->setEnabled(false);
  581. CHttpRequestPackage hrp;
  582. hrp.sUri = "/api/ecs_oe_student/examControl/getUploadedFile";
  583. hrp.nRequestType = RequestType::rtGetWXUploadedFile;
  584. hrp.sParamList.push_back(QString("examRecordDataId,%1").arg(g_appInfoPtr->m_oExamInfo.nExamRecordDataId));
  585. hrp.sParamList.push_back(QString("questionOrder,%1").arg(m_nOrder));
  586. hrp.eParamType = HttpParamType::hptUrl;
  587. g_httpBllPtr->post(hrp);
  588. m_pRefreshTimer->start();
  589. m_nRefreshSeconds = 20;
  590. ui->btn_refresh->setText(QString::fromLocal8Bit("倒计时%1s").arg(m_nRefreshSeconds));
  591. }
  592. void wxAnswer::onGetWXUploadedFile(CGetWXUploadedFile getWXUploadedFile)
  593. {
  594. if(getWXUploadedFile.nCode == 200)
  595. {
  596. if(getWXUploadedFile.sStatus == "UNCONFIRMED")
  597. {
  598. CHttpRequestPackage hrp;
  599. hrp.sUri = "/api/ecs_oe_student/examControl/saveUploadedFileAcknowledgeStatus";
  600. hrp.nRequestType = RequestType::rtSaveUploadedFileAcknowledgeStatus;
  601. Json::Value jBody = Json::Value::null;
  602. jBody["examRecordDataId"] = g_appInfoPtr->m_oExamInfo.nExamRecordDataId;
  603. jBody["order"] = m_nOrder;
  604. jBody["filePath"] = getWXUploadedFile.sFilePath.toStdString();
  605. jBody["acknowledgeStatus"] = "CONFIRMED";
  606. hrp.sParamList.push_back(QString("CustomBody,%1").arg(jBody.toStyledString().c_str()));
  607. hrp.sCommonStr = getWXUploadedFile.sFilePath;
  608. hrp.eParamType = HttpParamType::hptCustomBody;
  609. g_httpBllPtr->post(hrp);
  610. QString sFileUrl = getWXUploadedFile.sFilePath;
  611. if(m_sAnswerType == "SINGLE_AUDIO")
  612. {
  613. m_sFileUrl = sFileUrl;
  614. {
  615. QString sFileName = sFileUrl.right(sFileUrl.length() - sFileUrl.lastIndexOf("/") - 1);
  616. sFileName = g_appInfoPtr->m_sCacheFileDir + sFileName;
  617. CHttpRequestPackage hrp;
  618. hrp.sUri = sFileUrl;
  619. hrp.sCommonStr = sFileName;
  620. hrp.sCommonStr1 = __FILE__;
  621. hrp.nRequestType = RequestType::rtDownLoadFile;
  622. hrp.nRetryCount = 3;
  623. g_httpBllPtr->downLoad(hrp);
  624. }
  625. }
  626. else
  627. {
  628. if(m_picList == nullptr)
  629. {
  630. m_picList = std::make_shared<wPictureList>(g_appInfoPtr->m_fRate*108, g_appInfoPtr->m_fRate*10, ui->widget_wxa);
  631. }
  632. QStringList answerList = m_picList->getFileUrls().split(",");
  633. QStringList fileList;
  634. if(!sFileUrl.isEmpty())
  635. {
  636. fileList = sFileUrl.split(",");
  637. for (QString sFile : fileList)
  638. {
  639. if(answerList.indexOf(sFile) < 0)
  640. {
  641. m_picList->AddPic(sFile);
  642. }
  643. }
  644. }
  645. if(m_picList->itemCount() > 5)
  646. {
  647. ui->label_wxa_qrcode->setVisible(false);
  648. }
  649. int nHeight = m_picList->setUI(g_appInfoPtr->m_fRate*30, ui->label_wxa_qrcode->y() + ui->label_wxa_qrcode->height() + g_appInfoPtr->m_fRate*20,
  650. ui->widget_wxa->width() - g_appInfoPtr->m_fRate*30*2);
  651. ui->btn_refresh->setGeometry(g_appInfoPtr->m_fRate*20, ui->widget_wxa->height() - g_appInfoPtr->m_fRate*(30 + 30),
  652. g_appInfoPtr->m_fRate*80, g_appInfoPtr->m_fRate*30);
  653. ui->label_refreshTip->adjustSize();
  654. ui->label_refreshTip->setGeometry(ui->btn_refresh->x() + ui->btn_refresh->width() + g_appInfoPtr->m_fRate*10, ui->btn_refresh->y() + ui->btn_refresh->height()/2 - ui->label_refreshTip->height()/2,
  655. ui->label_refreshTip->width(), ui->label_refreshTip->height());
  656. ui->btn_wxa_comfirm->setGeometry((ui->widget_wxa->width() - g_appInfoPtr->m_fRate*120)/2, m_picList->y() + m_picList->height() + g_appInfoPtr->m_fRate*30,
  657. g_appInfoPtr->m_fRate*120, g_appInfoPtr->m_fRate*40);
  658. ui->widget_wxa->setGeometry((width() - g_appInfoPtr->m_fRate*760)/2, (height() - (ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate*30))/2,
  659. g_appInfoPtr->m_fRate*760, ui->btn_wxa_comfirm->y() + ui->btn_wxa_comfirm->height() + g_appInfoPtr->m_fRate*30);
  660. m_picList->show();
  661. }
  662. ui->label_wxa_status->setText(QString::fromLocal8Bit("已上传"));
  663. ShowMsg(QString::fromLocal8Bit("小程序作答已更新"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_information);
  664. }
  665. }
  666. else
  667. {
  668. if(getWXUploadedFile.sMessage.isEmpty())
  669. {
  670. ShowMsg(QString::fromLocal8Bit("同步拍照作答失败"), g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  671. }
  672. else
  673. {
  674. ShowMsg(getWXUploadedFile.sMessage, g_appInfoPtr->m_pAnsBgWidget, MSG_ICON_TYPE::mit_error);
  675. }
  676. }
  677. }