add banbanmini

This commit is contained in:
HycJack
2026-03-24 13:15:03 +08:00
parent 42567b7605
commit 0d0f995dc2
59 changed files with 26319 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
import { View, Text, Map } from '@tarojs/components'
import { useState } from 'react'
import Taro, { useDidShow } from '@tarojs/taro'
import './index.scss'
interface LocationInfo {
address: string
updateTime: string
locationType: string
}
interface Coordinates {
latitude: number
longitude: number
}
// 模拟接口:获取设备位置(返回随机经纬度)
const fetchDeviceLocation = async (): Promise<Coordinates> => {
// 模拟网络延迟
await new Promise(resolve => setTimeout(resolve, 800))
// 在北京范围内生成随机坐标(大致范围)
const baseLat = 39.9042
const baseLng = 116.4074
const randomOffset = () => (Math.random() - 0.5) * 0.1 // 约 ±5km 的偏移
return {
latitude: baseLat + randomOffset(),
longitude: baseLng + randomOffset()
}
}
export default function Location() {
const [location, setLocation] = useState<LocationInfo>({
address: '阳光社区 3期 附近',
updateTime: '刚刚',
locationType: '网络定位'
})
const [coordinates, setCoordinates] = useState<Coordinates>({
latitude: 39.9042,
longitude: 116.4074
})
// 每次页面显示时获取最新位置
useDidShow(() => {
loadLocation()
})
const loadLocation = async () => {
try {
const coords = await fetchDeviceLocation()
setCoordinates(coords)
} catch (error) {
console.error('获取位置失败:', error)
}
}
const refreshLocation = async () => {
Taro.showToast({ title: '正在刷新位置...', icon: 'loading' })
try {
const coords = await fetchDeviceLocation()
setCoordinates(coords)
setLocation({
...location,
updateTime: '刚刚'
})
Taro.showToast({ title: '位置已更新', icon: 'success' })
} catch (error) {
Taro.showToast({ title: '位置更新失败', icon: 'none' })
}
}
return (
<View className='location-page'>
<View className='page-header'>
<Text className='page-title'></Text>
<Text className='page-subtitle'></Text>
</View>
<View className='map-section'>
<Map
className='map'
latitude={coordinates.latitude}
longitude={coordinates.longitude}
scale={15}
markers={[{
id: 1,
latitude: coordinates.latitude,
longitude: coordinates.longitude,
title: '设备位置',
width: 40,
height: 40
}]}
showLocation
/>
<View className='location-marker'>
<View className='marker-pin'>
<Text className='marker-emoji'>🤖</Text>
</View>
</View>
</View>
<View className='location-card'>
<View className='card-header'>
<View className='header-left'>
<Text className='location-title'></Text>
<Text className='location-update'> {location.updateTime} ({location.locationType})</Text>
</View>
<View className='refresh-btn' onClick={refreshLocation}>
<Text className='refresh-icon'></Text>
</View>
</View>
<View className='location-detail'>
<View className='location-icon'>
<Text>📍</Text>
</View>
<View className='location-info'>
<Text className='location-address'>{location.address}</Text>
<Text className='location-desc'> 4G 50-200 </Text>
</View>
</View>
</View>
</View>
)
}