Merge branch 'yongpxu-dev' into develop
This commit is contained in:
@@ -33,25 +33,6 @@
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
margin: 8px 0;
|
margin: 8px 0;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
&::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
height: 1px;
|
|
||||||
background: #e8e8e8;
|
|
||||||
z-index: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
&::after {
|
|
||||||
content: attr(data-time);
|
|
||||||
background: #f5f5f5;
|
|
||||||
padding: 0 12px;
|
|
||||||
position: relative;
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 消息项
|
// 消息项
|
||||||
@@ -235,4 +216,4 @@
|
|||||||
max-width: 150px;
|
max-width: 150px;
|
||||||
max-height: 150px;
|
max-height: 150px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useRef } from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
import { Avatar } from "antd";
|
import { Avatar, Divider } from "antd";
|
||||||
import { UserOutlined } from "@ant-design/icons";
|
import { UserOutlined } from "@ant-design/icons";
|
||||||
import { ChatRecord, ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
|
import { ChatRecord, ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
|
||||||
import { formatWechatTime } from "@/utils/common";
|
import { formatWechatTime } from "@/utils/common";
|
||||||
@@ -18,7 +18,6 @@ const MessageRecord: React.FC<MessageRecordProps> = ({ contract }) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(currentMessages);
|
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
}, [currentMessages]);
|
}, [currentMessages]);
|
||||||
|
|
||||||
@@ -195,7 +194,9 @@ const MessageRecord: React.FC<MessageRecordProps> = ({ contract }) => {
|
|||||||
<div className={styles.messagesContainer}>
|
<div className={styles.messagesContainer}>
|
||||||
{groupMessagesByTime(currentMessages).map((group, groupIndex) => (
|
{groupMessagesByTime(currentMessages).map((group, groupIndex) => (
|
||||||
<React.Fragment key={`group-${groupIndex}`}>
|
<React.Fragment key={`group-${groupIndex}`}>
|
||||||
<div className={styles.messageTime}>{group.time}</div>
|
<Divider>
|
||||||
|
<div className={styles.messageTime}>{group.time}</div>
|
||||||
|
</Divider>
|
||||||
{group.messages.map(renderMessage)}
|
{group.messages.map(renderMessage)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ interface MessageListProps {}
|
|||||||
|
|
||||||
const MessageList: React.FC<MessageListProps> = () => {
|
const MessageList: React.FC<MessageListProps> = () => {
|
||||||
const { setCurrentContact, currentContract } = useWeChatStore();
|
const { setCurrentContact, currentContract } = useWeChatStore();
|
||||||
const chatSessions = useCkChatStore(state => state.chatSessions);
|
const chatSessions = useCkChatStore(state => state.getChatSessions());
|
||||||
const onContactClick = (session: ContractData | weChatGroup) => {
|
const onContactClick = (session: ContractData | weChatGroup) => {
|
||||||
setCurrentContact(session, true);
|
setCurrentContact(session, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.messageList}>
|
<div className={styles.messageList}>
|
||||||
<List
|
<List
|
||||||
|
|||||||
@@ -115,16 +115,19 @@ export interface weChatGroup {
|
|||||||
config?: {
|
config?: {
|
||||||
chat: boolean;
|
chat: boolean;
|
||||||
};
|
};
|
||||||
labels: string[];
|
labels?: string[];
|
||||||
unreadCount: number;
|
unreadCount: number;
|
||||||
notice: string;
|
notice: string;
|
||||||
selfDisplyName: string;
|
selfDisplyName: string;
|
||||||
|
wechatChatroomId: number;
|
||||||
|
serverId?: number;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 联系人数据接口
|
// 联系人数据接口
|
||||||
export interface ContractData {
|
export interface ContractData {
|
||||||
id?: number;
|
id?: number;
|
||||||
|
serverId?: number;
|
||||||
wechatAccountId: number;
|
wechatAccountId: number;
|
||||||
wechatId: string;
|
wechatId: string;
|
||||||
alias: string;
|
alias: string;
|
||||||
|
|||||||
@@ -233,6 +233,13 @@ export const getUniqueWechatAccountIds = (
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 遍历联系人列表,将每个wechatAccountId添加到Set中
|
||||||
|
groupList.forEach(group => {
|
||||||
|
if (group && group.wechatAccountId) {
|
||||||
|
uniqueAccountIdsSet.add(group.wechatAccountId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 将Set转换为数组并返回
|
// 将Set转换为数组并返回
|
||||||
return Array.from(uniqueAccountIdsSet);
|
return Array.from(uniqueAccountIdsSet);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
KfUserListData,
|
KfUserListData,
|
||||||
ContactGroupByLabel,
|
ContactGroupByLabel,
|
||||||
} from "@/pages/pc/ckbox/data";
|
} from "@/pages/pc/ckbox/data";
|
||||||
import { kfUserService, weChatGroupService, contractService } from "@/utils/db";
|
import { weChatGroupService, contractService } from "@/utils/db";
|
||||||
import { createContractList } from "@/store/module/ckchat/api";
|
import { createContractList } from "@/store/module/ckchat/api";
|
||||||
|
|
||||||
export const useCkChatStore = createPersistStore<CkChatState>(
|
export const useCkChatStore = createPersistStore<CkChatState>(
|
||||||
@@ -362,7 +362,6 @@ export const useCkChatStore = createPersistStore<CkChatState>(
|
|||||||
})(),
|
})(),
|
||||||
// 添加聊天会话
|
// 添加聊天会话
|
||||||
addChatSession: (session: ContractData | weChatGroup) => {
|
addChatSession: (session: ContractData | weChatGroup) => {
|
||||||
session.unreadCount = 0;
|
|
||||||
set(state => {
|
set(state => {
|
||||||
// 检查是否已存在相同id的会话
|
// 检查是否已存在相同id的会话
|
||||||
const exists = state.chatSessions.some(item => item.id === session.id);
|
const exists = state.chatSessions.some(item => item.id === session.id);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
import { WeChatState } from "./weChat.data";
|
import { WeChatState } from "./weChat.data";
|
||||||
import { clearUnreadCount, updateConfig } from "@/pages/pc/ckbox/api";
|
import { clearUnreadCount, updateConfig } from "@/pages/pc/ckbox/api";
|
||||||
import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
|
import { ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
|
||||||
|
import { weChatGroupService, contractService } from "@/utils/db";
|
||||||
import {
|
import {
|
||||||
addChatSession,
|
addChatSession,
|
||||||
updateChatSession,
|
updateChatSession,
|
||||||
@@ -87,22 +88,14 @@ export const useWeChatStore = create<WeChatState>()(
|
|||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
receivedMsg: message => {
|
receivedMsg: async message => {
|
||||||
const currentContract = useWeChatStore.getState().currentContract;
|
const currentContract = useWeChatStore.getState().currentContract;
|
||||||
//判断群还是好友
|
//判断群还是好友
|
||||||
const getMessageId =
|
const getMessageId =
|
||||||
currentContract?.chatroomId || message.wechatFriendId;
|
message?.wechatChatroomId || message.wechatFriendId;
|
||||||
const isGroup = currentContract?.chatroomId;
|
const isWechatGroup = message?.wechatChatroomId;
|
||||||
|
//当前选中聊天的群或好友
|
||||||
if (
|
if (currentContract && currentContract.id == getMessageId) {
|
||||||
currentContract &&
|
|
||||||
currentContract.wechatAccountId == message.wechatAccountId &&
|
|
||||||
currentContract.id == getMessageId
|
|
||||||
) {
|
|
||||||
console.log("进入");
|
|
||||||
if (isGroup) {
|
|
||||||
message.unreadCount = 1;
|
|
||||||
}
|
|
||||||
set(state => ({
|
set(state => ({
|
||||||
currentMessages: [...state.currentMessages, message],
|
currentMessages: [...state.currentMessages, message],
|
||||||
}));
|
}));
|
||||||
@@ -113,6 +106,22 @@ export const useWeChatStore = create<WeChatState>()(
|
|||||||
if (session) {
|
if (session) {
|
||||||
session.unreadCount = Number(session.unreadCount) + 1;
|
session.unreadCount = Number(session.unreadCount) + 1;
|
||||||
updateChatSession(session);
|
updateChatSession(session);
|
||||||
|
} else {
|
||||||
|
if (isWechatGroup) {
|
||||||
|
const [group] = await weChatGroupService.findByIds(getMessageId);
|
||||||
|
if (group) {
|
||||||
|
addChatSession({
|
||||||
|
...group,
|
||||||
|
unreadCount: 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const [user] = await contractService.findByIds(getMessageId);
|
||||||
|
addChatSession({
|
||||||
|
...user,
|
||||||
|
unreadCount: 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -39,16 +39,6 @@ export interface KfUserWithServerId extends Omit<KfUserListData, "id"> {
|
|||||||
id?: number; // 接口数据的原始ID字段
|
id?: number; // 接口数据的原始ID字段
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface weChatGroupServerId extends Omit<weChatGroup, "id"> {
|
|
||||||
serverId: number | string; // 服务器ID作为主键
|
|
||||||
id?: number; // 接口数据的原始ID字段
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ContractWithServerId extends Omit<ContractData, "id"> {
|
|
||||||
serverId: number | string; // 服务器ID作为主键
|
|
||||||
id?: number; // 接口数据的原始ID字段
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新联系人列表数据接口
|
// 新联系人列表数据接口
|
||||||
export interface NewContactListData {
|
export interface NewContactListData {
|
||||||
serverId: number | string; // 服务器ID作为主键
|
serverId: number | string; // 服务器ID作为主键
|
||||||
@@ -61,8 +51,8 @@ export interface NewContactListData {
|
|||||||
// 数据库类
|
// 数据库类
|
||||||
class CunkebaoDatabase extends Dexie {
|
class CunkebaoDatabase extends Dexie {
|
||||||
kfUsers!: Table<KfUserWithServerId>;
|
kfUsers!: Table<KfUserWithServerId>;
|
||||||
weChatGroup!: Table<weChatGroupServerId>;
|
weChatGroup!: Table<weChatGroup>;
|
||||||
contracts!: Table<ContractWithServerId>;
|
contracts!: Table<ContractData>;
|
||||||
newContractList!: Table<NewContactListData>;
|
newContractList!: Table<NewContactListData>;
|
||||||
messageList!: Table<MessageListData>;
|
messageList!: Table<MessageListData>;
|
||||||
|
|
||||||
@@ -74,7 +64,7 @@ class CunkebaoDatabase extends Dexie {
|
|||||||
kfUsers:
|
kfUsers:
|
||||||
"serverId, id, tenantId, wechatId, nickname, alias, avatar, gender, region, signature, bindQQ, bindEmail, bindMobile, createTime, currentDeviceId, isDeleted, deleteTime, groupId, memo, wechatVersion, lastUpdateTime, isOnline",
|
"serverId, id, tenantId, wechatId, nickname, alias, avatar, gender, region, signature, bindQQ, bindEmail, bindMobile, createTime, currentDeviceId, isDeleted, deleteTime, groupId, memo, wechatVersion, lastUpdateTime, isOnline",
|
||||||
weChatGroup:
|
weChatGroup:
|
||||||
"serverId, id, wechatAccountId, tenantId, accountId, chatroomId, chatroomOwner, conRemark, nickname, chatroomAvatar, groupId, config, unreadCount, notice, selfDisplyName",
|
"serverId, id, wechatAccountId, tenantId, accountId, chatroomId, chatroomOwner, conRemark, nickname, chatroomAvatar,wechatChatroomId, groupId, config, unreadCount, notice, selfDisplyName",
|
||||||
contracts:
|
contracts:
|
||||||
"serverId, id, wechatAccountId, wechatId, alias, conRemark, nickname, quanPin, avatar, gender, region, addFrom, phone, signature, accountId, extendFields, city, lastUpdateTime, isPassed, tenantId, groupId, thirdParty, additionalPicture, desc, config, lastMessageTime, unreadCount, duplicate",
|
"serverId, id, wechatAccountId, wechatId, alias, conRemark, nickname, quanPin, avatar, gender, region, addFrom, phone, signature, accountId, extendFields, city, lastUpdateTime, isPassed, tenantId, groupId, thirdParty, additionalPicture, desc, config, lastMessageTime, unreadCount, duplicate",
|
||||||
newContractList: "serverId, id, groupName, contacts",
|
newContractList: "serverId, id, groupName, contacts",
|
||||||
|
|||||||
Reference in New Issue
Block a user