核心功能

  1. 首頁概覽:顯示學習統計,快速開始學習
  2. 學習模式:瀏覽單詞卡片,顯示單詞、音標、釋義和例句
  3. 拼寫測試:根據釋義拼寫單詞,檢測正確率
  4. 錯題集:收集和複習拼寫錯誤的單詞
  5. 詞庫管理:下載、管理和選擇不同的詞庫
  6. 學習統計:查看學習進度和詳細報告
  7. 進度保存:使用Preferences保存學習進度

詞庫下載功能

  • 模擬下載過程:顯示進度條,從0%到100%
  • 下載狀態管理:顯示下載中、已下載狀態
  • 詞庫管理:可刪除已下載詞庫,重新下載
  • 詞庫篩選:按難度等級、下載狀態篩選詞庫

學習管理功能

  • 單詞掌握標記:標記單詞為已掌握
  • 學習進度跟蹤:記錄學習次數、正確率
  • 連續學習記錄:記錄連續學習天數
  • 數據持久化:保存所有學習數據

用户界面

  • 底部導航欄:快速切換不同功能模塊
  • 頂部返回按鈕:方便返回上一頁
  • 進度顯示:實時顯示學習進度
  • 響應式設計:適配不同屏幕尺寸

數據管理

  • 本地存儲:使用Preferences保存所有學習數據
  • 數據恢復:應用重啓後恢復上次學習狀態
  • 數據重置:支持重置所有學習進度

完整代碼


// 背單詞應用 - 修正版
// 文件名:WordMaster.ets

import promptAction from '@ohos.promptAction';
//import { request } from '@kit.BasicServicesKit';
// 單詞數據模型
class WordItem {
  id: number = 0;
  word: string = '';
  phonetic: string = '';
  meaning: string = '';
  example: string = '';
  level: number = 1; // 難度等級 1-5
  mastered: boolean = false;
  wrongCount: number = 0;
  lastReview: string = '';

  constructor(id: number, word: string = '', phonetic: string = '',
    meaning: string = '', example: string = '', level: number = 1) {
    this.id = id;
    this.word = word;
    this.phonetic = phonetic;
    this.meaning = meaning;
    this.example = example;
    this.level = level;
  }
}

// 單詞書模型
class WordBook {
  id: number = 0;
  name: string = '';
  wordCount: number = 0;
  level: string = '';
  downloaded: boolean = false;

  constructor(id: number, name: string = '', wordCount: number = 0, level: string = '') {
    this.id = id;
    this.name = name;
    this.wordCount = wordCount;
    this.level = level;
  }
}

@Entry
@Component

struct WordMaster {
  // 當前顯示的單詞
  @State currentWord: WordItem = new WordItem(0);
  @State showMeaning: boolean = false;

  // 單詞學習列表
  @State wordList: WordItem[] = [];
  @State currentIndex: number = 0;

  // 錯題集
  @State wrongWords: WordItem[] = [];

  // 單詞書
  @State wordBooks: WordBook[] = [];

  // 學習統計
  @State totalWords: number = 0;
  @State masteredWords: number = 0;
  @State accuracy: number = 0;

  // 拼寫測試
  @State spellingInput: string = '';
  @State spellingMode: boolean = false;
  @State showAnswer: boolean = false;

  // 當前頁面
  @State currentPage: string = 'learn'; // learn, spell, wrong, books

  // 單詞書詳情
  @State showBookDetail: boolean = false;
  @State selectedBook: WordBook = new WordBook(0);

  // 組件生命週期
  aboutToAppear() {
    this.initSampleData();
    this.loadCurrentWord();
    this.calculateStatistics();
  }

