feat:更新资料库模块

This commit is contained in:
2026-08-02 21:01:42 +08:00
parent fefd329ea8
commit 7bb08a7ac4
9 changed files with 136 additions and 283 deletions

View File

@@ -16,6 +16,7 @@
<div class="card-actions">
<el-button type="primary" :icon="Edit" @click="editClick(file)">编辑</el-button>
<el-button type="primary" :icon="Aim" @click="trainClick(file)">训练</el-button>
<el-button type="danger" :icon="Delete">删除</el-button>
</div>
</div>
@@ -25,15 +26,18 @@
</template>
<script setup lang="ts">
import { Delete, Edit, Picture, Document } from '@element-plus/icons-vue'
import { Delete, Edit, Picture, Document, Aim } from '@element-plus/icons-vue'
import { useLibraryStore } from '@/stores/library.ts'
import { usePracticeStore } from '@/stores/practice.ts'
import type { ILibraryFile } from '@/types/library.ts'
import LibraryFilter from '@/components/Library/LibraryFilter.vue'
import { computed } from 'vue'
import { fromNow } from '@/utils/dayUtil.ts'
import { filesize } from 'filesize'
import { ElLoading, ElMessage } from 'element-plus'
const libraryStore = useLibraryStore()
const practiceStore = usePracticeStore()
const filterLibraryFileList = computed(() => {
const subject = libraryStore.selectedSubject
@@ -52,4 +56,59 @@ const editClick = async (file: ILibraryFile) => {
libraryStore.activeStep = 1
libraryStore.fileDialogVisible = true
}
const trainClick = async (file: ILibraryFile) => {
await libraryStore.queryFileById(file.id)
await generateQuestion()
practiceStore.hasStart = true
practiceStore.hasSubmit = false
practiceStore.checkList = []
}
const generateQuestion = async () => {
practiceStore.questionContent = ''
practiceStore.hasGenerateQuestion = false
const loading = ElLoading.service({
lock: true,
text: '题库生成中 请等待',
background: 'rgba(0, 0, 0, 0.7)'
})
try {
const response = await fetch('/study-api/library/question', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: libraryStore.currentFile.content
})
})
if (!response.body) {
throw new Error('未获取到响应流')
}
const reader = response.body.getReader()
const decoder = new TextDecoder('utf-8')
while (true) {
const { value, done } = await reader.read()
if (done) break
practiceStore.questionContent += decoder.decode(value, { stream: true })
}
ElMessage.success('生成完成')
practiceStore.hasGenerateQuestion = true
practiceStore.questionList = JSON.parse(practiceStore.questionContent)
libraryStore.fileTrainDialogVisible = true
} catch (error) {
console.log(error)
ElMessage.error('生成失败 请联系管理员')
} finally {
loading.close()
}
}
</script>