refactor(广告组件): 移除动态广告配置改为使用静态配置
将广告组件从接收props动态配置改为使用组件内部静态配置 删除Dashboard和Welcome页面中不再需要的广告数据逻辑
Showing
3 changed files
with
14 additions
and
47 deletions
| ... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +10,7 @@ |
| 10 | <!-- 广告图片 --> | 10 | <!-- 广告图片 --> |
| 11 | <view class="ad-image-container" @click="handleAdClick"> | 11 | <view class="ad-image-container" @click="handleAdClick"> |
| 12 | <image | 12 | <image |
| 13 | - :src="adImageUrl" | 13 | + :src="adConfig.adImageUrl" |
| 14 | mode="aspectFill" | 14 | mode="aspectFill" |
| 15 | class="ad-image" | 15 | class="ad-image" |
| 16 | alt="广告图片" | 16 | alt="广告图片" |
| ... | @@ -31,24 +31,15 @@ import { ref, onMounted } from 'vue' | ... | @@ -31,24 +31,15 @@ import { ref, onMounted } from 'vue' |
| 31 | import Taro from '@tarojs/taro' | 31 | import Taro from '@tarojs/taro' |
| 32 | import { Close } from '@nutui/icons-vue-taro' | 32 | import { Close } from '@nutui/icons-vue-taro' |
| 33 | 33 | ||
| 34 | -// Props | 34 | +// TODO: Mock数据配置, 等待正式接口 |
| 35 | -const props = defineProps({ | 35 | +const adConfig = { |
| 36 | // 广告图片URL | 36 | // 广告图片URL |
| 37 | - adImageUrl: { | 37 | + adImageUrl: 'https://cdn.ipadbiz.cn/lls_prog/images/%E5%8D%97%E4%BA%AC%E8%B7%AF%E5%95%86%E5%9C%88.jpeg', |
| 38 | - type: String, | ||
| 39 | - default: '' | ||
| 40 | - }, | ||
| 41 | // 点击跳转的页面路径 | 38 | // 点击跳转的页面路径 |
| 42 | - targetPage: { | 39 | + targetPage: '/pages/Dashboard/index', |
| 43 | - type: String, | ||
| 44 | - default: '/pages/Dashboard/index' | ||
| 45 | - }, | ||
| 46 | // 存储键名(用于区分不同的广告) | 40 | // 存储键名(用于区分不同的广告) |
| 47 | - storageKey: { | 41 | + storageKey: 'dashboard_ad_overlay' |
| 48 | - type: String, | 42 | +} |
| 49 | - default: 'ad_overlay_shown' | ||
| 50 | - } | ||
| 51 | -}) | ||
| 52 | 43 | ||
| 53 | // Emits | 44 | // Emits |
| 54 | const emit = defineEmits(['close', 'click']) | 45 | const emit = defineEmits(['close', 'click']) |
| ... | @@ -74,7 +65,7 @@ const getTodayDateString = () => { | ... | @@ -74,7 +65,7 @@ const getTodayDateString = () => { |
| 74 | */ | 65 | */ |
| 75 | const hasShownToday = () => { | 66 | const hasShownToday = () => { |
| 76 | try { | 67 | try { |
| 77 | - const lastShownDate = Taro.getStorageSync(props.storageKey) | 68 | + const lastShownDate = Taro.getStorageSync(adConfig.storageKey) |
| 78 | const today = getTodayDateString() | 69 | const today = getTodayDateString() |
| 79 | return lastShownDate === today | 70 | return lastShownDate === today |
| 80 | } catch (error) { | 71 | } catch (error) { |
| ... | @@ -89,7 +80,7 @@ const hasShownToday = () => { | ... | @@ -89,7 +80,7 @@ const hasShownToday = () => { |
| 89 | const markAsShownToday = () => { | 80 | const markAsShownToday = () => { |
| 90 | try { | 81 | try { |
| 91 | const today = getTodayDateString() | 82 | const today = getTodayDateString() |
| 92 | - Taro.setStorageSync(props.storageKey, today) | 83 | + Taro.setStorageSync(adConfig.storageKey, today) |
| 93 | } catch (error) { | 84 | } catch (error) { |
| 94 | console.error('保存存储数据失败:', error) | 85 | console.error('保存存储数据失败:', error) |
| 95 | } | 86 | } |
| ... | @@ -123,7 +114,7 @@ const handleAdClick = () => { | ... | @@ -123,7 +114,7 @@ const handleAdClick = () => { |
| 123 | 114 | ||
| 124 | // 跳转到目标页面 | 115 | // 跳转到目标页面 |
| 125 | // Taro.navigateTo({ | 116 | // Taro.navigateTo({ |
| 126 | - // url: props.targetPage | 117 | + // url: adConfig.targetPage |
| 127 | // }).catch(error => { | 118 | // }).catch(error => { |
| 128 | // console.error('页面跳转失败:', error) | 119 | // console.error('页面跳转失败:', error) |
| 129 | // Taro.showToast({ | 120 | // Taro.showToast({ |
| ... | @@ -133,7 +124,7 @@ const handleAdClick = () => { | ... | @@ -133,7 +124,7 @@ const handleAdClick = () => { |
| 133 | // }) | 124 | // }) |
| 134 | 125 | ||
| 135 | // 触发点击事件 | 126 | // 触发点击事件 |
| 136 | - emit('click', props.targetPage) | 127 | + emit('click', adConfig.targetPage) |
| 137 | } | 128 | } |
| 138 | 129 | ||
| 139 | /** | 130 | /** | ... | ... |
| ... | @@ -145,9 +145,6 @@ | ... | @@ -145,9 +145,6 @@ |
| 145 | <!-- 广告遮罩层 --> | 145 | <!-- 广告遮罩层 --> |
| 146 | <AdOverlay | 146 | <AdOverlay |
| 147 | ref="adOverlayRef" | 147 | ref="adOverlayRef" |
| 148 | - :ad-image-url="adObj.adImageUrl" | ||
| 149 | - :target-page="adObj.targetPage" | ||
| 150 | - :storage-key="adObj.storageKey" | ||
| 151 | @close="handleAdClose" | 148 | @close="handleAdClose" |
| 152 | @click="handleAdClick" | 149 | @click="handleAdClick" |
| 153 | /> | 150 | /> |
| ... | @@ -190,7 +187,7 @@ const familyCover = ref('') | ... | @@ -190,7 +187,7 @@ const familyCover = ref('') |
| 190 | const familyOwner = ref(false); | 187 | const familyOwner = ref(false); |
| 191 | 188 | ||
| 192 | // 广告遮罩层数据 | 189 | // 广告遮罩层数据 |
| 193 | -const adObj = ref({}) | 190 | + |
| 194 | const adOverlayRef = ref(null) | 191 | const adOverlayRef = ref(null) |
| 195 | 192 | ||
| 196 | /** | 193 | /** |
| ... | @@ -401,15 +398,6 @@ useDidShow(async () => { | ... | @@ -401,15 +398,6 @@ useDidShow(async () => { |
| 401 | if (familyAlbumRef.value) { | 398 | if (familyAlbumRef.value) { |
| 402 | familyAlbumRef.value.refreshData(); | 399 | familyAlbumRef.value.refreshData(); |
| 403 | } | 400 | } |
| 404 | - | ||
| 405 | - // TODO: 获取广告信息 | ||
| 406 | - if (!adOverlayRef.value.hasShownToday()) { | ||
| 407 | - adObj.value = { | ||
| 408 | - adImageUrl: 'https://cdn.ipadbiz.cn/lls_prog/images/%E5%8D%97%E4%BA%AC%E8%B7%AF%E5%95%86%E5%9C%88.jpeg', | ||
| 409 | - targetPage: '/pages/Dashboard/index', | ||
| 410 | - storageKey: 'dashboard_ad_overlay', | ||
| 411 | - } | ||
| 412 | - } | ||
| 413 | }) | 401 | }) |
| 414 | 402 | ||
| 415 | useReady(async () => { | 403 | useReady(async () => { | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-08-27 17:43:45 | 2 | * @Date: 2025-08-27 17:43:45 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-13 01:40:20 | 4 | + * @LastEditTime: 2025-09-13 08:58:04 |
| 5 | * @FilePath: /lls_program/src/pages/Welcome/index.vue | 5 | * @FilePath: /lls_program/src/pages/Welcome/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -136,9 +136,6 @@ | ... | @@ -136,9 +136,6 @@ |
| 136 | <!-- 广告遮罩层 --> | 136 | <!-- 广告遮罩层 --> |
| 137 | <AdOverlay | 137 | <AdOverlay |
| 138 | ref="adOverlayRef" | 138 | ref="adOverlayRef" |
| 139 | - :ad-image-url="adObj.adImageUrl" | ||
| 140 | - :target-page="adObj.targetPage" | ||
| 141 | - :storage-key="adObj.storageKey" | ||
| 142 | @close="handleAdClose" | 139 | @close="handleAdClose" |
| 143 | @click="handleAdClick" | 140 | @click="handleAdClick" |
| 144 | /> | 141 | /> |
| ... | @@ -175,7 +172,7 @@ const navigateTo = (url) => { | ... | @@ -175,7 +172,7 @@ const navigateTo = (url) => { |
| 175 | }; | 172 | }; |
| 176 | 173 | ||
| 177 | // 广告遮罩层数据 | 174 | // 广告遮罩层数据 |
| 178 | -const adObj = ref({}) | 175 | + |
| 179 | const adOverlayRef = ref(null) | 176 | const adOverlayRef = ref(null) |
| 180 | 177 | ||
| 181 | /** | 178 | /** |
| ... | @@ -218,15 +215,6 @@ useDidShow(async () => { | ... | @@ -218,15 +215,6 @@ useDidShow(async () => { |
| 218 | hasProfile.value = userInfo.value.nickname && userInfo.value.birth_date && userInfo.value.wheelchair_needed !== null; | 215 | hasProfile.value = userInfo.value.nickname && userInfo.value.birth_date && userInfo.value.wheelchair_needed !== null; |
| 219 | userAge.value = userInfo.value.birthday; | 216 | userAge.value = userInfo.value.birthday; |
| 220 | } | 217 | } |
| 221 | - | ||
| 222 | - // TODO: 获取广告信息 | ||
| 223 | - if (!adOverlayRef.value.hasShownToday()) { | ||
| 224 | - adObj.value = { | ||
| 225 | - adImageUrl: 'https://cdn.ipadbiz.cn/lls_prog/images/%E5%8D%97%E4%BA%AC%E8%B7%AF%E5%95%86%E5%9C%88.jpeg', | ||
| 226 | - targetPage: '/pages/Dashboard/index', | ||
| 227 | - storageKey: 'dashboard_ad_overlay', | ||
| 228 | - } | ||
| 229 | - } | ||
| 230 | }); | 218 | }); |
| 231 | 219 | ||
| 232 | const handleNavigate = (url) => { | 220 | const handleNavigate = (url) => { | ... | ... |
-
Please register or login to post a comment