Login.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div>
  3. <header class="login-header">
  4. <a href="javascript:void(0)">
  5. <img v-if="!jwptCustomize" src="../assets/images/login_footer_logo.jpg">
  6. <img v-if="jwptCustomize" src="../assets/images/new_login_logo.png">
  7. </a>
  8. <ul>
  9. <li>
  10. <span></span>
  11. </li>
  12. <li>
  13. <h1 v-if="!jwptCustomize">考试云平台</h1>
  14. <h1 v-if="jwptCustomize" style="line-height: 36px; font-size: 24px">{{title}}</h1>
  15. </li>
  16. </ul>
  17. </header>
  18. <!--main-->
  19. <main class="login-main">
  20. <div class="main_bg"></div>
  21. <div class="main_box">
  22. <div class="left_tree fl"><img src="../assets/images/login_main_left_tree.png"></div>
  23. <div class="right_login fr">
  24. <div class="login">
  25. <h1>用户登录</h1>
  26. <div class="username">
  27. <i></i>
  28. <input @keyup.enter="login()" type="text" id="accountValue" v-model="loginInfo.accountValue" placeholder="账号" />
  29. </div>
  30. <div class="password">
  31. <em></em>
  32. <input @keyup.enter="login()" type="password" id="password" v-model="loginInfo.password" placeholder="密码" />
  33. </div>
  34. <input type="button" value="登 录" class="btn" @click="login()" />
  35. </div>
  36. </div>
  37. </div>
  38. </main>
  39. <!--footer-->
  40. <footer class="login-footer">
  41. <div class="main">
  42. <div>Copyright &copy; 2016
  43. <a href="javascript:void(0)">讯飞启明</a>.</div>
  44. </div>
  45. </footer>
  46. </div>
  47. </template>
  48. <script>
  49. import { mapActions } from "vuex";
  50. import { USER_SIGNIN } from "../store/user";
  51. import { core_api } from "../constants/constants";
  52. export default {
  53. data() {
  54. return {
  55. pending: false,
  56. errorInfo: "",
  57. title: "考试云平台",
  58. jwptCustomize: false,
  59. loginInfo: {
  60. rootOrgId: "",
  61. domain: "",
  62. accountType: "COMMON_LOGIN_NAME",
  63. accountValue: "",
  64. password: ""
  65. }
  66. };
  67. },
  68. methods: {
  69. ...mapActions([USER_SIGNIN]),
  70. checkAccountValue() {
  71. this.errorInfo = "";
  72. if (!this.loginInfo.accountValue) {
  73. this.errorInfo += "账号不能为空!\n";
  74. }
  75. if (this.errorInfo) {
  76. this.$notify({
  77. showClose: true,
  78. message: this.errorInfo,
  79. type: "error"
  80. });
  81. return false;
  82. }
  83. return true;
  84. },
  85. checkPassword() {
  86. this.errorInfo = "";
  87. if (!this.loginInfo.password) {
  88. this.errorInfo += "密码不能为空!\n";
  89. }
  90. if (this.errorInfo) {
  91. this.$notify({
  92. showClose: true,
  93. message: this.errorInfo,
  94. type: "error"
  95. });
  96. return false;
  97. }
  98. return true;
  99. },
  100. login() {
  101. if (!this.checkAccountValue()) {
  102. return;
  103. }
  104. if (!this.checkPassword()) {
  105. return;
  106. }
  107. if (this.pending) {
  108. return;
  109. }
  110. this.pending = true;
  111. var url = core_api + "/auth/login";
  112. this.$http
  113. .post(url, this.loginInfo)
  114. .then(response => {
  115. console.log(response);
  116. var user = response.data;
  117. this.USER_SIGNIN(user);
  118. user.loginUrl = "http://" + window.location.host + "/#/login";
  119. user.indexUrl = "http://" + window.location.host + "/#/index";
  120. window.name = JSON.stringify(user);
  121. this.$router.replace({ path: "/home" });
  122. this.$notify({
  123. message: "登录成功",
  124. type: "success"
  125. });
  126. this.pending = false;
  127. })
  128. .catch(response => {
  129. if (response.status == 500) {
  130. this.$notify({
  131. showClose: true,
  132. message: response.body.desc,
  133. type: "error"
  134. });
  135. }
  136. this.pending = false;
  137. });
  138. },
  139. jwptCustomizeMethod() {
  140. // 普通高校考试综合管理平台 定制
  141. if (location.host === "jwpt.ecs.qmth.com.cn") {
  142. document.title = "普通高校-题库";
  143. this.title = " | 普通高校-题库";
  144. this.jwptCustomize = true;
  145. }
  146. }
  147. },
  148. created() {
  149. this.loginInfo.domain = window.location.host;
  150. sessionStorage.clear();
  151. var params = this.$route.query;
  152. this.loginInfo.rootOrgId = params.orgId;
  153. console.log("rootOrgId=" + this.loginInfo.rootOrgId);
  154. this.jwptCustomizeMethod();
  155. },
  156. watch: {
  157. $route(to, from) {
  158. this.loginInfo.rootOrgId = to.query.orgId;
  159. }
  160. }
  161. };
  162. </script>
  163. <style lang="css">
  164. .h1 {
  165. font-family: "Micrsoft YaHei";
  166. }
  167. </style>