login.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div class="main_bg">
  3. <div class="login-main">
  4. <div class="username">
  5. <input class="form-control comminput" @keyup.enter="login()" type="text" id="accountValue" v-model="loginInfo.accountValue" placeholder="账号" />
  6. </div>
  7. <div class="password">
  8. <input class="form-control comminput" @keyup.enter="login()" type="password" id="password" v-model="loginInfo.password" placeholder="密码" />
  9. </div>
  10. <div class="domain">
  11. <input class="form-control comminput" @keyup.enter="login()" type="text" id="domain" v-model="loginInfo.domain" placeholder="机构域名" />
  12. </div>
  13. <input type="button" value="登 录" class="btn comminput" style="background: #3ed798;color:white;" @click="login()" />
  14. <div class="errorInfo">{{errorInfo}}</div>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. pending: false,
  23. errorInfo: "",
  24. loginInfo: {
  25. rootOrgId: "",
  26. domain: "",
  27. accountType: "COMMON_LOGIN_NAME",
  28. accountValue: "",
  29. password: ""
  30. }
  31. };
  32. },
  33. methods: {
  34. checkAccountValue() {
  35. this.errorInfo = "";
  36. if (!this.loginInfo.accountValue) {
  37. this.errorInfo += "用户名不能为空!\n";
  38. return false;
  39. }
  40. return true;
  41. },
  42. checkPassword() {
  43. this.errorInfo = "";
  44. if (!this.loginInfo.password) {
  45. this.errorInfo += "密码不能为空!\n";
  46. return false;
  47. }
  48. return true;
  49. },
  50. checkDomain() {
  51. this.errorInfo = "";
  52. if (!this.loginInfo.domain) {
  53. this.errorInfo += "机构域名不能为空!\n";
  54. return false;
  55. }
  56. return true;
  57. },
  58. login() {
  59. if (!this.checkAccountValue()) {
  60. return;
  61. }
  62. if (!this.checkPassword()) {
  63. return;
  64. }
  65. if (!this.checkDomain()) {
  66. return;
  67. }
  68. if (this.pending) {
  69. return;
  70. }
  71. this.pending = true;
  72. this.$http
  73. .post("/api/ecs_core/auth/login", this.loginInfo)
  74. .then(response => {
  75. var user = response.data;
  76. localStorage.setItem("user_token", user.userToken);
  77. localStorage.setItem("rootOrgId", user.rootOrgId);
  78. localStorage.setItem("userName", user.displayName);
  79. this.$router.replace({ path: "/index" });
  80. this.pending = false;
  81. })
  82. .catch(response => {
  83. this.errorInfo += response.body.desc;
  84. this.pending = false;
  85. });
  86. }
  87. },
  88. created() {
  89. var params = this.$route.query;
  90. this.loginInfo.rootOrgId = params.orgId;
  91. }
  92. };
  93. </script>
  94. <style>
  95. .h1 {
  96. font-family: "Micrsoft YaHei";
  97. }
  98. </style>