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