地址路径修改

This commit is contained in:
2025-10-26 13:15:04 +08:00
parent be2323074b
commit 271b88232c
77 changed files with 13254 additions and 228 deletions

View File

@@ -1,4 +1,5 @@
import { WarehouseInfo, UserInfo, DeliveryPerson, Order, EmployeeInfo } from '../types';
import { Role } from '../utils/roleUtils';
import locationTrackingService from './locationTrackingService';
@@ -9,7 +10,7 @@ import locationTrackingService from './locationTrackingService';
// API基础URL配置
const IS_LOCAL_DEV = false; // true: 本地开发环境, false: 生产环境
const API_BASE_URL = IS_LOCAL_DEV ? 'http://localhost:8080' : 'https://www.doubleyin.cn';
export const API_BASE_URL = IS_LOCAL_DEV ? 'http://localhost:8080' : 'https://www.doubleyin.cn';
console.log(`当前API地址: ${API_BASE_URL} (${IS_LOCAL_DEV ? '本地开发环境' : '生产环境'})`);
@@ -158,7 +159,7 @@ async ServerLogin(code: string) {
id: response.userInfo.id,
name: response.userInfo.name,
phone: response.userInfo.phone,
role: response.userInfo.role || 'DELIVERY_PERSON'
role: response.userInfo.role || Role.DELIVERY_PERSON
},
message: response.message
};
@@ -187,7 +188,7 @@ async ServerLogin(code: string) {
id: response.id,
name: response.name || userInfo.name,
phone: response.phone || userInfo.phone,
role: response.role || 'DELIVERY_PERSON'
role: response.role || Role.DELIVERY_PERSON
},
message: '绑定成功'
};
@@ -199,7 +200,7 @@ async ServerLogin(code: string) {
id: response.userInfo.id,
name: response.userInfo.name || userInfo.name,
phone: response.userInfo.phone || userInfo.phone,
role: response.userInfo.role || 'DELIVERY_PERSON'
role: response.userInfo.role || Role.DELIVERY_PERSON
},
message: response.message
};
@@ -212,7 +213,7 @@ async ServerLogin(code: string) {
id: 0,
name: userInfo.name,
phone: userInfo.phone,
role: 'DELIVERY_PERSON'
role: Role.DELIVERY_PERSON
},
message: '绑定响应格式错误'
};
@@ -430,6 +431,63 @@ async ServerLogin(code: string) {
});
}
/**
* 上传员工头像
* @param employeeId 员工ID
* @param filePath 头像文件路径
* @returns 上传结果
*/
async uploadEmployeeAvatar(employeeId: number, filePath: string): Promise<{ success: boolean; message?: string; avatarUrl?: string }> {
return new Promise((resolve, reject) => {
// 使用微信小程序的文件上传API
wx.uploadFile({
url: `${API_BASE_URL}/employees/${employeeId}/avatar`,
filePath: filePath,
name: 'avatar',
header: {
'Authorization': `Bearer ${getApp<any>().globalData.token}`
},
success: (res) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
try {
const data = JSON.parse(res.data);
resolve({
success: true,
avatarUrl: data.avatarUrl
});
} catch (error) {
resolve({
success: true,
avatarUrl: `${API_BASE_URL}/avatars/${employeeId}.jpg`
});
}
} else {
reject(new Error(`上传失败: HTTP ${res.statusCode}`));
}
},
fail: (err) => {
reject(new Error(`上传失败: ${err.errMsg}`));
}
});
});
}
/**
* 获取员工头像
* @param employeeId 员工ID
* @returns 头像URL
*/
async getEmployeeAvatar(employeeId: number): Promise<string> {
try {
// 尝试获取头像信息
const response = await this.request<{ avatarUrl: string }>(`/employees/${employeeId}/avatar`);
return response.avatarUrl || `${API_BASE_URL}/avatars/${employeeId}.jpg`;
} catch (error) {
// 如果获取失败返回默认头像URL
return `${API_BASE_URL}/avatars/${employeeId}.jpg`;
}
}
// ==================== 仓库相关接口 ====================
/**
@@ -458,6 +516,42 @@ async ServerLogin(code: string) {
return await this.request<Order[]>(`/warehouses/${warehouseId}/orders`);
}
/**
* 创建仓库
* @param warehouseData 仓库数据
* @returns 创建结果
*/
async createWarehouse(warehouseData: Omit<WarehouseInfo, 'id' | 'createdAt' | 'updatedAt'>): Promise<{ success: boolean; message?: string; data?: WarehouseInfo }> {
return await this.request<{ success: boolean; message?: string; data?: WarehouseInfo }>('/warehouses', {
method: 'POST',
data: warehouseData
});
}
/**
* 更新仓库信息
* @param warehouseId 仓库ID
* @param warehouseInfo 仓库信息
* @returns 更新结果
*/
async updateWarehouse(warehouseId: number, warehouseInfo: { name?: string; address?: string; contact?: string; phone?: string; description?: string; capacity?: number; longitude?: number; latitude?: number; status?: 'open' | 'closed' | 'maintenance' }): Promise<{ success: boolean; message?: string; data?: WarehouseInfo }> {
return await this.request<{ success: boolean; message?: string; data?: WarehouseInfo }>(`/warehouses/${warehouseId}`, {
method: 'PUT',
data: warehouseInfo
});
}
/**
* 删除仓库
* @param warehouseId 仓库ID
* @returns 删除结果
*/
async deleteWarehouse(warehouseId: number): Promise<{ success: boolean; message?: string }> {
return await this.request<{ success: boolean; message?: string }>(`/warehouses/${warehouseId}`, {
method: 'DELETE',
});
}
// ==================== 货运人员接口 ====================
/**