Răsfoiți Sursa

Merge branch 'dev/v1.0.94_yf' of jianyu/web into feature/v1.0.94

yangfeng 5 luni în urmă
părinte
comite
d9b8b64f39

+ 35 - 7
plugins/bind-phone-mobile/src/components/BindPhoneDialog.vue

@@ -6,6 +6,7 @@
   >
     <div class="bind-header">
       <van-image
+        v-if="getConfig.pic"
         :id="getConfig.id"
         class="reveal-box"
         :src="getConfig.pic"
@@ -78,10 +79,10 @@
 </template>
 
 <script>
-import Vue from 'vue'
 import { Dialog, Button, Loading, Field, Icon, Image } from 'vant'
 import { getPhoneCaptcha, setPhoneBind, ajaxGetAD } from '../api/api'
 import { adConfigFormatter, px2viewport } from '../utils/utils'
+
 export default {
   name: 'BindPhoneDialog',
   components: {
@@ -183,6 +184,11 @@ export default {
       }
     }
   },
+  watch: {
+    visible(val) {
+      console.log(val, 'visible')
+    }
+  },
   created() {
     if (!this.adCode) {
       const code = this.$envs.inWX
@@ -200,11 +206,6 @@ export default {
       }, 500)
     } catch (error) {}
   },
-  watch: {
-    visible(val) {
-      console.log(val, 'visible')
-    }
-  },
   methods: {
     showToast(message) {
       this.$toast({
@@ -221,6 +222,21 @@ export default {
       })
     },
     async getAdInfoFromRequest(codes) {
+      // 生成缓存键名
+      const cacheKey = `AD_CACHE_${codes.join('_')}-login-clear`
+      try {
+        // 尝试读取缓存
+        const cacheData = localStorage.getItem(cacheKey)
+        if (cacheData) {
+          const { data, timestamp } = JSON.parse(cacheData)
+          // 检查缓存是否在5分钟内(300000毫秒)
+          if (Date.now() - timestamp < 300000) {
+            return { info: data }
+          }
+        }
+      } catch (e) {
+        console.warn('广告缓存读取失败', e)
+      }
       const {
         error_code: code,
         error_msg: msg,
@@ -228,6 +244,18 @@ export default {
       } = await ajaxGetAD({ codes })
       if (code === 0 && data) {
         const info = adConfigFormatter(Object.values(data).flat()[0])
+        // 写入缓存
+        try {
+          localStorage.setItem(
+            cacheKey,
+            JSON.stringify({
+              data: info,
+              timestamp: Date.now()
+            })
+          )
+        } catch (e) {
+          console.warn('广告缓存写入失败', e)
+        }
         return { info }
       } else {
         console.warn(msg)
@@ -268,7 +296,7 @@ export default {
       const { error_code: code, error_msg: msg, data } = await getPhoneCaptcha()
       if (code === 0 && data) {
         // 是否缓存图片
-        if (needCache == 'cache') {
+        if (needCache === 'cache') {
           // 将下一张图片的状态缓存
           this.picCode.cacheShow = data.needVerify
           this.picCode.cacheImgBase64 = data.imageData