2023-07-29 09:25:21 +08:00
|
|
|
|
import 'dart:async';
|
2024-03-09 17:17:38 +08:00
|
|
|
|
import 'dart:io';
|
2023-07-29 09:25:21 +08:00
|
|
|
|
|
2024-03-09 17:17:38 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2023-07-29 09:25:21 +08:00
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
import 'package:star_lock/appRouters.dart';
|
2024-04-26 15:38:59 +08:00
|
|
|
|
import 'package:star_lock/app_settings/app_settings.dart';
|
2024-01-23 18:37:03 +08:00
|
|
|
|
import 'package:star_lock/blue/blue_manage.dart';
|
2024-03-09 17:17:38 +08:00
|
|
|
|
import 'package:system_settings/system_settings.dart';
|
|
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2023-07-29 09:25:21 +08:00
|
|
|
|
|
2024-01-18 11:25:56 +08:00
|
|
|
|
import '../common/XSConstantMacro/XSConstantMacro.dart';
|
2024-03-09 17:17:38 +08:00
|
|
|
|
import 'NativeInteractionTool.dart';
|
2024-04-01 16:21:46 +08:00
|
|
|
|
import 'dateTool.dart';
|
2023-07-29 09:25:21 +08:00
|
|
|
|
import 'manager/client_manager.dart';
|
2024-03-09 17:17:38 +08:00
|
|
|
|
import 'showIosTipView.dart';
|
2023-07-29 09:25:21 +08:00
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
class BaseGetXController extends GetxController {
|
2023-07-29 09:25:21 +08:00
|
|
|
|
int currentTimeSeconds = 0;
|
|
|
|
|
|
|
|
|
|
|
|
bool currentPage = true;
|
2024-01-25 17:40:41 +08:00
|
|
|
|
var pageNo = 1;
|
2024-06-04 16:38:23 +08:00
|
|
|
|
var pageSize = '20';
|
2023-07-29 09:25:21 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void onReady() {
|
|
|
|
|
|
super.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
|
|
|
|
|
|
super.onInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void onClose() {
|
|
|
|
|
|
// TODO: implement onClose
|
|
|
|
|
|
super.onClose();
|
|
|
|
|
|
currentPage = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
Future delay({Duration? duration, Function? something}) => Future.delayed(
|
|
|
|
|
|
duration ?? 500.milliseconds, something as FutureOr Function()?);
|
2023-07-29 09:25:21 +08:00
|
|
|
|
|
|
|
|
|
|
void showEasyLoading() => EasyLoading.show();
|
|
|
|
|
|
|
2024-05-14 09:32:06 +08:00
|
|
|
|
void dismissEasyLoading() {
|
2024-05-14 18:42:26 +08:00
|
|
|
|
if (EasyLoading.isShow) EasyLoading.dismiss();
|
2024-05-14 09:32:06 +08:00
|
|
|
|
}
|
2023-07-29 09:25:21 +08:00
|
|
|
|
|
2024-05-14 18:42:26 +08:00
|
|
|
|
void showTitleEasyLoading(String showContent) =>
|
|
|
|
|
|
EasyLoading.show(status: showContent);
|
2024-04-29 11:40:04 +08:00
|
|
|
|
|
2024-01-04 18:27:50 +08:00
|
|
|
|
Timer? _timer;
|
2024-05-14 18:42:26 +08:00
|
|
|
|
|
2024-01-04 18:27:50 +08:00
|
|
|
|
// CancelableOperation? _operation;
|
2024-05-14 18:42:26 +08:00
|
|
|
|
void showBlueConnetctToastTimer(
|
2024-05-16 17:49:08 +08:00
|
|
|
|
{bool isShowBlueConnetctToast = true,
|
|
|
|
|
|
int outTimer = 15,
|
|
|
|
|
|
Function? action}) {
|
2024-03-12 16:19:04 +08:00
|
|
|
|
if (_timer != null && _timer!.isActive) {
|
2024-01-04 18:27:50 +08:00
|
|
|
|
_timer!.cancel();
|
2024-01-05 13:56:34 +08:00
|
|
|
|
_timer = null;
|
2024-01-04 18:27:50 +08:00
|
|
|
|
}
|
2024-05-16 17:49:08 +08:00
|
|
|
|
_timer = Timer.periodic(outTimer.seconds, (timer) {
|
2024-03-12 16:19:04 +08:00
|
|
|
|
if (action != null) {
|
2024-01-06 16:26:13 +08:00
|
|
|
|
action();
|
|
|
|
|
|
}
|
2024-01-05 13:56:34 +08:00
|
|
|
|
cancelBlueConnetctToastTimer();
|
2024-03-12 16:19:04 +08:00
|
|
|
|
if (isShowBlueConnetctToast == true) {
|
2024-01-06 16:26:13 +08:00
|
|
|
|
showBlueConnetctToast();
|
2024-01-05 13:56:34 +08:00
|
|
|
|
}
|
2024-01-04 18:27:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cancelBlueConnetctToastTimer() {
|
2024-04-26 15:38:59 +08:00
|
|
|
|
// AppLog.log('超过15秒未响应,APP主动关菊花断开连接');
|
2024-03-12 16:19:04 +08:00
|
|
|
|
if (_timer != null && _timer!.isActive) {
|
2024-01-05 13:56:34 +08:00
|
|
|
|
_timer!.cancel();
|
|
|
|
|
|
_timer = null;
|
|
|
|
|
|
}
|
2024-01-04 18:27:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-02 18:03:50 +08:00
|
|
|
|
void showBlueConnetctToast() {
|
2024-06-04 16:38:23 +08:00
|
|
|
|
bool isContains = BlueManage().connectDeviceName.contains('T9A');
|
2024-03-12 16:19:04 +08:00
|
|
|
|
showToast(
|
2024-05-14 18:42:26 +08:00
|
|
|
|
"${'操作失败,请确认锁是否在附近,或重启手机蓝牙后再试。'.tr}${isContains == true ? "如果是全自动锁,请使屏幕变亮" : ""}");
|
2024-01-02 18:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-22 10:33:07 +08:00
|
|
|
|
void showToast(String status,
|
|
|
|
|
|
{Function? something,
|
|
|
|
|
|
EasyLoadingMaskType maskType = EasyLoadingMaskType.none}) {
|
|
|
|
|
|
EasyLoading.showToast(status,
|
|
|
|
|
|
duration: 2000.milliseconds, maskType: maskType);
|
2024-03-12 16:19:04 +08:00
|
|
|
|
if (something != null) {
|
|
|
|
|
|
delay(duration: 2100.milliseconds, something: something);
|
2023-07-29 09:25:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
void showError(String status, {Function? something}) {
|
|
|
|
|
|
EasyLoading.showError(status, duration: 2000.milliseconds);
|
|
|
|
|
|
if (something != null) {
|
|
|
|
|
|
delay(duration: 2100.milliseconds, something: something);
|
2023-07-29 09:25:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
void showSuccess(String status, {Function? something}) {
|
|
|
|
|
|
EasyLoading.showSuccess(status, duration: 1500.milliseconds);
|
|
|
|
|
|
if (something != null) {
|
|
|
|
|
|
delay(duration: 2000.milliseconds, something: something);
|
2023-07-29 09:25:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
void showOperationSuccessful({String? status, Function? something}) =>
|
2024-06-04 16:38:23 +08:00
|
|
|
|
showSuccess(status ?? '成功', something: something);
|
2024-05-14 18:42:26 +08:00
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
void showOperationFailed({String? status, Function? something}) =>
|
2024-06-04 16:38:23 +08:00
|
|
|
|
showError(status ?? '失败', something: something);
|
2023-07-29 09:25:21 +08:00
|
|
|
|
|
|
|
|
|
|
void logOff() async {
|
|
|
|
|
|
await ClientManager().logOff();
|
|
|
|
|
|
Get.offAllNamed(Routers.starLockLoginPage);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-09 17:17:38 +08:00
|
|
|
|
void checkBlueIsOpen(void Function() action) {
|
|
|
|
|
|
NativeInteractionTool().sendGetBlueStatus();
|
|
|
|
|
|
NativeInteractionTool().receiveChannelBlueIsOnEvent((String status) {
|
2024-06-04 16:38:23 +08:00
|
|
|
|
if (status == '1') {
|
2024-03-09 17:17:38 +08:00
|
|
|
|
// 蓝牙已打开
|
2024-04-26 15:38:59 +08:00
|
|
|
|
AppLog.log('蓝牙已打开');
|
2024-03-09 17:17:38 +08:00
|
|
|
|
action();
|
2024-06-04 16:38:23 +08:00
|
|
|
|
} else if (status == '0') {
|
2024-03-09 17:17:38 +08:00
|
|
|
|
// 蓝牙未打开
|
2024-04-26 15:38:59 +08:00
|
|
|
|
AppLog.log('蓝牙未打开');
|
2024-03-09 17:17:38 +08:00
|
|
|
|
showIosTipViewDialog();
|
|
|
|
|
|
return;
|
2024-03-12 16:19:04 +08:00
|
|
|
|
} else {
|
2024-03-09 17:17:38 +08:00
|
|
|
|
// 蓝牙未打开
|
2024-04-26 15:38:59 +08:00
|
|
|
|
AppLog.log('设备不支持蓝牙');
|
2024-06-04 16:38:23 +08:00
|
|
|
|
showToast('设备不支持蓝牙');
|
2024-03-09 17:17:38 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void showIosTipViewDialog() {
|
|
|
|
|
|
showDialog(
|
|
|
|
|
|
context: Get.context!,
|
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
|
return ShowIosTipView(
|
2024-06-04 16:38:23 +08:00
|
|
|
|
title: '提示',
|
|
|
|
|
|
tipTitle: '蓝牙未打开,请到设置里面打开蓝牙',
|
2024-03-09 17:17:38 +08:00
|
|
|
|
sureClick: () {
|
|
|
|
|
|
Get.back();
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
|
launch('App-Prefs:');
|
2024-03-12 16:19:04 +08:00
|
|
|
|
} else {
|
2024-03-09 17:17:38 +08:00
|
|
|
|
SystemSettings.system();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
cancelClick: () {
|
|
|
|
|
|
Get.back();
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
2024-03-12 16:19:04 +08:00
|
|
|
|
});
|
2024-03-09 17:17:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-12 16:19:04 +08:00
|
|
|
|
String getUseKeyTypeStr(int? startDate, int? endDate, int? keyType) {
|
2024-01-18 11:25:56 +08:00
|
|
|
|
String useDateStr = '';
|
|
|
|
|
|
if (keyType == XSConstantMacro.keyTypeTime) {
|
|
|
|
|
|
//限期
|
2024-05-14 18:42:26 +08:00
|
|
|
|
useDateStr =
|
|
|
|
|
|
"${DateTool().dateToYMDHNString(startDate.toString())}-${DateTool().dateToYMDHNString(endDate.toString())} ${"限时".tr}";
|
2024-01-18 11:25:56 +08:00
|
|
|
|
} else if (keyType == XSConstantMacro.keyTypeLong) {
|
|
|
|
|
|
//永久
|
2024-04-11 17:06:06 +08:00
|
|
|
|
useDateStr = '永久'.tr;
|
2024-01-18 11:25:56 +08:00
|
|
|
|
} else if (keyType == XSConstantMacro.keyTypeOnce) {
|
|
|
|
|
|
//单次
|
2024-04-11 17:06:06 +08:00
|
|
|
|
useDateStr = '单次'.tr;
|
2024-01-18 11:25:56 +08:00
|
|
|
|
} else if (keyType == XSConstantMacro.keyTypeLoop) {
|
|
|
|
|
|
//循环
|
2024-05-14 18:42:26 +08:00
|
|
|
|
useDateStr =
|
|
|
|
|
|
"${DateTool().dateToYMDString(startDate.toString())}-${DateTool().dateToYMDString(endDate.toString())} ${"循环".tr}";
|
2024-01-18 11:25:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
return useDateStr;
|
|
|
|
|
|
}
|
2023-09-28 18:05:23 +08:00
|
|
|
|
|
2024-06-04 16:38:23 +08:00
|
|
|
|
List<String> getUseKeyTypeListStr(
|
|
|
|
|
|
int? startDate, int? endDate, int? keyType) {
|
|
|
|
|
|
final List<String> useDateListStr = <String>[];
|
|
|
|
|
|
if (keyType == XSConstantMacro.keyTypeTime) {
|
|
|
|
|
|
//限期
|
|
|
|
|
|
useDateListStr.addAll(<String>[
|
|
|
|
|
|
DateTool().dateToYMDHNString(startDate.toString()),
|
|
|
|
|
|
DateTool().dateToYMDHNString(endDate.toString()),
|
|
|
|
|
|
'限时'.tr,
|
|
|
|
|
|
]);
|
|
|
|
|
|
} else if (keyType == XSConstantMacro.keyTypeLong) {
|
|
|
|
|
|
//永久
|
|
|
|
|
|
useDateListStr.add('永久'.tr);
|
|
|
|
|
|
} else if (keyType == XSConstantMacro.keyTypeOnce) {
|
|
|
|
|
|
//单次
|
|
|
|
|
|
useDateListStr.add('单次'.tr);
|
|
|
|
|
|
} else if (keyType == XSConstantMacro.keyTypeLoop) {
|
|
|
|
|
|
//循环
|
|
|
|
|
|
useDateListStr.addAll(<String>[
|
|
|
|
|
|
DateTool().dateToYMDString(startDate.toString()),
|
|
|
|
|
|
DateTool().dateToYMDString(endDate.toString()),
|
|
|
|
|
|
'循环'.tr,
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
return useDateListStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-28 18:05:23 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2023-07-29 09:25:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///Extension_Int
|
|
|
|
|
|
extension Extension_Int on int {
|
2023-07-29 18:33:48 +08:00
|
|
|
|
bool get codeIsSuccessful => this == 0;
|
2024-05-14 18:42:26 +08:00
|
|
|
|
|
2023-07-29 09:25:21 +08:00
|
|
|
|
bool get msgCodeIsSuccessful => this == 1;
|
2024-03-12 16:19:04 +08:00
|
|
|
|
}
|