diff --git a/src/components/modals/LoginModal.tsx b/src/components/modals/LoginModal.tsx index e1e87f1..91ec9e5 100644 --- a/src/components/modals/LoginModal.tsx +++ b/src/components/modals/LoginModal.tsx @@ -3,9 +3,18 @@ import { useEffect, useState } from 'react'; import { getVerificationCodeImage, loginByPassword } from '../../api'; import { Button, Input } from '../ui'; +interface LoginSuccessPayload { + userId: string; + userName: string; + accessToken: string; + refreshToken: string; + roles: string; + username: string; +} + interface LoginModalProps { onClose: () => void; - onLoginSuccess?: (userName: string) => void; + onLoginSuccess?: (payload: LoginSuccessPayload) => void; } const APP_ID = 'b2b49e91d21446aeb14579930f732985'; @@ -72,7 +81,14 @@ export const LoginModal = ({ onClose, onLoginSuccess }: LoginModalProps) => { verification_code_key: imgCodeKey, }); if (res.Status === 200 && res.Data?.access_token) { - onLoginSuccess?.(res.Data.user_name || username.trim()); + onLoginSuccess?.({ + userId: res.Data.user_id, + userName: res.Data.user_name, + accessToken: res.Data.access_token, + refreshToken: res.Data.refresh_token, + roles: res.Data.roles, + username: username.trim(), + }); onClose(); } else { setError(res.Message || '登录失败'); diff --git a/src/components/modals/NoteModal.tsx b/src/components/modals/NoteModal.tsx index 7fc35cb..dbd0e39 100644 --- a/src/components/modals/NoteModal.tsx +++ b/src/components/modals/NoteModal.tsx @@ -13,7 +13,7 @@ export const NoteModal = ({ noteText, onNoteChange, onClose }: NoteModalProps) = const [saving, setSaving] = useState(false); const [message, setMessage] = useState(null); - const operatorId = typeof window !== 'undefined' ? localStorage.getItem('operatorPhone') || 'unknown' : 'unknown'; + const operatorId = typeof window !== 'undefined' ? localStorage.getItem('operatorId') || '' : ''; const operatorName = typeof window !== 'undefined' ? localStorage.getItem('operatorName') || '未知' : '未知'; // 初始化拉取备注 diff --git a/src/layouts/MainLayout.tsx b/src/layouts/MainLayout.tsx index cd6c2bc..c421867 100644 --- a/src/layouts/MainLayout.tsx +++ b/src/layouts/MainLayout.tsx @@ -27,6 +27,15 @@ const routeToSection = Object.entries(sectionToRoute).reduce { const [search, setSearch] = useState(''); const [quickAction, setQuickAction] = useState('none'); @@ -46,14 +55,15 @@ export const MainLayout = () => { navigate(sectionToRoute[section]); }; - const handleLoginSuccess = (phone: string) => { - // 实际项目中应该从后端获取用户信息 - // 这里暂时使用手机号后4位作为操作员名称 - const displayName = phone.slice(-4); + const handleLoginSuccess = (info: LoginInfo) => { + const displayName = info.userName || info.username || '操作员'; setOperatorName(displayName); - // 可以存储到 localStorage 或状态管理中 - localStorage.setItem('operatorPhone', phone); + // 存储操作员信息与 token + localStorage.setItem('operatorId', info.userId || ''); localStorage.setItem('operatorName', displayName); + localStorage.setItem('operatorUsername', info.username || ''); + localStorage.setItem('accessToken', info.accessToken || ''); + localStorage.setItem('refreshToken', info.refreshToken || ''); }; // 初始化时检查是否有已登录的操作员