visitorApi.ts 665 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * 访客端 API 服务
  3. * 提供访客相关的 API 调用
  4. */
  5. import { apiUrl } from "@/lib/config";
  6. /**
  7. * 在线客服信息
  8. */
  9. export interface OnlineAgent {
  10. id: number;
  11. nickname: string;
  12. avatar_url: string;
  13. }
  14. /**
  15. * 获取在线客服列表
  16. */
  17. export async function fetchOnlineAgents(): Promise<OnlineAgent[]> {
  18. const response = await fetch(apiUrl("/visitor/online-agents"), {
  19. method: "GET",
  20. headers: {
  21. "Content-Type": "application/json",
  22. },
  23. });
  24. if (!response.ok) {
  25. throw new Error(`获取在线客服列表失败: ${response.statusText}`);
  26. }
  27. const data = await response.json();
  28. return data.agents || [];
  29. }