111
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
class ResponseCode {
|
||||
static const String success = '0000';
|
||||
static const String unauthorized = '0002';
|
||||
static const String kycRequired = 'KYC_REQUIRED';
|
||||
}
|
||||
|
||||
/// API 响应模型
|
||||
@@ -71,4 +72,5 @@ class ApiResponse<T> {
|
||||
|
||||
bool get isSuccess => success;
|
||||
bool get isUnauthorized => code == ResponseCode.unauthorized;
|
||||
bool get isKycRequired => code == ResponseCode.kycRequired;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,24 @@ class DioClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Multipart 文件上传
|
||||
Future<ApiResponse<T>> upload<T>(
|
||||
String path, {
|
||||
required FormData formData,
|
||||
T Function(dynamic)? fromJson,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _dio.post(
|
||||
path,
|
||||
data: formData,
|
||||
options: Options(contentType: 'multipart/form-data'),
|
||||
);
|
||||
return _handleResponse<T>(response, fromJson);
|
||||
} on DioException catch (e) {
|
||||
return _handleError<T>(e);
|
||||
}
|
||||
}
|
||||
|
||||
ApiResponse<T> _handleResponse<T>(
|
||||
Response response,
|
||||
T Function(dynamic)? fromJson,
|
||||
|
||||
Reference in New Issue
Block a user