|
@@ -5,7 +5,7 @@ import {
|
|
|
} from 'antd';
|
|
} from 'antd';
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
import dayjs from 'dayjs';
|
|
import dayjs from 'dayjs';
|
|
|
-import { UserAPI } from './api/index.ts';
|
|
|
|
|
|
|
+import * as UserAPI from './api/users.ts';
|
|
|
|
|
|
|
|
const { Title } = Typography;
|
|
const { Title } = Typography;
|
|
|
|
|
|
|
@@ -20,6 +20,7 @@ export const UsersPage = () => {
|
|
|
const [modalTitle, setModalTitle] = useState('');
|
|
const [modalTitle, setModalTitle] = useState('');
|
|
|
const [editingUser, setEditingUser] = useState<any>(null);
|
|
const [editingUser, setEditingUser] = useState<any>(null);
|
|
|
const [form] = Form.useForm();
|
|
const [form] = Form.useForm();
|
|
|
|
|
+ const [convertingId, setConvertingId] = useState<number | null>(null);
|
|
|
|
|
|
|
|
const { data: usersData, isLoading, refetch } = useQuery({
|
|
const { data: usersData, isLoading, refetch } = useQuery({
|
|
|
queryKey: ['users', searchParams],
|
|
queryKey: ['users', searchParams],
|
|
@@ -104,6 +105,21 @@ export const UsersPage = () => {
|
|
|
message.error('删除失败,请重试');
|
|
message.error('删除失败,请重试');
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ // 处理转为学员
|
|
|
|
|
+ const handleConvertToStudent = async (id: number) => {
|
|
|
|
|
+ setConvertingId(id);
|
|
|
|
|
+ try {
|
|
|
|
|
+ await UserAPI.convertToStudent(id);
|
|
|
|
|
+ message.success('用户已转为学员');
|
|
|
|
|
+ refetch(); // 刷新用户列表
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('转为学员失败:', error);
|
|
|
|
|
+ message.error('操作失败,请重试');
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ setConvertingId(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
const columns = [
|
|
const columns = [
|
|
|
{
|
|
{
|
|
@@ -137,6 +153,12 @@ export const UsersPage = () => {
|
|
|
key: 'created_at',
|
|
key: 'created_at',
|
|
|
render: (date: string) => dayjs(date).format('YYYY-MM-DD HH:mm:ss'),
|
|
render: (date: string) => dayjs(date).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ title: '有效期至',
|
|
|
|
|
+ dataIndex: 'expires_at',
|
|
|
|
|
+ key: 'expires_at',
|
|
|
|
|
+ render: (date: string) => date ? dayjs(date).format('YYYY-MM-DD') : '永久',
|
|
|
|
|
+ },
|
|
|
{
|
|
{
|
|
|
title: '操作',
|
|
title: '操作',
|
|
|
key: 'action',
|
|
key: 'action',
|
|
@@ -145,16 +167,27 @@ export const UsersPage = () => {
|
|
|
<Button type="link" onClick={() => showEditModal(record)}>
|
|
<Button type="link" onClick={() => showEditModal(record)}>
|
|
|
编辑
|
|
编辑
|
|
|
</Button>
|
|
</Button>
|
|
|
- <Popconfirm
|
|
|
|
|
- title="确定要删除此用户吗?"
|
|
|
|
|
- onConfirm={() => handleDelete(record.id)}
|
|
|
|
|
- okText="确定"
|
|
|
|
|
- cancelText="取消"
|
|
|
|
|
- >
|
|
|
|
|
- <Button type="link" danger>
|
|
|
|
|
- 删除
|
|
|
|
|
|
|
+ {record.role === 'admin' && (
|
|
|
|
|
+ <Popconfirm
|
|
|
|
|
+ title="确定要删除此用户吗?"
|
|
|
|
|
+ onConfirm={() => handleDelete(record.id)}
|
|
|
|
|
+ okText="确定"
|
|
|
|
|
+ cancelText="取消"
|
|
|
|
|
+ >
|
|
|
|
|
+ <Button type="link" danger>
|
|
|
|
|
+ 删除
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </Popconfirm>
|
|
|
|
|
+ )}
|
|
|
|
|
+ {record.role !== 'student' && (
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="link"
|
|
|
|
|
+ onClick={() => handleConvertToStudent(record.id)}
|
|
|
|
|
+ loading={convertingId === record.id}
|
|
|
|
|
+ >
|
|
|
|
|
+ 转为学员
|
|
|
</Button>
|
|
</Button>
|
|
|
- </Popconfirm>
|
|
|
|
|
|
|
+ )}
|
|
|
</Space>
|
|
</Space>
|
|
|
),
|
|
),
|
|
|
},
|
|
},
|