From 0ba7952082cfac4a0d91f4fe3b3de8a4f5cd13b6 Mon Sep 17 00:00:00 2001
From: Sakurasan <26715255+Sakurasan@users.noreply.github.com>
Date: Tue, 7 Jul 2026 15:05:19 +0800
Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=A0=E9=99=A4=E9=9B=86?=
=?UTF-8?q?=E5=90=88=E6=9D=A1=E7=9B=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/lib/api-client.ts | 6 +
src/routes/index.tsx | 356 ++++++++++++++++++++++++++++++++----------
2 files changed, 279 insertions(+), 83 deletions(-)
diff --git a/src/lib/api-client.ts b/src/lib/api-client.ts
index b618731..00a61c7 100644
--- a/src/lib/api-client.ts
+++ b/src/lib/api-client.ts
@@ -95,6 +95,12 @@ export const collectionsApi = {
body: JSON.stringify(stock),
});
},
+
+ removeStock(collectionId: number, stockCode: string): Promise<{ success: boolean }> {
+ return apiFetch(`/api/collections/${collectionId}/stocks/${stockCode}`, {
+ method: "DELETE",
+ });
+ },
};
// 分享链接 API
diff --git a/src/routes/index.tsx b/src/routes/index.tsx
index 419e750..2271412 100755
--- a/src/routes/index.tsx
+++ b/src/routes/index.tsx
@@ -1,5 +1,5 @@
-import { createFileRoute } from "@tanstack/react-router";
-import { useState, useEffect, useRef } from "react";
+import { createFileRoute, Link } from "@tanstack/react-router";
+import { useState, useEffect, useRef, useCallback } from "react";
import { collectionsApi, sharesApi } from "@/lib/api-client";
import { fetchStockQuote, fetchStockSearch, getStockBoard, type StockQuote, type StockSearchResult } from "@/lib/stock-api";
import { getUserId, updateLastAccessed } from "@/lib/user-id";
@@ -7,11 +7,11 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Card, CardContent } from "@/components/ui/card";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
+import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
-import { Search, Plus, Share2, TrendingUp, TrendingDown, Trash2, Loader2 } from "lucide-react";
+import { Search, Plus, Share2, Trash2, TrendingUp, Loader2 } from "lucide-react";
import { toast } from "sonner";
-import { Link } from "@tanstack/react-router";
export const Route = createFileRoute("/")({
component: Index,
@@ -192,21 +192,16 @@ function Index() {
}
};
- const deleteCollection = async (collectionId: number, collectionName: string) => {
- if (!confirm(`确定要删除集合"${collectionName}"吗?此操作不可恢复。`)) {
- return;
- }
-
+ const deleteCollection = useCallback(async (collectionId: number) => {
try {
await collectionsApi.delete(collectionId);
-
toast.success("删除成功");
loadCollections();
} catch (err) {
console.error("删除失败:", err);
toast.error("删除集合失败");
}
- };
+ }, []);
return (
@@ -390,13 +385,16 @@ function CollectionCard({
refreshKey
}: {
collection: StockCollection;
- onDelete: (id: number, name: string) => void;
+ onDelete: (id: number) => void;
refreshKey: number;
}) {
const [stocks, setStocks] = useState
([]);
const [stockQuotes, setStockQuotes] = useState