login.vue 3.1 KB

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