Browse Source

fix(frontend): AI/promotion/vendor/parent pages use API_BASE_URL for uploaded images

Convert relative image paths to absolute URLs via config.API_BASE_URL in AI chat, promotion material, vendor products, and parent market pages.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Xiaogang Liao 3 months ago
parent
commit
61e1c6478c

+ 5 - 1
cfc-frontend/pages/ai/chat.vue

@@ -102,7 +102,7 @@
         <!-- 推荐卡片 -->
         <view class="rec-list" v-if="msg.recommendations && msg.recommendations.length > 0">
           <view class="rec-card" v-for="(rec, ri) in msg.recommendations" :key="ri" @click="gotoRec(rec)">
-            <image class="rec-cover" v-if="rec.coverImage" :src="rec.coverImage" mode="aspectFill" />
+            <image class="rec-cover" v-if="rec.coverImage" :src="getImageUrl(rec.coverImage)" mode="aspectFill" />
             <view class="rec-info">
               <text class="rec-type-tag">{{ rec.type === 'product' ? '商品' : rec.type === 'activity' ? '活动' : '文章' }}</text>
               <text class="rec-name">{{ rec.name }}</text>
@@ -156,6 +156,7 @@
 import { aiSendMessage, aiGetConversations, aiGetMessages, aiDeleteConversation, aiSendNutritionMessage, aiSendHealthCoachMessage, aiSendHealthButlerMessage } from '../../utils/api.js'
 import BaseEmpty from '../../components/BaseEmpty.vue'
 import AITaskCard from '../../components/AITaskCard.vue'
+import config from '@/config.js'
 
 export default {
   components: { BaseEmpty, AITaskCard },
@@ -419,6 +420,9 @@ export default {
         return d.getHours().toString().padStart(2, '0') + ':' + d.getMinutes().toString().padStart(2, '0')
       }
       return (d.getMonth() + 1) + '/' + d.getDate()
+    },
+    getImageUrl: function(path) {
+      return config.API_BASE_URL + path
     }
   }
 }

+ 6 - 2
cfc-frontend/pages/parent/market/detail.vue

@@ -2,7 +2,7 @@
   <view class="container">
     <!-- 任务模板信息 -->
     <view class="package-header">
-      <image class="cover" :src="pkg.coverImage || '/static/default-cover.png'" mode="aspectFill" />
+      <image class="cover" :src="getImageUrl(pkg.coverImage) || '/static/default-cover.png'" mode="aspectFill" />
       <view class="header-content">
         <text class="name">{{ pkg.name }}</text>
         <view class="meta">
@@ -55,6 +55,7 @@
 
 <script>
 import { getPackage, getPackageItems, purchasePackage } from '@/utils/api.js'
+import config from '@/config.js'
 
 export default {
   data() {
@@ -127,7 +128,10 @@ export default {
             uni.showToast({ title: '应用失败', icon: 'none' })
           }
         }
-      })
+        })
+    },
+    getImageUrl: function(path) {
+      return config.API_BASE_URL + path
     }
   }
 }

+ 5 - 1
cfc-frontend/pages/parent/market/index.vue

@@ -29,7 +29,7 @@
         :key="pkg.id"
         @click="goToDetail(pkg.id)"
       >
-        <image class="package-cover" :src="pkg.coverImage || '/static/default-cover.png'" mode="aspectFill" />
+        <image class="package-cover" :src="getImageUrl(pkg.coverImage) || '/static/default-cover.png'" mode="aspectFill" />
         <view class="package-content">
           <text class="package-name">{{ pkg.name }}</text>
           <text class="package-desc">{{ pkg.description }}</text>
@@ -51,6 +51,7 @@
 
 <script>
 import { getPublicPackages } from '@/utils/api.js'
+import config from '@/config.js'
 
 export default {
   data() {
@@ -89,6 +90,9 @@ export default {
       uni.navigateTo({
         url: `/pages/parent/market/detail?id=${id}`
       })
+    },
+    getImageUrl: function(path) {
+      return config.API_BASE_URL + path
     }
   }
 }

+ 5 - 2
cfc-frontend/pages/promotion/material.vue

@@ -38,7 +38,7 @@
           :key="item.id"
           @click="goDetail(item)"
         >
-          <image class="material-cover" :src="item.coverUrl || '/static/default-cover.png'" mode="aspectFill" />
+          <image class="material-cover" :src="getImageUrl(item.coverUrl) || '/static/default-cover.png'" mode="aspectFill" />
           <view class="material-info">
             <text class="material-title">{{ item.title }}</text>
             <text class="material-tags" v-if="item.tags">{{ item.tags }}</text>
@@ -212,7 +212,10 @@ export default {
         fail: function() {
           uni.showToast({ title: '下载失败', icon: 'none' })
         }
-      })
+        })
+    },
+    getImageUrl: function(path) {
+      return config.API_BASE_URL + path
     }
   }
 }

+ 5 - 1
cfc-frontend/pages/vendor/products/products.vue

@@ -27,7 +27,7 @@
           class="product-card"
         >
           <view class="card-top">
-            <image class="cover" :src="item.coverImage || '/static/default-product.png'" mode="aspectFill" />
+            <image class="cover" :src="getImageUrl(item.coverImage) || '/static/default-product.png'" mode="aspectFill" />
             <view class="card-info">
               <text class="product-name">{{ item.name }}</text>
               <text class="product-price">{{ formatPriceWithSymbol(item.price) }}</text>
@@ -54,6 +54,7 @@
 
 <script>
 import { productMy, productShelve } from '@/utils/api.js'
+import config from '@/config.js'
 
 export default {
   data() {
@@ -143,6 +144,9 @@ export default {
         off_shelf: '已下架'
       }
       return map[status] || status
+    },
+    getImageUrl: function(path) {
+      return config.API_BASE_URL + path
     }
   }
 }