Ver código fonte

fix: 加上登录注释

zhaojing 2 anos atrás
pai
commit
1b37ffc11b
2 arquivos alterados com 12 adições e 6 exclusões
  1. 8 3
      src/app.tsx
  2. 4 3
      src/pages/Login/index.tsx

+ 8 - 3
src/app.tsx

@@ -28,11 +28,16 @@ export async function getInitialState(): Promise<{
 }> {
   const { location } = history;
   let currentUser = {};
-  //debugger;
   const checkUser = async () => {
     //获取用户信息 查看权限
-    var userres = await getUsersInfo();
-    if (userres.result === 'success') {
+    try {
+      var userres = await getUsersInfo();
+    } catch (err) {
+      history.push('/login');
+      return {};
+    }
+
+    if (userres?.result === 'success') {
       var roles = userres.roles || [];
       if (
         roles.find((item: any) => {

+ 4 - 3
src/pages/Login/index.tsx

@@ -1,4 +1,4 @@
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useRef } from 'react';
 import { Button, Form, Input } from 'antd';
 import { history, useModel } from 'umi';
 import { login } from '@/services/sagacare_service/equipment';
@@ -16,7 +16,7 @@ const Login: React.FC = () => {
   const onFinishFailed = (errorInfo) => {
     console.log('Failed:', errorInfo);
   };
-
+  //输入用户名 密码的登录
   const onSubmit = (values: any) => {
     let params: any = values;
     login(params)
@@ -24,7 +24,7 @@ const Login: React.FC = () => {
         let resData: any = loginres || {};
         if (resData.result === 'success') {
           localStorage.setItem('token', resData.token);
-          history.push('/equipment');
+          history.push('/equipment'); //登录成功跳转页面
           refresh(); //这个方法会调用 getInitialState方法,getInitialState方法获取用户信息
           // getUsersInfo()
           //   .then((userres) => {
@@ -61,6 +61,7 @@ const Login: React.FC = () => {
       })
       .catch(() => {});
   };
+
   return (
     <div className="homeContent">
       <div className="home-left">