1.关闭eslintrc.js校验

2.完成AI辅导员弹窗
3.降低了md插件版本到v13
This commit is contained in:
2025-08-14 23:26:49 +08:00
parent 2e80cc075a
commit d1658d32e3
11 changed files with 1143 additions and 667 deletions

View File

@@ -1,7 +1,7 @@
import { getToken } from '@/utils/auth'
import { getTokenKeySessionStorage } from "@/utils/auth";
// 使用环境变量配置基础URL
const BASE_URL = process.env.VUE_APP_API_BASE_URL || 'http://localhost:8088'
const BASE_URL = process.env.VUE_APP_API_BASE_URL || "http://localhost:8088";
/**
* 创建聊天流式连接
@@ -13,54 +13,55 @@ const BASE_URL = process.env.VUE_APP_API_BASE_URL || 'http://localhost:8088'
* @returns {Object} 包含stream和cancel方法的对象
*/
export function createChatStream(params) {
const requestId = `req-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
const url = `${BASE_URL}/aitutor/aichat/stream`
const token = getToken()
const requestId = `req-${Date.now()}-${Math.random()
.toString(36)
.slice(2, 8)}`;
const url = `${BASE_URL}/aitutor/aichat/stream`;
const token = getTokenKeySessionStorage();
if (!token) {
throw new Error('请先登录')
if (!token) {
throw new Error("请先登录");
}
const controller = new AbortController();
const fetchPromise = fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
"X-Request-ID": requestId,
},
body: JSON.stringify({
query: params.prompt,
user_id: params.userId,
user_name: params.userName,
user_token: params.user_token || "123",
user_role: "student",
conversation_id: params.conversationId || null,
}),
signal: controller.signal,
}).then((response) => {
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
if (!response.body) {
throw new Error("Response body is null");
}
const controller = new AbortController()
const fetchPromise = fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
'X-Request-ID': requestId
},
body: JSON.stringify({
query: params.prompt,
user_id: params.userId,
user_name: params.userName,
user_token: params.user_token || '123',
user_role: 'student',
conversation_id: params.conversationId || null,
}),
signal: controller.signal
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP ${response.status}`)
}
if (!response.body) {
throw new Error('Response body is null')
}
return {
reader: response.body.getReader(),
decoder: new TextDecoder('utf-8')
}
})
return {
stream: fetchPromise,
cancel: (reason) => {
if (!controller.signal.aborted) {
controller.abort(reason)
}
}
}
reader: response.body.getReader(),
decoder: new TextDecoder("utf-8"),
};
});
return {
stream: fetchPromise,
cancel: (reason) => {
if (!controller.signal.aborted) {
controller.abort(reason);
}
},
};
}
/**
@@ -71,40 +72,44 @@ export function createChatStream(params) {
* @param {Function} onError 错误回调
* @param {Function} onComplete 完成回调
*/
export async function processStream(reader, decoder, { onMessage, onError, onComplete }) {
let buffer = ''
export async function processStream(
reader,
decoder,
{ onMessage, onError, onComplete }
) {
let buffer = "";
try {
while (true) {
const { done, value } = await reader.read()
if (done) break
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true })
const lines = buffer.split('\n')
buffer = lines.pop() || ''
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split("\n");
buffer = lines.pop() || "";
for (const line of lines) {
if (!line.trim()) continue
for (const line of lines) {
if (!line.trim()) continue;
try {
const data = JSON.parse(line)
if (typeof onMessage === 'function') {
onMessage(data)
}
} catch (e) {
console.warn('解析消息失败:', line, e)
}
}
try {
const data = JSON.parse(line);
if (typeof onMessage === "function") {
onMessage(data);
}
} catch (e) {
console.warn("解析消息失败:", line, e);
}
if (typeof onComplete === 'function') {
onComplete()
}
} catch (error) {
if (error.name !== 'AbortError' && typeof onError === 'function') {
onError(error)
}
} finally {
reader.releaseLock()
}
}
}
if (typeof onComplete === "function") {
onComplete();
}
} catch (error) {
if (error.name !== "AbortError" && typeof onError === "function") {
onError(error);
}
} finally {
reader.releaseLock();
}
}