// @ts-nocheck import React, { useState, useEffect, useRef, useCallback } from 'react'; import { imUserAPI } from '@/api'; const WechatHistory: React.FC = () => { const [loading, setLoading] = useState(true); const [messages, setMessages] = useState([]); const [toast, setToast] = useState<{ msg: string; type: 'success' | 'error' } | null>(null); const bottomRef = useRef(null); const showToast = (msg: string, type: 'success' | 'error' = 'success') => { setToast({ msg, type }); setTimeout(() => setToast(null), 3000); }; const load = useCallback(async () => { setLoading(true); try { const res = await imUserAPI.history(); if ((res as any)?.success && (res as any).data) { setMessages((res as any).data.messages || []); } else { showToast('加载失败', 'error'); } } catch (e) { showToast('加载失败', 'error'); } finally { setLoading(false); } }, []); useEffect(() => { load(); }, [load]); useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages]); const formatTime = (t: string) => (t ? new Date(t).toLocaleString('zh-CN') : '-'); return (
{/* Header */}

微信对话记录

你通过个人微信与七虎AI 的对话历史,按时间顺序记录,可随时回看(仅本人可见,按账号隔离)。

{/* Toast */} {toast && (
{toast.msg}
)} {/* 记录列表 */}
{messages.length === 0 ? (
{loading ? '加载中…' : '暂无对话记录。请先在「微信机器人」中绑定并发送消息,对话记录会显示在这里。'}
) : ( messages.map((m, i) => (
{m.role === 'user' ? '我(微信)' : '七虎AI'} · {formatTime(m.created_at)}
{m.content}
)) )}
); }; const btnStyle: React.CSSProperties = { padding: '8px 20px', background: '#6C63FF', border: 'none', borderRadius: '6px', color: '#fff', fontSize: '14px', fontWeight: 500, cursor: 'pointer', }; export default WechatHistory;