Login.vue 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. <template>
  2. <div class="home">
  3. <header class="header">
  4. <div class="school-logo-container">
  5. <img
  6. v-show="logoPath"
  7. class="school-logo"
  8. :src="logoPath"
  9. alt="school logo"
  10. style="
  11. background: linear-gradient(to bottom, #38f6f5 0%, #8efdf4 100%);
  12. "
  13. @load="(e) => (e.target.style = '')"
  14. />
  15. </div>
  16. <a class="close" @click="closeApp"> 关闭 </a>
  17. </header>
  18. <div class="center">
  19. <div class="content">
  20. <div style="display: flex">
  21. <a
  22. v-if="allowLoginType.includes('STUDENT_CODE')"
  23. key="STUDENT_CODE"
  24. :class="[
  25. 'qm-big-text',
  26. 'login-type',
  27. loginType === 'STUDENT_CODE' && 'active-type',
  28. allowLoginType.length === 1 && 'single-login-type',
  29. ]"
  30. style="border-top-left-radius: 6px"
  31. @click="loginType = 'STUDENT_CODE'"
  32. >
  33. {{ QECSConfig.STUDENT_CODE_LOGIN_ALIAS }}
  34. </a>
  35. <a
  36. v-if="allowLoginType.includes('IDENTITY_NUMBER')"
  37. key="IDENTITY_NUMBER"
  38. :class="[
  39. 'qm-big-text',
  40. 'login-type',
  41. loginType !== 'STUDENT_CODE' && 'active-type',
  42. allowLoginType.length === 1 && 'single-login-type',
  43. ]"
  44. style="border-top-right-radius: 6px"
  45. @click="loginType = 'STUDENT_IDENTITY_NUMBER'"
  46. >
  47. {{ QECSConfig.IDENTITY_NUMBER_LOGIN_ALIAS }}
  48. </a>
  49. <a
  50. v-if="allowLoginType.length === 0"
  51. key="loading"
  52. :class="['qm-big-text', 'login-type']"
  53. >
  54. loading...
  55. </a>
  56. </div>
  57. <div class="qm-title-text" style="margin: 40px 0 20px 0">
  58. {{ productName }}
  59. </div>
  60. <div style="margin: 0 40px 40px 40px">
  61. <i-form ref="loginForm" :model="loginForm" :rules="loginFormRule">
  62. <i-form-item prop="accountValue" class="form-item-style">
  63. <i-input
  64. v-model="loginForm.accountValue"
  65. type="text"
  66. size="large"
  67. >
  68. <i-icon slot="prepend" type="ios-person"></i-icon>
  69. </i-input>
  70. </i-form-item>
  71. <i-form-item prop="password" class="form-item-style">
  72. <i-input
  73. v-model="loginForm.password"
  74. type="password"
  75. size="large"
  76. @on-enter="loginForuser"
  77. >
  78. <i-icon slot="prepend" type="ios-lock"></i-icon>
  79. </i-input>
  80. </i-form-item>
  81. <i-form-item
  82. v-if="isGeeTestEnabled"
  83. class="form-item-style"
  84. style="height: 40px; margin-top: 0px"
  85. >
  86. <GeeTest :reset="resetGeeTime" @on-load="handleGtResult" />
  87. </i-form-item>
  88. <i-form-item style="position: relative">
  89. <div
  90. v-if="errorInfo !== ''"
  91. style="position: absolute; top: -25px; width: 100%"
  92. >
  93. <i-alert type="error" show-icon>{{ errorInfo }}</i-alert>
  94. </div>
  95. <i-button
  96. size="large"
  97. class="qm-primary-button"
  98. style="margin-top: 10px"
  99. long
  100. :disabled="disableLoginBtn"
  101. :loading="loginBtnLoading"
  102. @click="loginForuser"
  103. >
  104. {{ newVersionAvailable ? "点击更新版本" : "登录" }}
  105. </i-button>
  106. </i-form-item>
  107. </i-form>
  108. </div>
  109. </div>
  110. </div>
  111. <footer class="footer">
  112. <div style="position: absolute; right: 20px; bottom: 20px">
  113. 版本: {{ VUE_APP_GIT_REPO_VERSION }}
  114. </div>
  115. <DevTools />
  116. </footer>
  117. <GlobalNotice />
  118. </div>
  119. </template>
  120. <script>
  121. import moment from "moment";
  122. import { mapMutations } from "vuex";
  123. import {
  124. FACE_API_MODEL_PATH,
  125. DOMAIN_IN_URL,
  126. EPCC_DOMAIN,
  127. VUE_APP_CONFIG_FILE_SEVER_URL,
  128. } from "@/constants/constants";
  129. import { REMOTE_APP_NAME, VCAM_LIST } from "@/constants/constant-namelist";
  130. import DevTools from "./DevTools.vue";
  131. import nativeExe, {
  132. fileExists,
  133. nodeCheckRemoteDesktop,
  134. nodeCheckProcess,
  135. } from "@/utils/nativeExe";
  136. import UA, { chromeUA } from "@/utils/ua.js";
  137. import {
  138. createLog,
  139. createUserDetailLog,
  140. createEncryptLog,
  141. } from "@/utils/logger";
  142. import { checkMainExe, isElectron, registerOnResize } from "@/utils/util";
  143. import GeeTest from "./GeeTest";
  144. import GlobalNotice from "./GlobalNotice";
  145. import { tryLimit } from "@/utils/tryLimit";
  146. // 检测devtools. 仅在chrome 72+ 有效。
  147. let element = new Image();
  148. Object.defineProperty(element, "id", {
  149. get: function () {
  150. // console.log("trigger devtools log");
  151. window._hmt.push([
  152. "_trackEvent",
  153. "控制台打开",
  154. window.location.href,
  155. "|||" +
  156. localStorage.getItem("domain") +
  157. "|||" +
  158. localStorage.getItem("key"),
  159. ]);
  160. createLog({
  161. currentPage: "登录页面",
  162. action: "控制台打开",
  163. UA: navigator.userAgent,
  164. url: window.location.href,
  165. });
  166. return null;
  167. },
  168. });
  169. /**
  170. * 在任何组件需要强制退出,做以下步骤
  171. * 1. this.logout("?LogoutReason=xxx")
  172. * 因为在/login里会删除localStorage的token,而在router.beforeEach会检查是否有token,达到退出的目的。
  173. */
  174. export default {
  175. name: "Login",
  176. components: {
  177. DevTools,
  178. GeeTest,
  179. GlobalNotice,
  180. },
  181. data() {
  182. return {
  183. QECSConfig: {},
  184. loginType: "STUDENT_CODE",
  185. errorInfo: "",
  186. loginForm: {
  187. accountValue: "",
  188. password: "",
  189. tid: "",
  190. },
  191. loginFormRule: {
  192. accountValue: [
  193. {
  194. required: true,
  195. message: "请填写登录账号",
  196. trigger: "blur",
  197. },
  198. ],
  199. password: [
  200. {
  201. required: true,
  202. message: "请填写密码",
  203. trigger: "blur",
  204. },
  205. ],
  206. },
  207. captchaObj: null,
  208. resetGeeTime: Date.now(),
  209. loginBtnLoading: false,
  210. disableLoginBtnBecauseRemoteApp: true,
  211. disableLoginBtnBecauseVCam: true,
  212. disableLoginBtnBecauseAppVersionChecker: false,
  213. disableLoginBtnBecauseRefreshServiceWorker: false,
  214. disableLoginBtnBecauseNotAllowedNative: true,
  215. newVersionAvailable: false,
  216. VUE_APP_GIT_REPO_VERSION: process.env.VUE_APP_GIT_REPO_VERSION,
  217. GeeTestConfig: {},
  218. };
  219. },
  220. computed: {
  221. logoPath() {
  222. // "!/progressive/true/format/webp"
  223. return this.QECSConfig.LOGO_FILE_URL ? this.QECSConfig.LOGO_FILE_URL : "";
  224. },
  225. productName() {
  226. return this.QECSConfig.OE_STUDENT_SYS_NAME || "远程教育网络考试";
  227. },
  228. allowLoginType() {
  229. return (
  230. (this.QECSConfig.LOGIN_TYPE && this.QECSConfig.LOGIN_TYPE.split(",")) ||
  231. []
  232. );
  233. },
  234. schoolDomain() {
  235. const domain = DOMAIN_IN_URL;
  236. if (!domain || !domain.includes("qmth.com.cn")) {
  237. this.$Message.error({
  238. content: "机构地址出错,请关闭程序后再登录。",
  239. duration: 15,
  240. closable: true,
  241. });
  242. }
  243. return domain;
  244. },
  245. isEPCC() {
  246. return this.schoolDomain === EPCC_DOMAIN;
  247. },
  248. usernameInputPlaceholder() {
  249. if (this.loginType === "STUDENT_CODE") {
  250. return "请输入学号";
  251. } else {
  252. return "请输入身份证号";
  253. }
  254. },
  255. passwordInputPlaceholder() {
  256. if (this.loginType === "STUDENT_CODE") {
  257. return "初始密码为身份证号后6位";
  258. } else {
  259. return "初始密码为身份证号后6位";
  260. }
  261. },
  262. disableLoginBtn() {
  263. return (
  264. (isElectron() &&
  265. (this.disableLoginBtnBecauseRemoteApp ||
  266. this.disableLoginBtnBecauseVCam)) ||
  267. this.disableLoginBtnBecauseAppVersionChecker ||
  268. this.disableLoginBtnBecauseRefreshServiceWorker ||
  269. this.disableLoginBtnBecauseNotAllowedNative
  270. );
  271. },
  272. isGeeTestEnabled() {
  273. const thisOrg = this.GeeTestConfig[this.QECSConfig.ROOT_ORG_ID];
  274. const isThisOrgUndefined = thisOrg === undefined;
  275. const allOrg = this.GeeTestConfig["-1"];
  276. return isThisOrgUndefined ? allOrg : thisOrg;
  277. },
  278. },
  279. watch: {
  280. "loginForm.accountValue": function () {
  281. if (Date.now() - this.resetGeeTime > 60 * 1000) {
  282. this.captchaObj.destroy();
  283. this.resetGeeTime = Date.now();
  284. }
  285. },
  286. "loginForm.password": function () {
  287. if (Date.now() - this.resetGeeTime > 60 * 1000) {
  288. this.captchaObj.destroy();
  289. this.resetGeeTime = Date.now();
  290. }
  291. },
  292. },
  293. async mounted() {
  294. // this.testServiceWorker();
  295. this.examShellStats();
  296. // await this.checkNewVersion();
  297. if (localStorage.getItem("__swReload")) {
  298. localStorage.removeItem("__swReload");
  299. this.$Message.info({
  300. content: "正在更新版本...",
  301. });
  302. this.disableLoginBtnBecauseRefreshServiceWorker = true;
  303. await new Promise((resolve) => {
  304. setTimeout(() => {
  305. resolve();
  306. }, 2000);
  307. });
  308. location.reload(true);
  309. }
  310. // manual precache for models
  311. fetch(
  312. FACE_API_MODEL_PATH + "tiny_face_detector_model-weights_manifest.json"
  313. );
  314. fetch(FACE_API_MODEL_PATH + "face_landmark_68_model-weights_manifest.json");
  315. fetch(FACE_API_MODEL_PATH + "face_expression_model-weights_manifest.json");
  316. // alread precached
  317. // fetch("/models/tiny_face_detector_model-shard1");
  318. // fetch("/models/face_landmark_68_model-shard1");
  319. // this.checkNewVersionInterval = setInterval(() => {
  320. // if (window.__newSWAvailable) {
  321. // this.newVersionAvailable = true;
  322. // }
  323. // }, 1000);
  324. this.checkNewVersionListener = document.addEventListener(
  325. "__newSWAvailable",
  326. () => {
  327. this.newVersionAvailable = true;
  328. },
  329. { once: true }
  330. );
  331. if (this.isEPCC) {
  332. const redirectUrl = new URLSearchParams(location.search).get(
  333. "redirectUrl"
  334. );
  335. if (redirectUrl) {
  336. sessionStorage.setItem("redirectUrl", redirectUrl);
  337. }
  338. this.login();
  339. }
  340. // 上传本机加密日志
  341. this.uploadLogInterval = setInterval(() => createEncryptLog(), 5 * 1000);
  342. if (isElectron()) {
  343. createLog({
  344. currentPage: "登录页面",
  345. action: "versonstats",
  346. packageVersion: "ua-" + UA.getBrowser().version,
  347. file: eval(`process.env.PORTABLE_EXECUTABLE_FILE`),
  348. uaGood:
  349. "uagood-" + (eval(`process.env.PORTABLE_EXECUTABLE_FILE`) ? 1 : 0),
  350. });
  351. this.processInterval = setInterval(
  352. () => nodeCheckProcess(),
  353. 2 * 60 * 1000
  354. );
  355. }
  356. },
  357. async created() {
  358. createLog({
  359. currentPage: "登录页面",
  360. action: "page created",
  361. UA: navigator.userAgent,
  362. });
  363. // 测试log顺序
  364. // createLog({
  365. // currentPage: "登录页面2",
  366. // action: "page created",
  367. // UA: navigator.userAgent,
  368. // });
  369. if (navigator.connection && navigator.connection.rtt) {
  370. console.log("UA: ", navigator.userAgent);
  371. console.log(
  372. "_trackEvent",
  373. "登录页面",
  374. `当前网速: ${Number(navigator.connection.downlink).toPrecision(
  375. 1
  376. )}Mib; 网络延迟: ${Number(navigator.connection.rtt).toPrecision(1)}ms`
  377. );
  378. window._hmt.push([
  379. "_trackEvent",
  380. "登录页面",
  381. `当前网速: ${Number(navigator.connection.downlink).toPrecision(
  382. 1
  383. )}Mib; 网络延迟: ${Number(navigator.connection.rtt).toPrecision(1)}ms`,
  384. ]);
  385. createLog({
  386. currentPage: "登录页面",
  387. action: "page created",
  388. UA: navigator.userAgent,
  389. });
  390. }
  391. if (this.isEPCC) {
  392. this.$Spin.show({
  393. render: () => {
  394. return <div style="font-size: 44px">正在登录...</div>;
  395. },
  396. });
  397. }
  398. if (
  399. navigator.userAgent.indexOf("WOW64") != -1 ||
  400. navigator.userAgent.indexOf("Win64") != -1
  401. ) {
  402. window._hmt.push(["_trackEvent", "登录页面", "64Bit OS"]);
  403. } else {
  404. window._hmt.push(["_trackEvent", "登录页面", "非64Bit OS"]);
  405. }
  406. this.$Message.config({
  407. duration: 15,
  408. size: "large",
  409. closable: true, // 没有影响到所有的组件。。。 https://github.com/iview/iview/issues/2962
  410. });
  411. window.sessionStorage.removeItem("token");
  412. window.sessionStorage.clear();
  413. window.localStorage.removeItem("key");
  414. // if (localStorage.getItem("user-for-reload")) {
  415. // const lsUser = JSON.parse(localStorage.getItem("user-for-reload"));
  416. // this.loginForm.accountValue =
  417. // process.env.NODE_ENV === "production"
  418. // ? ""
  419. // : lsUser.studentCode ||
  420. // (lsUser.studentCodeList && lsUser.studentCodeList[0]);
  421. // this.loginForm.password =
  422. // process.env.NODE_ENV === "production" ? "" : "180613";
  423. // }
  424. if (isElectron() && !eval(`process.env.PORTABLE_EXECUTABLE_FILE`)) {
  425. this.disableLoginBtnBecauseAppVersionChecker = true;
  426. this.$Message.error({
  427. content: "请与学校申请最新的客户端,进行考试!",
  428. duration: 2 * 24 * 60 * 60,
  429. });
  430. }
  431. registerOnResize();
  432. checkMainExe();
  433. if (
  434. [
  435. "xjtu.ecs.qmth.com.cn",
  436. "ccnu.ecs.qmth.com.cn",
  437. "snnu.ecs.qmth.com.cn",
  438. "swjtu.ecs.qmth.com.cn",
  439. ].includes(this.schoolDomain)
  440. ) {
  441. if (
  442. !isElectron() ||
  443. !window.nodeRequire("fs").existsSync("multiCamera.exe")
  444. ) {
  445. this.disableLoginBtnBecauseAppVersionChecker = true;
  446. this.$Message.error({
  447. content: "请与学校申请最新的客户端,进行考试!",
  448. duration: 2 * 24 * 60 * 60,
  449. });
  450. }
  451. }
  452. if (["cup.ecs.qmth.com.cn"].includes(this.schoolDomain)) {
  453. // console.log(UA.getBrowser(), chromeUA);
  454. if (
  455. UA.getBrowser().name !== "electron-exam-shell" ||
  456. (UA.getBrowser().major !== "2" && UA.getBrowser().major !== "1") ||
  457. chromeUA.major < "58"
  458. ) {
  459. this.disableLoginBtnBecauseAppVersionChecker = true;
  460. this.$Message.error({
  461. content: "请与学校申请最新的客户端,进行考试!",
  462. duration: 2 * 24 * 60 * 60,
  463. });
  464. }
  465. }
  466. // if (
  467. // ["cugr.ecs.qmth.com.cn", "sdu.ecs.qmth.com.cn"].includes(
  468. // this.$route.params.domain
  469. // )
  470. // ) {
  471. // // console.log(UA.getBrowser(), chromeUA);
  472. // if (
  473. // UA.getBrowser().name !== "electron-exam-shell" ||
  474. // UA.getBrowser().major !== "2" ||
  475. // chromeUA.major < "76"
  476. // ) {
  477. // this.disableLoginBtnBecauseAppVersionChecker = true;
  478. // this.$Message.error({
  479. // content: "请与学校申请最新的客户端,进行考试!",
  480. // duration: 2 * 24 * 60 * 60,
  481. // });
  482. // }
  483. // }
  484. await this.checkElectronConfig();
  485. await this.checkGeeTestConfig();
  486. await this.checkVCam();
  487. await this.checkAllowedClient();
  488. if (
  489. this.allowLoginType.length === 1 &&
  490. this.allowLoginType[0] === "IDENTITY_NUMBER"
  491. ) {
  492. this.loginType = "STUDENT_IDENTITY_NUMBER";
  493. }
  494. },
  495. beforeDestroy() {
  496. clearTimeout(this.loginTimeout);
  497. clearInterval(this.uploadLogInterval);
  498. clearInterval(this.processInterval);
  499. // clearInterval(this.checkNewVersionInterval);
  500. document.removeEventListener(
  501. "__newSWAvailable",
  502. this.checkNewVersionListener
  503. );
  504. },
  505. methods: {
  506. ...mapMutations(["updateUser", "updateTimeDifference", "updateQECSConfig"]),
  507. testServiceWorker() {
  508. if ("serviceWorker" in navigator) {
  509. // Register service worker
  510. navigator.serviceWorker
  511. .register("/service-worker-test.js")
  512. .then(function (reg) {
  513. console.log("Registration OK!. Scope is " + reg.scope);
  514. })
  515. .catch(function (err) {
  516. console.error("Registration FAILED! " + err);
  517. });
  518. }
  519. },
  520. async loginForuser() {
  521. // 供user点击的 login 方法。主要是保护 login 方法,不因为user重复点击,多个请求不按预期时间进行。
  522. createLog({ currentPage: "登录页面", action: "点击登录按钮" });
  523. try {
  524. const hasNewVersion = await this.checkNewVersion();
  525. if (hasNewVersion) return;
  526. } catch (error) {
  527. console.log("检测新版本出错");
  528. }
  529. if (this.loginBtnLoading) {
  530. return;
  531. }
  532. this.loginBtnLoading = true;
  533. const { limitResult, serverOk } = await tryLimit({
  534. action: "login",
  535. limit: 500,
  536. });
  537. this.logger({
  538. action: "登录页面--login clicked",
  539. logId: "登录限流API call",
  540. });
  541. if (!limitResult) {
  542. createLog({
  543. currentPage: "登录页面--login clicked",
  544. action: "登录被限流",
  545. serverOk,
  546. });
  547. this.$Modal.warning({
  548. title: "提示",
  549. content: "网络繁忙,请稍后再试。",
  550. });
  551. await new Promise((resolve) => setTimeout(() => resolve(), 3000));
  552. this.loginBtnLoading = false;
  553. return;
  554. }
  555. createLog({
  556. currentPage: "登录页面--login clicked",
  557. action: "登录未限流",
  558. });
  559. const before = Date.now();
  560. // console.log(this.captchaObj.getValidate());
  561. if (this.isGeeTestEnabled) {
  562. if (!this.captchaObj || !this.captchaObj.getValidate()) {
  563. this.$Message.error("请完成验证");
  564. this.loginBtnLoading = false;
  565. return;
  566. }
  567. }
  568. try {
  569. await this.login();
  570. } finally {
  571. const end = Date.now();
  572. this.loginTimeout = setTimeout(() => {
  573. this.loginBtnLoading = false;
  574. }, 10 * 1000 - (end - before));
  575. }
  576. },
  577. async login() {
  578. // 测试 createLog 在网络堵塞的情况下,是否会堵塞页面
  579. // alert("haha");
  580. createLog({
  581. currentPage: "登录页面--login clicked",
  582. action: "in login()",
  583. UA: navigator.userAgent,
  584. });
  585. // alert("haha end");
  586. this.errorInfo = "";
  587. // epcc立即登录
  588. if (!this.isEPCC && this.disableLoginBtn) {
  589. return;
  590. }
  591. let loginResponse;
  592. if (!this.isEPCC) {
  593. // https://www.cnblogs.com/weiqinl/p/6708993.html
  594. const valid = await this.$refs.loginForm.validate();
  595. if (!valid) {
  596. return;
  597. }
  598. let repPara = this.loginForm;
  599. let geeParams = {};
  600. if (this.isGeeTestEnabled) {
  601. // const geeForm = document.querySelector(".geetest_form").children;
  602. const geeRes = this.captchaObj.getValidate();
  603. geeParams = {
  604. // geetest
  605. user_id: localStorage.getItem("uuidForEcs"),
  606. client_type: "Web",
  607. challenge: geeRes.geetest_challenge, // geeForm[0].value,
  608. validate: geeRes.geetest_validate, // geeForm[1].value,
  609. seccode: geeRes.geetest_seccode, // geeForm[2].value,
  610. };
  611. }
  612. createLog({
  613. currentPage: "登录页面",
  614. action: "send params",
  615. domain: this.schoolDomain,
  616. rootOrgId: this.QECSConfig.ROOT_ORG_ID,
  617. accountType: this.loginType,
  618. accountValue: this.loginForm.accountValue,
  619. });
  620. // 以下网络请求失败,直接报网络异常错误
  621. loginResponse = await this.$http.post(
  622. "/api/ecs_core/verifyCode/gt/login",
  623. {
  624. ...repPara,
  625. accountType: this.loginType,
  626. domain: this.schoolDomain,
  627. rootOrgId: this.QECSConfig.ROOT_ORG_ID,
  628. alwaysOK: true,
  629. ...geeParams,
  630. }
  631. );
  632. } else {
  633. try {
  634. const hasNewVersion = await this.checkNewVersion();
  635. if (hasNewVersion) return;
  636. } catch (error) {
  637. console.log("检测新版本出错");
  638. }
  639. loginResponse = await this.epccLogin();
  640. if (!loginResponse) {
  641. return;
  642. } else {
  643. loginResponse.data = { content: loginResponse.data, code: "200" }; // 和老接口的always ok保持一致
  644. }
  645. }
  646. let data = loginResponse.data;
  647. // if (
  648. // Math.abs() >
  649. // 5 * 60 * 1000
  650. // ) {
  651. // window._hmt.push(["_trackEvent", "登录页面", "本机时间误差过大"]);
  652. // this.$Message.error({
  653. // content: "与服务器时间差异超过5分钟,请校准本机时间之后再重试!",
  654. // duration: 30
  655. // });
  656. // throw new Error("与服务器时间差异超过5分钟,请校准本机时间之后再重试!");
  657. // }
  658. this.updateTimeDifference(
  659. moment(loginResponse.headers.date).diff(moment())
  660. );
  661. if (data.code == "200") {
  662. data = data.content;
  663. this.errorInfo = "";
  664. //缓存用户信息
  665. window.sessionStorage.setItem("token", data.token);
  666. window.localStorage.setItem("key", data.key);
  667. window.localStorage.setItem("domain", this.schoolDomain);
  668. try {
  669. // const student = (
  670. // await this.$http.get(
  671. // "/api/ecs_core/student/getStudentInfoBySession"
  672. // )
  673. // ).data;
  674. // const specialty = (
  675. // await this.$http.get(
  676. // "/api/ecs_exam_work/exam_student/specialtyNameList/"
  677. // )
  678. // ).data;
  679. const [{ data: student }, { data: specialty }] = await Promise.all([
  680. this.$http.get("/api/ecs_core/student/getStudentInfoBySession"),
  681. this.$http.get(
  682. "/api/ecs_exam_work/exam_student/specialtyNameList/"
  683. ),
  684. ]);
  685. const user = {
  686. ...data,
  687. ...student,
  688. specialty: specialty.join(),
  689. schoolDomain: this.schoolDomain,
  690. };
  691. this.updateUser(user);
  692. window.localStorage.setItem("user-for-reload", JSON.stringify(user));
  693. window._hmt.push([
  694. "_trackEvent",
  695. "登录页面",
  696. "登录",
  697. this.$route.query.LogoutReason,
  698. ]);
  699. const alreadyInExam = await this.checkExamInProgress();
  700. window._hmt.push(["_trackEvent", "登录页面", "登录成功"]);
  701. createUserDetailLog({ action: "登录成功" });
  702. if (alreadyInExam) {
  703. this.logger({ action: "断点续考", detail: "登录页面" });
  704. window._hmt.push([
  705. "_trackEvent",
  706. "登录页面",
  707. "断点续考",
  708. "重新登录",
  709. ]);
  710. return;
  711. }
  712. this.$router.push("/online-exam");
  713. let userIds = JSON.parse(localStorage.getItem("userIds"));
  714. userIds = [...new Set(userIds).add(user.id)];
  715. localStorage.setItem("userIds", JSON.stringify(userIds));
  716. // 学习中心机器
  717. // (JSON.parse(localStorage.getItem("userIds")) || []).length > 5;
  718. this.$Spin.hide();
  719. this.$Message.destroy();
  720. } catch (error) {
  721. window._hmt.push([
  722. "_trackEvent",
  723. "登录页面",
  724. "登录失败",
  725. "getStudentInfoBySession失败",
  726. ]);
  727. this.logger({
  728. action: "登录失败",
  729. detail: "getStudentInfoBySession失败",
  730. });
  731. this.$Message.error({
  732. content: "获取学生信息失败,请重试!",
  733. duration: 15,
  734. closable: true,
  735. });
  736. if (this.isEPCC) {
  737. this.$Spin.hide();
  738. this.logout();
  739. }
  740. }
  741. } else {
  742. window._hmt.push(["_trackEvent", "登录页面", "登录失败", data.desc]);
  743. createLog({
  744. currentPage: "登录页面",
  745. action: "登录失败",
  746. desc: data.desc,
  747. });
  748. this.errorInfo = data.desc;
  749. // this.captchaObj.reset();
  750. this.captchaObj.destroy();
  751. // this.captchaObj = null;
  752. this.resetGeeTime = Date.now();
  753. }
  754. },
  755. async checkNewVersion() {
  756. let myHeaders = new Headers();
  757. myHeaders.append("Content-Type", "application/javascript");
  758. myHeaders.append("Cache-Control", "no-cache");
  759. const response = await fetch(
  760. document.scripts[document.scripts.length - 1].src + "?x" + Date.now(),
  761. {
  762. method: process.env.NODE_ENV === "development" ? "GET" : "HEAD",
  763. headers: myHeaders,
  764. }
  765. );
  766. // 给后台更多时间去处理 resource/uuid.js 的请求
  767. // await new Promise((resolve) => setTimeout(() => resolve(), 1500));
  768. if (!response.ok || this.newVersionAvailable) {
  769. if (
  770. response.ok &&
  771. this.newVersionAvailable &&
  772. localStorage.getItem("__swReload")
  773. ) {
  774. window._hmt.push([
  775. "_trackEvent",
  776. "登录页面",
  777. "service worker刷新失败",
  778. ]);
  779. this.$Message.destroy();
  780. this.$Message.info({
  781. content: "请重新打开程序。",
  782. duration: 2 * 24 * 60 * 60,
  783. });
  784. return true;
  785. }
  786. window._hmt.push([
  787. "_trackEvent",
  788. "登录页面",
  789. "新版本发布后,客户端自动刷新",
  790. ]);
  791. this.$Message.info({
  792. content: "正在获取新版本...",
  793. });
  794. localStorage.setItem("__swReload", "anything");
  795. this.disableLoginBtnBecauseRefreshServiceWorker = true;
  796. await new Promise((resolve) => {
  797. setTimeout(() => {
  798. resolve();
  799. }, 1000);
  800. });
  801. location.reload(true);
  802. return true;
  803. }
  804. },
  805. async checkElectronConfig() {
  806. try {
  807. const fileSever = VUE_APP_CONFIG_FILE_SEVER_URL;
  808. const res = await fetch(
  809. fileSever +
  810. "/org_properties/byOrgDomain/" +
  811. DOMAIN_IN_URL +
  812. "/studentClientConfig.json" +
  813. "?" +
  814. Date.now() +
  815. Math.random()
  816. );
  817. if (res.ok) {
  818. const json = await res.json();
  819. this.QECSConfig = json;
  820. this.updateQECSConfig(json);
  821. } else {
  822. this.$Message.error({
  823. content: "获取远程配置文件出错,请重新打开程序!",
  824. duration: 15,
  825. closable: true,
  826. });
  827. return;
  828. }
  829. } catch (e) {
  830. this.$Message.error({
  831. content: "获取远程配置文件出错,请重新打开程序!",
  832. duration: 15,
  833. closable: true,
  834. });
  835. return;
  836. }
  837. await this.checkRemoteApp();
  838. },
  839. async checkGeeTestConfig() {
  840. try {
  841. const fileSever = VUE_APP_CONFIG_FILE_SEVER_URL;
  842. const res = await fetch(
  843. fileSever +
  844. "/org_properties/geetestConfig.json" +
  845. "?" +
  846. Date.now() +
  847. Math.random()
  848. );
  849. if (res.ok) {
  850. const json = await res.json();
  851. this.GeeTestConfig = json;
  852. } else {
  853. this.$Message.error({
  854. content: "获取远程配置文件出错,请重新打开程序!",
  855. duration: 15,
  856. closable: true,
  857. });
  858. return;
  859. }
  860. } catch (e) {
  861. this.$Message.error({
  862. content: "获取远程配置文件出错,请重新打开程序!",
  863. duration: 15,
  864. closable: true,
  865. });
  866. return;
  867. }
  868. },
  869. async checkRemoteApp() {
  870. if (!isElectron()) {
  871. return;
  872. }
  873. async function checkRemoteAppTxt() {
  874. let applicationNames;
  875. try {
  876. const fs = window.nodeRequire("fs");
  877. try {
  878. applicationNames = fs.readFileSync(
  879. "remoteApplication.txt",
  880. "utf-8"
  881. );
  882. } catch (error) {
  883. console.log(error);
  884. window._hmt.push([
  885. "_trackEvent",
  886. "登录页面",
  887. "读取remoteApplication.txt出错--0",
  888. ]);
  889. await new Promise((resolve2) => setTimeout(() => resolve2(), 3000));
  890. applicationNames = fs.readFileSync(
  891. "remoteApplication.txt",
  892. "utf-8"
  893. );
  894. }
  895. } catch (error) {
  896. console.log(error);
  897. createLog({
  898. currentPage: "登录页面",
  899. errorType: "e-01",
  900. error: error.message,
  901. detail: applicationNames,
  902. });
  903. window._hmt.push([
  904. "_trackEvent",
  905. "登录页面",
  906. "读取remoteApplication.txt出错",
  907. ]);
  908. this.$Message.error({
  909. content: "系统检测出错(e-01),请退出程序后重试!",
  910. duration: 2 * 24 * 60 * 60,
  911. });
  912. return;
  913. }
  914. if (typeof nodeRequire !== "undefined") {
  915. const hasSun = nodeCheckRemoteDesktop();
  916. if (hasSun) {
  917. if (applicationNames) {
  918. applicationNames += ",sunloginclient";
  919. } else {
  920. applicationNames = "sunloginclient";
  921. }
  922. }
  923. }
  924. if (applicationNames && applicationNames.trim()) {
  925. let names = applicationNames
  926. .replace("qq", "QQ")
  927. .replace("teamviewer", "TeamViewer")
  928. .replace("lookmypc", "LookMyPC")
  929. .replace("xt", "协通")
  930. .replace("winaw32", "Symantec PCAnywhere")
  931. .replace("pcaquickconnect", "Symantec PCAnywhere")
  932. .replace("sessioncontroller", "Symantec PCAnywhere")
  933. .replace(/sunloginclient/gi, "向日葵")
  934. .replace(/sunloginremote/gi, "向日葵")
  935. .replace("wemeetapp", "腾讯会议")
  936. .replace("wechat", "微信");
  937. names = [...new Set(names.split(",").map((v) => v.trim()))].join(
  938. ","
  939. );
  940. this.disableLoginBtnBecauseRemoteApp = true;
  941. this.$Message.info({
  942. content: "在考试期间,请关掉" + names + "软件,诚信考试。",
  943. duration: 2 * 24 * 60 * 60,
  944. });
  945. } else {
  946. this.disableLoginBtnBecauseRemoteApp = false;
  947. }
  948. }
  949. //如果配置中配置了 DISABLE_REMOTE_ASSISTANCE
  950. if (
  951. this.QECSConfig.PREVENT_CHEATING_CONFIG.includes(
  952. "DISABLE_REMOTE_ASSISTANCE"
  953. )
  954. ) {
  955. let exe = "Project1.exe";
  956. if (fileExists("Project2.exe")) {
  957. const remoteAppName = REMOTE_APP_NAME;
  958. exe = `Project2.exe "${remoteAppName}" `;
  959. }
  960. const fs = window.nodeRequire("fs");
  961. try {
  962. fs.unlinkSync("remoteApplication.txt");
  963. } catch (error) {
  964. console.log(error);
  965. }
  966. await nativeExe(exe, checkRemoteAppTxt.bind(this));
  967. } else {
  968. this.disableLoginBtnBecauseRemoteApp = false;
  969. }
  970. },
  971. async checkVCam() {
  972. if (!isElectron()) {
  973. return;
  974. }
  975. const vcamList = VCAM_LIST;
  976. async function checkVCamTxt() {
  977. let applicationNames;
  978. try {
  979. const fs = window.nodeRequire("fs");
  980. try {
  981. applicationNames = fs.readFileSync("CameraInfo.txt", "utf-8");
  982. } catch (error) {
  983. console.log(error);
  984. window._hmt.push([
  985. "_trackEvent",
  986. "登录页面",
  987. "CameraInfo.txt出错--0",
  988. ]);
  989. await new Promise((resolve2) => setTimeout(() => resolve2(), 3000));
  990. applicationNames = fs.readFileSync("CameraInfo.txt", "utf-8");
  991. }
  992. } catch (error) {
  993. console.log(error);
  994. createLog({
  995. currentPage: "登录页面",
  996. errorType: "e-02",
  997. error: error.message,
  998. detail: applicationNames,
  999. });
  1000. window._hmt.push([
  1001. "_trackEvent",
  1002. "登录页面",
  1003. "读取CameraInfo.txt出错",
  1004. ]);
  1005. this.$Message.error({
  1006. content: "系统检测出错(e-02),请退出程序后重试!",
  1007. duration: 2 * 24 * 60 * 60,
  1008. });
  1009. return;
  1010. }
  1011. this.disableLoginBtnBecauseVCam = false;
  1012. if (applicationNames && applicationNames.trim()) {
  1013. for (const vc of vcamList) {
  1014. if (applicationNames.toUpperCase().includes(vc.toUpperCase())) {
  1015. this.disableLoginBtnBecauseVCam = true;
  1016. this.$Message.info({
  1017. content:
  1018. "在考试期间,请关掉" + "虚拟摄像头" + "软件,诚信考试。",
  1019. duration: 2 * 24 * 60 * 60,
  1020. });
  1021. console.log(applicationNames);
  1022. }
  1023. }
  1024. }
  1025. }
  1026. //如果配置中配置了 DISABLE_VIRTUAL_CAMERA
  1027. if (
  1028. this.QECSConfig.PREVENT_CHEATING_CONFIG.includes(
  1029. "DISABLE_VIRTUAL_CAMERA"
  1030. )
  1031. ) {
  1032. await nativeExe("multiCamera.exe", checkVCamTxt.bind(this));
  1033. } else {
  1034. this.disableLoginBtnBecauseVCam = false;
  1035. }
  1036. },
  1037. async checkAllowedClient() {
  1038. if (process.env.VUE_APP_SKIP_CHECK_NATIVE === "true") {
  1039. console.log(
  1040. "环境检查: process.env.VUE_APP_SKIP_CHECK_NATIVE === " +
  1041. process.env.VUE_APP_SKIP_CHECK_NATIVE,
  1042. " 允许浏览器访问"
  1043. );
  1044. this.disableLoginBtnBecauseNotAllowedNative = false;
  1045. return;
  1046. }
  1047. // if (!this.FE_FEATURE_ALLOW_CHECK) {
  1048. // this.disableLoginBtnBecauseNotAllowedNative = false;
  1049. // return;
  1050. // }
  1051. /**
  1052. * 本应用仅处理学生端的请求。不做跳转,不管浏览器类型。
  1053. * 允许NATIVE/允许BROWSER,在以下场景中能访问:学生端/移动端浏览器
  1054. */
  1055. // if (
  1056. // this.QECSConfig.LOGIN_SUPPORT.includes("BROWSER") &&
  1057. // this.QECSConfig.LOGIN_SUPPORT.includes("NATIVE")
  1058. // ) {
  1059. // // FIXME: 暂时允许选择浏览器的可以在浏览器中访问
  1060. // this.disableLoginBtnBecauseNotAllowedNative = false;
  1061. // return;
  1062. // } else
  1063. if (this.QECSConfig.LOGIN_SUPPORT.includes("NATIVE")) {
  1064. // 检测是否是学生端。 检测是否有node。检测是否能node调用。
  1065. const hasShell = UA.getBrowser().name === "electron-exam-shell";
  1066. const hasNode = isElectron();
  1067. let hasFs = false;
  1068. let hasReadFileSync = false;
  1069. if (hasShell && hasNode) {
  1070. const fs = window.nodeRequire("fs");
  1071. if (fs && typeof fs.readFileSync === "function") {
  1072. hasFs = true;
  1073. hasReadFileSync = true;
  1074. this.disableLoginBtnBecauseNotAllowedNative = false;
  1075. }
  1076. }
  1077. if (this.disableLoginBtnBecauseNotAllowedNative) {
  1078. window._hmt.push([
  1079. "_trackEvent",
  1080. "登录页面",
  1081. "不允许访问-" +
  1082. JSON.stringify({
  1083. hasShell,
  1084. hasNode,
  1085. hasFs,
  1086. hasReadFileSync,
  1087. }),
  1088. ]);
  1089. this.$Message.error({
  1090. content: "请与学校申请最新的客户端,进行考试!",
  1091. duration: 2 * 24 * 60 * 60,
  1092. });
  1093. }
  1094. // } else if (this.QECSConfig.LOGIN_SUPPORT.includes("BROWSER")) {
  1095. // const hasShell = UA.getBrowser().name === "electron-exam-shell";
  1096. // if (hasShell) {
  1097. // if (this.disableLoginBtnBecauseNotAllowedNative) {
  1098. // window._hmt.push([
  1099. // "_trackEvent",
  1100. // "登录页面",
  1101. // "不允许访问-不允许在考生端中访问只设定移动端浏览器访问的设置",
  1102. // ]);
  1103. // this.$Message.error({
  1104. // content: "本考试不支持在考生端中进行!",
  1105. // duration: 2 * 24 * 60 * 60,
  1106. // });
  1107. // }
  1108. // }
  1109. // // TODO: redirect to wap site
  1110. // // if(chromeUA.major < "66") { } // 到移动端去判断
  1111. // return;
  1112. } else {
  1113. this.$Message.error({
  1114. content: "本考试不支持在考生端中进行!",
  1115. duration: 2 * 24 * 60 * 60,
  1116. });
  1117. }
  1118. },
  1119. closeApp() {
  1120. this.logger({
  1121. page: "登录页",
  1122. button: "关闭按钮",
  1123. action: "点击",
  1124. });
  1125. console.log("关闭应用");
  1126. window.close();
  1127. },
  1128. examShellStats() {
  1129. const shellVersion = window.navigator.userAgent
  1130. .split(" ")
  1131. .find((v) => v.startsWith("electron-exam-shell/"));
  1132. const chromeVersion = window.navigator.userAgent
  1133. .split(" ")
  1134. .find((v) => v.startsWith("Chrome/"));
  1135. if (shellVersion) {
  1136. window._hmt.push([
  1137. "_trackEvent",
  1138. "登录页面",
  1139. "学生端版本",
  1140. shellVersion + "/" + chromeVersion,
  1141. ]);
  1142. } else {
  1143. window._hmt.push(["_trackEvent", "登录页面", "浏览器登录"]);
  1144. if (chromeVersion) {
  1145. window._hmt.push([
  1146. "_trackEvent",
  1147. "登录页面",
  1148. "学生端版本/chrome",
  1149. chromeVersion,
  1150. ]);
  1151. } else {
  1152. window._hmt.push([
  1153. "_trackEvent",
  1154. "登录页面",
  1155. "学生端版本/其他浏览器",
  1156. window.navigator.userAgent,
  1157. ]);
  1158. }
  1159. }
  1160. },
  1161. async epccLogin() {
  1162. const {
  1163. accountType,
  1164. accountValue,
  1165. rootOrgId,
  1166. appId,
  1167. timestamp,
  1168. token,
  1169. redirectUrl,
  1170. } = this.$route.query;
  1171. if (
  1172. accountType &&
  1173. accountValue &&
  1174. rootOrgId &&
  1175. appId &&
  1176. timestamp &&
  1177. token &&
  1178. redirectUrl
  1179. ) {
  1180. try {
  1181. const response = await this.$http.post(
  1182. "/api/ecs_core/auth/thirdPartyStudentAccess" + location.search
  1183. );
  1184. return response;
  1185. } catch (error) {
  1186. window._hmt.push(["_trackEvent", "第三方登录页面", "接口出错", ""]);
  1187. this.$Spin.hide();
  1188. this.logout();
  1189. }
  1190. } else {
  1191. this.$Spin.hide();
  1192. this.logout();
  1193. }
  1194. },
  1195. handleGtResult(captchaObj) {
  1196. // console.log(captchaObj);
  1197. this.captchaObj = captchaObj;
  1198. },
  1199. },
  1200. };
  1201. </script>
  1202. <style scoped>
  1203. .home {
  1204. display: flex;
  1205. flex-direction: column;
  1206. height: 100vh;
  1207. }
  1208. .school-logo-container {
  1209. justify-self: flex-start;
  1210. margin-left: 100px;
  1211. }
  1212. .school-logo {
  1213. height: 100px;
  1214. width: 400px;
  1215. object-fit: cover;
  1216. }
  1217. .header {
  1218. min-height: 120px;
  1219. display: grid;
  1220. align-items: center;
  1221. justify-items: center;
  1222. }
  1223. .center {
  1224. background-image: url("https://cdn.qmth.com.cn/ui/ecs-client-bg.jpg!/progressive/true");
  1225. background-position: center;
  1226. background-repeat: no-repeat;
  1227. background-size: cover;
  1228. width: 100vw;
  1229. min-height: 600px;
  1230. }
  1231. .content {
  1232. margin-top: 100px;
  1233. margin-left: 60%;
  1234. width: 340px;
  1235. border-radius: 6px;
  1236. background-color: white;
  1237. display: grid;
  1238. grid-template-areas: "";
  1239. }
  1240. .login-type {
  1241. flex: 1;
  1242. line-height: 40px;
  1243. background-color: #eeeeee;
  1244. }
  1245. .active-type {
  1246. background-color: #ffffff;
  1247. }
  1248. .single-login-type {
  1249. border-top-left-radius: 6px;
  1250. border-top-right-radius: 6px;
  1251. }
  1252. .form-item-style {
  1253. margin-bottom: 30px;
  1254. height: 42px;
  1255. }
  1256. .close {
  1257. position: absolute;
  1258. top: 0;
  1259. right: 0;
  1260. background-color: #eeeeee;
  1261. color: #999999;
  1262. width: 80px;
  1263. height: 40px;
  1264. line-height: 40px;
  1265. border-bottom-left-radius: 6px;
  1266. }
  1267. .close:hover {
  1268. color: #444444;
  1269. }
  1270. .footer {
  1271. position: relative;
  1272. }
  1273. </style>
  1274. <style>
  1275. .ivu-message-notice-content-text {
  1276. font-size: 32px;
  1277. }
  1278. .ivu-message-notice-content-text i.ivu-icon {
  1279. font-size: 32px;
  1280. }
  1281. </style>