fix:修正优化首页、个人中心页面广告图url跳转
This commit is contained in:
+54
-8
@@ -159,6 +159,7 @@ import {
|
||||
|
||||
const showMenuItem = ref(false)
|
||||
const bannerImages = ref([]) // 广告图片列表
|
||||
const bannerImageList = ref([]) // 完整的广告配置列表(包含链接信息)
|
||||
|
||||
// 将语言代码转换为后端接受的格式
|
||||
const convertLanguageCode = (lang) => {
|
||||
@@ -192,11 +193,13 @@ import {
|
||||
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)
|
||||
// 使用 imageList 字段(包含图片和链接信息)
|
||||
const imageList = res.data.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 || '未知错误')
|
||||
@@ -208,9 +211,52 @@ import {
|
||||
|
||||
// 处理广告点击
|
||||
const handleBannerClick = (index) => {
|
||||
console.log('点击广告:', index)
|
||||
// 可以根据需要添加跳转逻辑
|
||||
// 例如:navigateTo('/pages/join/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) {
|
||||
// 跳转到外部小程序
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.navigateToMiniProgram({
|
||||
appId: config.appId,
|
||||
path: config.linkUrl || '',
|
||||
success: () => {
|
||||
console.log('跳转小程序成功')
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('跳转小程序失败:', err)
|
||||
uni.showToast({
|
||||
title: '跳转失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.showToast({
|
||||
title: '请在微信小程序中使用',
|
||||
icon: 'none'
|
||||
})
|
||||
// #endif
|
||||
} else if (config.linkType === 'external' && config.linkUrl) {
|
||||
// 跳转到外部链接(H5页面)
|
||||
uni.navigateTo({
|
||||
url: `/pages/webview/index?url=${encodeURIComponent(config.linkUrl)}`
|
||||
})
|
||||
} else if (config.linkType === 'internal' && config.linkUrl) {
|
||||
// 跳转到内部页面
|
||||
uni.navigateTo({
|
||||
url: config.linkUrl
|
||||
})
|
||||
} else {
|
||||
console.log('无有效的跳转配置')
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载时初始化
|
||||
|
||||
Reference in New Issue
Block a user