feat: Bug 图片上传 + 转交 + 操作日志 + 开发中含自测
1. 开发中统计包含 in_progress + testing(自测) 2. Bug 支持上传图片: - BugCreateModal 加宽为 max-w-2xl - 新增拖拽/点击上传图片区域,转 base64 存储 - 上传后可预览缩略图、可删除 - BugDetailDrawer 展示截图列表,点击可放大 3. Bug 支持转交: - BugDetailDrawer 操作栏新增"转交"按钮 - 选人下拉 + 备注输入 → 确认转交 - transferBug store 方法:更新 assigneeId + 追加日志 4. Bug 操作日志: - BugLog interface: create/status_change/transfer/resolve - createBug 时记录创建日志 - changeStatus 时记录状态变更/修复日志 - transferBug 时记录转交日志 - BugDetailDrawer 底部展示操作时间线 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -208,7 +208,7 @@ export default function VersionDetailPage() {
|
|||||||
// DevTask 真实统计
|
// DevTask 真实统计
|
||||||
const versionDevTasks = devTasks.filter((t) => versionReqs.some((r) => r.id === t.requirementId));
|
const versionDevTasks = devTasks.filter((t) => versionReqs.some((r) => r.id === t.requirementId));
|
||||||
const devTaskTodo = versionDevTasks.filter((t) => t.status === 'todo').length;
|
const devTaskTodo = versionDevTasks.filter((t) => t.status === 'todo').length;
|
||||||
const devTaskInProgress = versionDevTasks.filter((t) => t.status === 'in_progress').length;
|
const devTaskInProgress = versionDevTasks.filter((t) => t.status === 'in_progress' || t.status === 'testing').length;
|
||||||
const devTaskBlocked = versionDevTasks.filter((t) => t.isBlocked).length;
|
const devTaskBlocked = versionDevTasks.filter((t) => t.isBlocked).length;
|
||||||
const versionBugs = bugs.filter((b) => b.versionId === version.id);
|
const versionBugs = bugs.filter((b) => b.versionId === version.id);
|
||||||
const bugOpenCount = versionBugs.filter((b) => b.status === 'open' || b.status === 'fixing').length;
|
const bugOpenCount = versionBugs.filter((b) => b.status === 'open' || b.status === 'fixing').length;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useMemo } from 'react';
|
import { useState, useMemo, useRef } from 'react';
|
||||||
import { X } from 'lucide-react';
|
import { X, ImagePlus, Trash2 } from 'lucide-react';
|
||||||
import { useBugStore } from '@/stores/useBugStore';
|
import { useBugStore } from '@/stores/useBugStore';
|
||||||
import { useTestCaseStore } from '@/stores/useTestCaseStore';
|
import { useTestCaseStore } from '@/stores/useTestCaseStore';
|
||||||
import { useDevTaskStore } from '@/stores/useDevTaskStore';
|
import { useDevTaskStore } from '@/stores/useDevTaskStore';
|
||||||
@@ -27,7 +27,6 @@ export function BugCreateModal({ testCaseId, onClose }: Props) {
|
|||||||
const tc = testCases.find((c) => c.id === testCaseId);
|
const tc = testCases.find((c) => c.id === testCaseId);
|
||||||
const requirement = requirements.find((r) => r.id === tc?.requirementId);
|
const requirement = requirements.find((r) => r.id === tc?.requirementId);
|
||||||
|
|
||||||
// 推导默认负责人
|
|
||||||
const defaultAssignee = useMemo(() => {
|
const defaultAssignee = useMemo(() => {
|
||||||
if (!tc) return '';
|
if (!tc) return '';
|
||||||
const reqTasks = devTasks.filter((t) => t.requirementId === tc.requirementId);
|
const reqTasks = devTasks.filter((t) => t.requirementId === tc.requirementId);
|
||||||
@@ -42,9 +41,23 @@ export function BugCreateModal({ testCaseId, onClose }: Props) {
|
|||||||
const [severity, setSeverity] = useState<BugSeverity>('major');
|
const [severity, setSeverity] = useState<BugSeverity>('major');
|
||||||
const [priority, setPriority] = useState<Priority>(tc?.priority || 'P1');
|
const [priority, setPriority] = useState<Priority>(tc?.priority || 'P1');
|
||||||
const [assigneeId, setAssigneeId] = useState(defaultAssignee);
|
const [assigneeId, setAssigneeId] = useState(defaultAssignee);
|
||||||
|
const [images, setImages] = useState<string[]>([]);
|
||||||
|
const fileRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const canSubmit = title.trim() && description.trim() && assigneeId;
|
const canSubmit = title.trim() && description.trim() && assigneeId;
|
||||||
|
|
||||||
|
const handleFiles = (files: FileList | null) => {
|
||||||
|
if (!files) return;
|
||||||
|
Array.from(files).forEach((file) => {
|
||||||
|
if (!file.type.startsWith('image/')) return;
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = () => {
|
||||||
|
setImages((prev) => [...prev, reader.result as string]);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
if (!canSubmit) return;
|
if (!canSubmit) return;
|
||||||
createBug({
|
createBug({
|
||||||
@@ -57,19 +70,19 @@ export function BugCreateModal({ testCaseId, onClose }: Props) {
|
|||||||
priority,
|
priority,
|
||||||
reportedBy: user?.name || '系统',
|
reportedBy: user?.name || '系统',
|
||||||
assigneeId,
|
assigneeId,
|
||||||
});
|
images: images.length > 0 ? images : undefined,
|
||||||
|
}, user?.name || '系统');
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-[60] flex items-center justify-center bg-black/40" onClick={onClose}>
|
<div className="fixed inset-0 z-[60] flex items-center justify-center bg-black/40" onClick={onClose}>
|
||||||
<div className="w-full max-w-md rounded-2xl bg-[var(--bg-card)] border border-[var(--line)] p-6 shadow-[var(--shadow-md)]" onClick={(e) => e.stopPropagation()}>
|
<div className="w-full max-w-2xl max-h-[90vh] overflow-y-auto rounded-2xl bg-[var(--bg-card)] border border-[var(--line)] p-6 shadow-[var(--shadow-md)]" onClick={(e) => e.stopPropagation()}>
|
||||||
<div className="flex items-center justify-between mb-4">
|
<div className="flex items-center justify-between mb-4">
|
||||||
<h3 className="text-[14px] font-semibold text-[var(--ink)]">提交 Bug</h3>
|
<h3 className="text-[14px] font-semibold text-[var(--ink)]">提交 Bug</h3>
|
||||||
<button onClick={onClose} className="rounded-md p-1 hover:bg-[var(--bg-subtle)]"><X className="h-4 w-4 text-[var(--ink-muted)]" /></button>
|
<button onClick={onClose} className="rounded-md p-1 hover:bg-[var(--bg-subtle)]"><X className="h-4 w-4 text-[var(--ink-muted)]" /></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 只读关联信息 */}
|
|
||||||
<div className="rounded-lg bg-[var(--bg-subtle)] px-3 py-2 mb-4 space-y-1 text-[12px]">
|
<div className="rounded-lg bg-[var(--bg-subtle)] px-3 py-2 mb-4 space-y-1 text-[12px]">
|
||||||
<div><span className="text-[var(--ink-muted)]">关联用例:</span><span className="text-[var(--ink)]">{tc?.caseNo} {tc?.title}</span></div>
|
<div><span className="text-[var(--ink-muted)]">关联用例:</span><span className="text-[var(--ink)]">{tc?.caseNo} {tc?.title}</span></div>
|
||||||
{requirement && <div><span className="text-[var(--ink-muted)]">关联需求:</span><span className="text-[var(--ink)]">{requirement.code} {requirement.title}</span></div>}
|
{requirement && <div><span className="text-[var(--ink-muted)]">关联需求:</span><span className="text-[var(--ink)]">{requirement.code} {requirement.title}</span></div>}
|
||||||
@@ -82,8 +95,39 @@ export function BugCreateModal({ testCaseId, onClose }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">Bug 描述 *</label>
|
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">Bug 描述 *</label>
|
||||||
<textarea rows={3} value={description} onChange={(e) => setDescription(e.target.value)} className="w-full rounded-lg border border-[var(--line)] bg-[var(--bg)] px-3 py-2 text-[13px] focus:border-[var(--accent)] focus:outline-none resize-none" placeholder="复现步骤、实际结果、预期结果" />
|
<textarea rows={5} value={description} onChange={(e) => setDescription(e.target.value)} className="w-full rounded-lg border border-[var(--line)] bg-[var(--bg)] px-3 py-2 text-[13px] focus:border-[var(--accent)] focus:outline-none resize-none" placeholder="复现步骤、实际结果、预期结果" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 图片上传 */}
|
||||||
|
<div>
|
||||||
|
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">截图附件</label>
|
||||||
|
<div
|
||||||
|
className="rounded-lg border-2 border-dashed border-[var(--line)] p-4 text-center cursor-pointer hover:border-[var(--accent)] hover:bg-[var(--bg-subtle)] transition-colors"
|
||||||
|
onClick={() => fileRef.current?.click()}
|
||||||
|
onDragOver={(e) => { e.preventDefault(); e.stopPropagation(); }}
|
||||||
|
onDrop={(e) => { e.preventDefault(); e.stopPropagation(); handleFiles(e.dataTransfer.files); }}
|
||||||
|
>
|
||||||
|
<ImagePlus className="h-6 w-6 text-[var(--ink-muted)] mx-auto mb-1" />
|
||||||
|
<span className="text-[12px] text-[var(--ink-muted)]">点击或拖拽上传图片</span>
|
||||||
|
<input ref={fileRef} type="file" accept="image/*" multiple className="hidden" onChange={(e) => handleFiles(e.target.files)} />
|
||||||
|
</div>
|
||||||
|
{images.length > 0 && (
|
||||||
|
<div className="flex flex-wrap gap-2 mt-2">
|
||||||
|
{images.map((src, i) => (
|
||||||
|
<div key={i} className="relative group">
|
||||||
|
<img src={src} alt={`截图${i + 1}`} className="h-20 w-20 object-cover rounded-lg border border-[var(--line)]" />
|
||||||
|
<button
|
||||||
|
onClick={() => setImages((prev) => prev.filter((_, j) => j !== i))}
|
||||||
|
className="absolute -top-1.5 -right-1.5 h-5 w-5 flex items-center justify-center rounded-full bg-red-500 text-white opacity-0 group-hover:opacity-100 transition-opacity"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-3 w-3" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-3 gap-3">
|
<div className="grid grid-cols-3 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">严重程度</label>
|
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">严重程度</label>
|
||||||
|
|||||||
@@ -1,23 +1,35 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { X, Link2, ChevronRight } from 'lucide-react';
|
import { X, Link2, ChevronRight, ArrowRightLeft } from 'lucide-react';
|
||||||
import { BugStatusBadge } from './BugStatusBadge';
|
import { BugStatusBadge } from './BugStatusBadge';
|
||||||
import { useBugStore } from '@/stores/useBugStore';
|
import { useBugStore } from '@/stores/useBugStore';
|
||||||
import { useTestCaseStore } from '@/stores/useTestCaseStore';
|
import { useTestCaseStore } from '@/stores/useTestCaseStore';
|
||||||
import { useRequirementStore } from '@/stores/useRequirementStore';
|
import { useRequirementStore } from '@/stores/useRequirementStore';
|
||||||
|
import { useMemberStore } from '@/stores/useMemberStore';
|
||||||
|
import { useAuthStore } from '@/stores/useAuthStore';
|
||||||
import { BUG_ALLOWED_TRANSITIONS, BUG_STATUS_LABEL, BUG_SEVERITY_LABEL, BUG_SEVERITY_COLOR } from '@/lib/bug';
|
import { BUG_ALLOWED_TRANSITIONS, BUG_STATUS_LABEL, BUG_SEVERITY_LABEL, BUG_SEVERITY_COLOR } from '@/lib/bug';
|
||||||
import type { BugStatus } from '@/lib/bug';
|
import type { BugStatus } from '@/lib/bug';
|
||||||
|
|
||||||
|
const LOG_ACTION_LABEL: Record<string, string> = {
|
||||||
|
create: '创建',
|
||||||
|
status_change: '状态变更',
|
||||||
|
transfer: '转交',
|
||||||
|
resolve: '修复',
|
||||||
|
};
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
bugId: string;
|
bugId: string;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function BugDetailDrawer({ bugId, onClose }: Props) {
|
export function BugDetailDrawer({ bugId, onClose }: Props) {
|
||||||
const { bugs, changeStatus } = useBugStore();
|
const { bugs, changeStatus, transferBug } = useBugStore();
|
||||||
const { testCases } = useTestCaseStore();
|
const { testCases } = useTestCaseStore();
|
||||||
const { requirements } = useRequirementStore();
|
const { requirements } = useRequirementStore();
|
||||||
|
const { members } = useMemberStore();
|
||||||
|
const user = useAuthStore((s) => s.user);
|
||||||
|
const operator = user?.name || '系统';
|
||||||
|
|
||||||
const bug = bugs.find((b) => b.id === bugId);
|
const bug = bugs.find((b) => b.id === bugId);
|
||||||
if (!bug) return null;
|
if (!bug) return null;
|
||||||
@@ -28,17 +40,29 @@ export function BugDetailDrawer({ bugId, onClose }: Props) {
|
|||||||
|
|
||||||
const [resolution, setResolution] = useState(bug.resolution || '');
|
const [resolution, setResolution] = useState(bug.resolution || '');
|
||||||
const [showResolutionInput, setShowResolutionInput] = useState(false);
|
const [showResolutionInput, setShowResolutionInput] = useState(false);
|
||||||
|
const [showTransfer, setShowTransfer] = useState(false);
|
||||||
|
const [transferTo, setTransferTo] = useState('');
|
||||||
|
const [transferRemark, setTransferRemark] = useState('');
|
||||||
|
const [lightboxSrc, setLightboxSrc] = useState<string | null>(null);
|
||||||
|
|
||||||
const handleTransition = (to: BugStatus) => {
|
const handleTransition = (to: BugStatus) => {
|
||||||
if (to === 'fixed') { setShowResolutionInput(true); return; }
|
if (to === 'fixed') { setShowResolutionInput(true); return; }
|
||||||
changeStatus(bug.id, to);
|
changeStatus(bug.id, to, operator);
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmFix = () => {
|
const confirmFix = () => {
|
||||||
changeStatus(bug.id, 'fixed', { resolution: resolution.trim() || undefined });
|
changeStatus(bug.id, 'fixed', operator, { resolution: resolution.trim() || undefined });
|
||||||
setShowResolutionInput(false);
|
setShowResolutionInput(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleTransfer = () => {
|
||||||
|
if (!transferTo) return;
|
||||||
|
transferBug(bug.id, transferTo, operator, transferRemark.trim() || undefined);
|
||||||
|
setShowTransfer(false);
|
||||||
|
setTransferTo('');
|
||||||
|
setTransferRemark('');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-50 flex justify-end" onClick={onClose}>
|
<div className="fixed inset-0 z-50 flex justify-end" onClick={onClose}>
|
||||||
<div className="w-full max-w-md h-full bg-[var(--bg)] border-l border-[var(--line)] shadow-[var(--shadow-lg)] flex flex-col" onClick={(e) => e.stopPropagation()}>
|
<div className="w-full max-w-md h-full bg-[var(--bg)] border-l border-[var(--line)] shadow-[var(--shadow-lg)] flex flex-col" onClick={(e) => e.stopPropagation()}>
|
||||||
@@ -87,6 +111,11 @@ export function BugDetailDrawer({ bugId, onClose }: Props) {
|
|||||||
{BUG_STATUS_LABEL[s]}
|
{BUG_STATUS_LABEL[s]}
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
|
{bug.status !== 'closed' && bug.status !== 'rejected' && (
|
||||||
|
<button onClick={() => setShowTransfer(!showTransfer)} className="h-8 px-3 rounded-lg text-[12px] font-medium border border-[var(--line)] text-[var(--ink-soft)] hover:bg-[var(--bg-subtle)] flex items-center gap-1">
|
||||||
|
<ArrowRightLeft className="h-3 w-3" />转交
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -99,6 +128,21 @@ export function BugDetailDrawer({ bugId, onClose }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{showTransfer && (
|
||||||
|
<div className="space-y-2 pt-1 border-t border-[var(--line)]">
|
||||||
|
<div className="text-[11px] text-[var(--ink-muted)]">转交给:</div>
|
||||||
|
<select value={transferTo} onChange={(e) => setTransferTo(e.target.value)} className="h-8 w-full rounded-lg border border-[var(--line)] px-3 text-[12px] focus:border-[var(--accent)] focus:outline-none">
|
||||||
|
<option value="">选择接收人</option>
|
||||||
|
{members.filter((m) => m.name !== bug.assigneeId).map((m) => <option key={m.id} value={m.name}>{m.name}</option>)}
|
||||||
|
</select>
|
||||||
|
<input value={transferRemark} onChange={(e) => setTransferRemark(e.target.value)} placeholder="转交备注(可选)" className="h-8 w-full rounded-lg border border-[var(--line)] px-3 text-[12px] focus:border-[var(--accent)] focus:outline-none" />
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<button onClick={handleTransfer} disabled={!transferTo} className="h-8 px-3 rounded-lg text-[11px] font-medium bg-blue-500 text-white disabled:opacity-50">确认转交</button>
|
||||||
|
<button onClick={() => setShowTransfer(false)} className="h-8 px-2 text-[11px] text-[var(--ink-muted)]">取消</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 基本信息 */}
|
{/* 基本信息 */}
|
||||||
@@ -107,9 +151,9 @@ export function BugDetailDrawer({ bugId, onClose }: Props) {
|
|||||||
<div className="grid grid-cols-2 gap-y-3 gap-x-4 text-[12px]">
|
<div className="grid grid-cols-2 gap-y-3 gap-x-4 text-[12px]">
|
||||||
<div><span className="text-[var(--ink-muted)]">提交人:</span><span className="text-[var(--ink)]">{bug.reportedBy}</span></div>
|
<div><span className="text-[var(--ink-muted)]">提交人:</span><span className="text-[var(--ink)]">{bug.reportedBy}</span></div>
|
||||||
<div><span className="text-[var(--ink-muted)]">修复人:</span><span className="text-[var(--ink)] font-medium">{bug.assigneeId}</span></div>
|
<div><span className="text-[var(--ink-muted)]">修复人:</span><span className="text-[var(--ink)] font-medium">{bug.assigneeId}</span></div>
|
||||||
<div><span className="text-[var(--ink-muted)]">提交:</span><span className="text-[var(--ink)]">{bug.createdAt.slice(0, 10)}</span></div>
|
<div><span className="text-[var(--ink-muted)]">提交:</span><span className="text-[var(--ink)]">{bug.createdAt.slice(0, 16).replace('T', ' ')}</span></div>
|
||||||
{bug.resolvedAt && <div><span className="text-[var(--ink-muted)]">修复:</span><span className="text-[var(--ink)]">{bug.resolvedAt}</span></div>}
|
{bug.resolvedAt && <div><span className="text-[var(--ink-muted)]">修复:</span><span className="text-[var(--ink)]">{bug.resolvedAt.slice(0, 16).replace('T', ' ')}</span></div>}
|
||||||
{bug.closedAt && <div><span className="text-[var(--ink-muted)]">关闭:</span><span className="text-emerald-600">{bug.closedAt}</span></div>}
|
{bug.closedAt && <div><span className="text-[var(--ink-muted)]">关闭:</span><span className="text-emerald-600">{bug.closedAt.slice(0, 16).replace('T', ' ')}</span></div>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -119,6 +163,18 @@ export function BugDetailDrawer({ bugId, onClose }: Props) {
|
|||||||
<p className="text-[12px] text-[var(--ink-soft)] leading-relaxed whitespace-pre-wrap">{bug.description}</p>
|
<p className="text-[12px] text-[var(--ink-soft)] leading-relaxed whitespace-pre-wrap">{bug.description}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 截图 */}
|
||||||
|
{bug.images && bug.images.length > 0 && (
|
||||||
|
<div className="rounded-xl border border-[var(--line)] bg-[var(--bg-card)] p-4">
|
||||||
|
<div className="text-[10px] text-[var(--ink-muted)] uppercase tracking-wide mb-2">截图附件</div>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{bug.images.map((src, i) => (
|
||||||
|
<img key={i} src={src} alt={`截图${i + 1}`} className="h-24 w-24 object-cover rounded-lg border border-[var(--line)] cursor-pointer hover:ring-2 hover:ring-[var(--accent)]" onClick={() => setLightboxSrc(src)} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* 修复说明 */}
|
{/* 修复说明 */}
|
||||||
{bug.resolution && (
|
{bug.resolution && (
|
||||||
<div className="rounded-xl border border-emerald-200 bg-emerald-50 p-4">
|
<div className="rounded-xl border border-emerald-200 bg-emerald-50 p-4">
|
||||||
@@ -126,8 +182,37 @@ export function BugDetailDrawer({ bugId, onClose }: Props) {
|
|||||||
<p className="text-[12px] text-emerald-800 leading-relaxed whitespace-pre-wrap">{bug.resolution}</p>
|
<p className="text-[12px] text-emerald-800 leading-relaxed whitespace-pre-wrap">{bug.resolution}</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* 操作日志 */}
|
||||||
|
{bug.logs && bug.logs.length > 0 && (
|
||||||
|
<div className="rounded-xl border border-[var(--line)] bg-[var(--bg-card)] p-4">
|
||||||
|
<div className="text-[10px] text-[var(--ink-muted)] uppercase tracking-wide mb-3">操作日志</div>
|
||||||
|
<div className="space-y-2.5">
|
||||||
|
{[...bug.logs].reverse().map((log) => (
|
||||||
|
<div key={log.id} className="flex gap-2.5 text-[11px]">
|
||||||
|
<span className="text-[var(--ink-muted)] tabular-nums shrink-0 w-[110px]">{log.createdAt.slice(0, 16).replace('T', ' ')}</span>
|
||||||
|
<div className="flex-1">
|
||||||
|
<span className="font-medium text-[var(--ink)]">{log.operator}</span>
|
||||||
|
<span className="text-[var(--ink-soft)]"> {LOG_ACTION_LABEL[log.action] || log.action}</span>
|
||||||
|
{log.fromValue && log.toValue && (
|
||||||
|
<span className="text-[var(--ink-muted)]"> {log.fromValue} → {log.toValue}</span>
|
||||||
|
)}
|
||||||
|
{log.remark && <span className="text-[var(--ink-muted)]"> ({log.remark})</span>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Lightbox */}
|
||||||
|
{lightboxSrc && (
|
||||||
|
<div className="fixed inset-0 z-[70] flex items-center justify-center bg-black/70" onClick={() => setLightboxSrc(null)}>
|
||||||
|
<img src={lightboxSrc} alt="大图预览" className="max-h-[85vh] max-w-[85vw] rounded-lg shadow-2xl" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,16 @@ import type { Priority } from './derive';
|
|||||||
export type BugStatus = 'open' | 'fixing' | 'fixed' | 'verifying' | 'closed' | 'rejected';
|
export type BugStatus = 'open' | 'fixing' | 'fixed' | 'verifying' | 'closed' | 'rejected';
|
||||||
export type BugSeverity = 'critical' | 'major' | 'minor' | 'trivial';
|
export type BugSeverity = 'critical' | 'major' | 'minor' | 'trivial';
|
||||||
|
|
||||||
|
export interface BugLog {
|
||||||
|
id: string;
|
||||||
|
action: 'create' | 'status_change' | 'transfer' | 'resolve';
|
||||||
|
fromValue?: string;
|
||||||
|
toValue?: string;
|
||||||
|
operator: string;
|
||||||
|
remark?: string;
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Bug {
|
export interface Bug {
|
||||||
id: string;
|
id: string;
|
||||||
bugNo: string;
|
bugNo: string;
|
||||||
@@ -16,6 +26,8 @@ export interface Bug {
|
|||||||
reportedBy: string;
|
reportedBy: string;
|
||||||
assigneeId: string;
|
assigneeId: string;
|
||||||
status: BugStatus;
|
status: BugStatus;
|
||||||
|
images?: string[];
|
||||||
|
logs?: BugLog[];
|
||||||
resolvedAt?: string;
|
resolvedAt?: string;
|
||||||
closedAt?: string;
|
closedAt?: string;
|
||||||
resolution?: string;
|
resolution?: string;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import type { Bug, BugStatus } from '@/lib/bug';
|
import type { Bug, BugStatus, BugLog } from '@/lib/bug';
|
||||||
import { canBugTransition, generateBugNo } from '@/lib/bug';
|
import { canBugTransition, generateBugNo } from '@/lib/bug';
|
||||||
|
|
||||||
const STORAGE_KEY = 'ftb_bugs_v1';
|
const STORAGE_KEY = 'ftb_bugs_v1';
|
||||||
@@ -17,13 +17,18 @@ function loadLocal(): Bug[] | null {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeLog(action: BugLog['action'], operator: string, from?: string, to?: string, remark?: string): BugLog {
|
||||||
|
return { id: `log-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`, action, fromValue: from, toValue: to, operator, remark, createdAt: new Date().toISOString() };
|
||||||
|
}
|
||||||
|
|
||||||
interface BugState {
|
interface BugState {
|
||||||
bugs: Bug[];
|
bugs: Bug[];
|
||||||
fetchBugs: () => void;
|
fetchBugs: () => void;
|
||||||
createBug: (data: Omit<Bug, 'id' | 'bugNo' | 'createdAt' | 'updatedAt' | 'status'>) => Bug;
|
createBug: (data: Omit<Bug, 'id' | 'bugNo' | 'createdAt' | 'updatedAt' | 'status' | 'logs'>, operator: string) => Bug;
|
||||||
updateBug: (id: string, data: Partial<Bug>) => void;
|
updateBug: (id: string, data: Partial<Bug>) => void;
|
||||||
deleteBug: (id: string) => void;
|
deleteBug: (id: string) => void;
|
||||||
changeStatus: (id: string, to: BugStatus, extra?: { resolution?: string }) => { ok: boolean; message?: string };
|
changeStatus: (id: string, to: BugStatus, operator: string, extra?: { resolution?: string }) => { ok: boolean; message?: string };
|
||||||
|
transferBug: (id: string, newAssigneeId: string, operator: string, remark?: string) => { ok: boolean; message?: string };
|
||||||
getByTestCase: (caseId: string) => Bug[];
|
getByTestCase: (caseId: string) => Bug[];
|
||||||
getByVersion: (versionId: string) => Bug[];
|
getByVersion: (versionId: string) => Bug[];
|
||||||
getByAssignee: (assigneeId: string) => Bug[];
|
getByAssignee: (assigneeId: string) => Bug[];
|
||||||
@@ -37,14 +42,16 @@ export const useBugStore = create<BugState>((set, get) => ({
|
|||||||
if (cached) set({ bugs: cached });
|
if (cached) set({ bugs: cached });
|
||||||
},
|
},
|
||||||
|
|
||||||
createBug: (data) => {
|
createBug: (data, operator) => {
|
||||||
const list = get().bugs;
|
const list = get().bugs;
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
|
const log = makeLog('create', operator);
|
||||||
const bug: Bug = {
|
const bug: Bug = {
|
||||||
...data,
|
...data,
|
||||||
id: `bug-${Date.now()}`,
|
id: `bug-${Date.now()}`,
|
||||||
bugNo: generateBugNo(list),
|
bugNo: generateBugNo(list),
|
||||||
status: 'open',
|
status: 'open',
|
||||||
|
logs: [log],
|
||||||
createdAt: now,
|
createdAt: now,
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
};
|
};
|
||||||
@@ -68,21 +75,32 @@ export const useBugStore = create<BugState>((set, get) => ({
|
|||||||
saveLocal(updated);
|
saveLocal(updated);
|
||||||
},
|
},
|
||||||
|
|
||||||
changeStatus: (id, to, extra) => {
|
changeStatus: (id, to, operator, extra) => {
|
||||||
const bug = get().bugs.find((b) => b.id === id);
|
const bug = get().bugs.find((b) => b.id === id);
|
||||||
if (!bug) return { ok: false, message: 'Bug不存在' };
|
if (!bug) return { ok: false, message: 'Bug不存在' };
|
||||||
if (!canBugTransition(bug.status, to)) {
|
if (!canBugTransition(bug.status, to)) {
|
||||||
return { ok: false, message: `不允许从「${bug.status}」流转到「${to}」` };
|
return { ok: false, message: `不允许从「${bug.status}」流转到「${to}」` };
|
||||||
}
|
}
|
||||||
const today = new Date().toISOString().slice(0, 10);
|
const now = new Date().toISOString();
|
||||||
const patch: Partial<Bug> = { status: to };
|
const patch: Partial<Bug> = { status: to };
|
||||||
if (to === 'fixed') patch.resolvedAt = today;
|
if (to === 'fixed') patch.resolvedAt = now;
|
||||||
if (to === 'closed') patch.closedAt = today;
|
if (to === 'closed') patch.closedAt = now;
|
||||||
if (extra?.resolution) patch.resolution = extra.resolution;
|
if (extra?.resolution) patch.resolution = extra.resolution;
|
||||||
|
const log = makeLog(to === 'fixed' ? 'resolve' : 'status_change', operator, bug.status, to, extra?.resolution);
|
||||||
|
patch.logs = [...(bug.logs || []), log];
|
||||||
get().updateBug(id, patch);
|
get().updateBug(id, patch);
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
},
|
},
|
||||||
|
|
||||||
|
transferBug: (id, newAssigneeId, operator, remark) => {
|
||||||
|
const bug = get().bugs.find((b) => b.id === id);
|
||||||
|
if (!bug) return { ok: false, message: 'Bug不存在' };
|
||||||
|
if (bug.assigneeId === newAssigneeId) return { ok: false, message: '已是当前负责人' };
|
||||||
|
const log = makeLog('transfer', operator, bug.assigneeId, newAssigneeId, remark);
|
||||||
|
get().updateBug(id, { assigneeId: newAssigneeId, logs: [...(bug.logs || []), log] });
|
||||||
|
return { ok: true };
|
||||||
|
},
|
||||||
|
|
||||||
getByTestCase: (caseId) => {
|
getByTestCase: (caseId) => {
|
||||||
return get().bugs.filter((b) => b.testCaseId === caseId);
|
return get().bugs.filter((b) => b.testCaseId === caseId);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user