fix:修复bug

This commit is contained in:
2026-01-22 10:52:58 +08:00
parent b0daa7b59b
commit 6a1dff4b94
46 changed files with 3779 additions and 2522 deletions
+45 -87
View File
@@ -198,10 +198,13 @@
transformDeviceData
} from '../../config/api/device.js'
import {
getPotionsDetail
getInUseOrder,
getUnpaidOrder
} from '../../config/api/order.js'
import {
getActiveActivity
getActiveActivity,
getCurrentAnnouncement,
getCurrentAdvertisement
} from '../../config/api/system.js'
// 导入地图工具函数
import {
@@ -227,7 +230,7 @@
// #endif
const {
t: $t
t
} = useI18n()
// 响应式数据
@@ -294,39 +297,21 @@
const bannerImages = ref([]) // 首页广告图片列表
const bannerImageList = ref([]) // 完整的广告配置列表(包含链接信息)
// 将语言代码转换为后端接受的格式
const convertLanguageCode = (lang) => {
// zh-CN -> zh_CN (转换下划线)
// en-US -> en_US (转换下划线)
return lang.replace(/-/g, '_')
}
// 获取公告内容(支持多语言)
const getNoticeText = async () => {
try {
// 获取当前语言设置
const currentLang = uni.getStorageSync('language') || 'zh-CN'
const languageCode = convertLanguageCode(currentLang)
console.log('加载公告,语言:', currentLang, '转换后:', languageCode)
console.log('加载公告')
// 调用接口获取公告内容
const res = await uni.request({
url: `${URL}/device/announcementConfig/current`,
method: 'GET',
header: {
'Content-Language': languageCode
},
data: {
type: 'wx_user_type' // 微信小程序用户端
}
const res = await getCurrentAnnouncement({
type: 'wx_user_type' // 微信小程序用户端
})
console.log('公告响应:', res)
if (res.statusCode === 200 && res.data.code === 200 && res.data.data) {
if (res && res.code === 200 && res.data) {
// 使用后端自动解析的 announcement 字段
const announcement = res.data.data.announcement || ''
const announcement = res.data.announcement || ''
noticeText.value = announcement
// 设置通知栏高度
@@ -342,7 +327,7 @@
console.warn('缓存通知内容失败:', e)
}
} else {
console.warn('获取公告失败:', res.data?.msg || '未知错误')
console.warn('获取公告失败:', res?.msg || '未知错误')
}
} catch (error) {
console.error('获取公告失败:', error)
@@ -352,31 +337,20 @@
// 获取首页广告图片(支持多语言)
const getBannerImages = async () => {
try {
// 获取当前语言设置
const currentLang = uni.getStorageSync('language') || 'zh-CN'
const languageCode = convertLanguageCode(currentLang)
console.log('加载首页广告,语言:', currentLang, '转换后:', languageCode)
console.log('加载首页广告')
// 调用接口获取广告内容
const res = await uni.request({
url: `${URL}/device/advertisementConfig/current`,
method: 'GET',
header: {
'Content-Language': languageCode
},
data: {
appPlatform: 'wechat', // 微信平台
appType: 'user' ,// 用户端
pictureLocation:'home_banner'
}
const res = await getCurrentAdvertisement({
appPlatform: 'wechat', // 微信平台
appType: 'user' ,// 用户端
pictureLocation:'home_banner'
})
console.log('首页广告响应:', res)
if (res.statusCode === 200 && res.data.code === 200 && res.data.data) {
if (res && res.code === 200 && res.data) {
// 使用 imageList 字段(包含图片和链接信息)
const imageList = res.data.data.imageList || []
const imageList = res.data.imageList || []
if (imageList.length > 0) {
bannerImageList.value = imageList
// 提取图片URL用于展示
@@ -385,7 +359,7 @@
console.warn('未获取到广告图片')
}
} else {
console.warn('获取首页广告失败:', res.data?.msg || '未知错误')
console.warn('获取首页广告失败:', res?.msg || '未知错误')
}
} catch (error) {
console.error('获取首页广告失败:', error)
@@ -415,7 +389,7 @@
fail: (err) => {
console.error('跳转小程序失败:', err)
uni.showToast({
title: '跳转失败',
title: t('common.loadFailed'),
icon: 'none'
})
}
@@ -423,7 +397,7 @@
// #endif
// #ifndef MP-WEIXIN
uni.showToast({
title: '请在微信小程序中使用',
title: t('auth.pleaseUseInWechat'),
icon: 'none'
})
// #endif
@@ -568,10 +542,10 @@
console.warn('清理旧缓存失败:', e);
}
// 开发环境测试距离计算
if (process.env.NODE_ENV === 'development') {
testDistanceCalculation()
}
// // 开发环境测试距离计算
// if (process.env.NODE_ENV === 'development') {
// testDistanceCalculation()
// }
// 并行加载公告和广告(不依赖定位)
await Promise.all([
@@ -586,12 +560,12 @@
await loadPositions()
// 3. 查询活动并显示弹窗
await checkActiveActivity()
// await checkActiveActivity()
} catch (error) {
console.error('初始化失败:', error)
uni.showToast({
title: $t('home.getLocationFailed'),
title: t('home.getLocationFailed'),
icon: 'none'
})
} finally {
@@ -787,12 +761,16 @@
isRelocating.value = true
uni.showLoading({
title: $t('home.relocating'),
title: t('home.relocating'),
mask: true
})
// 重新获取用户真实位置(不使用缓存)
// 重新获取用户真实位置
const loc = await getUserLocation()
if (!loc || !loc.longitude || !loc.latitude) {
throw new Error('location failed')
}
const newLocation = {
longitude: Number(loc.longitude),
latitude: Number(loc.latitude)
@@ -827,7 +805,7 @@
uni.hideLoading()
uni.showToast({
title: $t('home.locateSuccess'),
title: t('home.locateSuccess'),
icon: 'success',
duration: 1500
})
@@ -836,7 +814,7 @@
uni.hideLoading()
uni.showToast({
title: e.errMsg || $t('home.locateFailed'),
title: e.errMsg || t('home.locateFailed'),
icon: 'none',
duration: 2000
})
@@ -868,7 +846,7 @@
const selectPosition = (position) => {
uni.showActionSheet({
itemList: ['扫码使用', '导航前往'],
itemList: [t('home.scanToUse'), t('home.navigate')],
success: (res) => {
switch (res.tapIndex) {
case 0:
@@ -948,27 +926,17 @@
if (!deviceNo) {
uni.showToast({
title: $t('home.invalidQRCode'),
title: t('home.invalidQRCode'),
icon: 'none'
})
return
}
// 检查是否有使用中的订单
const inUseRes = await uni.request({
url: `${URL}/app/order/inUse`,
method: 'GET',
header: {
'Authorization': "Bearer " + uni.getStorageSync('token'),
'Clientid': uni.getStorageSync('client_id')
}
})
const inUseRes = await getInUseOrder()
if (inUseRes.statusCode === 401 || inUseRes.data?.code === 401 || inUseRes.data?.code === 40101) {
redirectToLogin()
return
} else if (inUseRes.statusCode == 200 && inUseRes.data.code == 200 && inUseRes.data.data) {
const inUseOrder = inUseRes.data.data
if (inUseRes && inUseRes.code === 200 && inUseRes.data) {
const inUseOrder = inUseRes.data
uni.reLaunch({
url: `/pages/order/detail?orderId=${inUseOrder.orderId}&deviceId=${deviceNo || inUseOrder.deviceNo}`
})
@@ -976,20 +944,10 @@
}
// 检查是否有待支付订单
const orderRes = await uni.request({
url: `${URL}/app/order/unpaid`,
method: 'GET',
header: {
'Authorization': "Bearer " + uni.getStorageSync('token'),
'Clientid': uni.getStorageSync('client_id')
}
})
const orderRes = await getUnpaidOrder()
if (orderRes.statusCode === 401 || orderRes.data?.code === 401 || orderRes.data?.code === 40101) {
redirectToLogin()
return
} else if (orderRes.statusCode == 200 && orderRes.data.code == 200 && orderRes.data.data) {
const unpaidOrder = orderRes.data.data
if (orderRes && orderRes.code === 200 && orderRes.data) {
const unpaidOrder = orderRes.data
uni.navigateTo({
url: `/pages/order/payment?orderId=${unpaidOrder.orderId}`
})
@@ -1018,7 +976,7 @@
}
} else {
uni.showToast({
title: '获取设备信息失败',
title: t('device.getDeviceInfoFailed'),
icon: 'none'
})
uni.navigateTo({