login.cpp 29 KB

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