优化首页的ui交互,解决打包生产环境下写入sessionStorage错误,优化权限路由的跳转问题
This commit is contained in:
@@ -151,7 +151,7 @@ export default function Index() {
|
||||
tabIndex={0}
|
||||
aria-label="合同管理"
|
||||
>
|
||||
<i className="ri-file-list-2-fill text-[3rem] text-[#269b6c]"></i>
|
||||
<img src="/images/icon_hetong.png" alt="合同管理" className="w-12 h-12 mx-1" />
|
||||
<span className="module-name">合同管理</span>
|
||||
</div>
|
||||
|
||||
@@ -164,7 +164,7 @@ export default function Index() {
|
||||
tabIndex={0}
|
||||
aria-label="案卷智能评查"
|
||||
>
|
||||
<i className="ri-folder-shared-fill text-[3rem] text-[#269b6c]"></i>
|
||||
<img src="/images/icon_anjuan.png" alt="案卷智能评查" className="w-12 h-12" />
|
||||
<span className="module-name">案卷智能评查</span>
|
||||
</div>
|
||||
|
||||
@@ -177,7 +177,7 @@ export default function Index() {
|
||||
tabIndex={0}
|
||||
aria-label="智慧法务大模型"
|
||||
>
|
||||
<i className="ri-robot-2-fill text-[3rem] text-[#269b6c]"></i>
|
||||
<img src="/images/icon_assistant.png" alt="智慧法务大模型" className="w-12 h-12" />
|
||||
<span className="module-name">智慧法务大模型</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+24
-24
@@ -1,8 +1,8 @@
|
||||
import { useState } from "react";
|
||||
import { Form, useActionData, useNavigation } from "@remix-run/react";
|
||||
import { useActionData } from "@remix-run/react";
|
||||
import { type MetaFunction, type ActionFunctionArgs, redirect, type LoaderFunctionArgs } from "@remix-run/node";
|
||||
import styles from "~/styles/pages/login.css?url";
|
||||
import { createUserSession, getUserSession, getSession, type UserRole } from "~/root";
|
||||
import { getUserSession, getSession, type UserRole, sessionStorage } from "~/root";
|
||||
|
||||
export const links = () => [
|
||||
{ rel: "stylesheet", href: styles }
|
||||
@@ -31,22 +31,30 @@ export async function action({ request }: ActionFunctionArgs) {
|
||||
|
||||
if (userRole === 'developer') {
|
||||
if (username !== 'admin' || password !== 'admin') {
|
||||
// toastService.error("管理员用户名或密码错误");
|
||||
return Response.json({ error: "管理员用户名或密码错误" });
|
||||
}
|
||||
}
|
||||
|
||||
// 在实际应用中,这里应该是对用户名和密码的验证逻辑
|
||||
// 简化起见,我们直接视为登录成功
|
||||
|
||||
// 获取session中存储的重定向URL,如果没有则默认到/
|
||||
const session = await getSession(request);
|
||||
// 查看session中存储的redirectTo值
|
||||
const redirectTo = session.get("redirectTo") || "/";
|
||||
// console.log("登录后重定向到:", redirectTo);
|
||||
console.log("登录后重定向到:", redirectTo);
|
||||
|
||||
// 创建登录会话并重定向
|
||||
return createUserSession(true, userRole, redirectTo);
|
||||
// 创建会话cookie
|
||||
const newSession = await sessionStorage.getSession();
|
||||
newSession.set("isAuthenticated", true);
|
||||
newSession.set("userRole", userRole);
|
||||
const cookie = await sessionStorage.commitSession(newSession);
|
||||
|
||||
console.log("设置cookie:", !!cookie);
|
||||
|
||||
// 使用新方法进行重定向
|
||||
return redirect(redirectTo, {
|
||||
headers: {
|
||||
"Set-Cookie": cookie
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 加载器,获取当前会话状态
|
||||
@@ -66,18 +74,7 @@ export default function Login() {
|
||||
const [password, setPassword] = useState("");
|
||||
const [userRole, setUserRole] = useState<UserRole>("common");
|
||||
const actionData = useActionData<typeof action>();
|
||||
const navigation = useNavigation();
|
||||
|
||||
// 使用 useEffect 确保错误提示只显示一次
|
||||
// useEffect(() => {
|
||||
// if(actionData?.error) {
|
||||
// toastService.error(actionData.error);
|
||||
// }
|
||||
// }, [actionData?.error]);
|
||||
|
||||
// 判断是否正在提交表单
|
||||
const isSubmitting = navigation.state === "submitting";
|
||||
|
||||
return (
|
||||
<div className="login-page">
|
||||
<div className="login-container">
|
||||
@@ -88,7 +85,11 @@ export default function Login() {
|
||||
|
||||
<div className="login-form-container">
|
||||
<h2 className="login-subtitle">用户登录</h2>
|
||||
<Form method="post" className="login-form">
|
||||
<form
|
||||
action="/login"
|
||||
method="post"
|
||||
className="login-form"
|
||||
>
|
||||
{actionData?.error && (
|
||||
<div className="error-message-container">
|
||||
<div className="error-icon"><i className="ri-error-warning-line"></i></div>
|
||||
@@ -140,11 +141,10 @@ export default function Login() {
|
||||
<button
|
||||
type="submit"
|
||||
className="login-button"
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{isSubmitting ? "登录中..." : "登录"}
|
||||
登录
|
||||
</button>
|
||||
</Form>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div className="login-footer">
|
||||
|
||||
Reference in New Issue
Block a user