feat:对接获取附近设备列表

This commit is contained in:
2025-10-29 16:35:51 +08:00
parent 3d67dc928d
commit 409da480b1
9 changed files with 266 additions and 168 deletions
+89 -109
View File
@@ -167,7 +167,9 @@
URL
} from "../../config/url.js"
import {
getDeviceInfo
getDeviceInfo,
getNearbyDevices,
transformDeviceData
} from '../../config/api/device.js'
import {
getPotionsDetail
@@ -422,32 +424,34 @@ const noticePopup = ref(null)
const loadPositions = async () => {
try {
const res = await uni.request({
url: `${URL}/device/position/app/list`,
method: 'GET',
header: {
'Authorization': "Bearer " + uni.getStorageSync('token'),
'Clientid': uni.getStorageSync('client_id')
},
data: {
latitude: userLocation.value.latitude,
longitude: userLocation.value.longitude
}
})
console.log(res);
if (res.statusCode === 401 || res.data?.code === 401 || res.data?.code === 40101) {
redirectToLogin()
if (!userLocation.value || !userLocation.value.latitude || !userLocation.value.longitude) {
console.warn('用户位置信息不完整,无法查询附近设备')
return
} else if (res.statusCode === 200 && res.data.code === 200) {
positionList.value = res.data.rows || []
}
const res = await getNearbyDevices({
userLatitude: userLocation.value.latitude,
userLongitude: userLocation.value.longitude,
queryType: 'rent', // 默认查询可租借设备
radiusKm: 5,
pageNum: 1,
pageSize: 100
})
console.log('查询附近设备结果:', res)
if (res.code === 200) {
// 新接口返回的是 data.records,需要适配字段名
const devices = res.data?.records || []
// 将设备数据转换为统一格式
positionList.value = devices.map(transformDeviceData)
calculateDistances()
filteredPositions.value = [...positionList.value]
} else {
console.error('获取场地列表失败:', res.data.msg)
console.error('获取设备列表失败:', res.msg)
}
} catch (error) {
console.error('获取场地列表异常:', error)
console.error('获取设备列表异常:', error)
}
}
@@ -494,50 +498,45 @@ const noticePopup = ref(null)
return
}
console.log('根据地图中心加载场地:', center)
console.log('根据地图中心加载设备:', center)
try {
// 使用原有接口获取所有场地,传入中心点经纬度
const res = await uni.request({
url: `${URL}/device/position/app/list`,
method: 'GET',
header: {
'Authorization': "Bearer " + uni.getStorageSync('token'),
'Clientid': uni.getStorageSync('client_id')
},
data: {
latitude: center.latitude,
longitude: center.longitude
}
// 使用新的附近设备查询接口
const res = await getNearbyDevices({
userLatitude: center.latitude,
userLongitude: center.longitude,
queryType: 'rent', // 默认查询可租借设备
radiusKm: 5,
pageNum: 1,
pageSize: 100
})
if (res.statusCode === 401 || res.data?.code === 401 || res.data?.code === 40101) {
redirectToLogin()
return
} else if (res.statusCode === 200 && res.data.code === 200) {
const rows = res.data.rows || []
console.log('加载到场地数量:', rows.length)
if (res.code === 200) {
const devices = res.data?.records || []
console.log('加载到设备数量:', devices.length)
// 将设备数据转换为统一格式
positionList.value = devices.map(transformDeviceData)
positionList.value = rows
// 基于地图中心计算距离
calculateDistances(center)
// 可以选择性过滤距离过远的场地(比如超过10km的)
// 可以选择性过滤距离过远的设备(比如超过10km的)
const maxDistanceInMeters = 10000 // 最大显示距离,单位米(10km)
filteredPositions.value = positionList.value.filter(item => {
return !item.distanceInMeters || item.distanceInMeters <= maxDistanceInMeters
})
console.log('过滤后场地数量:', filteredPositions.value.length)
console.log('过滤后设备数量:', filteredPositions.value.length)
} else {
console.error('根据地图中心加载场地失败:', res.data.msg)
console.error('根据地图中心加载设备失败:', res.msg)
positionList.value = []
filteredPositions.value = []
}
} catch (error) {
console.error('根据地图中心加载场地异常:', error)
// 如果请求失败,保持当前的场地列表不变
console.error('根据地图中心加载设备异常:', error)
// 如果请求失败,保持当前的设备列表不变
}
}
@@ -1238,37 +1237,39 @@ const closeNoticePopup = () => {
flex-direction: row;
align-items: center;
justify-content: space-between;
// gap: 16rpx;
gap: 16rpx;
padding: 0;
.action-btn {
display: flex;
flex-direction: column;
align-items: center;
align-content: center;
justify-content: center;
font-size: 26rpx;
font-weight: 600;
font-size: 24rpx;
font-weight: 500;
transition: all 0.3s ease;
&:active {
transform: scale(0.95);
opacity: 0.8;
}
&.primary {
background: #3EAB64;
color: #fff;
border-radius: 64rpx;
height: 100rpx;
min-width: 320rpx;
// box-shadow: 0 16rpx 40rpx rgba(7, 193, 96, 0.35);
padding: 12rpx 24rpx;
border-radius: 56rpx;
height: 112rpx;
flex: 1;
max-width: 400rpx;
padding: 0 24rpx;
// box-shadow: 0 8rpx 24rpx rgba(62, 171, 100, 0.3);
.icon-wrap {
width: 50rpx;
height: 50rpx;
border-radius: 50%;
// background: rgba(255, 255, 255, 0.25);
width: 48rpx;
height: 48rpx;
display: flex;
align-items: center;
align-content: center;
justify-content: center;
// margin-bottom: 10rpx;
}
}
@@ -1277,66 +1278,44 @@ const closeNoticePopup = () => {
color: #333;
border-radius: 24rpx;
height: 100rpx;
min-width: 180rpx;
// box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
padding: 12rpx 16rpx;
width: 140rpx;
flex-shrink: 0;
padding: 8rpx 12rpx;
// box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
// border: 1rpx solid #f0f0f0;
.icon-wrap {
width: 40rpx;
height: 40rpx;
border-radius: 50%;
// background: #f7f8fa;
// border: 2rpx solid #eaeaea;
width: 36rpx;
height: 36rpx;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 10rpx;
margin-bottom: 6rpx;
}
}
&.small {
height: 120rpx;
min-width: 180rpx;
border-radius: 28rpx;
}
}
.btn-nearby,
.btn-my {
gap: 10rpx;
}
.btn-scan {
/* 尺寸与布局(覆盖 primary 的默认尺寸) */
height: 112rpx;
min-width: 360rpx;
padding: 0 32rpx;
border-radius: 56rpx;
/* 中间扫码按钮:横向布局 */
flex-direction: row;
// gap: 16rpx;
align-items: center;
justify-content: center;
gap: 8rpx;
/* 左侧图标容器 */
.icon-wrap {
width: 64rpx;
height: 64rpx;
border-radius: 50%;
width: 48rpx;
height: 48rpx;
margin: 0;
margin-right: 12rpx;
// background: rgba(255, 255, 255, 0.18);
display: flex;
align-items: center;
justify-content: center;
box-shadow: none;
}
/* 图标大小与反色 */
.action-icon {
width: 40rpx;
height: 40rpx;
width: 32rpx;
height: 32rpx;
filter: brightness(0) invert(1);
}
.primary-label {
font-size: 28rpx;
font-weight: 600;
}
}
}
@@ -1506,17 +1485,18 @@ const closeNoticePopup = () => {
}
.action-icon {
width: 42rpx;
height: 42rpx;
width: 36rpx;
height: 36rpx;
filter: none;
box-shadow: none;
}
.btn-scan .action-icon {
filter: brightness(0) invert(1);
}
.action-label {
line-height: 1.2;
text-align: center;
}
.primary-label {
color: #ffffff;
line-height: 1;
}