  // 初始化示例數據
  initSampleData() {
    // 初始化單詞列表
    this.wordList = [
      new WordItem(1, 'abandon', '[əˈbændən]', '放棄,遺棄', 'He decided to abandon his studies.', 2),
      new WordItem(2, 'benefit', '[ˈbenɪfɪt]', '好處,益處', 'Regular exercise has many health benefits.', 1),
      new WordItem(3, 'candidate', '[ˈkændɪdeɪt]', '候選人,申請者', 'There are three candidates for the position.', 3),
      new WordItem(4, 'dilemma', '[dɪˈlemə]', '困境,進退兩難', 'She faced a moral dilemma.', 4),
      new WordItem(5, 'eloquent', '[ˈeləkwənt]', '雄辯的,有説服力的', 'He gave an eloquent speech.', 5),
      new WordItem(6, 'frugal', '[ˈfruːɡl]', '節儉的,樸素的', 'They lead a frugal lifestyle.', 4),
      new WordItem(7, 'gratitude', '[ˈɡrætɪtuːd]', '感激,感謝', 'I would like to express my gratitude.', 2),
      new WordItem(8, 'hypothesis', '[haɪˈpɒθəsɪs]', '假設,假説', 'This is just a hypothesis, not a fact.', 5)
    ];

    // 初始化錯題集
    this.wrongWords = [
      new WordItem(4, 'dilemma', '[dɪˈlemə]', '困境,進退兩難', 'She faced a moral dilemma.', 4),
      new WordItem(8, 'hypothesis', '[haɪˈpɒθəsɪs]', '假設,假説', 'This is just a hypothesis, not a fact.', 5)
    ];

    // 初始化單詞書
    this.wordBooks = [
      new WordBook(1, '四級核心詞彙', 3000, 'CET-4'),
      new WordBook(2, '六級高頻詞彙', 2500, 'CET-6'),
      new WordBook(3, '考研英語詞彙', 5500, 'Postgraduate'),
      new WordBook(4, '託福核心詞彙', 4000, 'TOEFL'),
      new WordBook(5, '雅思必備詞彙', 3500, 'IELTS'),
      new WordBook(6, '商務英語詞彙', 2000, 'Business')
    ];

    this.wordBooks[0].downloaded = true;
    this.wordBooks[1].downloaded = true;
  }

  // 構建主界面
  build() {
    Column({ space: 0 }) {
      // 頂部導航欄
      this.buildNavBar()

      // 主內容區
      Column({ space: 0 }) {
        if (this.currentPage === 'learn') {
          this.buildLearningPage()
        } else if (this.currentPage === 'spell') {
          this.buildSpellingPage()
        } else if (this.currentPage === 'wrong') {
          this.buildWrongWordsPage()
        } else if (this.currentPage === 'books') {
          this.buildBooksPage()
        }
      }
      .layoutWeight(1)
      .backgroundColor('#F8F9FA')

      // 底部統計欄
      this.buildStatsBar()

      // 單詞書詳情對話框
      if (this.showBookDetail) {
        this.buildBookDetailDialog()
      }
    }
    .width('100%')
    .height('100%')
  }

  // 頂部導航欄
  @Builder
  buildNavBar() {
    Row({ space: 10 }) {
      Button('學習')
        .width(80)
        .height(40)
        .fontSize(14)
        .backgroundColor(this.currentPage === 'learn' ? '#007DFF' : '#FFFFFF')
        .fontColor(this.currentPage === 'learn' ? '#FFFFFF' : '#666666')
        .onClick(() => { this.currentPage = 'learn'; })

      Button('拼寫')
        .width(80)
        .height(40)
        .fontSize(14)
        .backgroundColor(this.currentPage === 'spell' ? '#007DFF' : '#FFFFFF')
        .fontColor(this.currentPage === 'spell' ? '#FFFFFF' : '#666666')
        .onClick(() => {
          this.currentPage = 'spell';
          this.startSpellingTest();
        })

      Button('錯題')
        .width(80)
        .height(40)
        .fontSize(14)
        .backgroundColor(this.currentPage === 'wrong' ? '#007DFF' : '#FFFFFF')
        .fontColor(this.currentPage === 'wrong' ? '#FFFFFF' : '#666666')
        .onClick(() => { this.currentPage = 'wrong'; })

      Button('詞書')
        .width(80)
        .height(40)
        .fontSize(14)
        .backgroundColor(this.currentPage === 'books' ? '#007DFF' : '#FFFFFF')
        .fontColor(this.currentPage === 'books' ? '#FFFFFF' : '#666666')
        .onClick(() => { this.currentPage = 'books'; })
    }
    .width('100%')
    .padding(10)
    .justifyContent(FlexAlign.Center)
    .backgroundColor('#FFFFFF')
    .border({ width: { bottom: 1 }, color: '#E0E0E0' })
  }

