import {useEffect, useState} from "react"; import {Map} from '@tarojs/components' import {Search} from '@nutui/icons-react-taro' import {Button, Input} from '@nutui/nutui-react-taro' import Taro from '@tarojs/taro' import {useRouter} from '@tarojs/taro' import {getHjmCar, pageHjmCar} from "@/api/hjm/hjmCar"; import {HjmCar} from "@/api/hjm/hjmCar/model"; import './location.scss' /** * 文章终极列表 * @constructor */ const Location = () => { const {params} = useRouter(); const [keywords, setKeywords] = useState() const [item, setItem] = useState() const [longitude, setLongitude] = useState() const [latitude, setLatitude] = useState() const [scale, setScale] = useState(16) const onKeywords = (keywords: string) => { setKeywords(keywords) } // 获取当前位置 const getLocation = async () => { try { const res = await Taro.getLocation({ type: 'gcj02' //返回可以用于wx.openLocation的经纬度 }) if (res.latitude) { setLatitude(res.latitude) } if (res.longitude) { setLongitude(res.longitude) } console.log('当前位置:', res.latitude, res.longitude); return res; } catch (err) { console.error('获取位置失败:', err); } } // 打开地图选择位置 // const chooseLocation = async () => { // try { // const res = await Taro.chooseLocation({ // latitude, // 默认纬度 // longitude // 默认经度 // }) // console.log('选择的位置:', res); // } catch (err) { // console.error('选择位置失败:', err); // } // } const reload = () => { const id = Number(params.id); setScale(16) getLocation() // 执行搜索 if (keywords) { pageHjmCar({keywords}).then(res => { if (res?.list && res?.list?.length > 0) { const data = res?.list[0]; setItem(data) setLatitude(data.latitude) setLongitude(data.longitude) setKeywords(data.code) } }) return false; } // 获取车辆信息 if (id) { getHjmCar(id).then(data => { setItem(data) setLatitude(data.latitude) setLongitude(data.longitude) setKeywords(data.code) }) } } useEffect(() => { reload() }, []) return ( <>
{item ? (
最后更新时间:{item?.updateTime}
操作员:{item?.driver}
位置信息:{item?.address}
) : ''} { console.log('map tap') }} style={{width: '100%', height: '100vh'}} /> ) } export default Location