s''
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "@/i18n/navigation";
|
||||
import Footer from "@/app/components/Footer";
|
||||
import { apiFetch } from "@/app/lib/api-client";
|
||||
|
||||
interface ToolCity {
|
||||
id: string;
|
||||
name: string;
|
||||
temperature: number;
|
||||
humidity: number;
|
||||
costPerMonth: number;
|
||||
internetSpeed: number;
|
||||
}
|
||||
|
||||
const RATES = [
|
||||
{ from: "CNY", to: "USD", rate: 0.14 },
|
||||
@@ -16,11 +26,30 @@ export default function ToolsPage() {
|
||||
const [income, setIncome] = useState(100000);
|
||||
const [cnyAmount, setCnyAmount] = useState(10000);
|
||||
const [visaDate, setVisaDate] = useState("2025-06-15");
|
||||
const [monthlySpend, setMonthlySpend] = useState(6000);
|
||||
const [targetTemp, setTargetTemp] = useState(20);
|
||||
const [cities, setCities] = useState<ToolCity[]>([]);
|
||||
const [today] = useState(() => Date.now());
|
||||
|
||||
useEffect(() => {
|
||||
apiFetch<{ items: ToolCity[] }>("/api/cities")
|
||||
.then((data) => setCities(data.items || []))
|
||||
.catch(() => setCities([]));
|
||||
}, []);
|
||||
|
||||
const taxEstimate = Math.round(income * 0.15);
|
||||
const cnyToUsd = (v: number) => (v * 0.14).toFixed(2);
|
||||
const daysLeft = Math.ceil(
|
||||
(new Date(visaDate).getTime() - Date.now()) / (1000 * 60 * 60 * 24)
|
||||
(new Date(visaDate).getTime() - today) / (1000 * 60 * 60 * 24)
|
||||
);
|
||||
const fireNumber = monthlySpend * 12 * 25;
|
||||
const yearsToFire = Math.max(1, Math.ceil(fireNumber / Math.max(1, income - monthlySpend * 12)));
|
||||
const climateMatches = useMemo(
|
||||
() =>
|
||||
[...cities]
|
||||
.sort((a, b) => Math.abs(a.temperature - targetTemp) - Math.abs(b.temperature - targetTemp))
|
||||
.slice(0, 5),
|
||||
[cities, targetTemp]
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -129,8 +158,23 @@ export default function ToolsPage() {
|
||||
🌱 {t("fireCalculator")}
|
||||
</h2>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400 mb-4">{t("fireDesc")}</p>
|
||||
<div className="p-4 rounded-xl bg-gray-50 dark:bg-gray-800 text-center text-sm text-gray-500 dark:text-gray-400">
|
||||
{t("comingSoon")}
|
||||
<div className="grid gap-4 sm:grid-cols-[1fr_220px]">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||
月支出预算 (¥)
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
value={monthlySpend}
|
||||
onChange={(e) => setMonthlySpend(Number(e.target.value) || 0)}
|
||||
className="w-full rounded-lg border border-gray-200 dark:border-gray-700 px-4 py-2 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100"
|
||||
/>
|
||||
</div>
|
||||
<div className="rounded-xl bg-gray-50 p-4 text-sm dark:bg-gray-800">
|
||||
<p className="text-gray-500 dark:text-gray-400">FIRE 目标资产</p>
|
||||
<p className="mt-1 text-xl font-bold text-gray-900 dark:text-gray-100">¥{fireNumber.toLocaleString()}</p>
|
||||
<p className="mt-2 text-xs text-gray-500 dark:text-gray-400">按 4% 规则估算,当前收入约 {yearsToFire} 年达到。</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -139,8 +183,30 @@ export default function ToolsPage() {
|
||||
🌤️ {t("climateFinder")}
|
||||
</h2>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400 mb-4">{t("climateDesc")}</p>
|
||||
<div className="p-4 rounded-xl bg-gray-50 dark:bg-gray-800 text-center text-sm text-gray-500 dark:text-gray-400">
|
||||
{t("comingSoon")}
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||
目标体感温度:{targetTemp}°C
|
||||
</label>
|
||||
<input
|
||||
type="range"
|
||||
min={10}
|
||||
max={30}
|
||||
value={targetTemp}
|
||||
onChange={(e) => setTargetTemp(Number(e.target.value))}
|
||||
className="w-full accent-[#ff4d4f]"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
{climateMatches.map((city) => (
|
||||
<div key={city.id} className="rounded-xl bg-gray-50 p-4 text-sm dark:bg-gray-800">
|
||||
<p className="font-semibold text-gray-900 dark:text-gray-100">{city.name}</p>
|
||||
<p className="mt-1 text-gray-500 dark:text-gray-400">
|
||||
{city.temperature}°C · 湿度 {city.humidity}% · ¥{city.costPerMonth.toLocaleString()}/月 · {city.internetSpeed}Mbps
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user