  // 學習頁面
  @Builder
  buildLearningPage() {
    Column({ space: 20 }) {
      // 進度指示器
      Row() {
        Text('進度:' + (this.currentIndex + 1) + '/' + this.wordList.length)
          .fontSize(16)
          .fontColor('#666666')
          .layoutWeight(1)

        Text('難度:' + '★'.repeat(this.currentWord.level))
          .fontSize(16)
          .fontColor('#FF9800')
      }
      .width('90%')
      .margin({ top: 20 })

      // 單詞卡片
      Column({ space: 15 }) {
        // 單詞
        Text(this.currentWord.word)
          .fontSize(48)
          .fontWeight(FontWeight.Bold)
          .fontColor('#007DFF')
          .textAlign(TextAlign.Center)

        // 音標
        Text(this.currentWord.phonetic)
          .fontSize(20)
          .fontColor('#666666')
          .textAlign(TextAlign.Center)

        // 發音按鈕
        Button('🔊 發音')
          .width(120)
          .height(40)
          .fontSize(16)
          .backgroundColor('#4CAF50')
          .margin({ top: 10, bottom: 10 })
          .onClick(() => {
            this.speakWord();
          })

        // 顯示/隱藏釋義按鈕
        Button(this.showMeaning ? '隱藏釋義' : '顯示釋義')
          .width(150)
          .height(45)
          .fontSize(18)
          .backgroundColor('#007DFF')
          .onClick(() => {
            this.showMeaning = !this.showMeaning;
          })

        // 釋義(條件顯示)
        if (this.showMeaning) {
          Column({ space: 10 }) {
            Text(this.currentWord.meaning)
              .fontSize(20)
              .fontColor('#4CAF50')
              .textAlign(TextAlign.Center)

            Text('例句:' + this.currentWord.example)
              .fontSize(16)
              .fontColor('#666666')
              .padding(10)
              .backgroundColor('#FFFFFF')
              .borderRadius(8)
              .border({ width: 1, color: '#E0E0E0' })
          }
          .width('90%')
          .margin({ top: 20 })
        }
      }
      .width('90%')
      .padding(30)
      .backgroundColor('#FFFFFF')
      .borderRadius(15)
      .shadow({ radius: 10, color: '#E0E0E0', offsetX: 0, offsetY: 4 })

      // 操作按鈕
      Row({ space: 20 }) {
        Button('上一個')
          .width(100)
          .height(45)
          .fontSize(16)
          .backgroundColor('#9E9E9E')
          .onClick(() => {
            this.prevWord();
          })

        Column({ space: 5 }) {
          Checkbox({ name: 'mastered', group: 'wordMaster' })
            .select(this.currentWord.mastered)
            .selectedColor('#4CAF50')
            .width(25)
            .height(25)
            .onChange((checked: boolean) => {
              this.toggleMastered(checked);
            })
          Text('已掌握')
            .fontSize(12)
            .fontColor('#666666')
        }

        Button('下一個')
          .width(100)
          .height(45)
          .fontSize(16)
          .backgroundColor('#007DFF')
          .onClick(() => {
            this.nextWord();
          })
      }
      .margin({ top: 20 })
    }
    .width('100%')
    .justifyContent(FlexAlign.Center)
  }

  // 拼寫測試頁面
  @Builder
  buildSpellingPage() {
    Column({ space: 20 }) {
      // 題目信息
      Text('拼寫測試')
        .fontSize(24)
        .fontWeight(FontWeight.Bold)
        .fontColor('#333333')
        .margin({ top: 20 })

      // 提示信息
      Text('根據釋義拼寫單詞:')
        .fontSize(18)
        .fontColor('#666666')

      // 單詞釋義
      Text(this.currentWord.meaning)
        .fontSize(22)
        .fontWeight(FontWeight.Bold)
        .fontColor('#4CAF50')
        .padding(20)
        .backgroundColor('#FFFFFF')
        .borderRadius(10)
        .width('90%')

      // 拼寫輸入框
      TextInput({ placeholder: '輸入單詞拼寫', text: this.spellingInput })
        .width('90%')
        .height(55)
        .fontSize(20)
        .backgroundColor('#FFFFFF')
        .borderRadius(8)
        .onChange((value: string) => {
          this.spellingInput = value;
        })

      // 提示按鈕
      if (!this.showAnswer) {
        Button('提示:顯示音標')
          .width(180)
          .height(40)
          .fontSize(16)
          .backgroundColor('#FF9800')
          .onClick(() => {
            this.showAnswer = true;
          })
      } else {
        Text('音標:' + this.currentWord.phonetic)
          .fontSize(18)
          .fontColor('#FF9800')
          .padding(10)
          .backgroundColor('#FFF3E0')
          .borderRadius(8)
      }

      // 操作按鈕
      Row({ space: 20 }) {
        Button('跳過')
          .width(100)
          .height(45)
          .fontSize(16)
          .backgroundColor('#9E9E9E')
          .onClick(() => {
            this.skipSpelling();
          })

        Button('檢查')
          .width(100)
          .height(45)
          .fontSize(16)
          .backgroundColor('#007DFF')
          .onClick(() => {
            this.checkSpelling();
          })
      }
      .margin({ top: 20 })

      // 正確率顯示
      if (this.accuracy > 0) {
        Text('當前正確率:' + this.accuracy.toFixed(1) + '%')
          .fontSize(16)
          .fontColor('#4CAF50')
          .margin({ top: 15 })
      }
    }
    .width('100%')
    .justifyContent(FlexAlign.Center)
  }

