From af1d75b79a45368998cbd05a9854233415157282 Mon Sep 17 00:00:00 2001 From: Mac Date: Tue, 27 May 2025 00:20:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/screens/CartScreen.tsx | 325 ++++++++++++++++++------------------- app/utils/languageUtils.ts | 26 +++ 2 files changed, 186 insertions(+), 165 deletions(-) diff --git a/app/screens/CartScreen.tsx b/app/screens/CartScreen.tsx index 0f058a2..f5f3ec9 100644 --- a/app/screens/CartScreen.tsx +++ b/app/screens/CartScreen.tsx @@ -33,6 +33,7 @@ import useUserStore from "../store/user"; import { t } from "../i18n"; import { payApi } from "../services/api/payApi"; import IconComponent from "../components/IconComponent"; +import {getSubjectTransLanguage,getAttributeTransLanguage} from "../utils/languageUtils"; export const CartScreen = () => { const [cartList, setCartList] = useState([]); @@ -705,8 +706,12 @@ export const CartScreen = () => { style={styles.imageThumbnail} /> - - {item.subject} + + {getSubjectTransLanguage(item)} {t("cart.min_order")}: {item.min_order_quantity} @@ -714,199 +719,189 @@ export const CartScreen = () => { - {item.skus.map((sku, index) => ( - ( - - handleDeleteSku( + {item.skus.map((sku, index) => { + return ( + ( + handleDeleteSku( item.cart_id, sku.cart_item_id, item.cart_id - ) - } - disabled={!user_id} - > - - {t("cart.delete")} - - - )} - > - { - if (user_id) { - navigation.navigate("ProductDetail", { - offer_id: item.offer_id, - searchKeyword: item.subject, - price: sku.price, - }); - } - }} - style={[ - styles.productCardContainer5, - styles.productCardContainer4, - ]} + + {t("cart.delete")} + + + )} > - - - user_id && toggleSelection( + { + if (user_id) { + navigation.navigate("ProductDetail", { + offer_id: item.offer_id, + searchKeyword: item.subject, + price: sku.price, + }); + } + } } + style={[ + styles.productCardContainer5, + styles.productCardContainer4, + ]} + > + + user_id && toggleSelection( String(sku.cart_item_id), index1, index - ) - } - disabled={!user_id} - > - - {sku.selected === 1 ? ( - - ) : ( - )} - {/* */} - - - - - - {/* 1. SKU attributes at the top */} - {sku.attributes[0]?.value && ( - - - {sku.attributes[0]?.value}{" "} - {sku.attributes[1] ? "/" : ""}{" "} - {sku.attributes[1]?.value} - - - )} - - {/* 2. Price section - discount and actual price close together */} - - - {/* Discount price */} - - - - {sku.original_price} {sku.currency} - - - - - - -{((1 - vip_discount) * 100).toFixed(0)}% - - + disabled={!user_id} + > + + {sku.selected === 1 ? ( + + ) : ( + + )} + {/* */} + + + + + {/* 1. SKU attributes at the top */} + {sku.attributes[0]?.value && ( + + + {getAttributeTransLanguage(sku.attributes[0])}{" "} + {sku.attributes[1] ? "/" : ""}{" "} + {sku.attributes[1] ? getAttributeTransLanguage(sku.attributes[1]) : ""} + + + )} - {/* Actual price - right below discount price */} - - - {sku.price} + {/* 2. Price section - discount and actual price close together */} + + + {/* Discount price */} + + + + {sku.original_price} {sku.currency} - - {sku.currency} + + + + + -{((1 - vip_discount) * 100).toFixed(0)}% - {/* 3. Quantity controls on the right */} - - - user_id && handleDecreaseQuantity( + {/* Actual price - right below discount price */} + + + {sku.price} + + + {sku.currency} + + + + + {/* 3. Quantity controls on the right */} + + user_id && handleDecreaseQuantity( item.cart_id, sku.cart_item_id, sku.quantity, item.min_order_quantity - ) - } - disabled={!user_id} - > - - - - - - - user_id && handleQuantityPress( + + - + + + user_id && handleQuantityPress( item.cart_id, sku.cart_item_id, sku.quantity - ) - } - disabled={!user_id} - > - - {sku.quantity} - - - - user_id && handleIncreaseQuantity( + )} + disabled={!user_id} + > + + {sku.quantity} + + + user_id && handleIncreaseQuantity( item.cart_id, sku.cart_item_id, sku.quantity - ) - } - disabled={!user_id} - > - - + - - + + + + + + - - - - ))} + + + ); + })} ))} diff --git a/app/utils/languageUtils.ts b/app/utils/languageUtils.ts index 97f0dd6..a005904 100644 --- a/app/utils/languageUtils.ts +++ b/app/utils/languageUtils.ts @@ -30,6 +30,32 @@ export const getSubjectTransLanguage = >(data: T): +export const getAttributeTransLanguage = >(data: T): string => { + // 获取当前i18n语言 + const currentLang = getCurrentLanguage(); + + // 特殊处理中文 + if (currentLang === 'zh' && 'value' in data) { + return data.value as string; + } + + // 获取所有value_trans开头的字段 + const translationFields = Object.keys(data).filter(key => + key.startsWith('value_trans') + ); + + // 查找匹配的字段 + const matchedField = translationFields.find(field => { + // 从字段名中提取语言代码 + const langCode = field.replace('value_trans_', ''); + // 如果没有后缀,则为法语 + return langCode === '' ? currentLang === 'fr' : langCode === currentLang; + }); + + // 返回匹配的翻译值,如果没有匹配则返回法语 + return (data[matchedField || 'value_trans'] as string) || ''; +}; + export const getSkuTransLanguage = >(data: T): string => { // 获取当前i18n语言 const currentLang = getCurrentLanguage();