feat(customer): 优化客户列表访问权限及新增备注字段
- 修改客户添加页面,新增“备注”输入框,支持录入客户备注信息 - 调整环境配置,统一开发、生产、测试环境的API_BASE_URL为正式地址 - 在shopDealerApply模型中新增receptionistId字段,用于查询分配的客户 - 优化客户列表权限逻辑,改为登录即可查看,不再限制角色 - 更新接口调用参数,支持查询当前登录用户提交及分配的客户 - 移除对管理员角色的特殊判断,使权限逻辑更简洁 - UI调整,未登录时显示“请先登录”提示而非“没有查看权限”
This commit is contained in:
@@ -35,5 +35,5 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"lastUpdated": 1776331561536
|
"lastUpdated": 1776332994640
|
||||||
}
|
}
|
||||||
@@ -2,22 +2,22 @@
|
|||||||
export const ENV_CONFIG = {
|
export const ENV_CONFIG = {
|
||||||
// 开发环境
|
// 开发环境
|
||||||
development: {
|
development: {
|
||||||
// API_BASE_URL: 'https://mp-api.websoft.top/api',
|
API_BASE_URL: 'https://mp-api.websoft.top/api',
|
||||||
API_BASE_URL: 'http://127.0.0.1:9200/api',
|
// API_BASE_URL: 'http://127.0.0.1:9200/api',
|
||||||
APP_NAME: '开发环境',
|
APP_NAME: '开发环境',
|
||||||
DEBUG: 'true',
|
DEBUG: 'true',
|
||||||
},
|
},
|
||||||
// 生产环境
|
// 生产环境
|
||||||
production: {
|
production: {
|
||||||
// API_BASE_URL: 'https://mp-api.websoft.top/api',
|
API_BASE_URL: 'https://mp-api.websoft.top/api',
|
||||||
API_BASE_URL: 'http://127.0.0.1:9200/api',
|
// API_BASE_URL: 'http://127.0.0.1:9200/api',
|
||||||
APP_NAME: '南南佐顿门窗',
|
APP_NAME: '南南佐顿门窗',
|
||||||
DEBUG: 'false',
|
DEBUG: 'false',
|
||||||
},
|
},
|
||||||
// 测试环境
|
// 测试环境
|
||||||
test: {
|
test: {
|
||||||
// API_BASE_URL: 'https://mp-api.websoft.top/api',
|
API_BASE_URL: 'https://mp-api.websoft.top/api',
|
||||||
API_BASE_URL: 'http://127.0.0.1:9200/api',
|
// API_BASE_URL: 'http://127.0.0.1:9200/api',
|
||||||
APP_NAME: '测试环境',
|
APP_NAME: '测试环境',
|
||||||
DEBUG: 'true',
|
DEBUG: 'true',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,4 +66,5 @@ export interface ShopDealerApplyParam extends PageParam {
|
|||||||
userId?: number;
|
userId?: number;
|
||||||
keywords?: string;
|
keywords?: string;
|
||||||
applyStatus?: number; // 申请状态筛选 (10待审核 20审核通过 30驳回)
|
applyStatus?: number; // 申请状态筛选 (10待审核 20审核通过 30驳回)
|
||||||
|
receptionistId?: number; // 接待人员用户ID(用于查询分配给自己的客户)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1138,6 +1138,9 @@ const AddShopDealerApply = () => {
|
|||||||
<Form.Item name="mobile" label="手机号" initialValue={FormData?.mobile} required>
|
<Form.Item name="mobile" label="手机号" initialValue={FormData?.mobile} required>
|
||||||
<Input placeholder="手机号" disabled={isEditMode} maxLength={11}/>
|
<Input placeholder="手机号" disabled={isEditMode} maxLength={11}/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="comments" label="备注" initialValue={FormData?.comments}>
|
||||||
|
<Input placeholder="请输入备注信息" />
|
||||||
|
</Form.Item>
|
||||||
{isEditMode && (
|
{isEditMode && (
|
||||||
<>
|
<>
|
||||||
<Form.Item name="money" label="签约价格" initialValue={FormData?.money} required>
|
<Form.Item name="money" label="签约价格" initialValue={FormData?.money} required>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {useState, useEffect, useCallback, useRef} from 'react'
|
import {useState, useEffect, useCallback} from 'react'
|
||||||
import {View, Text} from '@tarojs/components'
|
import {View, Text} from '@tarojs/components'
|
||||||
import Taro, {useDidShow} from '@tarojs/taro'
|
import Taro, {useDidShow} from '@tarojs/taro'
|
||||||
import {Loading, InfiniteLoading, Empty, Space, Tabs, TabPane, Tag, Button, SearchBar} from '@nutui/nutui-react-taro'
|
import {Loading, InfiniteLoading, Empty, Space, Tabs, TabPane, Tag, Button, SearchBar} from '@nutui/nutui-react-taro'
|
||||||
@@ -33,24 +33,10 @@ const CustomerIndex = () => {
|
|||||||
const [page, setPage] = useState(1)
|
const [page, setPage] = useState(1)
|
||||||
const [hasMore, setHasMore] = useState(true)
|
const [hasMore, setHasMore] = useState(true)
|
||||||
|
|
||||||
// 非分销商不允许查看客户列表
|
// 权限检查:只要登录就能查看客户列表
|
||||||
const {user, hasRole, loading: userLoading} = useUser()
|
const {user, loading: userLoading} = useUser()
|
||||||
// 管理员允许查看全部;普通分销商仅查看自己
|
|
||||||
const isAdminUser = user?.isAdmin === true
|
|
||||||
const canView = hasRole('dealer') || isAdminUser
|
|
||||||
const roleCheckFinished = !userLoading
|
const roleCheckFinished = !userLoading
|
||||||
const noPermissionShownRef = useRef(false)
|
const isLoggedIn = roleCheckFinished && user !== null
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!roleCheckFinished || canView) return
|
|
||||||
if (noPermissionShownRef.current) return
|
|
||||||
noPermissionShownRef.current = true
|
|
||||||
Taro.showToast({
|
|
||||||
title: '没有查看权限',
|
|
||||||
icon: 'none',
|
|
||||||
duration: 1500
|
|
||||||
})
|
|
||||||
}, [roleCheckFinished, canView])
|
|
||||||
|
|
||||||
// Tab配置
|
// Tab配置
|
||||||
const tabList = getStatusOptions();
|
const tabList = getStatusOptions();
|
||||||
@@ -201,14 +187,13 @@ const CustomerIndex = () => {
|
|||||||
const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0;
|
const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0;
|
||||||
|
|
||||||
// 构建API参数,根据状态筛选
|
// 构建API参数,根据状态筛选
|
||||||
|
// 查看自己提交的(userId)或分配给自己的(receptionistId)的客户
|
||||||
const params: any = {
|
const params: any = {
|
||||||
type: 4,
|
type: 4,
|
||||||
page: currentPage
|
page: currentPage,
|
||||||
|
userId: currentUserId,
|
||||||
|
receptionistId: currentUserId
|
||||||
};
|
};
|
||||||
// 非管理员:只看自己添加的客户
|
|
||||||
if (!isAdminUser && currentUserId > 0) {
|
|
||||||
params.userId = currentUserId;
|
|
||||||
}
|
|
||||||
const applyStatus = mapCustomerStatusToApplyStatus(statusFilter || activeTab);
|
const applyStatus = mapCustomerStatusToApplyStatus(statusFilter || activeTab);
|
||||||
if (applyStatus !== undefined) {
|
if (applyStatus !== undefined) {
|
||||||
params.applyStatus = applyStatus;
|
params.applyStatus = applyStatus;
|
||||||
@@ -251,7 +236,7 @@ const CustomerIndex = () => {
|
|||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [activeTab, page, isAdminUser, user?.userId]);
|
}, [activeTab, page, user?.userId]);
|
||||||
|
|
||||||
const reloadMore = async () => {
|
const reloadMore = async () => {
|
||||||
if (loading || !hasMore) return; // 防止重复加载
|
if (loading || !hasMore) return; // 防止重复加载
|
||||||
@@ -300,11 +285,11 @@ const CustomerIndex = () => {
|
|||||||
const fetchStatusCounts = useCallback(async () => {
|
const fetchStatusCounts = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0;
|
const currentUserId = Number(Taro.getStorageSync('UserId')) || user?.userId || 0;
|
||||||
const baseParams: any = {type: 4};
|
const baseParams: any = {
|
||||||
// 非管理员:只统计自己添加的客户
|
type: 4,
|
||||||
if (!isAdminUser && currentUserId > 0) {
|
userId: currentUserId,
|
||||||
baseParams.userId = currentUserId;
|
receptionistId: currentUserId
|
||||||
}
|
};
|
||||||
|
|
||||||
// 并行获取各状态的数量
|
// 并行获取各状态的数量
|
||||||
const [allRes, pendingRes, signedRes, cancelledRes] = await Promise.all([
|
const [allRes, pendingRes, signedRes, cancelledRes] = await Promise.all([
|
||||||
@@ -323,7 +308,7 @@ const CustomerIndex = () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取状态统计失败:', error);
|
console.error('获取状态统计失败:', error);
|
||||||
}
|
}
|
||||||
}, [isAdminUser, user?.userId]);
|
}, [user?.userId]);
|
||||||
|
|
||||||
const getStatusCounts = () => statusCounts;
|
const getStatusCounts = () => statusCounts;
|
||||||
|
|
||||||
@@ -364,22 +349,22 @@ const CustomerIndex = () => {
|
|||||||
|
|
||||||
// 初始化统计数据
|
// 初始化统计数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!roleCheckFinished || !canView) return;
|
if (!isLoggedIn) return;
|
||||||
fetchStatusCounts().then();
|
fetchStatusCounts().then();
|
||||||
}, [roleCheckFinished, canView]);
|
}, [isLoggedIn]);
|
||||||
|
|
||||||
// 当activeTab变化时重新获取数据
|
// 当activeTab变化时重新获取数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!roleCheckFinished || !canView) return;
|
if (!isLoggedIn) return;
|
||||||
setList([]); // 清空列表
|
setList([]); // 清空列表
|
||||||
setPage(1); // 重置页码
|
setPage(1); // 重置页码
|
||||||
setHasMore(true); // 重置加载状态
|
setHasMore(true); // 重置加载状态
|
||||||
fetchCustomerData(activeTab, true);
|
fetchCustomerData(activeTab, true);
|
||||||
}, [activeTab, roleCheckFinished, canView]);
|
}, [activeTab, isLoggedIn]);
|
||||||
|
|
||||||
// 监听页面显示,当从其他页面返回时刷新数据
|
// 监听页面显示,当从其他页面返回时刷新数据
|
||||||
useDidShow(() => {
|
useDidShow(() => {
|
||||||
if (!roleCheckFinished || !canView) return;
|
if (!isLoggedIn) return;
|
||||||
// 刷新当前tab的数据和统计信息
|
// 刷新当前tab的数据和统计信息
|
||||||
setList([]);
|
setList([]);
|
||||||
setPage(1);
|
setPage(1);
|
||||||
@@ -593,10 +578,11 @@ const CustomerIndex = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canView) {
|
// 未登录时显示提示
|
||||||
|
if (!isLoggedIn) {
|
||||||
return (
|
return (
|
||||||
<View className="bg-white flex flex-col items-center justify-center p-4">
|
<View className="bg-white flex flex-col items-center justify-center p-4">
|
||||||
<Empty description="没有查看权限"/>
|
<Empty description="请先登录"/>
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
style={{marginTop: '12px'}}
|
style={{marginTop: '12px'}}
|
||||||
|
|||||||
Reference in New Issue
Block a user