// 货运人员服务 - 处理货运人员相关的数据操作 import { DeliveryPerson } from '../types'; import apiService from './apiService'; import { API_BASE_URL } from './apiService'; /** * 货运人员服务类 * 提供货运人员信息管理、状态管理等功能 */ class DeliveryPersonService { /** * 构造函数 */ constructor() { // 不再使用模拟数据 } /** * 获取所有货运人员 * @returns 货运人员列表 */ async getDeliveryPersons(): Promise { return apiService.getDeliveryPersons(); } /** * 根据ID获取货运人员 * @param id 货运人员ID * @returns 货运人员信息或null */ async getDeliveryPersonById(id: number): Promise { try { const result = await apiService.getDeliveryPersonById(id); return result; } catch (error) { console.error('获取货运人员失败:', error); return null; } } /** * 获取空闲的货运人员 * @returns 空闲货运人员列表 */ async getIdleDeliveryPersons(): Promise { return apiService.getIdleDeliveryPersons(); } /** * 获取忙碌的货运人员 * @returns 忙碌货运人员列表 */ async getBusyDeliveryPersons(): Promise { return apiService.getBusyDeliveryPersons(); } /** * 获取货运人员当前订单 * @param deliveryPersonId 货运人员ID * @returns 订单列表 */ async getDeliveryPersonOrders(deliveryPersonId: number): Promise> { return apiService.getDeliveryPersonOrders(deliveryPersonId); } /** * 获取货运人员头像URL * @param deliveryPersonId 货运人员ID * @returns 头像URL */ async getAvatarUrl(deliveryPersonId: number): Promise { try { // 首先尝试获取货运人员详细信息 const deliveryPerson = await this.getDeliveryPersonById(deliveryPersonId); if (deliveryPerson && deliveryPerson.avatarPath) { return `${API_BASE_URL}${deliveryPerson.avatarPath}`; } // 如果货运人员信息中没有头像路径,返回默认头像 return '/images/truck.png'; } catch (error) { console.error('获取货运人员头像失败:', error); return '/images/truck.png'; } } } /** * 货运人员服务单例实例 * 导出供应用程序全局使用 */ export default new DeliveryPersonService();