fix(任务): 修复快速创建导致的重复ID

This commit is contained in:
Script Generator
2026-06-25 18:03:53 +08:00
parent 5adc7759ad
commit 55e24442ab
4 changed files with 82 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ import { create } from 'zustand';
import type { TestCase, TestCaseStatus } from '@/lib/test-case';
import { generateCaseNo, normalizeTestCases } from '@/lib/test-case';
import { applyTestCaseTransition, normalizeTestCaseOnCreate } from '@/lib/test-case-workflow';
import { createEntityId, dedupeEntityIds } from '@/lib/entity-id';
import { loadServerData, saveServerData } from '@/lib/server-data';
function saveStored(items: TestCase[]) {
@@ -33,7 +34,11 @@ export const useTestCaseStore = create<TestCaseState>((set, get) => ({
fetchTestCases: async () => {
const cached = await loadStored();
if (cached) set({ testCases: normalizeTestCases(cached) });
if (cached) {
const result = dedupeEntityIds(normalizeTestCases(cached), 'tc');
if (result.changed) saveStored(result.items);
set({ testCases: result.items });
}
},
createTestCase: (data) => {
@@ -41,7 +46,7 @@ export const useTestCaseStore = create<TestCaseState>((set, get) => ({
const now = new Date().toISOString();
const tc: TestCase = normalizeTestCaseOnCreate({
...data,
id: `tc-${Date.now()}`,
id: createEntityId('tc'),
caseNo: generateCaseNo(list),
status: 'pending',
estimateHours: data.estimateHours ?? 0.5,