添加3个普通用户,注释管理员选项,优化登录

This commit is contained in:
2025-06-11 21:48:26 +08:00
parent f2c385d936
commit d4846869eb
4 changed files with 81 additions and 12 deletions
+1
View File
@@ -6,5 +6,6 @@ node_modules
.env
.idea
.history
logs/
+1 -1
View File
@@ -35,7 +35,7 @@ const configs: Record<string, ApiConfig> = {
// postgrest
baseUrl: 'http://10.79.97.16:8000',
// minio
documentUrl: 'http://10.76.244.156:9001/docauditai/',
documentUrl: 'http://10.76.244.156:9000/docauditai/',
// 文件上传
uploadUrl: 'http://10.79.97.16:8000/admin/documents/upload',
},
+45 -11
View File
@@ -29,8 +29,31 @@ export async function action({ request }: ActionFunctionArgs) {
return Response.json({ error: "用户名和密码不能为空" });
}
if(userRole === 'common') {
// console.log("username-----", username);
// console.log("password-----", password);
const validUsers = [
{ username: 'gdycuser', password: 'gdyc06111' },
{ username: 'gdycuser2', password: 'gdyc06112' },
{ username: 'gdycuser3', password: 'gdyc06113' }
];
const validUser = validUsers.find(user => user.username === username && user.password === password);
if (!validUser) {
return Response.json({ error: "普通用户用户名或密码错误" });
}
}
// console.log("login success", userRole);
// 管理员登录
if (userRole === 'developer') {
if (username !== 'admin' || password !== 'admin') {
const validAdminUsers = [
{ username: 'admin', password: 'admin0611' },
// { username: 'admin2', password: 'admin06112' },
// { username: 'admin3', password: 'admin06113' }
];
const validAdminUser = validAdminUsers.find(user => user.username === username && user.password === password);
if (!validAdminUser) {
return Response.json({ error: "管理员用户名或密码错误" });
}
}
@@ -73,6 +96,7 @@ export default function Login() {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [userRole, setUserRole] = useState<UserRole>("common");
const [showPassword, setShowPassword] = useState(false);
const actionData = useActionData<typeof action>();
return (
@@ -111,15 +135,25 @@ export default function Login() {
<div className="form-group">
<label htmlFor="password"></label>
<input
type="password"
id="password"
name="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="form-input"
placeholder="请输入密码"
/>
<div className="password-input-container">
<input
type={showPassword ? "text" : "password"}
id="password"
name="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="form-input password-input"
placeholder="请输入密码"
/>
<button
type="button"
className="password-toggle-btn"
onClick={() => setShowPassword(!showPassword)}
aria-label={showPassword ? "隐藏密码" : "显示密码"}
>
<i className={showPassword ? "ri-eye-off-line" : "ri-eye-line"}></i>
</button>
</div>
</div>
<div className="form-group">
@@ -133,7 +167,7 @@ export default function Login() {
required
>
<option value="common"></option>
<option value="developer"></option>
{/* <option value="developer">管理员</option> */}
</select>
</div>
+34
View File
@@ -112,6 +112,40 @@
box-shadow: 0 0 0 2px rgba(44, 173, 125, 0.2);
}
/* 密码输入框容器样式 */
.password-input-container {
position: relative;
display: flex;
align-items: center;
}
.password-input {
padding-right: 3rem; /* 为眼睛图标留出空间 */
}
.password-toggle-btn {
position: absolute;
right: 0.75rem;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
cursor: pointer;
padding: 0.25rem;
color: #666;
font-size: 1.25rem;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
transition: color 0.2s, background-color 0.2s;
}
.password-toggle-btn:hover {
color: #2cad7d;
}
.login-button {
margin-top: 1rem;
padding: 0.75rem 1.5rem;