  // 錯題集頁面 - 修正版(移除圖片資源引用)
  @Builder
  buildWrongWordsPage() {
    Column({ space: 0 }) {
      // 標題
      Row() {
        Text('錯題集')
          .fontSize(20)
          .fontWeight(FontWeight.Bold)
          .fontColor('#333333')
          .layoutWeight(1)

        Text('共' + this.wrongWords.length + '個單詞')
          .fontSize(14)
          .fontColor('#666666')
      }
      .width('90%')
      .padding({ top: 20, bottom: 15 })

      // 錯題列表
      if (this.wrongWords.length === 0) {
        Column() {
          // 移除圖片引用,用圖標代替
          Text('📝')
            .fontSize(48)
            .margin({ bottom: 15 })
          Text('暫無錯題')
            .fontSize(18)
            .fontColor('#999999')
          Text('繼續加油學習吧!')
            .fontSize(14)
            .fontColor('#999999')
            .margin({ top: 5 })
        }
        .width('100%')
        .height(300)
        .justifyContent(FlexAlign.Center)
      } else {
        List({ space: 10 }) {
          ForEach(this.wrongWords, (word: WordItem) => {
            ListItem() {
              this.buildWrongWordItem(word)
            }
          })
        }
        .width('100%')
        .layoutWeight(1)
      }

      // 複習按鈕
      if (this.wrongWords.length > 0) {
        Button('開始複習錯題')
          .width('90%')
          .height(50)
          .fontSize(18)
          .backgroundColor('#FF5722')
          .margin(20)
          .onClick(() => {
            this.reviewWrongWords();
          })
      }
    }
    .width('100%')
  }

  // 錯題項
  @Builder
  buildWrongWordItem(word: WordItem) {
    Row() {
      Column({ space: 3 }) {
        Text(word.word)
          .fontSize(18)
          .fontWeight(FontWeight.Bold)
          .fontColor('#FF5722')
        Text(word.phonetic)
          .fontSize(14)
          .fontColor('#666666')
      }
      .layoutWeight(1)

      Column({ space: 2 }) {
        Text(word.meaning)
          .fontSize(14)
          .fontColor('#333333')
          .maxLines(2)
          .textOverflow({ overflow: TextOverflow.Ellipsis })
        Text('錯誤次數:' + word.wrongCount)
          .fontSize(12)
          .fontColor('#999999')
      }
      .layoutWeight(2)

      Button('複習')
        .width(60)
        .height(30)
        .fontSize(12)
        .backgroundColor('#2196F3')
        .onClick(() => {
          this.reviewSingleWord(word);
        })
    }
    .width('95%')
    .padding(15)
    .backgroundColor('#FFFFFF')
    .borderRadius(10)
    .margin({ left: 10, right: 10 })
    .shadow({ radius: 3, color: '#FFEBEE', offsetX: 1, offsetY: 1 })
  }

