fix:修复bug
This commit is contained in:
+76
-4
@@ -23,10 +23,21 @@
|
||||
</view>
|
||||
</view> -->
|
||||
|
||||
<view class="section">
|
||||
<view class="banner-card" @click="navigateTo('/pages/join/index')">
|
||||
<image class="banner-image" src="/static/userCenter_swiper.png" mode="aspectFill"></image>
|
||||
</view>
|
||||
<view class="section">
|
||||
<!-- 广告轮播 -->
|
||||
<view class="banner-card" v-if="bannerImages.length > 0">
|
||||
<swiper class="banner-swiper" :indicator-dots="bannerImages.length > 1"
|
||||
:autoplay="bannerImages.length > 1" :circular="true" :interval="3000">
|
||||
<swiper-item v-for="(image, index) in bannerImages" :key="index">
|
||||
<image class="banner-image" :src="image" mode="aspectFill"
|
||||
@click="handleBannerClick(index)"></image>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
<!-- 默认图片(当没有广告时显示) -->
|
||||
<view class="banner-card" v-else @click="navigateTo('/pages/join/index')">
|
||||
<image class="banner-image" src="/static/userCenter_swiper.png" mode="aspectFill"></image>
|
||||
</view>
|
||||
<!-- <view class="section-title">常用服务</view> -->
|
||||
<view class="list">
|
||||
<view class="list-item" @click="handleQuickReturn">
|
||||
@@ -147,6 +158,60 @@ import {
|
||||
const appVersion = ref('1.0.0');
|
||||
|
||||
const showMenuItem = ref(false)
|
||||
const bannerImages = 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' // 用户端
|
||||
}
|
||||
})
|
||||
|
||||
console.log('个人中心广告响应:', res)
|
||||
|
||||
if (res.statusCode === 200 && res.data.code === 200 && res.data.data) {
|
||||
// 使用 files 字段(图片列表)
|
||||
const files = res.data.data.files || []
|
||||
if (files.length > 0) {
|
||||
bannerImages.value = files
|
||||
console.log('个人中心广告加载成功,图片数量:', files.length)
|
||||
}
|
||||
} else {
|
||||
console.warn('获取个人中心广告失败:', res.data?.msg || '未知错误')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取个人中心广告失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理广告点击
|
||||
const handleBannerClick = (index) => {
|
||||
console.log('点击广告:', index)
|
||||
// 可以根据需要添加跳转逻辑
|
||||
// 例如:navigateTo('/pages/join/index')
|
||||
}
|
||||
|
||||
// 页面加载时初始化
|
||||
onMounted(() => {
|
||||
@@ -155,11 +220,13 @@ import {
|
||||
})
|
||||
getInfo();
|
||||
initVersion();
|
||||
getBannerImages(); // 加载广告
|
||||
});
|
||||
|
||||
// 页面显示时刷新用户信息
|
||||
onShow(() => {
|
||||
getInfo();
|
||||
getBannerImages(); // 刷新广告
|
||||
});
|
||||
|
||||
// 获取用户信息
|
||||
@@ -571,6 +638,11 @@ import {
|
||||
border: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.banner-swiper {
|
||||
width: 100%;
|
||||
height: 260rpx;
|
||||
}
|
||||
|
||||
.banner-image {
|
||||
width: 100%;
|
||||
height: 260rpx;
|
||||
|
||||
Reference in New Issue
Block a user