From 55ea2bf7e3b97f9791eb4685ca83381fbb6c25da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Tue, 13 May 2025 14:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=81=E5=9F=9F=E6=93=8D=E7=9B=98=E6=89=8B?= =?UTF-8?q?=20-=20=E4=BF=AE=E5=A4=8D=E6=B5=81=E9=87=8F=E6=B1=A0=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=8D=E4=BC=9A=E8=87=AA=E5=8A=A8=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=88=97=E8=A1=A8=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cunkebao/app/traffic-pool/page.tsx | 130 +++++++++--------- Server/application/cunkebao/config/route.php | 4 +- ...otentialListWithInCompanyV1Controller.php} | 2 +- ...p => GetPotentialTypeListV1Controller.php} | 2 +- 4 files changed, 66 insertions(+), 72 deletions(-) rename Server/application/cunkebao/controller/traffic/{GetDissociateListWithInCompanyV1Controller.php => GetPotentialListWithInCompanyV1Controller.php} (96%) rename Server/application/cunkebao/controller/traffic/{GetDissociateTypeListV1Controller.php => GetPotentialTypeListV1Controller.php} (95%) diff --git a/Cunkebao/app/traffic-pool/page.tsx b/Cunkebao/app/traffic-pool/page.tsx index 07a7d9f0..942e1b49 100644 --- a/Cunkebao/app/traffic-pool/page.tsx +++ b/Cunkebao/app/traffic-pool/page.tsx @@ -37,7 +37,7 @@ interface TrafficUser { phone: string region: string note: string - status: "pending" | "added" | "failed" + status: number addTime: string source: string assignedTo: string @@ -48,6 +48,7 @@ interface TrafficUser { interface StatusType { id: number name: string + code: string } interface ApiResponse { @@ -144,37 +145,43 @@ export default function TrafficPoolPage() { const params = new URLSearchParams({ page: page.toString(), - limit: "30", // 设置每页显示30条 + limit: "30", search: debouncedSearchQuery, category: activeCategory, source: sourceFilter !== "all" ? sourceFilter : "", status: statusFilter === "all" ? "" : statusFilter, }) - // 检查是否有来源参数 const sourceParam = searchParams?.get("source") if (sourceParam) { params.append("wechatSource", sourceParam) } - const response = await api.get>(`/v1/traffic/pool?${params.toString()}`) + const response = await api.get>(`/v1/traffic/pool?${params.toString()}`, { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}` + } + } as any) if (response.code === 200) { const { list, pagination, statistics } = response.data - // 转换数据格式 const transformedUsers = list.map(user => ({ - ...user, id: user.id.toString(), - status: getStatusFromCode(user.status), - tags: user.tags || [], - category: user.category || "potential", + avatar: user.avatar, + nickname: user.name || user.nickname || '未知用户', + wechatId: user.wechatId, + phone: user.phone, + region: user.region, + note: user.note, + status: user.status, addTime: formatDateTime(user.createTime), source: user.fromd || '未知来源', - nickname: user.name || user.nickname || '未知用户' + assignedTo: user.assignedTo, + category: user.category || "potential", + tags: user.tags || [] })) - // 更新用户列表 setUsers(prev => isNewSearch ? transformedUsers : [...prev, ...transformedUsers]) setCurrentPage(page) setHasMore(list.length > 0 && page < pagination.totalPages) @@ -207,7 +214,11 @@ export default function TrafficPoolPage() { const fetchStatusTypes = useCallback(async () => { try { - const response = await api.get>('/v1/traffic/pool/types') + const response = await api.get>('/v1/traffic/pool/types', { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}` + } + } as any) if (response.code === 200) { setStatusTypes(response.data) @@ -236,9 +247,9 @@ export default function TrafficPoolPage() { fetchUsers(1, true) }, [fetchUsers]) - // 设置 IntersectionObserver + // 初始化 IntersectionObserver useEffect(() => { - observerRef.current = new IntersectionObserver( + const observer = new IntersectionObserver( (entries) => { if (entries[0].isIntersecting && hasMore && !isFetching) { fetchUsers(currentPage + 1) @@ -247,35 +258,30 @@ export default function TrafficPoolPage() { { threshold: 0.5 } ) - return () => { - if (observerRef.current) { - observerRef.current.disconnect() - } - } - }, [fetchUsers, currentPage, hasMore, isFetching]) - - // 观察加载指示器 - useEffect(() => { - if (loadingRef.current && observerRef.current) { - observerRef.current.observe(loadingRef.current) + if (loadingRef.current) { + observer.observe(loadingRef.current) } return () => { - if (loadingRef.current && observerRef.current) { - observerRef.current.unobserve(loadingRef.current) + if (loadingRef.current) { + observer.unobserve(loadingRef.current) } } - }, [loadingRef.current, observerRef.current]) + }, [hasMore, isFetching, currentPage, fetchUsers]) - // 初始加载 + // 初始化数据 useEffect(() => { + fetchStatusTypes() fetchUsers(1, true) - return () => { - if (abortControllerRef.current) { - abortControllerRef.current.abort() - } - } - }, [fetchUsers]) + }, []) + + // 监听筛选条件变化 + useEffect(() => { + setUsers([]) + setCurrentPage(1) + setHasMore(true) + fetchUsers(1, true) + }, [activeCategory, sourceFilter, statusFilter, debouncedSearchQuery]) const handleUserClick = (user: TrafficUser) => { setSelectedUser(user) @@ -283,16 +289,8 @@ export default function TrafficPoolPage() { } // 添加状态码转换函数 - const getStatusFromCode = (statusCode: number): "pending" | "added" | "failed" => { - const statusMap: Record = { - 1: "pending", // 待处理 - 2: "pending", // 处理中 - 3: "added", // 已添加 - 4: "failed", // 已拒绝 - 5: "failed", // 已过期 - 6: "failed", // 已取消 - } - return statusMap[statusCode] || "pending" + const getStatusFromCode = (statusCode: number): number => { + return statusCode; } return ( @@ -431,14 +429,14 @@ export default function TrafficPoolPage() {
{user.nickname}
- {user.status === "added" ? "已添加" : user.status === "pending" ? "待处理" : "已失败"} + {user.status === 2 ? "已添加" : user.status === 1 ? "待处理" : "已失败"}
微信号: {user.wechatId}
@@ -463,19 +461,19 @@ export default function TrafficPoolPage() { ))} - {/* 加载更多指示器 */} - {hasMore && ( -
- {isFetching && } -
- )} - - {/* 显示加载状态和总数 */} -
- {stats.total > 0 && ( - - 已加载 {users.length} / {stats.total} 条记录 - + {/* 加载状态显示 */} +
+ {isFetching && ( +
+
+ 加载中... +
+ )} + {!hasMore && users.length > 0 && ( + 已加载全部数据 + )} + {!isFetching && users.length === 0 && ( + 暂无数据 )}
@@ -502,18 +500,14 @@ export default function TrafficPoolPage() {
{selectedUser.wechatId}
- {selectedUser.status === "added" - ? "已添加" - : selectedUser.status === "pending" - ? "待处理" - : "已失败"} + {selectedUser.status === 2 ? "已添加" : selectedUser.status === 1 ? "待处理" : "已失败"}
diff --git a/Server/application/cunkebao/config/route.php b/Server/application/cunkebao/config/route.php index 73175ea5..b5315429 100644 --- a/Server/application/cunkebao/config/route.php +++ b/Server/application/cunkebao/config/route.php @@ -41,8 +41,8 @@ Route::group('v1/', function () { // 流量池相关 Route::group('traffic/pool', function () { - Route::get('', 'app\cunkebao\controller\traffic\GetDissociateListWithInCompanyV1Controller@index'); - Route::get('types', 'app\cunkebao\controller\traffic\GetDissociateTypeListV1Controller@index'); + Route::get('', 'app\cunkebao\controller\traffic\GetPotentialListWithInCompanyV1Controller@index'); + Route::get('types', 'app\cunkebao\controller\traffic\GetPotentialTypeListV1Controller@index'); }); // 工作台相关 diff --git a/Server/application/cunkebao/controller/traffic/GetDissociateListWithInCompanyV1Controller.php b/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php similarity index 96% rename from Server/application/cunkebao/controller/traffic/GetDissociateListWithInCompanyV1Controller.php rename to Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php index 6558de34..44513f04 100644 --- a/Server/application/cunkebao/controller/traffic/GetDissociateListWithInCompanyV1Controller.php +++ b/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php @@ -10,7 +10,7 @@ use library\ResponseHelper; /** * 流量池控制器 */ -class GetDissociateListWithInCompanyV1Controller extends BaseController +class GetPotentialListWithInCompanyV1Controller extends BaseController { /** * 构建查询条件 diff --git a/Server/application/cunkebao/controller/traffic/GetDissociateTypeListV1Controller.php b/Server/application/cunkebao/controller/traffic/GetPotentialTypeListV1Controller.php similarity index 95% rename from Server/application/cunkebao/controller/traffic/GetDissociateTypeListV1Controller.php rename to Server/application/cunkebao/controller/traffic/GetPotentialTypeListV1Controller.php index c48bab9a..16f5dbc9 100644 --- a/Server/application/cunkebao/controller/traffic/GetDissociateTypeListV1Controller.php +++ b/Server/application/cunkebao/controller/traffic/GetPotentialTypeListV1Controller.php @@ -10,7 +10,7 @@ use library\ResponseHelper; /** * 流量池控制器 */ -class GetDissociateTypeListV1Controller extends BaseController +class GetPotentialTypeListV1Controller extends BaseController { protected function getTypeList(): array {