From 1a63e14e8239218e03b66cd61ed2e1fc7446f637 Mon Sep 17 00:00:00 2001 From: Cxx0822 <1556464090@qq.com> Date: Sun, 9 Aug 2026 14:01:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=9B=B4=E6=96=B0=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/exam.ts | 9 --- src/apis/mistake.ts | 8 +-- src/apis/practice.ts | 15 ---- src/apis/record.ts | 15 ++++ src/components/question/QuestionList.vue | 89 ++++++++---------------- src/stores/exam.ts | 9 +-- src/stores/mistake.ts | 8 +-- src/stores/practice.ts | 19 ----- src/stores/question.ts | 6 +- src/stores/record.ts | 18 +++++ src/types/exam.ts | 9 --- src/types/mistake.ts | 3 - src/types/{practice.ts => record.ts} | 6 +- src/views/Exam.vue | 1 + src/views/Mistakes.vue | 22 ++++-- 15 files changed, 94 insertions(+), 143 deletions(-) delete mode 100644 src/apis/exam.ts delete mode 100644 src/apis/practice.ts create mode 100644 src/apis/record.ts delete mode 100644 src/stores/practice.ts create mode 100644 src/stores/record.ts rename src/types/{practice.ts => record.ts} (68%) diff --git a/src/apis/exam.ts b/src/apis/exam.ts deleted file mode 100644 index 73410ba..0000000 --- a/src/apis/exam.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { cloudService } from './index' -import type { IExamRecord } from '@/types/exam.ts' - -export const addExamRecordApi = (data: IExamRecord): Promise => - cloudService({ - url: '/study-api/exam/record', - method: 'post', - data - }) diff --git a/src/apis/mistake.ts b/src/apis/mistake.ts index e9e5857..d02e9f2 100644 --- a/src/apis/mistake.ts +++ b/src/apis/mistake.ts @@ -1,15 +1,15 @@ import { cloudService } from './index' import type { IMistake } from '@/types/mistake.ts' -export const queryMistakeListApi = (): Promise => +export const queryMistakeListApi = (subject: string): Promise => cloudService({ - url: '/study-api/mistake', + url: `/study-api/mistake/${subject}`, method: 'get' }) -export const addMistakeListApi = (data: IMistake[]): Promise => +export const addMistakeListApi = (subject: string, data: IMistake[]): Promise => cloudService({ - url: '/study-api/mistake', + url: `/study-api/mistake/${subject}`, method: 'post', data }) diff --git a/src/apis/practice.ts b/src/apis/practice.ts deleted file mode 100644 index d70d51e..0000000 --- a/src/apis/practice.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { cloudService } from './index' -import type { IPracticeRecord } from '@/types/practice.ts' - -export const queryPracticeRecordApi = (id: number): Promise => - cloudService({ - url: `/study-api/practice/record/${id}`, - method: 'get' - }) - -export const addPracticeRecordApi = (data: IPracticeRecord): Promise => - cloudService({ - url: '/study-api/practice/record', - method: 'post', - data - }) diff --git a/src/apis/record.ts b/src/apis/record.ts new file mode 100644 index 0000000..e07b0cb --- /dev/null +++ b/src/apis/record.ts @@ -0,0 +1,15 @@ +import { cloudService } from './index' +import type { IRecord } from '@/types/record.ts' + +export const queryRecordApi = (subject: string): Promise => + cloudService({ + url: `/study-api/record/${subject}`, + method: 'get' + }) + +export const addRecordApi = (subject: string, data: IRecord): Promise => + cloudService({ + url: `/study-api/record/${subject}`, + method: 'post', + data + }) diff --git a/src/components/question/QuestionList.vue b/src/components/question/QuestionList.vue index 10e7e9e..8bec346 100644 --- a/src/components/question/QuestionList.vue +++ b/src/components/question/QuestionList.vue @@ -42,20 +42,18 @@ diff --git a/src/stores/exam.ts b/src/stores/exam.ts index 03353e0..f1b82fb 100644 --- a/src/stores/exam.ts +++ b/src/stores/exam.ts @@ -1,12 +1,10 @@ import { defineStore } from 'pinia' -import type { IExamConfig, IExamRecord } from '@/types/exam.ts' -import { addExamRecordApi } from '@/apis/exam.ts' +import type { IExamConfig } from '@/types/exam.ts' export const useExamStore = defineStore('exam', { state: () => ({ dialogVisible: false, - config: {} as IExamConfig, - currentRecord: {} as IExamRecord + config: {} as IExamConfig }), actions: { getEmptyConfig(): IExamConfig { @@ -14,9 +12,6 @@ export const useExamStore = defineStore('exam', { subject: '', total: 50 } - }, - async addRecord() { - await addExamRecordApi(this.currentRecord) } } }) diff --git a/src/stores/mistake.ts b/src/stores/mistake.ts index dff326f..79a0624 100644 --- a/src/stores/mistake.ts +++ b/src/stores/mistake.ts @@ -8,11 +8,11 @@ export const useMistakeStore = defineStore('mistake', { currentMistakes: [] as IMistake[] }), actions: { - async queryMistakeList() { - this.mistakeList = await queryMistakeListApi() + async queryMistakeList(subject: string) { + this.mistakeList = await queryMistakeListApi(subject) }, - async addMistakeList() { - await addMistakeListApi(this.currentMistakes) + async addMistakeList(subject: string) { + await addMistakeListApi(subject, this.currentMistakes) }, async deleteMistakeById(id: number) { await deleteMistakeApi(id) diff --git a/src/stores/practice.ts b/src/stores/practice.ts deleted file mode 100644 index 49983d4..0000000 --- a/src/stores/practice.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { defineStore } from 'pinia' -import { addPracticeRecordApi, queryPracticeRecordApi } from '@/apis/practice.ts' -import type { IPracticeRecord } from '@/types/practice.ts' - -export const usePracticeStore = defineStore('practice', { - state: () => ({ - libraryFileId: 0, - recordList: [] as IPracticeRecord[], - currentRecord: {} as IPracticeRecord - }), - actions: { - async queryRecord() { - this.recordList = await queryPracticeRecordApi(this.libraryFileId) - }, - async addRecord() { - await addPracticeRecordApi(this.currentRecord) - } - } -}) diff --git a/src/stores/question.ts b/src/stores/question.ts index 4eb6bad..abba861 100644 --- a/src/stores/question.ts +++ b/src/stores/question.ts @@ -1,6 +1,6 @@ import { defineStore } from 'pinia' -import type { IPracticeCheck, IPracticeRecord } from '@/types/practice.ts' import type { IQuestion } from '@/types/question.ts' +import type { IRecord, IRecordCheck } from '@/types/record.ts' export const useQuestionStore = defineStore('question', { state: () => ({ @@ -8,7 +8,7 @@ export const useQuestionStore = defineStore('question', { type: 'Practice' as 'Practice' | 'Exam', questionContent: '', questionList: [] as IQuestion[], - recordList: [] as IPracticeRecord[], - checkList: [] as IPracticeCheck[] + recordList: [] as IRecord[], + checkList: [] as IRecordCheck[] }) }) diff --git a/src/stores/record.ts b/src/stores/record.ts new file mode 100644 index 0000000..5e80399 --- /dev/null +++ b/src/stores/record.ts @@ -0,0 +1,18 @@ +import { defineStore } from 'pinia' +import { addRecordApi, queryRecordApi } from '@/apis/record.ts' +import type { IRecord } from '@/types/record.ts' + +export const useRecordStore = defineStore('record', { + state: () => ({ + recordList: [] as IRecord[], + currentRecord: {} as IRecord + }), + actions: { + async queryRecord(subject: string) { + this.recordList = await queryRecordApi(subject) + }, + async addRecord(subject: string) { + await addRecordApi(subject, this.currentRecord) + } + } +}) diff --git a/src/types/exam.ts b/src/types/exam.ts index 546d3cb..49efef3 100644 --- a/src/types/exam.ts +++ b/src/types/exam.ts @@ -2,12 +2,3 @@ export interface IExamConfig { subject: string; total: number; } - -export interface IExamRecord { - id?: number; - subject: string; - totalCount: number; - correctCount: number; - wrongCount: number; - createTime?: string; -} diff --git a/src/types/mistake.ts b/src/types/mistake.ts index 557d946..9358b14 100644 --- a/src/types/mistake.ts +++ b/src/types/mistake.ts @@ -1,8 +1,5 @@ export interface IMistake { id?: number; - subject: string; - module: string; - name: string; type: string; question: string; options: string[]; diff --git a/src/types/practice.ts b/src/types/record.ts similarity index 68% rename from src/types/practice.ts rename to src/types/record.ts index 0db10f3..dcbba8b 100644 --- a/src/types/practice.ts +++ b/src/types/record.ts @@ -1,13 +1,13 @@ -export interface IPracticeCheck { +export interface IRecordCheck { id: number; answer: string[]; select: string[]; isCorrect: boolean; } -export interface IPracticeRecord { +export interface IRecord { id?: number; - libraryFileId:number; + type: string; totalCount: number; correctCount: number; wrongCount: number; diff --git a/src/views/Exam.vue b/src/views/Exam.vue index baeb478..ab46c37 100644 --- a/src/views/Exam.vue +++ b/src/views/Exam.vue @@ -9,6 +9,7 @@ +

请点击「开始考试」按钮进入考试

diff --git a/src/views/Mistakes.vue b/src/views/Mistakes.vue index 0fbad74..1907e38 100644 --- a/src/views/Mistakes.vue +++ b/src/views/Mistakes.vue @@ -7,13 +7,21 @@ +
+
+ 学科 + +
+
+
- {{ item.subject }} · {{ item.module }} - 已掌握 + {{ libraryStore.selectedSubject }} + 已掌握
{{ item.question }}
@@ -38,11 +46,13 @@ import { useMistakeStore } from '@/stores/mistake.ts' import { optLetter } from '@/utils/practiceUtil.ts' import type { IMistake } from '@/types/mistake.ts' import { ElMessageBox } from 'element-plus' +import { useLibraryStore } from '@/stores/library.ts' const mistakeStore = useMistakeStore() +const libraryStore = useLibraryStore() onMounted(async () => { - await mistakeStore.queryMistakeList() + await mistakeStore.queryMistakeList(libraryStore.selectedSubject as string) }) const optionClass = (item: IMistake, index: number) => { @@ -53,14 +63,14 @@ const optionClass = (item: IMistake, index: number) => { } } -const deleteClick = (id: number) => { +const deleteClick = (mistake: IMistake) => { ElMessageBox.confirm('确定已掌握该错题?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(async () => { - await mistakeStore.deleteMistakeById(id) - await mistakeStore.queryMistakeList() + await mistakeStore.deleteMistakeById(mistake.id as number) + await mistakeStore.queryMistakeList(libraryStore.selectedSubject as string) }) }