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
+64 -33
View File
@@ -2,7 +2,8 @@
<view class="position-detail-page">
<!-- 顶部设备柜图示 -->
<view class="device-illustration">
<image src="/static/device-info.png" class="device-img" mode="aspectFit"></image>
<image v-if="positionInfo.deviceImg" :src="positionInfo.deviceImg" class="device-img" mode="aspectFit"></image>
<image v-else src="/static/device-info.png" class="device-img" mode="aspectFit"></image>
</view>
<!-- 场地信息卡片 -->
@@ -27,6 +28,17 @@
<image src="/static/device-price.png" class="item-icon" mode="aspectFit"></image>
<text class="item-text">{{ $t('device.pricing') }}{{ pricingText }}</text>
</view>
<!-- 可用数量信息 -->
<view class="info-item" v-if="positionInfo.availablePowerBankCount !== undefined && positionInfo.availablePowerBankCount !== null">
<image src="/static/device-info.png" class="item-icon" mode="aspectFit"></image>
<text class="item-text">可租借风扇{{ positionInfo.availablePowerBankCount }} </text>
</view>
<view class="info-item" v-if="positionInfo.availableEmptyGridCount !== undefined && positionInfo.availableEmptyGridCount !== null">
<image src="/static/device-info.png" class="item-icon" mode="aspectFit"></image>
<text class="item-text">可归还空位{{ positionInfo.availableEmptyGridCount }} </text>
</view>
<!-- 按钮组 -->
<view class="button-group">
@@ -48,17 +60,21 @@
</template>
<script setup>
import {
ref,
computed,
onMounted
} from 'vue'
import {
onLoad
} from '@dcloudio/uni-app'
import {
URL
} from '../../config/url.js'
import {
ref,
computed,
onMounted
} from 'vue'
import {
onLoad
} from '@dcloudio/uni-app'
import {
getNearbyDevices,
transformDeviceData
} from '../../config/api/device.js'
import { useI18n } from '../../utils/i18n.js'
const { t: $t } = useI18n()
const positionInfo = ref({})
const positionId = ref('')
@@ -78,9 +94,12 @@
})
const pricingText = computed(() => {
// 这里可以根据实际的计费规则来显示
// 默认显示一个通用的计费说明
return '5元/小时,36元/24小时,总计¥899元'
// 使用设备的 remark 字段作为计费信息
if (positionInfo.value?.remark) {
return positionInfo.value.remark
}
// 如果 remark 为空,显示默认提示
return '暂无计费信息'
})
onLoad(async (options) => {
@@ -96,33 +115,45 @@
title: $t('common.loading')
})
const res = await uni.request({
url: `${URL}/device/position/app/list`,
method: 'GET',
header: {
'Authorization': 'Bearer ' + uni.getStorageSync('token'),
'Clientid': uni.getStorageSync('client_id')
}
// 获取用户位置用于查询附近设备
let userLocation = null
try {
userLocation = uni.getStorageSync('userLocation')
} catch (e) {
console.warn('获取用户位置失败:', e)
}
if (!userLocation || !userLocation.latitude || !userLocation.longitude) {
// 如果没有用户位置,使用默认位置
userLocation = { latitude: 39.916527, longitude: 116.397128 }
}
const res = await getNearbyDevices({
userLatitude: userLocation.latitude,
userLongitude: userLocation.longitude,
queryType: 'rent', // 查询可租借设备
radiusKm: 50, // 扩大查询范围以确保能找到目标设备
pageNum: 1,
pageSize: 100
})
if (res.statusCode === 200 && res.data?.code === 200) {
const positions = res.data.rows || []
if (res.code === 200) {
const devices = res.data?.records || []
// 将设备数据转换为统一格式
const positions = devices.map(transformDeviceData)
const position = positions.find(p => p.positionId === positionId.value)
if (position) {
positionInfo.value = position
} else {
uni.showToast({
title: this.$t('location.notExist'),
icon: 'none'
})
uni.showToast({
title: $t('location.notExist'),
icon: 'none'
})
}
} else if (res.statusCode === 401 || res.data?.code === 401 || res.data?.code === 40101) {
uni.reLaunch({
url: '/pages/login/index'
})
}
} catch (e) {
console.error('加载场地详情失败:', e)
console.error('加载设备详情失败:', e)
uni.showToast({
title: $t('common.loadFailed'),
icon: 'none'