From 0e3add1d6e8243245e355719be82f9569ebb68e4 Mon Sep 17 00:00:00 2001 From: tanlongsheng <252620078@qq.com> Date: Fri, 25 Jul 2025 22:06:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=9A=E8=AE=AE?= =?UTF-8?q?=E5=8A=A9=E6=89=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/meeting_controller.dart | 2 + .../meeting/views/meeting_home_view.dart | 12 +- lib/modules/meeting/views/meeting_view.dart | 170 +++++++++--------- 3 files changed, 95 insertions(+), 89 deletions(-) diff --git a/lib/modules/meeting/controllers/meeting_controller.dart b/lib/modules/meeting/controllers/meeting_controller.dart index 4f7b41e36..f5ead752e 100644 --- a/lib/modules/meeting/controllers/meeting_controller.dart +++ b/lib/modules/meeting/controllers/meeting_controller.dart @@ -15,6 +15,8 @@ class MeetingController extends GetxController { const MeetingMineView(), ]; + int type = 1; + RxInt pageIndex = 0.obs; RxMap user = {}.obs; diff --git a/lib/modules/meeting/views/meeting_home_view.dart b/lib/modules/meeting/views/meeting_home_view.dart index 712078790..9c4d4ee84 100644 --- a/lib/modules/meeting/views/meeting_home_view.dart +++ b/lib/modules/meeting/views/meeting_home_view.dart @@ -87,8 +87,8 @@ class _MeetingHomeViewState extends State vertical: 10.w, ), decoration: BoxDecoration( - color: isDarkMode - ? MeetingUIUtils.getTranslucentWhite(0.05) + color: isDarkMode + ? MeetingUIUtils.getTranslucentWhite(0.05) : MeetingUIUtils.getCardColor(isDarkMode), borderRadius: BorderRadius.circular(12.w), boxShadow: MeetingUIUtils.getCardShadow(isDarkMode), @@ -127,8 +127,8 @@ class _MeetingHomeViewState extends State vertical: 10.w, ), decoration: BoxDecoration( - color: isDarkMode - ? MeetingUIUtils.getTranslucentWhite(0.05) + color: isDarkMode + ? MeetingUIUtils.getTranslucentWhite(0.05) : MeetingUIUtils.getCardColor(isDarkMode), borderRadius: BorderRadius.circular(50.w), boxShadow: MeetingUIUtils.getCardShadow(isDarkMode), @@ -220,8 +220,8 @@ class _MeetingHomeViewState extends State padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 10.w), margin: EdgeInsets.symmetric(vertical: 5.w), decoration: BoxDecoration( - color: isDarkMode - ? MeetingUIUtils.getTranslucentWhite(0.05) + color: isDarkMode + ? MeetingUIUtils.getTranslucentWhite(0.05) : MeetingUIUtils.getCardColor(isDarkMode), borderRadius: BorderRadius.circular(12.w), boxShadow: MeetingUIUtils.getCardShadow(isDarkMode), diff --git a/lib/modules/meeting/views/meeting_view.dart b/lib/modules/meeting/views/meeting_view.dart index 372cf8f24..e433fc38c 100644 --- a/lib/modules/meeting/views/meeting_view.dart +++ b/lib/modules/meeting/views/meeting_view.dart @@ -30,93 +30,97 @@ class MeetingView extends GetView { child: const FiltrateDrawer(), ), drawerEnableOpenDragGesture: false, - bottomNavigationBar: Stack( - alignment: Alignment.center, - clipBehavior: Clip.none, - children: [ - Obx( - () => BottomNavigationBar( - items: const [ - BottomNavigationBarItem( - icon: Icon(Icons.folder_outlined), - activeIcon: Icon(Icons.folder), - label: '文件', - ), - BottomNavigationBarItem( - icon: SizedBox(), - label: '', - ), - BottomNavigationBarItem( - icon: Icon(Icons.person_outline), - activeIcon: Icon(Icons.person), - label: '我的', - ), - ], - backgroundColor: - isDarkMode ? const Color(0xFF1A1A1A) : Colors.white, - currentIndex: controller.pageIndex.value, - unselectedItemColor: Colors.grey, - selectedItemColor: isDarkMode ? Colors.white : Colors.blue, - unselectedFontSize: 10.sp, - selectedFontSize: 10.sp, - onTap: (int index) { - if (index == 1 || index == controller.pageIndex.value) return; - if (index == 0) { - controller.pageIndex.value = 0; - controller.pageController.jumpToPage(0); - } else { - controller.pageIndex.value = 2; - controller.pageController.jumpToPage(1); - } - }, - ), - ), - Positioned( - top: -18.w, - child: GestureDetector( - onTap: () { - Get.bottomSheet( - BackdropFilter( - filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), - child: const NavigationBarBottomSheet(), + bottomNavigationBar: controller.type == 0 + ? Stack( + alignment: Alignment.center, + clipBehavior: Clip.none, + children: [ + Obx( + () => BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.folder_outlined), + activeIcon: Icon(Icons.folder), + label: '文件', + ), + BottomNavigationBarItem( + icon: SizedBox(), + label: '', + ), + BottomNavigationBarItem( + icon: Icon(Icons.person_outline), + activeIcon: Icon(Icons.person), + label: '我的', + ), + ], + backgroundColor: + isDarkMode ? const Color(0xFF1A1A1A) : Colors.white, + currentIndex: controller.pageIndex.value, + unselectedItemColor: Colors.grey, + selectedItemColor: isDarkMode ? Colors.white : Colors.blue, + unselectedFontSize: 10.sp, + selectedFontSize: 10.sp, + onTap: (int index) { + if (index == 1 || index == controller.pageIndex.value) + return; + if (index == 0) { + controller.pageIndex.value = 0; + controller.pageController.jumpToPage(0); + } else { + controller.pageIndex.value = 2; + controller.pageController.jumpToPage(1); + } + }, ), - isScrollControlled: true, - ); - }, - child: Container( - width: 60.w, - height: 60.w, - padding: EdgeInsets.all(5.w), - alignment: Alignment.center, - decoration: BoxDecoration( - color: isDarkMode ? const Color(0xFF1A1A1A) : Colors.white, - borderRadius: BorderRadius.circular(60.w), - boxShadow: [ - BoxShadow( - color: Colors.black - .withValues(alpha: isDarkMode ? 0.3 : 0.1), - blurRadius: 8, - offset: const Offset(0, 2), - ), - ], ), - child: Container( - alignment: Alignment.center, - decoration: BoxDecoration( - color: MeetingUIUtils.getButtonColor(isDarkMode), - borderRadius: BorderRadius.circular(60.w), - ), - child: Icon( - Icons.add, - color: Colors.white, - size: 30.w, + Positioned( + top: -18.w, + child: GestureDetector( + onTap: () { + Get.bottomSheet( + BackdropFilter( + filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), + child: const NavigationBarBottomSheet(), + ), + isScrollControlled: true, + ); + }, + child: Container( + width: 60.w, + height: 60.w, + padding: EdgeInsets.all(5.w), + alignment: Alignment.center, + decoration: BoxDecoration( + color: + isDarkMode ? const Color(0xFF1A1A1A) : Colors.white, + borderRadius: BorderRadius.circular(60.w), + boxShadow: [ + BoxShadow( + color: Colors.black + .withValues(alpha: isDarkMode ? 0.3 : 0.1), + blurRadius: 8, + offset: const Offset(0, 2), + ), + ], + ), + child: Container( + alignment: Alignment.center, + decoration: BoxDecoration( + color: MeetingUIUtils.getButtonColor(isDarkMode), + borderRadius: BorderRadius.circular(60.w), + ), + child: Icon( + Icons.add, + color: Colors.white, + size: 30.w, + ), + ), + ), ), ), - ), - ), - ), - ], - ), + ], + ) + : null, ); } } From c9d649b9c1af36c3a9e71cc4fcb676b5dd765574 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sat, 26 Jul 2025 11:14:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/devices_controller.dart | 43 ++++++++-- .../chat_api/SystemFunctionHandler.swift | 79 +++++++++++++++++++ 2 files changed, 116 insertions(+), 6 deletions(-) diff --git a/lib/modules/devices/controllers/devices_controller.dart b/lib/modules/devices/controllers/devices_controller.dart index ba32f0c98..8dd28c7a8 100644 --- a/lib/modules/devices/controllers/devices_controller.dart +++ b/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 { late final BleManager _bleManager; - late final Map> devices; + + // 修改为响应式变量 + final RxMap> devices = >{}.obs; + + // 或者使用这种方式 + // final Rx>> devices = Rx>>({}); @override void onInit() { super.onInit(); _bleManager = Get.find(); + + // 在初始化时加载设备数据 + _loadDevices(); } - @override - void onClose() { - super.onClose(); + // 加载设备数据 + void _loadDevices() { + devices.clear(); for (var device in User.instance.devices) { - if (!devices.containsKey(device.id)) { + if (!devices.containsKey(device.devicetype)) { devices[device.devicetype] = []; } devices[device.devicetype]!.add(device); } } + @override + void onClose() { + super.onClose(); + // onClose 中不应该修改数据,这里应该是清理资源 + } + void unbindearphone(UserDevice device) async { final response = await Api.unbinddevice({ "id": device.id, }); if (response != null) { - devices[device.devicetype]!.remove(device); + // 响应式更新 + devices[device.devicetype]?.remove(device); + devices.refresh(); // 触发UI更新 + User.instance.removeUserDevice(device.id); _bleManager.clearPairedDevices(); _bleManager.disconnect(); @@ -48,4 +65,18 @@ class DevicesController extends GetxController { return; } } + + // 添加设备 + void addDevice(UserDevice device) { + if (!devices.containsKey(device.devicetype)) { + devices[device.devicetype] = []; + } + devices[device.devicetype]!.add(device); + devices.refresh(); // 触发UI更新 + } + + // 获取指定类型的设备列表 + List getDevicesByType(int deviceType) { + return devices[deviceType] ?? []; + } } diff --git a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift index 6a553d692..a2dc14ec2 100644 --- a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift +++ b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift @@ -4,6 +4,7 @@ import EventKit import CoreLocation import MessageUI import location_service +import user_portrait // 添加这行 /// 结果结构体 public struct Result { @@ -65,6 +66,9 @@ public class SystemFunctionHandler: NSObject { // 注册打开录音机功能 registerOpenRecorderFunction(client: client) + // 注册用户画像更新功能 + registerSetUserProfileFieldFunction(client: client) + } catch { // 静默处理错误 } @@ -720,3 +724,78 @@ private class OpenRecorderHandler: FunctionHandler { // 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)" + )) + } + } + } + } +}