Kaynağa Gözat

♻️ refactor(supplier): 重构供应商API调用方式

- 从直接使用supplierClient改为通过supplierClientManager.get()获取实例
- 更新SupplierManagement组件中的列表查询、删除、创建和更新操作
- 修改SupplierSelector组件中的供应商列表获取方式
- 确保所有API调用统一使用manager模式获取客户端实例
yourname 1 ay önce
ebeveyn
işleme
2864db353a

+ 5 - 5
packages/supplier-management-ui-mt/src/components/SupplierManagement.tsx

@@ -14,7 +14,7 @@ import {
   EyeOff
 } from 'lucide-react';
 
-import { supplierClient } from '../api/supplierClient';
+import { supplierClient , supplierClientManager} from '../api/supplierClient';
 import type { InferRequestType, InferResponseType } from 'hono/client';
 import { CreateAdminSupplierDto, UpdateAdminSupplierDto } from '@d8d/supplier-module-mt/schemas';
 
@@ -74,7 +74,7 @@ export const SupplierManagement = () => {
   const { data, isLoading, refetch } = useQuery({
     queryKey: ['suppliers', searchParams],
     queryFn: async () => {
-      const res = await supplierClient.index.$get({
+      const res = await supplierClientManager.get().index.$get({
         query: {
           page: searchParams.page,
           pageSize: searchParams.limit,
@@ -131,7 +131,7 @@ export const SupplierManagement = () => {
     if (!supplierToDelete) return;
 
     try {
-      const res = await supplierClient[':id']['$delete']({
+      const res = await supplierClientManager.get()[':id']['$delete']({
         param: { id: Number(supplierToDelete) },
       });
 
@@ -151,7 +151,7 @@ export const SupplierManagement = () => {
   // 表单提交处理
   const handleCreateSubmit = async (data: CreateRequest) => {
     try {
-      const res = await supplierClient.index.$post({ json: data });
+      const res = await supplierClientManager.get().index.$post({ json: data });
       if (res.status === 201) {
         toast.success('创建成功');
         setIsModalOpen(false);
@@ -175,7 +175,7 @@ export const SupplierManagement = () => {
         ...(data.password === '' && { password: undefined }),
       };
 
-      const res = await supplierClient[':id']['$put']({
+      const res = await supplierClientManager.get()[':id']['$put']({
         param: { id: Number(editingSupplier.id) },
         json: updateData,
       });

+ 2 - 2
packages/supplier-management-ui-mt/src/components/SupplierSelector.tsx

@@ -1,7 +1,7 @@
 import React from 'react';
 import { useQuery } from '@tanstack/react-query';
 import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@d8d/shared-ui-components/components/ui/select';
-import { supplierClient } from '../api/supplierClient';
+import { supplierClient, supplierClientManager } from '../api/supplierClient';
 import type { InferResponseType } from 'hono/client';
 
 // 供应商项类型
@@ -26,7 +26,7 @@ export const SupplierSelector: React.FC<SupplierSelectorProps> = ({
   const { data: suppliers, isLoading } = useQuery({
     queryKey: ['suppliers'],
     queryFn: async () => {
-      const res = await supplierClient.index.$get({
+      const res = await supplierClientManager.get().index.$get({
         query: {
           page: 1,
           pageSize: 100