wxAnswer.cpp 28 KB

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