完善备注面板
This commit is contained in:
@@ -3,9 +3,18 @@ import { useEffect, useState } from 'react';
|
|||||||
import { getVerificationCodeImage, loginByPassword } from '../../api';
|
import { getVerificationCodeImage, loginByPassword } from '../../api';
|
||||||
import { Button, Input } from '../ui';
|
import { Button, Input } from '../ui';
|
||||||
|
|
||||||
|
interface LoginSuccessPayload {
|
||||||
|
userId: string;
|
||||||
|
userName: string;
|
||||||
|
accessToken: string;
|
||||||
|
refreshToken: string;
|
||||||
|
roles: string;
|
||||||
|
username: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface LoginModalProps {
|
interface LoginModalProps {
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onLoginSuccess?: (userName: string) => void;
|
onLoginSuccess?: (payload: LoginSuccessPayload) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const APP_ID = 'b2b49e91d21446aeb14579930f732985';
|
const APP_ID = 'b2b49e91d21446aeb14579930f732985';
|
||||||
@@ -72,7 +81,14 @@ export const LoginModal = ({ onClose, onLoginSuccess }: LoginModalProps) => {
|
|||||||
verification_code_key: imgCodeKey,
|
verification_code_key: imgCodeKey,
|
||||||
});
|
});
|
||||||
if (res.Status === 200 && res.Data?.access_token) {
|
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();
|
onClose();
|
||||||
} else {
|
} else {
|
||||||
setError(res.Message || '登录失败');
|
setError(res.Message || '登录失败');
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export const NoteModal = ({ noteText, onNoteChange, onClose }: NoteModalProps) =
|
|||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [message, setMessage] = useState<string | null>(null);
|
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') || '未知' : '未知';
|
const operatorName = typeof window !== 'undefined' ? localStorage.getItem('operatorName') || '未知' : '未知';
|
||||||
|
|
||||||
// 初始化拉取备注
|
// 初始化拉取备注
|
||||||
|
|||||||
@@ -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 = () => {
|
export const MainLayout = () => {
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const [quickAction, setQuickAction] = useState<QuickActionType>('none');
|
const [quickAction, setQuickAction] = useState<QuickActionType>('none');
|
||||||
@@ -46,14 +55,15 @@ export const MainLayout = () => {
|
|||||||
navigate(sectionToRoute[section]);
|
navigate(sectionToRoute[section]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLoginSuccess = (phone: string) => {
|
const handleLoginSuccess = (info: LoginInfo) => {
|
||||||
// 实际项目中应该从后端获取用户信息
|
const displayName = info.userName || info.username || '操作员';
|
||||||
// 这里暂时使用手机号后4位作为操作员名称
|
|
||||||
const displayName = phone.slice(-4);
|
|
||||||
setOperatorName(displayName);
|
setOperatorName(displayName);
|
||||||
// 可以存储到 localStorage 或状态管理中
|
// 存储操作员信息与 token
|
||||||
localStorage.setItem('operatorPhone', phone);
|
localStorage.setItem('operatorId', info.userId || '');
|
||||||
localStorage.setItem('operatorName', displayName);
|
localStorage.setItem('operatorName', displayName);
|
||||||
|
localStorage.setItem('operatorUsername', info.username || '');
|
||||||
|
localStorage.setItem('accessToken', info.accessToken || '');
|
||||||
|
localStorage.setItem('refreshToken', info.refreshToken || '');
|
||||||
};
|
};
|
||||||
|
|
||||||
// 初始化时检查是否有已登录的操作员
|
// 初始化时检查是否有已登录的操作员
|
||||||
|
|||||||
Reference in New Issue
Block a user