Login.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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 = fs.readFileSync("config.js", "utf-8");
  112. var nameJson = JSON.parse(config);
  113. let electronConfig = null;
  114. try {
  115. electronConfig = (await this.$http.get(
  116. "https://ecs.qmth.com.cn:8878/electron-config/" +
  117. nameJson.name +
  118. ".js"
  119. )).data;
  120. } catch (error) {
  121. this.$Message.error("获取机构的客户端设置失败,请退出后重试!");
  122. return;
  123. }
  124. //如果配置中配置了 checkRemoteControl:true
  125. if (electronConfig.otherConfig.checkRemoteControl) {
  126. window.nodeRequire("node-cmd").get("Project1.exe", function() {
  127. var applicationNames = fs.readFileSync(
  128. "remoteApplication.txt",
  129. "utf-8"
  130. );
  131. if (applicationNames && applicationNames.trim()) {
  132. that.disableLoginBtn = true;
  133. that.$Message.info({
  134. content:
  135. "在考试期间,请关掉" +
  136. applicationNames.trim() +
  137. "软件,诚信考试。",
  138. duration: 30
  139. });
  140. } else {
  141. that.disableLoginBtn = false;
  142. }
  143. });
  144. } else {
  145. that.disableLoginBtn = false;
  146. }
  147. } else {
  148. this.disableLoginBtn = false;
  149. }
  150. },
  151. methods: {
  152. ...mapMutations(["updateUser"]),
  153. async login(name) {
  154. if (this.disableLoginBtn) {
  155. return;
  156. }
  157. this.disableLoginBtn = true;
  158. setTimeout(() => (this.disableLoginBtn = false), 5000);
  159. const valid = await this.$refs[name].validate();
  160. if (valid) {
  161. console.log("form validated. start login...");
  162. } else {
  163. return;
  164. }
  165. let repPara = this.loginForm;
  166. // 以下网络请求失败,直接报网络异常错误
  167. const response = await this.$http.post("/api/ecs_core/auth/login", {
  168. ...repPara,
  169. accountType: this.loginType,
  170. domain: this.$route.params.domain
  171. });
  172. let data = response.data;
  173. if (Math.abs(moment(response.headers.date).diff(moment())) > 30 * 1000) {
  174. this.$Message.error({
  175. content: "与服务器时间差异超过30秒,请校准本机时间之后再重试!",
  176. duration: 30
  177. });
  178. throw "与服务器时间差异超过30秒,请校准本机时间之后再重试!";
  179. }
  180. if (data.token) {
  181. this.errorInfo = "";
  182. //缓存用户信息
  183. window.sessionStorage.setItem("token", data.token);
  184. window.localStorage.setItem("key", data.key);
  185. window.localStorage.setItem("domain", this.$route.params.domain);
  186. try {
  187. const student = (await this.$http.get(
  188. "/api/ecs_core/student/getStudentInfoBySession"
  189. )).data;
  190. const user = { ...data, ...student };
  191. this.updateUser(user);
  192. window.localStorage.setItem("user-for-reload", JSON.stringify(user));
  193. this.$router.push("/online-exam");
  194. } catch (error) {
  195. this.$Message.error({
  196. content: "获取学生信息失败,请重试!",
  197. duration: 30
  198. });
  199. }
  200. } else {
  201. this.errorInfo = data.desc;
  202. }
  203. },
  204. closeApp() {
  205. window.close();
  206. }
  207. },
  208. computed: {
  209. usernameInputPlaceholder() {
  210. if (this.loginType === "STUDENT_CODE") {
  211. return "请输入学号";
  212. } else {
  213. return "请输入身份证号";
  214. }
  215. },
  216. passwordInputPlaceholder() {
  217. if (this.loginType === "STUDENT_CODE") {
  218. return "初始密码为身份证号后6位";
  219. } else {
  220. return "初始密码为身份证号后6位";
  221. }
  222. }
  223. }
  224. };
  225. </script>
  226. <style scoped>
  227. .home {
  228. display: flex;
  229. flex-direction: column;
  230. height: 100vh;
  231. }
  232. .school-logo {
  233. margin-left: -600px;
  234. }
  235. .logo-size {
  236. height: 100px;
  237. width: 300px;
  238. object-fit: cover;
  239. }
  240. .header {
  241. min-height: 120px;
  242. display: grid;
  243. align-items: center;
  244. justify-items: center;
  245. }
  246. .center {
  247. background-image: url("./bg.jpg");
  248. background-position: center;
  249. background-repeat: no-repeat;
  250. background-size: cover;
  251. width: 100vw;
  252. min-height: 600px;
  253. }
  254. .content {
  255. margin-top: 100px;
  256. margin-left: 65%;
  257. width: 300px;
  258. border-radius: 6px;
  259. background-color: white;
  260. display: grid;
  261. grid-template-areas: "";
  262. }
  263. .login-type {
  264. flex: 1;
  265. line-height: 40px;
  266. background-color: #eeeeee;
  267. }
  268. .active-type {
  269. background-color: #ffffff;
  270. }
  271. .close {
  272. position: absolute;
  273. top: 0;
  274. right: 0;
  275. background-color: #eeeeee;
  276. color: #999999;
  277. width: 80px;
  278. height: 40px;
  279. line-height: 40px;
  280. }
  281. .close:hover {
  282. color: #444444;
  283. }
  284. </style>
  285. <style>
  286. .ivu-message-notice-content-text {
  287. font-size: 32px;
  288. }
  289. .ivu-message-notice-content-text i.ivu-icon {
  290. font-size: 32px;
  291. }
  292. </style>