فهرست منبع

♻️ refactor(area-ui): 同步多租户区域管理组件与类型定义

- 更新多租户区域客户端导入路径,从 `adminAreasRoutes` 改为 `adminAreasRoutesMt`
- 在 `AreaNode` 接口中统一添加 `tenantId` 字段以支持多租户数据
- 统一区域选择组件中的 API 调用路径,从 `$get` 改为 `index.$get` 以匹配后端路由结构
- 同步标准区域管理组件,移除重复的 `AreaNode` 接口定义,改为从 `../types/area` 导入
- 在标准区域选择组件中,将直接使用 `areaClient` 改为通过 `areaClientManager.get()` 获取客户端实例
yourname 1 هفته پیش
والد
کامیت
13f0ab899b

+ 5 - 5
packages/area-management-ui-mt/src/api/areaClient.ts

@@ -1,9 +1,9 @@
-import { adminAreasRoutes } from '@d8d/geo-areas-mt';
+import { adminAreasRoutesMt } from '@d8d/geo-areas-mt';
 import { rpcClient } from '@d8d/shared-ui-components/utils/hc'
 
 class AreaClientManager {
   private static instance: AreaClientManager;
-  private client: ReturnType<typeof rpcClient<typeof adminAreasRoutes>> | null = null;
+  private client: ReturnType<typeof rpcClient<typeof adminAreasRoutesMt>> | null = null;
 
   private constructor() {}
 
@@ -15,12 +15,12 @@ class AreaClientManager {
   }
 
   // 初始化客户端
-  public init(baseUrl: string = '/'): ReturnType<typeof rpcClient<typeof adminAreasRoutes>> {
-    return this.client = rpcClient<typeof adminAreasRoutes>(baseUrl);
+  public init(baseUrl: string = '/'): ReturnType<typeof rpcClient<typeof adminAreasRoutesMt>> {
+    return this.client = rpcClient<typeof adminAreasRoutesMt>(baseUrl);
   }
 
   // 获取客户端实例
-  public get(): ReturnType<typeof rpcClient<typeof adminAreasRoutes>> {
+  public get(): ReturnType<typeof rpcClient<typeof adminAreasRoutesMt>> {
     if (!this.client) {
       return this.init()
     }

+ 1 - 0
packages/area-management-ui-mt/src/components/AreaManagement.tsx

@@ -21,6 +21,7 @@ type UpdateAreaRequest = InferRequestType<typeof areaClient[':id']['$put']>['jso
 // 树形节点类型
 interface AreaNode {
   id: number;
+  tenantId: number;
   name: string;
   code: string;
   level: number;

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

@@ -6,7 +6,7 @@ import { areaClient, areaClientManager } from '../api/areaClient';
 import type { InferResponseType } from 'hono/client';
 
 // 类型定义
-type AreaResponse = InferResponseType<typeof areaClient.$get, 200>['data'][0];
+type AreaResponse = InferResponseType<typeof areaClient.index.$get, 200>['data'][0];
 
 interface AreaSelectProps {
   value?: {
@@ -39,7 +39,7 @@ export const AreaSelect: React.FC<AreaSelectProps> = ({
   const { data: provinces, isLoading: isLoadingProvinces } = useQuery({
     queryKey: ['areas', 'provinces'],
     queryFn: async () => {
-      const res = await areaClientManager.get().$get({
+      const res = await areaClientManager.get().index.$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 areaClientManager.get().$get({
+      const res = await areaClientManager.get().index.$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 areaClientManager.get().$get({
+      const res = await areaClientManager.get().index.$get({
         query: {
           page: 1,
           pageSize: 100,

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

@@ -6,7 +6,7 @@ import { areaClient, areaClientManager } from '../api/areaClient';
 import type { InferResponseType } from 'hono/client';
 
 // 类型定义
-type AreaResponse = InferResponseType<typeof areaClient.$get, 200>['data'][0];
+type AreaResponse = InferResponseType<typeof areaClient.index.$get, 200>['data'][0];
 
 interface AreaSelect4LevelProps {
   provinceValue?: number;
@@ -46,7 +46,7 @@ export const AreaSelect4Level: React.FC<AreaSelect4LevelProps> = ({
   const { data: provinces, isLoading: isLoadingProvinces } = useQuery({
     queryKey: ['areas', 'provinces'],
     queryFn: async () => {
-      const res = await areaClientManager.get().$get({
+      const res = await areaClientManager.get().index.$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 areaClientManager.get().$get({
+      const res = await areaClientManager.get().index.$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 areaClientManager.get().$get({
+      const res = await areaClientManager.get().index.$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 areaClientManager.get().$get({
+      const res = await areaClientManager.get().index.$get({
         query: {
           page: 1,
           pageSize: 100,

+ 3 - 2
packages/area-management-ui-mt/src/types/area.ts

@@ -2,10 +2,10 @@ import type { InferResponseType, InferRequestType } from 'hono/client';
 import type { areaClient } from '../api/areaClient';
 
 // 区域响应类型
-export type AreaResponse = InferResponseType<typeof areaClient.$get, 200>['data'][0];
+export type AreaResponse = InferResponseType<typeof areaClient.index.$get, 200>['data'][0];
 
 // 创建区域请求类型
-export type CreateAreaRequest = InferRequestType<typeof areaClient.$post>['json'];
+export type CreateAreaRequest = InferRequestType<typeof areaClient.index.$post>['json'];
 
 // 更新区域请求类型
 export type UpdateAreaRequest = InferRequestType<typeof areaClient[':id']['$put']>['json'];
@@ -13,6 +13,7 @@ export type UpdateAreaRequest = InferRequestType<typeof areaClient[':id']['$put'
 // 树形节点类型
 export interface AreaNode {
   id: number;
+  tenantId: number;
   name: string;
   code: string;
   level: number;

+ 1 - 11
packages/area-management-ui/src/components/AreaManagement.tsx

@@ -12,23 +12,13 @@ import { AreaForm } from './AreaForm';
 import { AreaTreeAsync } from './AreaTreeAsync';
 import type { CreateAreaInput, UpdateAreaInput } from '@d8d/geo-areas/schemas';
 import { toast } from 'sonner';
+import type { AreaNode } from '../types/area';
 
 // 类型提取规范
 type AreaResponse = InferResponseType<typeof areaClient.index.$get, 200>['data'][0];
 type CreateAreaRequest = InferRequestType<typeof areaClient.index.$post>['json'];
 type UpdateAreaRequest = InferRequestType<typeof areaClient[':id']['$put']>['json'];
 
-// 树形节点类型
-interface AreaNode {
-  id: number;
-  name: string;
-  code: string;
-  level: number;
-  parentId: number | null;
-  isDisabled: number;
-  children?: AreaNode[];
-}
-
 // 统一操作处理函数
 const handleOperation = async (operation: () => Promise<void>) => {
   try {

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

@@ -2,11 +2,11 @@ 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';
 
 // 类型定义
-type AreaResponse = InferResponseType<typeof areaClient.$get, 200>['data'][0];
+type AreaResponse = InferResponseType<typeof areaClient.index.$get, 200>['data'][0];
 
 interface AreaSelectProps {
   value?: {
@@ -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().index.$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().index.$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().index.$get({
         query: {
           page: 1,
           pageSize: 100,

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

@@ -6,7 +6,7 @@ import { areaClient } from '../api/areaClient';
 import type { InferResponseType } from 'hono/client';
 
 // 类型定义
-type AreaResponse = InferResponseType<typeof areaClient.$get, 200>['data'][0];
+type AreaResponse = InferResponseType<typeof areaClient.index.$get, 200>['data'][0];
 
 interface AreaSelect4LevelProps {
   provinceValue?: number;
@@ -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 areaClient.index.$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 areaClient.index.$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 areaClient.index.$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 areaClient.index.$get({
         query: {
           page: 1,
           pageSize: 100,