فهرست منبع

feat: 优化广告位显示隐藏逻辑

cuiyalong 9 ماه پیش
والد
کامیت
f105208f2c
2فایلهای تغییر یافته به همراه19 افزوده شده و 5 حذف شده
  1. 18 5
      apps/mobile/src/components/ad/Ad.vue
  2. 1 0
      apps/mobile/src/utils/format/modules/ad-formatter.js

+ 18 - 5
apps/mobile/src/components/ad/Ad.vue

@@ -1,9 +1,10 @@
 <template>
   <van-image
     v-show="adShow"
-    class="reveal-box"
-    :class="{ radius: radius }"
+    v-if="adIfShow"
     :id="getConfig.id"
+    class="reveal-box"
+    :class="{ radius }"
     :src="getConfig.pic"
     :alt="getConfig.name"
     :style="getStyle"
@@ -18,12 +19,12 @@
 </template>
 
 <script>
-import { Image, Icon } from 'vant'
+import { Icon, Image } from 'vant'
 import { adConfigFormatter, openLinkOfAd, px2viewport } from '@/utils'
 import { ajaxGetAD } from '@/api/modules'
 
 export default {
-  name: 'ad-single',
+  name: 'AdSingle',
   components: {
     [Icon.name]: Icon,
     [Image.name]: Image
@@ -80,8 +81,19 @@ export default {
     info: {}
   }),
   computed: {
+    hasPic() {
+      return this.getConfig && this.getConfig.pic
+    },
     adShow() {
-      return this.show && this.loaded
+      return this.show && this.loaded && this.hasPic
+    },
+    adIfShow() {
+      // 没加载前v-if=true,v-show=false。
+      if (this.loaded) {
+        return this.adShow
+      } else {
+        return true
+      }
     },
     getStyle() {
       return {
@@ -102,6 +114,7 @@ export default {
     }
   },
   created() {
+    window.t = this
     if (this.ad) {
       this.getAD([this.ad])
     }

+ 1 - 0
apps/mobile/src/utils/format/modules/ad-formatter.js

@@ -6,6 +6,7 @@ import { getPic } from '@/utils'
  * @returns {*}
  */
 export function adConfigFormatter(config = {}) {
+  config = config || {}
   const oExtend = config.o_extend || {}
   return {
     pic: getPic(config?.s_pic),