  // 單詞書頁面
  @Builder
  buildBooksPage() {
    Column({ space: 0 }) {
      // 標題
      Text('單詞書庫')
        .fontSize(22)
        .fontWeight(FontWeight.Bold)
        .fontColor('#333333')
        .margin({ top: 20, bottom: 15 })

      // 單詞書列表
      List({ space: 15 }) {
        ForEach(this.wordBooks, (book: WordBook) => {
          ListItem() {
            this.buildBookItem(book)
          }
        })
      }
      .width('100%')
      .layoutWeight(1)
      .padding({ left: 15, right: 15 })
    }
    .width('100%')
  }

  // 單詞書項
  @Builder
  buildBookItem(book: WordBook) {
    Row() {
      Column({ space: 5 }) {
        Text(book.name)
          .fontSize(18)
          .fontWeight(FontWeight.Bold)
          .fontColor('#333333')
        Row() {
          Text('詞彙量:' + book.wordCount)
            .fontSize(14)
            .fontColor('#666666')
          Text('難度:' + book.level)
            .fontSize(14)
            .fontColor('#FF9800')
            .margin({ left: 20 })
        }
      }
      .layoutWeight(1)

      Button(book.downloaded ? '已下載' : '下載')
        .width(90)
        .height(35)
        .fontSize(14)
        .backgroundColor(book.downloaded ? '#4CAF50' : '#007DFF')
        .onClick(() => {
          if (!book.downloaded) {
            this.downloadWordBook(book);
          } else {
            this.showBookDetailDialog(book);
          }
        })
    }
    .width('100%')
    .padding(20)
    .backgroundColor('#FFFFFF')
    .borderRadius(12)
    .shadow({ radius: 5, color: '#E0E0E0', offsetX: 1, offsetY: 2 })
  }

  // 單詞書詳情對話框
  @Builder
  buildBookDetailDialog() {
    Column() {
      Text(this.selectedBook.name)
        .fontSize(20)
        .fontWeight(FontWeight.Bold)
        .margin({ top: 20, bottom: 10 })

      Row() {
        Text('詞彙量:')
          .fontSize(16)
          .fontColor('#666666')
        Text(this.selectedBook.wordCount.toString())
          .fontSize(18)
          .fontWeight(FontWeight.Bold)
          .fontColor('#007DFF')
      }
      .margin({ bottom: 8 })

      Row() {
        Text('難度等級:')
          .fontSize(16)
          .fontColor('#666666')
        Text(this.selectedBook.level)
          .fontSize(18)
          .fontWeight(FontWeight.Bold)
          .fontColor('#FF9800')
      }
      .margin({ bottom: 20 })

      Button('開始學習')
        .width('80%')
        .height(50)
        .fontSize(18)
        .backgroundColor('#007DFF')
        .margin({ bottom: 15 })
        .onClick(() => {
          this.startLearningBook();
        })

      Button('查看詞表')
        .width('80%')
        .height(50)
        .fontSize(18)
        .backgroundColor('#4CAF50')
        .margin({ bottom: 15 })
        .onClick(() => {
          this.viewWordList();
        })

      Button('關閉')
        .width('80%')
        .height(45)
        .fontSize(16)
        .backgroundColor('#9E9E9E')
        .margin({ bottom: 20 })
        .onClick(() => {
          this.showBookDetail = false;
        })
    }
    .width('85%')
    .backgroundColor('#FFFFFF')
    .borderRadius(15)
    .shadow({ radius: 20, color: '#00000040' })
    .position({ x: '7.5%', y: '15%' })
  }

  // 底部統計欄
  @Builder
  buildStatsBar() {
    Row() {
      Column({ space: 2 }) {
        Text(this.totalWords.toString())
          .fontSize(18)
          .fontWeight(FontWeight.Bold)
          .fontColor('#007DFF')
        Text('總詞彙')
          .fontSize(12)
          .fontColor('#666666')
      }
      .layoutWeight(1)

      Column({ space: 2 }) {
        Text(this.masteredWords.toString())
          .fontSize(18)
          .fontWeight(FontWeight.Bold)
          .fontColor('#4CAF50')
        Text('已掌握')
          .fontSize(12)
          .fontColor('#666666')
      }
      .layoutWeight(1)

      Column({ space: 2 }) {
        Text(this.accuracy.toFixed(1) + '%')
          .fontSize(18)
          .fontWeight(FontWeight.Bold)
          .fontColor('#FF9800')
        Text('正確率')
          .fontSize(12)
          .fontColor('#666666')
      }
      .layoutWeight(1)

      Column({ space: 2 }) {
        Text(this.wrongWords.length.toString())
          .fontSize(18)
          .fontWeight(FontWeight.Bold)
          .fontColor('#FF5722')
        Text('錯題')
          .fontSize(12)
          .fontColor('#666666')
      }
      .layoutWeight(1)
    }
    .width('100%')
    .padding(15)
    .backgroundColor('#FFFFFF')
    .border({ width: { top: 1 }, color: '#E0E0E0' })
  }

