Login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <div class="home">
  3. <header class="header">
  4. <div class="school-logo"><img class="logo-size" :src="this.logoPath" alt="school logo" />
  5. </div>
  6. <a class="close" style="border-bottom-left-radius: 6px;" @click="closeApp">关闭</a>
  7. </header>
  8. <div class="center">
  9. <div class="content">
  10. <div style="display:flex;">
  11. <a v-if="this.$route.params.domain !== 'cugr.ecs.qmth.com.cn'" :class="['qm-big-text', 'login-type', loginType === 'STUDENT_CODE' && 'active-type']" @click="loginType='STUDENT_CODE'" style="border-top-left-radius: 6px">学号登录</a>
  12. <a :class="['qm-big-text', 'login-type', loginType !== 'STUDENT_CODE' && 'active-type']" @click="loginType='STUDENT_IDENTITY_NUMBER'" style="border-top-right-radius: 6px">身份证号登录</a>
  13. </div>
  14. <div class="qm-title-text" style="margin: 40px 0 20px 0">
  15. 远程教育网络考试
  16. </div>
  17. <div style="margin: 0 40px 40px 40px">
  18. <i-form ref="loginForm" :model="loginForm" :rules="loginFormRule">
  19. <i-form-item prop="accountValue" style='margin-bottom:35px;height:42px'>
  20. <i-input type="text" size="large" v-model="loginForm.accountValue" :placeholder="usernameInputPlaceholder">
  21. <i-icon type="ios-person" slot="prepend"></i-icon>
  22. </i-input>
  23. </i-form-item>
  24. <i-form-item prop="password" style='margin-bottom:35px;height:42px'>
  25. <i-input type="password" size="large" v-model="loginForm.password" :placeholder="passwordInputPlaceholder" @on-enter="login('loginForm')">
  26. <i-icon type="ios-lock" slot="prepend"></i-icon>
  27. </i-input>
  28. </i-form-item>
  29. <i-form-item>
  30. <div v-if="errorInfo !== ''">
  31. <i-alert type="error" show-icon>{{errorInfo}}</i-alert>
  32. </div>
  33. <i-button size="large" class="qm-primary-button" long :disabled="disableLoginBtn" @click="login('loginForm')">登录</i-button>
  34. </i-form-item>
  35. </i-form>
  36. </div>
  37. </div>
  38. </div>
  39. <footer class="footer"></footer>
  40. </div>
  41. </template>
  42. <script>
  43. import moment from "moment";
  44. import { mapMutations } from "vuex";
  45. /**
  46. * 在任何组件需要强制退出,做以下步骤
  47. * 1. this.$Message.info()
  48. * 2. this.$router.push("/login"+domain);
  49. * 因为在/login里会删除localStorage的token,而在router.beforeEach会检查是否有token,达到退出的目的。
  50. */
  51. export default {
  52. data() {
  53. return {
  54. logoPath: "/api/ecs_core/org/logo?domain=" + this.$route.params.domain,
  55. productName: "远程教育网络考试",
  56. loginType: "STUDENT_CODE",
  57. errorInfo: "",
  58. loginForm: {
  59. accountValue: "",
  60. password: ""
  61. },
  62. loginFormRule: {
  63. accountValue: [
  64. {
  65. required: true,
  66. message: "请填写登录账号",
  67. trigger: "blur"
  68. }
  69. ],
  70. password: [
  71. {
  72. required: true,
  73. message: "请填写密码",
  74. trigger: "blur"
  75. }
  76. ]
  77. },
  78. disableLoginBtn: true
  79. };
  80. },
  81. async created() {
  82. if (this.$route.params.domain === "cugr.ecs.qmth.com.cn") {
  83. this.loginType = "STUDENT_IDENTITY_NUMBER";
  84. }
  85. this.$Message.config({
  86. duration: 15,
  87. size: "large",
  88. closable: true
  89. });
  90. try {
  91. const res = await this.$http.get(
  92. "/api/ecs_core/org/getRootOrgByCode?code=" + this.$route.params.domain
  93. );
  94. const productName = res.data.examSysName;
  95. this.productName = productName || "远程教育网络考试";
  96. } catch (e) {
  97. this.productName = "远程教育网络考试";
  98. }
  99. window.localStorage.removeItem("token");
  100. window.localStorage.removeItem("key");
  101. if (localStorage.getItem("user-for-reload")) {
  102. this.loginForm.accountValue = JSON.parse(
  103. localStorage.getItem("user-for-reload")
  104. ).studentCode;
  105. this.loginForm.password =
  106. process.env.NODE_ENV === "production" ? "" : "180613";
  107. }
  108. if (typeof nodeRequire != "undefined") {
  109. var that = this;
  110. var fs = window.nodeRequire("fs");
  111. var config;
  112. try {
  113. config = fs.readFileSync(process.cwd() + "/" + "config.js", "utf-8");
  114. console.log("使用旧客户端");
  115. } catch (error) {
  116. console.log("尝试使用新客户端");
  117. config = fs.readFileSync("config.js", "utf-8");
  118. }
  119. var nameJson = JSON.parse(config);
  120. let electronConfig = null;
  121. try {
  122. electronConfig = (await this.$http.get(
  123. "https://ecs.qmth.com.cn:8878/electron-config/" +
  124. nameJson.name +
  125. ".js"
  126. )).data;
  127. } catch (error) {
  128. this.$Message.error("获取机构的客户端设置失败,请退出后重试!");
  129. return;
  130. }
  131. //如果配置中配置了 checkRemoteControl:true
  132. if (electronConfig.otherConfig.checkRemoteControl) {
  133. window.nodeRequire("node-cmd").get("Project1.exe", function() {
  134. var applicationNames = fs.readFileSync(
  135. "remoteApplication.txt",
  136. "utf-8"
  137. );
  138. if (applicationNames && applicationNames.trim()) {
  139. that.disableLoginBtn = true;
  140. that.$Message.info({
  141. content:
  142. "在考试期间,请关掉" +
  143. applicationNames.trim() +
  144. "软件,诚信考试。",
  145. duration: 30
  146. });
  147. } else {
  148. that.disableLoginBtn = false;
  149. }
  150. });
  151. } else {
  152. that.disableLoginBtn = false;
  153. }
  154. } else {
  155. this.disableLoginBtn = false;
  156. }
  157. },
  158. methods: {
  159. ...mapMutations(["updateUser"]),
  160. async login(name) {
  161. if (this.disableLoginBtn) {
  162. return;
  163. }
  164. this.disableLoginBtn = true;
  165. setTimeout(() => (this.disableLoginBtn = false), 5000);
  166. const valid = await this.$refs[name].validate();
  167. if (valid) {
  168. console.log("form validated. start login...");
  169. } else {
  170. return;
  171. }
  172. let repPara = this.loginForm;
  173. // 以下网络请求失败,直接报网络异常错误
  174. const response = await this.$http.post("/api/ecs_core/auth/login", {
  175. ...repPara,
  176. accountType: this.loginType,
  177. domain: this.$route.params.domain
  178. });
  179. let data = response.data;
  180. if (Math.abs(moment(response.headers.date).diff(moment())) > 30 * 1000) {
  181. this.$Message.error({
  182. content: "与服务器时间差异超过30秒,请校准本机时间之后再重试!",
  183. duration: 30
  184. });
  185. throw "与服务器时间差异超过30秒,请校准本机时间之后再重试!";
  186. }
  187. if (data.token) {
  188. this.errorInfo = "";
  189. //缓存用户信息
  190. window.sessionStorage.setItem("token", data.token);
  191. window.localStorage.setItem("key", data.key);
  192. window.localStorage.setItem("domain", this.$route.params.domain);
  193. try {
  194. const student = (await this.$http.get(
  195. "/api/ecs_core/student/getStudentInfoBySession"
  196. )).data;
  197. const user = { ...data, ...student };
  198. this.updateUser(user);
  199. window.localStorage.setItem("user-for-reload", JSON.stringify(user));
  200. await this.checkExamInProgress();
  201. } catch (error) {
  202. this.$Message.error({
  203. content: "获取学生信息失败,请重试!",
  204. duration: 30
  205. });
  206. }
  207. } else {
  208. this.errorInfo = data.desc;
  209. }
  210. },
  211. async checkExamInProgress() {
  212. try {
  213. // 断点续考
  214. const examingRes = (await this.$http.get(
  215. "/api/ecs_oe_student/examControl/checkExamInProgress"
  216. )).data;
  217. if (examingRes) {
  218. this.$Spin.show({
  219. render: () => {
  220. return <div style="font-size: 24px">正在进入断点续考...</div>;
  221. }
  222. });
  223. this.$router.push(
  224. `/online-exam/exam/${examingRes.examId}/examRecordData/${
  225. examingRes.examRecordDataId
  226. }/order/1` +
  227. (examingRes.faceVerifyMinute
  228. ? `?faceVerifyMinute=${examingRes.faceVerifyMinute}`
  229. : "")
  230. );
  231. setTimeout(() => this.$Spin.hide(), 1000);
  232. return;
  233. }
  234. this.$router.push("/online-exam");
  235. } catch (error) {
  236. this.$Message.error("获取断点续考信息异常,退出登录");
  237. this.logout();
  238. return;
  239. }
  240. },
  241. closeApp() {
  242. window.close();
  243. }
  244. },
  245. computed: {
  246. usernameInputPlaceholder() {
  247. if (this.loginType === "STUDENT_CODE") {
  248. return "请输入学号";
  249. } else {
  250. return "请输入身份证号";
  251. }
  252. },
  253. passwordInputPlaceholder() {
  254. if (this.loginType === "STUDENT_CODE") {
  255. return "初始密码为身份证号后6位";
  256. } else {
  257. return "初始密码为身份证号后6位";
  258. }
  259. }
  260. }
  261. };
  262. </script>
  263. <style scoped>
  264. .home {
  265. display: flex;
  266. flex-direction: column;
  267. height: 100vh;
  268. }
  269. .school-logo {
  270. justify-self: flex-start;
  271. margin-left: 100px;
  272. }
  273. .logo-size {
  274. height: 100px;
  275. width: 300px;
  276. object-fit: cover;
  277. }
  278. .header {
  279. min-height: 120px;
  280. display: grid;
  281. align-items: center;
  282. justify-items: center;
  283. }
  284. .center {
  285. background-image: url("./bg.jpg");
  286. background-position: center;
  287. background-repeat: no-repeat;
  288. background-size: cover;
  289. width: 100vw;
  290. min-height: 600px;
  291. }
  292. .content {
  293. margin-top: 100px;
  294. margin-left: 65%;
  295. width: 300px;
  296. border-radius: 6px;
  297. background-color: white;
  298. display: grid;
  299. grid-template-areas: "";
  300. }
  301. .login-type {
  302. flex: 1;
  303. line-height: 40px;
  304. background-color: #eeeeee;
  305. }
  306. .active-type {
  307. background-color: #ffffff;
  308. }
  309. .close {
  310. position: absolute;
  311. top: 0;
  312. right: 0;
  313. background-color: #eeeeee;
  314. color: #999999;
  315. width: 80px;
  316. height: 40px;
  317. line-height: 40px;
  318. }
  319. .close:hover {
  320. color: #444444;
  321. }
  322. </style>
  323. <style>
  324. .ivu-message-notice-content-text {
  325. font-size: 32px;
  326. }
  327. .ivu-message-notice-content-text i.ivu-icon {
  328. font-size: 32px;
  329. }
  330. </style>