You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 lines
2.6 KiB

  1. import 'dart:convert';
  2. import 'package:demo001/scenes/login/login_view.dart';
  3. import 'package:demo001/scenes/public.dart';
  4. import 'package:demo001/tools/http_utils.dart';
  5. import 'package:flutter_easyloading/flutter_easyloading.dart';
  6. import 'package:get/get.dart';
  7. import 'package:logger/logger.dart';
  8. import 'package:permission_handler/permission_handler.dart';
  9. import 'home_state.dart';
  10. /// @description:
  11. /// @author
  12. /// @date: 2025-01-07 15:51:34
  13. class HomeLogic extends GetxController {
  14. final state = HomeState();
  15. //1.已连接到的蓝牙,2.失去连接的蓝牙
  16. final String _bluetoothConnectStateKey = "bluetoothConnected";
  17. final String _bluetoothDisConnectStateKey = "bluetoothDisConnect";
  18. //1.已经连接的蓝牙
  19. final String _bluetoothAlreadyConnectKey = "bluetoothAlreadyConnected";
  20. @override
  21. void onInit() {
  22. super.onInit();
  23. _getLoginInfo();
  24. _checkPermission();
  25. _checkConnectDevice();
  26. _checkBluetoothStatus();
  27. }
  28. void _checkPermission() {
  29. Permission.microphone.request();
  30. state.methodChannel.invokeMethod("bluetoothPermissionRequest");
  31. }
  32. void _checkBluetoothStatus() {}
  33. ///获取登录信息
  34. void _getLoginInfo() async {
  35. final info = await getSharedLoginInfo();
  36. if (info != null) {
  37. state.loginModel = info;
  38. _getAliToken();
  39. } else {
  40. EasyLoading.showError('登录过期');
  41. Get.offAll(() => LoginScene());
  42. }
  43. }
  44. void _getAliToken() {
  45. ApiClient.post(
  46. url: '/api/home/auth_alitoken',
  47. token: state.loginModel!.data!.token!,
  48. param: {},
  49. onSuccess: (data) {
  50. // Logger().i('---------_getAliToken--------token-:${data.runtimeType}');
  51. // Logger().i('---------_getAliToken--------token-:${data['data']['token']}');
  52. state.loginModel?.ali_appkey = data['data']['appkey'];
  53. state.loginModel?.ali_token = data['data']['token'];
  54. },
  55. onFailed: (msg) {
  56. Logger().e('-------_getAliToken-------error-$msg');
  57. });
  58. }
  59. ///原生传回的数据监听
  60. void _phoneCallRecordingListenner() {
  61. state.eventChannel.receiveBroadcastStream((data) {});
  62. }
  63. //开始监听蓝牙连接设备状态
  64. void _checkConnectDevice() {
  65. state.methodChannel.invokeMethod('checkConnectedBluetooth');
  66. }
  67. ///通话翻译按钮点击
  68. void startPhoneCallRecording() {
  69. state.methodChannel.invokeMethod('startPhoneCallRecording');
  70. }
  71. ///停止通讯录音
  72. void stopPhoneCallRecording() {
  73. state.methodChannel.invokeMethod('stopPhoneCallRecording');
  74. }
  75. //打开蓝牙扫描界面
  76. void toBonding() {}
  77. ///**************通话录音翻译*************** */
  78. }