fix: 修复个人聊天界面和导出csv文件不显示名称问题,fix #1

This commit is contained in:
电摇小子
2026-01-04 15:53:26 +08:00
parent 55b792b23c
commit 02baed9bb6
4 changed files with 28 additions and 8 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "wechatexplorer", "name": "wechatexplorer",
"version": "1.0.1", "version": "1.0.2",
"description": "mac 版本获取微信聊天记录, AI群聊总结助手", "description": "mac 版本获取微信聊天记录, AI群聊总结助手",
"keywords": [ "keywords": [
"wechat", "wechat",
+1 -3
View File
@@ -161,14 +161,12 @@ app.whenReady().then(() => {
return { return {
id: msg.mesLocalID || Math.random().toString(), id: msg.mesLocalID || Math.random().toString(),
from: msg.mesDes === '1' ? 'user' : 'assistant', // 1 通常是接收到的,0 是发送的?需要验证。Swift 说:[1: "user", 0: "assistant"] from: msg.mesDes === 1 ? 'user' : 'assistant', // 1 通常是接收到的,0 是发送的?需要验证。Swift 说:[1: "user", 0: "assistant"]
type: MSG_TYPE_DICT[msgType] || msg.messageType, type: MSG_TYPE_DICT[msgType] || msg.messageType,
datetime: date.toLocaleString('zh-CN', { hour12: false }), datetime: date.toLocaleString('zh-CN', { hour12: false }),
content: content, content: content,
isSender: msg.mesDes === '0',
img: img, img: img,
name: name name: name
// 实际上让我们坚持我们观察到的:1=用户(其他人), 0=助手(我)
} }
}) })
}) })
+1 -1
View File
@@ -13,7 +13,7 @@ export interface UserContact {
export interface WechatMessage { export interface WechatMessage {
mesLocalID: string mesLocalID: string
mesDes: string mesDes: number
messageType: string messageType: string
msgCreateTime: string msgCreateTime: string
msgContent: string msgContent: string
+25 -3
View File
@@ -39,6 +39,7 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
onRefresh, onRefresh,
onRefreshData onRefreshData
}) => { }) => {
const isGroupChat = contact?.type === 'group' || contact?.m_nsUsrName?.endsWith('@chatroom')
const messagesEndRef = useRef<HTMLDivElement>(null) const messagesEndRef = useRef<HTMLDivElement>(null)
const imageContainerRef = useRef<HTMLDivElement>(null) const imageContainerRef = useRef<HTMLDivElement>(null)
const [generatedImage, setGeneratedImage] = useState<string | null>(null) const [generatedImage, setGeneratedImage] = useState<string | null>(null)
@@ -115,11 +116,16 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
// 昨天 // 昨天
const startOfYesterday = startOfDay - 86400000 const startOfYesterday = startOfDay - 86400000
return parsed >= startOfYesterday && parsed < startOfDay return parsed >= startOfYesterday && parsed < startOfDay
} else { } else if (days === 7) {
// 过去 7 天 // 过去 7 天
const startOf7DaysAgo = startOfDay - 7 * 86400000 const startOf7DaysAgo = startOfDay - 7 * 86400000
return parsed >= startOf7DaysAgo return parsed >= startOf7DaysAgo
} else if (days === 30) {
// 过去 30 天
const startOf30DaysAgo = startOfDay - 30 * 86400000
return parsed >= startOf30DaysAgo
} }
return true
}) })
} }
@@ -127,7 +133,15 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
const csvContent = [ const csvContent = [
headers.join(','), headers.join(','),
...filtered.map((m) => { ...filtered.map((m) => {
const content = m.content.replace(/"/g, '""').replace(/\n/g, ' ') let prefix = ''
if (isGroupChat) {
prefix = m.name ? `${m.name}: ` : ''
} else {
const name = m.from === 'user' ? contact?.m_nsNickName || '未知' : '我'
prefix = `${name}: `
}
const fullContent = `${prefix}${m.content}`
const content = fullContent.replace(/"/g, '""').replace(/\n/g, ' ')
return `"${m.from}","${m.type}","${m.datetime}","${content}"` return `"${m.from}","${m.type}","${m.datetime}","${content}"`
}) })
].join('\n') ].join('\n')
@@ -300,7 +314,12 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
display: !showAvatar ? 'flex' : 'block' display: !showAvatar ? 'flex' : 'block'
}} }}
> >
{msg.name && <div style={{ fontSize: 18 }}>{msg.name}: </div>} {(msg.name || contact.m_nsNickName) && (
<div style={{ display: 'flex', fontSize: 18 }}>
{isGroupChat ? msg.name : msg.from === 'user' ? contact.m_nsNickName : '我'}
<span>{isGroupChat ? (msg.name ? ':' : '') : ':'} </span>
</div>
)}
<div <div
style={{ style={{
fontSize: 18, fontSize: 18,
@@ -367,6 +386,9 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
<button className="toolbar-btn" onClick={() => handleExport(7)}> <button className="toolbar-btn" onClick={() => handleExport(7)}>
📅 7 📅 7
</button> </button>
<button className="toolbar-btn" onClick={() => handleExport(30)}>
📅 30
</button>
<button className="toolbar-btn" onClick={() => setShowSettingsModal(true)}> <button className="toolbar-btn" onClick={() => setShowSettingsModal(true)}>
🤖 AI总结群聊 🤖 AI总结群聊
</button> </button>