"use client"; import { useMemo, useState } from "react"; const CURRENCIES = [ { code: "CNY", name: "人民币", flag: "🇨🇳", rate: 1 }, { code: "USD", name: "美元", flag: "🇺🇸", rate: 0.138 }, { code: "EUR", name: "欧元", flag: "🇪🇺", rate: 0.127 }, { code: "THB", name: "泰铢", flag: "🇹🇭", rate: 4.85 }, { code: "IDR", name: "印尼盾", flag: "🇮🇩", rate: 2180 }, { code: "JPY", name: "日元", flag: "🇯🇵", rate: 20.5 }, { code: "MXN", name: "墨西哥比索", flag: "🇲🇽", rate: 2.35 }, { code: "GBP", name: "英镑", flag: "🇬🇧", rate: 0.109 }, ]; const PRESETS = [ { label: "清迈月租", amount: 2500, from: "CNY", emoji: "🏔️" }, { label: "巴厘岛生活费", amount: 4500, from: "CNY", emoji: "🏝️" }, { label: "里斯本月租", amount: 800, from: "EUR", emoji: "🌊" }, { label: "东京月租", amount: 120000, from: "JPY", emoji: "🗼" }, ]; export default function CurrencyConverter() { const [amount, setAmount] = useState(5000); const [from, setFrom] = useState("CNY"); const [to, setTo] = useState("USD"); const [swapping, setSwapping] = useState(false); const result = useMemo(() => { const fromRate = CURRENCIES.find((c) => c.code === from)?.rate ?? 1; const toRate = CURRENCIES.find((c) => c.code === to)?.rate ?? 1; return (amount / fromRate) * toRate; }, [amount, from, to]); const swap = () => { setSwapping(true); setFrom(to); setTo(from); setTimeout(() => setSwapping(false), 400); }; const applyPreset = (p: typeof PRESETS[0]) => { setAmount(p.amount); setFrom(p.from); setTo("CNY"); }; const fromCur = CURRENCIES.find((c) => c.code === from)!; const toCur = CURRENCIES.find((c) => c.code === to)!; return (
💱 CURRENCY

多币种换算器

快速换算旅居生活费,规划跨国预算更轻松

setAmount(Math.max(0, +e.target.value || 0))} min={0} />
{toCur.flag} {result.toLocaleString(undefined, { maximumFractionDigits: 2 })} {toCur.code}

1 {fromCur.code} ≈ {((fromCur.rate / toCur.rate)).toLocaleString(undefined, { maximumFractionDigits: 4 })} {toCur.code}

{CURRENCIES.filter((c) => c.code !== from).map((c) => ( ))}

🏙️ 快捷参考

一键填入典型旅居开销

{PRESETS.map((p) => ( ))}
💡

实际汇率会波动,建议用 Wise 或 Revolut 获取实时汇率。此处为参考汇率。

); }