login.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. #include "login.h"
  2. #include "ui_login.h"
  3. #include <QFile>
  4. #include <QDesktopWidget>
  5. //#include <QAction>
  6. #include <QSettings>
  7. #include "CAppInfo.h"
  8. #include "CSqlite3DBProc.h"
  9. #include "logproc.h"
  10. #include "awMsgBox.h"
  11. #include "CCommonTools.h"
  12. #include "CLiveViodeProc.h"
  13. #include <QDateTime>
  14. #include "CKeyBoardHook.h"
  15. login::login(QWidget *parent)
  16. : QWidget(parent)
  17. , ui(new Ui::login)
  18. {
  19. ui->setupUi(this);
  20. setWindowFlags(Qt::FramelessWindowHint);
  21. m_loginType = LOGIN_TYPE::lt_studentCode;
  22. initParam();
  23. QDesktopWidget *dekwiget = QApplication::desktop();
  24. int nWidth = dekwiget->width();
  25. int nHeight = dekwiget->height();
  26. double fWRate = (double)nWidth/1280;
  27. double fHRate= (double)nHeight/800;
  28. double fRate = fWRate;
  29. if(fHRate < fWRate)
  30. {
  31. fRate = fHRate;
  32. }
  33. g_appInfoPtr->m_fRate = fRate;
  34. QFile qssFile(":/client.qss");
  35. qssFile.open(QFile::ReadOnly);
  36. QString qss;
  37. qss = qssFile.readAll();
  38. int RATE_BASE_SIZE1 = fRate < 1? 1 : fRate;
  39. int RATE_BASE_SIZE2 = 2*fRate;
  40. int RATE_BASE_SIZE3 = 3*fRate;
  41. int RATE_BASE_SIZE4 = 4*fRate;
  42. int RATE_BASE_SIZE5 = 5*fRate;
  43. int RATE_BASE_SIZE6 = 6*fRate;
  44. int RATE_BASE_SIZE7 = 7*fRate;
  45. int RATE_BASE_SIZE8 = 8*fRate;
  46. int RATE_BASE_SIZE10 = 10*fRate;
  47. int RATE_BASE_SIZE11 = 11*fRate;
  48. int RATE_BASE_SIZE12 = 12*fRate;
  49. int RATE_BASE_SIZE14 = 14*fRate;
  50. int RATE_BASE_SIZE15 = 15 * fRate;
  51. int RATE_BASE_SIZE16 = 16*fRate;
  52. int RATE_BASE_SIZE18 = 18*fRate;
  53. int RATE_BASE_SIZE20 = 20*fRate;
  54. int RATE_BASE_SIZE22 = 22*fRate;
  55. int RATE_BASE_SIZE24 = 24*fRate;
  56. int RATE_BASE_SIZE26 = 26*fRate;
  57. int RATE_BASE_SIZE30 = 30*fRate;
  58. int RATE_BASE_SIZE35 = 35*fRate;
  59. int RATE_BASE_SIZE39 = 39*fRate;
  60. int RATE_BASE_SIZE40 = 40*fRate;
  61. int RATE_BASE_SIZE48 = 48*fRate;
  62. int RATE_BASE_SIZE52 = 52*fRate;
  63. int RATE_BASE_SIZE76 = 76*fRate;
  64. int RATE_BASE_SIZE86 = 86*fRate;
  65. qss.replace("RATE_BASE_SIZE11", QString::number(RATE_BASE_SIZE11));
  66. qss.replace("RATE_BASE_SIZE12", QString::number(RATE_BASE_SIZE12));
  67. qss.replace("RATE_BASE_SIZE14", QString::number(RATE_BASE_SIZE14));
  68. qss.replace("RATE_BASE_SIZE15", QString::number(RATE_BASE_SIZE15));
  69. qss.replace("RATE_BASE_SIZE16", QString::number(RATE_BASE_SIZE16));
  70. qss.replace("RATE_BASE_SIZE18", QString::number(RATE_BASE_SIZE18));
  71. qss.replace("RATE_BASE_SIZE20", QString::number(RATE_BASE_SIZE20));
  72. qss.replace("RATE_BASE_SIZE22", QString::number(RATE_BASE_SIZE22));
  73. qss.replace("RATE_BASE_SIZE24", QString::number(RATE_BASE_SIZE24));
  74. qss.replace("RATE_BASE_SIZE26", QString::number(RATE_BASE_SIZE26));
  75. qss.replace("RATE_BASE_SIZE30", QString::number(RATE_BASE_SIZE30));
  76. qss.replace("RATE_BASE_SIZE35", QString::number(RATE_BASE_SIZE35));
  77. qss.replace("RATE_BASE_SIZE39", QString::number(RATE_BASE_SIZE39));
  78. qss.replace("RATE_BASE_SIZE40", QString::number(RATE_BASE_SIZE40));
  79. qss.replace("RATE_BASE_SIZE48", QString::number(RATE_BASE_SIZE48));
  80. qss.replace("RATE_BASE_SIZE52", QString::number(RATE_BASE_SIZE52));
  81. qss.replace("RATE_BASE_SIZE76", QString::number(RATE_BASE_SIZE76));
  82. qss.replace("RATE_BASE_SIZE86", QString::number(RATE_BASE_SIZE86));
  83. qss.replace("RATE_BASE_SIZE10", QString::number(RATE_BASE_SIZE10));
  84. qss.replace("RATE_BASE_SIZE8", QString::number(RATE_BASE_SIZE8));
  85. qss.replace("RATE_BASE_SIZE7", QString::number(RATE_BASE_SIZE7));
  86. qss.replace("RATE_BASE_SIZE6", QString::number(RATE_BASE_SIZE6));
  87. qss.replace("RATE_BASE_SIZE5", QString::number(RATE_BASE_SIZE5));
  88. qss.replace("RATE_BASE_SIZE4", QString::number(RATE_BASE_SIZE4));
  89. qss.replace("RATE_BASE_SIZE3", QString::number(RATE_BASE_SIZE3));
  90. qss.replace("RATE_BASE_SIZE2", QString::number(RATE_BASE_SIZE2));
  91. qss.replace("RATE_BASE_SIZE1", QString::number(RATE_BASE_SIZE1));
  92. g_appInfoPtr->m_sQssStr = qss;
  93. setStyleSheet(qss);
  94. qDebug()<<qss;
  95. ui->widget_BG->setVisible(false);
  96. setGeometry(0, 0, dekwiget->width(), dekwiget->height());
  97. m_pCourseList = nullptr;
  98. m_pLoading = std::make_shared<awResumeExam>(this, QString::fromLocal8Bit("程序加载中..."));
  99. m_pLoading->show();
  100. qRegisterMetaType<CStudentClientConfig>("CStudentClientConfig");
  101. connect(g_httpBllPtr.get(), &CHttpBll::sgnStudentClientConfig, this, &login::onStudentClientConfig);
  102. qRegisterMetaType<CLoginLimit>("CLoginLimit");
  103. connect(g_httpBllPtr.get(), &CHttpBll::sgnLoginLimit, this, &login::onLoginLimit);
  104. qRegisterMetaType<CLoginInfo>("CLoginInfo");
  105. connect(g_httpBllPtr.get(), &CHttpBll::sgnLoginInfo, this, &login::onLoginInfo);
  106. qRegisterMetaType<CLogout>("CLogout");
  107. connect(g_httpBllPtr.get(), &CHttpBll::sgnLogout, this, &login::onLogout);
  108. qRegisterMetaType<CDownLoadFileInfo>("CDownLoadFileInfo");
  109. connect(g_httpBllPtr.get(), &CHttpBll::sgnDownLoadFile, this, &login::onDownLoadFile);
  110. connect(g_httpBllPtr.get(), &CHttpBll::sgnTokenExpired, this, &login::onTokenExpired);
  111. CHttpRequestPackage hrp;
  112. hrp.sUri = QString("https://%1/org_properties/byOrgDomain/%2.ecs.qmth.com.cn/studentClientConfig.json")
  113. .arg(g_appInfoPtr->m_sEscDomain).arg(g_appInfoPtr->m_sOrgPrefix);
  114. hrp.nRequestType = RequestType::rtStudentClientConfig;
  115. g_httpBllPtr->getUrl(hrp);
  116. g_clientVideoProcPtr = std::make_shared<CLiveViodeProc>();
  117. }
  118. login::~login()
  119. {
  120. awMsgBox::clear();
  121. delete ui;
  122. }
  123. void login::initParam()
  124. {
  125. //g_appInfoPtr = std::make_shared<CAppInfo>();
  126. g_sysDBProcPtr = std::make_shared<CSqlite3DBProc>();
  127. if(!g_sysDBProcPtr->OpenDB("data/sys.db"))
  128. {
  129. ShowMsg(QString::fromLocal8Bit("打开数据库失败!"), this, MSG_ICON_TYPE::mit_error);
  130. // myDebug()<<QString::fromLocal8Bit("打开数据库失败!");
  131. }
  132. sqlite3_stmt *stmt;
  133. QString sSql = QString("select name,ifnull(value,'') from t_param");
  134. if(!g_sysDBProcPtr->QuerySql(sSql.toStdString(), &stmt))
  135. {
  136. ShowMsg(QString::fromLocal8Bit("加载参数信息失败!"), this, MSG_ICON_TYPE::mit_error);
  137. // myDebug()<<QString::fromLocal8Bit("查询参数信息失败!");
  138. return;
  139. }
  140. QString sProjectName = "";
  141. QString sEndpoint = "";
  142. QString sLogstore = "";
  143. QString sHttpServer ="";
  144. QString sHttpPort = "";
  145. QString sWebsocketServer = "";
  146. QString sWebsocketPort = "";
  147. QString sUseHttps = "";
  148. int nField64 = 0;
  149. std::string sField = "";
  150. g_sysDBProcPtr->BeginGetFields(stmt);
  151. while(!g_sysDBProcPtr->Eof())
  152. {
  153. QString sName = g_sysDBProcPtr->GetFields(0, sField, stmt).c_str();
  154. QString sValue = g_sysDBProcPtr->GetFields(1, sField, stmt).c_str();
  155. if(sName == "log_project_name")
  156. {
  157. sProjectName = sValue;
  158. }
  159. else if(sName == "log_endpoint")
  160. {
  161. sEndpoint = sValue;
  162. }
  163. else if(sName == "log_store")
  164. {
  165. sLogstore = sValue;
  166. }
  167. else if(sName == "http_server")
  168. {
  169. sHttpServer = sValue;
  170. QStringList sVl = sValue.split(".");
  171. if (sVl.count() > 0)
  172. {
  173. g_appInfoPtr->m_sOrgPrefix = sVl[0];
  174. }
  175. }
  176. else if(sName == "http_port")
  177. {
  178. sHttpPort = sValue;
  179. }
  180. else if(sName == "websocket_server")
  181. {
  182. sWebsocketServer = sValue;
  183. }
  184. else if(sName == "websocket_port")
  185. {
  186. sWebsocketPort = sValue;
  187. }
  188. else if(sName == "use_https")
  189. {
  190. sUseHttps = sValue;
  191. }
  192. else if (sName == "esc_domain")
  193. {
  194. g_appInfoPtr->m_sEscDomain = sValue;
  195. }
  196. g_sysDBProcPtr->Next(stmt);
  197. }
  198. g_sysDBProcPtr->EndGetFields(stmt);
  199. if(sProjectName.isEmpty() || sEndpoint.isEmpty() || sLogstore.isEmpty())
  200. {
  201. //未配置日志参数
  202. }
  203. else
  204. {
  205. g_logPtr = std::make_shared<CLogTrack>(sProjectName, sEndpoint, sLogstore);
  206. }
  207. g_appInfoPtr->m_sHttpServer = sHttpServer;
  208. g_appInfoPtr->m_sHttpPort = sHttpPort;
  209. g_httpBllPtr = std::make_shared<CHttpBll>();
  210. if(sUseHttps == "1")
  211. {
  212. g_httpBllPtr->init(sHttpServer, sHttpPort, true);
  213. }
  214. else
  215. {
  216. g_httpBllPtr->init(sHttpServer, sHttpPort);
  217. }
  218. sSql = QString("select version_id,version_code,ifnull(machine_id,''),ifnull(update_time,'') from t_sysinfo");
  219. if (!g_sysDBProcPtr->QuerySql(sSql.toStdString(), &stmt))
  220. {
  221. ShowMsg(QString::fromLocal8Bit("加载参数信息失败!"), this, MSG_ICON_TYPE::mit_error);
  222. // myDebug()<<QString::fromLocal8Bit("查询参数信息失败!");
  223. return;
  224. }
  225. int nField = 0;
  226. g_sysDBProcPtr->BeginGetFields(stmt);
  227. if (!g_sysDBProcPtr->Eof())
  228. {
  229. g_appInfoPtr->m_nVersionId = g_sysDBProcPtr->GetFields(0, nField, stmt);
  230. g_appInfoPtr->m_sVersionCode = g_sysDBProcPtr->GetFields(1, sField, stmt).c_str();
  231. g_appInfoPtr->m_sMachineId = g_sysDBProcPtr->GetFields(2, sField, stmt).c_str();
  232. }
  233. g_sysDBProcPtr->EndGetFields(stmt);
  234. if (g_appInfoPtr->m_sMachineId == "")
  235. {
  236. if (CCommonTools::IsWow64())
  237. {
  238. QSettings settings(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography)", QSettings::Registry64Format);
  239. g_appInfoPtr->m_sMachineId = settings.value("MachineGuid", "").toString();
  240. }
  241. else
  242. {
  243. QSettings settings(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography)", QSettings::Registry32Format);
  244. g_appInfoPtr->m_sMachineId = settings.value("MachineGuid", "").toString();
  245. }
  246. if (g_appInfoPtr->m_sMachineId == "")
  247. {
  248. g_appInfoPtr->m_sMachineId = CCommonTools::getUuid();
  249. }
  250. sSql = QString("update t_sysinfo set machine_id = '%1'").arg(g_appInfoPtr->m_sMachineId);
  251. if (!g_sysDBProcPtr->ExcuteSql(sSql.toStdString()))
  252. {
  253. ShowMsg(QString::fromLocal8Bit("保存机器信息失败!"), this, MSG_ICON_TYPE::mit_error);
  254. //myDebug() << QString::fromLocal8Bit("保存机器信息失败!");
  255. return;
  256. }
  257. }
  258. }
  259. void login::initUI()
  260. {
  261. QDesktopWidget *dekwiget = QApplication::desktop();
  262. setGeometry(0, 0, dekwiget->width(), dekwiget->height());
  263. ui->widget_BG->setGeometry(0, 0, dekwiget->width(), dekwiget->height());
  264. ui->btn_close->setGeometry(width() - g_appInfoPtr->m_fRate*24, 0,
  265. g_appInfoPtr->m_fRate*24, g_appInfoPtr->m_fRate*24);
  266. ui->label_org_logo->setGeometry(g_appInfoPtr->m_fRate * 20, g_appInfoPtr->m_fRate * 20, g_appInfoPtr->m_fRate * 80, g_appInfoPtr->m_fRate * 80);
  267. ui->label_org_bg->setGeometry(0, g_appInfoPtr->m_fRate * (100+10), ui->widget_BG->width(), ui->widget_BG->height() - g_appInfoPtr->m_fRate*(100 + 10));
  268. ui->widget_loginBG->setGeometry((width() - g_appInfoPtr->m_fRate*800)/2, (height() - g_appInfoPtr->m_fRate*480)/2,
  269. g_appInfoPtr->m_fRate*800, g_appInfoPtr->m_fRate*480);
  270. ui->widget_orgInfo->setGeometry(0,0, g_appInfoPtr->m_fRate*300, ui->widget_loginBG->height());
  271. ui->label_orgTitle->adjustSize();
  272. ui->label_orgTitle->setGeometry((ui->widget_orgInfo->width() - ui->label_orgTitle->width())/2,
  273. g_appInfoPtr->m_fRate*42, ui->label_orgTitle->width(), ui->label_orgTitle->height());
  274. ui->widget_login->setGeometry(ui->widget_orgInfo->width(), 0, ui->widget_loginBG->width() - ui->widget_orgInfo->width(),
  275. ui->widget_loginBG->height());
  276. ui->label_complay->adjustSize();
  277. ui->label_complay->setGeometry(g_appInfoPtr->m_fRate*42, ui->widget_orgInfo->height() - g_appInfoPtr->m_fRate*42 - ui->label_complay->height(),
  278. ui->label_complay->width(), ui->label_complay->height());
  279. if(!g_appInfoPtr->m_sVersionCode.isEmpty())
  280. {
  281. ui->label_version->setText(QString("V%1").arg(g_appInfoPtr->m_sVersionCode));
  282. }
  283. ui->label_version->adjustSize();
  284. ui->label_version->setGeometry(ui->label_complay->x(), ui->label_complay->y() - g_appInfoPtr->m_fRate*5 - ui->label_version->height(),
  285. ui->label_version->width(), ui->label_version->height());
  286. ui->btn_studentCodeLogin->setGeometry(0, 0, ui->widget_login->width() / 2, g_appInfoPtr->m_fRate * 44);
  287. ui->btn_identityLogin->setGeometry(ui->btn_studentCodeLogin->width(), ui->btn_studentCodeLogin->y(),
  288. ui->btn_studentCodeLogin->width(), ui->btn_studentCodeLogin->height());
  289. if (m_loginType == LOGIN_TYPE::lt_identity)
  290. {
  291. ui->btn_identityLogin->setGeometry((ui->widget_login->width() - ui->btn_studentCodeLogin->width() )/ 2, ui->btn_studentCodeLogin->y(),
  292. ui->btn_studentCodeLogin->width(), ui->btn_studentCodeLogin->height());
  293. }
  294. if(m_nloginTypeCount < 2)
  295. {
  296. if(m_loginType == LOGIN_TYPE::lt_studentCode)
  297. {
  298. ui->btn_studentCodeLogin->setGeometry(0, 0, ui->widget_login->width(), g_appInfoPtr->m_fRate * 44);
  299. }
  300. if(m_loginType == LOGIN_TYPE::lt_identity)
  301. {
  302. ui->btn_identityLogin->setGeometry(0, 0, ui->widget_login->width(), g_appInfoPtr->m_fRate * 44);
  303. }
  304. }
  305. ui->label_loginTitle->adjustSize();
  306. ui->label_loginTitle->setGeometry((ui->widget_login->width() - ui->label_loginTitle->width())/2,
  307. ui->btn_studentCodeLogin->y() + ui->btn_studentCodeLogin->height() + g_appInfoPtr->m_fRate*50,
  308. ui->label_loginTitle->width(), ui->label_loginTitle->height());
  309. ui->edt_account->setGeometry((ui->widget_login->width() - g_appInfoPtr->m_fRate*300)/2,
  310. ui->label_loginTitle->y() + ui->label_loginTitle->height() + g_appInfoPtr->m_fRate*50,
  311. g_appInfoPtr->m_fRate*300, g_appInfoPtr->m_fRate*40);
  312. ui->edt_password->setGeometry(ui->edt_account->x(), ui->edt_account->y() + ui->edt_account->height() + g_appInfoPtr->m_fRate*30,
  313. ui->edt_account->width(), ui->edt_account->height());
  314. ui->btn_login->setGeometry(ui->edt_account->x(), ui->edt_password->y() + ui->edt_password->height() + g_appInfoPtr->m_fRate*40,
  315. ui->edt_account->width(), g_appInfoPtr->m_fRate*44);
  316. ui->widget_BG->setVisible(true);
  317. setBtnStyle();
  318. m_pLoading.reset();
  319. }
  320. void login::setBtnStyle()
  321. {
  322. if(m_loginType == LOGIN_TYPE::lt_studentCode)
  323. {
  324. ui->btn_studentCodeLogin->setStyleSheet(QString(R"(QPushButton
  325. {
  326. outline:none;
  327. font-size:%1px;
  328. font-family:"Microsoft YaHei";
  329. font-weight:400;
  330. color:rgba(19,187,138,1);
  331. background:rgba(255,255,255,1);
  332. border:0px;
  333. })").arg((int)(g_appInfoPtr->m_fRate*14)));
  334. ui->btn_identityLogin->setStyleSheet(QString(R"(QPushButton
  335. {
  336. outline:none;
  337. font-size:%1px;
  338. font-family:"Microsoft YaHei";
  339. font-weight:400;
  340. color:rgba(153,153,153,1);
  341. background:rgba(239,240,245,1);
  342. border-top-right-radius:%2px;
  343. })").arg((int)(g_appInfoPtr->m_fRate*14)).arg((int)(g_appInfoPtr->m_fRate*20)));
  344. }
  345. else
  346. {
  347. ui->btn_studentCodeLogin->setStyleSheet(QString(R"(QPushButton
  348. {
  349. outline:none;
  350. font-size:%1px;
  351. font-family:"Microsoft YaHei";
  352. font-weight:400;
  353. color:rgba(153,153,153,1);
  354. background:rgba(239,240,245,1);
  355. border:0px;
  356. })").arg((int)(g_appInfoPtr->m_fRate*14)));
  357. ui->btn_identityLogin->setStyleSheet(QString(R"(QPushButton
  358. {
  359. outline:none;
  360. font-size:%1px;
  361. font-family:"Microsoft YaHei";
  362. font-weight:400;
  363. color:rgba(19,187,138,1);
  364. background:rgba(255,255,255,1);
  365. border-top-right-radius:%2px;
  366. })").arg((int)(g_appInfoPtr->m_fRate*14))
  367. .arg((int)(ui->btn_studentCodeLogin->isVisible() ? g_appInfoPtr->m_fRate*20 : 0)));
  368. }
  369. }
  370. void login::on_btn_close_clicked()
  371. {
  372. close();
  373. }
  374. void login::onStudentClientConfig(CStudentClientConfig studentClientConfig)
  375. {
  376. if (studentClientConfig.nCode == 200)
  377. {
  378. ui->btn_studentCodeLogin->setVisible(false);
  379. ui->btn_identityLogin->setVisible(false);
  380. if (studentClientConfig.bStudentCodeLogin )
  381. {
  382. ++m_nloginTypeCount;
  383. ui->btn_studentCodeLogin->setVisible(true);
  384. ui->btn_studentCodeLogin->setText(studentClientConfig.sStudentCodeLoginAlias);
  385. m_loginType = LOGIN_TYPE::lt_studentCode;
  386. }
  387. else
  388. {
  389. m_loginType = LOGIN_TYPE::lt_identity;
  390. }
  391. if (studentClientConfig.bIdentifyNumberLogin)
  392. {
  393. ++m_nloginTypeCount;
  394. ui->btn_identityLogin->setVisible(true);
  395. ui->btn_identityLogin->setText(studentClientConfig.sIdentityNumberLoginAlias);
  396. }
  397. ui->label_loginTitle->setText(studentClientConfig.sOeStudentSysName);
  398. g_appInfoPtr->m_bDisableMutiScreen = studentClientConfig.bDisableMutiScreen;
  399. g_appInfoPtr->m_bDisableRemoteAssistance = studentClientConfig.bDisableRemoteAssistance;
  400. g_appInfoPtr->m_bFullScreenTop = studentClientConfig.bFullScreenTop;
  401. g_appInfoPtr->m_bDisableVirtualCamera = studentClientConfig.bDisableVirtualCamera;
  402. g_appInfoPtr->m_sRootOrgId = studentClientConfig.sRootOrgId;
  403. g_appInfoPtr->m_bShowQmthLogo = studentClientConfig.bShowQmthLogo;
  404. g_appInfoPtr->m_bShowStudentClientAppQrcode = studentClientConfig.bShowStudentClientAppQrcode;
  405. if(studentClientConfig.bIsCustomMenuLogo)
  406. {
  407. g_appInfoPtr->m_sMenuLogoUrl = studentClientConfig.sCusMenuLogoFileUrl;
  408. }
  409. initUI();
  410. if (!studentClientConfig.sStudentClientBgPictureUrl.isEmpty())
  411. {
  412. m_sStudentClientBgPictureUrl = studentClientConfig.sStudentClientBgPictureUrl;
  413. QString sFileName = m_sStudentClientBgPictureUrl.right(m_sStudentClientBgPictureUrl.length() - m_sStudentClientBgPictureUrl.lastIndexOf("/") - 1);
  414. sFileName = g_appInfoPtr->m_sCacheFileDir + sFileName;
  415. CHttpRequestPackage hrp;
  416. hrp.sUri = studentClientConfig.sStudentClientBgPictureUrl;
  417. hrp.sCommonStr = sFileName;
  418. hrp.sAdditionStr = "downloadAnswerSheet";
  419. hrp.sCommonStr1 = __FILE__;
  420. hrp.nRequestType = RequestType::rtDownLoadFile;
  421. hrp.nRetryCount = 3;
  422. g_httpBllPtr->downLoad(hrp);
  423. }
  424. if (!studentClientConfig.sLogoFileUrl.isEmpty())
  425. {
  426. m_sLogoFileUrl = studentClientConfig.sLogoFileUrl;
  427. QString sFileName = m_sLogoFileUrl.right(m_sLogoFileUrl.length() - m_sLogoFileUrl.lastIndexOf("/") - 1);
  428. sFileName = g_appInfoPtr->m_sCacheFileDir + sFileName;
  429. CHttpRequestPackage hrp;
  430. hrp.sUri = studentClientConfig.sLogoFileUrl;
  431. hrp.sCommonStr = sFileName;
  432. hrp.sCommonStr1 = __FILE__;
  433. hrp.nRequestType = RequestType::rtDownLoadFile;
  434. hrp.nRetryCount = 3;
  435. g_httpBllPtr->downLoad(hrp);
  436. }
  437. #ifdef _DEBUG
  438. g_appInfoPtr->m_bFullScreenTop = false;
  439. #endif // _DEBUG
  440. if(g_appInfoPtr->m_bFullScreenTop)
  441. {
  442. CCommonTools::topMostSlot(this, true);
  443. g_keyBoardHookPtr = std::make_shared<CKeyBoardHook>();
  444. g_keyBoardHookPtr->Hotkey_Install(0);
  445. }
  446. }
  447. else
  448. {
  449. ShowMsg(QString::fromLocal8Bit("获取系统参数失败,请检查网络连接!"), this, MSG_ICON_TYPE::mit_error);
  450. if (m_pLoading != nullptr)
  451. {
  452. m_pLoading.reset();
  453. }
  454. QTimer::singleShot(3000, this, [&](){close();});
  455. }
  456. }
  457. void login::on_btn_login_clicked()
  458. {
  459. if (ui->btn_studentCodeLogin->text().isEmpty() ||
  460. ui->btn_identityLogin->text().isEmpty())
  461. {
  462. ShowMsg(QString::fromLocal8Bit("请填写账号和密码"), this, MSG_ICON_TYPE::mit_error);
  463. return;
  464. }
  465. ui->btn_login->setEnabled(false);
  466. m_nRetryCount = 0;
  467. //登录限流
  468. CHttpRequestPackage hrp;
  469. hrp.sUri = QString("https://tcc.qmth.com.cn/rate_limit/prod/login/%1").arg(500);
  470. hrp.nRequestType = RequestType::rtLoginLimit;
  471. g_httpBllPtr->getUrl(hrp);
  472. }
  473. void login::onLoginLimit(CLoginLimit loginLimit)
  474. {
  475. if (loginLimit.nCode == 200)
  476. {
  477. ++m_nRetryCount;
  478. if (loginLimit.bPass)
  479. {
  480. //登录
  481. CHttpRequestPackage hrp;
  482. hrp.sUri = "/api/ecs_core/client/login";
  483. hrp.nRequestType = RequestType::rtLogin;
  484. hrp.eParamType = HttpParamType::hptBody;
  485. hrp.sParamList.push_back(QString::fromLocal8Bit("accountValue,%1").arg(ui->edt_account->text()));
  486. hrp.sParamList.push_back(QString::fromLocal8Bit("password,%1").arg(ui->edt_password->text()));
  487. hrp.sParamList.push_back(QString::fromLocal8Bit("accountType,%1").arg(m_loginType == LOGIN_TYPE::lt_studentCode ? "STUDENT_CODE": "STUDENT_IDENTITY_NUMBER"));
  488. hrp.sParamList.push_back(QString::fromLocal8Bit("rootOrgId,%1").arg(g_appInfoPtr->m_sRootOrgId));
  489. g_httpBllPtr->post(hrp);
  490. }
  491. else
  492. {
  493. //等待重试
  494. if(m_nRetryCount >= 3)
  495. {
  496. ShowMsg(QString::fromLocal8Bit("系统繁忙,请稍后重试"), this, MSG_ICON_TYPE::mit_error);
  497. ui->btn_login->setEnabled(true);
  498. }
  499. else
  500. {
  501. QTimer::singleShot(3000, this, [](){
  502. //登录限流
  503. CHttpRequestPackage hrp;
  504. hrp.sUri = QString("https://tcc.qmth.com.cn/rate_limit/prod/login/%1").arg(500);
  505. hrp.nRequestType = RequestType::rtLoginLimit;
  506. g_httpBllPtr->getUrl(hrp);
  507. });
  508. }
  509. }
  510. }
  511. else
  512. {
  513. if(loginLimit.sMessage.isEmpty())
  514. {
  515. ShowMsg(QString::fromLocal8Bit("登录失败"), this, MSG_ICON_TYPE::mit_error);
  516. }
  517. else
  518. {
  519. ShowMsg(loginLimit.sMessage, this, MSG_ICON_TYPE::mit_error);
  520. }
  521. ui->btn_login->setEnabled(true);
  522. }
  523. }
  524. void login::onTokenExpired()
  525. {
  526. if(m_pCourseList != nullptr)
  527. {
  528. m_pCourseList.reset();
  529. }
  530. if (m_pLoading != nullptr)
  531. {
  532. m_pLoading.reset();
  533. }
  534. ShowMsg(QString::fromLocal8Bit("登录失效,请重新登录"), this, MSG_ICON_TYPE::mit_error);
  535. }
  536. void login::onLoginInfo(CLoginInfo loginInfo)
  537. {
  538. ui->btn_login->setEnabled(true);
  539. if (loginInfo.nCode == 200)
  540. {
  541. g_appInfoPtr->m_nStudentId = loginInfo.nUserId;
  542. if (m_pCourseList == nullptr)
  543. {
  544. m_pCourseList = std::make_shared<courseList>(this);
  545. connect(m_pCourseList.get(), &courseList::minisize, this, [&]() {showMinimized(); });
  546. }
  547. m_pCourseList->show();
  548. ui->edt_account->setText("");
  549. ui->edt_password->setText("");
  550. }
  551. else
  552. {
  553. if (loginInfo.sMessage != "")
  554. {
  555. ShowMsg(loginInfo.sMessage, this, MSG_ICON_TYPE::mit_error);
  556. }
  557. else
  558. {
  559. ShowMsg(QString::fromLocal8Bit("登录失败"), this, MSG_ICON_TYPE::mit_error);
  560. }
  561. }
  562. }
  563. void login::onLogout(CLogout )
  564. {
  565. if (m_pCourseList !=nullptr)
  566. {
  567. m_pCourseList.reset();
  568. }
  569. }
  570. void login::on_btn_studentCodeLogin_clicked()
  571. {
  572. m_loginType = LOGIN_TYPE::lt_studentCode;
  573. setBtnStyle();
  574. }
  575. void login::on_btn_identityLogin_clicked()
  576. {
  577. m_loginType = LOGIN_TYPE::lt_identity;
  578. setBtnStyle();
  579. }
  580. void login::onDownLoadFile(CDownLoadFileInfo downLoadFileInfo)
  581. {
  582. if (downLoadFileInfo.sModuleName == __FILE__)
  583. {
  584. if (downLoadFileInfo.nCode == 200)
  585. {
  586. QString sLogoFileName = m_sLogoFileUrl.right(m_sLogoFileUrl.length() - m_sLogoFileUrl.lastIndexOf("/") - 1);
  587. sLogoFileName = g_appInfoPtr->m_sCacheFileDir + sLogoFileName;
  588. QString sClientBgPictureFileName = m_sStudentClientBgPictureUrl.right(m_sStudentClientBgPictureUrl.length() - m_sStudentClientBgPictureUrl.lastIndexOf("/") - 1);
  589. sClientBgPictureFileName = g_appInfoPtr->m_sCacheFileDir + sClientBgPictureFileName;
  590. if (sLogoFileName == downLoadFileInfo.sFileName)
  591. {
  592. ui->label_org_logo->setPixmap(QPixmap(sLogoFileName).scaled(ui->label_org_logo->width(), ui->label_org_logo->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
  593. }
  594. if (sClientBgPictureFileName == downLoadFileInfo.sFileName)
  595. {
  596. ui->label_org_bg->setPixmap(QPixmap(sClientBgPictureFileName).scaled(ui->label_org_bg->width(), ui->label_org_bg->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
  597. }
  598. }
  599. }
  600. }