ChenYangfan 6 лет назад
Родитель
Сommit
8ec77c21f1
3 измененных файлов с 40 добавлено и 13 удалено
  1. 2 2
      src/components/CButton.vue
  2. 9 6
      src/server/user.js
  3. 29 5
      src/views/login/Login.vue

+ 2 - 2
src/components/CButton.vue

@@ -83,11 +83,11 @@ button {
   color: white;
   cursor: not-allowed;
   &:hover {
-    background: #cadaea;
+    background: #daeafa;
   }
 
   &:active {
-    background: #cadaea;
+    background: #daeafa;
   }
 }
 </style>

+ 9 - 6
src/server/user.js

@@ -7,7 +7,7 @@ import showMessage from '@/server/utils/show-message'
 import showErrorMessage from '@/server/utils/show-error-message'
 import catchHandler from '@/server/utils/catch-handler'
 
-export function register({ name, email, emailCode, phone, phoneCode, password }) {
+export function register ({ name, email, emailCode, phone, phoneCode, password }) {
   const data = {
     name,
     email,
@@ -34,7 +34,7 @@ export function register({ name, email, emailCode, phone, phoneCode, password })
     })
 }
 
-export function emailLogin({ email, password }) {
+export function emailLogin ({ email, password }) {
   const data = {
     username: email,
     password
@@ -45,14 +45,17 @@ export function emailLogin({ email, password }) {
     .then(res => {
       const resourceResponse = res.data
       if (resourceResponse.code === httpCode.success) {
+        showMessage({ message: '欢迎回来,' + resourceResponse.data.name })
         return resourceResponse.data
       } else {
-        // TODO
+        showErrorMessage(resourceResponse.msg)
       }
+    }).catch(() => {
+      catchHandler()
     })
 }
 
-export function logout() {
+export function logout () {
   return axios
     .post(useUserServer('/logout'))
     .then(res => {
@@ -65,7 +68,7 @@ export function logout() {
     })
 }
 
-export function modifyUser({ name, password }) {
+export function modifyUser ({ name, password }) {
   const data = {
     name,
     password
@@ -80,7 +83,7 @@ export function modifyUser({ name, password }) {
     })
 }
 
-export function getUserInfo() {
+export function getUserInfo () {
   return axios
     .get(useUserServer())
     .then(res => {

+ 29 - 5
src/views/login/Login.vue

@@ -2,10 +2,10 @@
   <div class="login-view-container">
     <div>
       <h1 class="title"><span>SEEC</span> 用户登录</h1>
-      <c-input placeholder="邮箱"></c-input>
-      <c-input placeholder="密码"></c-input>
+      <c-input placeholder="邮箱" type="email" v-model="email"></c-input>
+      <c-input placeholder="密码" type="password" v-model="password"></c-input>
       <div class="button-area">
-        <c-button @click="handleSubmit">确认</c-button>
+        <c-button @click="handleSubmit" :disabled="!formChecked()">登录</c-button>
         <c-button class="secondary" @click="handleToRegister">去注册</c-button>
       </div>
       <background></background>
@@ -17,12 +17,36 @@
 import CInput from '@/components/CInput'
 import CButton from '@/components/CButton'
 import Background from '@/components/Background'
+import { emailLogin } from '@/server/user'
 
 export default {
   components: { CButton, CInput, Background },
+  data () {
+    return {
+      email: '',
+      password: ''
+    }
+  },
   methods: {
+    formChecked () {
+      return this.email && this.password
+    },
     handleSubmit () {
-      this.$router.push('/teacher')
+      if (!this.formChecked()) {
+        this.$showMessage({ message: '请填写完整的信息', type: 'info' })
+        return
+      }
+
+      emailLogin({ email: this.email, password: this.password }).then(res => {
+        if (res) {
+          localStorage.setItem('userInfo', JSON.stringify(res))
+          if (res.type === 'TEACHER' || res.type === 'teacher') {
+            this.$router.push({ name: 'teacher' })
+          } else {
+            this.$router.push({ name: 'student' })
+          }
+        }
+      })
     },
     handleToRegister () {
       this.$router.push({ name: 'register' })
@@ -39,7 +63,7 @@ export default {
   justify-content: center;
 
   & > div {
-    max-width: 360px;
+    max-width: 340px;
     padding: 60px 24px;
     width: 100%;
   }