163 lines
5.3 KiB
Dart
Executable File
163 lines
5.3 KiB
Dart
Executable File
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/appRouters.dart';
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
|
import 'package:star_lock/mine/mineSet/lockUserManage/expireLockList/expireElectronicKey/expireLockList_entity.dart';
|
|
import 'package:star_lock/mine/mineSet/mineSet/mineSet_state.dart';
|
|
import 'package:star_lock/mine/mineSet/mineSet/userSettingInfoEntity.dart';
|
|
import 'package:star_lock/mine/mineSet/mineSet/weChatQRCodeEntity.dart';
|
|
import 'package:star_lock/tools/showCupertinoAlertView.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
|
import 'package:star_lock/versionUndate/versionUndate_entity.dart';
|
|
import '../../../../network/api_repository.dart';
|
|
import '../../../../tools/baseGetXController.dart';
|
|
import '../../../blue/blue_manage.dart';
|
|
import '../../../talk/udp/udp_help.dart';
|
|
import '../../../tools/eventBusEventManage.dart';
|
|
|
|
class MineSetLogic extends BaseGetXController {
|
|
final MineSetState state = MineSetState();
|
|
//用户信息
|
|
Future<void> userSettingsInfoRequest() async {
|
|
final UserSettingInfoEntity entity =
|
|
await ApiRepository.to.userSettingsInfo();
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.userInfoData.value = entity.data!;
|
|
state.userSetting.value = entity.data!.userSettings!;
|
|
state.lockScreen.value = entity.data!.userSettings!.lockScreen!;
|
|
state.hideExpiredAccessFlag.value =
|
|
entity.data!.userSettings!.hideExpiredAccessFlag!;
|
|
|
|
//提示音
|
|
if (entity.data!.alertMode == 1) {
|
|
state.isPrompTone.value = true;
|
|
} else {
|
|
state.isPrompTone.value = false;
|
|
}
|
|
//触摸开锁
|
|
if (entity.data!.userSettings!.touchUnlockFlag! == 1) {
|
|
state.isTouchUnlock.value = true;
|
|
} else {
|
|
state.isTouchUnlock.value = false;
|
|
}
|
|
//微信公众号推送
|
|
if (entity.data!.mpWechatPushSwitch! == 1) {
|
|
state.isWechatPublicAccountPush.value = true;
|
|
} else {
|
|
state.isWechatPublicAccountPush.value = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
//更新提示音
|
|
Future<void> updatePrompToneRequest() async {
|
|
final ExpireLockListEntity entity = await ApiRepository.to
|
|
.setAlertMode('1', state.isPrompTone.value == true ? '1' : '2');
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr);
|
|
userSettingsInfoRequest();
|
|
}
|
|
}
|
|
|
|
//设置微信公众号推送
|
|
Future<void> setMpWechatPushSwitchRequest(BuildContext widgetContext) async {
|
|
final VersionUndateEntity entity = await ApiRepository.to
|
|
.setMpWechatPushSwitch(
|
|
mpWechatPushSwitch:
|
|
state.isWechatPublicAccountPush.value == true ? 1 : 2);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr);
|
|
userSettingsInfoRequest();
|
|
} else if (entity.errorCode! == 421) {
|
|
if (state.isWechatPublicAccountPush.value == true) {
|
|
//请先扫码绑定微信公众号
|
|
getMpWechatQrCodeRequest(widgetContext);
|
|
}
|
|
}
|
|
}
|
|
|
|
//获取微信公众号二维码
|
|
Future<void> getMpWechatQrCodeRequest(BuildContext widgetContext) async {
|
|
final GetWechatQrCodeEntity entity =
|
|
await ApiRepository.to.getMpWechatQrCode();
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.qrCodeUrl.value = entity.data!.qrCodeUrl!;
|
|
state.qrCodeText.value = entity.data!.mpName ?? '';
|
|
showQRImageAlert(state.qrCodeUrl.value, widgetContext);
|
|
}
|
|
}
|
|
|
|
void showQRImageAlert(String qrCodeUrl, BuildContext widgetContext) {
|
|
ShowCupertinoAlertView()
|
|
.showQRImageAlert(widgetContext, qrCodeUrl, state.qrCodeText.value);
|
|
}
|
|
|
|
//退出登录请求
|
|
Future<void> userLogoutRequest() async {
|
|
var getPushDeviceID = '';
|
|
await Storage.getString(pushDeviceID).then((value) {
|
|
if (value != null && value.isNotEmpty) {
|
|
getPushDeviceID = value;
|
|
}
|
|
});
|
|
LoginEntity entity =
|
|
await ApiRepository.to.userLogout(deviceld: getPushDeviceID);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
UdpHelp().closeUDP();
|
|
logOut();
|
|
BlueManage().disconnect();
|
|
XSJPushProvider().initLocalNotification(isCancelLocalPush: true);
|
|
Get.offNamedUntil(Routers.starLockLoginPage, (route) => false);
|
|
}
|
|
}
|
|
|
|
///退出登录
|
|
void logOut() async {
|
|
Storage.clearAll();
|
|
}
|
|
|
|
//更新触摸开锁
|
|
Future<void> updateTouchUnlockRequest() async {
|
|
ExpireLockListEntity entity = await ApiRepository.to
|
|
.setTouchUnlockFlag(state.isTouchUnlock.value == true ? '1' : '2');
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr);
|
|
userSettingsInfoRequest();
|
|
}
|
|
}
|
|
|
|
// 下级界面修改成功后传递数据
|
|
StreamSubscription? _getNumberEvent;
|
|
void _initLoadDataAction() {
|
|
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
|
_getNumberEvent =
|
|
eventBus.on<ChangeLanguageBlockLastLanguageEvent>().listen((event) {
|
|
state.currentLanguage.value = event.languageTitle;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
// TODO: implement onReady
|
|
super.onReady();
|
|
|
|
_initLoadDataAction();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
// TODO: implement onInit
|
|
super.onInit();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
// TODO: implement onClose
|
|
super.onClose();
|
|
|
|
_getNumberEvent!.cancel();
|
|
}
|
|
}
|