176 lines
5.1 KiB
Dart
176 lines
5.1 KiB
Dart
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/appRouters.dart';
|
|
import 'package:star_lock/blue/blue_manage.dart';
|
|
|
|
import '../common/XSConstantMacro/XSConstantMacro.dart';
|
|
import 'manager/client_manager.dart';
|
|
|
|
class BaseGetXController extends GetxController{
|
|
int currentTimeSeconds = 0;
|
|
|
|
bool currentPage = true;
|
|
var pageNo = 1;
|
|
var pageSize = "20";
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
Get.log('$runtimeType onReady');
|
|
currentPage = true;
|
|
}
|
|
|
|
@override
|
|
// TODO: implement onDelete
|
|
InternalFinalCallback<void> get onDelete => super.onDelete;
|
|
|
|
@override
|
|
// TODO: implement onStart
|
|
InternalFinalCallback<void> get onStart => super.onStart;
|
|
|
|
@override
|
|
void onInit() {
|
|
// TODO: implement onInit
|
|
Get.log('$runtimeType onInit ');
|
|
super.onInit();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
// TODO: implement onClose
|
|
super.onClose();
|
|
currentPage = false;
|
|
Get.log('onClose -----> $runtimeType');
|
|
}
|
|
|
|
Future delay({Duration? duration,Function? something}) => Future.delayed(duration ?? 500. milliseconds,something as FutureOr Function()?);
|
|
|
|
void showEasyLoading() => EasyLoading.show();
|
|
|
|
void dismissEasyLoading() => EasyLoading.dismiss();
|
|
|
|
Timer? _timer;
|
|
// CancelableOperation? _operation;
|
|
void showBlueConnetctToastTimer({bool isShowBlueConnetctToast = true,Function? action}) {
|
|
if(_timer != null){
|
|
_timer!.cancel();
|
|
_timer = null;
|
|
}
|
|
_timer = Timer.periodic(15.seconds, (timer) {
|
|
if(action != null) {
|
|
action();
|
|
}
|
|
cancelBlueConnetctToastTimer();
|
|
if(isShowBlueConnetctToast == true){
|
|
showBlueConnetctToast();
|
|
}
|
|
});
|
|
// _operation = CancelableOperation.fromFuture(
|
|
// Future.delayed(const Duration(seconds: 15), () {
|
|
// print('Operation completed');
|
|
// showBlueConnetctToast();
|
|
// }),
|
|
// );
|
|
}
|
|
|
|
void cancelBlueConnetctToastTimer() {
|
|
Get.log('cancelBlueConnetctToastTimer');
|
|
if(_timer != null){
|
|
_timer!.cancel();
|
|
_timer = null;
|
|
}
|
|
// _operation?.cancel();
|
|
}
|
|
|
|
void showBlueConnetctToast() {
|
|
bool isContains = BlueManage().connectDeviceName!.contains("T9A");
|
|
showToast("连接设备失败,请确保在设备附近,设备未被连接,设备已打开${isContains == true ? "。如果是全自动锁,请使屏幕变亮" : ""}");
|
|
}
|
|
|
|
void showToast(String status,{Function? something}) {
|
|
EasyLoading.showToast(status,duration: 2000.milliseconds);
|
|
if(something != null) {
|
|
delay(duration: 2100.milliseconds,something: something);
|
|
}
|
|
}
|
|
|
|
void showError(String status,{Function? something}) {
|
|
EasyLoading.showError(status,duration: 2000.milliseconds);
|
|
if(something != null) {
|
|
delay(duration: 2100.milliseconds,something: something);
|
|
}
|
|
}
|
|
|
|
void showSuccess(String status,{Function? something}) {
|
|
EasyLoading.showSuccess(status,duration: 1500.milliseconds);
|
|
if(something != null) {
|
|
delay(duration: 2000.milliseconds,something: something);
|
|
}
|
|
}
|
|
|
|
void showOperationSuccessful({String? status,Function? something}) => showSuccess( status ?? "成功",something: something);
|
|
void showOperationFailed({String? status, Function? something}) => showError( status ?? "失败",something: something);
|
|
|
|
void logOff() async {
|
|
await ClientManager().logOff();
|
|
Get.offAllNamed(Routers.starLockLoginPage);
|
|
}
|
|
|
|
String getUseKeyTypeStr(int? startDate, int? endDate,int? keyType) {
|
|
String useDateStr = '';
|
|
if (keyType == XSConstantMacro.keyTypeTime) {
|
|
//限期
|
|
DateTime startDateStr =
|
|
DateTime.fromMillisecondsSinceEpoch(startDate!);
|
|
DateTime endDateStr =
|
|
DateTime.fromMillisecondsSinceEpoch(endDate!);
|
|
useDateStr =
|
|
'${startDateStr.toLocal().toString().substring(0, 16)} - ${endDateStr.toLocal().toString().substring(0, 16)}';
|
|
} else if (keyType == XSConstantMacro.keyTypeLong) {
|
|
//永久
|
|
// DateTime dateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.date!);
|
|
// useDateStr = '${dateStr.toLocal().toString().substring(0, 16)}\n永久';
|
|
useDateStr = '永久';
|
|
} else if (keyType == XSConstantMacro.keyTypeOnce) {
|
|
//单次
|
|
// DateTime dateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.date!);
|
|
// useDateStr = '${dateStr.toLocal().toString().substring(0, 16)} \n单次';
|
|
useDateStr = '单次';
|
|
} else if (keyType == XSConstantMacro.keyTypeLoop) {
|
|
//循环
|
|
useDateStr = '循环';
|
|
}
|
|
|
|
return useDateStr;
|
|
}
|
|
|
|
static List splitList(List list, int len) {
|
|
if (len <= 1) {
|
|
return [list];
|
|
}
|
|
List result = [];
|
|
int index = 1;
|
|
while (true) {
|
|
if (index * len < list.length) {
|
|
List temp = list.skip((index - 1) * len).take(len).toList();
|
|
result.add(temp);
|
|
index++;
|
|
continue;
|
|
}
|
|
List temp = list.skip((index - 1) * len).toList();
|
|
result.add(temp);
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
|
|
///Extension_Int
|
|
extension Extension_Int on int {
|
|
bool get codeIsSuccessful => this == 0;
|
|
bool get msgCodeIsSuccessful => this == 1;
|
|
} |