修复:查询局部刷新与智能分析会话交互,完善分析收尾和配置切换
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Alert, App, Button, Descriptions, Form, Input, Modal, Tabs } from 'antd';
|
||||
import { api } from './api';
|
||||
import type { AuthUser } from './types';
|
||||
|
||||
export type AccountTab = 'profile' | 'password';
|
||||
type PasswordValues = { currentPassword: string; newPassword: string; confirmation: string };
|
||||
const roles: Record<string, string> = {
|
||||
DATA_MAINTAINER: '数据维护', DATA_PUBLISHER: '数据发布', QUALITY_VIEWER: '质量查看',
|
||||
RULE_MAINTAINER: '规则维护', SYSTEM_ADMIN: '系统管理', SYSTEM_OPERATOR: '运行维护',
|
||||
BUSINESS_ANALYST: '业务分析', AUDIT_VIEWER: '审计查看',
|
||||
};
|
||||
|
||||
export default function PersonalAccount({ user, tab, onClose, onUserChange, onUnauthorized, onLogout }: {
|
||||
user: AuthUser; tab: AccountTab | null; onClose: () => void;
|
||||
onUserChange: (user: AuthUser) => void; onUnauthorized: (error: unknown) => boolean;
|
||||
onLogout: () => Promise<void>;
|
||||
}) {
|
||||
const { message } = App.useApp();
|
||||
const [form] = Form.useForm<PasswordValues>();
|
||||
const [activeTab, setActiveTab] = useState<AccountTab>('profile');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const forced = user.forcePasswordChange === true;
|
||||
const open = tab !== null || forced;
|
||||
|
||||
useEffect(() => {
|
||||
if (open) { setActiveTab(forced ? 'password' : tab || 'profile'); setError(''); form.resetFields(); }
|
||||
}, [open, tab, forced, form]);
|
||||
|
||||
const save = async (values: PasswordValues) => {
|
||||
setBusy(true); setError('');
|
||||
try {
|
||||
await api.changePassword(values.currentPassword, values.newPassword);
|
||||
form.resetFields();
|
||||
onUserChange({ ...user, forcePasswordChange: false });
|
||||
onClose();
|
||||
message.success('密码已修改,下次登录请使用新密码');
|
||||
} catch (failure) {
|
||||
if (!onUnauthorized(failure)) setError(failure instanceof Error ? failure.message : '修改失败,请重试');
|
||||
} finally { setBusy(false); }
|
||||
};
|
||||
|
||||
return <Modal className="personal-account-modal" open={open} title="个人账户" width={520} footer={null}
|
||||
closable={!forced && !busy} maskClosable={!forced && !busy} keyboard={!forced && !busy}
|
||||
onCancel={() => { if (!busy && !forced) onClose(); }} destroyOnHidden>
|
||||
{forced && <Alert type="warning" showIcon message="请先修改初始密码" style={{ marginBottom: 16 }} />}
|
||||
<Tabs activeKey={activeTab} onChange={key => setActiveTab(key as AccountTab)} items={[
|
||||
{ key: 'profile', label: '个人资料', disabled: forced || busy, children: <Descriptions column={1} bordered size="small" items={[
|
||||
{ key: 'username', label: '登录账号', children: user.username },
|
||||
{ key: 'name', label: '姓名', children: user.displayName || '未设置' },
|
||||
{ key: 'departments', label: '所属部门', children: user.departments.map(name => name === '质量管理部' ? '质量中心' : name).join('、') || '未设置' },
|
||||
{ key: 'roles', label: '角色', children: user.roles.map(role => roles[role] || role).join('、') || '未设置' },
|
||||
]} /> },
|
||||
{ key: 'password', label: '修改密码', children: <Form form={form} layout="vertical" onFinish={save} requiredMark={false}
|
||||
onValuesChange={() => setError('')} disabled={busy}>
|
||||
<Form.Item name="currentPassword" label="当前密码" rules={[{ required: true, message: '请输入当前密码' }]}>
|
||||
<Input.Password autoComplete="current-password" />
|
||||
</Form.Item>
|
||||
<Form.Item name="newPassword" label="新密码" dependencies={['currentPassword']} rules={[
|
||||
{ required: true, message: '请输入新密码' },
|
||||
{ min: 6, message: '新密码至少6位' },
|
||||
({ getFieldValue }) => ({ validator: (_, value: string) => {
|
||||
if (value && new TextEncoder().encode(value).length > 72) return Promise.reject(new Error('新密码过长,请缩短后重试'));
|
||||
if (value && value === getFieldValue('currentPassword')) return Promise.reject(new Error('新密码不能与当前密码相同'));
|
||||
return Promise.resolve();
|
||||
} }),
|
||||
]}>
|
||||
<Input.Password autoComplete="new-password" placeholder="至少6位" />
|
||||
</Form.Item>
|
||||
<Form.Item name="confirmation" label="确认新密码" dependencies={['newPassword']} rules={[
|
||||
{ required: true, message: '请再次输入新密码' },
|
||||
({ getFieldValue }) => ({ validator: (_, value: string) => !value || value === getFieldValue('newPassword')
|
||||
? Promise.resolve() : Promise.reject(new Error('两次输入的新密码不一致')) }),
|
||||
]}>
|
||||
<Input.Password autoComplete="new-password" />
|
||||
</Form.Item>
|
||||
{error && <Alert type="error" showIcon message={error} style={{ marginBottom: 16 }} />}
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 8 }}>
|
||||
{forced ? <Button disabled={busy} onClick={() => void onLogout()}>退出登录</Button> : <Button disabled={busy} onClick={onClose}>取消</Button>}
|
||||
<Button type="primary" htmlType="submit" loading={busy}>保存密码</Button>
|
||||
</div>
|
||||
</Form> },
|
||||
]} />
|
||||
</Modal>;
|
||||
}
|
||||
Reference in New Issue
Block a user