agent-list-mock.ts 4.67 KB
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,
  };
}