maps.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import axios from 'axios';
  2. import type {
  3. LoginLocation, LoginLocationDetail,
  4. } from '../../share/types.ts';
  5. const API_BASE_URL = '/api';
  6. // 地图相关API的接口类型定义
  7. export interface LoginLocationResponse {
  8. message: string;
  9. data: LoginLocation[];
  10. }
  11. export interface LoginLocationDetailResponse {
  12. message: string;
  13. data: LoginLocationDetail;
  14. }
  15. export interface LoginLocationUpdateResponse {
  16. message: string;
  17. data: LoginLocationDetail;
  18. }
  19. // 地图相关API
  20. export const MapAPI = {
  21. // 获取地图标记点数据
  22. getMarkers: async (params?: {
  23. startTime?: string;
  24. endTime?: string;
  25. userId?: number
  26. }): Promise<LoginLocationResponse> => {
  27. try {
  28. const response = await axios.get(`${API_BASE_URL}/map/markers`, { params });
  29. return response.data;
  30. } catch (error) {
  31. throw error;
  32. }
  33. },
  34. // 获取登录位置详情
  35. getLocationDetail: async (locationId: number): Promise<LoginLocationDetailResponse> => {
  36. try {
  37. const response = await axios.get(`${API_BASE_URL}/map/location/${locationId}`);
  38. return response.data;
  39. } catch (error) {
  40. throw error;
  41. }
  42. },
  43. // 更新登录位置信息
  44. updateLocation: async (locationId: number, data: {
  45. longitude: number;
  46. latitude: number;
  47. location_name?: string;
  48. }): Promise<LoginLocationUpdateResponse> => {
  49. try {
  50. const response = await axios.put(`${API_BASE_URL}/map/location/${locationId}`, data);
  51. return response.data;
  52. } catch (error) {
  53. throw error;
  54. }
  55. }
  56. };