Sfoglia il codice sorgente

写了服务的所有方法

追梦人 1 settimana fa
parent
commit
c6f24b7717
1 ha cambiato i file con 27 aggiunte e 0 eliminazioni
  1. 27 0
      src/app/services/data.service.ts

+ 27 - 0
src/app/services/data.service.ts

@@ -9,7 +9,34 @@ export class DataService {
   currentCards = this.cardsSource.asObservable();
 
   constructor() { }
+
+  // 更新所有卡片
   updateCards(cards: any[]) {
     this.cardsSource.next(cards);
   }
+
+  // 添加新卡片
+  addCard(newCard: any) {
+    const currentCards = this.cardsSource.value;
+    this.cardsSource.next([...currentCards, newCard]);
+  }
+
+  // 删除指定卡片
+  removeCard(cardId: string) {
+    const updatedCards = this.cardsSource.value.filter(card => card.id !== cardId);
+    this.cardsSource.next(updatedCards);
+  }
+
+  // 更新指定卡片
+  updateCard(updatedCard: any) {
+    const cards = this.cardsSource.value.map(card =>
+      card.id === updatedCard.id ? { ...card, ...updatedCard } : card
+    );
+    this.cardsSource.next(cards);
+  }
+
+  // 获取当前卡片快照
+  getCurrentCardsSnapshot(): any[] {
+    return this.cardsSource.value;
+  }
 }