From 78f94c0afae764d480ee4bde861474a18fcc43f0 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, 27 Oct 2025 15:40:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(user):=20=E6=B7=BB=E5=8A=A0=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6=E4=B8=8E=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入 useUser hook 获取用户信息 - 实现 hasRole 方法检查用户角色 - 根据角色动态显示用户身份标签 - 限制特定角色操作按钮的显示条件 - 移除旧的角色名称存储逻辑- 更新用户卡片中的角色显示方式为动态获取 --- src/hjm/location.tsx | 7 ++-- src/pages/user/components/UserCard.tsx | 46 ++++++++++++++++++++++---- src/user/userVerify/admin.tsx | 24 ++++++++++---- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/hjm/location.tsx b/src/hjm/location.tsx index c0d5b4a..926c5c0 100644 --- a/src/hjm/location.tsx +++ b/src/hjm/location.tsx @@ -57,8 +57,11 @@ const Location = () => { getHjmCarByCode(keywords).then(data => { console.log('执行搜索', data) setItem(data) - setLatitude(data.latitude) - setLongitude(data.longitude) + // setLatitude(data.latitude) + // setLongitude(data.longitude) + // wgs48坐标转gcj02坐标代 + + setKeywords(data.code) if (data.fence) { // 方法2:使用实际的 fence 数据(如果是字符串格式) diff --git a/src/pages/user/components/UserCard.tsx b/src/pages/user/components/UserCard.tsx index 12a4c28..0150825 100644 --- a/src/pages/user/components/UserCard.tsx +++ b/src/pages/user/components/UserCard.tsx @@ -8,7 +8,6 @@ import navTo from "@/utils/common"; function UserCard() { const [IsLogin, setIsLogin] = useState(false) const [userInfo, setUserInfo] = useState() - const [roleName, setRoleName] = useState('注册用户') useEffect(() => { @@ -51,11 +50,6 @@ function UserCard() { } }) } - // 判断身份 - const roleName = Taro.getStorageSync('RoleName'); - if(roleName){ - setRoleName(roleName) - } } }).catch(() => { console.log('未登录') @@ -98,6 +92,44 @@ function UserCard() { }); }; + // 获取用户显示的角色(同步版本) + const getRoleName = () => { + if(hasRole('superAdmin')){ + return '超级管理员'; + } + if(hasRole('admin')){ + return '管理员'; + } + if(hasRole('jiaojing')){ + return '交警'; + } + if(hasRole('youzheng')){ + return '邮政协会/管局'; + } + if(hasRole('Installer')){ + return '安装人员'; + } + if(hasRole('kuaidi')){ + return '快递公司'; + } + if(hasRole('zhandian')){ + return '快递站点'; + } + if(hasRole('kuaidiyuan')){ + return '快递员'; + } + return '注册用户'; + } + + + // 检查是否有特定角色 + const hasRole = (roleCode: string) => { + if (!userInfo || !userInfo.roles) { + return false; + } + return userInfo.roles.some(role => role.roleCode === roleCode); + }; + return ( <>
@@ -127,7 +159,7 @@ function UserCard() { {IsLogin ? ( -
{roleName || '注册用户'}
+
{getRoleName()}
{/*{*/} {/* userInfo?.organizationName && (*/} diff --git a/src/user/userVerify/admin.tsx b/src/user/userVerify/admin.tsx index 0ac71bf..1bc8924 100644 --- a/src/user/userVerify/admin.tsx +++ b/src/user/userVerify/admin.tsx @@ -13,6 +13,7 @@ import {UserVerify} from "@/api/system/userVerify/model"; import {pageUserVerify, updateUserVerify} from "@/api/system/userVerify"; import {listUserRole, updateUserRole} from "@/api/system/userRole"; import {listOrganizations} from "@/api/system/organization"; +import {useUser} from "@/hooks/useUser"; /** @@ -24,7 +25,9 @@ const UserVerifyAdmin: React.FC = () => { const [keywords, setKeywords] = useState('') // const [showTextArea, setShowTextArea] = useState(false) const [refreshing, setRefreshing] = useState(false) + const {user} = useUser() console.log(refreshing) + // 获取状态显示 const getStatusDisplay = (status?: number) => { switch (status) { @@ -92,6 +95,15 @@ const UserVerifyAdmin: React.FC = () => { setKeywords(value) } + // 检查是否有特定角色 + const hasRole = (roleCode: string) => { + if (!user || !user.roles) { + return false; + } + return user.roles.some(role => role.roleCode === roleCode); + }; + + const onPass = async (item: UserVerify) => { const role = await listUserRole({roleId: 1701,userId: item.userId}) const userRole = role[0]; @@ -305,12 +317,12 @@ const UserVerifyAdmin: React.FC = () => { }
)} - - - - - - + {Taro.getStorageSync('kuaidi') && ( + + + + + )} {/*{showTextArea && (*/} {/*