125 lines
4.2 KiB
TypeScript
125 lines
4.2 KiB
TypeScript
import React, { useMemo } from 'react';
|
||
import { Spin, Empty } from 'antd';
|
||
import {
|
||
ClockCircleOutlined,
|
||
EnvironmentOutlined,
|
||
SendOutlined,
|
||
NodeIndexOutlined,
|
||
} from '@ant-design/icons';
|
||
import type { BoatRouteListVO, BoatWaypointVO } from '@/types/boatRoute';
|
||
import styles from './index.less';
|
||
|
||
interface LeftPanelProps {
|
||
routes: BoatRouteListVO[];
|
||
routeWaypointsMap: Record<string, BoatWaypointVO[]>;
|
||
loading: boolean;
|
||
selectedRouteId: string | null;
|
||
onSelectRoute: (routeId: string | null) => void;
|
||
}
|
||
|
||
/** 格式化时间(秒 → "XX分钟") */
|
||
const formatDuration = (seconds?: number) => {
|
||
if (!seconds || seconds <= 0) return null;
|
||
const min = Math.round(seconds / 60);
|
||
return min > 0 ? `${min}分钟` : '<1分钟';
|
||
};
|
||
|
||
/** 格式化距离 */
|
||
const formatDistance = (meters?: number) => {
|
||
if (!meters || meters <= 0) return null;
|
||
return meters >= 1000 ? `${(meters / 1000).toFixed(1)}km` : `${Math.round(meters)}m`;
|
||
};
|
||
|
||
const LeftPanel: React.FC<LeftPanelProps> = ({
|
||
routes,
|
||
routeWaypointsMap,
|
||
loading,
|
||
selectedRouteId,
|
||
onSelectRoute,
|
||
}) => {
|
||
return (
|
||
<div className={styles.panel}>
|
||
<div className={styles.header}>
|
||
<div className={styles.headerIcon}>
|
||
<SendOutlined />
|
||
</div>
|
||
<div>
|
||
<div className={styles.headerTitle}>游览线路</div>
|
||
<div className={styles.headerSub}>选择线路开始游览</div>
|
||
</div>
|
||
<span className={styles.count}>{routes.length}</span>
|
||
</div>
|
||
|
||
<div className={styles.list}>
|
||
{loading ? (
|
||
<div className={styles.center}><Spin /></div>
|
||
) : routes.length === 0 ? (
|
||
<div className={styles.center}>
|
||
<Empty description="暂无游览线路" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||
</div>
|
||
) : (
|
||
routes.map((route) => {
|
||
const isSelected = selectedRouteId === route.routeId;
|
||
const waypoints = routeWaypointsMap[route.routeId] || [];
|
||
const duration = formatDuration(route.totalDuration);
|
||
const distance = formatDistance(route.totalDistance);
|
||
|
||
// 构建航点路径名称列表
|
||
const waypointNames = waypoints
|
||
.filter((wp) => wp.pointName)
|
||
.map((wp) => wp.pointName);
|
||
|
||
return (
|
||
<div
|
||
key={route.routeId}
|
||
className={`${styles.routeCard} ${isSelected ? styles.routeCardActive : ''}`}
|
||
onClick={() => onSelectRoute(isSelected ? null : route.routeId)}
|
||
>
|
||
{/* 线路名称 */}
|
||
<div className={styles.routeName}>{route.routeName}</div>
|
||
|
||
{/* 时长 + 距离 标签 */}
|
||
<div className={styles.tagRow}>
|
||
{duration && (
|
||
<span className={styles.tag}>
|
||
<ClockCircleOutlined className={styles.tagIcon} />
|
||
{duration}
|
||
</span>
|
||
)}
|
||
{distance && (
|
||
<span className={styles.tag}>
|
||
<EnvironmentOutlined className={styles.tagIcon} />
|
||
{distance}
|
||
</span>
|
||
)}
|
||
<span className={styles.tag}>
|
||
<NodeIndexOutlined className={styles.tagIcon} />
|
||
{route.waypointCount || waypoints.length}个景点
|
||
</span>
|
||
</div>
|
||
|
||
{/* 航点路径 */}
|
||
{waypointNames.length > 0 && (
|
||
<div className={styles.waypointPath}>
|
||
{waypointNames.map((name, idx) => (
|
||
<React.Fragment key={idx}>
|
||
<span className={styles.waypointDot} />
|
||
<span className={styles.waypointName}>{name}</span>
|
||
{idx < waypointNames.length - 1 && (
|
||
<span className={styles.waypointArrow}>→</span>
|
||
)}
|
||
</React.Fragment>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
);
|
||
})
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default LeftPanel;
|