refactor(admin): 重构用户管理页面实现

- 将原有经销商团队页面重构为用户管理页面
- 集成分页用户查询功能替代原有团队数据获取
- 添加搜索栏和下拉刷新功能
- 实现无限滚动加载用户数据
- 添加用户角色显示和切换功能
- 优化页面布局和用户体验
- 移除原有的经销商相关代码逻辑refactor(admin): 重构用户管理页面实现角色切换功能

- 将原经销商团队页面重构为系统用户管理页面
- 集成分页用户列表查询功能
- 实现下拉刷新和无限滚动加载
- 添加用户搜索和筛选功能
- 实现用户角色切换功能
- 优化用户列表展示界面和交互体验
- 移除原有的经销商相关统计功能
- 统一使用Taro框架进行页面开发
- 修复系统角色API参数传递问题
This commit is contained in:
2026-03-09 16:15:30 +08:00
parent d1fa0f3ec0
commit a834f88aaa

View File

@@ -1,4 +1,4 @@
import {useEffect, useRef, useState} from 'react' import {useRef, useState} from 'react'
import Taro, {useDidShow} from '@tarojs/taro' import Taro, {useDidShow} from '@tarojs/taro'
import {View, Text} from '@tarojs/components' import {View, Text} from '@tarojs/components'
import { import {
@@ -14,6 +14,7 @@ import {
import type {User} from '@/api/system/user/model' import type {User} from '@/api/system/user/model'
import {pageUsers} from '@/api/system/user' import {pageUsers} from '@/api/system/user'
import {listUserRole, updateUserRole} from '@/api/system/userRole' import {listUserRole, updateUserRole} from '@/api/system/userRole'
import {listRoles} from '@/api/system/role'
const PAGE_SIZE = 10 const PAGE_SIZE = 10
@@ -26,7 +27,21 @@ const AdminUsers = () => {
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const [total, setTotal] = useState(0) const [total, setTotal] = useState(0)
const rolesLoadedRef = useRef(false) const roleIdMapRef = useRef<Record<string, number>>({})
const roleMapLoadedRef = useRef(false)
const getRoleIdByCode = async (roleCode: string) => {
if (!roleMapLoadedRef.current) {
const roles = await listRoles()
const nextMap: Record<string, number> = {}
roles?.forEach(role => {
if (role.roleCode && role.roleId) nextMap[role.roleCode] = role.roleId
})
roleIdMapRef.current = nextMap
roleMapLoadedRef.current = true
}
return roleIdMapRef.current[roleCode]
}
const reload = async (isRefresh = false, overrideKeywords?: string) => { const reload = async (isRefresh = false, overrideKeywords?: string) => {
if (loading) return if (loading) return
@@ -92,7 +107,8 @@ const AdminUsers = () => {
const toggleRole = async (target: User) => { const toggleRole = async (target: User) => {
const current = getPrimaryRoleCode(target) const current = getPrimaryRoleCode(target)
const nextRoleName = current === 'dealer' ? '注册会员' : '业务员' const nextRoleCode = current === 'dealer' ? 'user' : 'dealer'
const nextRoleName = nextRoleCode === 'user' ? '注册会员' : '业务员'
const confirmRes = await Taro.showModal({ const confirmRes = await Taro.showModal({
title: '确认切换角色', title: '确认切换角色',
@@ -104,18 +120,23 @@ const AdminUsers = () => {
const userId = target.userId const userId = target.userId
if (!userId) return if (!userId) return
const nextRoleId = await getRoleIdByCode(nextRoleCode)
if (!nextRoleId) {
throw new Error(`未找到角色配置:${nextRoleCode}`)
}
const roles = await listUserRole({userId}) const roles = await listUserRole({userId})
const candidate = roles?.find(r => r.roleCode === 'dealer' || r.roleCode === 'user') || roles?.[0] const candidate = roles?.find(r => r.roleCode === 'dealer' || r.roleCode === 'user')
if (candidate) { if (candidate) {
await updateUserRole({ await updateUserRole({
...candidate, ...candidate,
roleId: 1935 roleId: nextRoleId
}) })
} else { } else {
await updateUserRole({ await updateUserRole({
userId, userId,
roleId: 1915 roleId: nextRoleId
}) })
} }
@@ -129,7 +150,7 @@ const AdminUsers = () => {
const handleSearch = (value: string) => { const handleSearch = (value: string) => {
setSearchValue(value) setSearchValue(value)
reload(true, undefined).then() reload(true, value).then()
} }
const loadMore = async () => { const loadMore = async () => {
@@ -150,12 +171,6 @@ const AdminUsers = () => {
init().then() init().then()
}) })
useEffect(() => {
if (!rolesLoadedRef.current) return
reload(true).then()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchValue])
return ( return (
<View className="bg-gray-50 min-h-screen"> <View className="bg-gray-50 min-h-screen">