功能:增加平台账号管理与管理员保护

This commit is contained in:
yml2213
2026-08-13 12:52:50 +08:00
parent 8c47b961e1
commit 2b3a1b111b
8 changed files with 167 additions and 10 deletions
+2
View File
@@ -12,6 +12,7 @@ import MerchantCenter from './pages/MerchantCenter'
import MerchantRecharge from './pages/MerchantRecharge'
import AlertSettings from './pages/AlertSettings'
import PlatformMerchants from './pages/PlatformMerchants'
import PlatformUsers from './pages/PlatformUsers'
import type { ReactNode } from 'react'
function PrivateRoute({ children }: { children: ReactNode }) {
const { token } = useAuth()
@@ -85,6 +86,7 @@ function AppRoutes() {
</AdminRoute>
}
/>
<Route path="platform-users" element={<AdminRoute><PlatformUsers /></AdminRoute>} />
<Route path="open-api" element={<MerchantPermissionRoute permission="api:manage"><OpenApiDocs /></MerchantPermissionRoute>} />
<Route
path="api-debug"
+2
View File
@@ -53,6 +53,8 @@ export const userApi = {
request.post('/users', data).then((r) => r.data.data as User),
updateStatus: (id: number, status: number) =>
request.patch(`/users/${id}/status`, { status }).then((r) => r.data.data),
remove: (id: number) =>
request.delete(`/users/${id}`).then((r) => r.data.data),
}
export const merchantApi = {
+7
View File
@@ -74,6 +74,12 @@ const adminSections: SidebarSection[] = [
icon: <ShopOutlined />,
children: [{ key: 'shop-list', label: '平台商户', path: '/platform-merchants' }],
},
{
key: 'accounts',
label: '账号管理',
icon: <UserOutlined />,
children: [{ key: 'platform-users', label: '平台账号', path: '/platform-users' }],
},
{
key: 'orders',
label: '订单管理',
@@ -180,6 +186,7 @@ function getSelectedKey(pathname: string, search: string) {
if (pathname.startsWith('/open-api')) return 'api-docs'
if (pathname.startsWith('/api-debug')) return 'api-debug'
if (pathname.startsWith('/platform-merchants')) return 'shop-list'
if (pathname.startsWith('/platform-users')) return 'platform-users'
return 'dashboard'
}
+64
View File
@@ -0,0 +1,64 @@
import { useCallback, useEffect, useState } from 'react'
import { Button, Popconfirm, Table, Tag, Typography, message } from 'antd'
import { DeleteOutlined, ReloadOutlined } from '@ant-design/icons'
import type { ColumnsType } from 'antd/es/table'
import { userApi } from '../api'
import { PageHeader } from '../components/PageHeader'
import type { PageResult, User } from '../types'
import { formatDateTime } from '../utils/time'
import { useAuth } from '../store/auth'
export default function PlatformUsers() {
const { user: currentUser } = useAuth()
const [data, setData] = useState<PageResult<User>>({ list: [], total: 0, page: 1, size: 20 })
const [loading, setLoading] = useState(false)
const load = useCallback(async (page = data.page, size = data.size) => {
setLoading(true)
try {
setData(await userApi.list({ page, size }))
} catch (e) {
message.error(e instanceof Error ? e.message : '加载失败')
} finally {
setLoading(false)
}
}, [data.page, data.size])
useEffect(() => {
void load()
}, [load])
const remove = async (record: User) => {
try {
await userApi.remove(record.id)
message.success('账号已删除')
load()
} catch (e) {
message.error(e instanceof Error ? e.message : '删除失败')
}
}
const columns: ColumnsType<User> = [
{ title: '用户名', dataIndex: 'username', width: 220, render: (value) => <Typography.Text strong>{value}</Typography.Text> },
{ title: '昵称', dataIndex: 'nickname', width: 180, render: (value) => value || '-' },
{ title: '账号类型', dataIndex: 'role', width: 140, render: (value) => <Tag color={value === 'admin' ? 'blue' : 'default'}>{value === 'admin' ? '平台管理员' : '商户账号'}</Tag> },
{ title: '状态', dataIndex: 'status', width: 100, render: (value) => value === 1 ? <Tag color="green"></Tag> : <Tag></Tag> },
{ title: '创建时间', dataIndex: 'created_at', width: 180, render: formatDateTime },
{
title: '操作',
width: 120,
render: (_, record) => record.id === currentUser?.id ? <Typography.Text type="secondary"></Typography.Text> : (
<Popconfirm title={`确认删除账号「${record.username}」?`} description="账号及其全部商户成员关系会被删除。" onConfirm={() => remove(record)} okButtonProps={{ danger: true }}>
<Button type="link" danger size="small" icon={<DeleteOutlined />}></Button>
</Popconfirm>
),
},
]
return (
<div>
<PageHeader title="账号管理" subtitle="管理平台管理员与商户登录账号;删除会同时解除该账号的商户成员关系。" breadcrumbs={[{ title: '账号管理' }]} extra={<Button icon={<ReloadOutlined />} loading={loading} onClick={() => load()}></Button>} />
<Table rowKey="id" loading={loading} columns={columns} dataSource={data.list} pagination={{ current: data.page, pageSize: data.size, total: data.total, showSizeChanger: true, onChange: (page, size) => load(page, size) }} />
</div>
)
}