人生啊人生 3 semanas atrás
pai
commit
21de44b844
1 arquivos alterados com 31 adições e 2 exclusões
  1. 31 2
      user_web/src/view/LogInExe.vue

+ 31 - 2
user_web/src/view/LogInExe.vue

@@ -35,6 +35,7 @@ import { ElForm, ElInput, ElNotification } from 'element-plus';
 import { loginApi, getCurrentUser } from '@/api/userApi';
 import { useUserInfo } from '@/stores/userInfo';
 import router from '../router/index';
+import { ElMessage } from 'element-plus';
 
 const userInfo = useUserInfo();
 const formRef = ref<InstanceType<typeof ElForm>>();
@@ -140,10 +141,38 @@ const onSubmit = (formEl: InstanceType<typeof ElForm> | undefined) => {
  */
 const loginEvent = () => {
     
-    console.log("新的登陆逻辑 form", form);
-
+    // console.log("新的登陆逻辑 form", form);
+    if (form.username == null || form.username == undefined || form.username == '') {
+        ElMessage({ message: '账号必须填写', type: 'warning', });
+        return;
+    }
 
+    if (form.password == null || form.password == undefined || form.password == '') {
+        ElMessage({ message: '密码必须填写', type: 'warning', });
+        return;
+    }
 
+    loginApi(form).then((res) => {
+        if (res.data.data.token) {
+            userInfo.setToken(res.data.data.token, 'auth');
+            const userType = res.data.data.userType;
+            getCurrentUser().then((res) => {
+                userInfo.dataFill(Object.assign({ userType: userType }, res.data.data));
+
+                // 老师
+                if (userType == 0) router.push({ path: '/TaskMng' });
+                // 学生
+                else if (userType == 1) router.push({ path: '/studentMain' });
+                else {
+                    ElNotification({
+                        message: '无效用户',
+                        type: 'info',
+                    });
+                }
+            });
+        }
+    });
+    
 }
 
 const regularPassword = (val: string) => {