fix(contact-import): 移除未使用的ContactImportTask导入
fix(traffic-pool): 添加tags存在性检查避免报错 feat(traffic-pool): 添加请求频率限制错误处理 refactor(traffic-pool): 使用防抖优化搜索功能
This commit is contained in:
@@ -34,7 +34,9 @@ export function useTrafficPoolListLogic() {
|
||||
const [showStats, setShowStats] = useState(false);
|
||||
const stats = useMemo(() => {
|
||||
const total = list.length;
|
||||
const highValue = list.filter(u => u.tags.includes("高价值客户池")).length;
|
||||
const highValue = list.filter(
|
||||
u => u.tags && u.tags.includes("高价值客户池"),
|
||||
).length;
|
||||
const added = list.filter(u => u.status === 1).length;
|
||||
const pending = list.filter(u => u.status === 0).length;
|
||||
const failed = list.filter(u => u.status === -1).length;
|
||||
@@ -64,6 +66,11 @@ export function useTrafficPoolListLogic() {
|
||||
const res = await fetchTrafficPoolList(params);
|
||||
setList(res.list || []);
|
||||
setTotal(res.total || 0);
|
||||
} catch (error) {
|
||||
// 忽略请求过于频繁的错误,避免页面崩溃
|
||||
if (error !== "请求过于频繁,请稍后再试") {
|
||||
console.error("获取列表失败:", error);
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from "react";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import Layout from "@/components/Layout/Layout";
|
||||
import {
|
||||
SearchOutlined,
|
||||
@@ -25,7 +25,6 @@ const TrafficPoolList: React.FC = () => {
|
||||
list,
|
||||
page,
|
||||
setPage,
|
||||
pageSize,
|
||||
total,
|
||||
search,
|
||||
setSearch,
|
||||
@@ -52,6 +51,22 @@ const TrafficPoolList: React.FC = () => {
|
||||
getList,
|
||||
} = useTrafficPoolListLogic();
|
||||
|
||||
// 搜索防抖处理
|
||||
const [searchInput, setSearchInput] = useState(search);
|
||||
|
||||
const debouncedSearch = useCallback(() => {
|
||||
const timer = setTimeout(() => {
|
||||
setSearch(searchInput);
|
||||
}, 500); // 500ms 防抖延迟
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [searchInput, setSearch]);
|
||||
|
||||
useEffect(() => {
|
||||
const cleanup = debouncedSearch();
|
||||
return cleanup;
|
||||
}, [debouncedSearch]);
|
||||
|
||||
return (
|
||||
<Layout
|
||||
loading={loading}
|
||||
@@ -73,8 +88,8 @@ const TrafficPoolList: React.FC = () => {
|
||||
<div className="search-input-wrapper">
|
||||
<Input
|
||||
placeholder="搜索计划名称"
|
||||
value={search}
|
||||
onChange={e => setSearch(e.target.value)}
|
||||
value={searchInput}
|
||||
onChange={e => setSearchInput(e.target.value)}
|
||||
prefix={<SearchOutlined />}
|
||||
allowClear
|
||||
size="large"
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
triggerImport,
|
||||
toggleContactImportTask,
|
||||
} from "../list/api";
|
||||
import { ContactImportTask, ContactImportRecord } from "../list/data";
|
||||
import { ContactImportRecord } from "../list/data";
|
||||
import {
|
||||
PlayCircleOutlined,
|
||||
PauseCircleOutlined,
|
||||
|
||||
Reference in New Issue
Block a user