Files
quality_analyse/web/src/PersonalAccount.tsx
T
lyun c3354c1f64 新增:查询页面快照并修复筛选选框闪烁
页面快照支持勾选查询条件、指标卡片、趋势、汇总表、不良构成和细分缺陷图,复制PNG或下载;增加取消、分阶段提示和等待超时恢复。

修复公共Select弹层准备帧被opacity覆盖导致的先闪出再展开,并取消查询字段原生label的重复点击转发。

同步已经验收上线的销售订单类型映射、排除筛选及预聚合,以及其线上权限、删除确认配套源码;保留既有公式编辑和名录编码修改。源码范围按发布清单冻结,不纳入本机数据、凭据及未发布工作。

验证:前后端独立源码构建通过;10项前端检查、4项订单分类单元测试通过;实际系统剪贴板粘贴PNG验证通过;线上配置及筛选结果与发布前一致,后端未重启。
2026-11-04 00:15:32 +08:00

86 lines
4.9 KiB
TypeScript

import { useEffect, useRef, useState } from 'react';
import { Alert, App, Button, Descriptions, Form, Input, Modal, Tabs } from 'antd';
import { api } from './api';
import type { AuthUser } from './types';
import { ROLE_LABELS as roles } from './userRoles';
export type AccountTab = 'profile' | 'password';
type PasswordValues = { currentPassword: string; newPassword: string; confirmation: string };
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 savingRef = useRef(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) => {
if (savingRef.current) return;
savingRef.current = true;
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 { savingRef.current = false; 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>;
}