完善备注面板

This commit is contained in:
xianyi
2025-12-16 18:08:39 +08:00
parent f8a7b41463
commit 1d993e76c5
3 changed files with 35 additions and 9 deletions

View File

@@ -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 || '登录失败');

View File

@@ -13,7 +13,7 @@ export const NoteModal = ({ noteText, onNoteChange, onClose }: NoteModalProps) =
const [saving, setSaving] = useState(false);
const [message, setMessage] = useState<string | null>(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') || '未知' : '未知';
// 初始化拉取备注

View File

@@ -27,6 +27,15 @@ const routeToSection = Object.entries(sectionToRoute).reduce<Record<string, Sect
{},
);
interface LoginInfo {
userId: string;
userName: string;
accessToken: string;
refreshToken: string;
roles: string;
username: string;
}
export const MainLayout = () => {
const [search, setSearch] = useState('');
const [quickAction, setQuickAction] = useState<QuickActionType>('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 || '');
};
// 初始化时检查是否有已登录的操作员