Browse Source

Merge branch 'new_dev' of https://github.com/deepcloud2048/deep_voice into new_dev

weicu
lxm 1 year ago
parent
commit
f563de5bb4
  1. 43
      lib/modules/devices/controllers/devices_controller.dart
  2. 2
      lib/modules/meeting/controllers/meeting_controller.dart
  3. 12
      lib/modules/meeting/views/meeting_view.dart
  4. 79
      local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift

43
lib/modules/devices/controllers/devices_controller.dart

@ -14,31 +14,48 @@ import 'package:get/get_state_manager/src/simple/get_controllers.dart';
*/ */
class DevicesController extends GetxController { class DevicesController extends GetxController {
late final BleManager _bleManager; late final BleManager _bleManager;
late final Map<int, List<UserDevice>> devices;
// 修改为响应式变量
final RxMap<int, List<UserDevice>> devices = <int, List<UserDevice>>{}.obs;
// 或者使用这种方式
// final Rx<Map<int, List<UserDevice>>> devices = Rx<Map<int, List<UserDevice>>>({});
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
_bleManager = Get.find<BleManager>(); _bleManager = Get.find<BleManager>();
// 在初始化时加载设备数据
_loadDevices();
} }
@override // 加载设备数据
void onClose() { void _loadDevices() {
super.onClose(); devices.clear();
for (var device in User.instance.devices) { for (var device in User.instance.devices) {
if (!devices.containsKey(device.id)) { if (!devices.containsKey(device.devicetype)) {
devices[device.devicetype] = []; devices[device.devicetype] = [];
} }
devices[device.devicetype]!.add(device); devices[device.devicetype]!.add(device);
} }
} }
@override
void onClose() {
super.onClose();
// onClose 中不应该修改数据,这里应该是清理资源
}
void unbindearphone(UserDevice device) async { void unbindearphone(UserDevice device) async {
final response = await Api.unbinddevice({ final response = await Api.unbinddevice({
"id": device.id, "id": device.id,
}); });
if (response != null) { if (response != null) {
devices[device.devicetype]!.remove(device); // 响应式更新
devices[device.devicetype]?.remove(device);
devices.refresh(); // 触发UI更新
User.instance.removeUserDevice(device.id); User.instance.removeUserDevice(device.id);
_bleManager.clearPairedDevices(); _bleManager.clearPairedDevices();
_bleManager.disconnect(); _bleManager.disconnect();
@ -48,4 +65,18 @@ class DevicesController extends GetxController {
return; return;
} }
} }
// 添加设备
void addDevice(UserDevice device) {
if (!devices.containsKey(device.devicetype)) {
devices[device.devicetype] = [];
}
devices[device.devicetype]!.add(device);
devices.refresh(); // 触发UI更新
}
// 获取指定类型的设备列表
List<UserDevice> getDevicesByType(int deviceType) {
return devices[deviceType] ?? [];
}
} }

2
lib/modules/meeting/controllers/meeting_controller.dart

@ -15,6 +15,8 @@ class MeetingController extends GetxController {
const MeetingMineView(), const MeetingMineView(),
]; ];
int type = 1;
RxInt pageIndex = 0.obs; RxInt pageIndex = 0.obs;
RxMap user = {}.obs; RxMap user = {}.obs;

12
lib/modules/meeting/views/meeting_view.dart

