fix(web): standardize user picker and message detail
This commit is contained in:
@@ -12,7 +12,9 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { http } from '../api/http';
|
||||
import { APPROVAL_COMPLETED_EVENT } from '../amis/approvalActionEvents';
|
||||
import { MESSAGE_DETAIL_CHANGED_EVENT } from '../amis/messageActionEvents';
|
||||
import { registerApprovalAction } from '../amis/registerApprovalAction';
|
||||
import { registerMessageAction } from '../amis/registerMessageAction';
|
||||
import { registerReplayAction } from '../amis/registerReplayAction';
|
||||
import { normalizeUserTransferSchemaTree, registerUserTransferPicker } from '../amis/registerUserTransferPicker';
|
||||
import { getProfile } from '../auth/token';
|
||||
@@ -67,7 +69,11 @@ export function AmisRenderer({ schema }: AmisRendererProps) {
|
||||
useEffect(() => {
|
||||
const reload = () => setReloadSeq((n) => n + 1);
|
||||
window.addEventListener(APPROVAL_COMPLETED_EVENT, reload);
|
||||
return () => window.removeEventListener(APPROVAL_COMPLETED_EVENT, reload);
|
||||
window.addEventListener(MESSAGE_DETAIL_CHANGED_EVENT, reload);
|
||||
return () => {
|
||||
window.removeEventListener(APPROVAL_COMPLETED_EVENT, reload);
|
||||
window.removeEventListener(MESSAGE_DETAIL_CHANGED_EVENT, reload);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -87,6 +93,11 @@ export function AmisRenderer({ schema }: AmisRendererProps) {
|
||||
} catch {
|
||||
// amis-core 未暴露 registerAction 时静默降级(审批抽屉入口不可用,不阻断渲染)
|
||||
}
|
||||
try {
|
||||
registerMessageAction(amisRequire('amis'));
|
||||
} catch {
|
||||
// amis-core 未暴露 registerAction 时静默降级(消息详情入口不可用,不阻断渲染)
|
||||
}
|
||||
try {
|
||||
registerUserTransferPicker(amisRequire('amis')) || registerUserTransferPicker(amisRequire('amis-core'));
|
||||
} catch {
|
||||
|
||||
186
src/components/MessageDetailDialog.tsx
Normal file
186
src/components/MessageDetailDialog.tsx
Normal file
@@ -0,0 +1,186 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import type { MessageDetailRequest } from '../amis/messageActionEvents';
|
||||
import { fetchNoticeDetail, openReceivedNotice, type NoticeDetail } from '../api/notice';
|
||||
import { Dialog } from './ui/Dialog';
|
||||
import { Icon } from './ui/Icon';
|
||||
|
||||
interface MessageDetailDialogProps {
|
||||
request: MessageDetailRequest;
|
||||
onClose: () => void;
|
||||
onReadChange: () => void;
|
||||
}
|
||||
|
||||
function fmtTime(value: number | string | null | undefined): string {
|
||||
if (value === null || value === undefined || value === '') return '';
|
||||
let d: Date;
|
||||
if (typeof value === 'number') {
|
||||
d = new Date(value < 10_000_000_000 ? value * 1000 : value);
|
||||
} else {
|
||||
const n = Number(value);
|
||||
d = Number.isFinite(n) ? new Date(n < 10_000_000_000 ? n * 1000 : n) : new Date(value);
|
||||
}
|
||||
if (Number.isNaN(d.getTime())) return String(value);
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} `
|
||||
+ `${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
}
|
||||
|
||||
function stringValue(value: unknown): string {
|
||||
if (value === null || value === undefined) return '';
|
||||
return String(value).trim();
|
||||
}
|
||||
|
||||
function documentLabels(value: unknown): string[] {
|
||||
if (!value) return [];
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item, index) => {
|
||||
if (item && typeof item === 'object') {
|
||||
const record = item as Record<string, unknown>;
|
||||
return stringValue(record.name)
|
||||
|| stringValue(record.fileName)
|
||||
|| stringValue(record.filename)
|
||||
|| stringValue(record.originalName)
|
||||
|| stringValue(record.title)
|
||||
|| `附件 ${index + 1}`;
|
||||
}
|
||||
return stringValue(item) || `附件 ${index + 1}`;
|
||||
});
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return value.trim() ? [value.trim()] : [];
|
||||
}
|
||||
return ['有附件'];
|
||||
}
|
||||
|
||||
function Field({ label, value }: { label: string; value: unknown }) {
|
||||
return (
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '88px minmax(0, 1fr)', gap: 12, alignItems: 'start' }}>
|
||||
<div style={{ color: 'var(--text-2)' }}>{label}</div>
|
||||
<div style={{ minWidth: 0, wordBreak: 'break-word' }}>{stringValue(value) || '-'}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function MessageDetailDialog({ request, onClose, onReadChange }: MessageDetailDialogProps) {
|
||||
const [detail, setDetail] = useState<NoticeDetail | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setLoading(true);
|
||||
setError('');
|
||||
setDetail(null);
|
||||
|
||||
const run = request.kind === 'received'
|
||||
? openReceivedNotice(request.receiveId ?? '')
|
||||
: fetchNoticeDetail(request.messageId ?? '');
|
||||
|
||||
run
|
||||
.then((data) => {
|
||||
if (!alive) return;
|
||||
setDetail(data);
|
||||
if (request.kind === 'received') {
|
||||
onReadChange();
|
||||
}
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
if (!alive) return;
|
||||
const message = (err as { response?: { data?: { message?: string } } }).response?.data?.message;
|
||||
setError(message || '消息详情加载失败');
|
||||
})
|
||||
.finally(() => {
|
||||
if (alive) setLoading(false);
|
||||
});
|
||||
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [request, onReadChange]);
|
||||
|
||||
const attachments = useMemo(() => documentLabels(detail?.document), [detail?.document]);
|
||||
const title = detail?.title || request.title || '查看';
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
title="查看"
|
||||
width={720}
|
||||
onClose={onClose}
|
||||
foot={<button className="btn btn-pri" onClick={onClose}>关闭</button>}
|
||||
>
|
||||
{loading ? (
|
||||
<div className="empty">加载中…</div>
|
||||
) : error ? (
|
||||
<div className="empty" style={{ color: 'var(--err)' }}>{error}</div>
|
||||
) : detail ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 14, fontSize: 'var(--fs)' }}>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
gap: 10,
|
||||
alignItems: 'flex-start',
|
||||
paddingBottom: 12,
|
||||
borderBottom: '1px solid var(--line)',
|
||||
}}
|
||||
>
|
||||
<Icon name="doc" size={18} style={{ color: 'var(--brand)', marginTop: 2 }} />
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<div style={{ fontSize: 'var(--fs-lg)', fontWeight: 600, wordBreak: 'break-word' }}>
|
||||
{title}
|
||||
</div>
|
||||
<div style={{ color: 'var(--text-3)', marginTop: 4 }}>
|
||||
{request.kind === 'sent' ? '已发送消息' : '收到的消息'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '1fr 1fr',
|
||||
gap: '10px 24px',
|
||||
}}
|
||||
>
|
||||
<Field label="发送人" value={detail.sender} />
|
||||
<Field label="发送时间" value={fmtTime(detail.createTime)} />
|
||||
<Field label="消息类型" value={detail.type} />
|
||||
<Field label="接收人" value={detail.receivers} />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div style={{ color: 'var(--text-2)', marginBottom: 6 }}>内容</div>
|
||||
<div style={{
|
||||
minHeight: 180,
|
||||
maxHeight: 280,
|
||||
overflow: 'auto',
|
||||
border: '1px solid var(--line)',
|
||||
borderRadius: 6,
|
||||
padding: 12,
|
||||
lineHeight: 1.7,
|
||||
whiteSpace: 'pre-wrap',
|
||||
wordBreak: 'break-word',
|
||||
background: 'var(--surface-2)',
|
||||
}}
|
||||
>
|
||||
{stringValue(detail.content) || '-'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div style={{ color: 'var(--text-2)', marginBottom: 6 }}>附件</div>
|
||||
{attachments.length ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
{attachments.map((item) => (
|
||||
<div key={item} style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<Icon name="doc" size={14} style={{ color: 'var(--text-3)' }} />
|
||||
<span>{item}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ color: 'var(--text-3)' }}>无附件</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user