  // 加載當前單詞
  loadCurrentWord() {
    if (this.wordList.length > 0 && this.currentIndex < this.wordList.length) {
      // 使用構造函數創建新對象,避免對象字面量問題
      const word = this.wordList[this.currentIndex];
      this.currentWord = new WordItem(
        word.id,
        word.word,
        word.phonetic,
        word.meaning,
        word.example,
        word.level
      );
      this.currentWord.mastered = word.mastered;
      this.currentWord.wrongCount = word.wrongCount;
    }
  }

  // 上一個單詞
  prevWord() {
    if (this.currentIndex > 0) {
      this.currentIndex--;
      this.loadCurrentWord();
      this.showMeaning = false;
    }
  }

  // 下一個單詞
  nextWord() {
    if (this.currentIndex < this.wordList.length - 1) {
      this.currentIndex++;
      this.loadCurrentWord();
      this.showMeaning = false;
    } else {
      promptAction.showToast({ message: '已經是最後一個單詞了', duration: 2000 });
    }
  }

  // 切換掌握狀態
  toggleMastered(checked: boolean) {
    this.wordList[this.currentIndex].mastered = checked;
    this.calculateStatistics();

    if (checked) {
      promptAction.showToast({ message: '已標記為掌握', duration: 1500 });
    }
  }

  // 開始拼寫測試
  startSpellingTest() {
    if (this.wordList.length === 0) {
      promptAction.showToast({ message: '請先添加單詞', duration: 2000 });
      return;
    }

    this.spellingMode = true;
    this.showAnswer = false;
    this.spellingInput = '';

    // 隨機選擇一個未掌握的單詞
    const unmasteredWords = this.wordList.filter(word => !word.mastered);
    if (unmasteredWords.length > 0) {
      const randomIndex = Math.floor(Math.random() * unmasteredWords.length);
      const word = unmasteredWords[randomIndex];
      this.currentWord = new WordItem(
        word.id,
        word.word,
        word.phonetic,
        word.meaning,
        word.example,
        word.level
      );
    } else {
      this.loadCurrentWord();
    }
  }

  // 檢查拼寫
  checkSpelling() {
    if (!this.spellingInput.trim()) {
      promptAction.showToast({ message: '請輸入單詞', duration: 2000 });
      return;
    }

    const isCorrect = this.spellingInput.toLowerCase() === this.currentWord.word.toLowerCase();

    if (isCorrect) {
      promptAction.showToast({ message: '✓ 拼寫正確!', duration: 2000 });

      // 更新單詞掌握狀態
      for (let i = 0; i < this.wordList.length; i++) {
        if (this.wordList[i].id === this.currentWord.id) {
          this.wordList[i].mastered = true;
          break;
        }
      }
      this.nextWord();
    } else {
      promptAction.showToast({ message: '✗ 拼寫錯誤', duration: 2000 });

      // 添加到錯題集
      let foundInWrongList = false;
      for (let i = 0; i < this.wrongWords.length; i++) {
        if (this.wrongWords[i].id === this.currentWord.id) {
          this.wrongWords[i].wrongCount++;
          foundInWrongList = true;
          break;
        }
      }

      if (!foundInWrongList) {
        const wrongWord = new WordItem(
          this.currentWord.id,
          this.currentWord.word,
          this.currentWord.phonetic,
          this.currentWord.meaning,
          this.currentWord.example,
          this.currentWord.level
        );
        wrongWord.wrongCount = 1;
        this.wrongWords.push(wrongWord);
      }

      // 更新主列表中的錯誤計數
      for (let i = 0; i < this.wordList.length; i++) {
        if (this.wordList[i].id === this.currentWord.id) {
          this.wordList[i].wrongCount++;
          break;
        }
      }
    }

    this.spellingInput = '';
    this.showAnswer = false;
    this.calculateStatistics();
  }