@ -30,7 +30,8 @@ class MeetingView extends GetView<MeetingController> {
child: const FiltrateDrawer(), child: const FiltrateDrawer(),
), ),
drawerEnableOpenDragGesture: false, drawerEnableOpenDragGesture: false,
bottomNavigationBar: Stack( bottomNavigationBar: controller.type == 0
? Stack(
alignment: Alignment.center, alignment: Alignment.center,
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
@ -60,7 +61,8 @@ class MeetingView extends GetView<MeetingController> {
unselectedFontSize: 10.sp, unselectedFontSize: 10.sp,
selectedFontSize: 10.sp, selectedFontSize: 10.sp,
onTap: (int index) { onTap: (int index) {
if (index == 1 || index == controller.pageIndex.value) return; if (index == 1 || index == controller.pageIndex.value)
return;
if (index == 0) { if (index == 0) {
controller.pageIndex.value = 0; controller.pageIndex.value = 0;
controller.pageController.jumpToPage(0); controller.pageController.jumpToPage(0);
@ -89,7 +91,8 @@ class MeetingView extends GetView<MeetingController> {
padding: EdgeInsets.all(5.w), padding: EdgeInsets.all(5.w),
alignment: Alignment.center, alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
color: isDarkMode ? const Color(0xFF1A1A1A) : Colors.white, color:
isDarkMode ? const Color(0xFF1A1A1A) : Colors.white,
borderRadius: BorderRadius.circular(60.w), borderRadius: BorderRadius.circular(60.w),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
@ -116,7 +119,8 @@ class MeetingView extends GetView<MeetingController> {
), ),
), ),
], ],
), )
: null,
); );
} }
} }

79
local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift

@ -4,6 +4,7 @@ import EventKit
import CoreLocation import CoreLocation
import MessageUI import MessageUI
import location_service import location_service
import user_portrait // 添加这行
/// 结果结构体 /// 结果结构体
public struct Result { public struct Result {
@ -65,6 +66,9 @@ public class SystemFunctionHandler: NSObject {
// 注册打开录音机功能 // 注册打开录音机功能
registerOpenRecorderFunction(client: client) registerOpenRecorderFunction(client: client)
// 注册用户画像更新功能
registerSetUserProfileFieldFunction(client: client)
} catch { } catch {
// 静默处理错误 // 静默处理错误
} }
@ -720,3 +724,78 @@ private class OpenRecorderHandler: FunctionHandler {
// private enum LocationError: Error { // private enum LocationError: Error {
// ... // ...
// } // }
/// 注册设置用户画像字段函数
private func registerSetUserProfileFieldFunction(client: MCPClient) {
let parameters: [String: Any] = [
"type": "object",
"properties": [
"key": [
"type": "string",
"description": "画像字段名,例如:age、tone、工作经历、device_preference"
],
"value": [
"type": "string",
"description": "字段对应的值"
]
],
"required": ["key", "value"]
]
let handler = SetUserProfileFieldHandler()
_ = client.registerLocalFunction(
name: "set_user_profile_field",
description: "设置或更新用户画像中的某一个字段",
parameters: parameters,
handler: handler
)
}
/// 设置用户画像字段处理器
private class SetUserProfileFieldHandler: FunctionHandler {
func handle(arguments: [String: Any]) async throws -> String {
guard let key = arguments["key"] as? String,
let value = arguments["value"] as? String else {
throw ChatApiException("缺少必要参数:key 和 value")
}
// 验证参数
if key.isEmpty {
throw ChatApiException("画像字段名不能为空")
}
if value.isEmpty {
throw ChatApiException("字段值不能为空")
}
let result = await setUserProfileField(key: key, value: value)
return "{\"result\": \"\(result.message)\", \"key\": \"\(key)\", \"value\": \"\(value)\"}\"}"
}
private func setUserProfileField(key: String, value: String) async -> Result {
return await withCheckedContinuation { continuation in
DispatchQueue.main.async {
do {
// 使用 UserPortrait 单例设置画像字段
UserPortrait.shared.set(key: key, value: value)
// 发送通知给其他模块
UserPortrait.shared.sendUpdateNotification(key: key, value: value)
print("[SetUserProfileFieldHandler] 成功设置用户画像字段: \(key) = \(value)")
continuation.resume(returning: Result(
success: true,
message: "成功设置用户画像字段 \(key) 为 \(value)"
))
} catch {
print("[SetUserProfileFieldHandler] 设置用户画像字段失败: \(error.localizedDescription)")
continuation.resume(returning: Result(
success: false,
message: "设置用户画像字段失败:\(error.localizedDescription)"
))
}
}
}
}
}

Loading…
Cancel
Save