diff --git a/client/admin/pages_dashboard.tsx b/client/admin/pages_dashboard.tsx new file mode 100644 index 0000000..47cf2fb --- /dev/null +++ b/client/admin/pages_dashboard.tsx @@ -0,0 +1,44 @@ +import React from 'react'; +import { + Card, Row, Col, Typography, Statistic +} from 'antd'; + +const { Title } = Typography; + +// 仪表盘页面 +export const DashboardPage = () => { + return ( +
+ 仪表盘 + + + + + + + + + + + + + + + + + +
+ ); +}; \ No newline at end of file diff --git a/client/admin/pages_sys.tsx b/client/admin/pages_file_library.tsx similarity index 70% rename from client/admin/pages_sys.tsx rename to client/admin/pages_file_library.tsx index dacae58..81fe93f 100644 --- a/client/admin/pages_sys.tsx +++ b/client/admin/pages_file_library.tsx @@ -1,11 +1,8 @@ import React, { useState, useEffect } from 'react'; import { - Layout, Menu, Button, Table, Space, - Form, Input, Select, message, Modal, - Card, Spin, Row, Col, Breadcrumb, Avatar, - Dropdown, ConfigProvider, theme, Typography, - Switch, Badge, Image, Upload, Divider, Descriptions, - Popconfirm, Tag, Statistic, DatePicker, Radio, Progress, Tabs, List, Alert, Collapse, Empty, Drawer + Button, Table, Space, Form, Input, Select, + message, Modal, Card, Typography, Tag, Popconfirm, + Tabs, Image, Upload, Descriptions } from 'antd'; import { UploadOutlined, @@ -14,336 +11,17 @@ import { FileWordOutlined, FilePdfOutlined, FileOutlined, -} from '@ant-design/icons'; -import { - useQuery, -} from '@tanstack/react-query'; +} from '@ant-design/icons'; +import { useQuery } from '@tanstack/react-query'; import dayjs from 'dayjs'; -import weekday from 'dayjs/plugin/weekday'; -import localeData from 'dayjs/plugin/localeData'; -import { uploadMinIOWithPolicy,uploadOSSWithPolicy } from '@d8d-appcontainer/api'; +import { uploadMinIOWithPolicy, uploadOSSWithPolicy } from '@d8d-appcontainer/api'; import type { MinioUploadPolicy, OSSUploadPolicy } from '@d8d-appcontainer/types'; -import 'dayjs/locale/zh-cn'; -import type { - FileLibrary, FileCategory -} from '../share/types.ts'; - -import { - OssType, -} from '../share/types.ts'; - - -import { FileAPI , UserAPI } from './api/index.ts'; - - -// 配置 dayjs 插件 -dayjs.extend(weekday); -dayjs.extend(localeData); - -// 设置 dayjs 语言 -dayjs.locale('zh-cn'); +import { FileAPI } from './api/index.ts'; +import type { FileLibrary, FileCategory } from '../share/types.ts'; +import { OssType } from '../share/types.ts'; const { Title } = Typography; - -// 仪表盘页面 -export const DashboardPage = () => { - return ( -
- 仪表盘 - - - - - - - - - - - - - - - - - -
- ); -}; - -// 用户管理页面 -export const UsersPage = () => { - const [searchParams, setSearchParams] = useState({ - page: 1, - limit: 10, - search: '' - }); - const [modalVisible, setModalVisible] = useState(false); - const [modalTitle, setModalTitle] = useState(''); - const [editingUser, setEditingUser] = useState(null); - const [form] = Form.useForm(); - - const { data: usersData, isLoading, refetch } = useQuery({ - queryKey: ['users', searchParams], - queryFn: async () => { - return await UserAPI.getUsers(searchParams); - } - }); - - const users = usersData?.data || []; - const pagination = { - current: searchParams.page, - pageSize: searchParams.limit, - total: usersData?.pagination?.total || 0 - }; - - // 处理搜索 - const handleSearch = (values: any) => { - setSearchParams(prev => ({ - ...prev, - search: values.search || '', - page: 1 - })); - }; - - // 处理分页变化 - const handleTableChange = (newPagination: any) => { - setSearchParams(prev => ({ - ...prev, - page: newPagination.current, - limit: newPagination.pageSize - })); - }; - - // 打开创建用户模态框 - const showCreateModal = () => { - setModalTitle('创建用户'); - setEditingUser(null); - form.resetFields(); - setModalVisible(true); - }; - - // 打开编辑用户模态框 - const showEditModal = (user: any) => { - setModalTitle('编辑用户'); - setEditingUser(user); - form.setFieldsValue(user); - setModalVisible(true); - }; - - // 处理模态框确认 - const handleModalOk = async () => { - try { - const values = await form.validateFields(); - - if (editingUser) { - // 编辑用户 - await UserAPI.updateUser(editingUser.id, values); - message.success('用户更新成功'); - } else { - // 创建用户 - await UserAPI.createUser(values); - message.success('用户创建成功'); - } - - setModalVisible(false); - form.resetFields(); - refetch(); // 刷新用户列表 - } catch (error) { - console.error('表单提交失败:', error); - message.error('操作失败,请重试'); - } - }; - - // 处理删除用户 - const handleDelete = async (id: number) => { - try { - await UserAPI.deleteUser(id); - message.success('用户删除成功'); - refetch(); // 刷新用户列表 - } catch (error) { - console.error('删除用户失败:', error); - message.error('删除失败,请重试'); - } - }; - - const columns = [ - { - title: '用户名', - dataIndex: 'username', - key: 'username', - }, - { - title: '昵称', - dataIndex: 'nickname', - key: 'nickname', - }, - { - title: '邮箱', - dataIndex: 'email', - key: 'email', - }, - { - title: '角色', - dataIndex: 'role', - key: 'role', - render: (role: string) => ( - - {role === 'admin' ? '管理员' : '普通用户'} - - ), - }, - { - title: '创建时间', - dataIndex: 'created_at', - key: 'created_at', - render: (date: string) => dayjs(date).format('YYYY-MM-DD HH:mm:ss'), - }, - { - title: '操作', - key: 'action', - render: (_: any, record: any) => ( - - - handleDelete(record.id)} - okText="确定" - cancelText="取消" - > - - - - ), - }, - ]; - - return ( -
- 用户管理 - -
- - - - - - - - - -
- - `共 ${total} 条记录` - }} - onChange={handleTableChange} - /> - - - {/* 创建/编辑用户模态框 */} - { - setModalVisible(false); - form.resetFields(); - }} - width={600} - > -
- - - - - - - - - - - - - {!editingUser && ( - - - - )} - - - - - -
- - ); -}; - // 文件库管理页面 export const FileLibraryPage = () => { const [loading, setLoading] = useState(false); diff --git a/client/admin/pages_users.tsx b/client/admin/pages_users.tsx new file mode 100644 index 0000000..4040f81 --- /dev/null +++ b/client/admin/pages_users.tsx @@ -0,0 +1,270 @@ +import React, { useState } from 'react'; +import { + Button, Table, Space, Form, Input, Select, + message, Modal, Card, Typography, Tag, Popconfirm +} from 'antd'; +import { useQuery } from '@tanstack/react-query'; +import dayjs from 'dayjs'; +import { UserAPI } from './api/index.ts'; + +const { Title } = Typography; + +// 用户管理页面 +export const UsersPage = () => { + const [searchParams, setSearchParams] = useState({ + page: 1, + limit: 10, + search: '' + }); + const [modalVisible, setModalVisible] = useState(false); + const [modalTitle, setModalTitle] = useState(''); + const [editingUser, setEditingUser] = useState(null); + const [form] = Form.useForm(); + + const { data: usersData, isLoading, refetch } = useQuery({ + queryKey: ['users', searchParams], + queryFn: async () => { + return await UserAPI.getUsers(searchParams); + } + }); + + const users = usersData?.data || []; + const pagination = { + current: searchParams.page, + pageSize: searchParams.limit, + total: usersData?.pagination?.total || 0 + }; + + // 处理搜索 + const handleSearch = (values: any) => { + setSearchParams(prev => ({ + ...prev, + search: values.search || '', + page: 1 + })); + }; + + // 处理分页变化 + const handleTableChange = (newPagination: any) => { + setSearchParams(prev => ({ + ...prev, + page: newPagination.current, + limit: newPagination.pageSize + })); + }; + + // 打开创建用户模态框 + const showCreateModal = () => { + setModalTitle('创建用户'); + setEditingUser(null); + form.resetFields(); + setModalVisible(true); + }; + + // 打开编辑用户模态框 + const showEditModal = (user: any) => { + setModalTitle('编辑用户'); + setEditingUser(user); + form.setFieldsValue(user); + setModalVisible(true); + }; + + // 处理模态框确认 + const handleModalOk = async () => { + try { + const values = await form.validateFields(); + + if (editingUser) { + // 编辑用户 + await UserAPI.updateUser(editingUser.id, values); + message.success('用户更新成功'); + } else { + // 创建用户 + await UserAPI.createUser(values); + message.success('用户创建成功'); + } + + setModalVisible(false); + form.resetFields(); + refetch(); // 刷新用户列表 + } catch (error) { + console.error('表单提交失败:', error); + message.error('操作失败,请重试'); + } + }; + + // 处理删除用户 + const handleDelete = async (id: number) => { + try { + await UserAPI.deleteUser(id); + message.success('用户删除成功'); + refetch(); // 刷新用户列表 + } catch (error) { + console.error('删除用户失败:', error); + message.error('删除失败,请重试'); + } + }; + + const columns = [ + { + title: '用户名', + dataIndex: 'username', + key: 'username', + }, + { + title: '昵称', + dataIndex: 'nickname', + key: 'nickname', + }, + { + title: '邮箱', + dataIndex: 'email', + key: 'email', + }, + { + title: '角色', + dataIndex: 'role', + key: 'role', + render: (role: string) => ( + + {role === 'admin' ? '管理员' : '普通用户'} + + ), + }, + { + title: '创建时间', + dataIndex: 'created_at', + key: 'created_at', + render: (date: string) => dayjs(date).format('YYYY-MM-DD HH:mm:ss'), + }, + { + title: '操作', + key: 'action', + render: (_: any, record: any) => ( + + + handleDelete(record.id)} + okText="确定" + cancelText="取消" + > + + + + ), + }, + ]; + + return ( +
+ 用户管理 + +
+ + + + + + + + + + + +
`共 ${total} 条记录` + }} + onChange={handleTableChange} + /> + + + {/* 创建/编辑用户模态框 */} + { + setModalVisible(false); + form.resetFields(); + }} + width={600} + > +
+ + + + + + + + + + + + + {!editingUser && ( + + + + )} + + + + + +
+ + ); +}; \ No newline at end of file diff --git a/client/admin/web_app.tsx b/client/admin/web_app.tsx index 1726e7b..f89e5d5 100644 --- a/client/admin/web_app.tsx +++ b/client/admin/web_app.tsx @@ -55,10 +55,14 @@ import { } from './hooks_sys.tsx'; import { - DashboardPage, - UsersPage, + DashboardPage +} from './pages_dashboard.tsx'; +import { + UsersPage +} from './pages_users.tsx'; +import { FileLibraryPage -} from './pages_sys.tsx'; +} from './pages_file_library.tsx'; import { KnowInfoPage } from './pages_know_info.tsx'; import { MessagesPage } from './pages_messages.tsx'; import {SettingsPage } from './pages_settings.tsx';