Login.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div class="login">
  3. <el-row style="z-index: 1;height: 100%;">
  4. <el-card class="login-box" element-loading-background="rgba(0, 0, 0, 0.8)">
  5. <el-form ref="form" :model="form" :rules="rules" label-with="80px" @keyup.enter.native="handleSubmit">
  6. <h1 class="title">Spug运维平台</h1>
  7. <!--<p class="login-box-msg">运维平台</p>-->
  8. <el-form-item prop="username">
  9. <el-input v-model="form.username" :autofocus="true" placeholder="请输入用户">
  10. <template slot="prepend">
  11. <i class="fa fa-user"></i>
  12. </template>
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item prop="password">
  16. <el-input type="password" v-model="form.password" placeholder="请输入密码" >
  17. <template slot="prepend">
  18. <i class="fa fa-lock"></i>
  19. </template>
  20. </el-input>
  21. </el-form-item>
  22. <el-form-item>
  23. <el-alert v-if="error" :title="error" type="error" style="margin-top: -10px; margin-bottom: 10px" show-icon></el-alert>
  24. <el-button type="primary" :loading="loading" @click="handleSubmit" style="width: 100%">登录</el-button>
  25. </el-form-item>
  26. </el-form>
  27. </el-card>
  28. </el-row>
  29. </div>
  30. </template>
  31. <style>
  32. .login {
  33. background: url(../assets/login.jpg) no-repeat scroll center center / cover;
  34. background-size: 100% 100%;
  35. width: 100%;
  36. height: 100%;
  37. position: fixed;
  38. }
  39. .login-box {
  40. background: rgba(0, 0, 0, 0.5);
  41. border: none;
  42. width: 25%;
  43. position: absolute;
  44. top: 50%;
  45. left: 50%;
  46. transform: translate3d(-50%, -50%,0);
  47. -webkit-transform: translate3d(-50%, -50%,0);
  48. }
  49. .login-box-msg {
  50. color: #ffffff;
  51. text-align: center;
  52. }
  53. .login-box .title {
  54. color: #ffffff;
  55. text-align: center;
  56. }
  57. </style>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. loading: false,
  63. error: '',
  64. form: {
  65. username: '',
  66. password: ''
  67. },
  68. rules: {
  69. username: [
  70. {required: true, message: '请输入用户', trigger: 'blur'}
  71. ],
  72. password: [
  73. {required: true, message: '请输入密码', trigger: 'blur'}
  74. ]
  75. }
  76. }
  77. },
  78. methods: {
  79. handleSubmit() {
  80. this.error = '';
  81. this.$refs['form'].validate(pass => {
  82. if (!pass) {
  83. return false
  84. }
  85. this.loading = true;
  86. this.$http.post('/api/account/users/login/', this.form).then(res => {
  87. localStorage.setItem('token', res.result['token']);
  88. localStorage.setItem('is_supper', res.result['is_supper']);
  89. localStorage.setItem('permissions', res.result['permissions']);
  90. localStorage.setItem('user_id', res.result['id']);
  91. localStorage.setItem('nickname', res.result['nickname']);
  92. this.$router.push('/welcome');
  93. }, response => {
  94. this.error = response.result
  95. }).finally(() => this.loading = false)
  96. })
  97. }
  98. },
  99. watch: {
  100. form: {
  101. handler: function () {
  102. this.error = ''
  103. },
  104. deep: true
  105. }
  106. }
  107. }
  108. </script>