From bf989067c14cb9fb0cb6a91756c8119e65340858 Mon Sep 17 00:00:00 2001 From: 18631081161 <2088094923@qq.com> Date: Wed, 8 Apr 2026 21:03:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/VendingMachine.Api/Program.cs | 7 ++++++- .../Properties/launchSettings.json | 2 +- mobile/api/request.js | 3 ++- mobile/pages/index/index.vue | 5 +++-- mobile/pages/membership/membership.vue | 3 ++- mobile/pages/stamps/stamps.vue | 3 ++- mobile/utils/image.js | 13 +++++++++++++ 7 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 mobile/utils/image.js diff --git a/backend/src/VendingMachine.Api/Program.cs b/backend/src/VendingMachine.Api/Program.cs index 19384c6f..14da4690 100644 --- a/backend/src/VendingMachine.Api/Program.cs +++ b/backend/src/VendingMachine.Api/Program.cs @@ -77,7 +77,12 @@ if (app.Environment.IsDevelopment()) } app.UseStaticFiles(); // 提供 wwwroot 下的静态文件(上传的图片等) -app.UseHttpsRedirection(); + +// 仅在非开发环境启用HTTPS重定向,避免本地调试时请求被重定向导致连接失败 +if (!app.Environment.IsDevelopment()) +{ + app.UseHttpsRedirection(); +} app.UseCors(); app.UseMiddleware(); app.UseMiddleware(); diff --git a/backend/src/VendingMachine.Api/Properties/launchSettings.json b/backend/src/VendingMachine.Api/Properties/launchSettings.json index 1d2e4fd3..1e33ceb0 100644 --- a/backend/src/VendingMachine.Api/Properties/launchSettings.json +++ b/backend/src/VendingMachine.Api/Properties/launchSettings.json @@ -5,7 +5,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": false, - "applicationUrl": "http://localhost:5082", + "applicationUrl": "http://0.0.0.0:5082", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/mobile/api/request.js b/mobile/api/request.js index 79c0bf13..4381c9ff 100644 --- a/mobile/api/request.js +++ b/mobile/api/request.js @@ -1,7 +1,8 @@ import { getStorage, removeStorage, TOKEN_KEY, LOCALE_KEY } from '../utils/storage.js' // 后端API基础地址 -export const BASE_URL = 'https://api.vendingmachine.com' +// MuMu模拟器需使用宿主机局域网IP,生产环境替换为正式域名 +export const BASE_URL = 'http://192.168.21.7:5082' /** * 统一请求封装,自动注入Token和语言请求头,统一处理响应和错误 diff --git a/mobile/pages/index/index.vue b/mobile/pages/index/index.vue index 94e001b5..2e76de2d 100644 --- a/mobile/pages/index/index.vue +++ b/mobile/pages/index/index.vue @@ -3,7 +3,7 @@ @@ -15,7 +15,7 @@ class="entry-item" @click="onEntryClick(entry)" > - + @@ -57,6 +57,7 @@ import { getBanners, getEntries, getCouponGuide } from '../../api/content.js' import { getRedeemableCoupons, redeemCoupon } from '../../api/coupon.js' import { useUserStore } from '../../stores/user.js' import { navigateBanner } from '../../utils/navigation.js' +import { resolveImageUrl } from '../../utils/image.js' import CouponCard from '../../components/CouponCard.vue' import RedeemPopup from '../../components/RedeemPopup.vue' import CouponGuidePopup from '../../components/CouponGuidePopup.vue' diff --git a/mobile/pages/membership/membership.vue b/mobile/pages/membership/membership.vue index 9585bf34..0f0e4231 100644 --- a/mobile/pages/membership/membership.vue +++ b/mobile/pages/membership/membership.vue @@ -66,6 +66,7 @@ import { ref, computed, onMounted } from 'vue' import { useI18n } from 'vue-i18n' import { useMembershipStore } from '../../stores/membership.js' import { getMembershipBanner } from '../../api/content.js' +import { resolveImageUrl } from '../../utils/image.js' const { t } = useI18n() const membershipStore = useMembershipStore() @@ -123,7 +124,7 @@ async function onSubscribe(product) { async function loadData() { try { const res = await getMembershipBanner() - bannerUrl.value = res.data?.imageUrl || res.data || '' + bannerUrl.value = resolveImageUrl(res.data?.imageUrl || res.data || '') } catch (e) { /* 错误已统一处理 */ } try { diff --git a/mobile/pages/stamps/stamps.vue b/mobile/pages/stamps/stamps.vue index 2ea4351f..aa85c1ae 100644 --- a/mobile/pages/stamps/stamps.vue +++ b/mobile/pages/stamps/stamps.vue @@ -45,6 +45,7 @@ import { ref, onMounted } from 'vue' import { useI18n } from 'vue-i18n' import { getStampBanner } from '../../api/content.js' +import { resolveImageUrl } from '../../utils/image.js' import { getStampCoupons, redeemStampCoupon } from '../../api/coupon.js' import { useUserStore } from '../../stores/user.js' import { resolveStampRedeemButton } from '../../utils/stamps.js' @@ -110,7 +111,7 @@ async function onRedeemConfirm() { async function loadBanner() { try { const res = await getStampBanner() - bannerUrl.value = res.data?.imageUrl || res.data || '' + bannerUrl.value = resolveImageUrl(res.data?.imageUrl || res.data || '') } catch (e) { /* 错误已统一处理 */ } } diff --git a/mobile/utils/image.js b/mobile/utils/image.js new file mode 100644 index 00000000..12b3ad51 --- /dev/null +++ b/mobile/utils/image.js @@ -0,0 +1,13 @@ +import { BASE_URL } from '../api/request.js' + +/** + * 将后端返回的相对路径图片URL转换为完整URL + * 如果已经是完整URL(http/https开头)则直接返回 + * @param {string} url - 图片路径 + * @returns {string} 完整的图片URL + */ +export function resolveImageUrl(url) { + if (!url) return '' + if (url.startsWith('http://') || url.startsWith('https://')) return url + return `${BASE_URL}${url}` +}