From fefd329ea8aea551c68b3f3df2ddc4788a715c60 Mon Sep 17 00:00:00 2001
From: Cxx0822 <1556464090@qq.com>
Date: Sun, 2 Aug 2026 09:47:02 +0800
Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0AI=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E8=B5=84=E6=96=99=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components/Library/LibraryFileDialog.vue | 67 ++++++++++++++++++--
1 file changed, 60 insertions(+), 7 deletions(-)
diff --git a/src/components/Library/LibraryFileDialog.vue b/src/components/Library/LibraryFileDialog.vue
index 5ce9a59..6cf73d0 100644
--- a/src/components/Library/LibraryFileDialog.vue
+++ b/src/components/Library/LibraryFileDialog.vue
@@ -33,7 +33,7 @@
@@ -51,11 +51,13 @@
+
+
+ AI生成
+
-
+
取消
@@ -73,12 +75,13 @@
import { ref } from 'vue'
import { useLibraryStore } from '@/stores/library.ts'
import { ElLoading, ElMessage, type FormInstance, type UploadRequestOptions } from 'element-plus'
-import { Document, Upload, UploadFilled } from '@element-plus/icons-vue'
-import { QuillEditor } from '@vueup/vue-quill'
+import { Document, Upload, UploadFilled, MagicStick } from '@element-plus/icons-vue'
import '@vueup/vue-quill/dist/vue-quill.snow.css'
import { uploadLibraryFileApi } from '@/apis/library.ts'
import { getModuleOptions } from '@/utils/libraryUtil.ts'
import { getFileExtension, getFileHashName } from '@/utils/fileUtil.ts'
+import { MdEditor } from 'md-editor-v3'
+import 'md-editor-v3/lib/style.css'
const libraryStore = useLibraryStore()
const libraryFileFormRef = ref()
@@ -147,6 +150,56 @@ const upload = async (options: UploadRequestOptions) => {
}
}
+const generateClick = async () => {
+ const { subject, module, name } = libraryStore.currentFile
+
+ if (subject && module && name) {
+ libraryStore.currentFile.content = ''
+ libraryStore.activeStep++
+
+ const loading = ElLoading.service({
+ lock: true,
+ text: '资料生成中 请等待',
+ background: 'rgba(0, 0, 0, 0.7)'
+ })
+
+ try {
+ const response = await fetch('/study-api/library/knowledge', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ subject,
+ module,
+ name
+ })
+ })
+
+ 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
+ libraryStore.currentFile.content += decoder.decode(value, { stream: true })
+ }
+
+ ElMessage.success('生成完成')
+ } catch (error) {
+ console.log(error)
+ ElMessage.error('生成失败 请联系管理员')
+ } finally {
+ loading.close()
+ }
+ } else {
+ ElMessage.error('请先填写信息')
+ }
+}
const submitForm = async () => {
if (libraryStore.currentFile.content) {
@@ -164,7 +217,7 @@ const submitForm = async () => {
flex-direction: column;
gap: 16px;
- .ql-container {
+ .md-editor {
height: auto;
}