117 lines
3.7 KiB
Dart
Executable File
117 lines
3.7 KiB
Dart
Executable File
import 'dart:async';
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/app_settings/app_settings.dart';
|
|
import 'package:star_lock/main/lockMian/lockMain/lockMain_page.dart';
|
|
import 'package:star_lock/main/lockMian/lockMain/xhj/lockMain_xhj_state.dart';
|
|
import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_entity.dart';
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
import 'package:star_lock/talk/startChart/start_chart_manage.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
import 'package:star_lock/tools/push/xs_jPhush.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
|
|
import '../../../../tools/store_service.dart';
|
|
|
|
class LockMainXHJLogic extends BaseGetXController {
|
|
final LockMainXHJState state = LockMainXHJState();
|
|
|
|
void setIndex(int index) {
|
|
state.index = index;
|
|
update();
|
|
}
|
|
|
|
bool get isMall => state.index == 1;
|
|
|
|
//用户信息
|
|
Future<void> getUserInfoRequest() async {
|
|
final MinePersonInfoEntity entity = await ApiRepository.to.getUserInfo();
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
final String languageCodeAndCountryCode = entity.data!.lang!;
|
|
if (languageCodeAndCountryCode.isEmpty) {
|
|
await StoreService.to.saveLanguageCode('');
|
|
await Get.updateLocale(Get.deviceLocale!);
|
|
} else if (languageCodeAndCountryCode.contains('-')) {
|
|
final List<String> parts = languageCodeAndCountryCode.split('-');
|
|
final Locale locale = Locale(parts[0], parts[1]);
|
|
await Get.updateLocale(locale);
|
|
await StoreService.to.saveLanguageCode(locale.toString());
|
|
} else if (languageCodeAndCountryCode.contains('_')) {
|
|
final List<String> parts = languageCodeAndCountryCode.split('_');
|
|
final Locale locale = Locale(parts[0], parts[1]);
|
|
await Get.updateLocale(locale);
|
|
AppLog.log('用户信息请求成功 更新locale: $locale');
|
|
await StoreService.to.saveLanguageCode(locale.toString());
|
|
}
|
|
|
|
Storage.setBool(saveIsVip, entity.data!.isVip == 1);
|
|
if (entity.data!.deviceId != null) {
|
|
if (entity.data!.deviceId!.isEmpty) {
|
|
bindPushDevice();
|
|
}
|
|
}
|
|
if (entity.data!.starchart != null) {
|
|
if (entity.data!.starchart!.starchartId!.isEmpty) {
|
|
bindStarChart();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//打开设备弹窗
|
|
void openEquipment() {
|
|
showModalBottomSheet(
|
|
context: Get.context!,
|
|
isScrollControlled: true,
|
|
backgroundColor: Colors.white,
|
|
builder: (context) {
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(16.r),
|
|
topRight: Radius.circular(16.r),
|
|
),
|
|
child: SizedBox(
|
|
height: Get.height * 0.7,
|
|
child: StarLockMainPage(
|
|
showAppBar: false,
|
|
showDrawer: false,
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
Future<void> bindPushDevice() async {
|
|
// 初始化JPush服务并绑定设备ID
|
|
final XSJPushProvider jpushProvider = XSJPushProvider();
|
|
await jpushProvider.initJPushService();
|
|
await jpushProvider.initLocalNotification(isCancelLocalPush: false);
|
|
}
|
|
|
|
//绑定星图
|
|
Future<void> bindStarChart() async {
|
|
//初始化星图服务并绑定配置
|
|
await StartChartManage().init();
|
|
}
|
|
|
|
@override
|
|
Future<void> onReady() async {
|
|
super.onReady();
|
|
|
|
bindPushDevice();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
getUserInfoRequest();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
}
|
|
}
|