callRecordStore.ts
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { create } from 'zustand';
import type { CallRecord, PaginatedResponse } from '../types';
import { callRecordService } from '../services/callRecordService';
interface CallRecordState {
records: CallRecord[];
total: number;
page: number;
pageSize: number;
totalPages: number;
loading: boolean;
detail: CallRecord | null;
detailLoading: boolean;
filterOptions: { model_names: string[]; account_names: string[]; biz_types: string[] };
fetchRecords: (params?: {
page?: number;
page_size?: number;
model_name?: string;
status?: string;
biz_type?: string;
account_name?: string;
start_time?: string;
end_time?: string;
}) => Promise<void>;
getCallDetail: (id: string) => Promise<CallRecord | null>;
fetchFilterOptions: () => Promise<void>;
}
export const useCallRecordStore = create<CallRecordState>((set, get) => ({
records: [],
total: 0,
page: 1,
pageSize: 20,
totalPages: 0,
loading: false,
detail: null,
detailLoading: false,
filterOptions: { model_names: [], account_names: [], biz_types: [] },
fetchRecords: async (params) => {
set({ loading: true });
try {
const p = { ...params };
if (!p.page) p.page = get().page;
if (!p.page_size) p.page_size = get().pageSize;
const res: PaginatedResponse<CallRecord> = await callRecordService.list(p);
set({
records: res.items,
total: res.total,
page: res.page,
pageSize: res.page_size,
totalPages: res.total_pages,
loading: false,
});
} catch (e) {
console.error('获取调用记录列表失败:', e);
set({ loading: false });
}
},
getCallDetail: async (id: string) => {
set({ detailLoading: true });
try {
const detail = await callRecordService.getById(id);
set({ detail, detailLoading: false });
return detail;
} catch (e) {
console.error('获取调用详情失败:', e);
set({ detailLoading: false });
return null;
}
},
fetchFilterOptions: async () => {
try {
const opts = await callRecordService.getFilterOptions();
set({ filterOptions: opts });
} catch (e) {
console.error('获取筛选选项失败:', e);
}
},
}));