From 06ab63b8e5354a325d4af3667817c1faf510549c Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Thu, 6 Nov 2025 13:08:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9A=82=E6=97=B6=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=88=87=E6=8D=A2=E8=AF=AD=E8=A8=80=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E8=BD=BD=E5=85=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 首页切换语言时当Translations为空时fallback为默认值 --- app/models/mappers/homepageMapper.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/mappers/homepageMapper.ts b/app/models/mappers/homepageMapper.ts index 428f526..71fe4dd 100644 --- a/app/models/mappers/homepageMapper.ts +++ b/app/models/mappers/homepageMapper.ts @@ -19,10 +19,15 @@ export function toHomepageView(raw: Homepage): HomepageView { const cover = isObject(item.cover) ? item.cover.id : item.cover; + console.log( + 'Has empty array in product translations:', + item.translations.length === 0 + ); + const trans = item.translations?.[0] ?? { name: '', summary: '' }; return { id: item.id, - name: item.translations?.[0].name, - summary: item.translations?.[0].summary, + name: trans.name, + summary: trans.summary, cover: cover, } satisfies HomepageProductView; }); @@ -33,11 +38,12 @@ export function toHomepageView(raw: Homepage): HomepageView { const cover = isObject(item.cover) ? item.cover.id : item.cover; + const trans = item.translations?.[0] ?? { title: '', summary: '' }; return { id: item.id, - title: item.translations?.[0].title, - summary: item.translations?.[0].summary, + title: trans.title, + summary: trans.summary, cover: cover, } satisfies HomepageSolutionView; });