|
|
@@ -4,7 +4,7 @@ import { PlusOutlined, EditOutlined, DeleteOutlined, EyeOutlined, LinkOutlined }
|
|
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
import { homeIconClient } from '@/client/api';
|
|
|
import type { HomeIcon } from '@/server/modules/home/home-icon.entity';
|
|
|
-import type { File } from '@/server/modules/files/file.entity';
|
|
|
+import type { File as FileType } from '@/server/modules/files/file.entity';
|
|
|
import type { InferResponseType, InferRequestType } from 'hono/client';
|
|
|
import MinioUploader from '@/client/admin/components/MinioUploader';
|
|
|
|
|
|
@@ -21,13 +21,12 @@ const HomeIconsPage: React.FC = () => {
|
|
|
const [editingRecord, setEditingRecord] = useState<HomeIcon | null>(null);
|
|
|
const [form] = Form.useForm();
|
|
|
const queryClient = useQueryClient();
|
|
|
- const client = useClient();
|
|
|
|
|
|
// 获取图标列表
|
|
|
const { data: iconsData, isLoading } = useQuery({
|
|
|
queryKey: ['home-icons', activeTab],
|
|
|
queryFn: async () => {
|
|
|
- const response = await client.homeIcons.$get({
|
|
|
+ const response = await homeIconClient.$get({
|
|
|
query: {
|
|
|
type: activeTab,
|
|
|
page: 1,
|
|
|
@@ -42,7 +41,7 @@ const HomeIconsPage: React.FC = () => {
|
|
|
// 创建图标
|
|
|
const createMutation = useMutation({
|
|
|
mutationFn: async (data: CreateHomeIconRequest) => {
|
|
|
- const response = await client.homeIcons.$post({ json: data });
|
|
|
+ const response = await homeIconClient.$post({ json: data });
|
|
|
if (response.status !== 200) throw new Error('创建图标失败');
|
|
|
return response.json();
|
|
|
},
|
|
|
@@ -60,7 +59,7 @@ const HomeIconsPage: React.FC = () => {
|
|
|
// 更新图标
|
|
|
const updateMutation = useMutation({
|
|
|
mutationFn: async ({ id, data }: { id: number; data: UpdateHomeIconRequest }) => {
|
|
|
- const response = await client.homeIcons[":id"].$put({
|
|
|
+ const response = await homeIconClient[":id"].$put({
|
|
|
param: { id: id.toString() },
|
|
|
json: data
|
|
|
});
|
|
|
@@ -81,7 +80,7 @@ const HomeIconsPage: React.FC = () => {
|
|
|
// 删除图标
|
|
|
const deleteMutation = useMutation({
|
|
|
mutationFn: async (id: number) => {
|
|
|
- const response = await client.homeIcons[":id"].$delete({
|
|
|
+ const response = await homeIconClient[":id"].$delete({
|
|
|
param: { id: id.toString() }
|
|
|
});
|
|
|
if (response.status !== 200) throw new Error('删除图标失败');
|
|
|
@@ -99,7 +98,7 @@ const HomeIconsPage: React.FC = () => {
|
|
|
// 切换启用状态
|
|
|
const toggleEnabledMutation = useMutation({
|
|
|
mutationFn: async ({ id, isEnabled }: { id: number; isEnabled: number }) => {
|
|
|
- const response = await client.homeIcons[":id"].$put({
|
|
|
+ const response = await homeIconClient[":id"].$put({
|
|
|
param: { id: id.toString() },
|
|
|
json: { isEnabled }
|
|
|
});
|
|
|
@@ -158,7 +157,7 @@ const HomeIconsPage: React.FC = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const handleUploadSuccess = (fileKey: string, fileUrl: string, file: File) => {
|
|
|
+ const handleUploadSuccess = (fileKey: string, fileUrl: string, file: FileType) => {
|
|
|
// 这里需要获取刚上传的文件ID
|
|
|
// 实际项目中,上传成功后应该返回文件ID
|
|
|
message.success('文件上传成功,请填写其他信息后提交');
|
|
|
@@ -170,10 +169,10 @@ const HomeIconsPage: React.FC = () => {
|
|
|
dataIndex: 'file',
|
|
|
key: 'file',
|
|
|
width: 80,
|
|
|
- render: (file: File) => (
|
|
|
- <img
|
|
|
- src={file.path}
|
|
|
- alt={file.name}
|
|
|
+ render: (file: FileType) => (
|
|
|
+ <img
|
|
|
+ src={file.path}
|
|
|
+ alt={file.name}
|
|
|
style={{ width: 60, height: 60, objectFit: 'cover', borderRadius: 4 }}
|
|
|
/>
|
|
|
)
|