第二次提交
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||||
|
||||
import '../../models/user_model.dart';
|
||||
import '../auth_http_datasource.dart';
|
||||
@@ -11,7 +12,7 @@ class AuthHttpDataSourceImpl implements AuthHttpDataSource {
|
||||
@override
|
||||
Future<UserModel> login(String username, String password, sourceType) async {
|
||||
final response = await dio.post(
|
||||
'/login',
|
||||
HttpApiConsts.loginUrl,
|
||||
data: {
|
||||
'username': username,
|
||||
'password': password,
|
||||
@@ -19,11 +20,21 @@ class AuthHttpDataSourceImpl implements AuthHttpDataSource {
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print('runtimeType = ${response.data.runtimeType}');
|
||||
return UserModel.fromJson(response.data);
|
||||
} else {
|
||||
throw Exception(response.data['message'] ?? 'Login failed');
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('网络请求失败: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final responseData = response.data;
|
||||
|
||||
if (responseData['code'] != 200) {
|
||||
throw Exception(responseData['msg'] ?? '业务异常');
|
||||
}
|
||||
|
||||
final loginUsername = responseData['username'];
|
||||
if (loginUsername == null || loginUsername == '') {
|
||||
throw Exception('服务器返回的数据结构不完整(缺少用户信息)');
|
||||
}
|
||||
var userModel = UserModel.fromJson(responseData);
|
||||
return userModel;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user