feat(客戶管理頁面優化): 更新客戶管理頁面,調整聯絡人卡片的最小高度,移除不必要的樣式,並整合聯絡人數據加載邏輯,提升頁面性能與用戶體驗。

This commit is contained in:
超级老白兔
2025-09-25 15:39:44 +08:00
parent b3bf342320
commit 5acdd13966
3 changed files with 275 additions and 169 deletions

View File

@@ -116,7 +116,6 @@
.tabs { .tabs {
display: flex; display: flex;
gap: 0; gap: 0;
margin-bottom: 24px;
border-bottom: 1px solid #f0f0f0; border-bottom: 1px solid #f0f0f0;
.tab { .tab {
@@ -155,7 +154,6 @@
padding: 20px; padding: 20px;
transition: all 0.3s; transition: all 0.3s;
height: 100%; height: 100%;
min-height: 380px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -320,7 +318,7 @@
} }
.contactCard { .contactCard {
min-height: 350px; min-height: 175px;
} }
.header { .header {

View File

@@ -1,4 +1,4 @@
import React, { useState, useMemo } from "react"; import React, { useState, useEffect } from "react";
import PowerNavigation from "@/components/PowerNavtion"; import PowerNavigation from "@/components/PowerNavtion";
import { import {
SearchOutlined, SearchOutlined,
@@ -7,11 +7,10 @@ import {
PhoneOutlined, PhoneOutlined,
} from "@ant-design/icons"; } from "@ant-design/icons";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import { Button, Input, Row, Col } from "antd"; import { Button, Input, Row, Col, Pagination, Spin, message } from "antd";
import { useCkChatStore } from "@/store/module/ckchat/ckchat"; import { getContactList } from "@/pages/pc/ckbox/weChat/api";
import { ContractData } from "@/pages/pc/ckbox/data"; import { ContractData } from "@/pages/pc/ckbox/data";
// 直接使用 ContractData 类型 import Layout from "@/components/Layout/LayoutFiexd";
// 头像组件 // 头像组件
const Avatar: React.FC<{ name: string; avatar?: string; size?: number }> = ({ const Avatar: React.FC<{ name: string; avatar?: string; size?: number }> = ({
name, name,
@@ -64,52 +63,112 @@ const Avatar: React.FC<{ name: string; avatar?: string; size?: number }> = ({
}; };
const CustomerManagement: React.FC = () => { const CustomerManagement: React.FC = () => {
const [activeTab, setActiveTab] = useState("customer"); const [activeTab, setActiveTab] = useState("all");
const [searchValue, setSearchValue] = useState(""); const [searchValue, setSearchValue] = useState("");
const [contacts, setContacts] = useState<ContractData[]>([]);
const [loading, setLoading] = useState(false);
const [pagination, setPagination] = useState({
current: 1,
pageSize: 12,
total: 0,
});
// 获取联系人数据 // 获取各分类的总数
const getContractList = useCkChatStore(state => state.getContractList); const [tabCounts, setTabCounts] = useState({
const contacts: ContractData[] = getContractList(); all: 0,
console.log(contacts, "contacts"); customer: 0,
potential: 0,
// 动态计算各分类的联系人数量 partner: 0,
const tabCounts = useMemo(() => { friend: 0,
return { });
customer: contacts.filter(c => c.isPassed).length,
potential: contacts.filter(c => !c.isPassed).length,
partner: 0, // 可以根据业务逻辑调整
friend: 0, // 可以根据业务逻辑调整
};
}, [contacts]);
const tabs = [ const tabs = [
{ key: "all", label: "全部", count: tabCounts.all },
{ key: "customer", label: "客户", count: tabCounts.customer }, { key: "customer", label: "客户", count: tabCounts.customer },
{ key: "potential", label: "潜在客户", count: tabCounts.potential }, { key: "potential", label: "潜在客户", count: tabCounts.potential },
{ key: "partner", label: "合作伙伴", count: tabCounts.partner }, { key: "partner", label: "合作伙伴", count: tabCounts.partner },
{ key: "friend", label: "朋友", count: tabCounts.friend }, { key: "friend", label: "朋友", count: tabCounts.friend },
]; ];
// const filteredContacts = contacts.filter(contact => { // 加载联系人数据
// const isCategoryMatch = const loadContacts = async (page: number = 1, pageSize: number = 12) => {
// (activeTab === "customer" && contact.isPassed) || try {
// (activeTab === "potential" && !contact.isPassed) || setLoading(true);
// activeTab === "partner" ||
// activeTab === "friend";
// const isSearchMatch = // 构建请求参数
// searchValue === "" || const params: any = {
// contact.nickname?.includes(searchValue) || page,
// contact.conRemark?.includes(searchValue) || limit: pageSize,
// contact.alias?.includes(searchValue) || };
// contact.desc?.includes(searchValue) ||
// contact.labels?.some(tag => tag.includes(searchValue)); // 添加搜索条件
if (searchValue.trim()) {
params.keyword = searchValue;
}
// 添加分类筛选
if (activeTab === "customer") {
params.isPassed = true;
} else if (activeTab === "potential") {
params.isPassed = false;
}
// "全部"、"partner" 和 "friend" 不添加额外筛选条件
const response = await getContactList(params);
// 假设接口返回格式为 { data: Contact[], total: number, page: number, limit: number }
setContacts(response.data || response.list || []);
setPagination(prev => ({
...prev,
current: response.page || page,
pageSize: response.limit || pageSize,
total: response.total || 0,
}));
// 更新分类统计
if (page === 1) {
// 只在第一页时更新统计,避免重复请求
const allResponse = await getContactList({ page: 1, limit: 1 });
const customerResponse = await getContactList({
page: 1,
limit: 1,
isPassed: true,
});
const potentialResponse = await getContactList({
page: 1,
limit: 1,
isPassed: false,
});
setTabCounts({
all: allResponse.total || 0,
customer: customerResponse.total || 0,
potential: potentialResponse.total || 0,
partner: 0, // 可以根据业务逻辑调整
friend: 0, // 可以根据业务逻辑调整
});
}
} catch (error) {
console.error("加载联系人数据失败:", error);
message.error("加载联系人数据失败,请稍后重试");
} finally {
setLoading(false);
}
};
// 当分类或搜索条件改变时重新加载数据
useEffect(() => {
loadContacts(1, pagination.pageSize);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activeTab, searchValue, pagination.pageSize]);
// return isCategoryMatch && isSearchMatch;
// });
const filteredContacts = contacts; const filteredContacts = contacts;
return ( return (
<div className={styles.container}> <Layout
header={
<>
<div style={{ padding: "20px" }}>
<PowerNavigation <PowerNavigation
title="客户好友管理" title="客户好友管理"
subtitle="管理客户关系,维护好友信息" subtitle="管理客户关系,维护好友信息"
@@ -117,8 +176,6 @@ const CustomerManagement: React.FC = () => {
backButtonText="返回功能中心" backButtonText="返回功能中心"
rightContent={<Button></Button>} rightContent={<Button></Button>}
/> />
<div className={styles.content}>
{/* 搜索和筛选 */} {/* 搜索和筛选 */}
<div className={styles.searchBar}> <div className={styles.searchBar}>
<Input <Input
@@ -130,12 +187,13 @@ const CustomerManagement: React.FC = () => {
size="large" size="large"
/> />
<Button <Button
onClick={() => {}} onClick={() => loadContacts(1, pagination.pageSize)}
size="large" size="large"
className={styles["refresh-btn"]} className={styles["refresh-btn"]}
loading={loading}
> >
<FilterOutlined /> <FilterOutlined />
</Button> </Button>
</div> </div>
{/* 标签页 */} {/* 标签页 */}
@@ -150,15 +208,49 @@ const CustomerManagement: React.FC = () => {
</button> </button>
))} ))}
</div> </div>
</div>
</>
}
footer={
<div className="pagination-wrapper">
<Pagination
current={pagination.current}
pageSize={pagination.pageSize}
total={pagination.total}
showSizeChanger
showQuickJumper
showTotal={(total, range) =>
`${range[0]}-${range[1]} 条,共 ${total}`
}
onChange={(page, pageSize) => {
loadContacts(page, pageSize || pagination.pageSize);
}}
onShowSizeChange={(current, size) => {
loadContacts(1, size);
}}
pageSizeOptions={["6", "12", "24", "48"]}
/>
</div>
}
>
<div className={styles.container}>
<div className={styles.content}>
{/* 联系人卡片列表 */} {/* 联系人卡片列表 */}
<div className={styles.contactsList}> <div className={styles.contactsList}>
{filteredContacts.length === 0 ? ( {loading ? (
<div style={{ textAlign: "center", padding: "50px" }}>
<Spin size="large" />
<p style={{ marginTop: "16px", color: "#666" }}>
...
</p>
</div>
) : filteredContacts.length === 0 ? (
<div style={{ textAlign: "center", padding: "50px" }}> <div style={{ textAlign: "center", padding: "50px" }}>
<p style={{ color: "#999" }}></p> <p style={{ color: "#999" }}></p>
</div> </div>
) : ( ) : (
<Row gutter={16}> <>
<Row gutter={[16, 16]}>
{filteredContacts.map(contact => ( {filteredContacts.map(contact => (
<Col span={8} key={contact.id || contact.serverId}> <Col span={8} key={contact.id || contact.serverId}>
<div className={styles.contactCard}> <div className={styles.contactCard}>
@@ -207,11 +299,13 @@ const CustomerManagement: React.FC = () => {
<div className={styles.tagsSection}> <div className={styles.tagsSection}>
<div className={styles.tags}> <div className={styles.tags}>
{contact?.labels?.map((tag: string, index: number) => ( {contact?.labels?.map(
(tag: string, index: number) => (
<span key={index} className={styles.tag}> <span key={index} className={styles.tag}>
{tag} {tag}
</span> </span>
))} ),
)}
</div> </div>
<span className={styles.source}></span> <span className={styles.source}></span>
</div> </div>
@@ -219,12 +313,16 @@ const CustomerManagement: React.FC = () => {
<div className={styles.lastContact}> <div className={styles.lastContact}>
:{" "} :{" "}
{contact.lastMessageTime {contact.lastMessageTime
? new Date(contact.lastMessageTime).toLocaleDateString() ? new Date(
contact.lastMessageTime,
).toLocaleDateString()
: "未联系"} : "未联系"}
</div> </div>
{contact.signature && ( {contact.signature && (
<div className={styles.notes}>{contact.signature}</div> <div className={styles.notes}>
{contact.signature}
</div>
)} )}
<div className={styles.actions}> <div className={styles.actions}>
@@ -241,10 +339,12 @@ const CustomerManagement: React.FC = () => {
</Col> </Col>
))} ))}
</Row> </Row>
</>
)} )}
</div> </div>
</div> </div>
</div> </div>
</Layout>
); );
}; };

View File

@@ -315,3 +315,11 @@ button {
flex: 1; flex: 1;
} }
} }
.pagination-wrapper {
display: flex;
justify-content: center;
align-items: center;
padding: 16px;
background: white;
border-top: 1px solid #f0f0f0;
}