From 2d4d73d0d12a8fd47ac92ee30daee91671319276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Mon, 1 Jun 2026 10:57:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor(customer):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E5=92=8C?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E5=AD=97=E6=AE=B5=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除新增客户页面对手机号的必填和格式校验 - 修改手机号字段标签为“手机号/微信号”,取消必填和长度限制 - 新增判断当前用户是否为超级管理员逻辑 - 抽取并统一构建客户查询参数方法,根据权限动态设置筛选条件 - 优化客户列表数据获取逻辑,支持超级管理员查看全部客户 - 调整依赖项,更新使用了新构建的查询参数函数 - 增强状态统计接口参数构建,统一调用参数生成函数 - 优化副作用 Hook 依赖,保证数据加载时机正确 --- src/dealer/customer/add.tsx | 23 ++---------------- src/dealer/customer/index.tsx | 46 ++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/src/dealer/customer/add.tsx b/src/dealer/customer/add.tsx index ee496bd..83fa845 100644 --- a/src/dealer/customer/add.tsx +++ b/src/dealer/customer/add.tsx @@ -359,25 +359,6 @@ const AddShopDealerApply = () => { return; } - // 验证必填字段 - if (!values.mobile || values.mobile.trim() === '') { - Taro.showToast({ - title: '请填写联系方式', - icon: 'error' - }); - return; - } - - // 验证手机号格式 - const phoneRegex = /^1[3-9]\d{9}$/; - if (!phoneRegex.test(values.mobile)) { - Taro.showToast({ - title: '请填写正确的手机号', - icon: 'error' - }); - return; - } - // 规范化报备人:留空=自己报备(当前登录用户) const rawUserId = normalizeText(values.userId); const submitUserId = rawUserId @@ -644,8 +625,8 @@ const AddShopDealerApply = () => { - - + + diff --git a/src/dealer/customer/index.tsx b/src/dealer/customer/index.tsx index 7e245ea..f0bc028 100644 --- a/src/dealer/customer/index.tsx +++ b/src/dealer/customer/index.tsx @@ -37,10 +37,29 @@ const CustomerIndex = () => { const {user, loading: userLoading} = useUser() const roleCheckFinished = !userLoading const isLoggedIn = roleCheckFinished && user !== null + const isSuperAdmin = user?.isSuperAdmin === true // Tab配置 const tabList = getStatusOptions(); + const buildCustomerQueryParams = useCallback((currentPage?: number) => { + const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0; + const params: any = { + type: 4 + }; + + if (currentPage !== undefined) { + params.page = currentPage; + } + + if (!isSuperAdmin) { + params.userId = currentUserId; + params.receptionistId = currentUserId; + } + + return params; + }, [isSuperAdmin, user?.userId]); + // 复制手机号 const copyPhone = (phone: string) => { Taro.setClipboardData({ @@ -183,17 +202,11 @@ const CustomerIndex = () => { const fetchCustomerData = useCallback(async (statusFilter?: CustomerStatus, resetPage = false, targetPage?: number) => { setLoading(true); try { - const currentPage = resetPage ? 1 : (targetPage || page); - const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0; + const currentPage = resetPage ? 1 : (targetPage || 1); // 构建API参数,根据状态筛选 - // 查看自己提交的(userId)或分配给自己的(receptionistId)的客户 - const params: any = { - type: 4, - page: currentPage, - userId: currentUserId, - receptionistId: currentUserId - }; + // 非超管查看自己提交的(userId)或分配给自己的(receptionistId)的客户;超管查询全部 + const params = buildCustomerQueryParams(currentPage); const applyStatus = mapCustomerStatusToApplyStatus(statusFilter || activeTab); if (applyStatus !== undefined) { params.applyStatus = applyStatus; @@ -236,7 +249,7 @@ const CustomerIndex = () => { } finally { setLoading(false); } - }, [activeTab, page, user?.userId]); + }, [activeTab, buildCustomerQueryParams]); const reloadMore = async () => { if (loading || !hasMore) return; // 防止重复加载 @@ -284,12 +297,7 @@ const CustomerIndex = () => { // 获取所有状态的统计数量 const fetchStatusCounts = useCallback(async () => { try { - const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0; - const baseParams: any = { - type: 4, - userId: currentUserId, - receptionistId: currentUserId - }; + const baseParams = buildCustomerQueryParams(); // 并行获取各状态的数量 const [allRes, pendingRes, signedRes, cancelledRes] = await Promise.all([ @@ -308,7 +316,7 @@ const CustomerIndex = () => { } catch (error) { console.error('获取状态统计失败:', error); } - }, [user?.userId]); + }, [buildCustomerQueryParams]); const getStatusCounts = () => statusCounts; @@ -351,7 +359,7 @@ const CustomerIndex = () => { useEffect(() => { if (!isLoggedIn) return; fetchStatusCounts().then(); - }, [isLoggedIn]); + }, [fetchStatusCounts, isLoggedIn]); // 当activeTab变化时重新获取数据 useEffect(() => { @@ -360,7 +368,7 @@ const CustomerIndex = () => { setPage(1); // 重置页码 setHasMore(true); // 重置加载状态 fetchCustomerData(activeTab, true); - }, [activeTab, isLoggedIn]); + }, [activeTab, fetchCustomerData, isLoggedIn]); // 监听页面显示,当从其他页面返回时刷新数据 useDidShow(() => {