2
0

maps.ts 1.4 KB

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