From 5d93f6fed3a825b20b431227e8067ef78e7aa152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=B6=A3=E4=BF=9D=E7=BD=97?= Date: Fri, 28 Aug 2026 22:25:25 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=9A=E9=87=91?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + pnpm-workspace.yaml | 2 ++ src/App.tsx | 28 ++++++++++++++-------------- 3 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 pnpm-workspace.yaml diff --git a/package.json b/package.json index 8ad3b06..beff0fb 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "dev": "vite", "build": "tsc -b && vite build", + "prod": "tsc -b && vite build --base calc", "lint": "eslint .", "preview": "vite preview" }, diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..5ed0b5a --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +allowBuilds: + esbuild: true diff --git a/src/App.tsx b/src/App.tsx index ed6127e..616a054 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -26,21 +26,21 @@ const packages: Package[] = [ const COMBO_DISCOUNT = 5; const DEPOSIT_RATE = 0.5; -/** 当「订单金额 ×50%」低于该值,且订单金额超过该值时,定金取该值 */ -const DEPOSIT_FLOOR = 50; +/** 定金封顶:50% 超过该值时只收该金额,避免大额订单定金过高 */ +const DEPOSIT_CAP = 50; function formatMoney(n: number): string { return n % 1 === 0 ? String(n) : n.toFixed(1); } -/** 定金:默认 50%;若 50% 不足 50 元且订单超过 50 元,则定金为 50 元(且不超过订单总额) */ -function computeDeposit(finalPrice: number): { amount: number; isFloor50: boolean; half: number } { - if (finalPrice <= 0) return { amount: 0, isFloor50: false, half: 0 }; +/** 定金:默认应付的 50%;若 50% 超过 50 元则封顶 50 元(且不超过订单总额) */ +function computeDeposit(finalPrice: number): { amount: number; isCapped: boolean; half: number } { + if (finalPrice <= 0) return { amount: 0, isCapped: false, half: 0 }; const half = finalPrice * DEPOSIT_RATE; - if (finalPrice > DEPOSIT_FLOOR && half < DEPOSIT_FLOOR) { - return { amount: Math.min(DEPOSIT_FLOOR, finalPrice), isFloor50: true, half }; + if (half > DEPOSIT_CAP) { + return { amount: Math.min(DEPOSIT_CAP, finalPrice), isCapped: true, half }; } - return { amount: half, isFloor50: false, half }; + return { amount: half, isCapped: false, half }; } function App() { @@ -70,7 +70,7 @@ function App() { const hasCombo = selectedSingle.length > 0 && selectedDual.length > 0; const finalPrice = hasCombo ? originalTotal - COMBO_DISCOUNT : originalTotal; - const { amount: deposit, isFloor50, half: depositHalf } = computeDeposit(finalPrice); + const { amount: deposit, isCapped, half: depositHalf } = computeDeposit(finalPrice); const balance = finalPrice - deposit; const totalSinglePhotos = selectedSingle.reduce((sum, p) => sum + p.photos * getQty(p.id), 0); @@ -218,9 +218,9 @@ function App() {
定金 - {isFloor50 ? ( + {isCapped ? ( - ({DEPOSIT_RATE * 100}% 为 {formatMoney(depositHalf)} 元,不足 ¥{DEPOSIT_FLOOR};订单 > ¥{DEPOSIT_FLOOR} 时收 ¥{DEPOSIT_FLOOR} 定金) + ({DEPOSIT_RATE * 100}% 为 {formatMoney(depositHalf)} 元,超过 ¥{DEPOSIT_CAP} 时封顶 ¥{DEPOSIT_CAP}) ) : ( (应付×{DEPOSIT_RATE * 100}%) @@ -253,9 +253,9 @@ function App() {

定金: - {isFloor50 ? ( + {isCapped ? ( - 应付 {formatMoney(finalPrice)} × {DEPOSIT_RATE} = {formatMoney(depositHalf)} 元 < ¥{DEPOSIT_FLOOR},且应付 > ¥{DEPOSIT_FLOOR},收{" "} + 应付 {formatMoney(finalPrice)} × {DEPOSIT_RATE} = {formatMoney(depositHalf)} 元 > ¥{DEPOSIT_CAP},封顶收{" "} ¥{formatMoney(deposit)};尾款 ¥{formatMoney(balance)} ) : finalPrice > 0 ? ( @@ -272,7 +272,7 @@ function App() {

);