Login.vue 8.3 KB

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