login.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="loginpage">
  3. <el-card class="box-card">
  4. <div class="title">阳光学院AI化教学平台</div>
  5. <div class="login-form">
  6. <el-form ref="form" :model="form" :rules="rules" @keyup.enter.native="doLogin()" label-width="80px">
  7. <el-form-item prop="userName">
  8. <el-input v-model="form.userName" placeholder="用户名" prefix-icon="el-icon-user-solid"></el-input>
  9. </el-form-item>
  10. <el-form-item prop="password">
  11. <el-input v-model="form.password" type="password" placeholder="密码" prefix-icon="el-icon-key"></el-input>
  12. <el-checkbox v-model="form.checked" style="margin-top: 7px">一周内自动登录</el-checkbox>
  13. <span class="forget">忘记密码?</span>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button @click="doLogin" type="primary">登录</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </div>
  20. </el-card>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'login.vue',
  26. data () {
  27. return {
  28. rules: {
  29. userName: [
  30. {required: true, message: '请输入用户名', trigger: 'blur'},
  31. ],
  32. password: [
  33. {required: true, message: '请输入密码', trigger: 'blur'},
  34. ],
  35. },
  36. imgUrl: this.$httpApi.httpUrl('/api/image'),
  37. form: {
  38. userName: '',
  39. password: '',
  40. checked: false
  41. }
  42. }
  43. },
  44. methods: {
  45. doLogin () {
  46. this.$refs['form'].validate((valid) => {
  47. if (valid) {
  48. this.axios.post(this.$httpApi.httpUrl('/student/login'), this.form)
  49. .then(response => {
  50. let result = response.data.data
  51. let token = response.headers.authorization
  52. this.$store.commit('user/updateToken', token)
  53. let userInfo = {
  54. name: result.name,
  55. id: result.id,
  56. headImg: result.headImg,
  57. sex: result.sex,
  58. age: result.age,
  59. gradeInfoName: result.gradeInfoName,
  60. gradeInfoId: result.gradeInfoId,
  61. address: result.address,
  62. mobile: result.mobile,
  63. }
  64. if (result.webSiteConfig) {
  65. this.$store.commit('common/updateWebSiteConfig', result.webSiteConfig)
  66. }
  67. this.$store.commit('user/updateUserInfo', userInfo)
  68. this.$message({
  69. type: 'success',
  70. message: response.data.message,
  71. duration:1000,
  72. })
  73. setTimeout(() =>{
  74. this.$router.push('/home')
  75. }, 1000)
  76. })
  77. }
  78. })
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="less" scoped>
  84. .forget {
  85. float: right;
  86. margin-top: 7px;
  87. cursor: pointer;
  88. }
  89. .forget:hover {
  90. color: #409eff;
  91. }
  92. .title {
  93. position: absolute;
  94. left: 25%;
  95. top: 10%;
  96. color: #409eff;
  97. font-weight: 700;
  98. font-size: 24px;
  99. margin-bottom: 20px;
  100. text-align: center;
  101. }
  102. .box-card {
  103. height: 380px;
  104. width: 420px;
  105. position: relative;
  106. top: 20%;
  107. left: 60%;
  108. }
  109. .el-button {
  110. width: 100%;
  111. }
  112. .login-form {
  113. width: 420px;
  114. position: absolute;
  115. top: 30%;
  116. right: 10%;
  117. }
  118. .loginpage{
  119. height: 100%;
  120. width: 100%;
  121. box-sizing: border-box;
  122. background: url("/static/image/timg.jpg");
  123. background-size:100% 100%; // background: url('/static/image/loginng.gif') no-repeat;
  124. background-position: center;
  125. position: fixed;
  126. }
  127. </style>