Browse Source

♻️ refactor(components): 优化区域选择组件的API调用方式

- 从直接使用areaClient改为通过areaClientManager.get()获取实例
- 更新AreaSelect、AreaSelect4Level和AreaTreeAsync组件中的所有API调用
- 统一区域数据请求的客户端实例获取方式,提高代码一致性和可维护性
yourname 1 tháng trước cách đây
mục cha
commit
1fefeed570

+ 4 - 4
packages/area-management-ui-mt/src/components/AreaSelect.tsx

@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
 import { useQuery } from '@tanstack/react-query';
 import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@d8d/shared-ui-components/components/ui/select';
 import { FormControl, FormDescription, FormItem, FormLabel, FormMessage } from '@d8d/shared-ui-components/components/ui/form';
-import { areaClient } from '../api/areaClient';
+import { areaClient, areaClientManager } from '../api/areaClient';
 import type { InferResponseType } from 'hono/client';
 
 // 类型定义
@@ -39,7 +39,7 @@ export const AreaSelect: React.FC<AreaSelectProps> = ({
   const { data: provinces, isLoading: isLoadingProvinces } = useQuery({
     queryKey: ['areas', 'provinces'],
     queryFn: async () => {
-      const res = await areaClient.$get({
+      const res = await areaClientManager.get().$get({
         query: {
           page: 1,
           pageSize: 100,
@@ -63,7 +63,7 @@ export const AreaSelect: React.FC<AreaSelectProps> = ({
     queryKey: ['areas', 'cities', selectedProvince],
     queryFn: async () => {
       if (!selectedProvince) return { data: [] };
-      const res = await areaClient.$get({
+      const res = await areaClientManager.get().$get({
         query: {
           page: 1,
           pageSize: 100,
@@ -89,7 +89,7 @@ export const AreaSelect: React.FC<AreaSelectProps> = ({
     queryKey: ['areas', 'districts', selectedCity],
     queryFn: async () => {
       if (!selectedCity) return { data: [] };
-      const res = await areaClient.$get({
+      const res = await areaClientManager.get().$get({
         query: {
           page: 1,
           pageSize: 100,

+ 5 - 5
packages/area-management-ui-mt/src/components/AreaSelect4Level.tsx

@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
 import { useQuery } from '@tanstack/react-query';
 import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@d8d/shared-ui-components/components/ui/select';
 import { FormControl, FormDescription, FormItem, FormLabel, FormMessage } from '@d8d/shared-ui-components/components/ui/form';
-import { areaClient } from '../api/areaClient';
+import { areaClient, areaClientManager } from '../api/areaClient';
 import type { InferResponseType } from 'hono/client';
 
 // 类型定义
@@ -46,7 +46,7 @@ export const AreaSelect4Level: React.FC<AreaSelect4LevelProps> = ({
   const { data: provinces, isLoading: isLoadingProvinces } = useQuery({
     queryKey: ['areas', 'provinces'],
     queryFn: async () => {
-      const res = await areaClient.$get({
+      const res = await areaClientManager.get().$get({
         query: {
           page: 1,
           pageSize: 100,
@@ -70,7 +70,7 @@ export const AreaSelect4Level: React.FC<AreaSelect4LevelProps> = ({
     queryKey: ['areas', 'cities', selectedProvince],
     queryFn: async () => {
       if (!selectedProvince) return { data: [] };
-      const res = await areaClient.$get({
+      const res = await areaClientManager.get().$get({
         query: {
           page: 1,
           pageSize: 100,
@@ -96,7 +96,7 @@ export const AreaSelect4Level: React.FC<AreaSelect4LevelProps> = ({
     queryKey: ['areas', 'districts', selectedCity],
     queryFn: async () => {
       if (!selectedCity) return { data: [] };
-      const res = await areaClient.$get({
+      const res = await areaClientManager.get().$get({
         query: {
           page: 1,
           pageSize: 100,
@@ -122,7 +122,7 @@ export const AreaSelect4Level: React.FC<AreaSelect4LevelProps> = ({
     queryKey: ['areas', 'towns', selectedDistrict],
     queryFn: async () => {
       if (!selectedDistrict) return { data: [] };
-      const res = await areaClient.$get({
+      const res = await areaClientManager.get().$get({
         query: {
           page: 1,
           pageSize: 100,

+ 2 - 2
packages/area-management-ui-mt/src/components/AreaTreeAsync.tsx

@@ -4,7 +4,7 @@ import { Button } from '@d8d/shared-ui-components/components/ui/button';
 import { Badge } from '@d8d/shared-ui-components/components/ui/badge';
 import { cn } from '@d8d/shared-ui-components/utils';
 import { useQuery } from '@tanstack/react-query';
-import { areaClient } from '../api/areaClient';
+import { areaClientManager } from '../api/areaClient';
 import type { AreaNode } from '../types/area';
 
 interface AreaTreeAsyncProps {
@@ -46,7 +46,7 @@ const SubTreeLoader: React.FC<SubTreeLoaderProps> = ({
   const { data: subTreeData, isLoading: isSubTreeLoading } = useQuery({
     queryKey: ['areas-subtree', nodeId],
     queryFn: async () => {
-      const res = await areaClient.index.$get({
+      const res = await areaClientManager.get().index.$get({
         query: {
           page: 1,
           pageSize: 100 ,