135 lines
3.9 KiB
Dart
135 lines
3.9 KiB
Dart
import 'package:cpnav/pages/pass_track/controller.dart';
|
|
import 'package:cpnav/pages/setting/project/model.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:get_storage/get_storage.dart';
|
|
import 'package:scence_map/controllers/controller.dart';
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
import '../../models/user.dart';
|
|
import '../../service/base.dart';
|
|
import '../../service/user/loginprefs.dart';
|
|
|
|
LoginPrefs loginPrefs = LoginPrefs();
|
|
ScenceMapController mapController = Get.find<ScenceMapController>();
|
|
PassTrackController passTrackController = Get.find<PassTrackController>();
|
|
|
|
final box = GetStorage(); // 实例化 GetStorage
|
|
|
|
class SettingController extends GetxController {
|
|
String projType = "hydraulic_tamping";
|
|
List<ProjectModel> projectList = [];
|
|
Rx<ProjectModel?> currentProject = Rx<ProjectModel?>(null);
|
|
List<DeviceItem> deviceList = [];
|
|
Rx<DeviceItem?> currentDevice = Rx<DeviceItem?>(null);
|
|
var updateCount = 0.obs;
|
|
GetServices services = GetServices();
|
|
var isInitialized = false;
|
|
// @override
|
|
// void onInit() async {
|
|
// super.onInit();
|
|
// }
|
|
|
|
Future<void> getDeviceId(context) async {
|
|
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
|
|
|
String id;
|
|
|
|
// 根据不同平台获取设备信息
|
|
if (Theme.of(context).platform == TargetPlatform.android) {
|
|
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
|
|
|
id = androidInfo.brand; // 仔细确认你需要的设备编号
|
|
}
|
|
// else if (Theme.of(context).platform == TargetPlatform.iOS) {
|
|
// IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
|
|
// // id = iosInfo.identifierForVendor; // iOS设备编号
|
|
// }
|
|
else {
|
|
id = 'Unknown platform';
|
|
}
|
|
}
|
|
|
|
init() async {
|
|
isInitialized = false;
|
|
UserModel? getUser = UserController().getUser();
|
|
// services.projType = projType;
|
|
if (getUser == null) {
|
|
Map? person = await services.getPerson();
|
|
if (person == null || person.isEmpty) {
|
|
isInitialized = true;
|
|
return;
|
|
}
|
|
UserController().setUser(person);
|
|
getUser = UserModel.fromJson(person);
|
|
}
|
|
// services.org_code = getUser.orgCode;
|
|
|
|
List projList = await services.getproject(getUser.orgCode, projType);
|
|
for (var element in projList) {
|
|
projectList.add(ProjectModel.fromJson(element));
|
|
}
|
|
currentProject.value = getproject();
|
|
currentDevice.value = getdevice();
|
|
|
|
if (currentProject.value == null && projectList.isNotEmpty) {
|
|
currentProject.value = projectList[0];
|
|
setProject(currentProject.value!.toJson());
|
|
// services.projCode = currentProject.value!.projCode;
|
|
}
|
|
await getBindService(services);
|
|
isInitialized = true;
|
|
}
|
|
|
|
getBindService(GetServices service) async {
|
|
deviceList.length = 0;
|
|
List list =
|
|
await service.getDeviceBind(projType, currentProject.value!.projCode);
|
|
mapController.deviceList = {};
|
|
for (var element in list) {
|
|
DeviceItem device = DeviceItem.fromJson(element);
|
|
if (device.type != "rtk_base") {
|
|
deviceList.add(device);
|
|
mapController.addDevice(device);
|
|
}
|
|
}
|
|
if (deviceList.isNotEmpty) {
|
|
currentDevice.value = deviceList[0];
|
|
}
|
|
setDevice(currentDevice.value!.toJson());
|
|
}
|
|
|
|
updateProject(ProjectModel val) async {
|
|
currentProject.value = val;
|
|
// services.projCode = val.projCode;
|
|
setProject(currentProject.value!.toJson());
|
|
passTrackController.loadSideLine();
|
|
await getBindService(services);
|
|
updateCount.value++;
|
|
}
|
|
|
|
void setProject(Map data) {
|
|
box.write('project', data);
|
|
update();
|
|
}
|
|
|
|
void setDevice(Map data) {
|
|
box.write('device', data);
|
|
}
|
|
|
|
ProjectModel? getproject() {
|
|
final p = box.read("project");
|
|
if (p != null) {
|
|
return ProjectModel.fromJson(p);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
DeviceItem? getdevice() {
|
|
final d = box.read("device");
|
|
if (d != null) {
|
|
return DeviceItem.fromJson(d);
|
|
}
|
|
return null;
|
|
}
|
|
}
|