diff --git a/src/pages/pc/ckbox/weChat/components/ChatWindow/components/ProfileCard/components/ProfileModules/index.tsx b/src/pages/pc/ckbox/weChat/components/ChatWindow/components/ProfileCard/components/ProfileModules/index.tsx index 3d36b43..f414478 100644 --- a/src/pages/pc/ckbox/weChat/components/ChatWindow/components/ProfileCard/components/ProfileModules/index.tsx +++ b/src/pages/pc/ckbox/weChat/components/ChatWindow/components/ProfileCard/components/ProfileModules/index.tsx @@ -33,6 +33,7 @@ import TwoColumnMemberSelection from "@/components/MemberSelection/TwoColumnMemb import { FriendSelectionItem } from "@/components/FriendSelection/data"; import DetailValue from "./components/detailValue"; import { getFriendInfo, FriendDetailResponse, updateFriendInfo } from "./api"; +import { getContactList } from "@/pages/pc/ckbox/weChat/api"; import styles from "./Person.module.scss"; interface PersonProps { contract: ContractData | weChatGroup; @@ -748,44 +749,35 @@ const Person: React.FC = ({ contract }) => { const [contactPageSize] = useState(10); const [isLoadingContacts, setIsLoadingContacts] = useState(false); - // 从数据库获取联系人数据的通用函数 + // 从好友列表 API 获取联系人数据的通用函数 const fetchContacts = async (page = 1) => { try { - const { databaseManager, initializeDatabaseFromPersistedUser } = - await import("@/utils/db"); + console.log("📋 [添加群成员] 从 API 获取好友列表:", { + page, + limit: contactPageSize, + wechatAccountId: contract.wechatAccountId, + }); - // 检查数据库初始化状态 - if (!databaseManager.isInitialized()) { - await initializeDatabaseFromPersistedUser(); - } - - // 获取当前用户ID - const userId = (kfSelectedUser as any)?.userId || 0; - const storeUserId = databaseManager.getCurrentUserId(); - const effectiveUserId = storeUserId || userId; - - if (!effectiveUserId) { - messageApi.error("无法获取用户信息,请尝试重新登录"); - return []; - } - - // 查询联系人数据 - const allContacts = await contactUnifiedService.findWhereMultiple([ - { field: "userId", operator: "equals", value: effectiveUserId }, + // 调用好友列表 API 接口 + const result = await getContactList( { - field: "wechatAccountId", - operator: "equals", - value: contract.wechatAccountId, + page, + limit: contactPageSize, + wechatAccountId: contract.wechatAccountId, }, - { field: "type", operator: "equals", value: "friend" }, - ]); + { debounceGap: 0 }, // 禁用防抖 + ); - // 手动分页 - const startIndex = (page - 1) * contactPageSize; - const endIndex = startIndex + contactPageSize; - return allContacts.slice(startIndex, endIndex); + const friendList = result?.list || []; + console.log("✅ [添加群成员] 获取到好友列表:", { + page, + count: friendList.length, + total: result?.total || 0, + }); + + return friendList; } catch (error) { - console.error("获取联系人数据失败:", error); + console.error("❌ [添加群成员] 获取联系人数据失败:", error); messageApi.error("获取联系人数据失败"); return []; }