- 替换 antd 为 tdesign-react 作为主要 UI 组件库 - 引入 Recharts 替代 @ant-design/charts 实现图表功能 - 移除主题系统相关代码(ThemeContext、themes 目录) - 更新所有组件以适配 TDesign 组件 API - 更新测试用例以匹配新的组件实现 - 新增 TDesign 和 Recharts 集成规范文档
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { MessagePlugin } from 'tdesign-react';
|
|
import type { CreateModelInput, UpdateModelInput } from '@/types';
|
|
import * as api from '@/api/models';
|
|
|
|
export const modelKeys = {
|
|
all: ['models'] as const,
|
|
filtered: (providerId?: string) => ['models', providerId] as const,
|
|
};
|
|
|
|
export function useModels(providerId?: string) {
|
|
return useQuery({
|
|
queryKey: modelKeys.filtered(providerId),
|
|
queryFn: () => api.listModels(providerId),
|
|
});
|
|
}
|
|
|
|
export function useCreateModel() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (input: CreateModelInput) => api.createModel(input),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: modelKeys.all });
|
|
MessagePlugin.success('模型创建成功');
|
|
},
|
|
onError: (error: Error) => {
|
|
MessagePlugin.error(error.message);
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useUpdateModel() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ id, input }: { id: string; input: UpdateModelInput }) =>
|
|
api.updateModel(id, input),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: modelKeys.all });
|
|
MessagePlugin.success('模型更新成功');
|
|
},
|
|
onError: (error: Error) => {
|
|
MessagePlugin.error(error.message);
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteModel() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (id: string) => api.deleteModel(id),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: modelKeys.all });
|
|
MessagePlugin.success('模型删除成功');
|
|
},
|
|
onError: (error: Error) => {
|
|
MessagePlugin.error(error.message);
|
|
},
|
|
});
|
|
}
|