agent-list-mock.ts
4.67 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
export type AgentStatus = 'enable' | 'disable';
export type AgentAction = 'detail' | 'edit' | 'enable' | 'disable' | 'delete';
export interface AgentPositionOption {
id: string;
name: string;
}
export interface AgentListMockItem extends Record<string, unknown> {
agent_id: number;
name: string;
is_manager: boolean;
positions: AgentPositionOption[];
status: AgentStatus;
bound_group_count: number;
bound_skill_count: number;
updated_at: string;
available_actions: AgentAction[];
}
export interface AgentListMockFixture {
loading?: boolean;
error?: boolean;
items: AgentListMockItem[];
total?: number;
}
export interface AgentListPageQuery {
keyword?: string;
positionId?: string;
status?: AgentStatus | 'all';
page: number;
pageSize: number;
source?: AgentListMockItem[];
}
export const agentPositionOptions: AgentPositionOption[] = [
{ id: 'sales', name: '驻店销售岗' },
{ id: 'service', name: '客服岗' },
{ id: 'ops', name: '运营岗' },
];
const managerAgent: AgentListMockItem = {
agent_id: 1,
name: '管家Agent',
is_manager: true,
positions: [],
status: 'enable',
bound_group_count: 12,
bound_skill_count: 0,
updated_at: '2026-05-19 10:30:00',
available_actions: ['detail', 'edit'],
};
const normalAgents: AgentListMockItem[] = [
{
agent_id: 101,
name: '复盘Agent',
is_manager: false,
positions: [agentPositionOptions[0]],
status: 'enable',
bound_group_count: 8,
bound_skill_count: 4,
updated_at: '2026-05-18 16:20:00',
available_actions: ['detail', 'edit', 'disable', 'delete'],
},
{
agent_id: 102,
name: '质检Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 3,
bound_skill_count: 2,
updated_at: '2026-05-17 09:15:00',
available_actions: ['detail', 'edit', 'enable', 'delete'],
},
{
agent_id: 103,
name: '销售助手Agent',
is_manager: false,
positions: [agentPositionOptions[0], agentPositionOptions[2]],
status: 'enable',
bound_group_count: 15,
bound_skill_count: 6,
updated_at: '2026-05-16 13:05:00',
available_actions: ['detail', 'edit', 'disable', 'delete'],
},
{
agent_id: 104,
name: '线索跟进Agent',
is_manager: false,
positions: [agentPositionOptions[2]],
status: 'enable',
bound_group_count: 5,
bound_skill_count: 3,
updated_at: '2026-05-15 18:40:00',
available_actions: ['detail', 'edit', 'disable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['detail', 'edit', 'enable', 'delete'],
},
];
export const agentListMockFixtures = {
normal: { items: [managerAgent, ...normalAgents], total: 6 },
managerOnly: { items: [managerAgent], total: 1 },
empty: { items: [], total: 0 },
filteredEmpty: { items: [], total: 0 },
loading: { loading: true, items: [] },
error: { error: true, items: [] },
longText: {
items: [
{
...normalAgents[0],
agent_id: 201,
name: '超长名称用于验证表格截断和换行规则的复盘Agent',
updated_at: '2026-05-13 08:00:00',
},
],
total: 1,
},
disabledActions: { items: [{ ...managerAgent, available_actions: ['detail', 'edit'] }], total: 1 },
paginationBoundary: { items: [managerAgent, ...normalAgents], total: 51 },
} satisfies Record<string, AgentListMockFixture>;
export function sortAgentsForDisplay(items: AgentListMockItem[]) {
return [...items].sort((left, right) => Number(right.is_manager) - Number(left.is_manager));
}
export function getAgentListItem(agentId?: string) {
if (!agentId) return undefined;
return agentListMockFixtures.normal.items.find((item) => String(item.agent_id) === agentId);
}
export function getAgentListPage({ keyword = '', page, pageSize, positionId, source, status = 'all' }: AgentListPageQuery) {
const normalizedKeyword = keyword.trim().toLowerCase();
const filtered = sortAgentsForDisplay(source ?? agentListMockFixtures.normal.items).filter((agent) => {
const matchesKeyword = !normalizedKeyword || agent.name.toLowerCase().includes(normalizedKeyword);
const matchesPosition = !positionId || agent.positions.some((position) => position.id === positionId);
const matchesStatus = status === 'all' || agent.status === status;
return matchesKeyword && matchesPosition && matchesStatus;
});
const start = (page - 1) * pageSize;
return {
items: filtered.slice(start, start + pageSize),
page,
pageSize,
total: filtered.length,
};
}