refactor(ckbox): 优化消息未读计数逻辑并调整导航栏布局
重构未读消息计数逻辑,使用chatSessions中的unreadCount替代原有的messageCount计算方式 调整导航栏中消息按钮和用户下拉菜单的位置顺序
This commit is contained in:
@@ -11,7 +11,6 @@ import {
|
||||
} from "@ant-design/icons";
|
||||
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
// import { useCkChatStore } from "@/store/module/ckchat/ckchat";
|
||||
import { useNavigate, useLocation } from "react-router-dom";
|
||||
import { drawerMenuData, menuList } from "./index.data";
|
||||
import styles from "./index.module.scss";
|
||||
@@ -32,7 +31,6 @@ const NavCommon: React.FC<NavCommonProps> = ({
|
||||
const [messageCount] = useState(3); // 模拟消息数量
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
// const { userInfo } = useCkChatStore();
|
||||
const { user, logout } = useUserStore();
|
||||
|
||||
// 处理菜单图标点击
|
||||
@@ -169,6 +167,11 @@ const NavCommon: React.FC<NavCommonProps> = ({
|
||||
</span>
|
||||
9307.423
|
||||
</span>
|
||||
<div className={styles.messageButton} onClick={handleMessageClick}>
|
||||
<Badge count={messageCount} size="small">
|
||||
<BellOutlined style={{ fontSize: 20 }} />
|
||||
</Badge>
|
||||
</div>
|
||||
<Dropdown
|
||||
menu={{ items: userMenuItems }}
|
||||
placement="bottomRight"
|
||||
@@ -183,11 +186,6 @@ const NavCommon: React.FC<NavCommonProps> = ({
|
||||
/>
|
||||
</div>
|
||||
</Dropdown>
|
||||
<div className={styles.messageButton} onClick={handleMessageClick}>
|
||||
<Badge count={messageCount} size="small">
|
||||
<BellOutlined style={{ fontSize: 20 }} />
|
||||
</Badge>
|
||||
</div>
|
||||
</Space>
|
||||
</div>
|
||||
</Header>
|
||||
|
||||
@@ -4,20 +4,23 @@ import styles from "./VerticalUserList.module.scss";
|
||||
import { useCkChatStore, asyncKfSelected } from "@/store/module/ckchat/ckchat";
|
||||
|
||||
const VerticalUserList: React.FC = () => {
|
||||
// 格式化消息数量显示
|
||||
const formatMessageCount = (count: number) => {
|
||||
if (count > 99) return "99+";
|
||||
return count.toString();
|
||||
};
|
||||
|
||||
const handleUserSelect = (userId: number) => {
|
||||
asyncKfSelected(userId);
|
||||
};
|
||||
const kfUserList = useCkChatStore(state => state.kfUserList);
|
||||
const kfSelected = useCkChatStore(state => state.kfSelected);
|
||||
const allCount = kfUserList
|
||||
.map(v => v.messageCount || 0)
|
||||
.reduce((pre, cur) => pre + cur, 0);
|
||||
const chatSessions = useCkChatStore(state => state.chatSessions);
|
||||
const getUnreadCount = (wechatAccountId: number) => {
|
||||
if (wechatAccountId != 0) {
|
||||
const session = chatSessions.filter(
|
||||
v => v.wechatAccountId === wechatAccountId,
|
||||
);
|
||||
return session.reduce((pre, cur) => pre + cur.unreadCount, 0);
|
||||
} else {
|
||||
return chatSessions.reduce((pre, cur) => pre + cur.unreadCount, 0);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.verticalUserList}>
|
||||
<div className={styles.userListHeader}>
|
||||
@@ -26,7 +29,7 @@ const VerticalUserList: React.FC = () => {
|
||||
<div className={styles.userList}>
|
||||
<div className={styles.userItem} onClick={() => handleUserSelect(0)}>
|
||||
<Badge
|
||||
count={allCount}
|
||||
count={getUnreadCount(0)}
|
||||
overflowCount={99}
|
||||
className={styles.messageBadge}
|
||||
>
|
||||
@@ -41,9 +44,7 @@ const VerticalUserList: React.FC = () => {
|
||||
onClick={() => handleUserSelect(user.id)}
|
||||
>
|
||||
<Badge
|
||||
count={
|
||||
user.messageCount ? formatMessageCount(user.messageCount) : 0
|
||||
}
|
||||
count={getUnreadCount(user.id)}
|
||||
overflowCount={99}
|
||||
className={styles.messageBadge}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user