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
+35 -84
View File
@@ -155,13 +155,12 @@
import {
uploadUserAvatar
} from '../../config/api/user.js'
import {
URL
} from '../../config/url.js'
import { getCurrentAdvertisement } from '@/config/api/system.js'
import { getInUseOrder } from '@/config/api/order.js'
import { useI18n } from '@/utils/i18n.js'
// 设置页执行退出登录,此页不再直接调用
const { t: $t } = useI18n()
const { t } = useI18n()
// 响应式状态
const userInfo = ref({});
@@ -175,48 +174,25 @@ import {
const bannerImages = ref([]) // 广告图片列表
const bannerImageList = ref([]) // 完整的广告配置列表(包含链接信息)
// 将语言代码转换为后端接受的格式
const convertLanguageCode = (lang) => {
// zh-CN -> zh_CN (转换下划线)
// en-US -> en_US (转换下划线)
return lang.replace(/-/g, '_')
}
// 获取广告图片
const getBannerImages = async () => {
try {
// 获取当前语言设置
const currentLang = uni.getStorageSync('language') || 'zh-CN'
const languageCode = convertLanguageCode(currentLang)
console.log('加载个人中心广告,语言:', currentLang, '转换后:', languageCode)
// 调用接口获取广告内容
const res = await uni.request({
url: `${URL}/device/advertisementConfig/current`,
method: 'GET',
header: {
'Content-Language': languageCode
},
data: {
appPlatform: 'wechat', // 微信平台
appType: 'user' // 用户端
}
const res = await getCurrentAdvertisement({
appPlatform: 'wechat', // 微信平台
appType: 'user' // 用户端
})
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用于展示
bannerImages.value = imageList.map(item => item.imageUrl)
console.log('个人中心广告加载成功,图片数量:', imageList.length)
}
} else {
console.warn('获取个人中心广告失败:', res.data?.msg || '未知错误')
console.warn('获取个人中心广告失败:', res?.msg || '未知错误')
}
} catch (error) {
console.error('获取个人中心广告失败:', error)
@@ -226,12 +202,10 @@ import {
// 处理广告点击
const handleBannerClick = (index) => {
if (!bannerImageList.value || !bannerImageList.value[index]) {
console.warn('未找到对应的广告配置')
return
}
const config = bannerImageList.value[index]
console.log('点击广告:', index, config)
// 根据链接类型进行跳转
if (config.linkType === 'miniapp' && config.appId) {
@@ -241,12 +215,11 @@ import {
appId: config.appId,
path: config.linkUrl || '',
success: () => {
console.log('跳转小程序成功')
},
fail: (err) => {
console.error('跳转小程序失败:', err)
uni.showToast({
title: '跳转失败',
title: t('common.loadFailed'),
icon: 'none'
})
}
@@ -254,7 +227,7 @@ import {
// #endif
// #ifndef MP-WEIXIN
uni.showToast({
title: '请在微信小程序中使用',
title: t('auth.pleaseUseInWechat'),
icon: 'none'
})
// #endif
@@ -268,15 +241,13 @@ import {
uni.navigateTo({
url: config.linkUrl
})
} else {
console.log('无有效的跳转配置')
}
}
// 页面加载时初始化
onMounted(() => {
uni.setNavigationBarTitle({
title: $t('user.personalCenter')
title: t('user.personalCenter')
})
getInfo();
initVersion();
@@ -293,7 +264,6 @@ import {
const getInfo = async () => {
try {
const res = await getUserInfo();
console.log('User info response:', res);
if (res.code == 401 || res.code == 40101) {
redirectToLogin()
@@ -317,9 +287,8 @@ import {
deposit.value = res.data.balanceAmount || '0.00';
}
} catch (error) {
console.error('获取用户信息失败:', error);
uni.showToast({
title: $t('user.getUserInfoFailed'),
title: t('user.getUserInfoFailed'),
icon: 'none'
});
}
@@ -374,43 +343,29 @@ import {
const handleQuickReturn = async () => {
try {
uni.showLoading({
title: $t('common.loading')
title: t('common.loading')
});
// 获取使用中的订单
const res = await uni.request({
url: `${URL}/app/order/inUse`,
method: 'GET',
header: {
'Authorization': "Bearer " + uni.getStorageSync('token'),
'Clientid': uni.getStorageSync('client_id')
}
});
const res = await getInUseOrder();
uni.hideLoading();
if (res.statusCode === 401 || res.data?.code === 401 || res.data?.code === 40101) {
redirectToLogin();
return;
}
if (res.statusCode === 200 && res.data.code === 200 && res.data.data) {
const inUseOrder = res.data.data;
if (res && res.code === 200 && res.data) {
const inUseOrder = res.data;
// 跳转到统一订单详情页面
uni.navigateTo({
url: `/pages/order/detail?orderId=${inUseOrder.orderId}&deviceId=${inUseOrder.deviceNo}`
});
} else {
uni.showToast({
title: $t('order.noOrder'),
title: t('order.noOrder'),
icon: 'none'
});
}
} catch (error) {
uni.hideLoading();
console.error('获取使用中订单失败:', error);
uni.showToast({
title: $t('order.getOrderFailed'),
title: t('order.getOrderFailed'),
icon: 'none'
});
}
@@ -433,7 +388,7 @@ import {
// #endif
// #ifndef MP-WEIXIN
uni.showToast({
title: $t('auth.pleaseUseInWechat'),
title: t('auth.pleaseUseInWechat'),
icon: 'none'
})
// #endif
@@ -450,13 +405,13 @@ import {
const avatarLocalPath = e?.detail?.avatarUrl
if (!avatarLocalPath) {
uni.showToast({
title: '未选择头像',
title: t('user.noAvatar'),
icon: 'none'
})
return
}
uni.showLoading({
title: $t('common.uploading'),
title: t('common.uploading'),
mask: true
})
const uploadRes = await uploadUserAvatar(avatarLocalPath)
@@ -469,14 +424,13 @@ import {
uni.setStorageSync('userInfo', userInfo.value)
}
uni.showToast({
title: '头像已更新',
title: t('user.avatarUpdated'),
icon: 'success'
})
await getInfo()
} catch (err) {
console.error('选择/上传头像失败:', err)
uni.showToast({
title: '头像更新失败',
title: t('user.avatarUploadFailed'),
icon: 'none'
})
} finally {
@@ -494,14 +448,12 @@ import {
// 弹窗打开事件处理
const onPopupOpen = () => {
console.log('授权弹窗已打开');
isPopupVisible.value = true;
// 这里可以添加弹窗打开后的逻辑
};
// 弹窗关闭事件处理
const onPopupClose = () => {
console.log('授权弹窗已关闭');
isPopupVisible.value = false;
// 这里可以添加弹窗关闭后的逻辑
};
@@ -510,7 +462,7 @@ import {
const getUserProfile = () => {
// #ifdef MP-WEIXIN
uni.showLoading({
title: $t('common.getting'),
title: t('common.getting'),
mask: true
});
@@ -524,7 +476,7 @@ import {
fail: (err) => {
console.error('获取用户信息失败:', err);
uni.showToast({
title: '获取用户信息失败',
title: t('user.getUserInfoFailed'),
icon: 'none'
});
},
@@ -537,7 +489,7 @@ import {
// #ifndef MP-WEIXIN
uni.showToast({
title: $t('auth.pleaseUseInWechat'),
title: t('auth.pleaseUseInWechat'),
icon: 'none'
});
closeAuthPopup();
@@ -566,7 +518,7 @@ import {
// });
uni.showToast({
title: $t('user.updateSuccess'),
title: t('user.updateSuccess'),
icon: 'success'
});
@@ -575,7 +527,7 @@ import {
} catch (error) {
console.error('更新用户信息失败:', error);
uni.showToast({
title: $t('user.updateFailed'),
title: t('user.updateFailed'),
icon: 'none'
});
}
@@ -587,7 +539,7 @@ import {
const avatarUrl = wxUserInfo?.avatarUrl
if (!avatarUrl) {
uni.showToast({
title: '未获取到头像地址',
title: t('user.noAvatarUrl'),
icon: 'none'
})
return
@@ -601,7 +553,7 @@ import {
resolve(res.tempFilePath)
return
}
reject(new Error('头像下载失败'))
reject(new Error(t('user.avatarDownloadFailed')))
},
fail: reject
})
@@ -618,14 +570,13 @@ import {
uni.setStorageSync('userInfo', userInfo.value)
}
uni.showToast({
title: '头像已更新',
title: t('user.avatarUpdated'),
icon: 'success'
})
await getInfo()
} catch (error) {
console.error('头像上传失败:', error)
uni.showToast({
title: '头像上传失败',
title: t('user.avatarUploadFailed'),
icon: 'none'
})
} finally {
@@ -644,7 +595,7 @@ import {
// 关于我们
const handleAboutUs = () => {
uni.showToast({
title: $t('help.functionDeveloping'),
title: t('help.functionDeveloping'),
icon: 'none'
});
};
@@ -652,7 +603,7 @@ import {
// 隐私政策
const handlePrivacyPolicy = () => {
uni.showToast({
title: $t('help.functionDeveloping'),
title: t('help.functionDeveloping'),
icon: 'none'
});
};