|
|
@@ -16,27 +16,21 @@ import { fileClient } from '@/client/api';
|
|
|
import type { InferResponseType, InferRequestType } from 'hono/client';
|
|
|
import dayjs from 'dayjs';
|
|
|
import { uploadMinIOWithPolicy } from '@/client/utils/minio';
|
|
|
+import { UpdateFileDto } from '@/server/modules/files/file.schema';
|
|
|
import * as z from 'zod';
|
|
|
|
|
|
// 定义类型
|
|
|
type FileItem = InferResponseType<typeof fileClient.$get, 200>['data'][0];
|
|
|
type FileListResponse = InferResponseType<typeof fileClient.$get, 200>;
|
|
|
type UpdateFileRequest = InferRequestType<typeof fileClient[':id']['$put']>['json'];
|
|
|
-
|
|
|
-// 表单验证schema
|
|
|
-const fileFormSchema = z.object({
|
|
|
- name: z.string().min(1, '文件名称不能为空'),
|
|
|
- description: z.string().optional(),
|
|
|
-});
|
|
|
-
|
|
|
-type FileFormData = z.infer<typeof fileFormSchema>;
|
|
|
+type FileFormData = z.infer<typeof UpdateFileDto>;
|
|
|
|
|
|
export const FilesPage: React.FC = () => {
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
const [editingFile, setEditingFile] = useState<FileItem | null>(null);
|
|
|
const [searchText, setSearchText] = useState('');
|
|
|
const [pagination, setPagination] = useState({
|
|
|
- page: 1,
|
|
|
+ current: 1,
|
|
|
pageSize: 10,
|
|
|
total: 0,
|
|
|
});
|
|
|
@@ -47,7 +41,7 @@ export const FilesPage: React.FC = () => {
|
|
|
|
|
|
// 表单初始化
|
|
|
const form = useForm<FileFormData>({
|
|
|
- resolver: zodResolver(fileFormSchema),
|
|
|
+ resolver: zodResolver(UpdateFileDto),
|
|
|
defaultValues: {
|
|
|
name: '',
|
|
|
description: '',
|
|
|
@@ -88,8 +82,8 @@ export const FilesPage: React.FC = () => {
|
|
|
};
|
|
|
|
|
|
const { data, isLoading, error } = useQuery({
|
|
|
- queryKey: ['files', pagination.page, pagination.pageSize, searchText],
|
|
|
- queryFn: () => fetchFiles({ page: pagination.page, pageSize: pagination.pageSize }),
|
|
|
+ queryKey: ['files', pagination.current, pagination.pageSize, searchText],
|
|
|
+ queryFn: () => fetchFiles({ page: pagination.current, pageSize: pagination.pageSize }),
|
|
|
});
|
|
|
|
|
|
// 更新文件记录
|
|
|
@@ -207,7 +201,7 @@ export const FilesPage: React.FC = () => {
|
|
|
};
|
|
|
|
|
|
const handleSearch = () => {
|
|
|
- setPagination({ ...pagination, page: 1 });
|
|
|
+ setPagination({ ...pagination, current: 1 });
|
|
|
};
|
|
|
|
|
|
// 格式化文件大小
|
|
|
@@ -366,27 +360,27 @@ export const FilesPage: React.FC = () => {
|
|
|
{tablePagination.total > 0 && (
|
|
|
<div className="flex justify-between items-center mt-4">
|
|
|
<div className="text-sm text-gray-600">
|
|
|
- 显示 {((tablePagination.page - 1) * tablePagination.pageSize + 1)}-
|
|
|
- {Math.min(tablePagination.page * tablePagination.pageSize, tablePagination.total)} 条,
|
|
|
+ 显示 {((tablePagination.current - 1) * tablePagination.pageSize + 1)}-
|
|
|
+ {Math.min(tablePagination.current * tablePagination.pageSize, tablePagination.total)} 条,
|
|
|
共 {tablePagination.total} 条
|
|
|
</div>
|
|
|
<div className="flex gap-2">
|
|
|
<Button
|
|
|
variant="outline"
|
|
|
size="sm"
|
|
|
- disabled={tablePagination.page <= 1}
|
|
|
- onClick={() => setPagination({ ...pagination, page: tablePagination.page - 1 })}
|
|
|
+ disabled={tablePagination.current <= 1}
|
|
|
+ onClick={() => setPagination({ ...pagination, current: tablePagination.current - 1 })}
|
|
|
>
|
|
|
上一页
|
|
|
</Button>
|
|
|
<span className="px-3 py-1 text-sm">
|
|
|
- 第 {tablePagination.page} 页
|
|
|
+ 第 {tablePagination.current} 页
|
|
|
</span>
|
|
|
<Button
|
|
|
variant="outline"
|
|
|
size="sm"
|
|
|
- disabled={tablePagination.page >= Math.ceil(tablePagination.total / tablePagination.pageSize)}
|
|
|
- onClick={() => setPagination({ ...pagination, page: tablePagination.page + 1 })}
|
|
|
+ disabled={tablePagination.current >= Math.ceil(tablePagination.total / tablePagination.pageSize)}
|
|
|
+ onClick={() => setPagination({ ...pagination, current: tablePagination.current + 1 })}
|
|
|
>
|
|
|
下一页
|
|
|
</Button>
|