231 lines
6.6 KiB
Dart
Executable File
231 lines
6.6 KiB
Dart
Executable File
import 'dart:async';
|
||
import 'dart:io';
|
||
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:star_lock/appRouters.dart';
|
||
import 'package:star_lock/app_settings/app_settings.dart';
|
||
import 'package:star_lock/blue/blue_manage.dart';
|
||
import 'package:system_settings/system_settings.dart';
|
||
import 'package:url_launcher/url_launcher.dart';
|
||
|
||
import '../common/XSConstantMacro/XSConstantMacro.dart';
|
||
import 'NativeInteractionTool.dart';
|
||
import 'dateTool.dart';
|
||
import 'manager/client_manager.dart';
|
||
import 'showIosTipView.dart';
|
||
|
||
class BaseGetXController extends GetxController {
|
||
int currentTimeSeconds = 0;
|
||
|
||
bool currentPage = true;
|
||
var pageNo = 1;
|
||
var pageSize = "20";
|
||
|
||
@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;
|
||
}
|
||
|
||
Future delay({Duration? duration, Function? something}) => Future.delayed(
|
||
duration ?? 500.milliseconds, something as FutureOr Function()?);
|
||
|
||
void showEasyLoading() => EasyLoading.show();
|
||
|
||
void dismissEasyLoading() {
|
||
if (EasyLoading.isShow) EasyLoading.dismiss();
|
||
}
|
||
|
||
void showTitleEasyLoading(String showContent) =>
|
||
EasyLoading.show(status: showContent);
|
||
|
||
Timer? _timer;
|
||
|
||
// CancelableOperation? _operation;
|
||
void showBlueConnetctToastTimer(
|
||
{bool isShowBlueConnetctToast = true,
|
||
int outTimer = 15,
|
||
Function? action}) {
|
||
if (_timer != null && _timer!.isActive) {
|
||
_timer!.cancel();
|
||
_timer = null;
|
||
}
|
||
_timer = Timer.periodic(outTimer.seconds, (timer) {
|
||
if (action != null) {
|
||
action();
|
||
}
|
||
cancelBlueConnetctToastTimer();
|
||
if (isShowBlueConnetctToast == true) {
|
||
showBlueConnetctToast();
|
||
}
|
||
});
|
||
}
|
||
|
||
void cancelBlueConnetctToastTimer() {
|
||
// AppLog.log('超过15秒未响应,APP主动关菊花断开连接');
|
||
if (_timer != null && _timer!.isActive) {
|
||
_timer!.cancel();
|
||
_timer = null;
|
||
}
|
||
}
|
||
|
||
void showBlueConnetctToast() {
|
||
bool isContains = BlueManage().connectDeviceName.contains("T9A");
|
||
showToast(
|
||
"${'操作失败,请确认锁是否在附近,或重启手机蓝牙后再试。'.tr}${isContains == true ? "如果是全自动锁,请使屏幕变亮" : ""}");
|
||
}
|
||
|
||
void showToast(String status,
|
||
{Function? something,
|
||
EasyLoadingMaskType maskType = EasyLoadingMaskType.none}) {
|
||
EasyLoading.showToast(status,
|
||
duration: 2000.milliseconds, maskType: maskType);
|
||
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);
|
||
}
|
||
|
||
void checkBlueIsOpen(void Function() action) {
|
||
NativeInteractionTool().sendGetBlueStatus();
|
||
NativeInteractionTool().receiveChannelBlueIsOnEvent((String status) {
|
||
if (status == "1") {
|
||
// 蓝牙已打开
|
||
AppLog.log('蓝牙已打开');
|
||
action();
|
||
} else if (status == "0") {
|
||
// 蓝牙未打开
|
||
AppLog.log('蓝牙未打开');
|
||
showIosTipViewDialog();
|
||
return;
|
||
} else {
|
||
// 蓝牙未打开
|
||
AppLog.log('设备不支持蓝牙');
|
||
showToast("设备不支持蓝牙");
|
||
return;
|
||
}
|
||
});
|
||
}
|
||
|
||
void showIosTipViewDialog() {
|
||
showDialog(
|
||
context: Get.context!,
|
||
builder: (BuildContext context) {
|
||
return ShowIosTipView(
|
||
title: "提示",
|
||
tipTitle: "蓝牙未打开,请到设置里面打开蓝牙",
|
||
sureClick: () {
|
||
Get.back();
|
||
if (Platform.isIOS) {
|
||
launch('App-Prefs:');
|
||
} else {
|
||
SystemSettings.system();
|
||
}
|
||
},
|
||
cancelClick: () {
|
||
Get.back();
|
||
},
|
||
);
|
||
});
|
||
}
|
||
|
||
String getUseKeyTypeStr(int? startDate, int? endDate, int? keyType) {
|
||
String useDateStr = '';
|
||
if (keyType == XSConstantMacro.keyTypeTime) {
|
||
//限期
|
||
useDateStr =
|
||
"${DateTool().dateToYMDHNString(startDate.toString())}-${DateTool().dateToYMDHNString(endDate.toString())} ${"限时".tr}";
|
||
} else if (keyType == XSConstantMacro.keyTypeLong) {
|
||
//永久
|
||
// DateTime dateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.date!);
|
||
// useDateStr = '${dateStr.toLocal().toString().substring(0, 16)}\n永久';
|
||
useDateStr = '永久'.tr;
|
||
} else if (keyType == XSConstantMacro.keyTypeOnce) {
|
||
//单次
|
||
// DateTime dateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.date!);
|
||
// useDateStr = '${dateStr.toLocal().toString().substring(0, 16)} \n单次';
|
||
useDateStr = '单次'.tr;
|
||
} else if (keyType == XSConstantMacro.keyTypeLoop) {
|
||
//循环
|
||
useDateStr =
|
||
"${DateTool().dateToYMDString(startDate.toString())}-${DateTool().dateToYMDString(endDate.toString())} ${"循环".tr}";
|
||
}
|
||
|
||
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;
|
||
}
|