  // 跳過拼寫
  skipSpelling() {
    promptAction.showToast({ message: '已跳過', duration: 1500 });
    this.spellingInput = '';
    this.showAnswer = false;
    this.nextWord();
  }

  // 發音功能
  speakWord() {
    promptAction.showToast({ message: '發音:' + this.currentWord.word, duration: 2000 });
  }

  // 下載單詞書
  downloadWordBook(book: WordBook) {
    promptAction.showDialog({
      title: '下載確認',
      message: '確定要下載《' + book.name + '》嗎?(' + book.wordCount + '個單詞)',
      buttons: [
        { text: '取消', color: '#666666' },
        { text: '下載', color: '#007DFF' }
      ]
    }).then((result) => {
      if (result.index === 1) {
        for (let i = 0; i < this.wordBooks.length; i++) {
          if (this.wordBooks[i].id === book.id) {
            this.wordBooks[i].downloaded = true;
            break;
          }
        }
        promptAction.showToast({
          message: '《' + book.name + '》下載完成',
          duration: 2000
        });
      }
    });
  }

  // 顯示單詞書詳情
  showBookDetailDialog(book: WordBook) {
    this.selectedBook = new WordBook(book.id, book.name, book.wordCount, book.level);
    this.selectedBook.downloaded = book.downloaded;
    this.showBookDetail = true;
  }

  // 開始學習單詞書
  startLearningBook() {
    this.currentPage = 'learn';
    this.showBookDetail = false;
    promptAction.showToast({
      message: '開始學習《' + this.selectedBook.name + '》',
      duration: 2000
    });
  }

  // 查看詞表
  viewWordList() {
    promptAction.showToast({
      message: '詞表功能開發中',
      duration: 2000
    });
  }

  // 複習錯題 - 修正版(避免使用擴展操作符)
  reviewWrongWords() {
    if (this.wrongWords.length === 0) {
      promptAction.showToast({ message: '暫無錯題可複習', duration: 2000 });
      return;
    }

    // 使用循環而不是擴展操作符
    const newWordList: WordItem[] = [];
    for (let i = 0; i < this.wrongWords.length; i++) {
      const word = this.wrongWords[i];
      newWordList.push(new WordItem(
        word.id,
        word.word,
        word.phonetic,
        word.meaning,
        word.example,
        word.level
      ));
    }

    this.wordList = newWordList;
    this.currentIndex = 0;
    this.currentPage = 'learn';
    this.loadCurrentWord();

    promptAction.showToast({
      message: '開始複習錯題集(' + this.wrongWords.length + '個單詞)',
      duration: 2000
    });
  }

  // 複習單個錯題
  reviewSingleWord(word: WordItem) {
    const index = this.wordList.findIndex(w => w.id === word.id);
    if (index !== -1) {
      this.currentIndex = index;
      this.currentPage = 'learn';
      this.loadCurrentWord();
    } else {
      // 如果不在當前列表中,添加到列表開始
      const newWord = new WordItem(
        word.id,
        word.word,
        word.phonetic,
        word.meaning,
        word.example,
        word.level
      );
      this.wordList.unshift(newWord);
      this.currentIndex = 0;
      this.currentPage = 'learn';
      this.loadCurrentWord();
    }
  }

  // 計算統計信息
  calculateStatistics() {
    this.totalWords = this.wordList.length;
    this.masteredWords = 0;

    for (let i = 0; i < this.wordList.length; i++) {
      if (this.wordList[i].mastered) {
        this.masteredWords++;
      }
    }

    const totalTests = this.masteredWords + this.wrongWords.reduce((sum, word) => sum + word.wrongCount, 0);
    this.accuracy = totalTests > 0 ? (this.masteredWords / totalTests) * 100 : 0;
  }
}

想入門鴻蒙開發又怕花冤枉錢?別錯過!現在能免費系統學 -- 從 ArkTS 面向對象核心的類和對象、繼承多態,到吃透鴻蒙開發關鍵技能,還能衝刺鴻蒙基礎 +高級開發者證書,更驚喜的是考證成功還送好禮!快加入我的鴻蒙班,一起從入門到精通,班級鏈接:點擊https://developer.huawei.com/consumer/cn/training/classDetail/b7365031334e4353a9a0fd6785bb0791?type=1?ha_source=hmosclass&ha_sourceId=89000248免費進入