chao 10 mesiacov pred
rodič
commit
65d19ab8f5
3 zmenil súbory, kde vykonal 32 pridanie a 32 odobranie
  1. 13 4
      src/App.js
  2. 2 4
      src/view/login.js
  3. 17 24
      src/view/signIn.js

+ 13 - 4
src/App.js

@@ -6,11 +6,15 @@ import SignIn from './view/signIn';
 import hans from './assets/json/hans.json'
 import hant from './assets/json/hant.json'
 import en from './assets/json/en.json'
-import httpRequest from './http/http'
 import config from './config'
 import axios from 'axios';
+import { Alert } from '@mui/joy';
 function App() {
   const [lang, setLang] = useState(hans)
+  const [alertShow, setAlertShow] = useState(false)
+  const [alertStr, setAlertStr] = useState(false)
+
+
   useEffect(() => {
     if (window.location.hostname.indexOf('cocorobo.com') > -1) {
       setLang(en)
@@ -24,14 +28,19 @@ function App() {
       if (res.data.length > 0) {
         axios.get(`${config.edu}admin/userinfo/userinfoById/${res.data[0][0].userid}`).then(r => {
           if (r.data.length > 0) {
+            setAlertStr(lang.loginSuccess)
+            setAlertShow(true)
             postMessageToParent('loginVerify', 'logged', r.data[0][0])
-          } 
+            setTimeout(() => {
+              setAlertShow(false)
+            }, 1000)
+            
+          }
         })
       }
     }).catch(e => {
       console.log(e)
     })
-
   }, [])
   const postMessageToParent = (id, status, data) => {
     //TODO: replace origin
@@ -45,7 +54,7 @@ function App() {
   return (
     <BrowserRouter>
       <Routes>
-        <Route path="/" element={<Login lang={lang} />} />
+        <Route path="/" element={<Login lang={lang} alertShow={alertShow} alertStr={alertStr} />} />
         <Route path="/signIn" element={<SignIn lang={lang} />} />
       </Routes>
     </BrowserRouter>

+ 2 - 4
src/view/login.js

@@ -5,8 +5,6 @@ import UserImg from '../assets/image/user.png'
 import PassworldImg from '../assets/image/passworld.png'
 import config from '../config'
 import { Alert, CircularProgress } from '@mui/joy';
-// import CircularProgress from '@mui/joy/CircularProgress';
-import httpRequest from '../http/http'
 import qs from 'qs';
 import axios from 'axios'
 
@@ -154,8 +152,8 @@ function Login(props) {
     }
     return (
         <div className="login" onKeyDown={enter}>
-            {alertShow && <div className='login-Progress'>
-                <Alert color="danger">{alertStr}</Alert>
+            {(alertShow || props.alertShow) && <div className='login-Progress'>
+                <Alert color="danger">{alertStr || props.alertStr}</Alert>
             </div>}
             {loading && <div className='login-Progress'>
                 <CircularProgress size="lg" determinate value={progressValue}></CircularProgress>

+ 17 - 24
src/view/signIn.js

@@ -10,7 +10,7 @@ import Dialog from '@mui/material/Dialog';
 import DialogTitle from '@mui/material/DialogTitle';
 import DialogContent from '@mui/material/DialogContent';
 import DialogActions from '@mui/material/DialogActions';
-import httpRequest from '../http/http'
+import axios from 'axios';
 import qs from 'qs';
 import SignInModel from '../components/signInModel';
 import SignInModelOne from '../components/signModel1';
@@ -71,23 +71,21 @@ function SignUp(props) {
             googleId: '',
             identity: 1,
         }
-        httpRequest(`${config.api}api/user`, {
-            method: 'POST',
-            headers: {
-                'Content-Type': 'application/json'
-            },
-            body: JSON.stringify(params)
-        }).then(res => {
-            console.log(res)
+        axios.defaults.withCredentials = true;
+        axios.post(`${config.api}api/user`, qs.stringify(params)).then(res => {
             clearInterval(progressTimer)
-            if (res[0].length > 0) {
+            if (res.data.length > 0) {
                 setProgressValue(100)
-                showAlert(props.lang.signInSuccess)
+                showAlert(props.lang.loginSuccess)
+                setAlertShow(true)
                 setTimeout(() => {
                     setLoading(false)
                     setProgressValue(0)
-                }, 10)
+                    setAlertShow(false)
+                }, 1000)
             } else {
+                setLoading(false)
+                setProgressValue(0)
                 showAlert(res)
                 setAlertShow(true)
                 setTimeout(() => {
@@ -95,11 +93,12 @@ function SignUp(props) {
                 }, 1500);
             }
         }).catch(err => {
+            setProgressValue(0)
             clearInterval(progressTimer)
-            showAlert(props.lang.signInFail)
+            setLoading(false)
+            showAlert(props.lang.loginError)
             console.log(err)
         })
-
     }
 
     const schoolChange = (e) => {
@@ -117,17 +116,11 @@ function SignUp(props) {
 
     const getSchool = e => {
         // 获取学校信息
-        httpRequest(`${config.edu}admin/selectorganize`, {
-            method: 'POST',
-            headers: {
-                'Content-Type': 'application/x-www-form-urlencoded'
-            },
-            body: qs.stringify({ mode: e })
-        }).then(res => {
+        axios.post(`${config.edu}admin/selectorganize`, qs.stringify({ mode: e })).then(res => {
             console.log(res)
-            if (res[0].length > 0) {
-                setSchoolNum(res[0][0].mail)
-                setSchoolName(res[0][0].name)
+            if (res.data.length > 0) {
+                setSchoolNum(res.data[0][0].mail)
+                setSchoolName(res.data[0][0].name)
                 setSchoolShow(true)
             } else {
                 setSchoolName(props.lang.notSchool)