| | |
| | | import type { GenreItem } from '../../../../../api/types/genre'; |
| | | import { getOrderId } from '../../../../../utils/order'; |
| | | import { TripStatus } from '../../../../../constants/trip-status'; |
| | | import { isMusicControlEnabled } from '../../../../../constants/music-control-feature'; |
| | | import useBottomPopupAnimation from '../../hooks/use-bottom-popup-animation'; |
| | | import type { ControlNodes } from '../types'; |
| | | import AcSwitch from '../ac-switch'; |
| | |
| | | pageDidShowVersion?: number; |
| | | /** 后端推送:当前被指派车辆是否仍在执行上一单(连环单) */ |
| | | hasPreviousOrder?: boolean; |
| | | /** 门槛:false 时暂不执行查询/下发逻辑(如派单成功转场动效未完成),卡片仍渲染占位 */ |
| | | active?: boolean; |
| | | }; |
| | | |
| | | /** |
| | |
| | | * 只要弹窗位于 scroll-view 子树内,iOS 会把它降级为相对滚动容器定位并裁切(Android 表现正常)。 |
| | | * 因此调用方必须把 card 放进 ScrollView、把 popup 放在 ScrollView 之外。 |
| | | */ |
| | | export function useMusicControl({ tripStatus, orderId, pageDidShowVersion = 0, hasPreviousOrder = false }: Props): ControlNodes { |
| | | export function useMusicControl({ tripStatus, orderId, pageDidShowVersion = 0, hasPreviousOrder = false, active = true }: Props): ControlNodes { |
| | | // 车端真实开关状态 |
| | | const [switchOn, setSwitchOn] = useState(false); |
| | | // 后台配置曲风列表 |
| | |
| | | // 开关 loading 仅在由开关(而非磁贴)触发下发时展示 |
| | | const switchLoading = applying && applyingGenreId === ''; |
| | | |
| | | // 进入接驾态查询曲风状态;连环单不查询、不展示 |
| | | // 进入接驾态查询曲风状态;功能开关关闭、连环单不查询、不展示 |
| | | useEffect(() => { |
| | | if (tripStatus !== TripStatus.VehicleApproaching || hasPreviousOrder) { |
| | | // 门槛未就绪(如派单成功转场动效未完成):暂不查询,active 就绪后重跑再查询一次。 |
| | | if (!active) { |
| | | return; |
| | | } |
| | | if (!isMusicControlEnabled() || tripStatus !== TripStatus.VehicleApproaching || hasPreviousOrder) { |
| | | // 离开接驾态:重置去重标记,允许下次进入接驾态时重新查询一次。 |
| | | queriedOrderIdRef.current = ''; |
| | | return; |
| | |
| | | setGenres([]); |
| | | setSelectedGenreId(''); |
| | | }); |
| | | }, [tripStatus, orderId, pageDidShowVersion, hasPreviousOrder]); |
| | | }, [tripStatus, orderId, pageDidShowVersion, hasPreviousOrder, active]); |
| | | |
| | | // 点击卡片:切换面板开合 |
| | | const togglePanel = () => { |
| | |
| | | applyGenre(nextSwitchOn, targetGenreId, ''); |
| | | }; |
| | | |
| | | // 连环单或非接驾态不展示音乐卡片 |
| | | if (tripStatus !== TripStatus.VehicleApproaching || hasPreviousOrder) { |
| | | // 功能开关关闭、连环单或非接驾态不展示音乐卡片 |
| | | if (!isMusicControlEnabled() || tripStatus !== TripStatus.VehicleApproaching || hasPreviousOrder) { |
| | | return { card: null, popup: null }; |
| | | } |
| | | |