fix:修复bug
This commit is contained in:
+120
-40
@@ -24,7 +24,7 @@
|
||||
:enableMarkers="true" :bannerImages="bannerImages"
|
||||
:hideMapOverlays="showGuidePopup || showNoticePopup || showActivityPopup" @relocate="handleRelocate"
|
||||
@scan="handleScan" @showList="showLocationList" @markerTap="selectPosition"
|
||||
@mapCenterChange="onMapCenterChange" @bannerClick="handleBannerClick" />
|
||||
@mapCenterChange="onMapCenterChange" @bannerClick="handleBannerClick" @guide="openGuidePopup" />
|
||||
|
||||
<!-- 地图加载状态 -->
|
||||
<view v-if="isLoading || !userLocation" class="map-loading-placeholder">
|
||||
@@ -44,11 +44,11 @@
|
||||
<text class="action-label">{{ $t('home.nearbyDevices') }}</text>
|
||||
</view> -->
|
||||
|
||||
<view class="action-btn secondary small btn-nearby" @click="openPopup">
|
||||
<view class="action-btn secondary small btn-nearby" @click="goToBuy">
|
||||
<view class="icon-wrap">
|
||||
<image src="/static/use_help.png" class="action-icon" mode="aspectFit"></image>
|
||||
<image src="/static/shop_icon.png" class="action-icon" mode="scaleToFill"></image>
|
||||
</view>
|
||||
<text class="action-label">{{ $t('home.useGuide') }}</text>
|
||||
<text class="action-label">{{ $t('home.buyDevice') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="action-btn primary btn-scan" @click="handleScan">
|
||||
@@ -206,6 +206,9 @@
|
||||
getCurrentAnnouncement,
|
||||
getCurrentAdvertisement
|
||||
} from '../../config/api/system.js'
|
||||
import {
|
||||
getProductList
|
||||
} from '../../config/api/product.js'
|
||||
// 导入地图工具函数
|
||||
import {
|
||||
getUserLocation,
|
||||
@@ -524,10 +527,20 @@
|
||||
onMounted(() => {
|
||||
initNavBarHeight()
|
||||
init()
|
||||
|
||||
// #ifdef H5
|
||||
// 监听 H5 扫码结果
|
||||
uni.$on('h5ScanSuccess', (data) => {
|
||||
console.log('接收到 H5 扫码结果:', data);
|
||||
processScanResult(data);
|
||||
});
|
||||
// #endif
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
// 清理工作在子组件中处理
|
||||
// #ifdef H5
|
||||
uni.$off('h5ScanSuccess');
|
||||
// #endif
|
||||
})
|
||||
|
||||
// 方法
|
||||
@@ -564,10 +577,10 @@
|
||||
|
||||
} catch (error) {
|
||||
console.error('初始化失败:', error)
|
||||
uni.showToast({
|
||||
title: t('home.getLocationFailed'),
|
||||
icon: 'none'
|
||||
})
|
||||
// uni.showToast({
|
||||
// title: t('home.getLocationFailed'),
|
||||
// icon: 'none'
|
||||
// })
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
@@ -760,10 +773,10 @@
|
||||
try {
|
||||
isRelocating.value = true
|
||||
|
||||
uni.showLoading({
|
||||
title: t('home.relocating'),
|
||||
mask: true
|
||||
})
|
||||
// uni.showLoading({
|
||||
// title: t('home.relocating'),
|
||||
// mask: true
|
||||
// })
|
||||
|
||||
// 重新获取用户真实位置
|
||||
const loc = await getUserLocation()
|
||||
@@ -804,20 +817,20 @@
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: t('home.locateSuccess'),
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
})
|
||||
// uni.showToast({
|
||||
// title: t('home.locateSuccess'),
|
||||
// icon: 'success',
|
||||
// duration: 1500
|
||||
// })
|
||||
} catch (e) {
|
||||
console.error('定位失败:', e)
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: e.errMsg || t('home.locateFailed'),
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
// uni.showToast({
|
||||
// title: e.errMsg || t('home.locateFailed'),
|
||||
// icon: 'none',
|
||||
// duration: 2000
|
||||
// })
|
||||
} finally {
|
||||
// 1秒后解除防抖锁定
|
||||
setTimeout(() => {
|
||||
@@ -866,6 +879,53 @@
|
||||
})
|
||||
}
|
||||
|
||||
const goToBuy = async () => {
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: t('common.loading'),
|
||||
mask: true
|
||||
})
|
||||
|
||||
// 查询商品列表
|
||||
const res = await getProductList({
|
||||
pageNum: 1,
|
||||
pageSize: 10
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
console.log('商品列表查询结果:', res)
|
||||
|
||||
// 根据实际返回格式:data.rows 是商品列表数组
|
||||
if (res && res.code === 200 && res.data && res.data.rows && res.data.rows.length > 0) {
|
||||
// 获取第一个商品的ID
|
||||
const firstProduct = res.data.rows[0]
|
||||
const productId = firstProduct.id
|
||||
|
||||
console.log('获取到商品ID:', productId)
|
||||
|
||||
// 跳转到商品详情页面,传递商品ID
|
||||
uni.navigateTo({
|
||||
url: `/pages/device/goods?productId=${productId}`
|
||||
})
|
||||
} else {
|
||||
console.warn('没有查询到商品数据')
|
||||
// 如果没有商品数据,仍然跳转到商品页面(显示空状态)
|
||||
uni.navigateTo({
|
||||
url: '/pages/device/goods'
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('查询商品列表失败:', error)
|
||||
uni.hideLoading()
|
||||
|
||||
// 即使查询失败,也跳转到商品页面
|
||||
uni.navigateTo({
|
||||
url: '/pages/device/goods'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const selectPositionFromPopup = (position) => {
|
||||
// 先关闭弹窗
|
||||
hideLocationList()
|
||||
@@ -905,6 +965,13 @@
|
||||
}
|
||||
|
||||
const handleScan = async () => {
|
||||
// #ifdef H5
|
||||
uni.navigateTo({
|
||||
url: '/pages/scan/index'
|
||||
});
|
||||
return;
|
||||
// #endif
|
||||
|
||||
try {
|
||||
const scanResult = await new Promise((resolve, reject) => {
|
||||
uni.scanCode({
|
||||
@@ -914,16 +981,23 @@
|
||||
})
|
||||
|
||||
console.log(scanResult);
|
||||
let deviceNo;
|
||||
if (scanResult.scanType=='"QR_CODE"') {
|
||||
processScanResult(scanResult);
|
||||
} catch (error) {
|
||||
console.error('扫码处理失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const processScanResult = async (scanResult) => {
|
||||
try {
|
||||
let deviceNo;
|
||||
if (scanResult.scanType == 'MANUAL') {
|
||||
deviceNo = scanResult.result;
|
||||
} else if (scanResult.scanType == '"QR_CODE"') {
|
||||
deviceNo = getQueryString(scanResult.result, 'deviceNo')
|
||||
} else {
|
||||
deviceNo = getQueryString(scanResult.path, 'deviceNo')
|
||||
deviceNo = getQueryString(scanResult.path || scanResult.result, 'deviceNo')
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!deviceNo) {
|
||||
uni.showToast({
|
||||
title: t('home.invalidQRCode'),
|
||||
@@ -975,10 +1049,10 @@
|
||||
})
|
||||
}
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: t('device.getDeviceInfoFailed'),
|
||||
icon: 'none'
|
||||
})
|
||||
// uni.showToast({
|
||||
// title: t('device.getDeviceInfoFailed'),
|
||||
// icon: 'none'
|
||||
// })
|
||||
uni.navigateTo({
|
||||
url: `/pages/device/detail?deviceNo=${deviceNo}`
|
||||
})
|
||||
@@ -991,11 +1065,7 @@
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('扫码处理失败:', error)
|
||||
// uni.showToast({
|
||||
// title: '扫码失败',
|
||||
// icon: 'none'
|
||||
// })
|
||||
console.error('处理扫码结果失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1015,6 +1085,16 @@
|
||||
|
||||
// 使用指南弹窗控制
|
||||
const openPopup = () => {
|
||||
uni.navigateTo({
|
||||
url:'/pages/device/goods'
|
||||
})
|
||||
// try {
|
||||
// showGuidePopup.value = true
|
||||
// guidePopup.value && typeof guidePopup.value.open === 'function' && guidePopup.value.open()
|
||||
// } catch (e) {}
|
||||
}
|
||||
|
||||
const openGuidePopup = () => {
|
||||
try {
|
||||
showGuidePopup.value = true
|
||||
guidePopup.value && typeof guidePopup.value.open === 'function' && guidePopup.value.open()
|
||||
@@ -1494,8 +1574,8 @@
|
||||
// box-shadow: 0 8rpx 24rpx rgba(62, 171, 100, 0.3);
|
||||
|
||||
.icon-wrap {
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
width: 52rpx;
|
||||
height: 52rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@@ -1745,7 +1825,7 @@
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
|
||||
/* 使用指南弹窗样式 */
|
||||
/* 弹窗样式 */
|
||||
.guide-popup {
|
||||
width: 640rpx;
|
||||
max-width: 86vw;
|
||||
|
||||
Reference in New Issue
Block a user