Преглед изворни кода

♻️ refactor(activity): 重构活动选择逻辑

- 移除Activity接口中冗余的isDisabled、isDeleted等字段
- 修改活动类型判断方式,通过路线数据而非activity.type字段筛选活动
- 优化地区信息显示逻辑,使用完整地区对象构建位置信息
- 移除Image组件,添加活动图片占位视图

♻️ refactor(route): 优化路线数据处理

- 在getRoutes和getRouteById方法中添加routeType字段
- 确保返回的路线数据包含明确的路线类型标识
- 优化路线数据结构,提升前后端数据交互一致性
yourname пре 3 месеци
родитељ
комит
93a762d176

+ 25 - 58
mini/src/pages/select-activity/ActivitySelectPage.tsx

@@ -1,5 +1,5 @@
 import React from 'react'
-import { View, Text, Image, ScrollView } from '@tarojs/components'
+import { View, Text, ScrollView } from '@tarojs/components'
 import { useRouter, navigateTo, navigateBack } from '@tarojs/taro'
 import { useQuery } from '@tanstack/react-query'
 import { format } from 'date-fns'
@@ -10,11 +10,9 @@ import { Navbar, NavbarPresets } from '@/components/ui/navbar'
 interface Activity {
   id: number
   name: string
-  description?: string
-  type: 'departure' | 'return'
+  description: string | null
   startDate: string
   endDate: string
-  imageUrl?: string
   venueLocationId: number
   venueLocation: {
     id: number
@@ -30,50 +28,20 @@ interface Activity {
       name: string
       level: number
       code: string
-      isDisabled: number
-      isDeleted: number
-      createdBy?: any
-      updatedBy?: any
-      createdAt: string
-      updatedAt: string
     }
     city: {
       id: number
       name: string
       level: number
       code: string
-      isDisabled: number
-      isDeleted: number
-      createdBy?: any
-      updatedBy?: any
-      createdAt: string
-      updatedAt: string
     }
     district: {
       id: number
       name: string
       level: number
       code: string
-      isDisabled: number
-      isDeleted: number
-      createdBy?: any
-      updatedBy?: any
-      createdAt: string
-      updatedAt: string
     }
-    isDisabled: number
-    isDeleted: number
-    createdBy?: any
-    updatedBy?: any
-    createdAt: string
-    updatedAt: string
   }
-  isDisabled: number
-  isDeleted: number
-  createdBy?: any
-  updatedBy?: any
-  createdAt: string
-  updatedAt: string
 }
 
 
@@ -172,18 +140,21 @@ const ActivitySelectPage: React.FC = () => {
 
   const areaNames = getAreaNames()
 
-  // 分离去程和返程活动
-  const departureActivities = (activities as Activity[])
-    .filter((activity: Activity) => activity.type === 'departure')
-    .filter((activity, index, self) =>
-      index === self.findIndex(a => a.id === activity.id)
-    )
+  // 根据路线数据分离去程和返程活动
+  const getActivitiesByRouteType = (routeType: 'departure' | 'return') => {
+    const routeIds = routeData?.routes
+      ?.filter(route => route.routeType === routeType)
+      .map(route => route.activityId) || [];
 
-  const returnActivities = (activities as Activity[])
-    .filter((activity: Activity) => activity.type === 'return')
-    .filter((activity, index, self) =>
+    return activities.filter(activity =>
+      routeIds.includes(activity.id)
+    ).filter((activity, index, self) =>
       index === self.findIndex(a => a.id === activity.id)
-    )
+    );
+  }
+
+  const departureActivities = getActivitiesByRouteType('departure')
+  const returnActivities = getActivitiesByRouteType('return')
 
   // 选择活动
   const handleSelectActivity = (activity: Activity, routeType: 'departure' | 'return') => {
@@ -204,6 +175,8 @@ const ActivitySelectPage: React.FC = () => {
   const getActivityDisplayInfo = (activity: Activity) => {
     const venue = activity.venueLocation
     const locationParts: string[] = []
+
+    // 使用完整的地区对象
     if (venue.district?.name) locationParts.push(venue.district.name)
     if (venue.city?.name) locationParts.push(venue.city.name)
     if (venue.province?.name) locationParts.push(venue.province.name)
@@ -285,13 +258,10 @@ const ActivitySelectPage: React.FC = () => {
                       onClick={() => handleSelectActivity(activity, 'departure')}
                     >
                       <View className="flex">
-                        {activity.imageUrl && (
-                          <Image
-                            src={activity.imageUrl}
-                            className="w-16 h-16 rounded-medium mr-4"
-                            mode="aspectFill"
-                          />
-                        )}
+                        {/* 活动图片占位 - 后续可添加图片功能 */}
+                        <View className="w-16 h-16 rounded-medium mr-4 bg-gray-200 flex items-center justify-center">
+                          <Text className="text-gray-500 text-xs">活动图片</Text>
+                        </View>
                         <View className="flex-1">
                           <Text className="text-base font-medium text-gray-800 block">
                             {activity.name}
@@ -349,13 +319,10 @@ const ActivitySelectPage: React.FC = () => {
                       onClick={() => handleSelectActivity(activity, 'return')}
                     >
                       <View className="flex">
-                        {activity.imageUrl && (
-                          <Image
-                            src={activity.imageUrl}
-                            className="w-16 h-16 rounded-medium mr-4"
-                            mode="aspectFill"
-                          />
-                        )}
+                        {/* 活动图片占位 - 后续可添加图片功能 */}
+                        <View className="w-16 h-16 rounded-medium mr-4 bg-gray-200 flex items-center justify-center">
+                          <Text className="text-gray-500 text-xs">活动图片</Text>
+                        </View>
                         <View className="flex-1">
                           <Text className="text-base font-medium text-gray-800 block">
                             {activity.name}

+ 17 - 2
packages/server/src/modules/routes/route.service.ts

@@ -182,8 +182,14 @@ export class RouteService extends GenericCrudService<RouteEntity> {
         })
       : [];
 
+    // 为每个路线添加 routeType 字段
+    const routesWithType = paginatedRoutes.map(route => ({
+      ...route,
+      routeType: route.routeType
+    }));
+
     return {
-      routes: paginatedRoutes,
+      routes: routesWithType,
       activities,
       pagination: {
         page,
@@ -226,7 +232,16 @@ export class RouteService extends GenericCrudService<RouteEntity> {
    * 根据ID获取路线详情
    */
   async getRouteById(id: number): Promise<RouteEntity | null> {
-    return this.getById(id, ['startLocation', 'endLocation', 'activity', 'activity.venueLocation']);
+    const route = await this.getById(id, ['startLocation', 'endLocation', 'activity', 'activity.venueLocation']);
+    if (!route) {
+      return null;
+    }
+
+    // 添加 routeType 字段
+    return {
+      ...route,
+      routeType: route.routeType
+    } as RouteEntity;
   }
 
   /**