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 '../main/lockMian/lockMain/lockMain_logic.dart'; import 'NativeInteractionTool.dart'; import 'commonDataManage.dart'; import 'dateTool.dart'; import 'manager/client_manager.dart'; import 'showIosTipView.dart'; class BaseGetXController extends GetxController { int currentTimeSeconds = 0; bool currentPage = true; int pageNo = 1; String pageSize = '20'; @override void onReady() { super.onReady(); currentPage = true; } @override InternalFinalCallback get onDelete => super.onDelete; @override InternalFinalCallback get onStart => super.onStart; @override void onInit() { super.onInit(); } @override void 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 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() { showToast( "${'操作失败,请确认锁是否在附近,或重启手机蓝牙后再试。'.tr}${CommonDataManage().currentKeyInfo.lockFeature?.isNoSupportedBlueBroadcast == 1 ? "如果是全自动锁,请使屏幕变亮".tr : ""}"); } 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 ?? '成功'.tr, something: something); void showOperationFailed({String? status, Function? something}) => showError(status ?? '失败'.tr, 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: '提示'.tr, tipTitle: '蓝牙未打开,请到设置里面打开蓝牙'.tr, 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) { //永久 useDateStr = '永久'.tr; } else if (keyType == XSConstantMacro.keyTypeOnce) { //单次 useDateStr = '单次'.tr; } else if (keyType == XSConstantMacro.keyTypeLoop) { //循环 useDateStr = "${DateTool().dateToYMDString(startDate.toString())}-${DateTool().dateToYMDString(endDate.toString())} ${"循环".tr}"; } return useDateStr; } List getUseKeyTypeListStr( int? startDate, int? endDate, int? keyType) { final List useDateListStr = []; if (keyType == XSConstantMacro.keyTypeTime) { //限期 useDateListStr.addAll([ 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([ DateTool().dateToYMDString(startDate.toString()), DateTool().dateToYMDString(endDate.toString()), '循环'.tr, ]); } return useDateListStr; } 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; }