Merge branch 'feature/my' of http://1.95.137.212:57001/APP/FlutterApp into feature/my
This commit is contained in:
@@ -3,12 +3,18 @@ import 'dart:math';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/storage/user_storage.dart';
|
||||
import '../../domain/repositories/path_repository.dart';
|
||||
import '../models/device_add_path_point_model.dart';
|
||||
import '../models/device_work_area_param_model.dart';
|
||||
|
||||
class PathRepositoryImpl implements PathRepository {
|
||||
final String baseUrl = 'https://serviceri.satabot.com'; // 后端接口地址
|
||||
/* final String baseUrl = 'https://serviceri.satabot.com'; // 后端接口地址*/
|
||||
/* final UserStorage localTokenStorage;
|
||||
PathRepositoryImpl({
|
||||
required this.localTokenStorage, // 👈 关键:注入依赖
|
||||
});*/
|
||||
// 生成路径
|
||||
@override
|
||||
Future<List<DeviceAddPathPointModel>> generatePath({
|
||||
@@ -17,9 +23,20 @@ class PathRepositoryImpl implements PathRepository {
|
||||
required OuterBoundary outer,
|
||||
required List<HoleBoundary> holes,
|
||||
required int workType,
|
||||
|
||||
}) async {
|
||||
final url = Uri.parse('$baseUrl/api/path');
|
||||
final headers = {'Content-Type': 'application/json'};
|
||||
final url = Uri.parse('https://servicepathplan.satabot.com/api/path');
|
||||
// ✅ 直接从 GetIt 获取 UserStorage(无需构造函数传参)
|
||||
final userStorage = sl<UserStorage>();
|
||||
final userEntity = await userStorage.getUser();
|
||||
final String? token = userEntity?.token;
|
||||
if (token == null) throw Exception('请先登录');
|
||||
|
||||
// ✅ 设置带 token 的 headers
|
||||
final headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': token,
|
||||
};
|
||||
|
||||
final body = jsonEncode({
|
||||
'reference': reference.toJson(),
|
||||
@@ -32,11 +49,18 @@ class PathRepositoryImpl implements PathRepository {
|
||||
|
||||
try {
|
||||
final response = await http.post(url, headers: headers, body: body);
|
||||
if (response.statusCode == 200) {
|
||||
final List<dynamic> jsonData = jsonDecode(response.body)['path'];
|
||||
return jsonData
|
||||
.map((item) => DeviceAddPathPointModel.fromJson(item))
|
||||
.toList();
|
||||
print('响应体: ${response.body}');
|
||||
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
if (decoded['code'] == 200) {
|
||||
final pathJson = decoded['path'];
|
||||
if (pathJson == null) {
|
||||
throw Exception('API returned null for "path"');
|
||||
}
|
||||
if (pathJson is! List) {
|
||||
throw Exception('Expected "path" to be a List, but got ${pathJson.runtimeType}');
|
||||
}
|
||||
final List<dynamic> jsonData = pathJson;
|
||||
return jsonData.map((item) => DeviceAddPathPointModel.fromJson(item)).toList();
|
||||
} else {
|
||||
throw Exception('Failed to load path: ${response.statusCode}');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user