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 'package:http/http.dart' as http;
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import '../../../../core/di/injection.dart';
|
||||||
|
import '../../../../core/storage/user_storage.dart';
|
||||||
import '../../domain/repositories/path_repository.dart';
|
import '../../domain/repositories/path_repository.dart';
|
||||||
import '../models/device_add_path_point_model.dart';
|
import '../models/device_add_path_point_model.dart';
|
||||||
import '../models/device_work_area_param_model.dart';
|
import '../models/device_work_area_param_model.dart';
|
||||||
|
|
||||||
class PathRepositoryImpl implements PathRepository {
|
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
|
@override
|
||||||
Future<List<DeviceAddPathPointModel>> generatePath({
|
Future<List<DeviceAddPathPointModel>> generatePath({
|
||||||
@@ -17,9 +23,20 @@ class PathRepositoryImpl implements PathRepository {
|
|||||||
required OuterBoundary outer,
|
required OuterBoundary outer,
|
||||||
required List<HoleBoundary> holes,
|
required List<HoleBoundary> holes,
|
||||||
required int workType,
|
required int workType,
|
||||||
|
|
||||||
}) async {
|
}) async {
|
||||||
final url = Uri.parse('$baseUrl/api/path');
|
final url = Uri.parse('https://servicepathplan.satabot.com/api/path');
|
||||||
final headers = {'Content-Type': 'application/json'};
|
// ✅ 直接从 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({
|
final body = jsonEncode({
|
||||||
'reference': reference.toJson(),
|
'reference': reference.toJson(),
|
||||||
@@ -32,11 +49,18 @@ class PathRepositoryImpl implements PathRepository {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final response = await http.post(url, headers: headers, body: body);
|
final response = await http.post(url, headers: headers, body: body);
|
||||||
if (response.statusCode == 200) {
|
print('响应体: ${response.body}');
|
||||||
final List<dynamic> jsonData = jsonDecode(response.body)['path'];
|
final decoded = jsonDecode(response.body) as Map<String, dynamic>;
|
||||||
return jsonData
|
if (decoded['code'] == 200) {
|
||||||
.map((item) => DeviceAddPathPointModel.fromJson(item))
|
final pathJson = decoded['path'];
|
||||||
.toList();
|
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 {
|
} else {
|
||||||
throw Exception('Failed to load path: ${response.statusCode}');
|
throw Exception('Failed to load path: ${response.statusCode}');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user