refactor(ckbox): 移除全局profile状态并移至ChatWindow组件

将profile显示状态从父组件移至ChatWindow组件内部管理,简化组件间通信
This commit is contained in:
超级老白兔
2025-09-05 17:04:34 +08:00
parent ae1ef52113
commit c4ba459b20
2 changed files with 19 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import { Layout, Button, Avatar, Space, Dropdown, Menu, Tooltip } from "antd";
import {
PhoneOutlined,
@@ -6,6 +6,7 @@ import {
MoreOutlined,
UserOutlined,
TeamOutlined,
InfoCircleOutlined,
} from "@ant-design/icons";
import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
import styles from "./ChatWindow.module.scss";
@@ -18,15 +19,13 @@ const { Header, Content } = Layout;
interface ChatWindowProps {
contract: ContractData | weChatGroup;
showProfile?: boolean;
onToggleProfile?: () => void;
}
const ChatWindow: React.FC<ChatWindowProps> = ({
contract,
showProfile = true,
onToggleProfile,
}) => {
const ChatWindow: React.FC<ChatWindowProps> = ({ contract }) => {
const [showProfile, setShowProfile] = useState(true);
const onToggleProfile = () => {
setShowProfile(!showProfile);
};
const chatMenu = (
<Menu>
<Menu.Item key="profile" icon={<UserOutlined />}>
@@ -76,6 +75,7 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
className={styles.headerButton}
/>
</Tooltip>
<Tooltip title="视频通话">
<Button
type="text"
@@ -83,6 +83,14 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
className={styles.headerButton}
/>
</Tooltip>
<Tooltip title="个人资料">
<Button
onClick={onToggleProfile}
type="text"
icon={<InfoCircleOutlined />}
className={styles.headerButton}
/>
</Tooltip>
<Dropdown overlay={chatMenu} trigger={["click"]}>
<Button
type="text"

View File

@@ -18,7 +18,6 @@ import { KfUserListData } from "@/pages/pc/ckbox/data";
const CkboxPage: React.FC = () => {
// 不要在组件初始化时获取sendCommand而是在需要时动态获取
const [loading, setLoading] = useState(false);
const [showProfile, setShowProfile] = useState(true);
const currentContract = useWeChatStore(state => state.currentContract);
useEffect(() => {
// 方法一:使用 Promise 链式调用处理异步函数
@@ -72,7 +71,7 @@ const CkboxPage: React.FC = () => {
<Content className={styles.mainContent}>
{currentContract ? (
<div className={styles.chatContainer}>
<div className={styles.chatToolbar}>
{/* <div className={styles.chatToolbar}>
<Space>
<Tooltip title={showProfile ? "隐藏资料" : "显示资料"}>
<Button
@@ -85,12 +84,8 @@ const CkboxPage: React.FC = () => {
</Button>
</Tooltip>
</Space>
</div>
<ChatWindow
contract={currentContract}
showProfile={showProfile}
onToggleProfile={() => setShowProfile(!showProfile)}
/>
</div> */}
<ChatWindow contract={currentContract} />
</div>
) : (
<div className={styles.welcomeScreen}>