add css module compile rule and a login guard
Change-Id: I5c99e236f92d3b6c6d0060b36cf90a252df93a95
diff --git a/src/views/forum/index.tsx b/src/views/forum/index.tsx
index 6090868..6e8ad59 100644
--- a/src/views/forum/index.tsx
+++ b/src/views/forum/index.tsx
@@ -1,11 +1,13 @@
import React from "react";
import { Navigate } from "react-router";
+import SelfStatus from "@/components/selfStatus/selfStatus";
export default function Forum() {
return (
<div>
+ <SelfStatus/>
<h1>Forum</h1>
<p>Welcome to the forum!</p>
</div>
diff --git a/src/views/login/index.tsx b/src/views/login/index.tsx
index 9c1abc2..4cb66a5 100644
--- a/src/views/login/index.tsx
+++ b/src/views/login/index.tsx
@@ -1,29 +1,37 @@
import React, { useEffect } from 'react';
import { useApi } from '@/hooks/request';
import request from '@/utils/request';
-import {userLogin} from '@/api/user';
+import { userLogin } from '@/api/user';
import { useAppDispatch } from '@/hooks/store';
+import { RootState } from '@/store';
+import style from './login.module.css';
+import { useSelector } from 'react-redux';
+import { useNavigate } from 'react-router';
const Login: React.FC = () => {
-
const dispatch = useAppDispatch();
const { data, loading, error, refresh } = useApi(() => request.post(userLogin), false);
+ const nav = useNavigate();
const handleLogin = async () => {
- // 点击时调用 execute 发起请求
const res = await refresh();
console.log(res);
- // 请求完成后可以使用返回的数据进行分发
dispatch({ type: "user/login", payload: res });
+ nav('/');
+
};
+ const userName = useSelector((state: RootState) => state.user.userName);
+
return (
- <div>
- <input type='email'></input>
- <input></input>
- <button onClick={handleLogin}>Login</button>
+
+ <div className={style.form}>
+ <img alt = "logo"></img>
+ <input type="email" className={style.email} placeholder="Enter your email" />
+ <input type="password" className={style.password} placeholder="Enter your password" />
+ <button className={style.submit} onClick={handleLogin}>Login</button>
<button>Register</button>
</div>
);
-}
+};
export default Login;
\ No newline at end of file
diff --git a/src/views/login/login.module.css b/src/views/login/login.module.css
new file mode 100644
index 0000000..7571160
--- /dev/null
+++ b/src/views/login/login.module.css
@@ -0,0 +1,75 @@
+.form {
+ display: flex;
+ flex-direction: column;
+ align-items: center; /* Center items horizontally */
+ justify-content: center; /* Center items vertically */
+ height: 40%; /* Occupy 40% of the viewport height */
+ width:25%;
+ background-color: #f0f8ff; /* Light blue background */
+ box-shadow: 3px 3px 5px 6px #ccc;
+ position: absolute; /* Position the form absolutely */
+ top: 50%; /* Move to the middle of the viewport */
+ left: 50%; /* Center horizontally */
+ transform: translate(-50%, -50%); /* Adjust for centering */
+ border-radius: 10px; /* Add rounded corners */
+ padding: 20px; /* Add padding for better spacing */
+ box-sizing: border-box; /* Include padding and border in width/height */
+
+}
+
+
+.form input {
+ margin: 5px;
+ padding: 5px;
+ border-radius: 5px;
+ border: 1px solid #ccc;
+ font-size: 16px;
+ width: 80%; /* Adjust width for better appearance */
+ max-width: 300px; /* Limit maximum width */
+ box-sizing: border-box;
+}
+
+.form .email,
+.form .password {
+ margin: 10px;
+ padding: 10px;
+ border-radius: 5px;
+ border: 1px solid #ccc;
+ font-size: 16px;
+ width: 80%;
+ max-width: 300px;
+}
+
+.form .submit {
+ margin: 10px;
+ padding: 10px;
+ border-radius: 5px;
+ border: 1px solid #ccc;
+ font-size: 16px;
+ background-color: #4CAF50; /* Green */
+ color: white;
+ cursor: pointer;
+ width: 80%;
+ max-width: 300px;
+}
+
+.form .submit:hover {
+ background-color: #45a049; /* Darker green */
+}
+
+.form button {
+ margin: 10px;
+ padding: 10px;
+ border-radius: 5px;
+ border: none;
+ font-size: 16px;
+ background-color: #007BFF; /* Blue */
+ color: white;
+ cursor: pointer;
+ width: 80%;
+ max-width: 300px;
+}
+
+.form button:hover {
+ background-color: #0056b3; /* Darker blue */
+}
\ No newline at end of file