注册修改为绑定
This commit is contained in:
@@ -95,8 +95,10 @@ class ApiService {
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
resolve(res.data);
|
||||
} else {
|
||||
console.error(`API Error: HTTP ${res.statusCode}: ${res.errMsg}`);
|
||||
reject(new Error(`HTTP ${res.statusCode}: ${res.errMsg}`));
|
||||
// 优先使用服务器返回的具体错误信息,如果没有则使用默认错误信息
|
||||
const errorMessage = res.data || res.errMsg || '请求失败';
|
||||
console.error(`API Error: HTTP ${res.statusCode}: ${errorMessage}`);
|
||||
reject(new Error(`HTTP ${res.statusCode}: ${errorMessage}`));
|
||||
}
|
||||
},
|
||||
fail: (err: any) => {
|
||||
@@ -163,29 +165,58 @@ async ServerLogin(code: string) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册接口
|
||||
* @param userInfo 注册用户信息
|
||||
* @returns 注册结果和员工信息
|
||||
* 绑定接口
|
||||
* @param userInfo 绑定用户信息
|
||||
* @returns 绑定结果和员工信息
|
||||
*/
|
||||
async userRegister(userInfo: { name: string; phone: string }): Promise<{ success: boolean; employeeInfo: EmployeeInfo; message?: string }> {
|
||||
console.log('API userRegister调用,参数userInfo:', userInfo);
|
||||
|
||||
// 服务器现在返回统一的DTO格式:{ success: boolean, userInfo: UserInfoResponse }
|
||||
// 服务器返回直接的用户信息格式:{id, name, phone, role, openid}
|
||||
const response = await this.request<any>('/user/register', {
|
||||
method: 'POST',
|
||||
data: userInfo,
|
||||
});
|
||||
|
||||
return {
|
||||
success: response.success,
|
||||
employeeInfo: {
|
||||
id: response.userInfo.id,
|
||||
name: response.userInfo.name || userInfo.name, // 如果服务器返回null,使用用户输入的值
|
||||
phone: response.userInfo.phone || userInfo.phone, // 如果服务器返回null,使用用户输入的值
|
||||
role: response.userInfo.role || 'DELIVERY_PERSON'
|
||||
},
|
||||
message: response.message
|
||||
};
|
||||
// 检查响应格式,兼容不同的返回格式
|
||||
if (response.id) {
|
||||
// 直接返回用户信息格式
|
||||
return {
|
||||
success: true,
|
||||
employeeInfo: {
|
||||
id: response.id,
|
||||
name: response.name || userInfo.name,
|
||||
phone: response.phone || userInfo.phone,
|
||||
role: response.role || 'DELIVERY_PERSON'
|
||||
},
|
||||
message: '绑定成功'
|
||||
};
|
||||
} else if (response.userInfo && response.userInfo.id) {
|
||||
// 包装格式:{success, userInfo, message}
|
||||
return {
|
||||
success: response.success !== false,
|
||||
employeeInfo: {
|
||||
id: response.userInfo.id,
|
||||
name: response.userInfo.name || userInfo.name,
|
||||
phone: response.userInfo.phone || userInfo.phone,
|
||||
role: response.userInfo.role || 'DELIVERY_PERSON'
|
||||
},
|
||||
message: response.message
|
||||
};
|
||||
} else {
|
||||
// 未知格式,返回错误
|
||||
console.error('未知的绑定响应格式:', response);
|
||||
return {
|
||||
success: false,
|
||||
employeeInfo: {
|
||||
id: 0,
|
||||
name: userInfo.name,
|
||||
phone: userInfo.phone,
|
||||
role: 'DELIVERY_PERSON'
|
||||
},
|
||||
message: '绑定响应格式错误'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,6 +228,25 @@ async ServerLogin(code: string) {
|
||||
return await this.request('/user/logout', { method: 'POST' });
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑微信接口
|
||||
* 清除当前用户的openid绑定,允许重新注册其他账号
|
||||
* @returns 解绑结果
|
||||
*/
|
||||
async unbindWechat(): Promise<{ success: boolean; message?: string }> {
|
||||
console.log('API unbindWechat调用');
|
||||
|
||||
const response = await this.request<any>('/user/unbind', {
|
||||
method: 'POST',
|
||||
data: {}
|
||||
});
|
||||
|
||||
return {
|
||||
success: response.success,
|
||||
message: response.message
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 签退接口
|
||||
* @param userId 用户ID
|
||||
|
Reference in New Issue
Block a user