Login.vue 34 KB

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