完成全部功能,优化图表和对话
This commit is contained in:
@@ -6,7 +6,7 @@ import * as echarts from 'echarts'
|
||||
import {CategoryScale, Chart, LinearScale, LineController, LineElement, PointElement, Title,} from 'chart.js'
|
||||
import 'chartjs-adapter-moment'
|
||||
import mermaid from 'mermaid'
|
||||
import {each, isEqual, isJson, nextTick} from 'licia'
|
||||
import {each, isEqual, isNull, nextTick} from 'licia'
|
||||
|
||||
Chart.register(
|
||||
LineController,
|
||||
@@ -35,14 +35,19 @@ md.use(function (md) {
|
||||
const content = tokens[idx].content
|
||||
// 此处判断是否为 echarts 代码块
|
||||
if (tokens[idx].info === 'echarts') {
|
||||
if (isJson(content)) {
|
||||
chartsMap.value.echarts[idx] = JSON.parse(content) //此处表示将内容存起来,存到当前页面的变量去
|
||||
try {
|
||||
chartsMap.value.echarts[idx] = JSON.parse(content)
|
||||
console.log('ok', content)
|
||||
} catch (e) {
|
||||
console.error(e, content)
|
||||
}
|
||||
return `<div id="echarts-${idx}" style="width: 600px;height:400px;"></div>`
|
||||
} else if (tokens[idx].info === 'chartjs') {
|
||||
// 此处判断是否为 chartjs 代码块
|
||||
if (isJson(content)) {
|
||||
try {
|
||||
chartsMap.value.chartjs[idx] = JSON.parse(content)
|
||||
} catch (e) {
|
||||
console.error(e, content)
|
||||
}
|
||||
return `<canvas id="chartjs-${idx}"></canvas>`
|
||||
} else if (tokens[idx].info === 'mermaid') {
|
||||
@@ -97,6 +102,7 @@ const handleSubmit = async () => {
|
||||
mermaid: {},
|
||||
}
|
||||
|
||||
let eventSource
|
||||
try {
|
||||
const url = 'http://localhost:7891/chat/stream'
|
||||
const formData = new FormData()
|
||||
@@ -112,7 +118,7 @@ const handleSubmit = async () => {
|
||||
formData.append('database_name', databaseName.value)
|
||||
}
|
||||
|
||||
const eventSource = createEventSource({
|
||||
eventSource = createEventSource({
|
||||
url: url,
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
@@ -131,6 +137,9 @@ const handleSubmit = async () => {
|
||||
answer.value = '抱歉,请求出现错误'
|
||||
renderedAnswer.value = answer.value
|
||||
showToastMessage('请求失败,请检查服务器连接', 'error')
|
||||
if (!isNull(eventSource)) {
|
||||
eventSource.close()
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -224,7 +233,7 @@ onMounted(() => {
|
||||
<template>
|
||||
<div class="chat-container">
|
||||
<div class="chat-header">
|
||||
<h1>数据库助手</h1>
|
||||
<h1>知识库助手</h1>
|
||||
</div>
|
||||
|
||||
<div class="messages-container">
|
||||
|
||||
Reference in New Issue
Block a user