Преглед изворни кода

feat: 移除旧版广告位接口

zhangyuhan пре 3 дана
родитељ
комит
0254bdf048

+ 6 - 12
apps/bigmember_pc/src/components/common/ContentLayout.vue

@@ -12,15 +12,15 @@
               class="ad-item-container"
               v-for="(item, index) in adList"
               :key="index"
-              :data-exposure="(adCodeMap[routerName] || routerName) + (item.s_picalt || '')"
+              :data-exposure="(adCodeMap[routerName] || routerName) + (item.name || '')"
               data-exposure-loop
             >
               <a
-                :href="item.s_link"
+                :href="item.link"
                 target="_blank"
-                :id="(adCodeMap[routerName] || routerName) + (item.s_picalt || index)"
+                :id="(adCodeMap[routerName] || routerName) + (item.name || index)"
               >
-                <img :src="item.s_pic" :alt="(adCodeMap[routerName] || routerName) + (item.s_picalt || '')"/>
+                <img :src="item.pic" :alt="(adCodeMap[routerName] || routerName) + (item.name || '')"/>
               </a>
             </div>
           </div>
@@ -32,8 +32,7 @@
 </template>
 
 <script>
-import { getAdList } from '@/api/modules/'
-import { getRandomString } from '@/utils/'
+import { fetchJyAdList } from '@/utils/'
 import { mapState } from 'vuex'
 export default {
   name: 'content-layout',
@@ -108,7 +107,6 @@ export default {
     this.routerName = this.$route.name
   },
   methods: {
-    getRandomString,
     async getAdvertisementList() {
       const params = {
         code: this.adCode
@@ -122,11 +120,7 @@ export default {
 
       if (!params.code) return console.warn('请传入adCode参数')
 
-      const { data } = await getAdList(params)
-
-      if (Array.isArray(data)) {
-        this.adList = data
-      }
+      this.adList = await fetchJyAdList(params.code)
     }
   }
 }

+ 23 - 0
apps/bigmember_pc/src/utils/format/ad.js

@@ -1,3 +1,5 @@
+import { getCommonAdList } from '@/api/modules'
+
 /**
  * 广告位响应值格式转换函数
  * @param config 广告位响应值
@@ -24,3 +26,24 @@ export function adConfigFormatter(config = {}) {
     }
   }
 }
+
+/**
+ * 获取单个广告配置列表
+ * @param {string} params - 广告位 code
+ * @returns {Promise<Array>}
+ */
+export async function fetchJyAdList (params = '') {
+  if (!params) return Promise.resolve([])
+
+  try {
+    const { data = {}, error_code: code } = await getCommonAdList({ codes: [params] })
+    const ad = data[params]
+    if (code === 0 && ad) {
+      return (Array.isArray(ad) ? ad : [ad]).map(adConfigFormatter)
+    }
+  } catch (error) {
+    console.error('[fetchJyAdList] 获取广告失败:', error)
+  }
+
+  return []
+}

+ 10 - 32
apps/bigmember_pc/src/views/order/components/adsense/index.vue

@@ -7,7 +7,7 @@
 </template>
 
 <script>
-import { getCommonAdList } from '@/api/modules'
+import { fetchJyAdList } from '@/utils'
 export default {
   name: 'adsense',
   props: {
@@ -30,38 +30,16 @@ export default {
   },
   methods: {
     async getAdList(params) {
-      if (!params) return
-      const codes = [params]
-      try {
-        const { data = {}, error_code: code } = await getCommonAdList({ codes })
-        const ad = data[params]
-        if (code === 0 && ad) {
-          if (Array.isArray(ad)) {
-            this.adList = ad.map(this.adConfigFormatter)
-          } else {
-            this.adList = [this.adConfigFormatter(ad)]
-          }
-          this.url = this.adList[0].pic
-          this.$emit('show')
-          this.link = this.adList[0].link
+      return fetchJyAdList(params).then(list => {
+        this.adList = list
+        if (this.adList.length === 0) {
+          return
         }
-      } catch (error) {
-        console.log(error)
-      }
-    },
-    adConfigFormatter(config) {
-      return {
-        pic: config?.s_pic,
-        link: config?.s_link,
-        name: config?.s_picalt || config?.s_remark,
-        type: config?.o_extend?.linktype,
-        title: config?.s_remark,
-        extend: {
-          width: config?.o_extend?.width,
-          height: config?.o_extend?.height,
-          type: config?.o_extend?.linktype
-        }
-      }
+
+        this.url = this.adList[0].pic
+        this.$emit('show')
+        this.link = this.adList[0].link
+      })
     },
     openUrl() {
       if (this.link) {

+ 4 - 30
apps/bigmember_pc/src/views/workspace/components/AdContainer.vue

@@ -12,7 +12,7 @@
 
 <script>
 import AdSwipe from '../ui/AdSwipe'
-import { getCommonAdList } from '@/api/modules'
+import { fetchJyAdList } from '@/utils'
 
 export default {
   name: 'AdContainer',
@@ -73,35 +73,9 @@ export default {
   },
   methods: {
     async getAdList(params) {
-      if (!params) return
-      const codes = [params]
-      try {
-        const { data = {}, error_code: code } = await getCommonAdList({ codes })
-        const ad = data[params]
-        if (code === 0 && ad) {
-          if (Array.isArray(ad)) {
-            this.adList = ad.map(this.adConfigFormatter)
-          } else {
-            this.adList = [this.adConfigFormatter(ad)]
-          }
-        }
-      } catch (error) {
-        console.log(error)
-      }
-    },
-    adConfigFormatter(config) {
-      return {
-        pic: config?.s_pic,
-        link: config?.s_link,
-        name: config?.s_picalt || config?.s_remark,
-        type: config?.o_extend?.linktype,
-        title: config?.s_remark,
-        extend: {
-          width: config?.o_extend?.width,
-          height: config?.o_extend?.height,
-          type: config?.o_extend?.linktype
-        }
-      }
+      return fetchJyAdList(params).then(list => {
+        this.adList = list
+      })
     }
   }
 }