import Taro from "@tarojs/taro"; import dayjs, { Dayjs } from "dayjs"; import "dayjs/locale/zh-cn"; import { calculateDistance } from "@/utils"; import { View, Image, Text, Map } from "@tarojs/components"; import img from "@/config/images"; import styles from "./index.module.scss"; dayjs.locale("zh-cn"); function genGameLength(startTime: Dayjs, endTime: Dayjs) { if (!startTime || !endTime) { return ""; } const hours = endTime.diff(startTime, "hour"); if (Math.floor(hours / 24) >= 1) { const leftHours = Math.floor(hours % 24); return `${Math.floor(hours / 24)}天${ leftHours !== 0 ? `${leftHours}小时` : "" }`; } return `${hours}小时`; } function genGameRange(startTime: Dayjs, endTime: Dayjs) { if (!startTime || !endTime) { return ""; } // 如果跨天(自然日) if (!startTime.isSame(endTime, "day")) { return `${startTime.format("HH:mm")} - ${endTime.format("MM月DD日 HH:mm")}`; } return `${startTime.format("HH:mm")} - ${endTime.format("HH:mm")}`; } // 球局信息 export default function GameInfo(props) { const { detail, currentLocation } = props; const { latitude, longitude, location, location_name, start_time, end_time, weather, } = detail || {}; const [{ iconDay, tempMax, tempMin }] = weather || [{}]; const openMap = () => { Taro.openLocation({ latitude, // 纬度(必填) longitude, // 经度(必填) name: location_name, // 位置名(可选) address: location, // 地址详情(可选) scale: 15, // 地图缩放级别(1-28) }); }; const [c_latitude, c_longitude] = currentLocation; const distance = latitude && longitude ? calculateDistance(c_latitude, c_longitude, latitude, longitude) / 1000 : 0; const startTime = dayjs(start_time); const endTime = dayjs(end_time); const game_length = genGameLength(startTime, endTime); const startMonth = startTime.format("M"); const startDay = startTime.format("D"); const theDayOfWeek = startTime.format("dddd"); const startDate = `${startMonth}月${startDay}日 ${theDayOfWeek}`; const gameRange = genGameRange(startTime, endTime); return ( {/* Date and Weather */} {/* Calendar and Date time */} {/* Calendar */} {startMonth}月 {startDay} {/* Date time */} {startDate} {gameRange} ({game_length}) {/* Weather */} {/* Weather icon */} {/**/} {/* Weather text and temperature */} {tempMin && tempMax && ( {tempMin}℃ - {tempMax}℃ )} {/* Place */} {/* venue location message */} {/* location icon */} {/* location message */} {/* venue name and distance */} {distance ? ( {location_name || "-"} · {distance.toFixed(1)}km ) : ( "" )} {/* venue address */} {location || "-"} {/* venue map */} {longitude && latitude && ( {}} // hide business msg showLocation theme="dark" /> )} ); }