import React, { useState, useEffect } from "react"; import { NavBar, List, Card, Button, SpinLoading, Popup, Toast, } from "antd-mobile"; import { Pagination, Input, Tooltip } from "antd"; import { ArrowLeftOutlined, SearchOutlined, ReloadOutlined, } from "@ant-design/icons"; import { useNavigate } from "react-router-dom"; import Layout from "@/components/Layout/Layout"; import style from "./index.module.scss"; import { getWechatAccounts } from "./api"; interface WechatAccount { id: number; nickname: string; avatar: string; wechatId: string; wechatAccount: string; deviceId: number; times: number; // 今日可添加 addedCount: number; // 今日新增 wechatStatus: number; // 1正常 0异常 totalFriend: number; deviceMemo: string; // 设备名 activeTime: string; // 最后活跃 } const PAGE_SIZE = 10; const WechatAccounts: React.FC = () => { const navigate = useNavigate(); const [accounts, setAccounts] = useState([]); const [searchTerm, setSearchTerm] = useState(""); const [currentPage, setCurrentPage] = useState(1); const [totalAccounts, setTotalAccounts] = useState(0); const [isLoading, setIsLoading] = useState(true); const [isRefreshing, setIsRefreshing] = useState(false); const [popupVisible, setPopupVisible] = useState(false); const [selectedAccount, setSelectedAccount] = useState( null ); const fetchAccounts = async (page = 1, keyword = "") => { setIsLoading(true); try { const res = await getWechatAccounts({ page, page_size: PAGE_SIZE, keyword, }); if (res && res.list) { setAccounts(res.list); setTotalAccounts(res.total || 0); } else { setAccounts([]); setTotalAccounts(0); } } catch (e) { Toast.show({ content: "获取微信号失败", position: "top" }); setAccounts([]); setTotalAccounts(0); } finally { setIsLoading(false); } }; useEffect(() => { fetchAccounts(currentPage, searchTerm); // eslint-disable-next-line }, [currentPage]); const handleSearch = () => { setCurrentPage(1); fetchAccounts(1, searchTerm); }; const handleRefresh = async () => { setIsRefreshing(true); await fetchAccounts(currentPage, searchTerm); setIsRefreshing(false); Toast.show({ content: "刷新成功", position: "top" }); }; const handleAccountClick = (account: WechatAccount) => { setSelectedAccount(account); setPopupVisible(true); }; const handleTransferFriends = (account: WechatAccount) => { // TODO: 实现好友转移弹窗或跳转 Toast.show({ content: `好友转移:${account.nickname}` }); }; return ( navigate(-1)} /> } > 微信号管理
setSearchTerm(e.target.value)} prefix={} allowClear size="large" onPressEnter={handleSearch} />
} >
{isLoading ? (
) : accounts.length === 0 ? (
暂无微信账号数据
) : (
{accounts.map((account) => { const percent = account.times > 0 ? Math.min((account.addedCount / account.times) * 100, 100) : 0; return (
handleAccountClick(account)} >
{account.nickname}
{account.nickname} {account.wechatStatus === 1 ? "正常" : "异常"}
微信号:{account.wechatAccount}
好友数量: {account.totalFriend}
今日新增: +{account.addedCount}
今日可添加: {account.times}
进度: {account.addedCount}/{account.times}
所属设备: {account.deviceMemo || "-"}
最后活跃: {account.activeTime}
); })}
)}
{totalAccounts > PAGE_SIZE && ( )}
setPopupVisible(false)} bodyStyle={{ borderRadius: "16px 16px 0 0" }} > {selectedAccount && (
avatar
{selectedAccount.nickname}
微信号:{selectedAccount.wechatAccount}
)}
); }; export default WechatAccounts;