初始化项目
This commit is contained in:
172
lib/controller/main_bottom/global_controller.dart
Normal file
172
lib/controller/main_bottom/global_controller.dart
Normal file
@@ -0,0 +1,172 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:vbvs_app/controller/main_bottom/main_page_controller.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
|
||||
class GlobalModel {
|
||||
List deviceList = [];
|
||||
Map deviceMain = {};
|
||||
|
||||
Map useBedController = {}; //之前控制的设备
|
||||
|
||||
List deviceType = [];
|
||||
|
||||
List homeImgList = []; //轮播图
|
||||
|
||||
bool hideBottomNavigationBar = false;
|
||||
|
||||
get deviceMainIsShare {
|
||||
if (deviceMain != null && deviceMain["type"] == 2) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// get JunheDevices {
|
||||
// List arr = [];
|
||||
|
||||
// deviceList.forEach((d) {
|
||||
// d?["personnelInfo"]?.forEach((item) {
|
||||
// if (item["mac"] == d["bindMacA"] &&
|
||||
// arr.indexWhere((a) => a["mac"] == item["mac"]) == -1) {
|
||||
// arr.add(item);
|
||||
// }
|
||||
// });
|
||||
// if (d["bindMacB"] != null && d["bindMacB"] != "") {
|
||||
// d["personnelInfo"].forEach((item) {
|
||||
// if (item["mac"] == d["bindMacB"] &&
|
||||
// arr.indexWhere((a) => a["mac"] == item["mac"]) == -1) {
|
||||
// arr.add(item);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
// return arr;
|
||||
// }
|
||||
|
||||
get JunheDevices {
|
||||
List arr = [];
|
||||
try {
|
||||
if (deviceList != null) {
|
||||
deviceList.forEach((d) {
|
||||
if (d?["personnelInfo"] != null) {
|
||||
d["personnelInfo"].forEach((item) {
|
||||
if (item["mac"] == d["bindMacA"] &&
|
||||
arr.indexWhere((a) => a["mac"] == item["mac"]) == -1) {
|
||||
arr.add(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (d["bindMacB"] != null && d["bindMacB"] != "") {
|
||||
if (d["personnelInfo"] != null) {
|
||||
d["personnelInfo"].forEach((item) {
|
||||
if (item["mac"] == d["bindMacB"] &&
|
||||
arr.indexWhere((a) => a["mac"] == item["mac"]) == -1) {
|
||||
arr.add(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
get mainDevicePeople {
|
||||
if (deviceMain == null || deviceMain["mac"] == null) {
|
||||
return [{}, {}];
|
||||
}
|
||||
List arr = [{}, {}];
|
||||
if (deviceMain["personnelInfo"] != null) {
|
||||
if (deviceMain["bindMacA"] != null) {
|
||||
deviceMain["personnelInfo"]?.forEach((d) {
|
||||
if (d["mac"] == deviceMain["bindMacA"]) {
|
||||
arr[0] = d;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (deviceMain["bindMacB"] != null) {
|
||||
deviceMain["personnelInfo"]?.forEach((d) {
|
||||
if (d["mac"] == deviceMain["bindMacB"]) {
|
||||
arr[1] = d;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
GlobalModel();
|
||||
}
|
||||
|
||||
class GlobalController extends GetControllerEx<GlobalModel> {
|
||||
GlobalController() {
|
||||
attr = GetModel(GlobalModel()).obs;
|
||||
}
|
||||
|
||||
get userInfoController => Get.find<UserInfoController>();
|
||||
|
||||
Timer? getDeviceListTimer;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
resetParmAll() {
|
||||
resetParm();
|
||||
Get.find<MainPageController>().resetParm();
|
||||
}
|
||||
|
||||
resetParm() {
|
||||
getDeviceListTimer?.cancel();
|
||||
getDeviceListTimer = null;
|
||||
model.deviceList = [];
|
||||
model.deviceMain = {};
|
||||
model.useBedController = {};
|
||||
model.deviceType = [];
|
||||
model.homeImgList = [];
|
||||
model.hideBottomNavigationBar = false;
|
||||
}
|
||||
|
||||
deviceUpdateTimerCreated() {
|
||||
if (getDeviceListTimer == null) {
|
||||
getDeviceListTimer = Timer.periodic(const Duration(seconds: 10), (t) {
|
||||
if (userInfoController.model.token != null) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
getDeviceGroupName(device) {
|
||||
return "${device['roomName']}/${device["deviceType"]?["name"]}/${device["name"]}";
|
||||
}
|
||||
|
||||
getDeviceGroupName2(device) {
|
||||
return "${device["deviceType"]?["name"]}/${device["name"]}";
|
||||
}
|
||||
|
||||
getUpperCaseMac(mac) {
|
||||
if (mac == null || mac == "") {
|
||||
return "";
|
||||
}
|
||||
return "$mac".toUpperCase();
|
||||
}
|
||||
|
||||
getDeviceType() async {
|
||||
var rs =
|
||||
await ef.from("app_device_type").select().order("id", ascending: true);
|
||||
model.deviceType = rs.where((d) => d["page"] != null).toList();
|
||||
updateAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user